AE2 First Commit, the dawn of 1.7 hast arrived.

This commit is contained in:
algorithmx2
2013-12-27 16:59:59 -06:00
commit e9acdcbee2
468 changed files with 47440 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
package appeng.core;
import java.io.File;
import java.util.logging.Level;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
public class AELog
{
public static cpw.mods.fml.relauncher.FMLRelaunchLog instance = cpw.mods.fml.relauncher.FMLRelaunchLog.log;
public static net.minecraftforge.common.Configuration localizeation = new net.minecraftforge.common.Configuration( new File( "en_us.lang" ) );
private AELog() {
}
private static void log(Level level, String format, Object... data)
{
FMLRelaunchLog.log( "AE", level, format, data );
}
public static void severe(String format, Object... data)
{
log( Level.SEVERE, format, data );
}
public static void warning(String format, Object... data)
{
log( Level.WARNING, format, data );
}
public static void info(String format, Object... data)
{
log( Level.INFO, format, data );
}
public static void grinder(String o)
{
log( Level.FINEST, "grinder: " + o );
}
public static void localization(String category, String unlocalizedName)
{
localizeation.get( category, unlocalizedName, unlocalizedName );
localizeation.save();
}
public static void error(Throwable e)
{
log( Level.SEVERE, "Error Occurred" );
e.printStackTrace();
}
}
+96
View File
@@ -0,0 +1,96 @@
package appeng.core;
import net.minecraftforge.common.ForgeDirection;
import appeng.api.IAppEngApi;
import appeng.api.definitions.Blocks;
import appeng.api.definitions.Items;
import appeng.api.definitions.Materials;
import appeng.api.definitions.Parts;
import appeng.api.features.IRegistryContainer;
import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridNode;
import appeng.api.parts.IPartHelper;
import appeng.api.storage.IStorageHelper;
import appeng.core.api.ApiPart;
import appeng.core.api.ApiStorage;
import appeng.core.features.registries.RegistryContainer;
import appeng.me.GridConnection;
import appeng.me.GridNode;
import appeng.util.Platform;
public class Api implements IAppEngApi
{
public static final Api instance = new Api();
private Api() {
}
// private MovableTileRegistry MovableRegistry = new MovableTileRegistry();
private RegistryContainer rc = new RegistryContainer();
private ApiStorage storageHelper = new ApiStorage();
public ApiPart partHelper = new ApiPart();
private Materials materials = new Materials();
private Items items = new Items();
private Blocks blocks = new Blocks();
private Parts parts = new Parts();
@Override
public IRegistryContainer registries()
{
return rc;
}
@Override
public Items items()
{
return items;
}
@Override
public Materials materials()
{
return materials;
}
@Override
public Blocks blocks()
{
return blocks;
}
@Override
public Parts parts()
{
return parts;
}
@Override
public IStorageHelper storage()
{
return storageHelper;
}
@Override
public IPartHelper partHelper()
{
return partHelper;
}
@Override
public IGridNode createGridNode(IGridBlock blk)
{
if ( Platform.isClient() )
throw new RuntimeException( "Grid Features are Server Side Only." );
return new GridNode( blk );
}
@Override
public IGridConnection createGridConnection(IGridNode a, IGridNode b)
{
return new GridConnection( a, b, ForgeDirection.UNKNOWN );
}
}
+169
View File
@@ -0,0 +1,169 @@
package appeng.core;
import net.minecraft.item.ItemStack;
import appeng.core.crash.CrashEnhancement;
import appeng.core.crash.CrashInfo;
import appeng.core.features.AEFeature;
import appeng.core.sync.AppEngClientPacketHandler;
import appeng.core.sync.AppEngServerPacketHandler;
import appeng.helpers.TickHandler;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationSide;
import appeng.server.AECommand;
import appeng.services.Profiler;
import appeng.services.VersionChecker;
import appeng.util.Platform;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
@Mod(modid = AppEng.modid, name = AppEng.name, version = Configuration.VERSION, dependencies = AppEng.dependencies)
@NetworkMod(clientSideRequired = true, serverSideRequired = true, clientPacketHandlerSpec = @SidedPacketHandler(channels = { Configuration.PACKET_CHANNEL }, packetHandler = AppEngClientPacketHandler.class), serverPacketHandlerSpec = @SidedPacketHandler(channels = (Configuration.PACKET_CHANNEL), packetHandler = AppEngServerPacketHandler.class))
public class AppEng
{
public final static String modid = "appliedenergistics2";
public final static String name = "Applied Energistics 2";
public static AppEng instance;
public final static String dependencies =
// a few mods, AE should load after, probably.
// required-after:AppliedEnergistics2API|all;
"after:gregtech_addon;after:Mekanism;after:IC2;after:ThermalExpansion;after:BuildCraft|Core;" +
// depend on version of forge used for build.
"required-after:Forge@[" // require forge.
+ net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion
+ net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
+ net.minecraftforge.common.ForgeVersion.buildVersion + ",)"; // buildVersion
public AppEng() {
instance = this;
for (CrashInfo ci : CrashInfo.values())
FMLCommonHandler.instance().registerCrashCallable( new CrashEnhancement( ci ) );
// detect funny obfuscation issues?
try
{
new ItemStack( 1, 1, 0 ).getItemDamage();
}
catch (Throwable t)
{
throw new Error( "AE2 is incompatible with this environment, please verify your using the correct version of AE2." );
}
}
private IntegrationRegistry integrationModules = new IntegrationRegistry( new Object[] {
/**
* Display Name, ModID ClassPostFix
*/
IntegrationSide.BOTH, "Industrial Craft 2", "IC2", "IC2", // IC2
IntegrationSide.BOTH, "Railcraft", "Railcraft", "RC", // RC
IntegrationSide.BOTH, "Thermal Expansion", "ThermalExpansion", "TE", // TE
IntegrationSide.BOTH, "Mystcraft", "Mystcraft", "Mystcraft", // MC
IntegrationSide.BOTH, "BuildCraft", "BuildCraft|Silicon", "BC", // BC
IntegrationSide.BOTH, "Greg Tech", "gregtech_addon", "GT", // GT
IntegrationSide.BOTH, "Universal Electricity", null, "UE", // UE
IntegrationSide.BOTH, "Logistics Pipes", "LogisticsPipes|Main", "LP", // LP
// IntegrationSide.CLIENT, "Inventory Tweaks", "", "InvTweaks",
IntegrationSide.BOTH, "Mine Factory Reloaded", "MineFactoryReloaded", "MFR", // MFR
IntegrationSide.BOTH, "Better Storage", "betterstorage", "BS", // BS
IntegrationSide.BOTH, "Factorization", "factorization", "FZ", // FZ
IntegrationSide.BOTH, "Forestry", "Forestry", "Forestry", // Forestry
IntegrationSide.BOTH, "Mekanism", "Mekanism", "Mekanism", // MeK
IntegrationSide.CLIENT, "Not Enought Items", "NotEnoughItems", "NEI", // Not Eneough Items
IntegrationSide.BOTH, "Forge MultiPart", "McMultipart", "FMP" } );
public boolean isIntegrationEnabled(String Name)
{
return integrationModules.isEnabled( Name );
}
public Object getIntegration(String Name)
{
return integrationModules.getInstance( Name );
}
@EventHandler
void PreInit(FMLPreInitializationEvent event)
{
AELog.info( "Starting ( PreInit )" );
Configuration.instance = new Configuration( event.getSuggestedConfigurationFile() );
if ( Platform.isClient() )
{
CreativeTab.init();
CommonHelper.proxy.init();
}
Registration.instance.PreInit( event );
if ( Configuration.instance.isFeatureEnabled( AEFeature.Profiler ) )
{
AELog.info( "Starting Profiler" );
(new Thread( Profiler.instance = new Profiler() )).start();
}
if ( Configuration.instance.isFeatureEnabled( AEFeature.VersionChecker ) )
{
AELog.info( "Starting VersionChecker" );
(new Thread( VersionChecker.instance = new VersionChecker() )).start();
}
AELog.info( "PreInit ( end )" );
}
@EventHandler
void Init(FMLInitializationEvent event)
{
AELog.info( "Init" );
Registration.instance.Init( event );
integrationModules.init();
AELog.info( "Init ( end )" );
}
@EventHandler
void PostInit(FMLPostInitializationEvent event)
{
AELog.info( "PostInit" );
Registration.instance.PostInit( event );
integrationModules.postinit();
Configuration.instance.save();
AELog.info( "PostInit ( end )" );
}
@EventHandler
public void serverStopping(FMLServerStoppingEvent event)
{
WorldSettings.getInstance().shutdown();
TickHandler.instance.shutdown();
}
@EventHandler
public void serverStarting(FMLServerStartingEvent evt)
{
WorldSettings.getInstance().init();
evt.registerServerCommand( new AECommand( evt.getServer() ) );
}
}
+27
View File
@@ -0,0 +1,27 @@
package appeng.core;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.packet.Packet;
import net.minecraft.world.World;
import appeng.block.AEBaseBlock;
import cpw.mods.fml.common.SidedProxy;
public abstract class CommonHelper
{
@SidedProxy(clientSide = "appeng.client.ClientHelper", serverSide = "appeng.server.ServerHelper")
public static CommonHelper proxy;
public abstract void init();
public abstract World getWorld();
public abstract void bindTileEntitySpecialRenderer(Class tile, AEBaseBlock blk);
public abstract List<EntityPlayer> getPlayers();
public abstract void sendToAllNearExcept(EntityPlayer p, double x, double y, double z, double dist, World w, Packet packet);
}
+184
View File
@@ -0,0 +1,184 @@
package appeng.core;
import java.io.File;
import java.util.EnumSet;
import appeng.api.config.CondenserOuput;
import appeng.api.config.PowerUnits;
import appeng.api.config.Settings;
import appeng.api.config.SortDir;
import appeng.api.config.SortOrder;
import appeng.api.config.YesNo;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigureableObject;
import appeng.core.features.AEFeature;
import appeng.core.features.AEFeatureHandler;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
public class Configuration extends net.minecraftforge.common.Configuration implements IConfigureableObject, IConfigManagerHost
{
public static Configuration instance;
public String latestVersion = VERSION;
public long latestTimeStamp = 0;
public static final String VERSION = "${version}";
public static final String CHANNEL = "${channel}";
public final static String PACKET_CHANNEL = "AE";
public IConfigManager settings = new ConfigManager( this );
public EnumSet<AEFeature> featureFlags = EnumSet.noneOf( AEFeature.class );
public int oresPerCluster = 4;
private double WirelessBaseCost = 8;
private double WirelessCostMultiplier = 1;
private double WirelessHighWirelessCount = 64;
private double WirelessBaseRange = 16;
private double WirelessBoosterRangeMultiplier = 1;
private double WirelessBoosterExp = 1.5;
public double wireless_getMaxRange(int boosters)
{
return WirelessBaseRange + WirelessBoosterRangeMultiplier * Math.pow( boosters, WirelessBoosterExp );
}
public double wireless_getPowerDrain(int boosters)
{
return WirelessBaseCost + WirelessCostMultiplier * Math.pow( boosters, 1 + boosters / WirelessHighWirelessCount );
}
public double spatialPowerScaler = 1.5;
public double spatialPowerMultiplier = 1500.0;
private int blkBaseNumber = 900;
private int blkItemNumber = 3841;
public String grinderOres[] = {
// Vanilla Items
"Obsidian", "EnderPearl", "Coal", "Iron", "Gold", "Charcoal",
// Common Mod Ores
"Copper", "Tin", "Silver", "Lead", "Bronze",
// Other Mod Ores
"Brass", "Platinum", "Nickel", "Invar", "Aluminium", "Electrum" };
public double oreDoublePercentage = 90.0;
public boolean enableEffects = true;
public boolean enableNetworkProfiler = true;
public Configuration(File f) {
super( f );
final double DEFAULT_BC_EXCHANGE = 5.0;
final double DEFAULT_UE_EXCHANGE = 5.0;
final double DEFAULT_IC2_EXCHANGE = 2.0;
final double DEFAULT_RTC_EXCHANGE = 1.0 / 11256.0;
final double DEFAULT_RF_EXCHANGE = 0.5;
PowerUnits.MJ.conversionRatio = get( "PowerInputRatios", "BuildCraft", DEFAULT_BC_EXCHANGE ).getDouble( DEFAULT_BC_EXCHANGE );
PowerUnits.KJ.conversionRatio = get( "PowerInputRatios", "UniversalElectricity", DEFAULT_UE_EXCHANGE ).getDouble( DEFAULT_UE_EXCHANGE );
PowerUnits.EU.conversionRatio = get( "PowerInputRatios", "IC2", DEFAULT_IC2_EXCHANGE ).getDouble( DEFAULT_IC2_EXCHANGE );
PowerUnits.WA.conversionRatio = get( "PowerInputRatios", "RotaryCraft", DEFAULT_RTC_EXCHANGE ).getDouble( DEFAULT_RTC_EXCHANGE );
PowerUnits.RF.conversionRatio = get( "PowerInputRatios", "ThermalExpansion", DEFAULT_RF_EXCHANGE ).getDouble( DEFAULT_RF_EXCHANGE );
CondenserOuput.MATTER_BALLS.requiredPower = get( "Condenser", "MatterBalls", 256 ).getInt( 256 );
CondenserOuput.SINGULARITY.requiredPower = get( "Condenser", "Singularity", 256000 ).getInt( 256000 );
grinderOres = get( "GrindStone", "grinderOres", grinderOres ).getStringList();
oreDoublePercentage = get( "GrindStone", "oreDoublePercentage", oreDoublePercentage ).getDouble( oreDoublePercentage );
enableEffects = get( "Client", "enableEffects", true ).getBoolean( true );
enableNetworkProfiler = get( "Server", "enableNetworkProfiler", true ).getBoolean( true );
// settings.registerSetting( Settings.SEARCH_MODS, YesNo.YES );
settings.registerSetting( Settings.SEARCH_TOOLTIPS, YesNo.YES );
settings.registerSetting( Settings.SORT_BY, SortOrder.NAME );
settings.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
for (AEFeature feature : AEFeature.values())
{
if ( feature.isVisible() )
{
if ( get( "Features." + feature.getCategory(), feature.name(), feature.defaultVaue() ).getBoolean( feature.defaultVaue() ) )
featureFlags.add( feature );
}
else
featureFlags.add( feature );
}
for (Enum e : settings.getSettings())
{
String Category = e.getClass().getSimpleName();
this.get( Category, e.name(), settings.getSetting( e ).name() );
}
if ( isFeatureEnabled( AEFeature.VersionChecker ) )
{
try
{
latestVersion = get( "VersionChecker", "LatestVersion", "" ).getString();
latestTimeStamp = Long.parseLong( get( "VersionChecker", "LatestTimeStamp", "" ).getString() );
}
catch (NumberFormatException err)
{
latestTimeStamp = 0;
}
}
}
@Override
public void updateSetting(Enum setting, Enum newValue)
{
for (Enum e : settings.getSettings())
{
String Category = e.getClass().getSimpleName();
this.get( Category, e.name(), settings.getSetting( e ).name() );
}
save();
}
@Override
public void save()
{
if ( isFeatureEnabled( AEFeature.VersionChecker ) )
{
get( "VersionChecker", "LatestVersion", latestVersion ).set( latestVersion );
get( "VersionChecker", "LatestTimeStamp", "" ).set( Long.toString( latestTimeStamp ) );
}
if ( hasChanged() )
super.save();
}
@Override
public IConfigManager getConfigManager()
{
return settings;
}
public boolean isFeatureEnabled(AEFeature f)
{
return featureFlags.contains( f );
}
public int getBlockID(Class c, String subname)
{
return getBlock( AEFeatureHandler.getName( c, subname ), blkBaseNumber++ ).getInt();
}
public int getItemID(Class c, String subname)
{
return getItem( AEFeatureHandler.getName( c, subname ), blkItemNumber++ ).getInt();
}
public boolean useTerminalUseLargeFont()
{
return false;
}
}
+30
View File
@@ -0,0 +1,30 @@
package appeng.core;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.util.Platform;
public final class CreativeTab extends CreativeTabs
{
public static CreativeTab instance = null;
public CreativeTab() {
super( "appliedenergistics2" );
if ( Platform.isClient() )
AELog.localization( "gui", "itemGroup." + getTabLabel() );
}
@Override
public ItemStack getIconItemStack()
{
return AEApi.instance().items().itemWirelessTerminal.stack( 1 );
}
public static void init()
{
instance = new CreativeTab();
}
}
+350
View File
@@ -0,0 +1,350 @@
package appeng.core;
import ic2.api.energy.tile.IEnergySink;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.IFluidHandler;
import appeng.api.AEApi;
import appeng.api.definitions.Blocks;
import appeng.api.definitions.Items;
import appeng.api.definitions.Materials;
import appeng.api.definitions.Parts;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.pathing.IPathingGrid;
import appeng.api.networking.spatial.ISpatialCache;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.util.AEItemDefinition;
import appeng.block.grindstone.BlockCrank;
import appeng.block.grindstone.BlockGrinder;
import appeng.block.mac.BlockContainmentWall;
import appeng.block.mac.BlockCraftingAccelerator;
import appeng.block.mac.BlockHeatVent;
import appeng.block.mac.BlockPatternProvider;
import appeng.block.misc.BlockCharger;
import appeng.block.misc.BlockCondenser;
import appeng.block.misc.BlockInscriber;
import appeng.block.misc.BlockInterface;
import appeng.block.misc.BlockNetworkEmitter;
import appeng.block.misc.BlockPartitionEditor;
import appeng.block.misc.BlockQuartzCrystalizer;
import appeng.block.misc.BlockQuartzTorch;
import appeng.block.misc.BlockTinyTNT;
import appeng.block.misc.BlockVibrationChamber;
import appeng.block.networking.BlockCableBus;
import appeng.block.networking.BlockController;
import appeng.block.networking.BlockCreativeEnergyCell;
import appeng.block.networking.BlockDenseEnergyCell;
import appeng.block.networking.BlockEnergyAcceptor;
import appeng.block.networking.BlockEnergyCell;
import appeng.block.networking.BlockWireless;
import appeng.block.qnb.BlockQuantumLinkChamber;
import appeng.block.qnb.BlockQuantumRing;
import appeng.block.solids.BlockMatrixFrame;
import appeng.block.solids.BlockQuartz;
import appeng.block.solids.BlockQuartzChiseled;
import appeng.block.solids.BlockQuartzGlass;
import appeng.block.solids.BlockQuartzLamp;
import appeng.block.solids.BlockQuartzPillar;
import appeng.block.solids.OreQuartz;
import appeng.block.solids.OreQuartzCharged;
import appeng.block.spatial.BlockSpatialIOPort;
import appeng.block.spatial.BlockSpatialPylon;
import appeng.block.storage.BlockChest;
import appeng.block.storage.BlockDrive;
import appeng.block.storage.BlockIOPort;
import appeng.core.features.AEFeature;
import appeng.core.features.IAEFeature;
import appeng.core.features.registries.entries.BasicCellHandler;
import appeng.core.features.registries.entries.CreativeCellHandler;
import appeng.core.localization.GuiText;
import appeng.core.localization.PlayerMessages;
import appeng.core.sync.GuiBridge;
import appeng.debug.ToolDebugCard;
import appeng.helpers.AETrading;
import appeng.helpers.PartPlacement;
import appeng.helpers.QuartzWorldGen;
import appeng.helpers.TickHandler;
import appeng.items.ItemEncodedPattern;
import appeng.items.materials.ItemMaterial;
import appeng.items.materials.MaterialType;
import appeng.items.parts.ItemFacade;
import appeng.items.parts.ItemPart;
import appeng.items.parts.PartType;
import appeng.items.storage.ItemBasicStorageCell;
import appeng.items.storage.ItemCreativeStorageCell;
import appeng.items.storage.ItemSpatialStorageCell;
import appeng.items.tools.ToolMemoryCard;
import appeng.items.tools.powered.ToolChargedStaff;
import appeng.items.tools.powered.ToolEntropyManipulator;
import appeng.items.tools.powered.ToolMassCannon;
import appeng.items.tools.powered.ToolWirelessTerminal;
import appeng.items.tools.quartz.ToolQuartzAxe;
import appeng.items.tools.quartz.ToolQuartzCuttingKnife;
import appeng.items.tools.quartz.ToolQuartzHoe;
import appeng.items.tools.quartz.ToolQuartzPickaxe;
import appeng.items.tools.quartz.ToolQuartzSpade;
import appeng.items.tools.quartz.ToolQuartzSword;
import appeng.items.tools.quartz.ToolQuartzWrench;
import appeng.me.cache.EnergyGridCache;
import appeng.me.cache.GridStorageCache;
import appeng.me.cache.P2PCache;
import appeng.me.cache.PathGridCache;
import appeng.me.cache.SpatialPylonCache;
import appeng.me.cache.TickManagerCache;
import appeng.me.storage.AEExternalHandler;
import appeng.recipes.ores.OreDictionaryHandler;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.common.registry.VillagerRegistry;
import cpw.mods.fml.relauncher.Side;
public class Registration
{
final public static Registration instance = new Registration();
public BiomeGenBase storageBiome;
private Registration() {
}
final private Multimap<AEFeature, Class> featuresToEntities = ArrayListMultimap.create();
public void PreInit(FMLPreInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register( OreDictionaryHandler.instance );
Items items = AEApi.instance().items();
Materials materials = AEApi.instance().materials();
Parts parts = AEApi.instance().parts();
Blocks blocks = AEApi.instance().blocks();
Class materialClass = materials.getClass();
for (MaterialType mat : MaterialType.values())
{
try
{
Field f = materialClass.getField( "material" + mat.name() );
f.set( materials, addFeature( ItemMaterial.class, mat ) );
}
catch (Throwable err)
{
AELog.severe( "Error creating material: " + mat.name() );
throw new RuntimeException( err );
}
}
Class partClass = parts.getClass();
for (PartType part : PartType.values())
{
try
{
Field f = partClass.getField( "part" + part.name() );
f.set( parts, addFeature( ItemPart.class, part ) );
}
catch (Throwable err)
{
AELog.severe( "Error creating part: " + part.name() );
throw new RuntimeException( err );
}
}
// very important block!
blocks.blockMultiPart = addFeature( BlockCableBus.class );
blocks.blockQuartzOre = addFeature( OreQuartz.class );
blocks.blockQuartzOreCharged = addFeature( OreQuartzCharged.class );
blocks.blockMatrixFrame = addFeature( BlockMatrixFrame.class );
blocks.blockQuartz = addFeature( BlockQuartz.class );
blocks.blockQuartzGlass = addFeature( BlockQuartzGlass.class );
blocks.blockQuartzVibrantGlass = addFeature( BlockQuartzLamp.class );
blocks.blockQuartzPiller = addFeature( BlockQuartzPillar.class );
blocks.blockQuartzChiseled = addFeature( BlockQuartzChiseled.class );
blocks.blockQuartzTorch = addFeature( BlockQuartzTorch.class );
blocks.blockCharger = addFeature( BlockCharger.class );
blocks.blockGrindStone = addFeature( BlockGrinder.class );
blocks.blockCrankHandle = addFeature( BlockCrank.class );
blocks.blockInscriber = addFeature( BlockInscriber.class );
blocks.blockWireless = addFeature( BlockWireless.class );
blocks.blockTinyTNT = addFeature( BlockTinyTNT.class );
blocks.blockQuartzCrystalizer = addFeature( BlockQuartzCrystalizer.class );
blocks.blockNetworkEmitter = addFeature( BlockNetworkEmitter.class );
blocks.blockPatternProvider = addFeature( BlockPatternProvider.class );
blocks.blockAssemblerFieldWall = addFeature( BlockContainmentWall.class );
blocks.blockHeatVent = addFeature( BlockHeatVent.class );
blocks.blockCraftingCPU = addFeature( BlockCraftingAccelerator.class );
blocks.blockQuantumRing = addFeature( BlockQuantumRing.class );
blocks.blockQuantumLink = addFeature( BlockQuantumLinkChamber.class );
blocks.blockSpatialPylon = addFeature( BlockSpatialPylon.class );
blocks.blockSpatialIOPort = addFeature( BlockSpatialIOPort.class );
blocks.blockController = addFeature( BlockController.class );
blocks.blockDrive = addFeature( BlockDrive.class );
blocks.blockChest = addFeature( BlockChest.class );
blocks.blockInterface = addFeature( BlockInterface.class );
blocks.blockPartitioner = addFeature( BlockPartitionEditor.class );
blocks.blockIOPort = addFeature( BlockIOPort.class );
blocks.blockCondenser = addFeature( BlockCondenser.class );
blocks.blockEnergyAcceptor = addFeature( BlockEnergyAcceptor.class );
blocks.blockVibrationChamber = addFeature( BlockVibrationChamber.class );
blocks.blockEnergyCell = addFeature( BlockEnergyCell.class );
blocks.blockEnergyCellDense = addFeature( BlockDenseEnergyCell.class );
blocks.blockEnergyCellCreative = addFeature( BlockCreativeEnergyCell.class );
items.itemEncodedAsemblerPattern = addFeature( ItemEncodedPattern.class );
items.itemCellCreative = addFeature( ItemCreativeStorageCell.class );
items.itemCell1k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell1kPart, 1 );
items.itemCell4k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell4kPart, 4 );
items.itemCell16k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell16kPart, 16 );
items.itemCell64k = addFeature( ItemBasicStorageCell.class, MaterialType.Cell64kPart, 64 );
items.itemSpatialCell2 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell2SpatialPart, 2 );
items.itemSpatialCell16 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell16SpatialPart, 16 );
items.itemSpatialCell128 = addFeature( ItemSpatialStorageCell.class, MaterialType.Cell128SpatialPart, 128 );
items.itemCertusQuartzKnife = addFeature( ToolQuartzCuttingKnife.class, AEFeature.CertusQuartzTools );
items.itemCertusQuartzWrench = addFeature( ToolQuartzWrench.class, AEFeature.CertusQuartzTools );
items.itemCertusQuartzAxe = addFeature( ToolQuartzAxe.class, AEFeature.CertusQuartzTools );
items.itemCertusQuartzHoe = addFeature( ToolQuartzHoe.class, AEFeature.CertusQuartzTools );
items.itemCertusQuartzPick = addFeature( ToolQuartzPickaxe.class, AEFeature.CertusQuartzTools );
items.itemCertusQuartzShovel = addFeature( ToolQuartzSpade.class, AEFeature.CertusQuartzTools );
items.itemCertusQuartzSword = addFeature( ToolQuartzSword.class, AEFeature.CertusQuartzTools );
items.itemNetherQuartzKnife = addFeature( ToolQuartzCuttingKnife.class, AEFeature.NetherQuartzTools );
items.itemNetherQuartzWrench = addFeature( ToolQuartzWrench.class, AEFeature.NetherQuartzTools );
items.itemNetherQuartzAxe = addFeature( ToolQuartzAxe.class, AEFeature.NetherQuartzTools );
items.itemNetherQuartzHoe = addFeature( ToolQuartzHoe.class, AEFeature.NetherQuartzTools );
items.itemNetherQuartzPick = addFeature( ToolQuartzPickaxe.class, AEFeature.NetherQuartzTools );
items.itemNetherQuartzShovel = addFeature( ToolQuartzSpade.class, AEFeature.NetherQuartzTools );
items.itemNetherQuartzSword = addFeature( ToolQuartzSword.class, AEFeature.NetherQuartzTools );
items.itemMassCannon = addFeature( ToolMassCannon.class );
items.itemMemoryCard = addFeature( ToolMemoryCard.class );
items.itemChargedStaff = addFeature( ToolChargedStaff.class );
items.itemEntropyManipulator = addFeature( ToolEntropyManipulator.class );
items.itemWirelessTerminal = addFeature( ToolWirelessTerminal.class );
items.itemFacade = addFeature( ItemFacade.class );
addFeature( ToolDebugCard.class );
}
private AEItemDefinition addFeature(Class c, Object... Args)
{
try
{
java.lang.reflect.Constructor[] con = c.getConstructors();
Object obj = null;
for (Constructor conItem : con)
{
if ( conItem.getParameterTypes().length == Args.length )
obj = conItem.newInstance( Args );
}
if ( obj instanceof IAEFeature )
{
IAEFeature feature = (IAEFeature) obj;
for (AEFeature f : feature.feature().getFeatures())
featuresToEntities.put( f, c );
feature.feature().register();
return feature.feature();
}
else if ( obj == null )
throw new RuntimeException( "No valid constructor found." );
else
throw new RuntimeException( "Non AE Feature Registered" );
}
catch (Throwable e)
{
AELog.severe( "Error with Feature: " + c.getName() );
throw new RuntimeException( e );
}
}
public void Init(FMLInitializationEvent event)
{
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIEnergySink", IEnergySink.class );
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerISidedInventory", ISidedInventory.class );
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIPowerEmitter", IPowerEmitter.class );
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIPowerReceptor", IPowerReceptor.class );
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIFluidHandler", IFluidHandler.class );
TickRegistry.registerTickHandler( TickHandler.instance, Side.SERVER );
TickRegistry.registerTickHandler( TickHandler.instance, Side.CLIENT );
MinecraftForge.EVENT_BUS.register( TickHandler.instance );
MinecraftForge.EVENT_BUS.register( new PartPlacement() );
AEApi.instance().registries().gridCache().registerGridCache( ITickManager.class, TickManagerCache.class );
AEApi.instance().registries().gridCache().registerGridCache( IEnergyGrid.class, EnergyGridCache.class );
AEApi.instance().registries().gridCache().registerGridCache( IPathingGrid.class, PathGridCache.class );
AEApi.instance().registries().gridCache().registerGridCache( IStorageGrid.class, GridStorageCache.class );
AEApi.instance().registries().gridCache().registerGridCache( P2PCache.class, P2PCache.class );
AEApi.instance().registries().gridCache().registerGridCache( ISpatialCache.class, SpatialPylonCache.class );
AEApi.instance().registries().externalStorage().addExternalStorageInterface( new AEExternalHandler() );
AEApi.instance().registries().cell().addCellHandler( new BasicCellHandler() );
AEApi.instance().registries().cell().addCellHandler( new CreativeCellHandler() );
NetworkRegistry.instance().registerGuiHandler( AppEng.instance, GuiBridge.GUI_Handler );
}
public void PostInit(FMLPostInitializationEvent event)
{
// add to localizaiton..
PlayerMessages.values();
GuiText.values();
Api.instance.partHelper.initFMPSupport();
((BlockCableBus) AEApi.instance().blocks().blockMultiPart.block()).setupTile();
if ( Configuration.instance.isFeatureEnabled( AEFeature.ChestLoot ) )
{
ChestGenHooks d = ChestGenHooks.getInfo( ChestGenHooks.MINESHAFT_CORRIDOR );
d.addItem( new WeightedRandomChestContent( AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), 1, 4, 2 ) );
d.addItem( new WeightedRandomChestContent( AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ), 1, 4, 2 ) );
}
// add villager trading to black smiths for a few basic materials
if ( Configuration.instance.isFeatureEnabled( AEFeature.VillagerTrading ) )
VillagerRegistry.instance().registerVillageTradeHandler( 3, new AETrading() );
if ( Configuration.instance.isFeatureEnabled( AEFeature.CertusQuartzWorldGen ) )
GameRegistry.registerWorldGenerator( new QuartzWorldGen() );
}
}
+144
View File
@@ -0,0 +1,144 @@
package appeng.core;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.DimensionManager;
import appeng.api.util.WorldCoord;
import appeng.me.GridStorage;
import appeng.me.GridStorageSearch;
import cpw.mods.fml.common.network.Player;
public class WorldSettings extends Configuration
{
private static WorldSettings instance;
long lastGridStorage = 0;
public WorldSettings(File f) {
super( f );
try
{
lastGridStorage = Long.parseLong( get( "Counters", "lastGridStorage", 0 ).getString() );
}
catch (NumberFormatException err)
{
lastGridStorage = 0;
}
}
public static WorldSettings getInstance()
{
if ( instance == null )
{
File f = DimensionManager.getWorld( 0 ).getSaveHandler().getMapFileFromName( "AppEng" );
instance = new WorldSettings( f );
}
return instance;
}
public void sendToPlayer(Player player)
{
}
public void init()
{
save();
}
public void shutdown()
{
save();
instance = null;
}
private WeakHashMap<GridStorageSearch, WeakReference<GridStorageSearch>> loadedStorage = new WeakHashMap();
public WorldCoord getStoredSize(int dim)
{
int x = get( "StorageCell" + dim, "scaleX", 0 ).getInt();
int y = get( "StorageCell" + dim, "scaleY", 0 ).getInt();
int z = get( "StorageCell" + dim, "scaleZ", 0 ).getInt();
return new WorldCoord( x, y, z );
}
public void setStoredSize(int dim, int targetX, int targetY, int targetZ)
{
get( "StorageCell" + dim, "scaleX", 0 ).set( targetX );
get( "StorageCell" + dim, "scaleY", 0 ).set( targetY );
get( "StorageCell" + dim, "scaleZ", 0 ).set( targetZ );
save();
}
/**
* lazy loading, can load any id, even ones that don't exist anymore.
*
* @param storageID
* @return
*/
public GridStorage getGridStorage(long storageID)
{
GridStorageSearch gss = new GridStorageSearch( storageID );
WeakReference<GridStorageSearch> result = loadedStorage.get( gss );
if ( result == null || result.get() == null )
{
String Data = get( "gridstorage", "" + storageID, "" ).getString();
GridStorage thisStorage = new GridStorage( Data, storageID, gss );
gss.gridStorage = new WeakReference<GridStorage>( thisStorage );
loadedStorage.put( gss, new WeakReference<GridStorageSearch>( gss ) );
return thisStorage;
}
return result.get().gridStorage.get();
}
/**
* create a new storage
*/
public GridStorage getNewGridStorage()
{
long storageID = nextGridStorage();
GridStorageSearch gss = new GridStorageSearch( storageID );
GridStorage newStorage = new GridStorage( storageID, gss );
gss.gridStorage = new WeakReference<GridStorage>( newStorage );
loadedStorage.put( gss, new WeakReference<GridStorageSearch>( gss ) );
return newStorage;
}
public void destroyGridStorage(long id)
{
this.getCategory( "gridstorage" ).remove( "" + id );
}
@Override
public void save()
{
// populate new data
for (GridStorageSearch gs : loadedStorage.keySet())
{
GridStorage thisStorage = gs.gridStorage.get();
if ( thisStorage != null && thisStorage.getGrid() != null && !thisStorage.getGrid().isEmpty() )
{
String value = thisStorage.getValue();
get( "gridstorage", "" + thisStorage.getID(), value ).set( value );
}
}
// save to files
if ( hasChanged() )
super.save();
}
private long nextGridStorage()
{
long r = lastGridStorage++;
get( "Counters", "lastGridStorage", lastGridStorage ).set( Long.toString( lastGridStorage ) );
return r;
}
}
+344
View File
@@ -0,0 +1,344 @@
package appeng.core.api;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.commons.RemappingClassAdapter;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import appeng.api.parts.IPartItem;
import appeng.api.parts.IPartHelper;
import appeng.api.parts.LayerBase;
import appeng.client.render.BusRenderer;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.helpers.PartPlacement;
import appeng.integration.abstraction.IFMP;
import appeng.tile.networking.TileCableBus;
import appeng.util.Platform;
import com.google.common.base.Joiner;
public class ApiPart implements IPartHelper
{
int classNum = 1;
HashMap<String, Class> TileImplementations = new HashMap();
HashMap<String, ClassNode> readerCache = new HashMap();
HashMap<Class, String> interfaces2Layer = new HashMap();
HashMap<String, Class> roots = new HashMap();
List<String> desc = new LinkedList();
public void initFMPSupport()
{
for (Class layerInterface : interfaces2Layer.keySet())
{
if ( AppEng.instance.isIntegrationEnabled( "FMP" ) )
((IFMP) AppEng.instance.getIntegration( "FMP" )).registerPassThru( layerInterface );
}
}
private Class loadClass(String Name, byte[] b)
{
// override classDefine (as it is protected) and define the class.
Class clazz = null;
try
{
ClassLoader loader = getClass().getClassLoader();// ClassLoader.getSystemClassLoader();
Class root = ClassLoader.class;
Class cls = loader.getClass();
java.lang.reflect.Method defineClassMethod = root.getDeclaredMethod( "defineClass",
new Class[] { String.class, byte[].class, int.class, int.class } );
java.lang.reflect.Method runTransformersMethod = cls
.getDeclaredMethod( "runTransformers", new Class[] { String.class, String.class, byte[].class } );
runTransformersMethod.setAccessible( true );
defineClassMethod.setAccessible( true );
try
{
Object[] argsA = new Object[] { Name, Name, b };
b = (byte[]) runTransformersMethod.invoke( loader, argsA );
Object[] args = new Object[] { Name, b, new Integer( 0 ), new Integer( b.length ) };
clazz = (Class) defineClassMethod.invoke( loader, args );
}
finally
{
runTransformersMethod.setAccessible( false );
defineClassMethod.setAccessible( false );
}
}
catch (Exception e)
{
e.printStackTrace();
System.exit( 1 );
}
return clazz;
}
public ClassNode getReader(String name)
{
// if ( readerCache.get( name ) != null )
// return readerCache.get( name );
ClassReader cr;
try
{
String path = "/" + name.replace( ".", "/" ) + ".class";
InputStream is = getClass().getResourceAsStream( path );
cr = new ClassReader( is );
ClassNode cn = new ClassNode();
cr.accept( cn, ClassReader.EXPAND_FRAMES );
// readerCache.put( name, cn );
return cn;
}
catch (Throwable e)
{
e.printStackTrace();
}
return null;
}
public Class getCombinedInstance(String base)// , CableBusContainer cbc)
{
/*
* List<String> desc = new LinkedList(); for (ForgeDirection side : ForgeDirection.values()) { IBusPart part =
* cbc.getPart( side ); if ( part != null ) { for (Class c : interfaces2Layer.keySet()) { if ( c.isInstance(
* part ) ) desc.add( interfaces2Layer.get( c ).getName() ); } } }
*/
if ( desc.size() == 0 )
{
try
{
return Class.forName( base );
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
}
String description = base + ":" + Joiner.on( ";" ).skipNulls().join( desc.iterator() );
if ( TileImplementations.get( description ) != null )
{
try
{
return TileImplementations.get( description );
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
}
String f = base;// TileCableBus.class.getName();
String Addendum = "";
try
{
Addendum = Class.forName( base ).getSimpleName();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
Class myCLass;
try
{
myCLass = Class.forName( f );
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
String path = f;
for (String name : desc)
{
path = path + ";" + name;
try
{
myCLass = getClassByDesc( Addendum, path, f, interfaces2Layer.get( Class.forName( name ) ) );
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
f = myCLass.getName();
}
TileImplementations.put( description, myCLass );
try
{
return myCLass;
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
}
class DefaultPackageClassNameRemapper extends Remapper
{
public HashMap<String, String> inputOutput = new HashMap<String, String>();
@Override
public String map(String typeName)
{
String o = inputOutput.get( typeName );
if ( o == null )
return typeName;
return o;
}
}
public Class getClassByDesc(String Addendum, String fullPath, String root, String next)
{
if ( roots.get( fullPath ) != null )
return roots.get( fullPath );
ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS );
ClassNode n = getReader( next );
String originalName = n.name;
try
{
n.name = n.name + "_" + Addendum;
n.superName = Class.forName( root ).getName().replace( ".", "/" );
}
catch (Throwable t)
{
t.printStackTrace();
}
for (MethodNode mn : n.methods)
{
Iterator<AbstractInsnNode> i = mn.instructions.iterator();
while (i.hasNext())
{
processNode( i.next(), n.superName );
}
}
DefaultPackageClassNameRemapper remapper = new DefaultPackageClassNameRemapper();
remapper.inputOutput.put( "appeng/api/parts/LayerBase", n.superName );
remapper.inputOutput.put( originalName, n.name );
n.accept( new RemappingClassAdapter( cw, remapper ) );
// n.accept( cw );
// n.accept( new TraceClassVisitor( new PrintWriter( System.out ) ) );
byte[] barray = cw.toByteArray();
int size = barray.length;
Class nclass = loadClass( n.name.replace( "/", "." ), barray );
try
{
Object fish = nclass.newInstance();
Class rootC = Class.forName( root );
boolean bads = false;
if ( !rootC.isInstance( fish ) )
{
bads = true;
AELog.severe( "Error, Expected layer to implement " + root + " did not." );
}
if ( fish instanceof LayerBase )
{
bads = true;
AELog.severe( "Error, Expected layer to NOT implement LayerBase but it DID." );
}
if ( !(fish instanceof TileCableBus) )
{
bads = true;
AELog.severe( "Error, Expected layer to implement TileCableBus did not." );
}
if ( !(fish instanceof TileEntity) )
{
bads = true;
AELog.severe( "Error, Expected layer to implement TileEntity did not." );
}
if ( !bads )
{
AELog.info( "Layer: " + n.name + " loaded successfully - " + size + " bytes" );
}
}
catch (Throwable t)
{
AELog.severe( "Layer: " + n.name + " Failed." );
t.printStackTrace();
}
roots.put( fullPath, nclass );
return nclass;
}
private void processNode(AbstractInsnNode next, String nePar)
{
if ( next instanceof MethodInsnNode )
{
MethodInsnNode min = (MethodInsnNode) next;
if ( min.owner.equals( "appeng/api/parts/LayerBase" ) )
{
min.owner = nePar;
}
}
}
@Override
public void setItemBusRenderer(IPartItem i)
{
if ( Platform.isClient() && i instanceof Item )
MinecraftForgeClient.registerItemRenderer( ((Item) i).itemID, BusRenderer.instance );
}
@Override
public boolean placeBus(ItemStack is, int x, int y, int z, int side, EntityPlayer player, World w)
{
return PartPlacement.place( is, x, y, z, side, player, w, PartPlacement.PlaceType.PLACE_ITEM, 0 );
}
@Override
public boolean registerNewLayer(String layer, Class<?> layerInterface)
{
if ( interfaces2Layer.get( layerInterface ) == null )
{
desc.add( layerInterface.getName() );
interfaces2Layer.put( layerInterface, layer );
}
else
AELog.info( "Layer " + layer + " not registered, " + layerInterface.getName() + " aready has a layer." );
return false;
}
}
+34
View File
@@ -0,0 +1,34 @@
package appeng.core.api;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.storage.IStorageHelper;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.util.item.AEFluidStack;
import appeng.util.item.AEItemStack;
import appeng.util.item.ItemList;
public class ApiStorage implements IStorageHelper
{
@Override
public IAEItemStack createItemStack(ItemStack is)
{
return AEItemStack.create( is );
}
@Override
public IAEFluidStack createFluidStack(FluidStack is)
{
return AEFluidStack.create( is );
}
@Override
public IItemList createItemList()
{
return new ItemList();
}
}
+50
View File
@@ -0,0 +1,50 @@
package appeng.core.crash;
import appeng.core.Configuration;
import appeng.integration.IntegrationRegistry;
import cpw.mods.fml.common.ICrashCallable;
public class CrashEnhancement implements ICrashCallable
{
final CrashInfo Output;
public CrashEnhancement(CrashInfo ci) {
Output = ci;
}
@Override
public String call() throws Exception
{
switch (Output)
{
case MOD_VERSION:
return Configuration.CHANNEL + " " + Configuration.VERSION + " for Forge "
+ net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion
+ net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
+ net.minecraftforge.common.ForgeVersion.buildVersion;
case INTEGRATION:
if ( IntegrationRegistry.instance == null )
return "N/A";
return IntegrationRegistry.instance.getStatus();
}
return "UNKNOWN_VALUE";
}
@Override
public String getLabel()
{
switch (Output)
{
case MOD_VERSION:
return "AE2 Version";
case INTEGRATION:
return "AE2 Integration";
}
return "AE2_UNKNOWN";
}
}
+6
View File
@@ -0,0 +1,6 @@
package appeng.core.crash;
public enum CrashInfo
{
MOD_VERSION, INTEGRATION
}
+75
View File
@@ -0,0 +1,75 @@
package appeng.core.features;
public enum AEFeature
{
Core(null), // stuff that has no reason for ever being turned off, or that
// is just flat out required by tons of
// important stuff.
CertusQuartzWorldGen("World"),
DecorativeLights("DecorativeLights"), DecorativeQuartzBlocks("World"),
GrindStone("World"), Flour("World"), Inscriber("World"),
ChestLoot("World"), VillagerTrading("World"),
TinyTNT("World"),
PoweredTools("ToolsClassifications"),
CertusQuartzTools("ToolsClassifications"),
NetherQuartzTools("ToolsClassifications"),
QuartzHoe("Tools"), QuartzSpade("Tools"), QuartzSword("Tools"), QuartzPickaxe("Tools"), QuartzAxe("Tools"), QuartzKnife("Tools"), QuartzWrench("Tools"),
ChargedStaff("Tools"), EntropyManipulator("Tools"), MatterCannon("Tools"), WirelessAccessTerminal("Tools"),
PowerGen("NetworkFeatures"),
Crafting("NetworkFeatures"), MolecularAssembler("NetworkFeatures"), SpatialIO("NetworkFeatures"), QuantumNetworkBridge("NetworkFeatures"),
LevelEmiter("NetworkBuses"), CraftingTerminal("NetworkBuses"), StorageMonitor("NetworkBuses"), P2PTunnel("NetworkBuses"), FormationPlane("NetworkBuses"), AnnihilationPlane(
"NetworkBuses"), ImportBus("NetworkBuses"), ExportBus("NetworkBuses"), StorageBus("NetworkBuses"), PartConversionMonitor("NetworkBuses"),
StorageCells("Storage"), MEChest("Storage"), MEDrive("Storage"), IOPort("Storage"),
DenseEnergyCells("HigherCapacity"), DenseCables("HigherCapacity"),
P2PTunnelME("P2PTunnels"), P2PTunnelItems("P2PTunnels"), P2PTunnelRedstone("P2PTunnels"), P2PTunnelEU("P2PTunnels"), P2PTunnelMJ("P2PTunnels"), P2PTunnelLiquids("P2PTunnels"),
MassCannonBlockDamage("BlockFeatures"), TinyTNTBlockDamage("BlockFeatures"), Facades("Facades"),
DuplicateItems("Misc", false), Profiler("Services"), VersionChecker("Services"), Debug("Misc"), Creative("Misc");
String Category;
boolean visible = true;
boolean defValue = true;
private AEFeature(String cat) {
Category = cat;
visible = !this.name().equals( "Core" );
}
private AEFeature(String cat, boolean defv) {
this( cat );
defValue = defv;
}
public String getCategory()
{
return Category;
}
public Boolean defaultVaue()
{
return defValue;
}
public Boolean isVisible()
{
return visible;
}
}
+164
View File
@@ -0,0 +1,164 @@
package appeng.core.features;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.util.AEItemDefinition;
import appeng.block.AEBaseBlock;
import appeng.block.AEBaseItemBlock;
import appeng.core.AELog;
import appeng.core.CommonHelper;
import appeng.core.Configuration;
import appeng.core.CreativeTab;
import appeng.util.Platform;
import cpw.mods.fml.common.registry.GameRegistry;
public class AEFeatureHandler implements AEItemDefinition
{
private final EnumSet<AEFeature> myFeatures;
private final String subname;
private IAEFeature obj;
private Item ItemData;
private Block BlockData;
private ItemStack StackData;
public AEFeatureHandler(EnumSet<AEFeature> featureSet, IAEFeature _obj, String _subname) {
myFeatures = featureSet;
obj = _obj;
subname = _subname;
}
public void register()
{
if ( isFeatureAvailable() )
{
if ( obj instanceof Item )
initItem( (Item) obj );
if ( obj instanceof Block )
initBlock( (Block) obj );
}
}
public static String getName(Class o, String subname)
{
String name = o.getSimpleName();
if ( subname != null )
{
// simple hack to allow me to do get nice names for these without
// mode code outside of AEBaseItem
if ( subname.equals( "CertusQuartzTools" ) )
return name.replace( "Quartz", "CertusQuartz" );
if ( subname.equals( "NetherQuartzTools" ) )
return name.replace( "Quartz", "NetherQuartz" );
name += "." + subname;
}
return name;
}
private void initItem(Item i)
{
ItemData = i;
StackData = new ItemStack( i );
String name = getName( i.getClass(), subname );
i.setTextureName( "appliedenergistics2:" + name );
i.setCreativeTab( CreativeTab.instance );
i.setUnlocalizedName( /* "item." */"appliedenergistics2." + name );
GameRegistry.registerItem( i, "item." + name );
AELog.localization( "item", i.getUnlocalizedName() );
}
private void initBlock(Block b)
{
BlockData = b;
StackData = new ItemStack( b );
String name = getName( b.getClass(), subname );
b.setCreativeTab( CreativeTab.instance );
b.setUnlocalizedName( /* "tile." */"appliedenergistics2." + name );
b.setTextureName( "appliedenergistics2:" + name );
if ( Platform.isClient() && BlockData instanceof AEBaseBlock )
{
AEBaseBlock bb = (AEBaseBlock) b;
CommonHelper.proxy.bindTileEntitySpecialRenderer( bb.getTileEntityClass(), bb );
}
Class itemBlock = AEBaseItemBlock.class;
if ( b instanceof AEBaseBlock )
itemBlock = ((AEBaseBlock) b).getItemBlockClass();
GameRegistry.registerBlock( b, itemBlock, "tile." + name );
AELog.localization( "block", b.getUnlocalizedName() );
}
public EnumSet<AEFeature> getFeatures()
{
return myFeatures.clone();
}
public boolean isFeatureAvailable()
{
boolean enabled = true;
for (AEFeature f : myFeatures)
enabled = enabled && Configuration.instance.isFeatureEnabled( f );
return enabled;
}
@Override
public Block block()
{
return BlockData;
}
@Override
public Class<? extends TileEntity> entity()
{
if ( BlockData instanceof AEBaseBlock )
{
AEBaseBlock bb = (AEBaseBlock) BlockData;
return bb.getTileEntityClass();
}
return null;
}
@Override
public Item item()
{
return ItemData;
}
@Override
public ItemStack stack(int stackSize)
{
if ( isFeatureAvailable() )
{
ItemStack rv = StackData.copy();
rv.stackSize = stackSize;
return rv;
}
return null;
}
@Override
public boolean sameAs(ItemStack is)
{
if ( isFeatureAvailable() )
return Platform.isSameItemType( is, StackData );
return false;
}
}
+8
View File
@@ -0,0 +1,8 @@
package appeng.core.features;
public interface IAEFeature
{
public AEFeatureHandler feature();
}
@@ -0,0 +1,68 @@
package appeng.core.features.registries;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.ICellRegistry;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
public class CellRegistry implements ICellRegistry
{
List<ICellHandler> handlers;
public CellRegistry() {
handlers = new ArrayList();
}
@Override
public void addCellHandler(ICellHandler h)
{
if ( h != null )
handlers.add( h );
}
@Override
public boolean isCellHandled(ItemStack is)
{
if ( is == null )
return false;
for (ICellHandler ch : handlers)
if ( ch.isCell( is ) )
return true;
return false;
}
@Override
public ICellHandler getHander(ItemStack is)
{
if ( is == null )
return null;
for (ICellHandler ch : handlers)
{
if ( ch.isCell( is ) )
{
return ch;
}
}
return null;
}
@Override
public IMEInventoryHandler getCellInventory(ItemStack is, StorageChannel chan)
{
if ( is == null )
return null;
for (ICellHandler ch : handlers)
{
if ( ch.isCell( is ) )
{
return ch.getCellInventory( is, chan );
}
}
return null;
}
}
@@ -0,0 +1,38 @@
package appeng.core.features.registries;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import appeng.api.storage.IExternalStorageHandler;
import appeng.api.storage.IExternalStorageRegistry;
import appeng.api.storage.StorageChannel;
public class ExternalStorageRegistry implements IExternalStorageRegistry
{
List<IExternalStorageHandler> Handlers;
public ExternalStorageRegistry() {
Handlers = new ArrayList();
}
@Override
public IExternalStorageHandler getHandler(TileEntity te, ForgeDirection d, StorageChannel chan)
{
for (IExternalStorageHandler x : Handlers)
{
if ( x.canHandle( te, d, chan ) )
return x;
}
return null;
}
@Override
public void addExternalStorageInterface(IExternalStorageHandler ei)
{
Handlers.add( ei );
}
}
@@ -0,0 +1,46 @@
package appeng.core.features.registries;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridCache;
import appeng.api.networking.IGridCacheRegistry;
import appeng.core.AELog;
public class GridCacheRegistry implements IGridCacheRegistry
{
final private HashMap<Class<? extends IGridCache>, Class<? extends IGridCache>> caches = new HashMap();
@Override
public void registerGridCache(Class<? extends IGridCache> iface, Class<? extends IGridCache> implementation)
{
if ( iface.isAssignableFrom( implementation ) )
caches.put( iface, implementation );
else
throw new RuntimeException( "Invalid setup, grid cache must either be the same class, or an interface that the implementation implements" );
}
@Override
public HashMap<Class<? extends IGridCache>, IGridCache> createCacheInstance(IGrid g)
{
HashMap<Class<? extends IGridCache>, IGridCache> map = new HashMap();
for (Class<? extends IGridCache> iface : caches.keySet())
{
try
{
Constructor<? extends IGridCache> c = caches.get( iface ).getConstructor( IGrid.class );
map.put( iface, c.newInstance( g ) );
}
catch (Throwable e)
{
AELog.severe( "Grid Caches must have a constructor with IGrid as the single param." );
throw new RuntimeException( e );
}
}
return map;
}
}
@@ -0,0 +1,227 @@
package appeng.core.features.registries;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import appeng.api.features.IGrinderEntry;
import appeng.api.features.IGrinderRegistry;
import appeng.core.AELog;
import appeng.core.Configuration;
import appeng.core.features.registries.entries.AppEngGrinderRecipe;
import appeng.recipes.ores.IOreListener;
import appeng.recipes.ores.OreDictionaryHandler;
import appeng.util.Platform;
public class GrinderRecipeManager implements IGrinderRegistry, IOreListener
{
public List<IGrinderEntry> RecipeList;
private ItemStack copy(ItemStack is)
{
if ( is != null )
return is.copy();
return null;
}
public GrinderRecipeManager() {
RecipeList = new ArrayList();
addOre( "Gold", new ItemStack( Block.oreGold ) );
addOre( "Iron", new ItemStack( Block.oreIron ) );
addIngot( "Gold", new ItemStack( Item.ingotGold ) );
addIngot( "Iron", new ItemStack( Item.ingotIron ) );
addOre( "Obsidian", new ItemStack( Block.obsidian ) );
addOre( "EnderPearl", new ItemStack( Item.enderPearl ) );
addOre( "Coal", new ItemStack( Item.coal ) );
addOre( "Charcoal", new ItemStack( Item.coal, 1, 1 ) );
OreDictionaryHandler.instance.observe( this );
}
@Override
public List<IGrinderEntry> getRecipes()
{
log( "API - getRecipes" );
return RecipeList;
}
@Override
public void addRecipe(ItemStack in, ItemStack out, int cost)
{
if ( in == null || out == null )
{
log( "Invalid Grinder Recipe Specified." );
return;
}
log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out ) + " for "
+ cost );
RecipeList.add( new AppEngGrinderRecipe( copy( in ), copy( out ), cost ) );
}
@Override
public void addRecipe(ItemStack in, ItemStack out, ItemStack optional, float chance, int cost)
{
if ( in == null || (optional == null && out == null) )
{
log( "Invalid Grinder Recipe Specified." );
return;
}
log( "Allow Grinding of " + Platform.getItemDisplayName( in ) + " to " + Platform.getItemDisplayName( out )
+ " with optional " + Platform.getItemDisplayName( optional ) + " for " + cost );
RecipeList.add( new AppEngGrinderRecipe( copy( in ), copy( out ), copy( optional ), chance, cost ) );
}
@Override
public IGrinderEntry getRecipeForInput(ItemStack input)
{
log( "Looking up recipe for " + Platform.getItemDisplayName( input ) );
if ( input != null )
{
for (IGrinderEntry r : RecipeList)
{
if ( Platform.isSameItem( input, r.getInput() ) )
{
log( "Recipe for " + input.getUnlocalizedName() + " found " + Platform.getItemDisplayName( r.getOutput() ) );
return r;
}
}
log( "Count not find recipe for " + Platform.getItemDisplayName( input ) );
}
return null;
}
public void log(String o)
{
AELog.grinder( o );
}
private int getDustToOreRatio(String name)
{
if ( name.equals( "Obsidian" ) )
return 1;
if ( name.equals( "EnderPearl" ) )
return 1;
if ( name.equals( "Charcoal" ) )
return 1;
if ( name.equals( "Coal" ) )
return 1;
if ( name.contains( "Quartz" ) )
return 1;
return 2;
}
public Map<ItemStack, String> Ores = new HashMap<ItemStack, String>();
public Map<ItemStack, String> Ingots = new HashMap<ItemStack, String>();
public Map<String, ItemStack> Dusts = new HashMap<String, ItemStack>();
private void addOre(String name, ItemStack item)
{
if ( item == null )
return;
log( "Adding Ore - " + name + " : " + Platform.getItemDisplayName( item ) );
Ores.put( item, name );
if ( Dusts.containsKey( name ) )
{
ItemStack is = Dusts.get( name ).copy();
int ratio = getDustToOreRatio( name );
if ( ratio > 1 )
{
ItemStack extra = is.copy();
extra.stackSize = ratio - 1;
addRecipe( item, is, extra, (float) (Configuration.instance.oreDoublePercentage / 100.0), 8 );
}
else
addRecipe( item, is, 8 );
}
}
private void addIngot(String name, ItemStack item)
{
if ( item == null )
return;
log( "Adding Ingot - " + name + " : " + Platform.getItemDisplayName( item ) );
Ingots.put( item, name );
if ( Dusts.containsKey( name ) )
{
addRecipe( item, Dusts.get( name ), 4 );
}
}
private void addDust(String name, ItemStack item)
{
if ( item == null )
return;
if ( Dusts.containsKey( name ) )
{
log( "Rejecting Dust - " + name + " : " + Platform.getItemDisplayName( item ) );
return;
}
log( "Adding Dust - " + name + " : " + Platform.getItemDisplayName( item ) );
Dusts.put( name, item );
for (Entry<ItemStack, String> d : Ores.entrySet())
if ( name.equals( d.getValue() ) )
{
ItemStack is = item.copy();
is.stackSize = 1;
int ratio = getDustToOreRatio( name );
if ( ratio > 1 )
{
ItemStack extra = is.copy();
extra.stackSize = ratio - 1;
addRecipe( d.getKey(), is, extra, (float) (Configuration.instance.oreDoublePercentage / 100.0), 8 );
}
else
addRecipe( d.getKey(), is, 8 );
}
for (Entry<ItemStack, String> d : Ingots.entrySet())
if ( name.equals( d.getValue() ) )
addRecipe( d.getKey(), item, 4 );
}
@Override
public void oreRegistered(String Name, ItemStack item)
{
if ( Name.startsWith( "ore" ) || Name.startsWith( "ingot" ) || Name.startsWith( "dust" ) )
{
for (String ore : Configuration.instance.grinderOres)
{
if ( ore.equals( "CertusQuartz" ) )
continue;
if ( ore.equals( "NetherQuartz" ) )
continue;
if ( Name.equals( "ore" + ore ) )
{
addOre( ore, item );
}
else if ( Name.equals( "ingot" + ore ) )
{
addIngot( ore, item );
}
else if ( Name.equals( "dust" + ore ) )
{
addDust( ore, item );
}
}
}
}
}
@@ -0,0 +1,45 @@
package appeng.core.features.registries;
import java.util.HashMap;
import net.minecraftforge.event.ForgeSubscribe;
import appeng.api.events.LocatableEventAnnounce;
import appeng.api.events.LocatableEventAnnounce.LocatableEvent;
import appeng.api.features.ILocatable;
import appeng.api.features.ILocateableRegistry;
import appeng.util.Platform;
public class LocateableRegistry implements ILocateableRegistry
{
private HashMap<Long, ILocatable> set;
@ForgeSubscribe
public void updateLocateable(LocatableEventAnnounce e)
{
if ( Platform.isClient() )
return; // IGNORE!
if ( e.change == LocatableEvent.Register )
{
set.put( e.target.getLocatableSerial(), e.target );
} else if ( e.change == LocatableEvent.Unregister )
{
set.remove( e.target.getLocatableSerial() );
}
}
public LocateableRegistry() {
set = new HashMap();
}
/**
* Find a locate-able object by its serial.
*/
@Override
public Object findLocateableBySerial(long ser)
{
return set.get( ser );
}
}
@@ -0,0 +1,129 @@
package appeng.core.features.registries;
import java.util.HashMap;
import java.util.LinkedList;
import net.minecraft.tileentity.TileEntity;
import appeng.api.exceptions.AppEngException;
import appeng.api.movable.IMovableHandler;
import appeng.api.movable.IMovableRegistry;
import appeng.api.movable.IMovableTile;
import appeng.spatial.DefaultSpatialHandler;
public class MovableTileRegistry implements IMovableRegistry
{
private HashMap<Class<? extends TileEntity>, IMovableHandler> Valid = new HashMap<Class<? extends TileEntity>, IMovableHandler>();
private LinkedList<Class<? extends TileEntity>> test = new LinkedList<Class<? extends TileEntity>>();
private LinkedList<IMovableHandler> handlers = new LinkedList<IMovableHandler>();
private DefaultSpatialHandler dsh = new DefaultSpatialHandler();
private IMovableHandler nullHandler = new DefaultSpatialHandler();
private IMovableHandler testClass(Class myClass, TileEntity te)
{
IMovableHandler handler = null;
// ask handlers...
for (IMovableHandler han : handlers)
{
if ( han.canHandle( myClass, te ) )
{
handler = han;
break;
}
}
// if you have a handler your opted in
if ( handler != null )
{
Valid.put( myClass, handler );
return handler;
}
// if your movable our opted in
if ( te instanceof IMovableTile )
{
Valid.put( myClass, dsh );
return dsh;
}
// if you are on the white list your opted in.
for (Class<? extends TileEntity> testClass : test)
{
if ( testClass.isAssignableFrom( myClass ) )
{
Valid.put( myClass, dsh );
return dsh;
}
}
Valid.put( myClass, nullHandler );
return nullHandler;
}
@Override
public boolean askToMove(TileEntity te)
{
Class myClass = te.getClass();
IMovableHandler canMove = Valid.get( myClass );
if ( canMove == null )
canMove = testClass( myClass, te );
if ( canMove != nullHandler )
{
if ( te instanceof IMovableTile )
((IMovableTile) te).prepareToMove();
te.invalidate();
return true;
}
return false;
}
@Override
public void doneMoving(TileEntity te)
{
if ( te instanceof IMovableTile )
{
IMovableTile mt = (IMovableTile) te;
mt.doneMoving();
}
}
@Override
public void whiteListTileEntity(Class<? extends TileEntity> c)
{
if ( c.getName().equals( TileEntity.class.getName() ) )
{
throw new RuntimeException( new AppEngException( "Someone tried to make all tiles movable, this is a clear violation of the purpose of the white list." ) );
}
test.add( c );
}
@Override
public void addHandler(IMovableHandler han)
{
handlers.add( han );
}
@Override
public IMovableHandler getHandler(TileEntity te)
{
Class myClass = te.getClass();
IMovableHandler h = Valid.get( myClass );
return h == null ? dsh : h;
}
@Override
public IMovableHandler getDefaultHandler()
{
return dsh;
}
}
@@ -0,0 +1,40 @@
package appeng.core.features.registries;
import java.util.HashMap;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import appeng.api.config.TunnelType;
import appeng.api.features.IP2PTunnelRegistry;
import appeng.util.Platform;
public class P2PTunnelRegistry implements IP2PTunnelRegistry
{
HashMap<ItemStack, TunnelType> Tunnels = new HashMap();
@Override
public void addNewAttunement(ItemStack trigger, TunnelType type)
{
if ( type == null )
throw new RuntimeException( "Invalid Tunnel Type." );
Tunnels.put( trigger, type );
}
@Override
public TunnelType getTunnelTypeByItem(ItemStack trigger)
{
if ( FluidContainerRegistry.isContainer( trigger ) )
return TunnelType.FLUID;
for (ItemStack is : Tunnels.keySet())
{
if ( Platform.isSameItemType( is, trigger ) )
return Tunnels.get( is );
}
return null;
}
}
@@ -0,0 +1,81 @@
package appeng.core.features.registries;
import appeng.api.features.IGrinderRegistry;
import appeng.api.features.ILocateableRegistry;
import appeng.api.features.IP2PTunnelRegistry;
import appeng.api.features.IRegistryContainer;
import appeng.api.features.ISpecialComparisonRegistry;
import appeng.api.features.IWirelessTermRegistery;
import appeng.api.movable.IMovableRegistry;
import appeng.api.networking.IGridCacheRegistry;
import appeng.api.storage.ICellRegistry;
import appeng.api.storage.IExternalStorageRegistry;
public class RegistryContainer implements IRegistryContainer
{
private GrinderRecipeManager GrinderRecipes = new GrinderRecipeManager();
private ExternalStorageRegistry ExternalStorageHandlers = new ExternalStorageRegistry();
private CellRegistry CellRegistry = new CellRegistry();
private LocateableRegistry LocateableRegistry = new LocateableRegistry();
private SpecialComparisonRegistry SpecialComparsonRegistry = new SpecialComparisonRegistry();
private WirelessRegistry WirelessRegistery = new WirelessRegistry();
private GridCacheRegistry GridCacheRegistry = new GridCacheRegistry();
private P2PTunnelRegistry P2PRegistry = new P2PTunnelRegistry();
private MovableTileRegistry MoveableReg = new MovableTileRegistry();
@Override
public IWirelessTermRegistery wireless()
{
return WirelessRegistery;
}
@Override
public ICellRegistry cell()
{
return CellRegistry;
}
@Override
public IGrinderRegistry grinder()
{
return GrinderRecipes;
}
@Override
public ISpecialComparisonRegistry specialComparson()
{
return SpecialComparsonRegistry;
}
@Override
public IExternalStorageRegistry externalStorage()
{
return ExternalStorageHandlers;
}
@Override
public ILocateableRegistry locateable()
{
return LocateableRegistry;
}
@Override
public IGridCacheRegistry gridCache()
{
return GridCacheRegistry;
}
@Override
public IMovableRegistry moveable()
{
return MoveableReg;
}
@Override
public IP2PTunnelRegistry p2pTunnel()
{
return P2PRegistry;
}
}
@@ -0,0 +1,41 @@
package appeng.core.features.registries;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.features.IItemComparisionProvider;
import appeng.api.features.IItemComparison;
import appeng.api.features.ISpecialComparisonRegistry;
public class SpecialComparisonRegistry implements ISpecialComparisonRegistry
{
private List<IItemComparisionProvider> CompRegistry;
public SpecialComparisonRegistry() {
CompRegistry = new ArrayList<IItemComparisionProvider>();
}
@Override
public IItemComparison getSpecialComparion(ItemStack stack)
{
for (IItemComparisionProvider i : CompRegistry)
{
IItemComparison comp = i.getComparison( stack );
if ( comp != null )
{
return comp;
}
}
return null;
}
@Override
public void addComparisonProvider(IItemComparisionProvider prov)
{
CompRegistry.add( prov );
}
}
@@ -0,0 +1,16 @@
package appeng.core.features.registries;
import net.minecraft.tileentity.TileEntity;
public class WirelessRangeResult
{
public WirelessRangeResult(TileEntity t, float d) {
dist = d;
te = t;
}
final public float dist;
final public TileEntity te;
}
@@ -0,0 +1,71 @@
package appeng.core.features.registries;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import appeng.api.features.IWirelessTermHandler;
import appeng.api.features.IWirelessTermRegistery;
import appeng.util.Platform;
import cpw.mods.fml.common.network.Player;
public class WirelessRegistry implements IWirelessTermRegistery
{
List<IWirelessTermHandler> handlers;
public WirelessRegistry() {
handlers = new ArrayList();
}
@Override
public void registerWirelessHandler(IWirelessTermHandler handler)
{
handlers.add( handler );
}
@Override
public boolean isWirelessTerminal(ItemStack is)
{
for (IWirelessTermHandler h : handlers)
{
if ( h.canHandle( is ) )
return true;
}
return false;
}
@Override
public IWirelessTermHandler getWirelessTerminalHandler(ItemStack is)
{
for (IWirelessTermHandler h : handlers)
{
if ( h.canHandle( is ) )
return h;
}
return null;
}
@Override
public void OpenWirelessTermainlGui(ItemStack item, World w, EntityPlayer player)
{
if ( Platform.isClient() )
return;
IWirelessTermHandler handler = getWirelessTerminalHandler( item );
if ( handler == null )
{
player.addChatMessage( "Item is not a wireless terminal." );
return;
}
if ( handler.usePower( (Player) player, 10.0f, item ) )
{
}
}
}
@@ -0,0 +1,88 @@
package appeng.core.features.registries.entries;
import net.minecraft.item.ItemStack;
import appeng.api.features.IGrinderEntry;
public class AppEngGrinderRecipe implements IGrinderEntry
{
private ItemStack in;
private ItemStack out;
private float optionalChance;
private ItemStack optionalOutput;
private int energy;
public AppEngGrinderRecipe(ItemStack a, ItemStack b, int cost) {
in = a;
out = b;
energy = cost;
}
public AppEngGrinderRecipe(ItemStack a, ItemStack b, ItemStack c, float chance, int cost) {
in = a;
out = b;
optionalOutput = c;
optionalChance = chance;
energy = cost;
}
@Override
public ItemStack getInput()
{
return in;
}
@Override
public void setInput(ItemStack i)
{
in = i.copy();
}
@Override
public ItemStack getOutput()
{
return out;
}
@Override
public void setOutput(ItemStack o)
{
out = o.copy();
}
@Override
public int getEnergyCost()
{
return energy;
}
@Override
public void setEnergyCost(int c)
{
energy = c;
}
@Override
public ItemStack getOptionalOutput()
{
return optionalOutput;
}
@Override
public void setOptionalOutput(ItemStack output, float chance)
{
optionalOutput = output;
optionalChance = chance;
}
@Override
public float getOptionalChance()
{
return optionalChance;
}
}
@@ -0,0 +1,58 @@
package appeng.core.features.registries.entries;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import appeng.api.implementations.IChestOrDrive;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.client.texture.ExtraTextures;
import appeng.core.sync.GuiBridge;
import appeng.me.storage.CellInventory;
import appeng.tile.AEBaseTile;
import appeng.util.Platform;
public class BasicCellHandler implements ICellHandler
{
@Override
public boolean isCell(ItemStack is)
{
return CellInventory.isCell( is );
}
@Override
public IMEInventoryHandler getCellInventory(ItemStack is, StorageChannel channel)
{
if ( channel == StorageChannel.ITEMS )
return CellInventory.getCell( is );
return null;
}
@Override
public Icon getTopTexture()
{
return ExtraTextures.BlockMEChestItems.getIcon();
}
@Override
public void openChestGui(EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler inv, ItemStack is, StorageChannel chan)
{
Platform.openGUI( player, (AEBaseTile) chest, chest.getUp(), GuiBridge.GUI_ME );
}
@Override
public int getStatusForCell(ItemStack is, IMEInventory handler)
{
return 1;
}
@Override
public double cellIdleDrain(ItemStack is, IMEInventory handler)
{
CellInventory inv = (CellInventory) handler;
return inv.getIdleDrain();
}
}
@@ -0,0 +1,62 @@
package appeng.core.features.registries.entries;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.AEApi;
import appeng.api.features.IWirelessTermHandler;
import appeng.util.Platform;
import cpw.mods.fml.common.network.Player;
public class BasicTerminalHandler implements IWirelessTermHandler
{
@Override
public boolean canHandle(ItemStack is)
{
if ( is == null )
return false;
if ( AEApi.instance().items().itemWirelessTerminal.sameAs( is ) )
return true;
return false;
}
@Override
public boolean usePower(Player player, float amount, ItemStack is)
{
return false;
}
@Override
public boolean hasPower(Player player, ItemStack is)
{
return false;
}
@Override
public String getEncryptionKey(ItemStack i)
{
if ( i == null )
return null;
NBTTagCompound tag = Platform.openNbtData( i );
if ( tag != null )
{
return tag.getString( "encKey" );
}
return null;
}
@Override
public void setEncryptionKey(ItemStack i, String encKey, String name)
{
if ( i == null )
return;
NBTTagCompound tag = Platform.openNbtData( i );
if ( tag != null )
{
tag.setString( "encKey", encKey );
}
}
}
@@ -0,0 +1,57 @@
package appeng.core.features.registries.entries;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.Icon;
import appeng.api.implementations.IChestOrDrive;
import appeng.api.storage.ICellHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.client.texture.ExtraTextures;
import appeng.items.storage.ItemCreativeStorageCell;
import appeng.me.storage.CreativeCellInventory;
public class CreativeCellHandler implements ICellHandler
{
@Override
public boolean isCell(ItemStack is)
{
return is != null && is.getItem() instanceof ItemCreativeStorageCell;
}
@Override
public IMEInventoryHandler getCellInventory(ItemStack is, StorageChannel channel)
{
if ( channel == StorageChannel.ITEMS && is != null && is.getItem() instanceof ItemCreativeStorageCell )
return CreativeCellInventory.getCell( is );
return null;
}
@Override
public Icon getTopTexture()
{
return ExtraTextures.BlockMEChestItems.getIcon();
}
@Override
public void openChestGui(EntityPlayer player, IChestOrDrive chest, ICellHandler cellHandler, IMEInventoryHandler inv, ItemStack is, StorageChannel chan)
{
player.sendChatToPlayer( ChatMessageComponent.createFromText( "Not ready yet..." ) );
}
@Override
public int getStatusForCell(ItemStack is, IMEInventory handler)
{
return 2;
}
@Override
public double cellIdleDrain(ItemStack is, IMEInventory handler)
{
return 0;
}
}
+33
View File
@@ -0,0 +1,33 @@
package appeng.core.localization;
import net.minecraft.util.StatCollector;
import appeng.core.AELog;
public enum GuiText
{
inventory("container"), // mc's default Inventory localization.
Chest, StoredEnergy, Of, Condenser, Drive, GrindStone, VibrationChamber, SpatialIOPort, NetworkStatus, LevelEmitter, Terminal;
String root;
GuiText() {
root = "gui.appliedenergistics2";
AELog.localization( "gui", getName() );
}
GuiText(String r) {
root = r;
}
private String getName()
{
return root + "." + toString();
}
public String getLocal()
{
return StatCollector.translateToLocal( getName() );
}
}
+24
View File
@@ -0,0 +1,24 @@
package appeng.core.localization;
import net.minecraft.util.ChatMessageComponent;
import appeng.core.AELog;
public enum PlayerMessages
{
ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered;
private PlayerMessages() {
AELog.localization( "chat", getName() );
}
String getName()
{
return "chat.appliedenergistics2." + toString();
}
public ChatMessageComponent get()
{
return ChatMessageComponent.createFromTranslationKey( getName() );
}
}
+46
View File
@@ -0,0 +1,46 @@
package appeng.core.sync;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
public class AppEngClientPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player)
{
DataInputStream stream = new DataInputStream( new ByteArrayInputStream( packet.data ) );
// Determine packet type and coordinates of affected tile entity
int packetType = -1;
try
{
packetType = stream.readInt();
AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
pack.clientPacketData( network, pack, player );
} catch (IOException e)
{
e.printStackTrace();
} catch (InstantiationException e)
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
} catch (IllegalArgumentException e)
{
e.printStackTrace();
} catch (InvocationTargetException e)
{
e.printStackTrace();
}
}
}
+49
View File
@@ -0,0 +1,49 @@
package appeng.core.sync;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.NetLoginHandler;
import net.minecraft.network.packet.NetHandler;
import net.minecraft.network.packet.Packet1Login;
import net.minecraft.server.MinecraftServer;
import appeng.core.WorldSettings;
import cpw.mods.fml.common.network.IConnectionHandler;
import cpw.mods.fml.common.network.Player;
public class AppEngConnectionHandler implements IConnectionHandler
{
@Override
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
{
WorldSettings.getInstance().sendToPlayer( player );
}
@Override
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
{
return null;
}
@Override
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
{
}
@Override
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
{
}
@Override
public void connectionClosed(INetworkManager manager)
{
}
@Override
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
{
}
}
+43
View File
@@ -0,0 +1,43 @@
package appeng.core.sync;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import appeng.core.Configuration;
import cpw.mods.fml.common.network.Player;
public abstract class AppEngPacket
{
private Packet250CustomPayload p;
protected boolean isChunkDataPacket;
AppEngPacketHandlerBase.PacketTypes id;
final public int getPacketID()
{
return AppEngPacketHandlerBase.PacketTypes.getID( this.getClass() ).ordinal();
}
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
{
throw new RuntimeException( "This packet ( " + getPacketID() + " does not implement a server side handler." );
}
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
{
throw new RuntimeException( "This packet ( " + getPacketID() + " does not implement a client side handler." );
}
public Packet250CustomPayload getPacket()
{
// / += p.getPacketSize();
return p;
}
protected void configureWrite(byte[] par2ArrayOfByte)
{
p = new Packet250CustomPayload( Configuration.PACKET_CHANNEL, par2ArrayOfByte );
p.isChunkDataPacket = isChunkDataPacket;
}
}
+86
View File
@@ -0,0 +1,86 @@
package appeng.core.sync;
import java.io.DataInputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.sync.packets.PacketLightning;
import appeng.core.sync.packets.PacketLocalizedChatMsg;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketMatterCannon;
import appeng.core.sync.packets.PacketMockExplosion;
import appeng.core.sync.packets.PacketMultiPart;
import appeng.core.sync.packets.PacketPartPlacement;
public class AppEngPacketHandlerBase
{
public static Map<Class, PacketTypes> reverseLookup = new HashMap<Class, AppEngPacketHandlerBase.PacketTypes>();
public enum PacketTypes
{
PACKET_INVENTORY_ACTION(PacketInventoryAction.class),
PACKET_ME_INVENTORY_UPDATE(PacketMEInventoryUpdate.class),
PACKET_CONFIG_BUTTON(PacketConfigButton.class),
PACKET_MULTIPART(PacketMultiPart.class),
PACKET_PARTPLACEMENT(PacketPartPlacement.class),
PACKET_LIGHTNING(PacketLightning.class),
PACKET_MATTERCANNON(PacketMatterCannon.class),
PACKET_MOCKEXPLOSION(PacketMockExplosion.class),
PACKET_LOCALIZED_CHATMSG(PacketLocalizedChatMsg.class);
final public Class pc;
final public Constructor con;
private PacketTypes(Class c) {
pc = c;
Constructor x = null;
try
{
x = pc.getConstructor( DataInputStream.class );
}
catch (NoSuchMethodException e)
{
}
catch (SecurityException e)
{
}
con = x;
AppEngPacketHandlerBase.reverseLookup.put( pc, this );
if ( con == null )
throw new RuntimeException( "Invalid Packet Class, must be constructable on DataInputStream" );
}
AppEngPacket parsePacket(DataInputStream in) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
return (AppEngPacket) con.newInstance( in );
}
public static PacketTypes getPacket(int id)
{
return (values())[id];
}
public static PacketTypes getID(Class<? extends AppEngPacket> c)
{
return AppEngPacketHandlerBase.reverseLookup.get( c );
}
};
}
+46
View File
@@ -0,0 +1,46 @@
package appeng.core.sync;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
public final class AppEngServerPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
{
DataInputStream stream = new DataInputStream( new ByteArrayInputStream( packet.data ) );
// Determine packet type and coordinates of affected tile entity
int packetType = -1;
try
{
packetType = stream.readInt();
AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
pack.serverPacketData( manager, pack, player );
} catch (IOException e)
{
e.printStackTrace();
} catch (InstantiationException e)
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
} catch (IllegalArgumentException e)
{
e.printStackTrace();
} catch (InvocationTargetException e)
{
e.printStackTrace();
}
}
}
+172
View File
@@ -0,0 +1,172 @@
package appeng.core.sync;
import java.lang.reflect.Constructor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.IStorageMonitorable;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.client.gui.GuiNull;
import appeng.container.ContainerNull;
import appeng.container.implementations.ContainerChest;
import appeng.container.implementations.ContainerCondenser;
import appeng.container.implementations.ContainerDrive;
import appeng.container.implementations.ContainerGrinder;
import appeng.container.implementations.ContainerMEMonitorable;
import appeng.container.implementations.ContainerVibrationChamber;
import appeng.tile.grindstone.TileGrinder;
import appeng.tile.misc.TileCondenser;
import appeng.tile.misc.TileVibrationChamber;
import appeng.tile.storage.TileChest;
import appeng.tile.storage.TileDrive;
import appeng.util.Platform;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.relauncher.ReflectionHelper;
public enum GuiBridge implements IGuiHandler
{
GUI_Handler(),
GUI_GRINDER(ContainerGrinder.class, TileGrinder.class),
GUI_CHEST(ContainerChest.class, TileChest.class),
GUI_ME(ContainerMEMonitorable.class, IStorageMonitorable.class),
GUI_DRIVE(ContainerDrive.class, TileDrive.class),
GUI_VIBRATIONCHAMBER(ContainerVibrationChamber.class, TileVibrationChamber.class),
GUI_CONDENSER(ContainerCondenser.class, TileCondenser.class);
private Class Tile;
private Class Gui;
private Class Container;
private GuiBridge() {
Tile = null;
Gui = null;
Container = null;
}
/**
* I honestly wish I could just use the GuiClass Names myself, but I can't access them without MC's Server
* Exploding.
*/
private void getGui()
{
if ( Platform.isClient() )
{
String start = Container.getName();
String GuiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
if ( start.equals( GuiClass ) )
throw new RuntimeException( "Unable to find gui class" );
Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), GuiClass );
if ( Gui == null )
throw new RuntimeException( "Cannot Load class: " + GuiClass );
}
}
private GuiBridge(Class _Container) {
Container = _Container;
Tile = null;
getGui();
}
private GuiBridge(Class _Container, Class _Tile) {
Container = _Container;
Tile = _Tile;
getGui();
}
public boolean CorrectTileOrPart(Object tE)
{
if ( Tile == null )
throw new RuntimeException( "This Gui Cannot use the standard Handler." );
return Tile.isInstance( tE );
}
public Object ConstructContainer(InventoryPlayer inventory, ForgeDirection side, Object tE)
{
try
{
Constructor[] c = Container.getConstructors();
if ( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
return c[0].newInstance( inventory, tE );
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
}
public Object ConstructGui(InventoryPlayer inventory,ForgeDirection side, Object tE)
{
try
{
Constructor[] c = Gui.getConstructors();
if ( c.length == 0 )
throw new AppEngException( "Invalid Gui Class" );
return c[0].newInstance( inventory, tE );
}
catch (Throwable t)
{
throw new RuntimeException( t );
}
}
@Override
public Object getServerGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
{
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL& 0x07 );
GuiBridge ID = values()[ID_ORDINAL >> 3];
TileEntity TE = w.getBlockTileEntity( x, y, z );
if ( TE instanceof IPartHost )
{
((IPartHost) TE).getPart( side );
IPart part = ((IPartHost) TE).getPart(side);
if ( ID.CorrectTileOrPart(part) )
return ID.ConstructContainer( player.inventory, side, part );
}
else
{
if ( ID.CorrectTileOrPart( TE ) )
return ID.ConstructContainer( player.inventory, side, TE );
}
return new ContainerNull();
}
@Override
public Object getClientGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
{
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL& 0x07 );
GuiBridge ID = values()[ID_ORDINAL >> 3];
TileEntity TE = w.getBlockTileEntity( x, y, z );
if ( TE instanceof IPartHost )
{
((IPartHost) TE).getPart( side );
IPart part = ((IPartHost) TE).getPart(side);
if ( ID.CorrectTileOrPart(part) )
return ID.ConstructGui( player.inventory, side, part );
}
else
{
if ( ID.CorrectTileOrPart( TE ) )
return ID.ConstructGui( player.inventory, side, TE );
}
return new GuiNull( new ContainerNull() );
}
}
+57
View File
@@ -0,0 +1,57 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager;
import net.minecraft.tileentity.TileEntity;
import appeng.api.config.Settings;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigureableObject;
import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.util.Platform;
import cpw.mods.fml.common.network.Player;
public class PacketConfigButton extends AppEngPacket
{
final public Settings option;
// automatic.
public PacketConfigButton(DataInputStream stream) throws IOException {
option = Settings.values()[stream.readInt()];
}
@Override
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
AEBaseContainer aebc = (AEBaseContainer) sender.openContainer;
TileEntity bt = aebc.getTileEntity();
if ( bt instanceof IConfigureableObject )
{
IConfigManager cm = ((IConfigureableObject) bt).getConfigManager();
Enum newState = Platform.nextEnum( cm.getSetting( option ) );
cm.putSetting( option, newState );
}
}
// api
public PacketConfigButton(Settings option) throws IOException {
this.option = option;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
data.writeInt( option.ordinal() );
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
}
}
@@ -0,0 +1,68 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.core.sync.AppEngPacket;
import appeng.helpers.InventoryAction;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.network.Player;
public class PacketInventoryAction extends AppEngPacket
{
final public InventoryAction action;
final public int slot;
final public IAEItemStack slotItem;
// automatic.
public PacketInventoryAction(DataInputStream stream) throws IOException {
action = InventoryAction.values()[stream.readInt()];
slot = stream.readInt();
boolean hasItem = stream.readBoolean();
if ( hasItem )
slotItem = AEItemStack.loadItemStackFromPacket( stream );
else
slotItem = null;
}
@Override
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
AEBaseContainer aebc = (AEBaseContainer) sender.openContainer;
aebc.doAction( sender, action, slot, slotItem );
}
// api
public PacketInventoryAction(InventoryAction action, int slot, IAEItemStack slotItem) throws IOException {
this.action = action;
this.slot = slot;
this.slotItem = slotItem;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
data.writeInt( action.ordinal() );
data.writeInt( slot );
if ( slotItem == null )
data.writeBoolean( false );
else
{
data.writeBoolean( true );
slotItem.writeToPacket( data );
}
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
}
}
+70
View File
@@ -0,0 +1,70 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.network.INetworkManager;
import appeng.client.ClientHelper;
import appeng.client.render.effects.LightningEffect;
import appeng.core.Configuration;
import appeng.core.sync.AppEngPacket;
import appeng.util.Platform;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketLightning extends AppEngPacket
{
final double x;
final double y;
final double z;
// automatic.
public PacketLightning(DataInputStream stream) throws IOException {
x = stream.readFloat();
y = stream.readFloat();
z = stream.readFloat();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
{
try
{
if ( Platform.isClient() && Configuration.instance.enableEffects )
{
LightningEffect fx = new LightningEffect( ClientHelper.proxy.getWorld(), x, y, z, 0.0f, 0.0f, 0.0f );
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
}
}
catch (Exception err)
{
}
}
// api
public PacketLightning(double x, double y, double z) throws IOException {
this.x = x;
this.y = y;
this.z = z;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
data.writeFloat( (float) x );
data.writeFloat( (float) y );
data.writeFloat( (float) z );
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
}
}
@@ -0,0 +1,47 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.util.ChatMessageComponent;
import appeng.core.sync.AppEngPacket;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketLocalizedChatMsg extends AppEngPacket
{
final public String msg;
// automatic.
public PacketLocalizedChatMsg(DataInputStream stream) throws IOException {
msg = stream.readUTF();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
{
((EntityPlayer) player).sendChatToPlayer( ChatMessageComponent.createFromTranslationWithSubstitutions( msg ) );
}
// api
public PacketLocalizedChatMsg(String msg) throws IOException {
this.msg = msg;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
data.writeUTF( msg );
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
}
}
@@ -0,0 +1,81 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.implementations.GuiMEMonitorable;
import appeng.core.sync.AppEngPacket;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketMEInventoryUpdate extends AppEngPacket
{
// output...
final private ByteArrayOutputStream bytes;
final private DataOutputStream data;
boolean empty = true;
// input.
final List<IAEItemStack> list;
// automatic.
public PacketMEInventoryUpdate(DataInputStream stream) throws IOException {
bytes = null;
data = null;
list = new LinkedList();
while (stream.available() > 0)
list.add( AEItemStack.loadItemStackFromPacket( stream ) );
empty = list.isEmpty();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
{
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if ( gs instanceof GuiMEMonitorable )
{
((GuiMEMonitorable) gs).postUpdate( list );
}
}
@Override
public Packet250CustomPayload getPacket()
{
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
return super.getPacket();
}
// api
public PacketMEInventoryUpdate() throws IOException {
bytes = new ByteArrayOutputStream();
data = new DataOutputStream( bytes );
list = null;
data.writeInt( getPacketID() );
}
public void appendItem(IAEItemStack is) throws IOException
{
is.writeToPacket( data );
empty = false;
}
public boolean isEmpty()
{
return empty;
}
}
+90
View File
@@ -0,0 +1,90 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.item.Item;
import net.minecraft.network.INetworkManager;
import net.minecraft.world.World;
import appeng.client.render.effects.MatterCannonEffect;
import appeng.core.sync.AppEngPacket;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketMatterCannon extends AppEngPacket
{
final double x;
final double y;
final double z;
final double dx;
final double dy;
final double dz;
final byte len;
// automatic.
public PacketMatterCannon(DataInputStream stream) throws IOException {
x = stream.readFloat();
y = stream.readFloat();
z = stream.readFloat();
dx = stream.readFloat();
dy = stream.readFloat();
dz = stream.readFloat();
len = stream.readByte();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
{
try
{
World world = FMLClientHandler.instance().getClient().theWorld;
for (int a = 1; a < len; a++)
{
MatterCannonEffect fx = new MatterCannonEffect( world, x + dx * a, y + dy * a, z + dz * a, Item.diamond );
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
}
} catch (Exception err)
{
}
}
// api
public PacketMatterCannon(double x, double y, double z, float dx, float dy, float dz, byte len) throws IOException {
float dl = dx * dx + dy * dy + dz * dz;
float dlz = (float) Math.sqrt( dl );
this.x = x;
this.y = y;
this.z = z;
this.dx = dx / dlz;
this.dy = dy / dlz;
this.dz = dz / dlz;
this.len = len;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
data.writeFloat( (float) x );
data.writeFloat( (float) y );
data.writeFloat( (float) z );
data.writeFloat( (float) this.dx );
data.writeFloat( (float) this.dy );
data.writeFloat( (float) this.dz );
data.writeByte( len );
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
}
}
@@ -0,0 +1,56 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.network.INetworkManager;
import net.minecraft.world.World;
import appeng.core.CommonHelper;
import appeng.core.sync.AppEngPacket;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketMockExplosion extends AppEngPacket
{
final public double x;
final public double y;
final public double z;
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkManager network, AppEngPacket packet, Player player)
{
World world = CommonHelper.proxy.getWorld();
world.spawnParticle( "largeexplode", this.x, this.y, this.z, 1.0D, 0.0D, 0.0D );
}
// automatic.
public PacketMockExplosion(DataInputStream stream) throws IOException {
x = stream.readDouble();
y = stream.readDouble();
z = stream.readDouble();
}
// api
public PacketMockExplosion(double x, double y, double z) throws IOException {
this.x = x;
this.y = y;
this.z = z;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
data.writeDouble( x );
data.writeDouble( y );
data.writeDouble( z );
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
}
}
+42
View File
@@ -0,0 +1,42 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager;
import net.minecraftforge.common.MinecraftForge;
import appeng.core.sync.AppEngPacket;
import appeng.integration.modules.helpers.FMPPacketEvent;
import cpw.mods.fml.common.network.Player;
public class PacketMultiPart extends AppEngPacket
{
// automatic.
public PacketMultiPart(DataInputStream stream) throws IOException {
}
@Override
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
MinecraftForge.EVENT_BUS.post( new FMPPacketEvent( sender ) );
}
// api
public PacketMultiPart() throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
}
}
@@ -0,0 +1,50 @@
package appeng.core.sync.packets;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetworkManager;
import appeng.core.sync.AppEngPacket;
import appeng.helpers.PartPlacement;
import cpw.mods.fml.common.network.Player;
public class PacketPartPlacement extends AppEngPacket
{
int x, y, z, face;
// automatic.
public PacketPartPlacement(DataInputStream stream) throws IOException {
x = stream.readInt();
y = stream.readInt();
z = stream.readInt();
face = stream.readByte();
}
@Override
public void serverPacketData(INetworkManager manager, AppEngPacket packet, Player player)
{
EntityPlayerMP sender = (EntityPlayerMP) player;
PartPlacement.place( sender.getHeldItem(), x, y, z, face, sender, sender.worldObj, PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0 );
}
// api
public PacketPartPlacement(int x, int y, int z, int face) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream( bytes );
data.writeInt( getPacketID() );
data.writeInt( x );
data.writeInt( y );
data.writeInt( z );
data.writeByte( face );
isChunkDataPacket = false;
configureWrite( bytes.toByteArray() );
}
}