diff options
| author | GlodBlock <1356392126@qq.com> | 2021-12-07 23:02:17 +0800 |
|---|---|---|
| committer | GlodBlock <1356392126@qq.com> | 2021-12-07 23:02:17 +0800 |
| commit | 92238a0f3b06a80683f50dfd2d6e9164d2d0f1ab (patch) | |
| tree | 2d1118c74e43d5f4337266c3d64f1921c0526d42 /src/main/java/goodgenerator/blocks | |
| parent | 06cac63657f40c489477abe923ea3f144fe6749c (diff) | |
| download | GT5-Unofficial-92238a0f3b06a80683f50dfd2d6e9164d2d0f1ab.tar.gz GT5-Unofficial-92238a0f3b06a80683f50dfd2d6e9164d2d0f1ab.tar.bz2 GT5-Unofficial-92238a0f3b06a80683f50dfd2d6e9164d2d0f1ab.zip | |
rename package
Diffstat (limited to 'src/main/java/goodgenerator/blocks')
17 files changed, 3688 insertions, 0 deletions
diff --git a/src/main/java/goodgenerator/blocks/myFluids/BaseFluid.java b/src/main/java/goodgenerator/blocks/myFluids/BaseFluid.java new file mode 100644 index 0000000000..9ccbd27e70 --- /dev/null +++ b/src/main/java/goodgenerator/blocks/myFluids/BaseFluid.java @@ -0,0 +1,54 @@ +package goodgenerator.blocks.myFluids; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.util.IIcon; +import net.minecraftforge.fluids.BlockFluidClassic; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +import static goodgenerator.main.GoodGenerator.MOD_ID; + +public class BaseFluid extends BlockFluidClassic{ + @SideOnly( Side.CLIENT ) + protected IIcon stillIcon; + @SideOnly( Side.CLIENT ) + protected IIcon flowingIcon; + private String stillTexture; + private String flowingTexture; + + public BaseFluid(Fluid fluid, Material material) + { + super( fluid, material ); + } + + public void SetTexture(String fluidName) + { + stillTexture = MOD_ID + ":fluids/" + fluidName + ".still"; + flowingTexture = MOD_ID + ":fluids/" + fluidName + ".flowing"; + } + + public static Fluid BuildFluid(String fluidName){ + Fluid tFluid = new Fluid(fluidName); + FluidRegistry.registerFluid(tFluid); + return tFluid; + } + + @SideOnly( Side.CLIENT ) + @Override + public void registerBlockIcons( IIconRegister register ) + { + stillIcon = register.registerIcon(stillTexture); + flowingIcon = register.registerIcon(flowingTexture); + + super.getFluid().setIcons( stillIcon, flowingIcon ); + } + + @Override + public IIcon getIcon( int side, int meta ) + { + return ( side == 0 || side == 1 ) ? stillIcon : flowingIcon; + } +} diff --git a/src/main/java/goodgenerator/blocks/myFluids/FluidsBuilder.java b/src/main/java/goodgenerator/blocks/myFluids/FluidsBuilder.java new file mode 100644 index 0000000000..94857b73f6 --- /dev/null +++ b/src/main/java/goodgenerator/blocks/myFluids/FluidsBuilder.java @@ -0,0 +1,176 @@ +package goodgenerator.blocks.myFluids; + +import goodgenerator.crossmod.nei.NEI_Config; +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.block.material.Material; +import net.minecraftforge.fluids.Fluid; + +public class FluidsBuilder { + public FluidsBuilder(){ + } + + public static void Register() { + crackedNaquadahGas_Lightly(); + crackedNaquadahGas_Moderately(); + crackedNaquadahGas_Heavily(); + crackedLightNaquadahFuel_Lightly(); + crackedLightNaquadahFuel_Moderately(); + crackedLightNaquadahFuel_Heavily(); + crackedHeavyNaquadahFuel_Lightly(); + crackedHeavyNaquadahFuel_Moderately(); + crackedHeavyNaquadahFuel_Heavily(); + crackedNaquadahAsphalt_Lightly(); + crackedNaquadahAsphalt_Moderately(); + crackedNaquadahAsphalt_Heavily(); + combustionPromotor(); + } + + public static void crackedNaquadahGas_Lightly(){ + Fluid tmp = BaseFluid.BuildFluid("lightlyCrackedNaquadahGas"); + tmp.setGaseous(true) + .setTemperature(800); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("lightlyCrackedNaquadahGas"); + tmp2.setBlockName("lightlyCrackedNaquadahGas"); + GameRegistry.registerBlock(tmp2,"lightlyCrackedNaquadahGas"); + NEI_Config.hide(tmp2); + } + + public static void crackedNaquadahGas_Moderately(){ + Fluid tmp = BaseFluid.BuildFluid("moderatelyCrackedNaquadahGas"); + tmp.setGaseous(true) + .setTemperature(800); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("moderatelyCrackedNaquadahGas"); + tmp2.setBlockName("moderatelyCrackedNaquadahGas"); + GameRegistry.registerBlock(tmp2,"moderatelyCrackedNaquadahGas"); + NEI_Config.hide(tmp2); + } + + public static void crackedNaquadahGas_Heavily(){ + Fluid tmp = BaseFluid.BuildFluid("heavilyCrackedNaquadahGas"); + tmp.setGaseous(true) + .setTemperature(800); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("heavilyCrackedNaquadahGas"); + tmp2.setBlockName("heavilyCrackedNaquadahGas"); + GameRegistry.registerBlock(tmp2,"heavilyCrackedNaquadahGas"); + NEI_Config.hide(tmp2); + } + + public static void crackedLightNaquadahFuel_Lightly(){ + Fluid tmp = BaseFluid.BuildFluid("lightlyCrackedLightNaquadahFuel"); + tmp.setGaseous(false) + .setTemperature(1200); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("lightlyCrackedLightNaquadahFuel"); + tmp2.setBlockName("lightlyCrackedLightNaquadahFuel"); + GameRegistry.registerBlock(tmp2,"lightlyCrackedLightNaquadahFuel"); + NEI_Config.hide(tmp2); + } + + public static void crackedLightNaquadahFuel_Moderately(){ + Fluid tmp = BaseFluid.BuildFluid("moderatelyCrackedLightNaquadahFuel"); + tmp.setGaseous(false) + .setTemperature(1200); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("moderatelyCrackedLightNaquadahFuel"); + tmp2.setBlockName("moderatelyCrackedLightNaquadahFuel"); + GameRegistry.registerBlock(tmp2,"moderatelyCrackedLightNaquadahFuel"); + NEI_Config.hide(tmp2); + } + + public static void crackedLightNaquadahFuel_Heavily(){ + Fluid tmp = BaseFluid.BuildFluid("heavilyCrackedLightNaquadahFuel"); + tmp.setGaseous(false) + .setTemperature(1200); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("heavilyCrackedLightNaquadahFuel"); + tmp2.setBlockName("heavilyCrackedLightNaquadahFuel"); + GameRegistry.registerBlock(tmp2,"heavilyCrackedLightNaquadahFuel"); + NEI_Config.hide(tmp2); + } + + public static void crackedHeavyNaquadahFuel_Lightly(){ + Fluid tmp = BaseFluid.BuildFluid("lightlyCrackedHeavyNaquadahFuel"); + tmp.setGaseous(false) + .setTemperature(1200); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("lightlyCrackedHeavyNaquadahFuel"); + tmp2.setBlockName("lightlyCrackedHeavyNaquadahFuel"); + GameRegistry.registerBlock(tmp2,"lightlyCrackedHeavyNaquadahFuel"); + NEI_Config.hide(tmp2); + } + + public static void crackedHeavyNaquadahFuel_Moderately(){ + Fluid tmp = BaseFluid.BuildFluid("moderatelyCrackedHeavyNaquadahFuel"); + tmp.setGaseous(false) + .setTemperature(1200); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("moderatelyCrackedHeavyNaquadahFuel"); + tmp2.setBlockName("moderatelyCrackedHeavyNaquadahFuel"); + GameRegistry.registerBlock(tmp2,"moderatelyCrackedHeavyNaquadahFuel"); + NEI_Config.hide(tmp2); + } + + public static void crackedHeavyNaquadahFuel_Heavily(){ + Fluid tmp = BaseFluid.BuildFluid("heavilyCrackedHeavyNaquadahFuel"); + tmp.setGaseous(false) + .setTemperature(1200); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("heavilyCrackedHeavyNaquadahFuel"); + tmp2.setBlockName("heavilyCrackedHeavyNaquadahFuel"); + GameRegistry.registerBlock(tmp2,"heavilyCrackedHeavyNaquadahFuel"); + NEI_Config.hide(tmp2); + } + + public static void crackedNaquadahAsphalt_Lightly(){ + Fluid tmp = BaseFluid.BuildFluid("lightlyCrackedNaquadahAsphalt"); + tmp.setGaseous(false) + .setTemperature(1800) + .setDensity(20000) + .setViscosity(20000); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("lightlyCrackedNaquadahAsphalt"); + tmp2.setBlockName("lightlyCrackedNaquadahAsphalt"); + GameRegistry.registerBlock(tmp2,"lightlyCrackedNaquadahAsphalt"); + NEI_Config.hide(tmp2); + } + + public static void crackedNaquadahAsphalt_Moderately(){ + Fluid tmp = BaseFluid.BuildFluid("moderatelyCrackedNaquadahAsphalt"); + tmp.setGaseous(false) + .setTemperature(1800) + .setDensity(20000) + .setViscosity(20000); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("moderatelyCrackedNaquadahAsphalt"); + tmp2.setBlockName("moderatelyCrackedNaquadahAsphalt"); + GameRegistry.registerBlock(tmp2,"moderatelyCrackedNaquadahAsphalt"); + NEI_Config.hide(tmp2); + } + + public static void crackedNaquadahAsphalt_Heavily(){ + Fluid tmp = BaseFluid.BuildFluid("heavilyCrackedNaquadahAsphalt"); + tmp.setGaseous(false) + .setTemperature(1800) + .setDensity(20000) + .setViscosity(20000); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("heavilyCrackedNaquadahAsphalt"); + tmp2.setBlockName("heavilyCrackedNaquadahAsphalt"); + GameRegistry.registerBlock(tmp2,"heavilyCrackedNaquadahAsphalt"); + NEI_Config.hide(tmp2); + } + + public static void combustionPromotor(){ + Fluid tmp = BaseFluid.BuildFluid("combustionPromotor"); + tmp.setGaseous(false) + .setTemperature(300); + BaseFluid tmp2 = new BaseFluid(tmp, Material.water); + tmp2.SetTexture("combustionPromotor"); + tmp2.setBlockName("combustionPromotor"); + GameRegistry.registerBlock(tmp2,"combustionPromotor"); + NEI_Config.hide(tmp2); + } +} diff --git a/src/main/java/goodgenerator/blocks/regularBlock/Casing.java b/src/main/java/goodgenerator/blocks/regularBlock/Casing.java new file mode 100644 index 0000000000..7a1db3278d --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/Casing.java @@ -0,0 +1,123 @@ +package goodgenerator.blocks.regularBlock; + +import goodgenerator.main.GoodGenerator; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import java.util.List; + +public class Casing extends Block { + + @SideOnly(Side.CLIENT) + protected IIcon[] texture; + String[] textureNames; + protected String name; + + public Casing(String name) { + super(Material.iron); + this.setHardness(9.0F); + this.setResistance(5.0F); + this.name = name; + this.setHarvestLevel("wrench",2); + this.setCreativeTab(GoodGenerator.GG); + GregTech_API.registerMachineBlock(this, -1); + } + + public Casing(String name, String[] texture){ + super(Material.iron); + this.setHardness(9.0F); + this.setResistance(5.0F); + this.name = name; + this.textureNames = texture; + this.setHarvestLevel("wrench",2); + this.setCreativeTab(GoodGenerator.GG); + GregTech_API.registerMachineBlock(this, -1); + } + + public Casing(String name, String[] texture, Material material){ + super(material); + this.setHardness(9.0F); + this.setResistance(5.0F); + this.name = name; + this.textureNames = texture; + this.setHarvestLevel("wrench",2); + this.setCreativeTab(GoodGenerator.GG); + GregTech_API.registerMachineBlock(this, -1); + } + + @Override + public int damageDropped(int meta) { + return meta; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) { + return meta < this.texture.length ? this.texture[meta] : this.texture[0]; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister par1IconRegister) { + this.texture = new IIcon[this.textureNames.length]; + for (int i = 0; i < this.textureNames.length; i++) { + this.texture[i] = par1IconRegister.registerIcon(this.textureNames[i]); + } + } + + @Override + @SideOnly(Side.CLIENT) + @SuppressWarnings("unchecked") + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < this.textureNames.length; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public void onBlockAdded(World aWorld, int aX, int aY, int aZ) { + if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) { + GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ); + } + } + + @Override + public void breakBlock(World aWorld, int aX, int aY, int aZ, Block aBlock, int aMetaData) { + if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) { + GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ); + } + } + + @Override + public String getUnlocalizedName() { + return this.name; + } + + @Override + public boolean canBeReplacedByLeaves(IBlockAccess world, int x, int y, int z) { + return false; + } + + @Override + public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) { + return false; + } + + @Override + public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z) { + return false; + } + +} diff --git a/src/main/java/goodgenerator/blocks/regularBlock/ComplexTextureCasing.java b/src/main/java/goodgenerator/blocks/regularBlock/ComplexTextureCasing.java new file mode 100644 index 0000000000..18a1629cbf --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/ComplexTextureCasing.java @@ -0,0 +1,58 @@ +package goodgenerator.blocks.regularBlock; + +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 ComplexTextureCasing extends Casing{ + + @SideOnly(Side.CLIENT) + protected IIcon[] texture1, texture2; + String[] textureSide; + String[] textureTopAndDown; + + public ComplexTextureCasing(String name, String[] textureSide, String[] textureTopAndDown){ + super(name); + this.textureSide = textureSide; + this.textureTopAndDown = textureTopAndDown; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) { + if (side < 2) { + return meta < this.texture2.length ? this.texture2[meta] : this.texture2[0]; + } + else { + return meta < this.texture1.length ? this.texture1[meta] : this.texture1[0]; + } + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister par1IconRegister) { + this.texture1 = new IIcon[this.textureSide.length]; + for (int i = 0; i < this.textureSide.length; i++) { + this.texture1[i] = par1IconRegister.registerIcon(this.textureSide[i]); + } + this.texture2 = new IIcon[this.textureTopAndDown.length]; + for (int i = 0; i < this.textureTopAndDown.length; i++) { + this.texture2[i] = par1IconRegister.registerIcon(this.textureTopAndDown[i]); + } + } + + @Override + @SideOnly(Side.CLIENT) + @SuppressWarnings("unchecked") + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < Math.max(this.textureSide.length, this.textureTopAndDown.length); i++) { + list.add(new ItemStack(item, 1, i)); + } + } +} diff --git a/src/main/java/goodgenerator/blocks/regularBlock/Frame.java b/src/main/java/goodgenerator/blocks/regularBlock/Frame.java new file mode 100644 index 0000000000..90c38c4cce --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/Frame.java @@ -0,0 +1,36 @@ +package goodgenerator.blocks.regularBlock; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.material.Material; +import net.minecraft.world.IBlockAccess; + +public class Frame extends Casing{ + public Frame(String name,String[] texture){ + super(name,texture, Material.iron); + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public boolean shouldSideBeRendered(IBlockAccess worldClient, int xCoord, int yCoord, int zCoord, int aSide) { + if (worldClient.getBlock(xCoord, yCoord, zCoord) instanceof Frame) + return false; + return super.shouldSideBeRendered(worldClient, xCoord, yCoord, zCoord, aSide); + } + + @Override + @SideOnly(Side.CLIENT) + public int getRenderBlockPass() { + return 1; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } +} diff --git a/src/main/java/goodgenerator/blocks/regularBlock/TEBlock.java b/src/main/java/goodgenerator/blocks/regularBlock/TEBlock.java new file mode 100644 index 0000000000..b33dbffdec --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/TEBlock.java @@ -0,0 +1,180 @@ +package goodgenerator.blocks.regularBlock; + +import goodgenerator.blocks.tileEntity.EssentiaHatch; +import goodgenerator.main.GoodGenerator; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.util.GT_Utility; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EnumCreatureType; +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.StatCollector; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.IEssentiaContainerItem; + +import java.util.List; + +public class TEBlock extends BlockContainer { + + @SideOnly(Side.CLIENT) + protected IIcon[] texture; + String[] textureNames; + protected String name; + protected int index; + + public TEBlock(String name, String[] texture, CreativeTabs Tab){ + super(Material.iron); + this.setHardness(9.0F); + this.setResistance(5.0F); + this.name = name; + this.textureNames = texture; + this.setHarvestLevel("wrench",2); + this.setCreativeTab(GoodGenerator.GG); + GregTech_API.registerMachineBlock(this, -1); + } + + public TEBlock(String name, String[] texture, int index){ + super(Material.iron); + this.setHardness(9.0F); + this.setResistance(5.0F); + this.name = name; + this.textureNames = texture; + this.setHarvestLevel("wrench",2); + this.index = index; + this.setCreativeTab(GoodGenerator.GG); + GregTech_API.registerMachineBlock(this, -1); + } + + public TEBlock(String name, String[] texture, Material material){ + super(material); + this.setHardness(9.0F); + this.setResistance(5.0F); + this.name = name; + this.textureNames = texture; + this.setHarvestLevel("wrench",2); + this.setCreativeTab(GoodGenerator.GG); + GregTech_API.registerMachineBlock(this, -1); + } + + public int getIndex() { + return this.index; + } + + @Override + public int damageDropped(int meta) { + return meta; + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) { + return meta < this.texture.length ? this.texture[meta] : this.texture[0]; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister par1IconRegister) { + this.texture = new IIcon[this.textureNames.length]; + for (int i = 0; i < this.textureNames.length; i++) { + this.texture[i] = par1IconRegister.registerIcon(this.textureNames[i]); + } + } + + @Override + @SideOnly(Side.CLIENT) + @SuppressWarnings("unchecked") + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < this.textureNames.length; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public void onBlockAdded(World aWorld, int aX, int aY, int aZ) { + if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) { + GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ); + } + } + + @Override + public void breakBlock(World aWorld, int aX, int aY, int aZ, Block aBlock, int aMetaData) { + if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) { + GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ); + } + aWorld.removeTileEntity(aX, aY, aZ); + } + + @Override + public String getUnlocalizedName() { + return this.name; + } + + @Override + public boolean canBeReplacedByLeaves(IBlockAccess world, int x, int y, int z) { + return false; + } + + @Override + public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) { + return false; + } + + @Override + public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z) { + return false; + } + + @Override + public TileEntity createTileEntity(World world, int meta) { + if (index == 1) + return new EssentiaHatch(); + return null; + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { + if (world.isRemote) { + return false; + } else { + TileEntity tile = world.getTileEntity(x, y, z); + if (index == 1) { + if (tile instanceof EssentiaHatch) { + ItemStack tItemStack = player.getHeldItem(); + if (tItemStack != null) { + Item tItem = tItemStack.getItem(); + if (tItem instanceof IEssentiaContainerItem && ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem()) != null && ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem()).size() > 0) { + Aspect tLocked = ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem()).getAspects()[0]; + ((EssentiaHatch) tile).setLockedAspect(tLocked); + GT_Utility.sendChatToPlayer(player, String.format(StatCollector.translateToLocal("essentiahatch.chat.0"), tLocked.getLocalizedDescription())); + } + } + else { + ((EssentiaHatch) tile).setLockedAspect(null); + GT_Utility.sendChatToPlayer(player, StatCollector.translateToLocal("essentiahatch.chat.1")); + } + world.markBlockForUpdate(x, y, z); + return true; + } + else return false; + } + else return false; + } + } + + @Override + public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { + return null; + } +} diff --git a/src/main/java/goodgenerator/blocks/tileEntity/EssentiaHatch.java b/src/main/java/goodgenerator/blocks/tileEntity/EssentiaHatch.java new file mode 100644 index 0000000000..c8a4b1c713 --- /dev/null +++ b/src/main/java/goodgenerator/blocks/tileEntity/EssentiaHatch.java @@ -0,0 +1,225 @@ +package goodgenerator.blocks.tileEntity; + +import goodgenerator.crossmod.thaumcraft.LargeEssentiaEnergyData; +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 thaumcraft.api.ThaumcraftApiHelper; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.api.aspects.IAspectContainer; +import thaumcraft.api.aspects.IEssentiaTransport; + +import java.util.ArrayList; + +public class EssentiaHatch extends TileEntity implements IAspectContainer, IEssentiaTransport { + + private Aspect mLocked; + private AspectList current = new AspectList(); + public int mState = 0; + + public void setLockedAspect(Aspect aAspect) { + this.mLocked = aAspect; + } + + @Override + public void readFromNBT(NBTTagCompound tagCompound) { + super.readFromNBT(tagCompound); + + this.mLocked = Aspect.getAspect(tagCompound.getString("mLocked")); + this.mState = tagCompound.getInteger("mState"); + current = new AspectList(); + NBTTagList tlist = tagCompound.getTagList("Aspects", 10); + for (int j = 0; j < tlist.tagCount(); ++j) { + NBTTagCompound rs = tlist.getCompoundTagAt(j); + if (rs.hasKey("key")) { + current.add(Aspect.getAspect(rs.getString("key")), rs.getInteger("amount")); + } + } + } + + @Override + public void writeToNBT(NBTTagCompound tagCompound) { + super.writeToNBT(tagCompound); + + tagCompound.setString("mLocked", this.mLocked == null ? "" : this.mLocked.getTag()); + tagCompound.setInteger("mState", mState); + NBTTagList tlist = new NBTTagList(); + Aspect[] aspectA = current.getAspects(); + for (Aspect aspect : aspectA) { + if (aspect != null) { + NBTTagCompound f = new NBTTagCompound(); + f.setString("key", aspect.getTag()); + f.setInteger("amount", current.getAmount(aspect)); + tlist.appendTag(f); + } + } + tagCompound.setTag("Aspects", tlist); + } + + public final Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + writeToNBT(nbt); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt); + } + + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + NBTTagCompound nbt = pkt.func_148857_g(); + readFromNBT(nbt); + } + + public void markDirty() { + super.markDirty(); + if (this.worldObj.isRemote) { + return; + } + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + + @Override + public void updateEntity() { + fillfrompipe(); + } + + public void fillfrompipe() { + if (getEssentiaAmount(null) > 1000) + return; + TileEntity[] te = new TileEntity[ForgeDirection.VALID_DIRECTIONS.length]; + for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { + te[i] = ThaumcraftApiHelper.getConnectableTile(this.worldObj, this.xCoord, this.yCoord, this.zCoord, ForgeDirection.VALID_DIRECTIONS[i]); + if (te[i] != null) { + IEssentiaTransport pipe = (IEssentiaTransport) te[i]; + if (!pipe.canOutputTo(ForgeDirection.VALID_DIRECTIONS[i])) { + return; + } + if ((pipe.getEssentiaType(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()) != null) && (pipe.getSuctionAmount(ForgeDirection.VALID_DIRECTIONS[i]) < getSuctionAmount(ForgeDirection.VALID_DIRECTIONS[i]))) { + Aspect readyInput = pipe.getEssentiaType(ForgeDirection.VALID_DIRECTIONS[i].getOpposite()); + int type = LargeEssentiaEnergyData.getAspectTypeIndex(readyInput); + if (type != -1 && (mState & (1 << type)) == 0) continue; + if (readyInput.equals(mLocked)) { + addToContainer(mLocked, pipe.takeEssentia(mLocked, 1, ForgeDirection.VALID_DIRECTIONS[i])); + } + if (mLocked == null) + addToContainer(pipe.getEssentiaType(ForgeDirection.VALID_DIRECTIONS[i]), pipe.takeEssentia(pipe.getEssentiaType(ForgeDirection.VALID_DIRECTIONS[i]), 1, ForgeDirection.VALID_DIRECTIONS[i])); + } + } + } + } + + @Override + public AspectList getAspects() { + return current; + } + + @Override + public void setAspects(AspectList aspectList) { + this.current.add(aspectList); + } + + @Override + public boolean doesContainerAccept(Aspect aspect) { + return mLocked == null || mLocked.equals(aspect); + } + + @Override + public int addToContainer(Aspect aspect, int i) { + current.add(aspect, i); + this.markDirty(); + return 0; + } + + @Override + public boolean takeFromContainer(Aspect aspect, int i) { + return false; + } + + @Override + public boolean takeFromContainer(AspectList aspectList) { + return false; + } + + @Override + public boolean doesContainerContainAmount(Aspect aspect, int i) { + return current.aspects.containsKey(aspect) && i <= current.getAmount(aspect); + } + + @Override + public boolean doesContainerContain(AspectList aspectList) { + ArrayList<Boolean> ret = new ArrayList<Boolean>(); + for (Aspect a : aspectList.aspects.keySet()) + ret.add(current.aspects.containsKey(a)); + return !ret.contains(false); + } |
