From b2f8f479060bfe6c3adc8dd70edaeecda903adbc Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Tue, 25 Dec 2018 22:58:41 +0100 Subject: added Windmill +added a shitton of Recipes and Items for it +added GUI's for them aswell --- .../github/bartimaeusnek/bartworks/MainMod.java | 13 +- .../client/gui/BW_GUIContainer_RotorBlock.java | 55 ++ .../client/gui/BW_GUIContainer_Windmill.java | 45 ++ .../common/blocks/BW_TileEntityContainer.java | 81 +++ .../bartworks/common/items/BW_Stonage_Rotors.java | 90 +++ .../bartworks/common/items/SimpleSubItemClass.java | 58 ++ .../bartworks/common/loaders/ItemRegistry.java | 22 + .../bartworks/common/loaders/RecipeLoader.java | 206 ++++++- .../common/tileentities/BW_RotorBlock.java | 27 + .../tileentities/GT_TileEntity_Windmill.java | 608 +++++++++++++++++++++ 10 files changed, 1169 insertions(+), 36 deletions(-) create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_RotorBlock.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_Windmill.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/common/blocks/BW_TileEntityContainer.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/common/items/BW_Stonage_Rotors.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/common/items/SimpleSubItemClass.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/BW_RotorBlock.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/GT_TileEntity_Windmill.java (limited to 'src/main/java') diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java index a2fc611223..0219ef93bd 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java @@ -4,7 +4,10 @@ package com.github.bartimaeusnek.bartworks; import com.github.bartimaeusnek.bartworks.client.creativetabs.GT2Tab; import com.github.bartimaeusnek.bartworks.client.creativetabs.bartworksTab; import com.github.bartimaeusnek.bartworks.common.ConfigHandler; +import com.github.bartimaeusnek.bartworks.common.blocks.BW_TileEntityContainer; import com.github.bartimaeusnek.bartworks.common.loaders.LoaderRegistry; +import com.github.bartimaeusnek.bartworks.common.tileentities.BW_RotorBlock; +import com.github.bartimaeusnek.bartworks.common.tileentities.GT_TileEntity_Windmill; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLInitializationEvent; @@ -12,16 +15,12 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.NetworkRegistry; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.util.GT_OreDictUnificator; +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.item.ItemStack; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import static com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry.BW_BLOCKS; - @Mod( modid = MainMod.modID, name = MainMod.name, version = MainMod.version, dependencies = "required-after:IC2; " @@ -53,7 +52,7 @@ public final class MainMod { } @Mod.EventHandler public void init(FMLInitializationEvent init) { - new LoaderRegistry().run(); + new LoaderRegistry().run(); } @Mod.EventHandler diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_RotorBlock.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_RotorBlock.java new file mode 100644 index 0000000000..1311c291ac --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_RotorBlock.java @@ -0,0 +1,55 @@ +package com.github.bartimaeusnek.bartworks.client.gui; + +import com.github.bartimaeusnek.bartworks.MainMod; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ic2.core.block.kineticgenerator.container.ContainerWindKineticGenerator; +import ic2.core.block.kineticgenerator.gui.GuiWindKineticGenerator; +import ic2.core.util.GuiTooltipHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class BW_GUIContainer_RotorBlock extends GuiWindKineticGenerator +{ + public ContainerWindKineticGenerator container; + public String name; + + public BW_GUIContainer_RotorBlock(ContainerWindKineticGenerator container1) { + super(container1); + this.container = container1; + this.name = StatCollector.translateToLocal("tile.BWRotorBlock.name"); + } + + protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { + this.fontRendererObj.drawString(this.name, (this.xSize - this.fontRendererObj.getStringWidth(this.name)) / 2, 6, 2157374); + if (this.container.base.checkrotor()) { + if (!this.container.base.rotorspace()) { + this.fontRendererObj.drawString(StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.rotorspace"), 27, 52, 2157374); + } else if (this.container.base.checkrotor() && !this.container.base.guiisminWindStrength()) { + this.fontRendererObj.drawString(StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.windweak1"), 27, 52, 2157374); + } else { + this.fontRendererObj.drawString(this.container.base.getRotorhealth() + " %", 46, 52, 2157374); + if (this.container.base.guiisoverload()) { + GuiTooltipHelper.drawAreaTooltip(p_146979_1_ - this.guiLeft, p_146979_2_ - this.guiTop, StatCollector.translateToLocal("ic2.WindKineticGenerator.error.overload"), 44, 27, 79, 52); + } + } + } else { + this.fontRendererObj.drawString(StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.rotormiss"), 27, 52, 2157374); + } + + } + + protected void drawGuiContainerBackgroundLayer(float f, int x, int y) { + GL11.glColor3f(0.5f,0.25f,0.07f); + this.mc.getTextureManager().bindTexture(new ResourceLocation(MainMod.modID, "textures/GUI/GUIPrimitiveKUBox.png")); + int j = (this.width - this.xSize) / 2; + int k = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize); + if (this.container.base.guiisoverload() && this.container.base.checkrotor()) { + this.drawTexturedModalRect(j + 44, k + 20, 176, 0, 30, 26); + this.drawTexturedModalRect(j + 102, k + 20, 176, 0, 30, 26); + } + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_Windmill.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_Windmill.java new file mode 100644 index 0000000000..76cd7d2998 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/gui/BW_GUIContainer_Windmill.java @@ -0,0 +1,45 @@ +package com.github.bartimaeusnek.bartworks.client.gui; + +import com.github.bartimaeusnek.bartworks.MainMod; +import gregtech.api.gui.GT_Container_MultiMachine; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +public class BW_GUIContainer_Windmill extends GT_GUIContainer_MultiMachine { + + public BW_GUIContainer_Windmill(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { + super(aInventoryPlayer, aTileEntity, aName, null); + } + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + if (!(this.mContainer instanceof GT_Container_MultiMachine)) + return; + + if ((((GT_Container_MultiMachine)this.mContainer).mDisplayErrorCode & 64) != 0) + this.fontRendererObj.drawString(this.trans("138", "Incomplete Structure."), 92, 22, 16448255); + } + + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + GL11.glColor3f(0.5f,0.25f,0.07f); + this.mc.getTextureManager().bindTexture(new ResourceLocation(MainMod.modID, "textures/GUI/GUI_Windmill.png")); + + int x = (this.width - this.xSize) / 2; + int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + if (this.mContainer.mMaxProgressTime > 0){ + this.drawTexturedModalRect(x+152, y+5,176,0,16,15); + this.drawTexturedModalRect(x+53, y+63,176,16,13,17); + } + + if (((GT_Container_MultiMachine)this.mContainer).mDisplayErrorCode == 0) { + if (((GT_Container_MultiMachine) this.mContainer).mActive == 0) { + GL11.glColor3f(1f,1f,1f); + this.drawTexturedModalRect(x+66, y+66,176,33,15,15); + } + } + + + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/blocks/BW_TileEntityContainer.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/blocks/BW_TileEntityContainer.java new file mode 100644 index 0000000000..b90bfeeec9 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/blocks/BW_TileEntityContainer.java @@ -0,0 +1,81 @@ +package com.github.bartimaeusnek.bartworks.common.blocks; + +import com.github.bartimaeusnek.bartworks.MainMod; +import ic2.api.tile.IWrenchable; +import ic2.core.IC2; +import ic2.core.IHasGui; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +public class BW_TileEntityContainer extends BlockContainer { + + Class tileEntity = null; + + public BW_TileEntityContainer(Material p_i45386_1_,Class tileEntity, String blockName) { + super(p_i45386_1_); + this.tileEntity=tileEntity; + this.setCreativeTab(MainMod.BWT); + this.setBlockName(blockName); + this.setBlockTextureName(MainMod.modID+":"+blockName); + } + + + @Override + public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { + if (worldObj.isRemote) { + return true; + } + if (!player.isSneaking()) { + final TileEntity tile = worldObj.getTileEntity(x, y, z); + if (tile instanceof IHasGui) { + return worldObj.isRemote || IC2.platform.launchGui(player, (IHasGui)tile); + } + } + + return false; + } + + + public void onBlockPlacedBy(final World world, final int x, final int y, final int z, final EntityLivingBase entity, final ItemStack itemStack) { + final TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof IWrenchable && itemStack != null) { + final IWrenchable tile2 = (IWrenchable)tile; + int meta = itemStack.getItemDamage(); + world.setBlockMetadataWithNotify(x, y, z, meta, 2); + if (entity != null) { + final int face = MathHelper.floor_double(entity.rotationYaw * 4.0f / 360.0f + 0.5) & 0x3; + switch (face) { + case 0: + tile2.setFacing((short)2); + break; + case 1: + tile2.setFacing((short)5); + break; + case 2: + tile2.setFacing((short)3); + break; + case 3: + tile2.setFacing((short)4); + break; + } + } + } + } + + @Override + public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { + try { + return this.tileEntity.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/items/BW_Stonage_Rotors.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/items/BW_Stonage_Rotors.java new file mode 100644 index 0000000000..3fb86d4963 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/items/BW_Stonage_Rotors.java @@ -0,0 +1,90 @@ +package com.github.bartimaeusnek.bartworks.common.items; + +import com.github.bartimaeusnek.bartworks.MainMod; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ic2.api.item.IKineticRotor; +import ic2.core.block.kineticgenerator.gui.GuiWaterKineticGenerator; +import ic2.core.block.kineticgenerator.gui.GuiWindKineticGenerator; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +import java.util.List; + +import static ic2.api.item.IKineticRotor.GearboxType.WATER; +import static ic2.api.item.IKineticRotor.GearboxType.WIND; + +public class BW_Stonage_Rotors extends Item implements IKineticRotor { + + private int[] DiaMinMax = new int[3]; + private float eff; + private GearboxType type; + private ResourceLocation tex; + private String itemTex; + + public BW_Stonage_Rotors(int diameter, float eff, int min, int max,int durability, GearboxType type,ResourceLocation tex, String Name, String itemTex){ + this.DiaMinMax[0]=diameter; + this.DiaMinMax[1]=min; + this.DiaMinMax[2]=max; + this.eff=eff; + this.type=type; + this.tex=tex; + this.setMaxDamage(durability); + this.setUnlocalizedName(Name); + this.setCreativeTab(MainMod.BWT); + this.itemTex=itemTex; + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + this.itemIcon = iconRegister.registerIcon(MainMod.modID+":"+itemTex); + } + + public void addInformation(ItemStack itemStack, EntityPlayer player, List info, boolean b) { + info.add(StatCollector.translateToLocalFormatted("ic2.itemrotor.wind.info", this.DiaMinMax[1], this.DiaMinMax[2])); + GearboxType type = null; + if (Minecraft.getMinecraft().currentScreen instanceof GuiWaterKineticGenerator) { + type = WATER; + } else if (Minecraft.getMinecraft().currentScreen instanceof GuiWindKineticGenerator) { + type = WIND; + } + if (type != null) { + info.add(StatCollector.translateToLocal(("ic2.itemrotor.fitsin." + this.isAcceptedType(itemStack, type)))); + } + } + + @Override + public int getDiameter(ItemStack itemStack) { + return this.DiaMinMax[0]; + } + + @Override + public ResourceLocation getRotorRenderTexture(ItemStack itemStack) { + return this.tex; + } + + @Override + public float getEfficiency(ItemStack itemStack) { + return this.eff; + } + + @Override + public int getMinWindStrength(ItemStack itemStack) { + return this.DiaMinMax[1]; + } + + @Override + public int getMaxWindStrength(ItemStack itemStack) { + return this.DiaMinMax[2]; + } + + @Override + public boolean isAcceptedType(ItemStack itemStack, GearboxType gearboxType) { + return gearboxType.equals(this.type); + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/items/SimpleSubItemClass.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/items/SimpleSubItemClass.java new file mode 100644 index 0000000000..76b0d79b78 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/items/SimpleSubItemClass.java @@ -0,0 +1,58 @@ +package com.github.bartimaeusnek.bartworks.common.items; + +import com.github.bartimaeusnek.bartworks.MainMod; +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.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import java.util.List; + +public class SimpleSubItemClass extends Item { + String[] tex; + @SideOnly(Side.CLIENT) + protected IIcon[] itemIcon; + + public SimpleSubItemClass(String[] tex){ + this.tex=tex; + this.hasSubtypes=true; + this.setCreativeTab(MainMod.BWT); + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + itemIcon = new IIcon[tex.length]; + for (int i = 0; i < tex.length; i++) { + itemIcon[i]=iconRegister.registerIcon(MainMod.modID+":"+tex[i]); + } + + } + + @Override + public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_) { + for (int i = 0; i < tex.length; i++) { + p_150895_3_.add(new ItemStack(p_150895_1_, 1, i)); + } + } + + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamage(int p_77617_1_) + { + if (p_77617_1_ tedList = new ArrayList(); + private BW_RotorBlock rotorBlock; + private byte hasDoor; + + public GT_TileEntity_Windmill(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + private GT_TileEntity_Windmill(String aName) { + super(aName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack itemStack) { + return true; + } + + public boolean onRunningTick(ItemStack aStack) { + if (this.mMaxProgresstime > 0) + this.mProgresstime += this.rotorBlock.getGrindPower(); + return this.rotorBlock.getGrindPower() > 0; + } + + public boolean doRandomMaintenanceDamage() { + return true; + } + + public boolean recipe_fallback(ItemStack aStack){ + //sight... fallback to the macerator recipes + GT_Recipe.GT_Recipe_Map tMap = GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; + if (tMap == null) + return false; + GT_Recipe tRecipe = tMap.findRecipe(getBaseMetaTileEntity(), false, false, V[1], null, aStack); + if (tRecipe == null) + return false; + if (tRecipe.getOutput(0) != null) { + aStack.stackSize--; + mOutputItems[0] = tRecipe.getOutput(0); + if (new XSTR().nextInt(2) == 0){ + if (tRecipe.getOutput(1) != null) + mOutputItems[1] = tRecipe.getOutput(1); + else + mOutputItems[1] = tRecipe.getOutput(0); + } + } + this.mMaxProgresstime = (tRecipe.mDuration * 2 *100); + return true; + } + + @Override + public boolean checkRecipe(ItemStack itemStack) { + + if (itemStack == null || itemStack.getItem() == null) + return false; + + if (this.mOutputItems == null) + this.mOutputItems = new ItemStack[2]; + + //Override Recipes that doesnt quite work well with OreUnificator + //Items + if (itemStack.getItem().equals(Items.wheat)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 15 * 20 * 100; + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wheat, 1L)); + this.mOutputItems[1] = (GT_OreDictUnificator.get(OrePrefixes.dustSmall, Materials.Wheat, 1L)); + return true; + } else if (itemStack.getItem().equals(Items.bone)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 15 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = new ItemStack(Items.dye, 4, 15); + else + this.mOutputItems[0] = new ItemStack(Items.dye, 3, 15); + return true; + } + //Blocks + else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.gravel)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 30 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = new ItemStack(Items.flint, 2); + else + this.mOutputItems[0] = new ItemStack(Items.flint); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.cobblestone) || Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.stone)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 2L); + else + this.mOutputItems[0] = GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Stone, 1L); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.sandstone)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 45 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = new ItemStack(Blocks.sand, 3); + else + this.mOutputItems[0] = new ItemStack(Blocks.sand, 2); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.clay) || Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.hardened_clay) || Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.stained_hardened_clay)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + this.mOutputItems[0] = Materials.Clay.getDust(1); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.redstone_block)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + this.mOutputItems[0] = Materials.Redstone.getDust(9); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.glass)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Glass, 1L)); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.wool)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = new ItemStack(Items.string, 3); + else + this.mOutputItems[0] = new ItemStack(Items.string, 2); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.glowstone)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = new ItemStack(Items.glowstone_dust, 4); + else + this.mOutputItems[0] = new ItemStack(Items.glowstone_dust, 3); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.netherrack)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Netherrack, 2L)); + else + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Netherrack, 1L)); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.log)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 2L)); + else + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L)); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.log2)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 2L)); + else + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1L)); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.pumpkin)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 15 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = new ItemStack(Items.pumpkin_seeds, 2); + else + this.mOutputItems[0] = new ItemStack(Items.pumpkin_seeds, 1); + return true; + } else if (Block.getBlockFromItem(itemStack.getItem()).equals(Blocks.melon_block)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 15 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = new ItemStack(Items.melon_seeds, 2); + else + this.mOutputItems[0] = new ItemStack(Items.melon_seeds, 1); + return true; + } + + //null checks for GT shit + if (GT_OreDictUnificator.getAssociation(itemStack) == null || + GT_OreDictUnificator.getAssociation(itemStack).mPrefix == null || + GT_OreDictUnificator.getAssociation(itemStack).mMaterial == null || + GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial == null || + GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial.getDust(1) == null + ) + return recipe_fallback(itemStack); //fallback for all non-unificated Items + + //Ore Unificator shit for balance + if (OrePrefixes.ingot.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || OrePrefixes.gem.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 45 * 20 * 100; + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial, 1L)); + return true; + } else if (OrePrefixes.ore.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.crushed, GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial, 1L)); + return true; + } else if (OrePrefixes.crushed.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 30 * 20 * 100; + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dustImpure, GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial, 1L)); + return true; + } else if (OrePrefixes.crushedPurified.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 30 * 20 * 100; + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dustPure, GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial, 1L)); + return true; + } else if (OrePrefixes.crushedCentrifuged.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 30 * 20 * 100; + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial, 1L)); + return true; + } else if (OrePrefixes.block.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix)) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial, (GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial.mSubTags.contains(SubTag.METAL) || GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial.mSubTags.contains(SubTag.CRYSTAL)) ? 9L : 1L)); + return true; + } else if ( + OrePrefixes.stone.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || + OrePrefixes.stoneBricks.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || + OrePrefixes.stoneChiseled.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || + OrePrefixes.stoneCobble.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || + OrePrefixes.stoneCracked.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || + OrePrefixes.stoneMossy.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || + OrePrefixes.stoneMossyBricks.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || + OrePrefixes.stoneSmooth.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) || + OrePrefixes.cobblestone.equals(GT_OreDictUnificator.getAssociation(itemStack).mPrefix) + ) { + itemStack.stackSize -= 1; + this.mMaxProgresstime = 60 * 20 * 100; + if (new XSTR().nextInt(2) == 0) + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial, 2L)); + else + this.mOutputItems[0] = (GT_OreDictUnificator.get(OrePrefixes.dust, GT_OreDictUnificator.getAssociation(itemStack).mMaterial.mMaterial, 1L)); + return true; + } + return recipe_fallback(itemStack); //2nd fallback + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new BW_GUIContainer_Windmill(aPlayerInventory, aBaseMetaTileEntity,this.getLocalName()); + } + + public boolean addDispenserToOutputSet(TileEntity aTileEntity) { + if (aTileEntity instanceof TileEntityDispenser) { + this.tedList.add((TileEntityDispenser) aTileEntity); + return true; + } + return false; + } + + public boolean addOutput(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) + return false; + + for (TileEntityDispenser tHatch : this.tedList) { + for (int i = tHatch.getSizeInventory() - 1; i >= 0; i--) { + if (tHatch.getStackInSlot(i) == null || GT_Utility.areStacksEqual(tHatch.getStackInSlot(i), aStack) && aStack.stackSize + tHatch.getStackInSlot(i).stackSize <= 64) { + if (GT_Utility.areStacksEqual(tHatch.getStackInSlot(i), aStack)) { + ItemStack merge = tHatch.getStackInSlot(i).copy(); + merge.stackSize = aStack.stackSize + tHatch.getStackInSlot(i).stackSize; + tHatch.setInventorySlotContents(i, merge); + } else { + tHatch.setInventorySlotContents(i, aStack.copy()); + } + + if (GT_Utility.areStacksEqual(tHatch.getStackInSlot(i), aStack)) { + aStack = null; + return true; + } else { + tHatch.setInventorySlotContents(i, null); + aStack = null; + return false; + } + } + } + } + return false; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack itemStack) { + + /* + * offset x1 = 3x3 + * offset x2 = 5x5 + * offset x3 = 7x7 + * etc. + */ + + int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 3; + int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 3; + + //floor + for (int x = -3; x <= 3; x++) { + for (int z = -3; z <= 3; z++) { + if (!((Math.abs(x) == 3 && Math.abs(z) == 3) || (xDir + x == 0 && zDir + z == 0))) + if (aBaseMetaTileEntity.getBlockOffset(xDir + x, 0, zDir + z) != Blocks.brick_block) { + return false; + } + } + } + + //h_clay shaft + for (int y = 1; y <= 4; y++) + for (int x = -2; x <= 2; x++) + for (int z = -2; z <= 2; z++) { + if (!((Math.abs(x) == 2 && Math.abs(z) == 2) || (Math.abs(x) < 2 && Math.abs(z) != 2))) + if (aBaseMetaTileEntity.getBlockOffset(xDir + x, y, zDir + z) != Blocks.hardened_clay && !this.addDispenserToOutputSet(aBaseMetaTileEntity.getTileEntityOffset(xDir + x, y, zDir + z))) { + if (aBaseMetaTileEntity.getBlockOffset(xDir + x, y, zDir + z) == Blocks.wooden_door && this.hasDoor < 3) { + this.hasDoor++; + continue; + } + return false; + } + } + + //plank layer 1 + for (int x = -2; x <= 2; x++) + for (int z = -2; z <= 2; z++) { + if (!(Math.abs(x) < 2 && Math.abs(z) != 2)) { + if (aBaseMetaTileEntity.getBlockOffset(xDir + x, 5, zDir + z) != Blocks.planks) + return false; + } + } + + //plank layer 2-4 + for (int x = -3; x <= 3; x++) + for (int y = 6; y <= 8; y++) + for (int z = -3; z <= 3; z++) + if (!(((Math.abs(x) == 3 && Math.abs(z) == 3) || (Math.abs(x) < 3 && (Math.abs(z) != 2 || Math.abs(z) != 1))) || (xDir + x == 0 && zDir + z == 0 && y == 7))) + if (aBaseMetaTileEntity.getBlockOffset(xDir + x, y, zDir + z) != Blocks.planks) + return false; + + //plank layer 5 + for (int x = -2; x <= 2; x++) + for (int z = -2; z <= 2; z++) + if (!(Math.abs(x) < 2 && (Math.abs(z) != 2))) { + if (aBaseMetaTileEntity.getBlockOffset(xDir + x, 9, zDir + z) != Blocks.planks) + return false; + } + //plank layer 6 + for (int x = -1; x <= 1; x++) + for (int z = -1; z <= 1; z++) + if (!(Math.abs(x) < 1 && (Math.abs(z) != 1))) { + if (aBaseMetaTileEntity.getBlockOffset(xDir + x, 10, zDir + z) != Blocks.planks) + return false; + } + //plank layer 7 + if (aBaseMetaTileEntity.getBlockOffset(xDir, 11, zDir) != Blocks.planks) + return false; + + //Rotor Block + TileEntity te = this.getBaseMetaTileEntity().getWorld().getTileEntity(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord() + 7, this.getBaseMetaTileEntity().getZCoord()); + + if (te instanceof BW_RotorBlock) + this.rotorBlock = (BW_RotorBlock) te; + else + return false; + + //check for outputs + if (this.tedList.isEmpty()) + return false; + + this.mWrench = true; + this.mScrewdriver = true; + this.mSoftHammer = true; + this.mHardHammer = true; + this.mSolderingTool = true; + this.mCrowbar = true; + + //reset door cause bugs >_> + this.hasDoor = 0; + + return true; + } + + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mEfficiency < 0) + this.mEfficiency = 0; + if (--this.mUpdate == 0 || --this.mStartUpCheck == 0) { + this.hasDoor = 0; + this.tedList.clear(); + this.mMachine = this.checkMachine(aBaseMetaTileEntity, this.mInventory[1]); + } + if (this.mStartUpCheck < 0) { + if (this.mMachine) { + if (this.mMaxProgresstime > 0) { + if (this.onRunningTick(this.mInventory[1])) { + if (this.mMaxProgresstime > 0 && this.mProgresstime >= this.mMaxProgresstime) { + if (this.mOutputItems != null) + for (ItemStack tStack : this.mOutputItems) + if (tStack != null) { + this.addOutput(tStack); + } + this.mEfficiency = 10000; + this.mOutputItems = new ItemStack[2]; + this.mProgresstime = 0; + this.mMaxProgresstime = 0; + this.mEfficiencyIncrease = 0; + if (aBaseMetaTileEntity.isAllowedToWork()) { + if (this.checkRecipe(this.mInventory[1])) + this.updateSlots(); + } + } + } + } else { + if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified()) { + if (aBaseMetaTileEntity.isAllowedToWork()) { + if (this.checkRecipe(this.mInventory[1])) + this.updateSlots(); + } + } + } + } else { + this.mMachine = this.checkMachine(aBaseMetaTileEntity, this.mInventory[1]); + return; + } + } else { + this.stopMachine(); + } + } + aBaseMetaTileEntity.setErrorDisplayID((aBaseMetaTileEntity.getErrorDisplayID() & ~127) | (this.mWrench ? 0 : 1) | (this.mScrewdriver ? 0 : 2) | (this.mSoftHammer ? 0 : 4) | (this.mHardHammer ? 0 : 8) | (this.mSolderingTool ? 0 : 16) | (this.mCrowbar ? 0 : 32) | (this.mMachine ? 0 : 64)); + aBaseMetaTileEntity.setActive(this.mMaxProgresstime > 0); + } + + @Override + public int getCurrentEfficiency(ItemStack itemStack) { + return 10000; + } + + @Override + public void updateSlots() { + if (this.mInventory[1] != null && this.mInventory[1].stackSize <= 0) { + this.mInventory[1] = null; + } + } + + @Override + public int getMaxEfficiency(ItemStack itemStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack itemStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack itemStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack itemStack) { + return false; + } + + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity iGregTechTileEntity) { + return new GT_TileEntity_Windmill(this.mName); + } + + @Override + public String[] getDescription() { + return new String[]{ + "A primitive Grinder powered by Kinetic energy.", + "WxHxL: 7x12x7", + "Layer 1: 7x7 Bricks, corners are air, controller at front centered.", + "Layer 2-4: 5x5 Hardened Clay, corners are air, can contain one door,", + " must contain at least one Dispenser", + "Layer 5: 5x5 Wood Planks. Corners are filled.", + "Layer 6: 7x7 Wood Planks. Corners are air.", + "Layer 8: 7x7 Wood Planks. Corners are air,", + " front centered must be a Primitive Kinetic Shaftbox", + "Layer 9: 7x7 Wood Planks. Corners are air.", + "Layer 10: 5x5 Wood Planks. Corners are filled.", + "Layer 11: 3x3 Wood Planks. Corners are filled.", + "Layer 12: 1x1 Wood Plank.", + "Needs a Wind Mill Rotor in the Shaftbox to operate", + "Input items in Controller", + "Output items will appear in the dispensers", + "Added by bartimaeusnek via "+ ChatColorHelper.DARKGREEN+"BartWorks" + }; + } + + @Override + public String[] getInfoData() { + return new String[]{"Progress:", this.mProgresstime + " Grindings of " + this.mMaxProgresstime + " needed Grindings", "GrindPower:", Integer.toString(this.rotorBlock.getGrindPower()) + "KU/t"}; + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister aBlockIconRegister) { + iIcons[0]=aBlockIconRegister.registerIcon("brick"); + iIconContainers[0]=new IIconContainer() { + @Override + public IIcon getIcon() { + return iIcons[0]; + } + + @Override + public IIcon getOverlayIcon() { + return iIcons[0]; + } + + @Override + public ResourceLocation getTextureFile() { + return new ResourceLocation("brick"); + } + }; + + iIcons[1]=aBlockIconRegister.registerIcon(MainMod.modID+":windmill_top"); + iIconContainers[1]=new IIconContainer() { + @Override + public IIcon getIcon() { + return iIcons[1]; + } + + @Override + public IIcon getOverlayIcon() { + return iIcons[1]; + } + + @Override + public ResourceLocation getTextureFile() { + return new ResourceLocation(MainMod.modID+":windmill_top"); + } + }; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + + ITexture[] ret = new ITexture[0]; + + if (isClientSide()) { + iTextures[0] = new GT_RenderedTexture(iIconContainers[0], Dyes.getModulation(0, Dyes.MACHINE_METAL.mRGBa)); + + ret = new ITexture[6]; + for (int i = 0; i < 6; i++) { + ret[i] = iTextures[0]; + } + if (aSide == 1){ + iTextures[1] = new GT_RenderedTexture(iIconContainers[1], Dyes.getModulation(0, Dyes.MACHINE_METAL.mRGBa)); + + ret = new ITexture[6]; + for (int i = 0; i < 6; i++) { + ret[i] = iTextures[1]; + } + } + + } + + + return ret; + } + + public boolean isClientSide() { + if (this.getBaseMetaTileEntity().getWorld() != null) + return this.getBaseMetaTileEntity().getWorld().isRemote ? FMLCommonHandler.instance().getSide() == Side.CLIENT : FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT; + return FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT; + } +} -- cgit