diff --git a/.gitignore b/.gitignore index 8d16946..23c3dc7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .gradle -.idea build run +bin +off diff --git a/build.gradle b/build.gradle index 7c2d31b..5b0dc6c 100644 --- a/build.gradle +++ b/build.gradle @@ -17,9 +17,9 @@ buildscript { apply plugin: 'forge' -version = "1.0" -group= "modgroup" -archivesBaseName = "modid" +version = "1.0.0-dirty" +group= "universalelectricity" +archivesBaseName = "basiccomponents" minecraft { version = "1.7.10-10.13.4.1614-1.7.10" diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/basiccomponents/client/ModelCopperWire.java b/src/main/java/basiccomponents/client/ModelCopperWire.java new file mode 100644 index 0000000..58235f5 --- /dev/null +++ b/src/main/java/basiccomponents/client/ModelCopperWire.java @@ -0,0 +1,117 @@ +package basiccomponents.client; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; + +@SideOnly(Side.CLIENT) +public class ModelCopperWire extends ModelBase { + + ModelRenderer Middle; + ModelRenderer Right; + ModelRenderer Left; + ModelRenderer Back; + ModelRenderer Front; + ModelRenderer Top; + ModelRenderer Bottom; + + + public ModelCopperWire() { + super.textureWidth = 64; + super.textureHeight = 32; + this.Middle = new ModelRenderer(this, 0, 0); + this.Middle.addBox(-1.0F, -1.0F, -1.0F, 4, 4, 4); + this.Middle.setRotationPoint(-1.0F, 15.0F, -1.0F); + this.Middle.setTextureSize(64, 32); + this.Middle.mirror = true; + this.setRotation(this.Middle, 0.0F, 0.0F, 0.0F); + this.Right = new ModelRenderer(this, 21, 0); + this.Right.addBox(0.0F, 0.0F, 0.0F, 6, 4, 4); + this.Right.setRotationPoint(2.0F, 14.0F, -2.0F); + this.Right.setTextureSize(64, 32); + this.Right.mirror = true; + this.setRotation(this.Right, 0.0F, 0.0F, 0.0F); + this.Left = new ModelRenderer(this, 21, 0); + this.Left.addBox(0.0F, 0.0F, 0.0F, 6, 4, 4); + this.Left.setRotationPoint(-8.0F, 14.0F, -2.0F); + this.Left.setTextureSize(64, 32); + this.Left.mirror = true; + this.setRotation(this.Left, 0.0F, 0.0F, 0.0F); + this.Back = new ModelRenderer(this, 0, 11); + this.Back.addBox(0.0F, 0.0F, 0.0F, 4, 4, 6); + this.Back.setRotationPoint(-2.0F, 14.0F, 2.0F); + this.Back.setTextureSize(64, 32); + this.Back.mirror = true; + this.setRotation(this.Back, 0.0F, 0.0F, 0.0F); + this.Front = new ModelRenderer(this, 0, 11); + this.Front.addBox(0.0F, 0.0F, 0.0F, 4, 4, 6); + this.Front.setRotationPoint(-2.0F, 14.0F, -8.0F); + this.Front.setTextureSize(64, 32); + this.Front.mirror = true; + this.setRotation(this.Front, 0.0F, 0.0F, 0.0F); + this.Top = new ModelRenderer(this, 21, 11); + this.Top.addBox(0.0F, 0.0F, 0.0F, 4, 6, 4); + this.Top.setRotationPoint(-2.0F, 8.0F, -2.0F); + this.Top.setTextureSize(64, 32); + this.Top.mirror = true; + this.setRotation(this.Top, 0.0F, 0.0F, 0.0F); + this.Bottom = new ModelRenderer(this, 21, 11); + this.Bottom.addBox(0.0F, 0.0F, 0.0F, 4, 6, 4); + this.Bottom.setRotationPoint(-2.0F, 18.0F, -2.0F); + this.Bottom.setTextureSize(64, 32); + this.Bottom.mirror = true; + this.setRotation(this.Bottom, 0.0F, 0.0F, 0.0F); + } + + public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { + super.render(entity, f, f1, f2, f3, f4, f5); + this.setRotationAngles(f, f1, f2, f3, f4, f5, entity); + this.renderMiddle(); + this.renderBottom(); + this.renderTop(); + this.renderLeft(); + this.renderRight(); + this.renderBack(); + this.renderFront(); + } + + public void renderMiddle() { + this.Middle.render(0.0625F); + } + + public void renderBottom() { + this.Bottom.render(0.0625F); + } + + public void renderTop() { + this.Top.render(0.0625F); + } + + public void renderLeft() { + this.Left.render(0.0625F); + } + + public void renderRight() { + this.Right.render(0.0625F); + } + + public void renderBack() { + this.Back.render(0.0625F); + } + + public void renderFront() { + this.Front.render(0.0625F); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } + + public void setRotationAngles(float x, float y, float z, float f3, float f4, float f5, Entity entity) { + super.setRotationAngles(x, y, z, f3, f4, f5, entity); + } +} diff --git a/src/main/java/basiccomponents/client/RenderCopperWire.java b/src/main/java/basiccomponents/client/RenderCopperWire.java new file mode 100644 index 0000000..a1a314d --- /dev/null +++ b/src/main/java/basiccomponents/client/RenderCopperWire.java @@ -0,0 +1,57 @@ +package basiccomponents.client; + +import basiccomponents.client.ModelCopperWire; +import basiccomponents.common.tileentity.TileEntityCopperWire; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class RenderCopperWire extends TileEntitySpecialRenderer { + + public static final ModelCopperWire model = new ModelCopperWire(); + + + public void renderModelAt(TileEntityCopperWire tileEntity, double d, double d1, double d2, float f) { + this.bindTexture(new ResourceLocation("basiccomponents", "textures/models/copperWire.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)d + 0.5F, (float)d1 + 1.5F, (float)d2 + 0.5F); + GL11.glScalef(1.0F, -1.0F, -1.0F); + if(tileEntity.visuallyConnected[0]) { + model.renderBottom(); + } + + if(tileEntity.visuallyConnected[1]) { + model.renderTop(); + } + + if(tileEntity.visuallyConnected[2]) { + model.renderBack(); + } + + if(tileEntity.visuallyConnected[3]) { + model.renderFront(); + } + + if(tileEntity.visuallyConnected[4]) { + model.renderLeft(); + } + + if(tileEntity.visuallyConnected[5]) { + model.renderRight(); + } + + model.renderMiddle(); + GL11.glPopMatrix(); + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) { + this.renderModelAt((TileEntityCopperWire)tileEntity, var2, var4, var6, var8); + } + +} diff --git a/src/main/java/basiccomponents/client/gui/GuiBatteryBox.java b/src/main/java/basiccomponents/client/gui/GuiBatteryBox.java new file mode 100644 index 0000000..e5bc2ad --- /dev/null +++ b/src/main/java/basiccomponents/client/gui/GuiBatteryBox.java @@ -0,0 +1,52 @@ +package basiccomponents.client.gui; + +import basiccomponents.common.container.ContainerBatteryBox; +import basiccomponents.common.tileentity.TileEntityBatteryBox; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.electricity.ElectricityDisplay; + +@SideOnly(Side.CLIENT) +public class GuiBatteryBox extends GuiContainer { + + private TileEntityBatteryBox tileEntity; + private int containerWidth; + private int containerHeight; + + + public GuiBatteryBox(InventoryPlayer par1InventoryPlayer, TileEntityBatteryBox batteryBox) { + super(new ContainerBatteryBox(par1InventoryPlayer, batteryBox)); + this.tileEntity = batteryBox; + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + this.fontRendererObj.drawString(this.tileEntity.getInventoryName(), 65, 6, 4210752); + String displayJoules = ElectricityDisplay.getDisplayShort(this.tileEntity.getJoules(), ElectricityDisplay.ElectricUnit.JOULES); + String displayMaxJoules = ElectricityDisplay.getDisplay(this.tileEntity.getMaxJoules(), ElectricityDisplay.ElectricUnit.JOULES); + if(this.tileEntity.isDisabled()) { + displayMaxJoules = "Disabled"; + } + + this.fontRendererObj.drawString(displayJoules + " of", 98 - displayJoules.length(), 30, 4210752); + this.fontRendererObj.drawString(displayMaxJoules, 78, 40, 4210752); + this.fontRendererObj.drawString("Voltage: " + (int)this.tileEntity.getVoltage(), 90, 60, 4210752); + this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + this.mc.renderEngine.bindTexture(new ResourceLocation("basiccomponents", "textures/gui/battery_box.png")); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.containerWidth = (this.width - this.xSize) / 2; + this.containerHeight = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize); + int scale = (int)(this.tileEntity.getJoules() / this.tileEntity.getMaxJoules() * 72.0D); + this.drawTexturedModalRect(this.containerWidth + 87, this.containerHeight + 52, 176, 0, scale, 20); + } +} diff --git a/src/main/java/basiccomponents/client/gui/GuiCoalGenerator.java b/src/main/java/basiccomponents/client/gui/GuiCoalGenerator.java new file mode 100644 index 0000000..41d179c --- /dev/null +++ b/src/main/java/basiccomponents/client/gui/GuiCoalGenerator.java @@ -0,0 +1,55 @@ +package basiccomponents.client.gui; + +import basiccomponents.common.container.ContainerCoalGenerator; +import basiccomponents.common.tileentity.TileEntityCoalGenerator; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.electricity.ElectricityDisplay; + +@SideOnly(Side.CLIENT) +public class GuiCoalGenerator extends GuiContainer { + + private TileEntityCoalGenerator tileEntity; + private int containerWidth; + private int containerHeight; + + + public GuiCoalGenerator(InventoryPlayer par1InventoryPlayer, TileEntityCoalGenerator tileEntity) { + super(new ContainerCoalGenerator(par1InventoryPlayer, tileEntity)); + this.tileEntity = tileEntity; + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + this.fontRendererObj.drawString(this.tileEntity.getInventoryName(), 55, 6, 4210752); + this.fontRendererObj.drawString("Generating", 90, 33, 4210752); + String displayText = ""; + if(this.tileEntity.isDisabled()) { + displayText = "Disabled"; + } else if(this.tileEntity.generateWatts <= 0.0D) { + displayText = "Not Generating"; + } else if(this.tileEntity.generateWatts < 100.0D) { + displayText = "Hull Heat: " + (int)(this.tileEntity.generateWatts / 100.0D * 100.0D) + "%"; + } else { + displayText = ElectricityDisplay.getDisplay(this.tileEntity.generateWatts, ElectricityDisplay.ElectricUnit.WATT); + } + + this.fontRendererObj.drawString(displayText, (int)(100.0D - (double)displayText.length() * 1.25D), 45, 4210752); + this.fontRendererObj.drawString("Voltage: " + (int)this.tileEntity.getVoltage(), 85, 60, 4210752); + this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + this.mc.renderEngine.bindTexture(new ResourceLocation("basiccomponents", "textures/gui/coal_generator.png")); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.containerWidth = (this.width - this.xSize) / 2; + this.containerHeight = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize); + } +} diff --git a/src/main/java/basiccomponents/client/gui/GuiElectricFurnace.java b/src/main/java/basiccomponents/client/gui/GuiElectricFurnace.java new file mode 100644 index 0000000..31a18da --- /dev/null +++ b/src/main/java/basiccomponents/client/gui/GuiElectricFurnace.java @@ -0,0 +1,60 @@ +package basiccomponents.client.gui; + +import basiccomponents.common.container.ContainerElectricFurnace; +import basiccomponents.common.tileentity.TileEntityElectricFurnace; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.electricity.ElectricityDisplay; + +@SideOnly(Side.CLIENT) +public class GuiElectricFurnace extends GuiContainer { + + private TileEntityElectricFurnace tileEntity; + private int containerWidth; + private int containerHeight; + + + public GuiElectricFurnace(InventoryPlayer par1InventoryPlayer, TileEntityElectricFurnace tileEntity) { + super(new ContainerElectricFurnace(par1InventoryPlayer, tileEntity)); + this.tileEntity = tileEntity; + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + this.fontRendererObj.drawString(this.tileEntity.getInventoryName(), 45, 6, 4210752); + this.fontRendererObj.drawString("Smelting:", 10, 28, 4210752); + this.fontRendererObj.drawString("Battery:", 10, 53, 4210752); + String displayText = ""; + if(this.tileEntity.isDisabled()) { + displayText = "Disabled!"; + } else if(this.tileEntity.processTicks > 0) { + displayText = "Smelting"; + } else { + displayText = "Idle"; + } + + this.fontRendererObj.drawString("Status: " + displayText, 82, 45, 4210752); + this.fontRendererObj.drawString(ElectricityDisplay.getDisplay(10000.0D, ElectricityDisplay.ElectricUnit.WATT), 82, 56, 4210752); + this.fontRendererObj.drawString(ElectricityDisplay.getDisplay(this.tileEntity.getVoltage(), ElectricityDisplay.ElectricUnit.VOLTAGE), 82, 68, 4210752); + this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + this.mc.renderEngine.bindTexture(new ResourceLocation("basiccomponents", "textures/gui/electric_furnace.png")); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.containerWidth = (this.width - this.xSize) / 2; + this.containerHeight = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize); + if(this.tileEntity.processTicks > 0) { + int scale = (int)((double)this.tileEntity.processTicks / 130.0D * 23.0D); + this.drawTexturedModalRect(this.containerWidth + 77, this.containerHeight + 24, 176, 0, 23 - scale, 20); + } + + } +} diff --git a/src/main/java/basiccomponents/common/BCGuiHandler.java b/src/main/java/basiccomponents/common/BCGuiHandler.java new file mode 100644 index 0000000..f462a4e --- /dev/null +++ b/src/main/java/basiccomponents/common/BCGuiHandler.java @@ -0,0 +1,57 @@ +package basiccomponents.common; + +import basiccomponents.client.gui.GuiBatteryBox; +import basiccomponents.client.gui.GuiCoalGenerator; +import basiccomponents.client.gui.GuiElectricFurnace; +import basiccomponents.common.container.ContainerBatteryBox; +import basiccomponents.common.container.ContainerCoalGenerator; +import basiccomponents.common.container.ContainerElectricFurnace; +import basiccomponents.common.tileentity.TileEntityBatteryBox; +import basiccomponents.common.tileentity.TileEntityCoalGenerator; +import basiccomponents.common.tileentity.TileEntityElectricFurnace; +import cpw.mods.fml.common.network.IGuiHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BCGuiHandler implements IGuiHandler { + + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity != null) { + if(tileEntity instanceof TileEntityBatteryBox) { + return new GuiBatteryBox(player.inventory, (TileEntityBatteryBox)tileEntity); + } + + if(tileEntity instanceof TileEntityCoalGenerator) { + return new GuiCoalGenerator(player.inventory, (TileEntityCoalGenerator)tileEntity); + } + + if(tileEntity instanceof TileEntityElectricFurnace) { + return new GuiElectricFurnace(player.inventory, (TileEntityElectricFurnace)tileEntity); + } + } + + return null; + } + + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + System.out.println("Open GUI"); + if(tileEntity != null) { + if(tileEntity instanceof TileEntityBatteryBox) { + return new ContainerBatteryBox(player.inventory, (TileEntityBatteryBox)tileEntity); + } + + if(tileEntity instanceof TileEntityCoalGenerator) { + return new ContainerCoalGenerator(player.inventory, (TileEntityCoalGenerator)tileEntity); + } + + if(tileEntity instanceof TileEntityElectricFurnace) { + return new ContainerElectricFurnace(player.inventory, (TileEntityElectricFurnace)tileEntity); + } + } + + return null; + } +} diff --git a/src/main/java/basiccomponents/common/BasicComponents.java b/src/main/java/basiccomponents/common/BasicComponents.java new file mode 100644 index 0000000..97b0468 --- /dev/null +++ b/src/main/java/basiccomponents/common/BasicComponents.java @@ -0,0 +1,328 @@ +package basiccomponents.common; + +import basiccomponents.client.RenderCopperWire; +import basiccomponents.common.BCGuiHandler; +import basiccomponents.common.CommonProxy; +import basiccomponents.common.block.BlockBase; +import basiccomponents.common.block.BlockBasicMachine; +import basiccomponents.common.block.BlockCopperWire; +import basiccomponents.common.item.ItemBase; +import basiccomponents.common.item.ItemBattery; +import basiccomponents.common.item.ItemBlockBasicMachine; +import basiccomponents.common.item.ItemBlockCopperWire; +import basiccomponents.common.item.ItemInfiniteBattery; +import basiccomponents.common.item.ItemIngot; +import basiccomponents.common.item.ItemPlate; +import basiccomponents.common.item.ItemWrench; +import basiccomponents.common.tileentity.TileEntityBatteryBox; +import basiccomponents.common.tileentity.TileEntityCoalGenerator; +import basiccomponents.common.tileentity.TileEntityCopperWire; +import basiccomponents.common.tileentity.TileEntityElectricFurnace; +import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Mod; +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.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.ReflectionHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.io.File; +import java.lang.reflect.Field; +import java.util.ArrayList; +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.item.ElectricItemHelper; +import universalelectricity.prefab.RecipeHelper; +import universalelectricity.prefab.TranslationHelper; +import universalelectricity.prefab.ore.OreGenBase; +import universalelectricity.prefab.ore.OreGenReplaceStone; +import universalelectricity.prefab.ore.OreGenerator; + +@Mod(modid = BasicComponents.MODID, name = BasicComponents.NAME, version = BasicComponents.VERSION) +public class BasicComponents { + + public static final String NAME = "Basic Components"; + public static final String MODID = "basiccomponents"; + public static final String VERSION = "1.0.0-dirty"; + public static String CHANNEL = ""; + public static final String RESOURCE_PATH = "/mods/basiccomponents/"; + public static CommonProxy proxy; + public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "BasicComponents.cfg")); + public static final String TEXTURE_DIRECTORY = "/mods/basiccomponents/textures/"; + public static final String GUI_DIRECTORY = "/mods/basiccomponents/textures/gui/"; + public static final String BLOCK_TEXTURE_DIRECTORY = "/mods/basiccomponents/textures/blocks/"; + public static final String ITEM_TEXTURE_DIRECTORY = "/mods/basiccomponents/textures/items/"; + public static final String MODEL_TEXTURE_DIRECTORY = "/mods/basiccomponents/textures/models/"; + public static final String TEXTURE_NAME_PREFIX = "basiccomponents:"; + public static final String LANGUAGE_PATH = "/mods/basiccomponents/languages/"; + private static final String[] LANGUAGES_SUPPORTED = new String[]{"en_US", "zh_CN", "es_ES", "it_IT", "nl_NL", "de_DE"}; + public static Block blockOreCopper; + public static Block blockOreTin; + public static Block blockCopperWire; + public static Block blockMachine; + public static Item itemBattery; + public static Item itemInfiniteBattery; + public static Item itemWrench; + public static Item itemMotor; + public static Item itemCircuitBasic; + public static Item itemCircuitAdvanced; + public static Item itemCircuitElite; + public static Item itemPlateCopper; + public static Item itemPlateTin; + public static Item itemPlateBronze; + public static Item itemPlateSteel; + public static Item itemPlateIron; + public static Item itemPlateGold; + public static Item itemIngotCopper; + public static Item itemIngotTin; + public static Item itemIngotSteel; + public static Item itemIngotBronze; + public static Item itemDustSteel; + public static Item itemDustBronze; + public static OreGenBase generationOreCopper; + public static OreGenBase generationOreTin; + public static final ArrayList bcDependants = new ArrayList(); + public static SimpleNetworkWrapper NETWRAPPER = NetworkRegistry.INSTANCE.newSimpleChannel("basiccomponents"); + @Mod.Instance + public static BasicComponents INSTANCE; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent e) { + + } + + @Mod.EventHandler + public void init(FMLInitializationEvent e) { + System.out.println("Basic Components Loaded: " + TranslationHelper.loadLanguages("/assets/basiccomponents/languages/", LANGUAGES_SUPPORTED) + " Languages."); + NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new BCGuiHandler()); + CONFIGURATION.load(); + registerIngots(); + registerPlates(); + registerDusts(); + + registerBattery(); + registerWrench(); + + registerTileEntities(); + registerOres(); + registerCopperWire(); + registerCircuits(); + registerMachines(); + CONFIGURATION.save(); + } + + @Mod.EventHandler + public void postInit(FMLPostInitializationEvent e) { + + } + + public static void registerDusts() { + if (OreDictionary.getOres("dustBronze").isEmpty()) { + itemDustBronze = new ItemBase("dustBronze"); + itemDustBronze.setCreativeTab(CreativeTabs.tabMaterials); + GameRegistry.registerItem(itemDustBronze, "dustBronze"); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemDustBronze), new Object[]{"!#!", Character.valueOf('!'), "ingotCopper", Character.valueOf('#'), "ingotTin"}), CONFIGURATION, true); + GameRegistry.addSmelting(itemDustBronze, (ItemStack)OreDictionary.getOres("ingotBronze").get(0), 0.6F); + } + if (OreDictionary.getOres("dustSteel").isEmpty()) { + itemDustSteel = new ItemBase("dustSteel"); + itemDustSteel.setCreativeTab(CreativeTabs.tabMaterials); + GameRegistry.registerItem(itemDustSteel, "dustSteel"); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemDustSteel), new Object[]{" C ", "CIC", " C ", Character.valueOf('I'), Items.iron_ingot, Character.valueOf('C'), Items.coal}), CONFIGURATION, true); + GameRegistry.addSmelting(itemDustSteel, (ItemStack)OreDictionary.getOres("ingotSteel").get(0), 0.6F); + } + } + + public static void registerPlates() { + if (OreDictionary.getOres("plateCopper").isEmpty()) { + itemPlateCopper = new ItemPlate("plateCopper"); + GameRegistry.registerItem(itemPlateCopper, "plateCopper"); + OreDictionary.registerOre("plateCopper", itemPlateCopper); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemPlateCopper), new Object[]{"!!", "!!", Character.valueOf('!'), "ingotCopper"}), CONFIGURATION, true); + } + if (OreDictionary.getOres("plateTin").isEmpty()) { + itemPlateTin = new ItemPlate("plateTin"); + GameRegistry.registerItem(itemPlateTin, "plateTin"); + OreDictionary.registerOre("plateTin", itemPlateTin); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemPlateTin), new Object[]{"!!", "!!", Character.valueOf('!'), "ingotTin"}), CONFIGURATION, true); + } + if (OreDictionary.getOres("plateIron").isEmpty()) { + itemPlateIron = new ItemPlate("plateIron"); + GameRegistry.registerItem(itemPlateIron, "plateIron"); + OreDictionary.registerOre("plateIron", itemPlateIron); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemPlateIron), new Object[]{"!!", "!!", Character.valueOf('!'), "ingotIron"}), CONFIGURATION, true); + } + if (OreDictionary.getOres("plateGold").isEmpty()) { + itemPlateGold = new ItemPlate("plateGold"); + GameRegistry.registerItem(itemPlateGold, "plateGold"); + OreDictionary.registerOre("plateGold", itemPlateGold); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemPlateGold), new Object[]{"!!", "!!", Character.valueOf('!'), "ingotGold"}), CONFIGURATION, true); + } + if (OreDictionary.getOres("plateBronze").isEmpty()) { + itemPlateBronze = new ItemPlate("plateBronze"); + GameRegistry.registerItem(itemPlateBronze, "plateBronze"); + OreDictionary.registerOre("plateBronze", itemPlateBronze); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemPlateBronze), new Object[]{"!!", "!!", Character.valueOf('!'), "ingotBronze"}), CONFIGURATION, true); + } + if (OreDictionary.getOres("plateSteel").isEmpty()) { + itemPlateSteel = new ItemPlate("plateSteel"); + GameRegistry.registerItem(itemPlateSteel, "plateSteel"); + OreDictionary.registerOre("plateSteel", itemPlateSteel); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemPlateSteel), new Object[]{"!!", "!!", Character.valueOf('!'), "ingotSteel"}), CONFIGURATION, true); + } + } + + public static void registerIngots() { + if (OreDictionary.getOres("ingotCopper").isEmpty()) { + itemIngotCopper = new ItemIngot("ingotCopper"); + GameRegistry.registerItem(itemIngotCopper, "ingotCopper"); + OreDictionary.registerOre("ingotCopper", itemIngotCopper); + } + if (OreDictionary.getOres("ingotTin").isEmpty()) { + itemIngotTin = new ItemIngot("ingotTin"); + GameRegistry.registerItem(itemIngotTin, "ingotTin"); + OreDictionary.registerOre("ingotTin", itemIngotTin); + } + if (OreDictionary.getOres("ingotBronze").isEmpty()) { + itemIngotBronze = new ItemIngot("ingotBronze"); + GameRegistry.registerItem(itemIngotBronze, "ingotBronze"); + OreDictionary.registerOre("ingotBronze", itemIngotBronze); + } + if (OreDictionary.getOres("ingotSteel").isEmpty()) { + itemIngotSteel = new ItemIngot("ingotSteel"); + GameRegistry.registerItem(itemIngotSteel, "ingotSteel"); + OreDictionary.registerOre("ingotSteel", itemIngotSteel); + } + } + + public static void registerCircuits() { + itemCircuitBasic = new ItemBase("circuitBasic"); + itemCircuitBasic.setCreativeTab(CreativeTabs.tabMaterials); + GameRegistry.registerItem(itemCircuitBasic, "circuitBasic"); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemCircuitBasic), new Object[]{"!#!", "#@#", "!#!", Character.valueOf('@'), "plateBronze", Character.valueOf('#'), Items.redstone, Character.valueOf('!'), "copperWire"}), CONFIGURATION, true); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemCircuitBasic), new Object[]{"!#!", "#@#", "!#!", Character.valueOf('@'), "plateSteel", Character.valueOf('#'), Items.redstone, Character.valueOf('!'), "copperWire"}), CONFIGURATION, true); + OreDictionary.registerOre("circuitBasic", itemCircuitBasic); + itemCircuitAdvanced = new ItemBase("circuitAdvanced"); + itemCircuitAdvanced.setCreativeTab(CreativeTabs.tabMaterials); + GameRegistry.registerItem(itemCircuitAdvanced, "circuitAdvanced"); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemCircuitAdvanced), new Object[]{"@@@", "#?#", "@@@", Character.valueOf('@'), Items.redstone, Character.valueOf('?'), Items.diamond, Character.valueOf('#'), "circuitBasic"}), CONFIGURATION, true); + OreDictionary.registerOre("circuitAdvanced", itemCircuitAdvanced); + itemCircuitElite = new ItemBase("circuitElite"); + itemCircuitElite.setCreativeTab(CreativeTabs.tabMaterials); + GameRegistry.registerItem(itemCircuitElite, "circuitElite"); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemCircuitAdvanced), new Object[]{"@@@", "?#?", "@@@", Character.valueOf('@'), Items.gold_ingot, Character.valueOf('?'), "circuitAdvanced", Character.valueOf('#'), Blocks.lapis_block}), CONFIGURATION, true); + OreDictionary.registerOre("circuitElite", itemCircuitElite); + itemMotor = new ItemBase("motor"); + itemMotor.setCreativeTab(CreativeTabs.tabMaterials); + GameRegistry.registerItem(itemMotor, "motor"); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemMotor), new Object[]{"@!@", "!#!", "@!@", Character.valueOf('!'), "ingotSteel", Character.valueOf('#'), Items.iron_ingot, Character.valueOf('@'), "copperWire"}), CONFIGURATION, true); + OreDictionary.registerOre("motor", itemMotor); + } + + public static void registerWrench() { + itemWrench = new ItemWrench(); + GameRegistry.registerItem(itemWrench, "wrench"); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemWrench), new Object[]{" S ", " SS", "S ", Character.valueOf('S'), Items.iron_ingot}), CONFIGURATION, true); + } + + public static void registerBattery() { + itemInfiniteBattery = new ItemInfiniteBattery("infiniteBattery"); + GameRegistry.registerItem(itemInfiniteBattery, "infiniteBattery"); + itemBattery = new ItemBattery("battery"); + GameRegistry.registerItem(itemBattery, "battery"); + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(itemBattery), new Object[]{" T ", "TRT", "TCT", Character.valueOf('T'), "ingotTin", Character.valueOf('R'), Items.redstone, Character.valueOf('C'), Items.coal}), CONFIGURATION, true); + OreDictionary.registerOre("battery", ElectricItemHelper.getUncharged(itemBattery)); + + } + + public static void registerOres() { + for (ItemStack stack : OreDictionary.getOres("oreCopper")) { + if (stack.getItem() instanceof ItemBlock) { + blockOreCopper = Block.getBlockFromItem(stack.getItem()); + break; + } + } + for (ItemStack stack : OreDictionary.getOres("oreTin")) { + if (stack.getItem() instanceof ItemBlock) { + blockOreTin = Block.getBlockFromItem(stack.getItem()); + break; + } + } + if (blockOreCopper == null) { + blockOreCopper = new BlockBase("oreCopper"); + GameRegistry.registerBlock(blockOreCopper, "oreCopper"); + GameRegistry.addSmelting(blockOreCopper, OreDictionary.getOres("ingotCopper").get(0), 0.6F); + generationOreCopper = new OreGenReplaceStone("oreCopper", "oreCopper", new ItemStack(blockOreCopper), 60, 22, 4); + OreGenerator.addOre(generationOreCopper); + } + if (blockOreTin == null) { + blockOreTin = new BlockBase("oreTin"); + GameRegistry.registerBlock(blockOreTin, "oreTin"); + GameRegistry.addSmelting(blockOreTin, OreDictionary.getOres("ingotTin").get(0), 0.6F); + generationOreTin = new OreGenReplaceStone("oreTin", "oreTin", new ItemStack(blockOreTin), 60, 22, 4); + OreGenerator.addOre(generationOreTin); + } + } + + public static void registerCopperWire() { + blockCopperWire = new BlockCopperWire(); + GameRegistry.registerBlock(blockCopperWire, ItemBlockCopperWire.class, "copperWire"); + if(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { + try { + registerCopperWireRenderer(); + } catch (Exception var8) { + FMLLog.severe("Basic Components copper wire registry error!", new Object[0]); + var8.printStackTrace(); + } + } + RecipeHelper.addRecipe(new ShapedOreRecipe(new ItemStack(blockCopperWire, 6), new Object[]{"WWW", "CCC", "WWW", Character.valueOf('W'), Blocks.wool, Character.valueOf('C'), "ingotCopper"}), CONFIGURATION, true); + UniversalElectricity.isNetworkActive = true; + OreDictionary.registerOre("copperWire", blockCopperWire); + } + + @SideOnly(Side.CLIENT) + private static void registerCopperWireRenderer() throws Exception { + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCopperWire.class, new RenderCopperWire()); + } + + public static ItemStack registerMachines() { + blockMachine = new BlockBasicMachine(0); + GameRegistry.registerBlock(blockMachine, ItemBlockBasicMachine.class, "basicMachine"); + ItemStack generator = ((BlockBasicMachine)blockMachine).getCoalGenerator(); + ItemStack bbox = ((BlockBasicMachine)blockMachine).getBatteryBox(); + ItemStack efurnace = ((BlockBasicMachine)blockMachine).getElectricFurnace(); + OreDictionary.registerOre("coalGenerator", generator.copy()); + OreDictionary.registerOre("batteryBox", bbox.copy()); + OreDictionary.registerOre("electricFurnace", efurnace.copy()); + RecipeHelper.addRecipe(new ShapedOreRecipe(bbox.copy(), new Object[]{"SSS", "BBB", "SSS", Character.valueOf('B'), "battery", Character.valueOf('S'), "ingotSteel"}), CONFIGURATION, true); + RecipeHelper.addRecipe(new ShapedOreRecipe(generator.copy(), new Object[]{"MMM", "MOM", "MCM", Character.valueOf('M'), "ingotSteel", Character.valueOf('C'), "motor", Character.valueOf('O'), Blocks.furnace}), CONFIGURATION, true); + RecipeHelper.addRecipe(new ShapedOreRecipe(generator.copy(), new Object[]{"MMM", "MOM", "MCM", Character.valueOf('M'), "ingotBronze", Character.valueOf('C'), "motor", Character.valueOf('O'), Blocks.furnace}), CONFIGURATION, true); + RecipeHelper.addRecipe(new ShapedOreRecipe(efurnace.copy(), new Object[]{"SSS", "SCS", "SMS", Character.valueOf('S'), "ingotSteel", Character.valueOf('C'), "circuitAdvanced", Character.valueOf('M'), "motor"}), CONFIGURATION, true); + + return new ItemStack(blockMachine); + } + + public static void registerTileEntities() { + GameRegistry.registerTileEntity(TileEntityBatteryBox.class, "UEBatteryBox"); + GameRegistry.registerTileEntity(TileEntityCoalGenerator.class, "UECoalGenerator"); + GameRegistry.registerTileEntity(TileEntityElectricFurnace.class, "UEElectricFurnace"); + GameRegistry.registerTileEntity(TileEntityCopperWire.class, "copperWire"); + } + +} diff --git a/src/main/java/basiccomponents/common/CommonProxy.java b/src/main/java/basiccomponents/common/CommonProxy.java new file mode 100644 index 0000000..9b46b83 --- /dev/null +++ b/src/main/java/basiccomponents/common/CommonProxy.java @@ -0,0 +1,11 @@ +package basiccomponents.common; + +import basiccomponents.common.tileentity.TileEntityCopperWire; +import cpw.mods.fml.common.registry.GameRegistry; + +public class CommonProxy { + + public void registerCopperWireTileEntity() { + GameRegistry.registerTileEntity(TileEntityCopperWire.class, "copperWire"); + } +} diff --git a/src/main/java/basiccomponents/common/block/BlockBase.java b/src/main/java/basiccomponents/common/block/BlockBase.java new file mode 100644 index 0000000..13e984c --- /dev/null +++ b/src/main/java/basiccomponents/common/block/BlockBase.java @@ -0,0 +1,17 @@ +package basiccomponents.common.block; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; + +public class BlockBase extends Block { + + public BlockBase(String name) { + super(Material.rock); + this.setCreativeTab(CreativeTabs.tabBlock); + this.setBlockName("basiccomponents:" + name); + this.setHardness(2.0F); + this.setBlockTextureName("basiccomponents:" + name); + + } +} diff --git a/src/main/java/basiccomponents/common/block/BlockBasicMachine.java b/src/main/java/basiccomponents/common/block/BlockBasicMachine.java new file mode 100644 index 0000000..b7ff418 --- /dev/null +++ b/src/main/java/basiccomponents/common/block/BlockBasicMachine.java @@ -0,0 +1,288 @@ +package basiccomponents.common.block; + +import basiccomponents.common.BasicComponents; +import basiccomponents.common.tileentity.TileEntityBatteryBox; +import basiccomponents.common.tileentity.TileEntityCoalGenerator; +import basiccomponents.common.tileentity.TileEntityElectricFurnace; +import java.util.List; +import java.util.Random; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.prefab.block.BlockAdvanced; + +public class BlockBasicMachine extends BlockAdvanced { + + public static final int COAL_GENERATOR_METADATA = 0; + public static final int BATTERY_BOX_METADATA = 4; + public static final int ELECTRIC_FURNACE_METADATA = 8; + private IIcon iconMachineSide; + private IIcon iconInput; + private IIcon iconOutput; + private IIcon iconCoalGenerator; + private IIcon iconBatteryBox; + private IIcon iconElectricFurnace; + + + public BlockBasicMachine(int textureIndex) { + super(UniversalElectricity.machine); + this.setBlockName("basiccomponents:bcMachine"); + this.setCreativeTab(CreativeTabs.tabDecorations); + this.setStepSound(soundTypeMetal); //TODO Metal Footstep + } + + @Override + public void registerBlockIcons(IIconRegister par1IconRegister) { + this.blockIcon = par1IconRegister.registerIcon("basiccomponents:machine"); + this.iconInput = par1IconRegister.registerIcon("basiccomponents:machine_input"); + this.iconOutput = par1IconRegister.registerIcon("basiccomponents:machine_output"); + this.iconMachineSide = par1IconRegister.registerIcon("basiccomponents:machine_side"); + this.iconCoalGenerator = par1IconRegister.registerIcon("basiccomponents:coalGenerator"); + this.iconBatteryBox = par1IconRegister.registerIcon("basiccomponents:batteryBox"); + this.iconElectricFurnace = par1IconRegister.registerIcon("basiccomponents:electricFurnace"); + } + + @Override + public void randomDisplayTick(World par1World, int x, int y, int z, Random par5Random) { + TileEntity tile = par1World.getTileEntity(x, y, z); + if(tile instanceof TileEntityCoalGenerator) { + TileEntityCoalGenerator tileEntity = (TileEntityCoalGenerator)tile; + if(tileEntity.generateWatts > 0.0D) { + int metadata = par1World.getBlockMetadata(x, y, z); + float var7 = (float)x + 0.5F; + float var8 = (float)y + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F; + float var9 = (float)z + 0.5F; + float var10 = 0.52F; + float var11 = par5Random.nextFloat() * 0.6F - 0.3F; + if(metadata == 3) { + par1World.spawnParticle("smoke", (double)(var7 - var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D); + par1World.spawnParticle("flame", (double)(var7 - var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D); + } else if(metadata == 2) { + par1World.spawnParticle("smoke", (double)(var7 + var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D); + par1World.spawnParticle("flame", (double)(var7 + var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D); + } else if(metadata == 1) { + par1World.spawnParticle("smoke", (double)(var7 + var11), (double)var8, (double)(var9 - var10), 0.0D, 0.0D, 0.0D); + par1World.spawnParticle("flame", (double)(var7 + var11), (double)var8, (double)(var9 - var10), 0.0D, 0.0D, 0.0D); + } else if(metadata == 0) { + par1World.spawnParticle("smoke", (double)(var7 + var11), (double)var8, (double)(var9 + var10), 0.0D, 0.0D, 0.0D); + par1World.spawnParticle("flame", (double)(var7 + var11), (double)var8, (double)(var9 + var10), 0.0D, 0.0D, 0.0D); + } + } + } + + } + + @Override + public IIcon getIcon(int side, int metadata) { + if(side != 0 && side != 1) { + if(metadata >= 8) { + metadata -= 8; + if(side == metadata + 2) { + return this.iconInput; + } + + if(side == ForgeDirection.getOrientation(metadata + 2).getOpposite().ordinal()) { + return this.iconElectricFurnace; + } + } else { + if(metadata >= 4) { + metadata -= 4; + if(side == metadata + 2) { + return this.iconOutput; + } + + if(side == ForgeDirection.getOrientation(metadata + 2).getOpposite().ordinal()) { + return this.iconInput; + } + + return this.iconBatteryBox; + } + + if(side == metadata + 2) { + return this.iconOutput; + } + + if(side == ForgeDirection.getOrientation(metadata + 2).getOpposite().ordinal()) { + return this.iconCoalGenerator; + } + } + + return this.iconMachineSide; + } else { + return this.blockIcon; + } + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) { + int metadata = world.getBlockMetadata(x, y, z); + int angle = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + byte change = 0; + switch(angle) { + case 0: + change = 1; + break; + case 1: + change = 2; + break; + case 2: + change = 0; + break; + case 3: + change = 3; + } + + if(metadata >= 8) { + world.setBlockMetadataWithNotify(x, y, z, 8 + change, 3); + } else if(metadata >= 4) { + switch(angle) { + case 0: + change = 3; + break; + case 1: + change = 1; + break; + case 2: + change = 2; + break; + case 3: + change = 0; + } + + world.setBlockMetadataWithNotify(x, y, z, 4 + change, 3); + } else { + world.setBlockMetadataWithNotify(x, y, z, 0 + change, 3); + } + + } + + public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + int metadata = par1World.getBlockMetadata(x, y, z); + int original = metadata; + int change = 0; + if(metadata >= 8) { + original = metadata - 8; + } else if(metadata >= 4) { + original = metadata - 4; + } + + switch(original) { + case 0: + change = 3; + break; + case 1: + change = 2; + break; + case 2: + change = 0; + break; + case 3: + change = 1; + } + + if(metadata >= 8) { + change += 8; + } else if(metadata >= 4) { + change += 4; + } + + par1World.setBlockMetadataWithNotify(x, y, z, change, 3); + return true; + } + + public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + int metadata = par1World.getBlockMetadata(x, y, z); + if(!par1World.isRemote) { + if(metadata >= 8) { + par5EntityPlayer.openGui(BasicComponents.INSTANCE, -1, par1World, x, y, z); + return true; + } else if(metadata >= 4) { + par5EntityPlayer.openGui(BasicComponents.INSTANCE, -1, par1World, x, y, z); + return true; + } else { + par5EntityPlayer.openGui(BasicComponents.INSTANCE, -1, par1World, x, y, z); + return true; + } + } else { + return true; + } + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public TileEntity createNewTileEntity(World world, int metadata) { + System.out.println("Create TE"); + return (TileEntity)(metadata >= 8?new TileEntityElectricFurnace():(metadata >= 4?new TileEntityBatteryBox():new TileEntityCoalGenerator())); + } + + @Override + public TileEntity createTileEntity(World var1, int meta) { + return createNewTileEntity(var1, meta); + } + + @Override + public boolean hasTileEntity(int metadata) { + return true; + } + + public ItemStack getCoalGenerator() { + return new ItemStack(Item.getItemFromBlock(this), 1, 0); + } + + public ItemStack getBatteryBox() { + return new ItemStack(Item.getItemFromBlock(this), 1, 4); + } + + public ItemStack getElectricFurnace() { + return new ItemStack(Item.getItemFromBlock(this), 1, 8); + } + + @Override + public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) { + par3List.add(this.getCoalGenerator()); + par3List.add(this.getBatteryBox()); + par3List.add(this.getElectricFurnace()); + } + + @Override + public int damageDropped(int metadata) { + return metadata >= 8?8:(metadata >= 4?4:0); + } + + //TODO WTF + /*@Override + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { + int id = this.func_71922_a(world, x, y, z); + if(id == 0) { + return null; + } else { + Item item = Item.field_77698_e[id]; + if(item == null) { + return null; + } else { + int metadata = this.func_71873_h(world, x, y, z); + return new ItemStack(id, 1, metadata); + } + } + }*/ +} diff --git a/src/main/java/basiccomponents/common/block/BlockCopperWire.java b/src/main/java/basiccomponents/common/block/BlockCopperWire.java new file mode 100644 index 0000000..da32e63 --- /dev/null +++ b/src/main/java/basiccomponents/common/block/BlockCopperWire.java @@ -0,0 +1,45 @@ +package basiccomponents.common.block; + +import basiccomponents.common.BasicComponents; +import basiccomponents.common.tileentity.TileEntityCopperWire; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.prefab.block.BlockConductor; + +public class BlockCopperWire extends BlockConductor { + + public BlockCopperWire() { + super(Material.cloth); + this.setBlockName("basiccomponents:copperWire"); + this.setStepSound(soundTypeCloth); + this.setResistance(0.2F); + this.setHardness(0.1F); + this.setBlockBounds(0.3F, 0.3F, 0.3F, 0.7F, 0.7F, 0.7F); + this.setCreativeTab(CreativeTabs.tabRedstone); + //TODO this + //Block.setBurnProperties(this.field_71990_ca, 30, 60); + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public int getRenderType() { + return -1; + } + + @Override + public TileEntity createNewTileEntity(World var1, int meta) { + return new TileEntityCopperWire(); + } +} diff --git a/src/main/java/basiccomponents/common/container/ContainerBatteryBox.java b/src/main/java/basiccomponents/common/container/ContainerBatteryBox.java new file mode 100644 index 0000000..06a30e6 --- /dev/null +++ b/src/main/java/basiccomponents/common/container/ContainerBatteryBox.java @@ -0,0 +1,82 @@ +package basiccomponents.common.container; + +import basiccomponents.common.tileentity.TileEntityBatteryBox; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import universalelectricity.core.item.IItemElectric; +import universalelectricity.prefab.SlotSpecific; + +public class ContainerBatteryBox extends Container { + + private TileEntityBatteryBox tileEntity; + + + public ContainerBatteryBox(InventoryPlayer par1InventoryPlayer, TileEntityBatteryBox batteryBox) { + this.tileEntity = batteryBox; + this.addSlotToContainer(new SlotSpecific(batteryBox, 0, 33, 24, new Class[]{IItemElectric.class})); + this.addSlotToContainer(new SlotSpecific(batteryBox, 1, 33, 48, new Class[]{IItemElectric.class})); + + int var3; + for(var3 = 0; var3 < 3; ++var3) { + for(int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } + + for(var3 = 0; var3 < 9; ++var3) { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142)); + } + + this.tileEntity.playersUsing.add(par1InventoryPlayer.player); + } + + public void onContainerClosed(EntityPlayer entityplayer) { + super.onContainerClosed(entityplayer); + this.tileEntity.playersUsing.remove(entityplayer); + } + + public boolean canInteractWith(EntityPlayer par1EntityPlayer) { + return this.tileEntity.isUseableByPlayer(par1EntityPlayer); + } + + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotID) { + ItemStack returnStack = null; + Slot slot = (Slot)super.inventorySlots.get(slotID); + if(slot != null && slot.getHasStack()) { + ItemStack itemStack = slot.getStack(); + returnStack = itemStack.copy(); + if(slotID != 0 && slotID != 1) { + if(this.getSlot(0).isItemValid(itemStack)) { + if(((IItemElectric)itemStack.getItem()).getProvideRequest(itemStack).getWatts() > 0.0D) { + if(!this.mergeItemStack(itemStack, 1, 2, false)) { + return null; + } + } else if(!this.mergeItemStack(itemStack, 0, 1, false)) { + return null; + } + } else if(slotID >= 30 && slotID < 38 && !this.mergeItemStack(itemStack, 3, 30, false)) { + return null; + } + } else if(!this.mergeItemStack(itemStack, 3, 38, false)) { + return null; + } + + if(itemStack.stackSize == 0) { + slot.putStack((ItemStack)null); + } else { + slot.onSlotChanged(); + } + + if(itemStack.stackSize == returnStack.stackSize) { + return null; + } + + slot.onPickupFromSlot(par1EntityPlayer, itemStack); + } + + return returnStack; + } +} diff --git a/src/main/java/basiccomponents/common/container/ContainerCoalGenerator.java b/src/main/java/basiccomponents/common/container/ContainerCoalGenerator.java new file mode 100644 index 0000000..a666020 --- /dev/null +++ b/src/main/java/basiccomponents/common/container/ContainerCoalGenerator.java @@ -0,0 +1,77 @@ +package basiccomponents.common.container; + +import basiccomponents.common.tileentity.TileEntityCoalGenerator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class ContainerCoalGenerator extends Container { + + private TileEntityCoalGenerator tileEntity; + + + public ContainerCoalGenerator(InventoryPlayer par1InventoryPlayer, TileEntityCoalGenerator tileEntity) { + this.tileEntity = tileEntity; + this.addSlotToContainer(new Slot(tileEntity, 0, 33, 34)); + + int var3; + for(var3 = 0; var3 < 3; ++var3) { + for(int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } + + for(var3 = 0; var3 < 9; ++var3) { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142)); + } + + tileEntity.playersUsing.add(par1InventoryPlayer.player); + } + + public void onContainerClosed(EntityPlayer entityplayer) { + super.onContainerClosed(entityplayer); + this.tileEntity.playersUsing.remove(entityplayer); + } + + public boolean canInteractWith(EntityPlayer par1EntityPlayer) { + return this.tileEntity.isUseableByPlayer(par1EntityPlayer); + } + + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) { + ItemStack var2 = null; + Slot var3 = (Slot)super.inventorySlots.get(par1); + if(var3 != null && var3.getHasStack()) { + ItemStack var4 = var3.getStack(); + var2 = var4.copy(); + if(par1 != 0) { + if(var4.getItem() == Items.coal) { + if(!this.mergeItemStack(var4, 0, 1, false)) { + return null; + } + } else if(par1 >= 30 && par1 < 37 && !this.mergeItemStack(var4, 3, 30, false)) { + return null; + } + } else if(!this.mergeItemStack(var4, 3, 37, false)) { + return null; + } + + if(var4.stackSize == 0) { + var3.putStack((ItemStack)null); + } else { + var3.onSlotChanged(); + } + + if(var4.stackSize == var2.stackSize) { + return null; + } + + var3.onPickupFromSlot(par1EntityPlayer, var4); + } + + return var2; + } +} diff --git a/src/main/java/basiccomponents/common/container/ContainerElectricFurnace.java b/src/main/java/basiccomponents/common/container/ContainerElectricFurnace.java new file mode 100644 index 0000000..8a46660 --- /dev/null +++ b/src/main/java/basiccomponents/common/container/ContainerElectricFurnace.java @@ -0,0 +1,95 @@ +package basiccomponents.common.container; + +import basiccomponents.common.tileentity.TileEntityElectricFurnace; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.inventory.SlotFurnace; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; +import universalelectricity.core.item.IItemElectric; +import universalelectricity.prefab.SlotSpecific; + +public class ContainerElectricFurnace extends Container { + + private TileEntityElectricFurnace tileEntity; + + + public ContainerElectricFurnace(InventoryPlayer par1InventoryPlayer, TileEntityElectricFurnace tileEntity) { + this.tileEntity = tileEntity; + this.addSlotToContainer(new SlotSpecific(tileEntity, 0, 55, 49, new Class[]{IItemElectric.class})); + this.addSlotToContainer(new Slot(tileEntity, 1, 55, 25)); + this.addSlotToContainer(new SlotFurnace(par1InventoryPlayer.player, tileEntity, 2, 108, 25)); + + int var3; + for(var3 = 0; var3 < 3; ++var3) { + for(int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } + + for(var3 = 0; var3 < 9; ++var3) { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142)); + } + + tileEntity.playersUsing.add(par1InventoryPlayer.player); + } + + public void onContainerClosed(EntityPlayer entityplayer) { + super.onContainerClosed(entityplayer); + this.tileEntity.playersUsing.remove(entityplayer); + } + + public boolean canInteractWith(EntityPlayer par1EntityPlayer) { + return this.tileEntity.isUseableByPlayer(par1EntityPlayer); + } + + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) { + ItemStack var2 = null; + Slot var3 = (Slot)super.inventorySlots.get(par1); + if(var3 != null && var3.getHasStack()) { + ItemStack var4 = var3.getStack(); + var2 = var4.copy(); + if(par1 == 2) { + if(!this.mergeItemStack(var4, 3, 39, true)) { + return null; + } + + var3.onSlotChange(var4, var2); + } else if(par1 != 1 && par1 != 0) { + if(var4.getItem() instanceof IItemElectric) { + if(!this.mergeItemStack(var4, 0, 1, false)) { + return null; + } + } else if(FurnaceRecipes.smelting().getSmeltingResult(var4) != null) { + if(!this.mergeItemStack(var4, 1, 2, false)) { + return null; + } + } else if(par1 >= 3 && par1 < 30) { + if(!this.mergeItemStack(var4, 30, 39, false)) { + return null; + } + } else if(par1 >= 30 && par1 < 39 && !this.mergeItemStack(var4, 3, 30, false)) { + return null; + } + } else if(!this.mergeItemStack(var4, 3, 39, false)) { + return null; + } + + if(var4.stackSize == 0) { + var3.putStack((ItemStack)null); + } else { + var3.onSlotChanged(); + } + + if(var4.stackSize == var2.stackSize) { + return null; + } + + var3.onPickupFromSlot(par1EntityPlayer, var4); + } + + return var2; + } +} diff --git a/src/main/java/basiccomponents/common/item/ItemBase.java b/src/main/java/basiccomponents/common/item/ItemBase.java new file mode 100644 index 0000000..50b9576 --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemBase.java @@ -0,0 +1,17 @@ +package basiccomponents.common.item; + +import basiccomponents.common.BasicComponents; +import net.minecraft.item.Item; +import net.minecraft.util.IIcon; + +public class ItemBase extends Item { + + protected final IIcon[] icons = new IIcon[256]; + + public ItemBase(String name) { + super(); + this.setUnlocalizedName("basiccomponents:" + name); + this.setTextureName("basiccomponents:" + name); + this.setNoRepair(); + } +} diff --git a/src/main/java/basiccomponents/common/item/ItemBattery.java b/src/main/java/basiccomponents/common/item/ItemBattery.java new file mode 100644 index 0000000..61e9b89 --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemBattery.java @@ -0,0 +1,32 @@ +package basiccomponents.common.item; + +import basiccomponents.common.BasicComponents; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.ItemStack; +import universalelectricity.core.item.ItemElectric; + +public class ItemBattery extends ItemElectric { + + public ItemBattery(String name) { + super(); + this.setUnlocalizedName("basiccomponents:" + name); + this.setCreativeTab(CreativeTabs.tabRedstone); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerIcons(IIconRegister iconRegister) { + this.itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().replace("item.", "")); + } + + public double getMaxJoules(ItemStack itemStack) { + return 1000000.0D; + } + + public double getVoltage(ItemStack itemStack) { + return 25.0D; + } +} diff --git a/src/main/java/basiccomponents/common/item/ItemBlockBasicMachine.java b/src/main/java/basiccomponents/common/item/ItemBlockBasicMachine.java new file mode 100644 index 0000000..a40525f --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemBlockBasicMachine.java @@ -0,0 +1,33 @@ +package basiccomponents.common.item; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +public class ItemBlockBasicMachine extends ItemBlock { + + public ItemBlockBasicMachine(Block block) { + super(block); + this.setMaxDamage(0); + this.setHasSubtypes(true); + } + + public int getMetadata(int damage) { + return damage; + } + + public String getUnlocalizedName(ItemStack itemstack) { + byte metadata = 0; + if(itemstack.getItemDamage() >= 8) { + metadata = 2; + } else if(itemstack.getItemDamage() >= 4) { + metadata = 1; + } + + return this.field_150939_a.getUnlocalizedName() + "." + metadata; + } + + public String getUnlocalizedName() { + return this.field_150939_a.getUnlocalizedName() + ".0"; + } +} diff --git a/src/main/java/basiccomponents/common/item/ItemBlockCopperWire.java b/src/main/java/basiccomponents/common/item/ItemBlockCopperWire.java new file mode 100644 index 0000000..211bae9 --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemBlockCopperWire.java @@ -0,0 +1,44 @@ +package basiccomponents.common.item; + +import basiccomponents.common.tileentity.TileEntityCopperWire; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import universalelectricity.core.electricity.ElectricityDisplay; + +public class ItemBlockCopperWire extends ItemBlock { + + IIcon icon; + + public ItemBlockCopperWire(Block block) { + super(block); + this.setMaxDamage(0); + this.setHasSubtypes(true); + this.setTextureName("basiccomponents:copperWire"); + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIconFromDamage(int meta) { + return icon; + } + + @SideOnly(Side.CLIENT) + @Override + public void registerIcons(IIconRegister reg) { + icon = reg.registerIcon("basiccomponents:copperWire"); + } + + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { + par3List.add("Resistance: " + ElectricityDisplay.getDisplay(TileEntityCopperWire.RESISTANCE, ElectricityDisplay.ElectricUnit.RESISTANCE)); + par3List.add("Max Amps: " + ElectricityDisplay.getDisplay(TileEntityCopperWire.MAX_AMPS, ElectricityDisplay.ElectricUnit.AMPERE)); + } +} diff --git a/src/main/java/basiccomponents/common/item/ItemCircuit.java b/src/main/java/basiccomponents/common/item/ItemCircuit.java new file mode 100644 index 0000000..5cae031 --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemCircuit.java @@ -0,0 +1,34 @@ +package basiccomponents.common.item; + +import basiccomponents.common.item.ItemBase; +import java.util.List; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.ItemStack; + +public class ItemCircuit extends ItemBase { + + public static final String[] TYPES = new String[]{"circuitBasic", "circuitAdvanced", "circuitElite"}; + + + public ItemCircuit(int texture) { + super("circuit"); + this.setMaxDamage(0); + this.setHasSubtypes(true); + } + + public int getMetadata(int damage) { + return damage; + } + + public String getUnlocalizedName(ItemStack itemStack) { + return "item.basiccomponents:" + TYPES[itemStack.getItemDamage()]; + } + + public void func_77633_a(int par1, CreativeTabs par2CreativeTabs, List list) { + for(int i = 0; i < TYPES.length; ++i) { + list.add(new ItemStack(this, 1, i)); + } + + } + +} diff --git a/src/main/java/basiccomponents/common/item/ItemInfiniteBattery.java b/src/main/java/basiccomponents/common/item/ItemInfiniteBattery.java new file mode 100644 index 0000000..be8aa2b --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemInfiniteBattery.java @@ -0,0 +1,53 @@ +package basiccomponents.common.item; + +import basiccomponents.common.item.ItemBase; +import java.util.List; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.IItemElectric; + +public class ItemInfiniteBattery extends ItemBase implements IItemElectric { + + public ItemInfiniteBattery(String name) { + super(name); + this.setMaxStackSize(1); + this.setNoRepair(); + this.setCreativeTab(CreativeTabs.tabRedstone); + } + + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { + par3List.add("§2Infinite"); + } + + public double getJoules(ItemStack itemStack) { + return this.getMaxJoules(itemStack); + } + + public void setJoules(double joules, ItemStack itemStack) {} + + public double getMaxJoules(ItemStack itemStack) { + return Double.POSITIVE_INFINITY; + } + + public double getVoltage(ItemStack itemStack) { + return 25.0D; + } + + public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) { + return electricityPack; + } + + public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) { + return electricityPack; + } + + public ElectricityPack getReceiveRequest(ItemStack itemStack) { + return new ElectricityPack(Double.POSITIVE_INFINITY, this.getVoltage(itemStack)); + } + + public ElectricityPack getProvideRequest(ItemStack itemStack) { + return new ElectricityPack(Double.POSITIVE_INFINITY, this.getVoltage(itemStack)); + } +} diff --git a/src/main/java/basiccomponents/common/item/ItemIngot.java b/src/main/java/basiccomponents/common/item/ItemIngot.java new file mode 100644 index 0000000..afb4796 --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemIngot.java @@ -0,0 +1,11 @@ +package basiccomponents.common.item; + +import net.minecraft.creativetab.CreativeTabs; + +public class ItemIngot extends ItemBase { + + public ItemIngot(String name) { + super(name); + this.setCreativeTab(CreativeTabs.tabMaterials); + } +} diff --git a/src/main/java/basiccomponents/common/item/ItemPlate.java b/src/main/java/basiccomponents/common/item/ItemPlate.java new file mode 100644 index 0000000..c1ad6a6 --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemPlate.java @@ -0,0 +1,11 @@ +package basiccomponents.common.item; + +import net.minecraft.creativetab.CreativeTabs; + +public class ItemPlate extends ItemBase { + + public ItemPlate(String name) { + super(name); + this.setCreativeTab(CreativeTabs.tabMaterials); + } +} diff --git a/src/main/java/basiccomponents/common/item/ItemWrench.java b/src/main/java/basiccomponents/common/item/ItemWrench.java new file mode 100644 index 0000000..4ca912a --- /dev/null +++ b/src/main/java/basiccomponents/common/item/ItemWrench.java @@ -0,0 +1,51 @@ +package basiccomponents.common.item; + +import basiccomponents.common.item.ItemBase; +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.prefab.implement.IToolConfigurator; + +public class ItemWrench extends ItemBase implements IToolConfigurator { + + public ItemWrench() { + super("wrench"); + this.setMaxStackSize(1); + this.setCreativeTab(CreativeTabs.tabTools); + } + + public boolean canWrench(EntityPlayer entityPlayer, int x, int y, int z) { + return true; + } + + public void wrenchUsed(EntityPlayer entityPlayer, int x, int y, int z) {} + + public boolean onItemUseFirst(ItemStack stack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + Block block = world.getBlock(x, y, z); + if(block != Blocks.furnace && block != Blocks.lit_furnace && block != Blocks.dropper && block != Blocks.hopper && block != Blocks.dispenser && block != Blocks.piston && block != Blocks.sticky_piston) { + return false; + } else { + int metadata = world.getBlockMetadata(x, y, z); + int[] rotationMatrix = new int[]{1, 2, 3, 4, 5, 0}; + if(block == Blocks.furnace || block == Blocks.lit_furnace) { + rotationMatrix = ForgeDirection.ROTATION_MATRIX[0]; + } + + world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.getOrientation(rotationMatrix[metadata]).ordinal(), 3); + this.wrenchUsed(entityPlayer, x, y, z); + return true; + } + } + + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + return false; + } + + public boolean shouldPassSneakingClickToBlock(World world, int x, int y, int z) { + return true; + } +} diff --git a/src/main/java/basiccomponents/common/tileentity/TileEntityBatteryBox.java b/src/main/java/basiccomponents/common/tileentity/TileEntityBatteryBox.java new file mode 100644 index 0000000..43f4940 --- /dev/null +++ b/src/main/java/basiccomponents/common/tileentity/TileEntityBatteryBox.java @@ -0,0 +1,251 @@ +package basiccomponents.common.tileentity; + +import basiccomponents.common.BasicComponents; +import com.google.common.io.ByteArrayDataInput; +import cpw.mods.fml.common.registry.LanguageRegistry; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IElectricityStorage; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.item.ElectricItemHelper; +import universalelectricity.core.item.IItemElectric; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; +import universalelectricity.prefab.tile.TileEntityElectricityStorage; + +public class TileEntityBatteryBox extends TileEntityElectricityStorage implements IElectricityStorage, ISidedInventory { + + private ItemStack[] containingItems = new ItemStack[2]; + public final Set playersUsing = new HashSet(); + + + @Override + public void updateEntity() { + super.updateEntity(); + if(!this.isDisabled() && !this.worldObj.isRemote) { + this.setJoules(this.getJoules() - ElectricItemHelper.chargeItem(this.containingItems[0], this.getJoules(), this.getVoltage())); + this.setJoules(this.getJoules() + ElectricItemHelper.dechargeItem(this.containingItems[1], this.getMaxJoules() - this.getJoules(), this.getVoltage())); + ForgeDirection i$ = ForgeDirection.getOrientation(this.getBlockMetadata() - 4 + 2); + TileEntity player = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), i$.getOpposite()); + TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), i$); + IElectricityNetwork inputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(player, i$.getOpposite()); + IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, i$); + if(outputNetwork != null && inputNetwork != outputNetwork) { + double outputWatts = Math.min(outputNetwork.getRequest(new TileEntity[]{this}).getWatts(), Math.min(this.getJoules(), 10000.0D)); + if(this.getJoules() > 0.0D && outputWatts > 0.0D) { + outputNetwork.startProducing(this, outputWatts / this.getVoltage(), this.getVoltage()); + this.setJoules(this.getJoules() - outputWatts); + } else { + outputNetwork.stopProducing(this); + } + } + } + + this.setJoules(this.getJoules() - 5.0E-5D); + if(!this.worldObj.isRemote && super.ticks % 3L == 0L) { + /*Iterator i$1 = this.playersUsing.iterator(); + + while(i$1.hasNext()) { + EntityPlayer player1 = (EntityPlayer)i$1.next(); + + PacketDispatcher.sendPacketToPlayer(this.func_70319_e(), (Player)player1); + }*/ + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + } + + public boolean canConnect(ForgeDirection direction) { + return direction == ForgeDirection.getOrientation(this.getBlockMetadata() - 4 + 2) || direction == ForgeDirection.getOrientation(this.getBlockMetadata() - 4 + 2).getOpposite(); + } + + protected EnumSet getConsumingSides() { + return EnumSet.of(ForgeDirection.getOrientation(this.getBlockMetadata() - 4 + 2).getOpposite()); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setDouble("joules", this.getJoules()); + nbt.setInteger("disabledTicks", super.disabledTicks); + //return PacketManager.getPacket(BasicComponents.CHANNEL, this, new Object[]{Double.valueOf(this.getJoules()), Integer.valueOf(super.disabledTicks)}); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(), nbt); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if (this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.setJoules(nbt.getDouble("joules")); + super.disabledTicks = nbt.getInteger("disabledTicks"); + } + } + + /*public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { + try { + this.setJoules(dataStream.readDouble()); + super.disabledTicks = dataStream.readInt(); + } catch (Exception var7) { + var7.printStackTrace(); + } + + }*/ + + + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public void readFromNBT(NBTTagCompound par1NBTTagCompound) { + super.readFromNBT(par1NBTTagCompound); + NBTTagList var2 = par1NBTTagCompound.getTagList("Items", 10); + this.containingItems = new ItemStack[this.getSizeInventory()]; + + for(int var3 = 0; var3 < var2.tagCount(); ++var3) { + NBTTagCompound var4 = (NBTTagCompound)var2.getCompoundTagAt(var3); + byte var5 = var4.getByte("Slot"); + if(var5 >= 0 && var5 < this.containingItems.length) { + this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4); + } + } + + } + + @Override + public void writeToNBT(NBTTagCompound par1NBTTagCompound) { + super.writeToNBT(par1NBTTagCompound); + NBTTagList var2 = new NBTTagList(); + + for(int var3 = 0; var3 < this.containingItems.length; ++var3) { + if(this.containingItems[var3] != null) { + NBTTagCompound var4 = new NBTTagCompound(); + var4.setByte("Slot", (byte)var3); + this.containingItems[var3].writeToNBT(var4); + var2.appendTag(var4); + } + } + + par1NBTTagCompound.setTag("Items", var2); + } + + public int getSizeInventory() { + return this.containingItems.length; + } + + public ItemStack getStackInSlot(int par1) { + return this.containingItems[par1]; + } + + public ItemStack decrStackSize(int par1, int par2) { + if(this.containingItems[par1] != null) { + ItemStack var3; + if(this.containingItems[par1].stackSize <= par2) { + var3 = this.containingItems[par1]; + this.containingItems[par1] = null; + return var3; + } else { + var3 = this.containingItems[par1].splitStack(par2); + if(this.containingItems[par1].stackSize == 0) { + this.containingItems[par1] = null; + } + + return var3; + } + } else { + return null; + } + } + + public ItemStack getStackInSlotOnClosing(int par1) { + if(this.containingItems[par1] != null) { + ItemStack var2 = this.containingItems[par1]; + this.containingItems[par1] = null; + return var2; + } else { + return null; + } + } + + public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { + this.containingItems[par1] = par2ItemStack; + if(par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { + par2ItemStack.stackSize = this.getInventoryStackLimit(); + } + + } + + @Override + public String getInventoryName() { + return LanguageRegistry.instance().getStringLocalization("tile.basiccomponents:bcMachine.1.name"); + } + + public int getInventoryStackLimit() { + return 1; + } + + public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this?false:par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; + } + + public double getMaxJoules() { + return 5000000.0D; + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + public boolean isItemValidForSlot(int slotID, ItemStack itemstack) { + return itemstack.getItem() instanceof IItemElectric; + } + + public int[] getAccessibleSlotsFromSide(int slotID) { + return new int[]{0, 1}; + } + + public boolean canInsertItem(int slotID, ItemStack itemstack, int side) { + if(this.isItemValidForSlot(slotID, itemstack)) { + if(slotID == 0) { + return ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() > 0.0D; + } + + if(slotID == 1) { + return ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() > 0.0D; + } + } + + return false; + } + + public boolean canExtractItem(int slotID, ItemStack itemstack, int side) { + if(this.isItemValidForSlot(slotID, itemstack)) { + if(slotID == 0) { + return ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() <= 0.0D; + } + + if(slotID == 1) { + return ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() <= 0.0D; + } + } + + return false; + } +} diff --git a/src/main/java/basiccomponents/common/tileentity/TileEntityCoalGenerator.java b/src/main/java/basiccomponents/common/tileentity/TileEntityCoalGenerator.java new file mode 100644 index 0000000..e5f7ce0 --- /dev/null +++ b/src/main/java/basiccomponents/common/tileentity/TileEntityCoalGenerator.java @@ -0,0 +1,263 @@ +package basiccomponents.common.tileentity; + +import basiccomponents.common.BasicComponents; +import com.google.common.io.ByteArrayDataInput; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.registry.LanguageRegistry; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; +import universalelectricity.prefab.tile.TileEntityElectrical; + +public class TileEntityCoalGenerator extends TileEntityElectrical implements IInventory, ISidedInventory { + + public static final int MAX_GENERATE_WATTS = 10000; + public static final int MIN_GENERATE_WATTS = 100; + private static final float BASE_ACCELERATION = 0.3F; + public double prevGenerateWatts; + public double generateWatts = 0.0D; + public IConductor connectedElectricUnit = null; + public int itemCookTime = 0; + private ItemStack[] containingItems = new ItemStack[1]; + public final Set playersUsing = new HashSet(); + + + public boolean canConnect(ForgeDirection direction) { + return direction == ForgeDirection.getOrientation(this.getBlockMetadata() - 0 + 2); + } + + @Override + public void updateEntity() { + super.updateEntity(); + if(!this.worldObj.isRemote) { + this.prevGenerateWatts = this.generateWatts; + ForgeDirection outputDirection = ForgeDirection.getOrientation(this.getBlockMetadata() - 0 + 2); + TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3((double)this.xCoord, (double)this.yCoord, (double)this.zCoord), outputDirection); + IElectricityNetwork network = ElectricityNetworkHelper.getNetworkFromTileEntity(outputTile, outputDirection); + if(network != null) { + if(network.getRequest(new TileEntity[0]).getWatts() > 0.0D) { + this.connectedElectricUnit = (IConductor)outputTile; + } else { + this.connectedElectricUnit = null; + } + } else { + this.connectedElectricUnit = null; + } + + if(!this.isDisabled()) { + if(this.itemCookTime > 0) { + --this.itemCookTime; + if(this.connectedElectricUnit != null) { + this.generateWatts = Math.min(this.generateWatts + Math.min(this.generateWatts * 0.005D + 0.30000001192092896D, 5.0D), 10000.0D); + } + } + + if(this.containingItems[0] != null && this.connectedElectricUnit != null && this.containingItems[0].getItem() == Items.coal && this.itemCookTime <= 0) { //TODO DON'T HARDCOE FUEL!!! + this.itemCookTime = 320; + this.decrStackSize(0, 1); + } + + if(this.connectedElectricUnit == null || this.itemCookTime <= 0) { + this.generateWatts = Math.max(this.generateWatts - 8.0D, 0.0D); + } + + if(this.connectedElectricUnit != null) { + if(this.generateWatts > 100.0D) { + this.connectedElectricUnit.getNetwork().startProducing(this, this.generateWatts / this.getVoltage() / 20.0D, this.getVoltage()); + } else { + this.connectedElectricUnit.getNetwork().stopProducing(this); + } + } + } + + if(super.ticks % 3L == 0L) { + /*Iterator i$ = this.playersUsing.iterator(); + + while(i$.hasNext()) { + EntityPlayer player = (EntityPlayer)i$.next(); + PacketDispatcher.sendPacketToPlayer(this.func_70319_e(), (Player)player); + }*/ + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + if(this.prevGenerateWatts <= 0.0D && this.generateWatts > 0.0D || this.prevGenerateWatts > 0.0D && this.generateWatts <= 0.0D) { + //PacketManager.sendPacketToClients(this.func_70319_e(), this.field_70331_k); + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setDouble("generateWatts", this.generateWatts); + nbt.setInteger("itemCookTime", this.itemCookTime); + nbt.setInteger("disabledTicks", super.disabledTicks); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(), nbt); + //return PacketManager.getPacket(BasicComponents.CHANNEL, this, new Object[]{Double.valueOf(this.generateWatts), Integer.valueOf(this.itemCookTime), Integer.valueOf(super.disabledTicks)}); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if (this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.generateWatts = nbt.getDouble("generateWatts"); + this.itemCookTime = nbt.getInteger("itemCookTime"); + super.disabledTicks = nbt.getInteger("disabledTicks"); + } + } + + /*public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { + try { + if(this.field_70331_k.isRemote) { + this.generateWatts = dataStream.readDouble(); + this.itemCookTime = dataStream.readInt(); + super.disabledTicks = dataStream.readInt(); + } + } catch (Exception var7) { + var7.printStackTrace(); + } + + }*/ + + public void openInventory() {} + + public void closeInventory() {} + + @Override + public void readFromNBT(NBTTagCompound par1NBTTagCompound) { + super.readFromNBT(par1NBTTagCompound); + this.itemCookTime = par1NBTTagCompound.getInteger("itemCookTime"); + this.generateWatts = par1NBTTagCompound.getDouble("generateRate"); + NBTTagList var2 = par1NBTTagCompound.getTagList("Items", 10); + this.containingItems = new ItemStack[this.getSizeInventory()]; + + for(int var3 = 0; var3 < var2.tagCount(); ++var3) { + NBTTagCompound var4 = (NBTTagCompound)var2.getCompoundTagAt(var3); + byte var5 = var4.getByte("Slot"); + if(var5 >= 0 && var5 < this.containingItems.length) { + this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4); + } + } + + } + + @Override + public void writeToNBT(NBTTagCompound par1NBTTagCompound) { + super.writeToNBT(par1NBTTagCompound); + par1NBTTagCompound.setInteger("itemCookTime", this.itemCookTime); + par1NBTTagCompound.setDouble("generateRate", this.generateWatts); + NBTTagList var2 = new NBTTagList(); + + for(int var3 = 0; var3 < this.containingItems.length; ++var3) { + if(this.containingItems[var3] != null) { + NBTTagCompound var4 = new NBTTagCompound(); + var4.setByte("Slot", (byte)var3); + this.containingItems[var3].writeToNBT(var4); + var2.appendTag(var4); + } + } + + par1NBTTagCompound.setTag("Items", var2); + } + + public int getSizeInventory() { + return this.containingItems.length; + } + + public ItemStack getStackInSlot(int par1) { + return this.containingItems[par1]; + } + + public ItemStack decrStackSize(int par1, int par2) { + if(this.containingItems[par1] != null) { + ItemStack var3; + if(this.containingItems[par1].stackSize <= par2) { + var3 = this.containingItems[par1]; + this.containingItems[par1] = null; + return var3; + } else { + var3 = this.containingItems[par1].splitStack(par2); + if(this.containingItems[par1].stackSize == 0) { + this.containingItems[par1] = null; + } + + return var3; + } + } else { + return null; + } + } + + public ItemStack getStackInSlotOnClosing(int par1) { + if(this.containingItems[par1] != null) { + ItemStack var2 = this.containingItems[par1]; + this.containingItems[par1] = null; + return var2; + } else { + return null; + } + } + + public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { + this.containingItems[par1] = par2ItemStack; + if(par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { + par2ItemStack.stackSize = this.getInventoryStackLimit(); + } + + } + + @Override + public String getInventoryName() { + return LanguageRegistry.instance().getStringLocalization("tile.basiccomponents:bcMachine.0.name"); + } + + public int getInventoryStackLimit() { + return 64; + } + + public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this?false:par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + public boolean isItemValidForSlot(int slotID, ItemStack itemstack) { + return itemstack.getItem() == Items.coal; //TODO WTF + } + + public int[] getAccessibleSlotsFromSide(int var1) { + return new int[]{0}; + } + + public boolean canInsertItem(int slotID, ItemStack itemstack, int j) { + return this.isItemValidForSlot(slotID, itemstack); + } + + public boolean canExtractItem(int slotID, ItemStack itemstack, int j) { + return slotID == 0; + } +} diff --git a/src/main/java/basiccomponents/common/tileentity/TileEntityCopperWire.java b/src/main/java/basiccomponents/common/tileentity/TileEntityCopperWire.java new file mode 100644 index 0000000..b9f41df --- /dev/null +++ b/src/main/java/basiccomponents/common/tileentity/TileEntityCopperWire.java @@ -0,0 +1,36 @@ +package basiccomponents.common.tileentity; + +import basiccomponents.common.BasicComponents; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import universalelectricity.prefab.tile.TileEntityConductor; + +public class TileEntityCopperWire extends TileEntityConductor { + + public static double RESISTANCE = 0.05D; + public static double MAX_AMPS = 200.0D; + + + public TileEntityCopperWire() { + super.channel = BasicComponents.CHANNEL; + } + + public double getResistance() { + return RESISTANCE; + } + + public double getCurrentCapcity() { + return MAX_AMPS; + } + + @Override + public void updateEntity() { + super.updateEntity(); + if(this.getNetwork() != null && super.ticks % 20L == 0L && this.getNetwork().getProduced(new TileEntity[0]).amperes > this.getCurrentCapcity() && !this.worldObj.isRemote) { + this.worldObj.setBlock(this.xCoord, this.yCoord, this.zCoord, Blocks.fire); + } + + } + +} diff --git a/src/main/java/basiccomponents/common/tileentity/TileEntityElectricFurnace.java b/src/main/java/basiccomponents/common/tileentity/TileEntityElectricFurnace.java new file mode 100644 index 0000000..40f0287 --- /dev/null +++ b/src/main/java/basiccomponents/common/tileentity/TileEntityElectricFurnace.java @@ -0,0 +1,267 @@ +package basiccomponents.common.tileentity; + +import basiccomponents.common.BasicComponents; +import com.google.common.io.ByteArrayDataInput; +import cpw.mods.fml.common.registry.LanguageRegistry; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.ElectricItemHelper; +import universalelectricity.core.item.IItemElectric; +import universalelectricity.prefab.tile.TileEntityElectricityRunnable; + +public class TileEntityElectricFurnace extends TileEntityElectricityRunnable implements IInventory, ISidedInventory { + + public static final double WATTS_PER_TICK = 500.0D; + public static final int PROCESS_TIME_REQUIRED = 130; + public int processTicks = 0; + private ItemStack[] containingItems = new ItemStack[3]; + public final Set playersUsing = new HashSet(); + + @Override + public void updateEntity() { + super.updateEntity(); + super.wattsReceived += ElectricItemHelper.dechargeItem(this.containingItems[0], 500.0D, this.getVoltage()); + if(!this.worldObj.isRemote) { + if(this.canProcess()) { + if(super.wattsReceived >= 500.0D) { + if(this.processTicks == 0) { + this.processTicks = 130; + } else if(this.processTicks > 0) { + --this.processTicks; + if(this.processTicks < 1) { + this.smeltItem(); + this.processTicks = 0; + } + } else { + this.processTicks = 0; + } + } else { + this.processTicks = 0; + } + + super.wattsReceived = Math.max(super.wattsReceived - 125.0D, 0.0D); + } else { + this.processTicks = 0; + } + + if(super.ticks % 3L == 0L) { + /*Iterator i$ = this.playersUsing.iterator(); + + while(i$.hasNext()) { + EntityPlayer player = (EntityPlayer)i$.next(); + PacketDispatcher.sendPacketToPlayer(this.func_70319_e(), (Player)player); + }*/ + + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + } + + public boolean canConnect(ForgeDirection direction) { + return direction == ForgeDirection.getOrientation(this.getBlockMetadata() - 8 + 2); + } + + public ElectricityPack getRequest() { + return this.canProcess()?new ElectricityPack(500.0D / this.getVoltage(), this.getVoltage()):new ElectricityPack(); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger("processTicks", this.processTicks); + nbt.setInteger("disabledTicks", super.disabledTicks); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(), nbt); + //return PacketManager.getPacket(BasicComponents.CHANNEL, this, new Object[]{Integer.valueOf(this.processTicks), Integer.valueOf(super.disabledTicks)}); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if (this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.processTicks = nbt.getInteger("processTicks"); + super.disabledTicks = nbt.getInteger("disabledTicks"); + } + } + + /*public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { + try { + this.processTicks = dataStream.readInt(); + super.disabledTicks = dataStream.readInt(); + } catch (Exception var7) { + var7.printStackTrace(); + } + + }*/ + + public void openInventory() {} + + public void closeInventory() {} + + public boolean canProcess() { + if (this.containingItems[1] == null) { + return false; + } else if(FurnaceRecipes.smelting().getSmeltingResult(this.containingItems[1]) == null) { + return false; + } else if(this.containingItems[1] == null) { + return false; + } else { + if(this.containingItems[2] != null) { + if(!this.containingItems[2].isItemEqual(FurnaceRecipes.smelting().getSmeltingResult(this.containingItems[1]))) { + return false; + } + + if(this.containingItems[2].stackSize + 1 > 64) { + return false; + } + } + + return true; + } + } + + public void smeltItem() { + if(this.canProcess()) { + ItemStack resultItemStack = FurnaceRecipes.smelting().getSmeltingResult(this.containingItems[1]); + if(this.containingItems[2] == null) { + this.containingItems[2] = resultItemStack.copy(); + } else if(this.containingItems[2].isItemEqual(resultItemStack)) { + ++this.containingItems[2].stackSize; + } + + --this.containingItems[1].stackSize; + if(this.containingItems[1].stackSize <= 0) { + this.containingItems[1] = null; + } + } + + } + + @Override + public void readFromNBT(NBTTagCompound par1NBTTagCompound) { + super.readFromNBT(par1NBTTagCompound); + this.processTicks = par1NBTTagCompound.getInteger("smeltingTicks"); + NBTTagList var2 = par1NBTTagCompound.getTagList("Items", 10); + this.containingItems = new ItemStack[this.getSizeInventory()]; + + for(int var3 = 0; var3 < var2.tagCount(); ++var3) { + NBTTagCompound var4 = (NBTTagCompound)var2.getCompoundTagAt(var3); + byte var5 = var4.getByte("Slot"); + if(var5 >= 0 && var5 < this.containingItems.length) { + this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4); + } + } + + } + + @Override + public void writeToNBT(NBTTagCompound par1NBTTagCompound) { + super.writeToNBT(par1NBTTagCompound); + par1NBTTagCompound.setInteger("smeltingTicks", this.processTicks); + NBTTagList var2 = new NBTTagList(); + + for(int var3 = 0; var3 < this.containingItems.length; ++var3) { + if(this.containingItems[var3] != null) { + NBTTagCompound var4 = new NBTTagCompound(); + var4.setByte("Slot", (byte)var3); + this.containingItems[var3].writeToNBT(var4); + var2.appendTag(var4); + } + } + + par1NBTTagCompound.setTag("Items", var2); + } + + public int getSizeInventory() { + return this.containingItems.length; + } + + public ItemStack getStackInSlot(int par1) { + return this.containingItems[par1]; + } + + public ItemStack decrStackSize(int par1, int par2) { + if(this.containingItems[par1] != null) { + ItemStack var3; + if(this.containingItems[par1].stackSize <= par2) { + var3 = this.containingItems[par1]; + this.containingItems[par1] = null; + return var3; + } else { + var3 = this.containingItems[par1].splitStack(par2); + if(this.containingItems[par1].stackSize == 0) { + this.containingItems[par1] = null; + } + + return var3; + } + } else { + return null; + } + } + + public ItemStack getStackInSlotOnClosing(int par1) { + if(this.containingItems[par1] != null) { + ItemStack var2 = this.containingItems[par1]; + this.containingItems[par1] = null; + return var2; + } else { + return null; + } + } + + public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { + this.containingItems[par1] = par2ItemStack; + if(par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { + par2ItemStack.stackSize = this.getInventoryStackLimit(); + } + + } + + @Override + public String getInventoryName() { + return LanguageRegistry.instance().getStringLocalization("tile.basiccomponents:bcMachine.2.name"); + } + + public int getInventoryStackLimit() { + return 64; + } + + public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this?false:par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + public boolean isItemValidForSlot(int slotID, ItemStack itemStack) { + return slotID == 1?FurnaceRecipes.smelting().getSmeltingResult(itemStack) != null:(slotID == 0?itemStack.getItem() instanceof IItemElectric:false); + } + + public int[] getAccessibleSlotsFromSide(int side) { + return side == 0?new int[]{2}:(side == 1?new int[]{0, 1}:new int[]{0}); + } + + public boolean canInsertItem(int slotID, ItemStack par2ItemStack, int par3) { + return this.isItemValidForSlot(slotID, par2ItemStack); + } + + public boolean canExtractItem(int slotID, ItemStack par2ItemStack, int par3) { + return slotID == 2; + } +} diff --git a/src/main/java/universalelectricity/core/UniversalElectricity.java b/src/main/java/universalelectricity/core/UniversalElectricity.java new file mode 100644 index 0000000..93c5f81 --- /dev/null +++ b/src/main/java/universalelectricity/core/UniversalElectricity.java @@ -0,0 +1,36 @@ +package universalelectricity.core; + +import cpw.mods.fml.common.Loader; +import java.io.File; +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraftforge.common.config.Configuration; + +public class UniversalElectricity { + + public static final String MAJOR_VERSION = "0"; + public static final String MINOR_VERSION = "6"; + public static final String REVISION_VERSION = "2"; + public static final String BUILD_VERSION = "117"; + public static final String VERSION = "0.6.2"; + public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity.cfg")); + public static double IC2_RATIO = 40.0D; + public static double BC3_RATIO = 100.0D; + public static double TO_IC2_RATIO = 1.0D / IC2_RATIO; + public static double TO_BC_RATIO = 1.0D / BC3_RATIO; + public static boolean isVoltageSensitive = false; + public static boolean isNetworkActive = false; + public static final Material machine = new Material(MapColor.ironColor); + + + static { + CONFIGURATION.load(); + IC2_RATIO = CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", IC2_RATIO).getDouble(IC2_RATIO); + BC3_RATIO = CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", BC3_RATIO).getDouble(BC3_RATIO); + TO_IC2_RATIO = 1.0D / IC2_RATIO; + TO_BC_RATIO = 1.0D / BC3_RATIO; + isVoltageSensitive = CONFIGURATION.get("Compatiblity", "Is Voltage Sensitive", isVoltageSensitive).getBoolean(isVoltageSensitive); + isNetworkActive = CONFIGURATION.get("Compatiblity", "Is Network Active", isNetworkActive).getBoolean(isNetworkActive); + CONFIGURATION.save(); + } +} diff --git a/src/main/java/universalelectricity/core/block/IConductor.java b/src/main/java/universalelectricity/core/block/IConductor.java new file mode 100644 index 0000000..4a182b9 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IConductor.java @@ -0,0 +1,11 @@ +package universalelectricity.core.block; + +import universalelectricity.core.block.IConnectionProvider; +import universalelectricity.core.block.INetworkProvider; + +public interface IConductor extends INetworkProvider, IConnectionProvider { + + double getResistance(); + + double getCurrentCapcity(); +} diff --git a/src/main/java/universalelectricity/core/block/IConnectionProvider.java b/src/main/java/universalelectricity/core/block/IConnectionProvider.java new file mode 100644 index 0000000..653d6e6 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IConnectionProvider.java @@ -0,0 +1,11 @@ +package universalelectricity.core.block; + +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.block.IConnector; + +public interface IConnectionProvider extends IConnector { + + TileEntity[] getAdjacentConnections(); + + void updateAdjacentConnections(); +} diff --git a/src/main/java/universalelectricity/core/block/IConnector.java b/src/main/java/universalelectricity/core/block/IConnector.java new file mode 100644 index 0000000..c903fba --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IConnector.java @@ -0,0 +1,8 @@ +package universalelectricity.core.block; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IConnector { + + boolean canConnect(ForgeDirection var1); +} diff --git a/src/main/java/universalelectricity/core/block/IElectricityStorage.java b/src/main/java/universalelectricity/core/block/IElectricityStorage.java new file mode 100644 index 0000000..98b5192 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IElectricityStorage.java @@ -0,0 +1,11 @@ +package universalelectricity.core.block; + + +public interface IElectricityStorage { + + double getJoules(); + + void setJoules(double var1); + + double getMaxJoules(); +} diff --git a/src/main/java/universalelectricity/core/block/INetworkProvider.java b/src/main/java/universalelectricity/core/block/INetworkProvider.java new file mode 100644 index 0000000..5c190bd --- /dev/null +++ b/src/main/java/universalelectricity/core/block/INetworkProvider.java @@ -0,0 +1,10 @@ +package universalelectricity.core.block; + +import universalelectricity.core.electricity.IElectricityNetwork; + +public interface INetworkProvider { + + IElectricityNetwork getNetwork(); + + void setNetwork(IElectricityNetwork var1); +} diff --git a/src/main/java/universalelectricity/core/block/IVoltage.java b/src/main/java/universalelectricity/core/block/IVoltage.java new file mode 100644 index 0000000..be0c0d2 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IVoltage.java @@ -0,0 +1,7 @@ +package universalelectricity.core.block; + + +public interface IVoltage { + + double getVoltage(); +} diff --git a/src/main/java/universalelectricity/core/electricity/ElectricityDisplay.java b/src/main/java/universalelectricity/core/electricity/ElectricityDisplay.java new file mode 100644 index 0000000..88ecc8a --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/ElectricityDisplay.java @@ -0,0 +1,97 @@ +package universalelectricity.core.electricity; + + +public class ElectricityDisplay { + + public static String getDisplay(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces, boolean isShort) { + String unitName = unit.name; + if(isShort) { + unitName = unit.symbol; + } else if(value > 1.0D) { + unitName = unit.getPlural(); + } + + return value == 0.0D?value + " " + unitName:(value <= ElectricityDisplay.MeasurementUnit.MILLI.value?roundDecimals(ElectricityDisplay.MeasurementUnit.MICRO.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MICRO.getName(isShort) + unitName:(value < 1.0D?roundDecimals(ElectricityDisplay.MeasurementUnit.MILLI.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MILLI.getName(isShort) + unitName:(value > ElectricityDisplay.MeasurementUnit.MEGA.value?roundDecimals(ElectricityDisplay.MeasurementUnit.MEGA.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.MEGA.getName(isShort) + unitName:(value > ElectricityDisplay.MeasurementUnit.KILO.value?roundDecimals(ElectricityDisplay.MeasurementUnit.KILO.process(value), decimalPlaces) + " " + ElectricityDisplay.MeasurementUnit.KILO.getName(isShort) + unitName:roundDecimals(value, decimalPlaces) + " " + unitName)))); + } + + public static String getDisplay(double value, ElectricityDisplay.ElectricUnit unit) { + return getDisplay(value, unit, 2, false); + } + + public static String getDisplayShort(double value, ElectricityDisplay.ElectricUnit unit) { + return getDisplay(value, unit, 2, true); + } + + public static String getDisplayShort(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces) { + return getDisplay(value, unit, decimalPlaces, true); + } + + public static String getDisplaySimple(double value, ElectricityDisplay.ElectricUnit unit, int decimalPlaces) { + return value > 1.0D?(decimalPlaces < 1?(int)value + " " + unit.getPlural():roundDecimals(value, decimalPlaces) + " " + unit.getPlural()):(decimalPlaces < 1?(int)value + " " + unit.name:roundDecimals(value, decimalPlaces) + " " + unit.name); + } + + public static double roundDecimals(double d, int decimalPlaces) { + int j = (int)(d * Math.pow(10.0D, (double)decimalPlaces)); + return (double)j / Math.pow(10.0D, (double)decimalPlaces); + } + + public static double roundDecimals(double d) { + return roundDecimals(d, 2); + } + + public static enum ElectricUnit { + + AMPERE("AMPERE", 0, "Amp", "I"), + AMP_HOUR("AMP_HOUR", 1, "Amp Hour", "Ah"), + VOLTAGE("VOLTAGE", 2, "Volt", "V"), + WATT("WATT", 3, "Watt", "W"), + WATT_HOUR("WATT_HOUR", 4, "Watt Hour", "Wh"), + RESISTANCE("RESISTANCE", 5, "Ohm", "R"), + CONDUCTANCE("CONDUCTANCE", 6, "Siemen", "S"), + JOULES("JOULES", 7, "Joule", "J"); + public String name; + public String symbol; + // $FF: synthetic field + private static final ElectricityDisplay.ElectricUnit[] $VALUES = new ElectricityDisplay.ElectricUnit[]{AMPERE, AMP_HOUR, VOLTAGE, WATT, WATT_HOUR, RESISTANCE, CONDUCTANCE, JOULES}; + + + private ElectricUnit(String var1, int var2, String name, String symbol) { + this.name = name; + this.symbol = symbol; + } + + public String getPlural() { + return this.name + "s"; + } + + } + + public static enum MeasurementUnit { + + MICRO("MICRO", 0, "Micro", "mi", 1.0E-6D), + MILLI("MILLI", 1, "Milli", "m", 0.001D), + KILO("KILO", 2, "Kilo", "k", 1000.0D), + MEGA("MEGA", 3, "Mega", "M", 1000000.0D); + public String name; + public String symbol; + public double value; + // $FF: synthetic field + private static final ElectricityDisplay.MeasurementUnit[] $VALUES = new ElectricityDisplay.MeasurementUnit[]{MICRO, MILLI, KILO, MEGA}; + + + private MeasurementUnit(String var1, int var2, String name, String symbol, double value) { + this.name = name; + this.symbol = symbol; + this.value = value; + } + + public String getName(boolean isSymbol) { + return isSymbol?this.symbol:this.name; + } + + public double process(double value) { + return value / this.value; + } + + } +} diff --git a/src/main/java/universalelectricity/core/electricity/ElectricityNetwork.java b/src/main/java/universalelectricity/core/electricity/ElectricityNetwork.java new file mode 100644 index 0000000..a269201 --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/ElectricityNetwork.java @@ -0,0 +1,330 @@ +package universalelectricity.core.electricity; + +import cpw.mods.fml.common.FMLLog; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.Map.Entry; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnectionProvider; +import universalelectricity.core.block.INetworkProvider; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.path.PathfinderChecker; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public class ElectricityNetwork implements IElectricityNetwork { + + private final HashMap producers = new HashMap(); + private final HashMap consumers = new HashMap(); + private final Set conductors = new HashSet(); + + + public ElectricityNetwork() {} + + public ElectricityNetwork(IConductor ... conductors) { + this.conductors.addAll(Arrays.asList(conductors)); + } + + public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack) { + if(tileEntity != null && electricityPack.getWatts() > 0.0D) { + this.producers.put(tileEntity, electricityPack); + } + + } + + public void startProducing(TileEntity tileEntity, double amperes, double voltage) { + this.startProducing(tileEntity, new ElectricityPack(amperes, voltage)); + } + + public boolean isProducing(TileEntity tileEntity) { + return this.producers.containsKey(tileEntity); + } + + public void stopProducing(TileEntity tileEntity) { + this.producers.remove(tileEntity); + } + + public void startRequesting(TileEntity tileEntity, ElectricityPack electricityPack) { + if(tileEntity != null && electricityPack.getWatts() > 0.0D) { + this.consumers.put(tileEntity, electricityPack); + } + + } + + public void startRequesting(TileEntity tileEntity, double amperes, double voltage) { + this.startRequesting(tileEntity, new ElectricityPack(amperes, voltage)); + } + + public boolean isRequesting(TileEntity tileEntity) { + return this.consumers.containsKey(tileEntity); + } + + public void stopRequesting(TileEntity tileEntity) { + this.consumers.remove(tileEntity); + } + + public ElectricityPack getProduced(TileEntity ... ignoreTiles) { + ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D); + Iterator it = this.producers.entrySet().iterator(); + + label47: + while(it.hasNext()) { + Entry pairs = (Entry)it.next(); + if(pairs != null) { + TileEntity tileEntity = (TileEntity)pairs.getKey(); + if(tileEntity == null) { + it.remove(); + } else if(tileEntity.isInvalid()) { + it.remove(); + } else if(tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity) { + it.remove(); + } else { + if(ignoreTiles != null) { + TileEntity[] pack = ignoreTiles; + int newWatts = ignoreTiles.length; + + for(int i$ = 0; i$ < newWatts; ++i$) { + TileEntity newVoltage = pack[i$]; + if(tileEntity == newVoltage) { + continue label47; + } + } + } + + ElectricityPack var11 = (ElectricityPack)pairs.getValue(); + if(pairs.getKey() != null && pairs.getValue() != null && var11 != null) { + double var12 = totalElectricity.getWatts() + var11.getWatts(); + double var13 = Math.max(totalElectricity.voltage, var11.voltage); + totalElectricity.amperes = var12 / var13; + totalElectricity.voltage = var13; + } + } + } + } + + return totalElectricity; + } + + public ElectricityPack getRequest(TileEntity ... ignoreTiles) { + ElectricityPack totalElectricity = this.getRequestWithoutReduction(); + totalElectricity.amperes = Math.max(totalElectricity.amperes - this.getProduced(ignoreTiles).amperes, 0.0D); + return totalElectricity; + } + + public ElectricityPack getRequestWithoutReduction() { + ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D); + Iterator it = this.consumers.entrySet().iterator(); + + while(it.hasNext()) { + Entry pairs = (Entry)it.next(); + if(pairs != null) { + TileEntity tileEntity = (TileEntity)pairs.getKey(); + if(tileEntity == null) { + it.remove(); + } else if(tileEntity.isInvalid()) { + it.remove(); + } else if(tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity) { + it.remove(); + } else { + ElectricityPack pack = (ElectricityPack)pairs.getValue(); + if(pack != null) { + totalElectricity.amperes += pack.amperes; + totalElectricity.voltage = Math.max(totalElectricity.voltage, pack.voltage); + } + } + } + } + + return totalElectricity; + } + + public ElectricityPack consumeElectricity(TileEntity tileEntity) { + ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D); + + try { + ElectricityPack e = (ElectricityPack)this.consumers.get(tileEntity); + if(this.consumers.containsKey(tileEntity) && e != null) { + totalElectricity = this.getProduced(new TileEntity[0]); + if(totalElectricity.getWatts() > 0.0D) { + ElectricityPack totalRequest = this.getRequestWithoutReduction(); + totalElectricity.amperes *= e.amperes / totalRequest.amperes; + int distance = this.conductors.size(); + double ampsReceived = totalElectricity.amperes - totalElectricity.amperes * totalElectricity.amperes * this.getTotalResistance() / totalElectricity.voltage; + double voltsReceived = totalElectricity.voltage - totalElectricity.amperes * this.getTotalResistance(); + totalElectricity.amperes = ampsReceived; + totalElectricity.voltage = voltsReceived; + return totalElectricity; + } + } + } catch (Exception var10) { + FMLLog.severe("Failed to consume electricity!", new Object[0]); + var10.printStackTrace(); + } + + return totalElectricity; + } + + public HashMap getProducers() { + return this.producers; + } + + public List getProviders() { + ArrayList providers = new ArrayList(); + providers.addAll(this.producers.keySet()); + return providers; + } + + public HashMap getConsumers() { + return this.consumers; + } + + public List getReceivers() { + ArrayList receivers = new ArrayList(); + receivers.addAll(this.consumers.keySet()); + return receivers; + } + + public void cleanUpConductors() { + Iterator it = this.conductors.iterator(); + + while(it.hasNext()) { + IConductor conductor = (IConductor)it.next(); + if(conductor == null) { + it.remove(); + } else if(((TileEntity)conductor).isInvalid()) { + it.remove(); + } else { + conductor.setNetwork(this); + } + } + + } + + public void refreshConductors() { + this.cleanUpConductors(); + + try { + Iterator e = this.conductors.iterator(); + + while(e.hasNext()) { + IConductor conductor = (IConductor)e.next(); + conductor.updateAdjacentConnections(); + } + } catch (Exception var3) { + FMLLog.severe("Universal Electricity: Failed to refresh conductor.", new Object[0]); + var3.printStackTrace(); + } + + } + + public double getTotalResistance() { + double resistance = 0.0D; + + IConductor conductor; + for(Iterator i$ = this.conductors.iterator(); i$.hasNext(); resistance += conductor.getResistance()) { + conductor = (IConductor)i$.next(); + } + + return resistance; + } + + public double getLowestCurrentCapacity() { + double lowestAmp = 0.0D; + Iterator i$ = this.conductors.iterator(); + + while(i$.hasNext()) { + IConductor conductor = (IConductor)i$.next(); + if(lowestAmp == 0.0D || conductor.getCurrentCapcity() < lowestAmp) { + lowestAmp = conductor.getCurrentCapcity(); + } + } + + return lowestAmp; + } + + public Set getConductors() { + return this.conductors; + } + + public void mergeConnection(IElectricityNetwork network) { + if(network != null && network != this) { + ElectricityNetwork newNetwork = new ElectricityNetwork(); + newNetwork.getConductors().addAll(this.getConductors()); + newNetwork.getConductors().addAll(network.getConductors()); + newNetwork.cleanUpConductors(); + } + + } + + public void splitNetwork(IConnectionProvider splitPoint) { + if(splitPoint instanceof TileEntity) { + this.getConductors().remove(splitPoint); + ForgeDirection[] connectedBlocks = ForgeDirection.values(); + int i = connectedBlocks.length; + + for(int connectedBlockA = 0; connectedBlockA < i; ++connectedBlockA) { + ForgeDirection ii = connectedBlocks[connectedBlockA]; + if(ii != ForgeDirection.UNKNOWN) { + Vector3 connectedBlockB = new Vector3((TileEntity)splitPoint); + TileEntity finder = VectorHelper.getTileEntityFromSide(((TileEntity)splitPoint).getWorldObj(), connectedBlockB, ii); + if(this.producers.containsKey(finder)) { + this.stopProducing(finder); + this.stopRequesting(finder); + } + } + } + + TileEntity[] var12 = splitPoint.getAdjacentConnections(); + + for(i = 0; i < var12.length; ++i) { + TileEntity var13 = var12[i]; + if(var13 instanceof IConnectionProvider) { + for(int var14 = 0; var14 < var12.length; ++var14) { + TileEntity var15 = var12[var14]; + if(var13 != var15 && var15 instanceof IConnectionProvider) { + PathfinderChecker var16 = new PathfinderChecker(((TileEntity)splitPoint).getWorldObj(), (IConnectionProvider)var15, new IConnectionProvider[]{splitPoint}); + var16.init(new Vector3(var13)); + if(var16.results.size() > 0) { + Iterator newNetwork = var16.closedSet.iterator(); + + while(newNetwork.hasNext()) { + Vector3 i$ = (Vector3)newNetwork.next(); + TileEntity node = i$.getTileEntity(((TileEntity)splitPoint).getWorldObj()); + if(node instanceof INetworkProvider && node != splitPoint) { + ((INetworkProvider)node).setNetwork(this); + } + } + } else { + ElectricityNetwork var17 = new ElectricityNetwork(); + Iterator var18 = var16.closedSet.iterator(); + + while(var18.hasNext()) { + Vector3 var19 = (Vector3)var18.next(); + TileEntity nodeTile = var19.getTileEntity(((TileEntity)splitPoint).getWorldObj()); + if(nodeTile instanceof INetworkProvider && nodeTile != splitPoint) { + var17.getConductors().add((IConductor)nodeTile); + } + } + + var17.cleanUpConductors(); + } + } + } + } + } + } + + } + + public String toString() { + return "ElectricityNetwork[" + this.hashCode() + "|Wires:" + this.conductors.size() + "]"; + } +} diff --git a/src/main/java/universalelectricity/core/electricity/ElectricityNetworkHelper.java b/src/main/java/universalelectricity/core/electricity/ElectricityNetworkHelper.java new file mode 100644 index 0000000..9d143a5 --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/ElectricityNetworkHelper.java @@ -0,0 +1,140 @@ +package universalelectricity.core.electricity; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.List; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.INetworkProvider; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public class ElectricityNetworkHelper { + + public static void invalidate(TileEntity tileEntity) { + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + TileEntity checkTile = VectorHelper.getConnectorFromSide(tileEntity.getWorldObj(), new Vector3(tileEntity), direction); + if(checkTile instanceof INetworkProvider) { + IElectricityNetwork network = ((INetworkProvider)checkTile).getNetwork(); + if(network != null) { + network.stopRequesting(tileEntity); + network.stopProducing(tileEntity); + } + } + } + + } + + public static EnumSet getDirections(TileEntity tileEntity) { + EnumSet possibleSides = EnumSet.noneOf(ForgeDirection.class); + if(tileEntity instanceof IConnector) { + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + if(((IConnector)tileEntity).canConnect(direction)) { + possibleSides.add(direction); + } + } + } + + return possibleSides; + } + + public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) { + return produceFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack); + } + + public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection, ElectricityPack producingPack) { + ElectricityPack remainingElectricity = producingPack.clone(); + if(tileEntity != null && approachingDirection != null) { + List connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection); + if(connectedNetworks.size() > 0) { + double wattsPerSide = producingPack.getWatts() / (double)connectedNetworks.size(); + double voltage = producingPack.voltage; + Iterator i$ = connectedNetworks.iterator(); + + while(i$.hasNext()) { + IElectricityNetwork network = (IElectricityNetwork)i$.next(); + if(wattsPerSide > 0.0D && producingPack.getWatts() > 0.0D) { + double amperes = Math.min(wattsPerSide / voltage, network.getRequest(new TileEntity[]{tileEntity}).amperes); + if(amperes > 0.0D) { + network.startProducing(tileEntity, amperes, voltage); + remainingElectricity.amperes -= amperes; + } + } else { + network.stopProducing(tileEntity); + } + } + } + } + + return remainingElectricity; + } + + public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) { + return consumeFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack); + } + + public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection, ElectricityPack requestPack) { + ElectricityPack consumedPack = new ElectricityPack(); + if(tileEntity != null && approachingDirection != null) { + List connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection); + if(connectedNetworks.size() > 0) { + double wattsPerSide = requestPack.getWatts() / (double)connectedNetworks.size(); + double voltage = requestPack.voltage; + Iterator i$ = connectedNetworks.iterator(); + + while(i$.hasNext()) { + IElectricityNetwork network = (IElectricityNetwork)i$.next(); + if(wattsPerSide > 0.0D && requestPack.getWatts() > 0.0D) { + network.startRequesting(tileEntity, wattsPerSide / voltage, voltage); + ElectricityPack receivedPack = network.consumeElectricity(tileEntity); + consumedPack.amperes += receivedPack.amperes; + consumedPack.voltage = Math.max(consumedPack.voltage, receivedPack.voltage); + } else { + network.stopRequesting(tileEntity); + } + } + } + } + + return consumedPack; + } + + public static List getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection) { + ArrayList connectedNetworks = new ArrayList(); + + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + if(approachingDirection.contains(direction)) { + Vector3 position = new Vector3(tileEntity); + position.modifyPositionFromSide(direction); + TileEntity outputConductor = position.getTileEntity(tileEntity.getWorldObj()); + IElectricityNetwork electricityNetwork = getNetworkFromTileEntity(outputConductor, direction); + if(electricityNetwork != null && !connectedNetworks.contains(connectedNetworks)) { + connectedNetworks.add(electricityNetwork); + } + } + } + + return connectedNetworks; + } + + public static IElectricityNetwork getNetworkFromTileEntity(TileEntity tileEntity, ForgeDirection approachDirection) { + if(tileEntity != null && tileEntity instanceof INetworkProvider) { + if(!(tileEntity instanceof IConnector)) { + return ((INetworkProvider)tileEntity).getNetwork(); + } + + if(((IConnector)tileEntity).canConnect(approachDirection.getOpposite())) { + return ((INetworkProvider)tileEntity).getNetwork(); + } + } + + return null; + } +} diff --git a/src/main/java/universalelectricity/core/electricity/ElectricityPack.java b/src/main/java/universalelectricity/core/electricity/ElectricityPack.java new file mode 100644 index 0000000..1560db0 --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/ElectricityPack.java @@ -0,0 +1,102 @@ +package universalelectricity.core.electricity; + + +public class ElectricityPack implements Cloneable { + + public double amperes; + public double voltage; + + + public ElectricityPack(double amperes, double voltage) { + this.amperes = amperes; + this.voltage = voltage; + } + + public ElectricityPack() { + this(0.0D, 0.0D); + } + + public static ElectricityPack getFromWatts(double watts, double voltage) { + return new ElectricityPack(watts / voltage, voltage); + } + + public double getWatts() { + return getWatts(this.amperes, this.voltage); + } + + public double getConductance() { + return getConductance(this.amperes, this.voltage); + } + + public double getResistance() { + return getResistance(this.amperes, this.voltage); + } + + public static double getJoules(double watts, double seconds) { + return watts * seconds; + } + + public static double getJoules(double amps, double voltage, double seconds) { + return amps * voltage * seconds; + } + + public static double getWattsFromJoules(double joules, double seconds) { + return joules / seconds; + } + + public static double getAmps(double watts, double voltage) { + return watts / voltage; + } + + public static double getAmps(double ampHours) { + return ampHours * 3600.0D; + } + + public static double getAmpsFromWattHours(double wattHours, double voltage) { + return getWatts(wattHours) / voltage; + } + + public static double getWattHoursFromAmpHours(double ampHours, double voltage) { + return ampHours * voltage; + } + + public static double getAmpHours(double amps) { + return amps / 3600.0D; + } + + public static double getWatts(double amps, double voltage) { + return amps * voltage; + } + + public static double getWatts(double wattHours) { + return wattHours * 3600.0D; + } + + public static double getWattHours(double watts) { + return watts / 3600.0D; + } + + public static double getWattHours(double amps, double voltage) { + return getWattHours(getWatts(amps, voltage)); + } + + public static double getResistance(double amps, double voltage) { + return voltage / amps; + } + + public static double getConductance(double amps, double voltage) { + return amps / voltage; + } + + public String toString() { + return "ElectricityPack [Amps:" + this.amperes + " Volts:" + this.voltage + "]"; + } + + public ElectricityPack clone() { + return new ElectricityPack(this.amperes, this.voltage); + } + + public boolean isEqual(ElectricityPack electricityPack) { + return this.amperes == electricityPack.amperes && this.voltage == electricityPack.voltage; + } +} diff --git a/src/main/java/universalelectricity/core/electricity/IConductorRegistry.java b/src/main/java/universalelectricity/core/electricity/IConductorRegistry.java new file mode 100644 index 0000000..79aa9db --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/IConductorRegistry.java @@ -0,0 +1,15 @@ +package universalelectricity.core.electricity; + +import java.util.List; +import universalelectricity.core.block.IConductor; + +public interface IConductorRegistry { + + void register(IConductor var1); + + void cleanConductors(); + + void resetAllConnections(); + + List getConductors(); +} diff --git a/src/main/java/universalelectricity/core/electricity/IElectricityNetwork.java b/src/main/java/universalelectricity/core/electricity/IElectricityNetwork.java new file mode 100644 index 0000000..d0d95c6 --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/IElectricityNetwork.java @@ -0,0 +1,57 @@ +package universalelectricity.core.electricity; + +import java.util.HashMap; +import java.util.List; +import java.util.Set; +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.block.IConnectionProvider; +import universalelectricity.core.electricity.ElectricityPack; + +public interface IElectricityNetwork { + + void startProducing(TileEntity var1, ElectricityPack var2); + + void startProducing(TileEntity var1, double var2, double var4); + + boolean isProducing(TileEntity var1); + + void stopProducing(TileEntity var1); + + void startRequesting(TileEntity var1, ElectricityPack var2); + + void startRequesting(TileEntity var1, double var2, double var4); + + boolean isRequesting(TileEntity var1); + + void stopRequesting(TileEntity var1); + + ElectricityPack getProduced(TileEntity ... var1); + + ElectricityPack getRequest(TileEntity ... var1); + + ElectricityPack getRequestWithoutReduction(); + + ElectricityPack consumeElectricity(TileEntity var1); + + HashMap getProducers(); + + List getProviders(); + + HashMap getConsumers(); + + List getReceivers(); + + Set getConductors(); + + double getTotalResistance(); + + double getLowestCurrentCapacity(); + + void cleanUpConductors(); + + void refreshConductors(); + + void mergeConnection(IElectricityNetwork var1); + + void splitNetwork(IConnectionProvider var1); +} diff --git a/src/main/java/universalelectricity/core/item/ElectricItemHelper.java b/src/main/java/universalelectricity/core/item/ElectricItemHelper.java new file mode 100644 index 0000000..6a3c16f --- /dev/null +++ b/src/main/java/universalelectricity/core/item/ElectricItemHelper.java @@ -0,0 +1,60 @@ +package universalelectricity.core.item; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.IItemElectric; + +public class ElectricItemHelper { + + public static double chargeItem(ItemStack itemStack, double joules, double voltage) { + if(itemStack != null && itemStack.getItem() instanceof IItemElectric) { + IItemElectric electricItem = (IItemElectric)itemStack.getItem(); + double providingWatts = Math.min(joules, electricItem.getReceiveRequest(itemStack).getWatts()); + if(providingWatts > 0.0D) { + ElectricityPack providedElectricity = electricItem.onReceive(ElectricityPack.getFromWatts(providingWatts, voltage), itemStack); + return providedElectricity.getWatts(); + } + } + + return 0.0D; + } + + public static double dechargeItem(ItemStack itemStack, double joules, double voltage) { + if(itemStack != null && itemStack.getItem() instanceof IItemElectric) { + IItemElectric electricItem = (IItemElectric)itemStack.getItem(); + double requestingWatts = Math.min(joules, electricItem.getProvideRequest(itemStack).getWatts()); + if(requestingWatts > 0.0D) { + ElectricityPack receivedElectricity = electricItem.onProvide(ElectricityPack.getFromWatts(requestingWatts, voltage), itemStack); + return receivedElectricity.getWatts(); + } + } + + return 0.0D; + } + + public static ItemStack getWithCharge(ItemStack itemStack, double joules) { + if(itemStack != null && itemStack.getItem() instanceof IItemElectric) { + ((IItemElectric)itemStack.getItem()).setJoules(joules, itemStack); + return itemStack; + } else { + return itemStack; + } + } + + public static ItemStack getWithCharge(Item item, double joules) { + return getWithCharge(new ItemStack(item), joules); + } + + public static ItemStack getCloneWithCharge(ItemStack itemStack, double joules) { + return getWithCharge(itemStack.copy(), joules); + } + + public static ItemStack getUncharged(ItemStack itemStack) { + return getWithCharge(itemStack, 0.0D); + } + + public static ItemStack getUncharged(Item item) { + return getUncharged(new ItemStack(item)); + } +} diff --git a/src/main/java/universalelectricity/core/item/IItemElectric.java b/src/main/java/universalelectricity/core/item/IItemElectric.java new file mode 100644 index 0000000..17eb647 --- /dev/null +++ b/src/main/java/universalelectricity/core/item/IItemElectric.java @@ -0,0 +1,17 @@ +package universalelectricity.core.item; + +import net.minecraft.item.ItemStack; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.IItemElectricityStorage; +import universalelectricity.core.item.IItemVoltage; + +public interface IItemElectric extends IItemElectricityStorage, IItemVoltage { + + ElectricityPack onReceive(ElectricityPack var1, ItemStack var2); + + ElectricityPack onProvide(ElectricityPack var1, ItemStack var2); + + ElectricityPack getReceiveRequest(ItemStack var1); + + ElectricityPack getProvideRequest(ItemStack var1); +} diff --git a/src/main/java/universalelectricity/core/item/IItemElectricityStorage.java b/src/main/java/universalelectricity/core/item/IItemElectricityStorage.java new file mode 100644 index 0000000..5a88ab4 --- /dev/null +++ b/src/main/java/universalelectricity/core/item/IItemElectricityStorage.java @@ -0,0 +1,12 @@ +package universalelectricity.core.item; + +import net.minecraft.item.ItemStack; + +public interface IItemElectricityStorage { + + double getJoules(ItemStack var1); + + void setJoules(double var1, ItemStack var3); + + double getMaxJoules(ItemStack var1); +} diff --git a/src/main/java/universalelectricity/core/item/IItemVoltage.java b/src/main/java/universalelectricity/core/item/IItemVoltage.java new file mode 100644 index 0000000..b5b577d --- /dev/null +++ b/src/main/java/universalelectricity/core/item/IItemVoltage.java @@ -0,0 +1,8 @@ +package universalelectricity.core.item; + +import net.minecraft.item.ItemStack; + +public interface IItemVoltage { + + double getVoltage(ItemStack var1); +} diff --git a/src/main/java/universalelectricity/core/item/ItemElectric.java b/src/main/java/universalelectricity/core/item/ItemElectric.java new file mode 100644 index 0000000..eac9b03 --- /dev/null +++ b/src/main/java/universalelectricity/core/item/ItemElectric.java @@ -0,0 +1,92 @@ +package universalelectricity.core.item; + +import java.util.List; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import universalelectricity.core.electricity.ElectricityDisplay; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.ElectricItemHelper; +import universalelectricity.core.item.IItemElectric; + +public abstract class ItemElectric extends Item implements IItemElectric { + + public ItemElectric() { + super(); + this.setMaxStackSize(1); + this.setMaxDamage(100); + this.setNoRepair(); + } + + public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4) { + String color = ""; + double joules = this.getJoules(itemStack); + if(joules <= this.getMaxJoules(itemStack) / 3.0D) { + color = "§4"; + } else if(joules > this.getMaxJoules(itemStack) * 2.0D / 3.0D) { + color = "§2"; + } else { + color = "§6"; + } + + list.add(color + ElectricityDisplay.getDisplay(joules, ElectricityDisplay.ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplay(this.getMaxJoules(itemStack), ElectricityDisplay.ElectricUnit.JOULES)); + } + + public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer) { + this.setJoules(0.0D, itemStack); + } + + public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) { + double rejectedElectricity = Math.max(this.getJoules(itemStack) + electricityPack.getWatts() - this.getMaxJoules(itemStack), 0.0D); + double joulesToStore = electricityPack.getWatts() - rejectedElectricity; + this.setJoules(this.getJoules(itemStack) + joulesToStore, itemStack); + return ElectricityPack.getFromWatts(joulesToStore, this.getVoltage(itemStack)); + } + + public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) { + double electricityToUse = Math.min(this.getJoules(itemStack), electricityPack.getWatts()); + this.setJoules(this.getJoules(itemStack) - electricityToUse, itemStack); + return ElectricityPack.getFromWatts(electricityToUse, this.getVoltage(itemStack)); + } + + public ElectricityPack getReceiveRequest(ItemStack itemStack) { + return ElectricityPack.getFromWatts(Math.min(this.getMaxJoules(itemStack) - this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack)); + } + + public ElectricityPack getProvideRequest(ItemStack itemStack) { + return ElectricityPack.getFromWatts(Math.min(this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack)); + } + + public double getTransferRate(ItemStack itemStack) { + return this.getMaxJoules(itemStack) * 0.01D; + } + + public void setJoules(double joules, ItemStack itemStack) { + if(itemStack.getTagCompound() == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + + double electricityStored = Math.max(Math.min(joules, this.getMaxJoules(itemStack)), 0.0D); + itemStack.getTagCompound().setDouble("electricity", electricityStored); + itemStack.setItemDamage((int)(100.0D - electricityStored / this.getMaxJoules(itemStack) * 100.0D)); + } + + public double getJoules(ItemStack itemStack) { + if(itemStack.getTagCompound() == null) { + return 0.0D; + } else { + double electricityStored = itemStack.getTagCompound().getDouble("electricity"); + itemStack.setItemDamage((int)(100.0D - electricityStored / this.getMaxJoules(itemStack) * 100.0D)); + return electricityStored; + } + } + + public void func_77633_a(int par1, CreativeTabs par2CreativeTabs, List par3List) { + par3List.add(ElectricItemHelper.getUncharged(new ItemStack(this))); + ItemStack chargedItem = new ItemStack(this); + par3List.add(ElectricItemHelper.getWithCharge(chargedItem, this.getMaxJoules(chargedItem))); + } +} diff --git a/src/main/java/universalelectricity/core/path/IPathCallBack.java b/src/main/java/universalelectricity/core/path/IPathCallBack.java new file mode 100644 index 0000000..fc20f3b --- /dev/null +++ b/src/main/java/universalelectricity/core/path/IPathCallBack.java @@ -0,0 +1,12 @@ +package universalelectricity.core.path; + +import java.util.Set; +import universalelectricity.core.path.Pathfinder; +import universalelectricity.core.vector.Vector3; + +public interface IPathCallBack { + + Set getConnectedNodes(Pathfinder var1, Vector3 var2); + + boolean onSearch(Pathfinder var1, Vector3 var2); +} diff --git a/src/main/java/universalelectricity/core/path/Pathfinder.java b/src/main/java/universalelectricity/core/path/Pathfinder.java new file mode 100644 index 0000000..e137fde --- /dev/null +++ b/src/main/java/universalelectricity/core/path/Pathfinder.java @@ -0,0 +1,51 @@ +package universalelectricity.core.path; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import universalelectricity.core.path.IPathCallBack; +import universalelectricity.core.vector.Vector3; + +public class Pathfinder { + + public IPathCallBack callBackCheck; + public Set closedSet; + public Set results; + + + public Pathfinder(IPathCallBack callBack) { + this.callBackCheck = callBack; + this.reset(); + } + + public boolean findNodes(Vector3 currentNode) { + this.closedSet.add(currentNode); + if(this.callBackCheck.onSearch(this, currentNode)) { + return false; + } else { + Iterator i$ = this.callBackCheck.getConnectedNodes(this, currentNode).iterator(); + + Vector3 node; + do { + if(!i$.hasNext()) { + return false; + } + + node = (Vector3)i$.next(); + } while(this.closedSet.contains(node) || !this.findNodes(node)); + + return true; + } + } + + public Pathfinder init(Vector3 startNode) { + this.findNodes(startNode); + return this; + } + + public Pathfinder reset() { + this.closedSet = new HashSet(); + this.results = new HashSet(); + return this; + } +} diff --git a/src/main/java/universalelectricity/core/path/PathfinderAStar.java b/src/main/java/universalelectricity/core/path/PathfinderAStar.java new file mode 100644 index 0000000..51eae44 --- /dev/null +++ b/src/main/java/universalelectricity/core/path/PathfinderAStar.java @@ -0,0 +1,112 @@ +package universalelectricity.core.path; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.path.IPathCallBack; +import universalelectricity.core.path.Pathfinder; +import universalelectricity.core.vector.Vector3; + +public class PathfinderAStar extends Pathfinder { + + public IPathCallBack callBackCheck; + public Set openSet; + public HashMap navigationMap; + public HashMap gScore; + public HashMap fScore; + public Vector3 goal; + + + public PathfinderAStar(IPathCallBack callBack, Vector3 goal) { + super(callBack); + this.goal = goal; + } + + public boolean findNodes(Vector3 start) { + this.openSet.add(start); + this.gScore.put(start, Double.valueOf(0.0D)); + this.fScore.put(start, Double.valueOf(((Double)this.gScore.get(start)).doubleValue() + this.getHeuristicEstimatedCost(start, this.goal))); + + while(!this.openSet.isEmpty()) { + Vector3 currentNode = null; + double lowestFScore = 0.0D; + Iterator i$ = this.openSet.iterator(); + + Vector3 neighbor; + while(i$.hasNext()) { + neighbor = (Vector3)i$.next(); + if(currentNode == null || ((Double)this.fScore.get(neighbor)).doubleValue() < lowestFScore) { + currentNode = neighbor; + lowestFScore = ((Double)this.fScore.get(neighbor)).doubleValue(); + } + } + + if(currentNode == null) { + break; + } + + if(this.callBackCheck.onSearch(this, currentNode)) { + return false; + } + + if(currentNode.equals(this.goal)) { + super.results = this.reconstructPath(this.navigationMap, this.goal); + return true; + } + + this.openSet.remove(currentNode); + super.closedSet.add(currentNode); + i$ = this.getNeighborNodes(currentNode).iterator(); + + while(i$.hasNext()) { + neighbor = (Vector3)i$.next(); + double tentativeGScore = ((Double)this.gScore.get(currentNode)).doubleValue() + currentNode.distanceTo(neighbor); + if((!super.closedSet.contains(neighbor) || tentativeGScore < ((Double)this.gScore.get(neighbor)).doubleValue()) && (!this.openSet.contains(neighbor) || tentativeGScore < ((Double)this.gScore.get(neighbor)).doubleValue())) { + this.navigationMap.put(neighbor, currentNode); + this.gScore.put(neighbor, Double.valueOf(tentativeGScore)); + this.fScore.put(neighbor, Double.valueOf(((Double)this.gScore.get(neighbor)).doubleValue() + this.getHeuristicEstimatedCost(neighbor, this.goal))); + this.openSet.add(neighbor); + } + } + } + + return false; + } + + public Pathfinder reset() { + this.openSet = new HashSet(); + this.navigationMap = new HashMap(); + return super.reset(); + } + + public Set reconstructPath(HashMap nagivationMap, Vector3 current_node) { + HashSet path = new HashSet(); + path.add(current_node); + if(nagivationMap.containsKey(current_node)) { + path.addAll(this.reconstructPath(nagivationMap, (Vector3)nagivationMap.get(current_node))); + return path; + } else { + return path; + } + } + + public double getHeuristicEstimatedCost(Vector3 start, Vector3 goal) { + return start.distanceTo(goal); + } + + public Set getNeighborNodes(Vector3 vector) { + if(this.callBackCheck != null) { + return this.callBackCheck.getConnectedNodes(this, vector); + } else { + HashSet neighbors = new HashSet(); + + for(int i = 0; i < 6; ++i) { + neighbors.add(vector.clone().modifyPositionFromSide(ForgeDirection.getOrientation(i))); + } + + return neighbors; + } + } +} diff --git a/src/main/java/universalelectricity/core/path/PathfinderChecker.java b/src/main/java/universalelectricity/core/path/PathfinderChecker.java new file mode 100644 index 0000000..7e7bd08 --- /dev/null +++ b/src/main/java/universalelectricity/core/path/PathfinderChecker.java @@ -0,0 +1,43 @@ +package universalelectricity.core.path; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnectionProvider; +import universalelectricity.core.path.IPathCallBack; +import universalelectricity.core.path.Pathfinder; +import universalelectricity.core.vector.Vector3; + +public class PathfinderChecker extends Pathfinder { + + public PathfinderChecker(final World world, final IConnectionProvider targetConnector, final IConnectionProvider ... ignoreConnector) { + super(new IPathCallBack() { + public Set getConnectedNodes(Pathfinder finder, Vector3 currentNode) { + HashSet neighbors = new HashSet(); + + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + Vector3 position = currentNode.clone().modifyPositionFromSide(direction); + TileEntity connectedBlock = position.getTileEntity(world); + if(connectedBlock instanceof IConductor && !Arrays.asList(ignoreConnector).contains(connectedBlock) && ((IConductor)connectedBlock).canConnect(direction.getOpposite())) { + neighbors.add(position); + } + } + + return neighbors; + } + public boolean onSearch(Pathfinder finder, Vector3 node) { + if(node.getTileEntity(world) == targetConnector) { + finder.results.add(node); + return true; + } else { + return false; + } + } + }); + } +} diff --git a/src/main/java/universalelectricity/core/vector/Vector2.java b/src/main/java/universalelectricity/core/vector/Vector2.java new file mode 100644 index 0000000..4b9e35f --- /dev/null +++ b/src/main/java/universalelectricity/core/vector/Vector2.java @@ -0,0 +1,101 @@ +package universalelectricity.core.vector; + +import net.minecraft.util.MathHelper; + +public class Vector2 implements Cloneable { + + public double x; + public double y; + + + public Vector2() { + this(0.0D, 0.0D); + } + + public Vector2(double x, double y) { + this.x = x; + this.y = y; + } + + public int intX() { + return (int)Math.floor(this.x); + } + + public int intY() { + return (int)Math.floor(this.y); + } + + public Vector2 clone() { + return new Vector2(this.x, this.y); + } + + public static double distance(Vector2 point1, Vector2 point2) { + double xDifference = point1.x - point2.x; + double yDiference = point1.y - point2.y; + return (double)MathHelper.sqrt_double(xDifference * xDifference + yDiference * yDiference); + } + + public static double slope(Vector2 point1, Vector2 point2) { + double xDifference = point1.x - point2.x; + double yDiference = point1.y - point2.y; + return yDiference / xDifference; + } + + public double distanceTo(Vector2 target) { + double xDifference = this.x - target.x; + double yDifference = this.y - target.y; + return (double)MathHelper.sqrt_double(xDifference * xDifference + yDifference * yDifference); + } + + public Vector2 add(Vector2 par1) { + this.x += par1.x; + this.y += par1.y; + return this; + } + + public Vector2 add(double par1) { + this.x += par1; + this.y += par1; + return this; + } + + public Vector2 invert() { + this.multiply(-1.0D); + return this; + } + + public Vector2 multiply(double amount) { + this.x *= amount; + this.y *= amount; + return this; + } + + public Vector2 round() { + return new Vector2((double)Math.round(this.x), (double)Math.round(this.y)); + } + + public Vector2 ceil() { + return new Vector2(Math.ceil(this.x), Math.ceil(this.y)); + } + + public Vector2 floor() { + return new Vector2(Math.floor(this.x), Math.floor(this.y)); + } + + public int hashCode() { + return ("X:" + this.x + "Y:" + this.y).hashCode(); + } + + public boolean equals(Object o) { + if(!(o instanceof Vector2)) { + return false; + } else { + Vector2 vector = (Vector2)o; + return this.x == vector.x && this.y == vector.y; + } + } + + public String toString() { + return "Vector2 [" + this.x + "," + this.y + "]"; + } +} diff --git a/src/main/java/universalelectricity/core/vector/Vector3.java b/src/main/java/universalelectricity/core/vector/Vector3.java new file mode 100644 index 0000000..766e7ae --- /dev/null +++ b/src/main/java/universalelectricity/core/vector/Vector3.java @@ -0,0 +1,286 @@ +package universalelectricity.core.vector; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class Vector3 implements Cloneable { + + public double x; + public double y; + public double z; + + + public Vector3() { + this(0.0D, 0.0D, 0.0D); + } + + public Vector3(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Vector3(Entity par1) { + this.x = par1.posX; + this.y = par1.posY; + this.z = par1.posZ; + } + + public Vector3(TileEntity par1) { + this.x = (double)par1.xCoord; + this.y = (double)par1.yCoord; + this.z = (double)par1.zCoord; + } + + public Vector3(Vec3 par1) { + this.x = par1.xCoord; + this.y = par1.yCoord; + this.z = par1.zCoord; + } + + public Vector3(MovingObjectPosition par1) { + this.x = (double)par1.blockX; + this.y = (double)par1.blockY; + this.z = (double)par1.blockZ; + } + + public Vector3(ChunkCoordinates par1) { + this.x = (double)par1.posX; + this.y = (double)par1.posY; + this.z = (double)par1.posZ; + } + + public Vector3(ForgeDirection direction) { + this.x = (double)direction.offsetX; + this.y = (double)direction.offsetY; + this.z = (double)direction.offsetZ; + } + + public int intX() { + return (int)Math.floor(this.x); + } + + public int intY() { + return (int)Math.floor(this.y); + } + + public int intZ() { + return (int)Math.floor(this.z); + } + + public Vector3 clone() { + return new Vector3(this.x, this.y, this.z); + } + + public Block getBlock(IBlockAccess world) { + return world.getBlock(this.intX(), this.intY(), this.intZ()); + } + + public int getBlockMetadata(IBlockAccess world) { + return world.getBlockMetadata(this.intX(), this.intY(), this.intZ()); + } + + public TileEntity getTileEntity(IBlockAccess world) { + return world.getTileEntity(this.intX(), this.intY(), this.intZ()); + } + + public boolean setBlock(World world, Block block, int metadata, int notify) { + return world.setBlock(this.intX(), this.intY(), this.intZ(), block, metadata, notify); + } + + public boolean setBlock(World world, Block block, int metadata) { + return this.setBlock(world, block, metadata, 3); + } + + public boolean setBlock(World world, Block block) { + return this.setBlock(world, block, 0); + } + + public Vector2 toVector2() { + return new Vector2(this.x, this.z); + } + + public Vec3 toVec3() { + return Vec3.createVectorHelper(this.x, this.y, this.z); + } + + public double getMagnitude() { + return Math.sqrt(this.getMagnitudeSquared()); + } + + public double getMagnitudeSquared() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + public Vector3 normalize() { + double d = this.getMagnitude(); + if(d != 0.0D) { + this.multiply(1.0D / d); + } + + return this; + } + + public static double distance(Vector3 par1, Vector3 par2) { + double var2 = par1.x - par2.x; + double var4 = par1.y - par2.y; + double var6 = par1.z - par2.z; + return (double)MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6); + } + + public double distanceTo(Vector3 vector3) { + double var2 = vector3.x - this.x; + double var4 = vector3.y - this.y; + double var6 = vector3.z - this.z; + return (double)MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6); + } + + public Vector3 add(Vector3 par1) { + this.x += par1.x; + this.y += par1.y; + this.z += par1.z; + return this; + } + + public Vector3 add(double par1) { + this.x += par1; + this.y += par1; + this.z += par1; + return this; + } + + public Vector3 subtract(Vector3 amount) { + this.x -= amount.x; + this.y -= amount.y; + this.z -= amount.z; + return this; + } + + public Vector3 invert() { + this.multiply(-1.0D); + return this; + } + + public Vector3 multiply(double amount) { + this.x *= amount; + this.y *= amount; + this.z *= amount; + return this; + } + + public Vector3 multiply(Vector3 vec) { + this.x *= vec.x; + this.y *= vec.y; + this.z *= vec.z; + return this; + } + + public static Vector3 subtract(Vector3 par1, Vector3 par2) { + return new Vector3(par1.x - par2.x, par1.y - par2.y, par1.z - par2.z); + } + + public static Vector3 add(Vector3 par1, Vector3 par2) { + return new Vector3(par1.x + par2.x, par1.y + par2.y, par1.z + par2.z); + } + + public static Vector3 add(Vector3 par1, double par2) { + return new Vector3(par1.x + par2, par1.y + par2, par1.z + par2); + } + + public static Vector3 multiply(Vector3 vec1, Vector3 vec2) { + return new Vector3(vec1.x * vec2.x, vec1.y * vec2.y, vec1.z * vec2.z); + } + + public static Vector3 multiply(Vector3 vec1, double vec2) { + return new Vector3(vec1.x * vec2, vec1.y * vec2, vec1.z * vec2); + } + + public Vector3 round() { + return new Vector3((double)Math.round(this.x), (double)Math.round(this.y), (double)Math.round(this.z)); + } + + public Vector3 ceil() { + return new Vector3(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); + } + + public Vector3 floor() { + return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); + } + + public List getEntitiesWithin(World worldObj, Class par1Class) { + return worldObj.getEntitiesWithinAABB(par1Class, AxisAlignedBB.getBoundingBox((double)this.intX(), (double)this.intY(), (double)this.intZ(), (double)(this.intX() + 1), (double)(this.intY() + 1), (double)(this.intZ() + 1))); + } + + public Vector3 modifyPositionFromSide(ForgeDirection side, double amount) { + switch(side.ordinal()) { + case 0: + this.y -= amount; + break; + case 1: + this.y += amount; + break; + case 2: + this.z -= amount; + break; + case 3: + this.z += amount; + break; + case 4: + this.x -= amount; + break; + case 5: + this.x += amount; + } + + return this; + } + + public Vector3 modifyPositionFromSide(ForgeDirection side) { + this.modifyPositionFromSide(side, 1.0D); + return this; + } + + public static Vector3 readFromNBT(NBTTagCompound nbtCompound) { + Vector3 tempVector = new Vector3(); + tempVector.x = nbtCompound.getDouble("x"); + tempVector.y = nbtCompound.getDouble("y"); + tempVector.z = nbtCompound.getDouble("z"); + return tempVector; + } + + public NBTTagCompound writeToNBT(NBTTagCompound par1NBTTagCompound) { + par1NBTTagCompound.setDouble("x", this.x); + par1NBTTagCompound.setDouble("y", this.y); + par1NBTTagCompound.setDouble("z", this.z); + return par1NBTTagCompound; + } + + public int hashCode() { + return ("X:" + this.x + "Y:" + this.y + "Z:" + this.z).hashCode(); + } + + public boolean equals(Object o) { + if(!(o instanceof Vector3)) { + return false; + } else { + Vector3 vector3 = (Vector3)o; + return this.x == vector3.x && this.y == vector3.y && this.z == vector3.z; + } + } + + public String toString() { + return "Vector3 [" + this.x + "," + this.y + "," + this.z + "]"; + } +} diff --git a/src/main/java/universalelectricity/core/vector/VectorHelper.java b/src/main/java/universalelectricity/core/vector/VectorHelper.java new file mode 100644 index 0000000..0013758 --- /dev/null +++ b/src/main/java/universalelectricity/core/vector/VectorHelper.java @@ -0,0 +1,26 @@ +package universalelectricity.core.vector; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IConnector; + +public class VectorHelper { + + public static final int[][] RELATIVE_MATRIX = new int[][]{{3, 2, 1, 0, 5, 4}, {4, 5, 0, 1, 2, 3}, {0, 1, 3, 2, 4, 5}, {0, 1, 2, 3, 5, 4}, {0, 1, 5, 4, 3, 2}, {0, 1, 4, 5, 2, 3}}; + + + public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side) { + return front != ForgeDirection.UNKNOWN && side != ForgeDirection.UNKNOWN?ForgeDirection.getOrientation(RELATIVE_MATRIX[front.ordinal()][side.ordinal()]):ForgeDirection.UNKNOWN; + } + + public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side) { + TileEntity tileEntity = getTileEntityFromSide(world, position, side); + return tileEntity instanceof IConnector && ((IConnector)tileEntity).canConnect(getOrientationFromSide(side, ForgeDirection.NORTH))?tileEntity:null; + } + + public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side) { + return position.clone().modifyPositionFromSide(side).getTileEntity(world); + } + +} diff --git a/src/main/java/universalelectricity/prefab/CustomDamageSource.java b/src/main/java/universalelectricity/prefab/CustomDamageSource.java new file mode 100644 index 0000000..3ea4c78 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/CustomDamageSource.java @@ -0,0 +1,32 @@ +package universalelectricity.prefab; + +import cpw.mods.fml.common.registry.LanguageRegistry; +import net.minecraft.util.DamageSource; + +public class CustomDamageSource extends DamageSource { + + public static final CustomDamageSource electrocution = ((CustomDamageSource)(new CustomDamageSource("electrocution")).setDamageBypassesArmor()).setDeathMessage("%1$s got electrocuted!"); + + + public CustomDamageSource(String damageType) { + super(damageType); + } + + public CustomDamageSource setDeathMessage(String deathMessage) { + LanguageRegistry.instance().addStringLocalization("death.attack." + super.damageType, deathMessage); + return this; + } + + public DamageSource setDamageBypassesArmor() { + return super.setDamageBypassesArmor(); + } + + public DamageSource setDamageAllowedInCreativeMode() { + return super.setDamageAllowedInCreativeMode(); + } + + public DamageSource setFireDamage() { + return super.setFireDamage(); + } + +} diff --git a/src/main/java/universalelectricity/prefab/GuiBase.java b/src/main/java/universalelectricity/prefab/GuiBase.java new file mode 100644 index 0000000..d7ba311 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/GuiBase.java @@ -0,0 +1,131 @@ +package universalelectricity.prefab; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public abstract class GuiBase extends GuiScreen { + + protected int xSize = 176; + protected int ySize = 166; + protected int guiLeft; + protected int guiTop; + + + public void initGui() { + super.initGui(); + this.guiLeft = (this.width - this.xSize) / 2; + this.guiTop = (this.height - this.ySize) / 2; + } + + public void drawScreen(int par1, int par2, float par3) { + this.drawDefaultBackground(); + int var4 = this.guiLeft; + int var5 = this.guiTop; + this.drawBackgroundLayer(par1, par2, par3); + GL11.glPushMatrix(); + GL11.glTranslatef((float)var4, (float)var5, 0.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glEnable('\u803a'); + short var7 = 240; + short var8 = 240; + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var7 / 1.0F, (float)var8 / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.drawForegroundLayer(par1, par2, par3); + GL11.glDisable('\u803a'); + GL11.glDisable(2896); + GL11.glDisable(2929); + GL11.glPopMatrix(); + super.drawScreen(par1, par2, par3); + GL11.glEnable(2896); + GL11.glEnable(2929); + } + + protected abstract void drawForegroundLayer(int var1, int var2, float var3); + + protected abstract void drawBackgroundLayer(int var1, int var2, float var3); + + protected void keyTyped(char x, int y) { + if(y == 1 || y == this.mc.gameSettings.keyBindInventory.getKeyCode()) { + this.mc.thePlayer.closeScreen(); + } + + } + + public boolean doesGuiPauseGame() { + return false; + } + + public void updateScreen() { + super.updateScreen(); + if(!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) { + this.mc.thePlayer.closeScreen(); + } + + } + + public void drawTooltip(int x, int y, String ... toolTips) { + GL11.glDisable('\u803a'); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(2896); + GL11.glDisable(2929); + if(toolTips != null) { + int var5 = 0; + + int var6; + int var7; + for(var6 = 0; var6 < toolTips.length; ++var6) { + var7 = this.fontRendererObj.getStringWidth(toolTips[var6]); + if(var7 > var5) { + var5 = var7; + } + } + + var6 = x + 12; + var7 = y - 12; + int var9 = 8; + if(toolTips.length > 1) { + var9 += 2 + (toolTips.length - 1) * 10; + } + + if(this.guiTop + var7 + var9 + 6 > this.height) { + var7 = this.height - var9 - this.guiTop - 6; + } + + super.zLevel = 300.0F; + int var10 = -267386864; + this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10); + this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10); + this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10); + this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10); + this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10); + int var11 = 1347420415; + int var12 = (var11 & 16711422) >> 1 | var11 & -16777216; + this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12); + this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12); + this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11); + this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12); + + for(int var13 = 0; var13 < toolTips.length; ++var13) { + String var14 = toolTips[var13]; + this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1); + if(var13 == 0) { + var7 += 2; + } + + var7 += 10; + } + + super.zLevel = 0.0F; + } + + GL11.glEnable(2929); + GL11.glEnable(2896); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glEnable('\u803a'); + } +} diff --git a/src/main/java/universalelectricity/prefab/RecipeHelper.java b/src/main/java/universalelectricity/prefab/RecipeHelper.java new file mode 100644 index 0000000..7ee0a03 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/RecipeHelper.java @@ -0,0 +1,131 @@ +package universalelectricity.prefab; + +import cpw.mods.fml.common.registry.GameRegistry; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.common.config.Configuration; + +public class RecipeHelper { + + public static List getRecipesByOutput(ItemStack output) { + ArrayList list = new ArrayList(); + Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator(); + + while(i$.hasNext()) { + Object obj = i$.next(); + if(obj instanceof IRecipe && ((IRecipe)obj).getRecipeOutput() == output) { + list.add((IRecipe)obj); + } + } + + return list; + } + + public static boolean replaceRecipe(IRecipe recipe, IRecipe newRecipe) { + Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator(); + + Object obj; + do { + do { + if(!i$.hasNext()) { + return false; + } + + obj = i$.next(); + } while(!(obj instanceof IRecipe)); + } while(!((IRecipe)obj).equals(recipe) && obj != recipe); + + CraftingManager.getInstance().getRecipeList().remove(obj); + CraftingManager.getInstance().getRecipeList().add(newRecipe); + return true; + } + + public static boolean replaceRecipe(ItemStack recipe, IRecipe newRecipe) { + if(removeRecipe(recipe)) { + CraftingManager.getInstance().getRecipeList().add(newRecipe); + return true; + } else { + return false; + } + } + + public static boolean removeRecipe(IRecipe recipe) { + Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator(); + + Object obj; + do { + do { + do { + if(!i$.hasNext()) { + return false; + } + + obj = i$.next(); + } while(obj == null); + } while(!(obj instanceof IRecipe)); + } while(!((IRecipe)obj).equals(recipe) && obj != recipe); + + CraftingManager.getInstance().getRecipeList().remove(obj); + return true; + } + + public static boolean removeRecipe(ItemStack stack) { + Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator(); + + Object obj; + do { + if(!i$.hasNext()) { + return false; + } + + obj = i$.next(); + } while(obj == null || !(obj instanceof IRecipe) || ((IRecipe)obj).getRecipeOutput() == null || !((IRecipe)obj).getRecipeOutput().isItemEqual(stack)); + + CraftingManager.getInstance().getRecipeList().remove(obj); + return true; + } + + public static boolean removeRecipes(ItemStack ... itemStacks) { + boolean didRemove = false; + Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); + + while(itr.hasNext()) { + Object obj = itr.next(); + if(obj != null && obj instanceof IRecipe && ((IRecipe)obj).getRecipeOutput() != null) { + ItemStack[] arr$ = itemStacks; + int len$ = itemStacks.length; + + for(int i$ = 0; i$ < len$; ++i$) { + ItemStack itemStack = arr$[i$]; + if(((IRecipe)obj).getRecipeOutput().isItemEqual(itemStack)) { + itr.remove(); + didRemove = true; + break; + } + } + } + } + + return didRemove; + } + + public static void addRecipe(IRecipe recipe, String name, Configuration configuration, boolean defaultBoolean) { + if(configuration != null) { + configuration.load(); + if(configuration.get("Crafting", "Allow " + name + " Crafting", defaultBoolean).getBoolean(defaultBoolean)) { + GameRegistry.addRecipe(recipe); + } + + configuration.save(); + } + + } + + public static void addRecipe(IRecipe recipe, Configuration config, boolean defaultBoolean) { + addRecipe(recipe, recipe.getRecipeOutput().getUnlocalizedName(), config, defaultBoolean); + } +} diff --git a/src/main/java/universalelectricity/prefab/SlotSpecific.java b/src/main/java/universalelectricity/prefab/SlotSpecific.java new file mode 100644 index 0000000..12e53ba --- /dev/null +++ b/src/main/java/universalelectricity/prefab/SlotSpecific.java @@ -0,0 +1,74 @@ +package universalelectricity.prefab; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotSpecific extends Slot { + + public ItemStack[] validItemStacks = new ItemStack[0]; + public Class[] validClasses = new Class[0]; + public boolean isInverted = false; + public boolean isMetadataSensitive = false; + + + public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, ItemStack ... itemStacks) { + super(par2IInventory, par3, par4, par5); + this.setItemStacks(itemStacks); + } + + public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, Class ... validClasses) { + super(par2IInventory, par3, par4, par5); + this.setClasses(validClasses); + } + + public SlotSpecific setMetadataSensitive() { + this.isMetadataSensitive = true; + return this; + } + + public SlotSpecific setItemStacks(ItemStack ... validItemStacks) { + this.validItemStacks = validItemStacks; + return this; + } + + public SlotSpecific setClasses(Class ... validClasses) { + this.validClasses = validClasses; + return this; + } + + public SlotSpecific toggleInverted() { + this.isInverted = !this.isInverted; + return this; + } + + public boolean isItemValid(ItemStack compareStack) { + boolean returnValue = false; + ItemStack[] arr$ = this.validItemStacks; + int len$ = arr$.length; + + int i$; + for(i$ = 0; i$ < len$; ++i$) { + ItemStack clazz = arr$[i$]; + if(compareStack.isItemEqual(clazz) || !this.isMetadataSensitive && compareStack.getItem() == clazz.getItem()) { + returnValue = true; + break; + } + } + + if(!returnValue) { + Class[] var7 = this.validClasses; + len$ = var7.length; + + for(i$ = 0; i$ < len$; ++i$) { + Class var8 = var7[i$]; + if(var8.equals(compareStack.getItem().getClass()) || var8.isInstance(compareStack.getItem())) { + returnValue = true; + break; + } + } + } + + return this.isInverted?!returnValue:returnValue; + } +} diff --git a/src/main/java/universalelectricity/prefab/TranslationHelper.java b/src/main/java/universalelectricity/prefab/TranslationHelper.java new file mode 100644 index 0000000..6456da6 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/TranslationHelper.java @@ -0,0 +1,49 @@ +package universalelectricity.prefab; + +import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.registry.LanguageRegistry; + +public class TranslationHelper { + + public static int loadLanguages(String languagePath, String[] languageSupported) { + int languages = 0; + String[] arr$ = languageSupported; + int len$ = languageSupported.length; + + for(int i$ = 0; i$ < len$; ++i$) { + String language = arr$[i$]; + LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", language, false); + if(LanguageRegistry.instance().getStringLocalization("children", language) != "") { + try { + String[] e = LanguageRegistry.instance().getStringLocalization("children", language).split(","); + String[] arr$1 = e; + int len$1 = e.length; + + for(int i$1 = 0; i$1 < len$1; ++i$1) { + String child = arr$1[i$1]; + if(child != "" || child != null) { + LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", child, false); + ++languages; + } + } + } catch (Exception var12) { + FMLLog.severe("Failed to load a child language file.", new Object[0]); + var12.printStackTrace(); + } + } + + ++languages; + } + + return languages; + } + + public static String getLocal(String key) { + String text = LanguageRegistry.instance().getStringLocalization(key); + if(text == null || text == "") { + text = LanguageRegistry.instance().getStringLocalization(key, "en_US"); + } + + return text; + } +} diff --git a/src/main/java/universalelectricity/prefab/block/BlockAdvanced.java b/src/main/java/universalelectricity/prefab/block/BlockAdvanced.java new file mode 100644 index 0000000..bed7a7c --- /dev/null +++ b/src/main/java/universalelectricity/prefab/block/BlockAdvanced.java @@ -0,0 +1,154 @@ +package universalelectricity.prefab.block; + +import java.lang.reflect.Method; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public abstract class BlockAdvanced extends BlockContainer { + + public BlockAdvanced(Material material) { + super(material); + this.setHardness(0.6F); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + world.getBlockMetadata(x, y, z); + if(this.isUsableWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z)) { + this.damageWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z); + if(entityPlayer.isSneaking() && this.onSneakUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ)) { + return true; + } + + if(this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ)) { + return true; + } + } + + return entityPlayer.isSneaking() && this.onSneakMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ)?true:this.onMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); + } + + public boolean isUsableWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z) { + if(entityPlayer != null && itemStack != null) { + Class wrenchClass = itemStack.getItem().getClass(); + + try { + Method e = wrenchClass.getMethod("canWrench", new Class[]{EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE}); + return ((Boolean)e.invoke(itemStack.getItem(), new Object[]{entityPlayer, Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z)})).booleanValue(); + } catch (NoClassDefFoundError var8) { + ; + } catch (Exception var9) { + ; + } + + try { + if(wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric")) { + return itemStack.getItemDamage() < itemStack.getMaxDamage(); + } + } catch (Exception var10) { + ; + } + } + + return false; + } + + public boolean damageWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z) { + if(this.isUsableWrench(entityPlayer, itemStack, x, y, z)) { + Class wrenchClass = itemStack.getItem().getClass(); + + Method e; + try { + e = wrenchClass.getMethod("wrenchUsed", new Class[]{EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE}); + e.invoke(itemStack.getItem(), new Object[]{entityPlayer, Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z)}); + return true; + } catch (Exception var9) { + try { + if(wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric")) { + e = wrenchClass.getMethod("damage", new Class[]{ItemStack.class, Integer.TYPE, EntityPlayer.class}); + e.invoke(itemStack.getItem(), new Object[]{itemStack, Integer.valueOf(1), entityPlayer}); + return true; + } + } catch (Exception var8) { + ; + } + } + } + + return false; + } + + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + return false; + } + + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + return false; + } + + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + return false; + } + + public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); + } + + @Override + public TileEntity createTileEntity(World var1, int meta) { + return null; + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { + this.dropEntireInventory(world, x, y, z, par5, par6); + super.breakBlock(world, x, y, z, par5, par6); + } + + public void dropEntireInventory(World world, int x, int y, int z, Block par5, int par6) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity != null && tileEntity instanceof IInventory) { + IInventory inventory = (IInventory)tileEntity; + + for(int var6 = 0; var6 < inventory.getSizeInventory(); ++var6) { + ItemStack var7 = inventory.getStackInSlot(var6); + if(var7 != null) { + Random random = new Random(); + float var8 = random.nextFloat() * 0.8F + 0.1F; + float var9 = random.nextFloat() * 0.8F + 0.1F; + float var10 = random.nextFloat() * 0.8F + 0.1F; + + while(var7.stackSize > 0) { + int var11 = random.nextInt(21) + 10; + if(var11 > var7.stackSize) { + var11 = var7.stackSize; + } + + var7.stackSize -= var11; + EntityItem var12 = new EntityItem(world, (double)((float)x + var8), (double)((float)y + var9), (double)((float)z + var10), new ItemStack(var7.getItem(), var11, var7.getItemDamage())); + if(var7.hasTagCompound()) { + var12.getEntityItem().setTagCompound((NBTTagCompound)var7.getTagCompound().copy()); + } + + float var13 = 0.05F; + var12.motionX = (double)((float)random.nextGaussian() * var13); + var12.motionY = (double)((float)random.nextGaussian() * var13 + 0.2F); + var12.motionZ = (double)((float)random.nextGaussian() * var13); + world.spawnEntityInWorld(var12); + } + } + } + } + + } +} diff --git a/src/main/java/universalelectricity/prefab/block/BlockConductor.java b/src/main/java/universalelectricity/prefab/block/BlockConductor.java new file mode 100644 index 0000000..48ab516 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/block/BlockConductor.java @@ -0,0 +1,34 @@ +package universalelectricity.prefab.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.core.block.IConductor; + +public abstract class BlockConductor extends BlockContainer { + + public BlockConductor(Material material) { + super(material); + } + + @Override + public void onBlockAdded(World world, int x, int y, int z) { + super.onBlockAdded(world, x, y, z); + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity instanceof IConductor) { + ((IConductor)tileEntity).updateAdjacentConnections(); + } + + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block blockID) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity instanceof IConductor) { + ((IConductor)tileEntity).updateAdjacentConnections(); + } + + } +} diff --git a/src/main/java/universalelectricity/prefab/block/BlockRotatable.java b/src/main/java/universalelectricity/prefab/block/BlockRotatable.java new file mode 100644 index 0000000..da83333 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/block/BlockRotatable.java @@ -0,0 +1,51 @@ +package universalelectricity.prefab.block; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.prefab.implement.IRotatable; + +public abstract class BlockRotatable extends BlockAdvanced implements IRotatable { + + public BlockRotatable(Material material) { + super(material); + } + + public void func_71860_a(World world, int x, int y, int z, EntityLiving entityLiving, ItemStack itemStack) { + int angle = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + byte change = 3; + switch(angle) { + case 0: + change = 2; + break; + case 1: + change = 5; + break; + case 2: + change = 3; + break; + case 3: + change = 4; + } + + this.setDirection(world, x, y, z, ForgeDirection.getOrientation(change)); + } + + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + this.setDirection(world, x, y, z, ForgeDirection.getOrientation(ForgeDirection.ROTATION_MATRIX[0][this.getDirection(world, x, y, z).ordinal()])); + return true; + } + + public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z) { + return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)); + } + + public void setDirection(World world, int x, int y, int z, ForgeDirection facingDirection) { + world.setBlockMetadataWithNotify(x, y, z, facingDirection.ordinal(), 3); + } +} diff --git a/src/main/java/universalelectricity/prefab/implement/IDisableable.java b/src/main/java/universalelectricity/prefab/implement/IDisableable.java new file mode 100644 index 0000000..c4e3d16 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IDisableable.java @@ -0,0 +1,9 @@ +package universalelectricity.prefab.implement; + + +public interface IDisableable { + + void onDisable(int var1); + + boolean isDisabled(); +} diff --git a/src/main/java/universalelectricity/prefab/implement/IRedstoneProvider.java b/src/main/java/universalelectricity/prefab/implement/IRedstoneProvider.java new file mode 100644 index 0000000..7631422 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IRedstoneProvider.java @@ -0,0 +1,10 @@ +package universalelectricity.prefab.implement; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IRedstoneProvider { + + boolean isPoweringTo(ForgeDirection var1); + + boolean isIndirectlyPoweringTo(ForgeDirection var1); +} diff --git a/src/main/java/universalelectricity/prefab/implement/IRedstoneReceptor.java b/src/main/java/universalelectricity/prefab/implement/IRedstoneReceptor.java new file mode 100644 index 0000000..22c9001 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IRedstoneReceptor.java @@ -0,0 +1,9 @@ +package universalelectricity.prefab.implement; + + +public interface IRedstoneReceptor { + + void onPowerOn(); + + void onPowerOff(); +} diff --git a/src/main/java/universalelectricity/prefab/implement/IRotatable.java b/src/main/java/universalelectricity/prefab/implement/IRotatable.java new file mode 100644 index 0000000..e007baf --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IRotatable.java @@ -0,0 +1,12 @@ +package universalelectricity.prefab.implement; + +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public interface IRotatable { + + ForgeDirection getDirection(IBlockAccess var1, int var2, int var3, int var4); + + void setDirection(World var1, int var2, int var3, int var4, ForgeDirection var5); +} diff --git a/src/main/java/universalelectricity/prefab/implement/ITier.java b/src/main/java/universalelectricity/prefab/implement/ITier.java new file mode 100644 index 0000000..9a84564 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/ITier.java @@ -0,0 +1,9 @@ +package universalelectricity.prefab.implement; + + +public interface ITier { + + int getTier(); + + void setTier(int var1); +} diff --git a/src/main/java/universalelectricity/prefab/implement/IToolConfigurator.java b/src/main/java/universalelectricity/prefab/implement/IToolConfigurator.java new file mode 100644 index 0000000..c8f3e32 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IToolConfigurator.java @@ -0,0 +1,10 @@ +package universalelectricity.prefab.implement; + +import net.minecraft.entity.player.EntityPlayer; + +public interface IToolConfigurator { + + boolean canWrench(EntityPlayer var1, int var2, int var3, int var4); + + void wrenchUsed(EntityPlayer var1, int var2, int var3, int var4); +} diff --git a/src/main/java/universalelectricity/prefab/multiblock/BlockMulti.java b/src/main/java/universalelectricity/prefab/multiblock/BlockMulti.java new file mode 100644 index 0000000..839bca4 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/multiblock/BlockMulti.java @@ -0,0 +1,110 @@ +package universalelectricity.prefab.multiblock; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.vector.Vector3; + +public class BlockMulti extends BlockContainer { + + public String textureName = null; + public String channel = ""; + + + public BlockMulti() { + super(UniversalElectricity.machine); + this.setHardness(0.8F); + //TODO WTF + //this.setUnlocalizedName("multiBlock"); + } + + public BlockMulti setChannel(String channel) { + this.channel = channel; + return this; + } + + public BlockMulti setTextureName(String name) { + this.textureName = name; + return this; + } + + public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock) { + worldObj.setBlock(position.intX(), position.intY(), position.intZ(), this); + ((TileEntityMulti)worldObj.getTileEntity(position.intX(), position.intY(), position.intZ())).setMainBlock(mainBlock); + } + + @SideOnly(Side.CLIENT) + @Override + public void registerBlockIcons(IIconRegister iconRegister) { + if(this.textureName != null) { + this.blockIcon = iconRegister.registerIcon(this.textureName); + } else { + super.registerBlockIcons(iconRegister); + } + + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity instanceof TileEntityMulti) { + ((TileEntityMulti)tileEntity).onBlockRemoval(); + } + + super.breakBlock(world, x, y, z, par5, par6); + } + + @Override + public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { + TileEntityMulti tileEntity = (TileEntityMulti)par1World.getTileEntity(x, y, z); + return tileEntity.onBlockActivated(par1World, x, y, z, par5EntityPlayer); + } + + @Override + public int quantityDropped(Random par1Random) { + return 0; + } + + @Override + public int getRenderType() { + return -1; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public TileEntity createNewTileEntity(World var1, int meta) { + return new TileEntityMulti(this.channel); + } + + public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z) { + TileEntity tileEntity = par1World.getTileEntity(x, y, z); + Vector3 mainBlockPosition = ((TileEntityMulti)tileEntity).mainBlockPosition; + if(mainBlockPosition != null) { + Block mainBlockID = par1World.getBlock(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ()); + if(mainBlockID != Blocks.air) { + return mainBlockID.getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ()); + } + } + + return null; + } +} diff --git a/src/main/java/universalelectricity/prefab/multiblock/IBlockActivate.java b/src/main/java/universalelectricity/prefab/multiblock/IBlockActivate.java new file mode 100644 index 0000000..7657fca --- /dev/null +++ b/src/main/java/universalelectricity/prefab/multiblock/IBlockActivate.java @@ -0,0 +1,8 @@ +package universalelectricity.prefab.multiblock; + +import net.minecraft.entity.player.EntityPlayer; + +public interface IBlockActivate { + + boolean onActivated(EntityPlayer var1); +} diff --git a/src/main/java/universalelectricity/prefab/multiblock/IMultiBlock.java b/src/main/java/universalelectricity/prefab/multiblock/IMultiBlock.java new file mode 100644 index 0000000..820c5cc --- /dev/null +++ b/src/main/java/universalelectricity/prefab/multiblock/IMultiBlock.java @@ -0,0 +1,12 @@ +package universalelectricity.prefab.multiblock; + +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.multiblock.IBlockActivate; + +public interface IMultiBlock extends IBlockActivate { + + void onCreate(Vector3 var1); + + void onDestroy(TileEntity var1); +} diff --git a/src/main/java/universalelectricity/prefab/multiblock/TileEntityMulti.java b/src/main/java/universalelectricity/prefab/multiblock/TileEntityMulti.java new file mode 100644 index 0000000..b518d6c --- /dev/null +++ b/src/main/java/universalelectricity/prefab/multiblock/TileEntityMulti.java @@ -0,0 +1,106 @@ +package universalelectricity.prefab.multiblock; + +import com.google.common.io.ByteArrayDataInput; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.network.play.server.S3FPacketCustomPayload; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.multiblock.BlockMulti; +import universalelectricity.prefab.multiblock.IMultiBlock; + +public class TileEntityMulti extends TileEntity { + + public Vector3 mainBlockPosition; + public String channel; + + + public TileEntityMulti() {} + + public TileEntityMulti(String channel) { + this.channel = channel; + } + + public void setMainBlock(Vector3 mainBlock) { + this.mainBlockPosition = mainBlock; + if(!this.worldObj.isRemote) { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + + } + + /*@Override + public Packet getDescriptionPacket() { + if(this.mainBlockPosition == null) { + return null; + } else { + if(this.channel == null || this.channel == "" && this.getBlockType() instanceof BlockMulti) { + this.channel = ((BlockMulti)this.getBlockType()).channel; + } + + return PacketManager.getPacket(this.channel, this, new Object[]{Integer.valueOf(this.mainBlockPosition.intX()), Integer.valueOf(this.mainBlockPosition.intY()), Integer.valueOf(this.mainBlockPosition.intZ())}); + } + }*/ + + public void onBlockRemoval() { + if(this.mainBlockPosition != null) { + TileEntity tileEntity = this.worldObj.getTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ()); + if(tileEntity != null && tileEntity instanceof IMultiBlock) { + IMultiBlock mainBlock = (IMultiBlock)tileEntity; + if(mainBlock != null) { + mainBlock.onDestroy(this); + } + } + } + + } + + public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer) { + if(this.mainBlockPosition != null) { + TileEntity tileEntity = this.worldObj.getTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ()); + if(tileEntity != null && tileEntity instanceof IMultiBlock) { + return ((IMultiBlock)tileEntity).onActivated(par5EntityPlayer); + } + } + + return false; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.mainBlockPosition = Vector3.readFromNBT(nbt.getCompoundTag("mainBlockPosition")); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + if(this.mainBlockPosition != null) { + nbt.setTag("mainBlockPosition", this.mainBlockPosition.writeToNBT(new NBTTagCompound())); + } + + } + + public boolean canUpdate() { + return false; + } + + /*@Override + public void handlePacketData(NetworkManager network, int packetType, S3FPacketCustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { + try { + this.mainBlockPosition = new Vector3((double)dataStream.readInt(), (double)dataStream.readInt(), (double)dataStream.readInt()); + } catch (Exception var7) { + var7.printStackTrace(); + } + }*/ + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + + } + +} diff --git a/src/main/java/universalelectricity/prefab/ore/OreGenBase.java b/src/main/java/universalelectricity/prefab/ore/OreGenBase.java new file mode 100644 index 0000000..26388a1 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/ore/OreGenBase.java @@ -0,0 +1,60 @@ +package universalelectricity.prefab.ore; + +import cpw.mods.fml.common.FMLLog; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.oredict.OreDictionary; + +public abstract class OreGenBase { + + public String name; + public String oreDictionaryName; + public boolean shouldGenerate = false; + public int blockIndexTexture; + public ItemStack oreStack; + public Block oreID; + public int oreMeta; + public int harvestLevel; + public String harvestTool; + + + public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel) { + if(stack != null) { + this.name = name; + this.harvestTool = harvestTool; + this.harvestLevel = harvestLevel; + this.oreDictionaryName = oreDiectionaryName; + this.oreStack = stack; + this.oreID = Block.getBlockFromItem(stack.getItem()); + this.oreMeta = stack.getItemDamage(); + OreDictionary.registerOre(this.oreDictionaryName, stack); + oreID.setHarvestLevel(harvestTool, harvestLevel, stack.getItemDamage()); + + } else { + FMLLog.severe("ItemStack is null while registering ore generation!", new Object[0]); + } + + } + + public OreGenBase enable(Configuration config) { + this.shouldGenerate = shouldGenerateOre(config, this.name); + return this; + } + + private static boolean shouldGenerateOre(Configuration configuration, String oreName) { + configuration.load(); + boolean shouldGenerate = configuration.get("Ore_Generation", "Generate " + oreName, true).getBoolean(true); + configuration.save(); + return shouldGenerate; + } + + public abstract void generate(World var1, Random var2, int var3, int var4); + + public abstract boolean isOreGeneratedInWorld(World var1, IChunkProvider var2); +} diff --git a/src/main/java/universalelectricity/prefab/ore/OreGenReplace.java b/src/main/java/universalelectricity/prefab/ore/OreGenReplace.java new file mode 100644 index 0000000..39cc980 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/ore/OreGenReplace.java @@ -0,0 +1,99 @@ +package universalelectricity.prefab.ore; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.ChunkProviderEnd; +import net.minecraft.world.gen.ChunkProviderGenerate; +import net.minecraft.world.gen.ChunkProviderHell; + +public class OreGenReplace extends OreGenBase { + + public int minGenerateLevel; + public int maxGenerateLevel; + public int amountPerChunk; + public int amountPerBranch; + public Block replaceID; + public boolean ignoreSurface = false; + public boolean ignoreNether = true; + public boolean ignoreEnd = true; + + + public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, Block replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) { + super(name, oreDiectionaryName, stack, harvestTool, harvestLevel); + this.minGenerateLevel = minGenerateLevel; + this.maxGenerateLevel = maxGenerateLevel; + this.amountPerChunk = amountPerChunk; + this.amountPerBranch = amountPerBranch; + this.replaceID = replaceID; + } + + public void generate(World world, Random random, int varX, int varZ) { + try { + for(int e = 0; e < this.amountPerChunk; ++e) { + int x = varX + random.nextInt(16); + int z = varZ + random.nextInt(16); + int y = random.nextInt(Math.max(this.maxGenerateLevel - this.minGenerateLevel, 0)) + this.minGenerateLevel; + this.generateReplace(world, random, x, y, z); + } + } catch (Exception var9) { + System.out.println("Error generating ore: " + super.name); + var9.printStackTrace(); + } + + } + + public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5) { + float var6 = par2Random.nextFloat() * 3.1415927F; + double var7 = (double)((float)(par3 + 8) + MathHelper.sin(var6) * (float)this.amountPerBranch / 8.0F); + double var9 = (double)((float)(par3 + 8) - MathHelper.sin(var6) * (float)this.amountPerBranch / 8.0F); + double var11 = (double)((float)(par5 + 8) + MathHelper.cos(var6) * (float)this.amountPerBranch / 8.0F); + double var13 = (double)((float)(par5 + 8) - MathHelper.cos(var6) * (float)this.amountPerBranch / 8.0F); + double var15 = (double)(par4 + par2Random.nextInt(3) - 2); + double var17 = (double)(par4 + par2Random.nextInt(3) - 2); + + for(int var19 = 0; var19 <= this.amountPerBranch; ++var19) { + double var20 = var7 + (var9 - var7) * (double)var19 / (double)this.amountPerBranch; + double var22 = var15 + (var17 - var15) * (double)var19 / (double)this.amountPerBranch; + double var24 = var11 + (var13 - var11) * (double)var19 / (double)this.amountPerBranch; + double var26 = par2Random.nextDouble() * (double)this.amountPerBranch / 16.0D; + double var28 = (double)(MathHelper.sin((float)var19 * 3.1415927F / (float)this.amountPerBranch) + 1.0F) * var26 + 1.0D; + double var30 = (double)(MathHelper.sin((float)var19 * 3.1415927F / (float)this.amountPerBranch) + 1.0F) * var26 + 1.0D; + int var32 = MathHelper.floor_double(var20 - var28 / 2.0D); + int var33 = MathHelper.floor_double(var22 - var30 / 2.0D); + int var34 = MathHelper.floor_double(var24 - var28 / 2.0D); + int var35 = MathHelper.floor_double(var20 + var28 / 2.0D); + int var36 = MathHelper.floor_double(var22 + var30 / 2.0D); + int var37 = MathHelper.floor_double(var24 + var28 / 2.0D); + + for(int var38 = var32; var38 <= var35; ++var38) { + double var39 = ((double)var38 + 0.5D - var20) / (var28 / 2.0D); + if(var39 * var39 < 1.0D) { + for(int var41 = var33; var41 <= var36; ++var41) { + double var42 = ((double)var41 + 0.5D - var22) / (var30 / 2.0D); + if(var39 * var39 + var42 * var42 < 1.0D) { + for(int var44 = var34; var44 <= var37; ++var44) { + double var45 = ((double)var44 + 0.5D - var24) / (var28 / 2.0D); + Block block = par1World.getBlock(var38, var41, var44); + if(var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == Blocks.air || block == this.replaceID)) { + par1World.setBlock(var38, var41, var44, super.oreID, super.oreMeta, 2); + } + } + } + } + } + } + } + + return true; + } + + public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator) { + return !super.shouldGenerate?false:(this.ignoreSurface && chunkGenerator instanceof ChunkProviderGenerate?false:(this.ignoreNether && chunkGenerator instanceof ChunkProviderHell?false:!this.ignoreEnd || !(chunkGenerator instanceof ChunkProviderEnd))); + } +} diff --git a/src/main/java/universalelectricity/prefab/ore/OreGenReplaceStone.java b/src/main/java/universalelectricity/prefab/ore/OreGenReplaceStone.java new file mode 100644 index 0000000..8e033e8 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/ore/OreGenReplaceStone.java @@ -0,0 +1,16 @@ +package universalelectricity.prefab.ore; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import universalelectricity.prefab.ore.OreGenReplace; + +public class OreGenReplaceStone extends OreGenReplace { + + public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) { + super(name, oreDiectionaryName, stack, Blocks.stone, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel); + } + + public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int maxGenerateLevel, int amountPerChunk, int amountPerBranch) { + this(name, oreDiectionaryName, stack, 0, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1); + } +} diff --git a/src/main/java/universalelectricity/prefab/ore/OreGenerator.java b/src/main/java/universalelectricity/prefab/ore/OreGenerator.java new file mode 100644 index 0000000..4b0d74a --- /dev/null +++ b/src/main/java/universalelectricity/prefab/ore/OreGenerator.java @@ -0,0 +1,60 @@ +package universalelectricity.prefab.ore; + +import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.registry.GameRegistry; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import universalelectricity.prefab.ore.OreGenBase; + +public class OreGenerator implements IWorldGenerator { + + public static boolean isInitiated = false; + private static final List ORES_TO_GENERATE = new ArrayList(); + + + public static void addOre(OreGenBase data) { + if(!isInitiated) { + GameRegistry.registerWorldGenerator(new OreGenerator(), 10); //TODO figure out the right value instead of 10 + } + + ORES_TO_GENERATE.add(data); + } + + public static boolean oreExists(String oreName) { + Iterator i$ = ORES_TO_GENERATE.iterator(); + + OreGenBase ore; + do { + if(!i$.hasNext()) { + return false; + } + + ore = (OreGenBase)i$.next(); + } while(ore.oreDictionaryName != oreName); + + return true; + } + + public static void removeOre(OreGenBase data) { + ORES_TO_GENERATE.remove(data); + } + + public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + chunkX <<= 4; + chunkZ <<= 4; + Iterator i$ = ORES_TO_GENERATE.iterator(); + + while(i$.hasNext()) { + OreGenBase oreData = (OreGenBase)i$.next(); + if(oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator)) { + oreData.generate(world, rand, chunkX, chunkZ); + } + } + + } + +} diff --git a/src/main/java/universalelectricity/prefab/potion/CustomPotion.java b/src/main/java/universalelectricity/prefab/potion/CustomPotion.java new file mode 100644 index 0000000..3f46380 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/potion/CustomPotion.java @@ -0,0 +1,22 @@ +package universalelectricity.prefab.potion; + +import net.minecraft.potion.Potion; + +public abstract class CustomPotion extends Potion { + + public CustomPotion(int id, boolean isBadEffect, int color, String name) { + super(id, isBadEffect, color); + this.setPotionName("potion." + name); + Potion.potionTypes[this.getId()] = this; + } + + public Potion setIconIndex(int par1, int par2) { + super.setIconIndex(par1, par2); + return this; + } + + protected Potion setEffectiveness(double par1) { + super.setEffectiveness(par1); + return this; + } +} diff --git a/src/main/java/universalelectricity/prefab/potion/CustomPotionEffect.java b/src/main/java/universalelectricity/prefab/potion/CustomPotionEffect.java new file mode 100644 index 0000000..02579f6 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/potion/CustomPotionEffect.java @@ -0,0 +1,27 @@ +package universalelectricity.prefab.potion; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; + +public class CustomPotionEffect extends PotionEffect { + + public CustomPotionEffect(int potionID, int duration, int amplifier) { + super(potionID, duration, amplifier); + } + + public CustomPotionEffect(Potion potion, int duration, int amplifier) { + this(potion.getId(), duration, amplifier); + } + + public CustomPotionEffect(int potionID, int duration, int amplifier, List curativeItems) { + super(potionID, duration, amplifier); + if(curativeItems == null) { + this.setCurativeItems(new ArrayList()); + } else { + this.setCurativeItems(curativeItems); + } + + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityAdvanced.java b/src/main/java/universalelectricity/prefab/tile/TileEntityAdvanced.java new file mode 100644 index 0000000..6bd2c3e --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityAdvanced.java @@ -0,0 +1,42 @@ +package universalelectricity.prefab.tile; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; + +public abstract class TileEntityAdvanced extends TileEntity { + + protected long ticks = 0L; + + @Override + public void updateEntity() { + if(this.ticks == 0L) { + this.initiate(); + } + + if(this.ticks >= Long.MAX_VALUE) { + this.ticks = 1L; + } + + ++this.ticks; + } + + public void initiate() {} + + @Override + public int getBlockMetadata() { + if(this.blockMetadata == -1) { + this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); + } + + return this.blockMetadata; + } + + @Override + public Block getBlockType() { + if(this.blockType == null) { + this.blockType = this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord); + } + + return this.blockType; + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityConductor.java b/src/main/java/universalelectricity/prefab/tile/TileEntityConductor.java new file mode 100644 index 0000000..df053ab --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityConductor.java @@ -0,0 +1,144 @@ +package universalelectricity.prefab.tile; + +import java.util.Arrays; + +import com.google.common.io.ByteArrayDataInput; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.network.play.server.S3FPacketCustomPayload; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.ForgeDirection; + +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.INetworkProvider; +import universalelectricity.core.electricity.ElectricityNetwork; +import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public abstract class TileEntityConductor extends TileEntityAdvanced implements IConductor { + + private IElectricityNetwork network; + public boolean[] visuallyConnected = new boolean[]{false, false, false, false, false, false}; + public TileEntity[] connectedBlocks = new TileEntity[]{null, null, null, null, null, null}; + protected String channel = ""; + + + public void updateConnection(TileEntity tileEntity, ForgeDirection side) { + if(!this.worldObj.isRemote) { + if(tileEntity instanceof IConnector && ((IConnector)tileEntity).canConnect(side.getOpposite())) { + this.connectedBlocks[side.ordinal()] = tileEntity; + this.visuallyConnected[side.ordinal()] = true; + if(tileEntity.getClass() == this.getClass() && tileEntity instanceof INetworkProvider) { + this.getNetwork().mergeConnection(((INetworkProvider)tileEntity).getNetwork()); + } + + return; + } + + if(this.connectedBlocks[side.ordinal()] != null) { + this.getNetwork().stopProducing(this.connectedBlocks[side.ordinal()]); + this.getNetwork().stopRequesting(this.connectedBlocks[side.ordinal()]); + } + + this.connectedBlocks[side.ordinal()] = null; + this.visuallyConnected[side.ordinal()] = false; + } + + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if(this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.visuallyConnected[0] = nbt.getBoolean("bottom"); + this.visuallyConnected[1] = nbt.getBoolean("top"); + this.visuallyConnected[2] = nbt.getBoolean("back"); + this.visuallyConnected[3] = nbt.getBoolean("front"); + this.visuallyConnected[4] = nbt.getBoolean("left"); + this.visuallyConnected[5] = nbt.getBoolean("right"); + } + } + + public void initiate() { + this.updateAdjacentConnections(); + } + + @Override + public void invalidate() { + if(!this.worldObj.isRemote) { + this.getNetwork().splitNetwork(this); + } + + super.invalidate(); + } + + @Override + public void updateEntity() { + super.updateEntity(); + if(!this.worldObj.isRemote && super.ticks % 300L == 0L) { + this.updateAdjacentConnections(); + } + + } + + public void updateAdjacentConnections() { + if(this.worldObj != null && !this.worldObj.isRemote) { + boolean[] previousConnections = (boolean[])this.visuallyConnected.clone(); + + for(byte i = 0; i < 6; ++i) { + this.updateConnection(VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i)); + } + + if(!Arrays.equals(previousConnections, this.visuallyConnected)) { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + } + + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setBoolean("bottom", this.visuallyConnected[0]); + nbt.setBoolean("top", this.visuallyConnected[1]); + nbt.setBoolean("back", this.visuallyConnected[2]); + nbt.setBoolean("front", this.visuallyConnected[3]); + nbt.setBoolean("left", this.visuallyConnected[4]); + nbt.setBoolean("right", this.visuallyConnected[5]); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.getBlockMetadata(), nbt); + //return PacketManager.getPacket(this.channel, this, new Object[]{Boolean.valueOf(this.visuallyConnected[0]), Boolean.valueOf(this.visuallyConnected[1]), Boolean.valueOf(this.visuallyConnected[2]), Boolean.valueOf(this.visuallyConnected[3]), Boolean.valueOf(this.visuallyConnected[4]), Boolean.valueOf(this.visuallyConnected[5])}); + } + + public IElectricityNetwork getNetwork() { + if(this.network == null) { + this.setNetwork(new ElectricityNetwork(new IConductor[]{this})); + } + + return this.network; + } + + public void setNetwork(IElectricityNetwork network) { + this.network = network; + } + + public TileEntity[] getAdjacentConnections() { + return this.connectedBlocks; + } + + public boolean canConnect(ForgeDirection direction) { + return true; + } + + @SideOnly(Side.CLIENT) + public AxisAlignedBB getRenderBoundingBox() { + return AxisAlignedBB.getBoundingBox((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1)); + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityDisableable.java b/src/main/java/universalelectricity/prefab/tile/TileEntityDisableable.java new file mode 100644 index 0000000..1f9b3c9 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityDisableable.java @@ -0,0 +1,27 @@ +package universalelectricity.prefab.tile; + +import universalelectricity.prefab.implement.IDisableable; + +public abstract class TileEntityDisableable extends TileEntityAdvanced implements IDisableable { + + protected int disabledTicks = 0; + + @Override + public void updateEntity() { + super.updateEntity(); + if(this.disabledTicks > 0) { + --this.disabledTicks; + this.whileDisable(); + } + } + + protected void whileDisable() {} + + public void onDisable(int duration) { + this.disabledTicks = duration; + } + + public boolean isDisabled() { + return this.disabledTicks > 0; + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityElectrical.java b/src/main/java/universalelectricity/prefab/tile/TileEntityElectrical.java new file mode 100644 index 0000000..9771f5b --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityElectrical.java @@ -0,0 +1,19 @@ +package universalelectricity.prefab.tile; + +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.IVoltage; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.prefab.tile.TileEntityDisableable; + +public abstract class TileEntityElectrical extends TileEntityDisableable implements IConnector, IVoltage { + + public double getVoltage() { + return 120.0D; + } + + @Override + public void invalidate() { + ElectricityNetworkHelper.invalidate(this); + super.invalidate(); + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java b/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java new file mode 100644 index 0000000..899bd20 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java @@ -0,0 +1,48 @@ +package universalelectricity.prefab.tile; + +import java.util.EnumSet; +import net.minecraft.entity.Entity; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.ElectricityPack; + +public abstract class TileEntityElectricityRunnable extends TileEntityElectrical { + + public double prevWatts; + public double wattsReceived = 0.0D; + + @Override + public void updateEntity() { + super.updateEntity(); + this.prevWatts = this.wattsReceived; + if(!this.worldObj.isRemote) { + if(!this.isDisabled()) { + ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest()); + this.onReceive(electricityPack); + } else { + ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack()); + } + } + + } + + protected EnumSet getConsumingSides() { + return ElectricityNetworkHelper.getDirections(this); + } + + public ElectricityPack getRequest() { + return new ElectricityPack(); + } + + public void onReceive(ElectricityPack electricityPack) { + if(UniversalElectricity.isVoltageSensitive && electricityPack.voltage > this.getVoltage()) { + this.worldObj.createExplosion((Entity)null, (double)this.xCoord, (double)this.yCoord, (double)this.zCoord, 1.5F, true); + } else { + this.wattsReceived = Math.min(this.wattsReceived + electricityPack.getWatts(), this.getWattBuffer()); + } + } + + public double getWattBuffer() { + return this.getRequest().getWatts() * 2.0D; + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityStorage.java b/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityStorage.java new file mode 100644 index 0000000..3f48d3b --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityStorage.java @@ -0,0 +1,67 @@ +package universalelectricity.prefab.tile; + +import java.util.EnumSet; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.block.IElectricityStorage; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.prefab.tile.TileEntityElectrical; + +public abstract class TileEntityElectricityStorage extends TileEntityElectrical implements IElectricityStorage { + + private double joules = 0.0D; + public double prevJoules = 0.0D; + + @Override + public void updateEntity() { + super.updateEntity(); + this.prevJoules = this.joules; + if(!this.worldObj.isRemote) { + if(!this.isDisabled()) { + ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest()); + this.onReceive(electricityPack); + } else { + ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack()); + } + } + + } + + protected EnumSet getConsumingSides() { + return ElectricityNetworkHelper.getDirections(this); + } + + public ElectricityPack getRequest() { + return new ElectricityPack((this.getMaxJoules() - this.getJoules()) / this.getVoltage(), this.getVoltage()); + } + + public void onReceive(ElectricityPack electricityPack) { + if(UniversalElectricity.isVoltageSensitive && electricityPack.voltage > this.getVoltage()) { + this.worldObj.createExplosion((Entity)null, (double)this.xCoord, (double)this.yCoord, (double)this.zCoord, 1.5F, true); + } else { + this.setJoules(this.getJoules() + electricityPack.getWatts()); + } + } + + @Override + public void readFromNBT(NBTTagCompound par1NBTTagCompound) { + super.readFromNBT(par1NBTTagCompound); + this.joules = par1NBTTagCompound.getDouble("joules"); + } + + @Override + public void writeToNBT(NBTTagCompound par1NBTTagCompound) { + super.writeToNBT(par1NBTTagCompound); + par1NBTTagCompound.setDouble("joules", this.joules); + } + + public double getJoules() { + return this.joules; + } + + public void setJoules(double joules) { + this.joules = Math.max(Math.min(joules, this.getMaxJoules()), 0.0D); + } +} diff --git a/src/main/java/universalelectricity/prefab/vector/Region2.java b/src/main/java/universalelectricity/prefab/vector/Region2.java new file mode 100644 index 0000000..8becb39 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/vector/Region2.java @@ -0,0 +1,27 @@ +package universalelectricity.prefab.vector; + +import universalelectricity.core.vector.Vector2; + +public class Region2 { + + public Vector2 min; + public Vector2 max; + + + public Region2() { + this(new Vector2(), new Vector2()); + } + + public Region2(Vector2 min, Vector2 max) { + this.min = min; + this.max = max; + } + + public boolean isIn(Vector2 point) { + return point.x > this.min.x && point.x < this.max.x && point.y > this.min.y && point.y < this.max.y; + } + + public boolean isIn(Region2 region) { + return region.max.x > this.min.x && region.min.x < this.max.x?region.max.y > this.min.y && region.min.y < this.max.y:false; + } +} diff --git a/src/main/java/universalelectricity/prefab/vector/Region3.java b/src/main/java/universalelectricity/prefab/vector/Region3.java new file mode 100644 index 0000000..ba83c0b --- /dev/null +++ b/src/main/java/universalelectricity/prefab/vector/Region3.java @@ -0,0 +1,94 @@ +package universalelectricity.prefab.vector; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.vector.Region2; + +public class Region3 { + + public Vector3 min; + public Vector3 max; + + + public Region3() { + this(new Vector3(), new Vector3()); + } + + public Region3(Vector3 min, Vector3 max) { + this.min = min; + this.max = max; + } + + public Region3(AxisAlignedBB aabb) { + this.min = new Vector3(aabb.minX, aabb.minY, aabb.minZ); + this.max = new Vector3(aabb.maxX, aabb.maxY, aabb.maxZ); + } + + public AxisAlignedBB toAABB() { + return AxisAlignedBB.getBoundingBox(this.min.x, this.min.y, this.min.z, this.max.x, this.max.y, this.max.z); + } + + public Region2 toRegion2() { + return new Region2(this.min.toVector2(), this.max.toVector2()); + } + + public boolean isIn(Vector3 point) { + return point.x > this.min.x && point.x < this.max.x && point.y > this.min.y && point.y < this.max.y && point.z > this.min.z && point.z < this.max.z; + } + + public boolean isIn(Region3 region) { + return region.max.x > this.min.x && region.min.x < this.max.x?(region.max.y > this.min.y && region.min.y < this.max.y?region.max.z > this.min.z && region.min.z < this.max.z:false):false; + } + + public void expand(Vector3 difference) { + this.min.subtract(difference); + this.max.add(difference); + } + + public List getVectors() { + ArrayList vectors = new ArrayList(); + + for(int x = this.min.intX(); x < this.max.intX(); ++x) { + for(int y = this.min.intY(); x < this.max.intY(); ++y) { + for(int z = this.min.intZ(); x < this.max.intZ(); ++z) { + vectors.add(new Vector3((double)x, (double)y, (double)z)); + } + } + } + + return vectors; + } + + public List getVectors(Vector3 center, int radius) { + ArrayList vectors = new ArrayList(); + + for(int x = this.min.intX(); x < this.max.intX(); ++x) { + for(int y = this.min.intY(); x < this.max.intY(); ++y) { + for(int z = this.min.intZ(); x < this.max.intZ(); ++z) { + Vector3 vector3 = new Vector3((double)x, (double)y, (double)z); + if(center.distanceTo(vector3) <= (double)radius) { + vectors.add(vector3); + } + } + } + } + + return vectors; + } + + public List getEntities(World world, Class entityClass) { + return world.getEntitiesWithinAABB(entityClass, this.toAABB()); + } + + public List getEntitiesExlude(World world, Entity entity) { + return world.getEntitiesWithinAABBExcludingEntity(entity, this.toAABB()); + } + + public List getEntities(World world) { + return this.getEntities(world, Entity.class); + } +} diff --git a/src/main/resources/assets/basiccomponents/languages/de_DE.properties b/src/main/resources/assets/basiccomponents/languages/de_DE.properties new file mode 100644 index 0000000..460c1db --- /dev/null +++ b/src/main/resources/assets/basiccomponents/languages/de_DE.properties @@ -0,0 +1,34 @@ +# Basic Components Language Properties +# @author Calclavia +# @translator TheVanoq + +# Blocks +tile.basiccomponents\:basiccomponents\:bcOre.0.name=Kupfererz +tile.basiccomponents\:basiccomponents\:bcOre.1.name=Zinnerz +tile.basiccomponents\:basiccomponents\:copperWire.name=Kupferkabel +tile.basiccomponents\:basiccomponents\:bcMachine.0.name=Kohle Generator +tile.basiccomponents\:basiccomponents\:bcMachine.1.name=Batteriekasten +tile.basiccomponents\:basiccomponents\:bcMachine.2.name=Elektro-Ofen + +# Items +item.basiccomponents\:battery.name=Batterie +item.basiccomponents\:circuit.name=Schaltkreis +item.basiccomponents\:circuit.0.name=Einfacher Schaltkreis +item.basiccomponents\:circuit.1.name=Erweiterter Schaltkreis +item.basiccomponents\:circuit.2.name=Elite Schaltkreis +item.basiccomponents\:bucketOil.name=Eimer mit Öl +item.basiccomponents\:wrench.name=Schraubenschlüssel +item.basiccomponents\:motor.name=Motor + +item.basiccomponents\:plateCopper.name=Kupferplatte +item.basiccomponents\:plateTin.name=Zinnplatte +item.basiccomponents\:plateBronze.name=Bronzeplatte +item.basiccomponents\:plateSteel.name=Stahlplatte + +item.basiccomponents\:ingotCopper.name=Kupferbarren +item.basiccomponents\:ingotTin.name=Zinnbarren +item.basiccomponents\:ingotBronze.name=Bronzebarren +item.basiccomponents\:ingotSteel.name=Stahlbarren + +item.basiccomponents\:dustBronze.name=Bronzestaub +item.basiccomponents\:dustSteel.name=Stahlstaub diff --git a/src/main/resources/assets/basiccomponents/languages/en_US.properties b/src/main/resources/assets/basiccomponents/languages/en_US.properties new file mode 100644 index 0000000..eb808b4 --- /dev/null +++ b/src/main/resources/assets/basiccomponents/languages/en_US.properties @@ -0,0 +1,36 @@ +# Basic Components Language Properties +# @author Calclavia + +itemGroup.BasicComponents=Basic Components + +# Blocks +tile.basiccomponents\:oreCopper.name=Copper Ore +tile.basiccomponents\:oreTin.name=Tin Ore +tile.basiccomponents\:copperWire.name=Copper Wire +tile.basiccomponents\:bcMachine.0.name=Coal Generator +tile.basiccomponents\:bcMachine.1.name=Battery Box +tile.basiccomponents\:bcMachine.2.name=Electric Furnace + +# Items +item.basiccomponents\:battery.name=Battery +item.basiccomponents\:infiniteBattery.name=Infinite Battery +item.basiccomponents\:circuitBasic.name=Basic Circuit +item.basiccomponents\:circuitAdvanced.name=Advanced Circuit +item.basiccomponents\:circuitElite.name=Elite Circuit +item.basiccomponents\:wrench.name=Wrench +item.basiccomponents\:motor.name=Motor + +item.basiccomponents\:plateCopper.name=Copper Plate +item.basiccomponents\:plateTin.name=Tin Plate +item.basiccomponents\:plateBronze.name=Bronze Plate +item.basiccomponents\:plateSteel.name=Steel Plate +item.basiccomponents\:plateIron.name=Iron Plate +item.basiccomponents\:plateGold.name=Gold Plate + +item.basiccomponents\:ingotCopper.name=Copper Ingot +item.basiccomponents\:ingotTin.name=Tin Ingot +item.basiccomponents\:ingotBronze.name=Bronze Ingot +item.basiccomponents\:ingotSteel.name=Steel Ingot + +item.basiccomponents\:dustBronze.name=Bronze Dust +item.basiccomponents\:dustSteel.name=Steel Dust \ No newline at end of file diff --git a/src/main/resources/assets/basiccomponents/languages/es_ES.properties b/src/main/resources/assets/basiccomponents/languages/es_ES.properties new file mode 100644 index 0000000..7668f16 --- /dev/null +++ b/src/main/resources/assets/basiccomponents/languages/es_ES.properties @@ -0,0 +1,37 @@ +# Basic Components Language Properties +# @author francogp + +children=es_AR,es_MX,es_UY,es_VE + +# Blocks +tile.basiccomponents\:bcOre.0.name=Mineral de Cobre +tile.basiccomponents\:bcOre.1.name=Mineral de Esta\u00F1o +tile.basiccomponents\:oilMoving.name=Petr\u00F3leo +tile.basiccomponents\:oilStill.name=Petr\u00F3leo +tile.basiccomponents\:copperWire.name=Cable de Cobre +tile.basiccomponents\:bcMachine.0.name=Generador a Carb\u00F3n +tile.basiccomponents\:bcMachine.1.name=Caja de Bater\u00EDa +tile.basiccomponents\:bcMachine.2.name=Horno El\u00E9ctrico + +# Items +item.basiccomponents\:battery.name=Bater\u00EDa +item.basiccomponents\:circuit.name=Circuito +item.basiccomponents\:circuit.0.name=Circuito B\u00E1sico +item.basiccomponents\:circuit.1.name=Circuito Avanzado +item.basiccomponents\:circuit.2.name=Circuito \u00E9lite +item.basiccomponents\:bucketOil.name=Balde de Petr\u00F3leo +item.basiccomponents\:wrench.name=Llave Inglesa +item.basiccomponents\:motor.name=Motor + +item.basiccomponents\:plateCopper.name=Placa de Cobre +item.basiccomponents\:plateTin.name=Placa de Esta\u00F1o +item.basiccomponents\:plateBronze.name=Placa de Bronce +item.basiccomponents\:plateSteel.name=Placa de Acero + +item.basiccomponents\:ingotCopper.name=Lingote de Cobre +item.basiccomponents\:ingotTin.name=Lingote de Esta\u00F1o +item.basiccomponents\:ingotBronze.name=Lingote de Bronce +item.basiccomponents\:ingotSteel.name=Lingote de Acero + +item.basiccomponents\:dustBronze.name=Polvo de Bronce +item.basiccomponents\:dustSteel.name=Polvo de Acero \ No newline at end of file diff --git a/src/main/resources/assets/basiccomponents/languages/it_IT.properties b/src/main/resources/assets/basiccomponents/languages/it_IT.properties new file mode 100644 index 0000000..c5dca55 --- /dev/null +++ b/src/main/resources/assets/basiccomponents/languages/it_IT.properties @@ -0,0 +1,33 @@ +# Basic Components Language Properties +# @author Calclavia + +# Blocks +tile.basiccomponents\:bcOre.0.name=Minerale Di Rame +tile.basiccomponents\:bcOre.1.name=Minerale Di Stagno +tile.basiccomponents\:copperWire.name=Cavo Di Rame +tile.basiccomponents\:bcMachine.0.name=Generatore A Carbone +tile.basiccomponents\:bcMachine.1.name=Scatola Batteria +tile.basiccomponents\:bcMachine.2.name=Fornace Elettrica + +# Items +item.basiccomponents\:battery.name=Batteria +item.basiccomponents\:circuit.name=Circuito +item.basiccomponents\:circuit.0.name=Circuito Base +item.basiccomponents\:circuit.1.name=Circuito Avanzato +item.basiccomponents\:circuit.2.name=Circuito Elite +item.basiccomponents\:bucketOil.name=Secchio Di Petrolio +item.basiccomponents\:wrench.name=Chiave Inglese +item.basiccomponents\:motor.name=Motore + +item.basiccomponents\:plateCopper.name=Piastra Di Rame +item.basiccomponents\:plateTin.name=Piastra Di Stagno +item.basiccomponents\:plateBronze.name=Piastra Di Bronzo +item.basiccomponents\:plateSteel.name=Piastra D'Acciaio + +item.basiccomponents\:ingotCopper.name=Lingotto Di Rame +item.basiccomponents\:ingotTin.name=Lingotto Di Stagno +item.basiccomponents\:ingotBronze.name=Lingotto Di Bronzo +item.basiccomponents\:ingotSteel.name=Lingotto D'Acciaio + +item.basiccomponents\:dustBronze.name=Polvere Di Bronzo +item.basiccomponents\:dustSteel.name=Polvere D'Acciaio \ No newline at end of file diff --git a/src/main/resources/assets/basiccomponents/languages/nl_NL.properties b/src/main/resources/assets/basiccomponents/languages/nl_NL.properties new file mode 100644 index 0000000..3b903a0 --- /dev/null +++ b/src/main/resources/assets/basiccomponents/languages/nl_NL.properties @@ -0,0 +1,35 @@ +# Basic Components Language Properties +# @author Kees Nijenhuis + +# Blocks +tile.basiccomponents\:bcOre.0.name=Koper Erts +tile.basiccomponents\:bcOre.1.name=Tin Erts +tile.basiccomponents\:oilMoving.name=Olie +tile.basiccomponents\:oilStill.name=Olie +tile.basiccomponents\:copperWire.name=Koper Draad +tile.basiccomponents\:bcMachine.0.name=Kool Generator +tile.basiccomponents\:bcMachine.1.name=Batterijen Doos +tile.basiccomponents\:bcMachine.2.name=Elektrische Oven + +# Items +item.basiccomponents\:battery.name=Batterij +item.basiccomponents\:circuit.name=Stroomkring +item.basiccomponents\:circuit.0.name=Basis Stroomkring +item.basiccomponents\:circuit.1.name=Geavanceerde Stroomkring +item.basiccomponents\:circuit.2.name=Elite Stroomkring +item.basiccomponents\:bucketOil.name=Emmer Olie +item.basiccomponents\:wrench.name=Moersleutel +item.basiccomponents\:motor.name=Moter + +item.basiccomponents\:plateCopper.name=Koperen Plaat +item.basiccomponents\:plateTin.name=Tinnen Plaat +item.basiccomponents\:plateBronze.name=Bronzen Plaat +item.basiccomponents\:plateSteel.name=Stalen Plaat + +item.basiccomponents\:ingotCopper.name=Koper Staaf +item.basiccomponents\:ingotTin.name=Tin Staaf +item.basiccomponents\:ingotBronze.name=Brons Staaf +item.basiccomponents\:ingotSteel.name=Staal Staaf + +item.basiccomponents\:dustBronze.name=Brons Poeder +item.basiccomponents\:dustSteel.name=Staal Poede diff --git a/src/main/resources/assets/basiccomponents/languages/pl_PL.properties b/src/main/resources/assets/basiccomponents/languages/pl_PL.properties new file mode 100644 index 0000000..b9d2179 --- /dev/null +++ b/src/main/resources/assets/basiccomponents/languages/pl_PL.properties @@ -0,0 +1,35 @@ +# Basic Components Language Properties +# @author unekpl + +# Bloki +tile.basiccomponents\:bcOre.0.name=Ruda miedzi +tile.basiccomponents\:bcOre.1.name=Ruda cyny +tile.basiccomponents\:oilMoving.name=Ropa naftowa +tile.basiccomponents\:oilStill.name=Ropa naftowa +tile.basiccomponents\:copperWire.name=Miedziany kabel +tile.basiccomponents\:bcMachine.0.name=Generator cieplny +tile.basiccomponents\:bcMachine.1.name=Akumulator +tile.basiccomponents\:bcMachine.2.name=Piec elektryczny + +# Przedmioty +item.basiccomponents\:battery.name=Ogniwo +item.basiccomponents\:circuit.name=Obw\u00F3d elektroniczny +item.basiccomponents\:circuit.0.name=Prosty obw\u00F3d elektroniczny +item.basiccomponents\:circuit.1.name=Zaawansowany obw\u00F3d elektroniczny +item.basiccomponents\:circuit.2.name=Skomplikowany obw\u00F3d elektroniczny +item.basiccomponents\:bucketOil.name=Wiadro ropy +item.basiccomponents\:wrench.name=Klucz +item.basiccomponents\:motor.name=Silnik + +item.basiccomponents\:plateCopper.name=Miedziana p\u0142ytka +item.basiccomponents\:plateTin.name=Cynowa p\u0142ytka +item.basiccomponents\:plateBronze.name=Br\u0105zowa p\u0142ytka +item.basiccomponents\:plateSteel.name=Stalowa p\u0142ytka + +item.basiccomponents\:ingotCopper.name=Sztabka miedzi +item.basiccomponents\:ingotTin.name=Sztabka cyny +item.basiccomponents\:ingotBronze.name=Sztabka br\u0105zu +item.basiccomponents\:ingotSteel.name=Sztabka stali + +item.basiccomponents\:dustBronze.name=Py\u0142 br\u0105zu +item.basiccomponents\:dustSteel.name=Py\u0142 stali \ No newline at end of file diff --git a/src/main/resources/assets/basiccomponents/languages/zh_CN.properties b/src/main/resources/assets/basiccomponents/languages/zh_CN.properties new file mode 100644 index 0000000..84fed92 --- /dev/null +++ b/src/main/resources/assets/basiccomponents/languages/zh_CN.properties @@ -0,0 +1,38 @@ +#Basic Components Language Properties +#@author Calclavia + +children=zh_TW + +itemGroup.BasicComponents=\u901A\u7528\u7535\u529B-\u57FA\u672C\u7EC4\u4EF6 + +# Blocks +tile.basiccomponents\:bcOre.0.name=\u94DC\u77FF\u77F3 +tile.basiccomponents\:bcOre.1.name=\u9521\u77FF\u77F3 +tile.basiccomponents\:copperWire.name=\u94DC\u7EBF +tile.basiccomponents\:bcMachine.0.name=\u706B\u529B\u53D1\u7535\u673A +tile.basiccomponents\:bcMachine.1.name=\u7535\u6C60\u7BB1 +tile.basiccomponents\:bcMachine.2.name=\u7535\u7089 + +# Items +item.basiccomponents\:battery.name=\u7535\u6C60 +item.basiccomponents\:infiniteBattery.name=\u65E0\u9650\u5BB9\u91CF\u7535\u6C60 +item.basiccomponents\:circuitBasic.name=\u57FA\u672C\u7535\u8DEF +item.basiccomponents\:circuitAdvanced.name=\u8FDB\u9636\u7535\u8DEF +item.basiccomponents\:circuitElite.name=\u9AD8\u7EA7\u7535\u8DEF +item.basiccomponents\:wrench.name=\u6273\u624B +item.basiccomponents\:motor.name=\u7535\u52A8\u673A + +item.basiccomponents\:plateCopper.name=\u94DC\u677F +item.basiccomponents\:plateTin.name=\u9521\u677F +item.basiccomponents\:plateBronze.name=\u9752\u94DC\u677F +item.basiccomponents\:plateSteel.name=\u94A2\u677F +item.basiccomponents\:plateIron.name=\u94C1\u677F +item.basiccomponents\:plateGold.name=\u91D1\u677F + +item.basiccomponents\:ingotCopper.name=\u94DC\u952D +item.basiccomponents\:ingotTin.name=\u9521\u952D +item.basiccomponents\:ingotBronze.name=\u9752\u94DC\u952D +item.basiccomponents\:ingotSteel.name=\u94A2\u952D + +item.basiccomponents\:dustBronze.name=\u9752\u94DC\u7C89 +item.basiccomponents\:dustSteel.name=\u94A2\u7C89 diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/batteryBox.png b/src/main/resources/assets/basiccomponents/textures/blocks/batteryBox.png new file mode 100644 index 0000000..5795f1c Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/batteryBox.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/coalGenerator.png b/src/main/resources/assets/basiccomponents/textures/blocks/coalGenerator.png new file mode 100644 index 0000000..0555658 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/coalGenerator.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/copperWire.png b/src/main/resources/assets/basiccomponents/textures/blocks/copperWire.png new file mode 100644 index 0000000..bd54ce5 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/copperWire.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/electricFurnace.png b/src/main/resources/assets/basiccomponents/textures/blocks/electricFurnace.png new file mode 100644 index 0000000..55e3cc9 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/electricFurnace.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/machine.png b/src/main/resources/assets/basiccomponents/textures/blocks/machine.png new file mode 100644 index 0000000..28e43c0 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/machine.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/machine_input.png b/src/main/resources/assets/basiccomponents/textures/blocks/machine_input.png new file mode 100644 index 0000000..df5fde3 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/machine_input.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/machine_output.png b/src/main/resources/assets/basiccomponents/textures/blocks/machine_output.png new file mode 100644 index 0000000..7634894 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/machine_output.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/machine_side.png b/src/main/resources/assets/basiccomponents/textures/blocks/machine_side.png new file mode 100644 index 0000000..ed5713e Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/machine_side.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/oreCopper.png b/src/main/resources/assets/basiccomponents/textures/blocks/oreCopper.png new file mode 100644 index 0000000..94736cb Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/oreCopper.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/blocks/oreTin.png b/src/main/resources/assets/basiccomponents/textures/blocks/oreTin.png new file mode 100644 index 0000000..914647c Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/blocks/oreTin.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/gui/battery_box.png b/src/main/resources/assets/basiccomponents/textures/gui/battery_box.png new file mode 100644 index 0000000..f3ab2bd Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/gui/battery_box.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/gui/coal_generator.png b/src/main/resources/assets/basiccomponents/textures/gui/coal_generator.png new file mode 100644 index 0000000..aaa65af Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/gui/coal_generator.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/gui/electric_furnace.png b/src/main/resources/assets/basiccomponents/textures/gui/electric_furnace.png new file mode 100644 index 0000000..3563c6b Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/gui/electric_furnace.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/battery.png b/src/main/resources/assets/basiccomponents/textures/items/battery.png new file mode 100644 index 0000000..60fcdb6 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/battery.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/circuitAdvanced.png b/src/main/resources/assets/basiccomponents/textures/items/circuitAdvanced.png new file mode 100644 index 0000000..1402e4f Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/circuitAdvanced.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/circuitBasic.png b/src/main/resources/assets/basiccomponents/textures/items/circuitBasic.png new file mode 100644 index 0000000..a235115 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/circuitBasic.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/circuitElite.png b/src/main/resources/assets/basiccomponents/textures/items/circuitElite.png new file mode 100644 index 0000000..5c77472 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/circuitElite.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/dustBronze.png b/src/main/resources/assets/basiccomponents/textures/items/dustBronze.png new file mode 100644 index 0000000..b384235 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/dustBronze.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/dustSteel.png b/src/main/resources/assets/basiccomponents/textures/items/dustSteel.png new file mode 100644 index 0000000..6aa1898 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/dustSteel.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/infiniteBattery.png b/src/main/resources/assets/basiccomponents/textures/items/infiniteBattery.png new file mode 100644 index 0000000..910619b Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/infiniteBattery.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/ingotBronze.png b/src/main/resources/assets/basiccomponents/textures/items/ingotBronze.png new file mode 100644 index 0000000..660c8b5 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/ingotBronze.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/ingotCopper.png b/src/main/resources/assets/basiccomponents/textures/items/ingotCopper.png new file mode 100644 index 0000000..62758ef Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/ingotCopper.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/ingotSteel.png b/src/main/resources/assets/basiccomponents/textures/items/ingotSteel.png new file mode 100644 index 0000000..ad5a9f7 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/ingotSteel.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/ingotTin.png b/src/main/resources/assets/basiccomponents/textures/items/ingotTin.png new file mode 100644 index 0000000..3b7d0d2 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/ingotTin.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/motor.png b/src/main/resources/assets/basiccomponents/textures/items/motor.png new file mode 100644 index 0000000..ed206ab Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/motor.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/plateBronze.png b/src/main/resources/assets/basiccomponents/textures/items/plateBronze.png new file mode 100644 index 0000000..85fa709 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/plateBronze.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/plateCopper.png b/src/main/resources/assets/basiccomponents/textures/items/plateCopper.png new file mode 100644 index 0000000..f036fd8 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/plateCopper.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/plateGold.png b/src/main/resources/assets/basiccomponents/textures/items/plateGold.png new file mode 100644 index 0000000..aa58bd4 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/plateGold.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/plateIron.png b/src/main/resources/assets/basiccomponents/textures/items/plateIron.png new file mode 100644 index 0000000..f3b08a2 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/plateIron.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/plateSteel.png b/src/main/resources/assets/basiccomponents/textures/items/plateSteel.png new file mode 100644 index 0000000..9f65ea2 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/plateSteel.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/plateTin.png b/src/main/resources/assets/basiccomponents/textures/items/plateTin.png new file mode 100644 index 0000000..581c9b8 Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/plateTin.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/items/wrench.png b/src/main/resources/assets/basiccomponents/textures/items/wrench.png new file mode 100644 index 0000000..ad13e8a Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/items/wrench.png differ diff --git a/src/main/resources/assets/basiccomponents/textures/models/copperWire.png b/src/main/resources/assets/basiccomponents/textures/models/copperWire.png new file mode 100644 index 0000000..c92754d Binary files /dev/null and b/src/main/resources/assets/basiccomponents/textures/models/copperWire.png differ