diff options
| author | Raven Szewczyk <git@eigenraven.me> | 2024-05-25 14:13:58 +0100 |
|---|---|---|
| committer | Raven Szewczyk <git@eigenraven.me> | 2024-05-25 14:13:58 +0100 |
| commit | 91b1909427bb0cab0f72505c325b07f8fb39c62e (patch) | |
| tree | d6570897b7150afd4f3cb1470202af11e3e9ece3 /src/main/java/goodgenerator/blocks/regularBlock | |
| parent | 40efa0d238677418071b658b11b0a1a7c9e0d864 (diff) | |
| download | GT5-Unofficial-91b1909427bb0cab0f72505c325b07f8fb39c62e.tar.gz GT5-Unofficial-91b1909427bb0cab0f72505c325b07f8fb39c62e.tar.bz2 GT5-Unofficial-91b1909427bb0cab0f72505c325b07f8fb39c62e.zip | |
Move GoodGen sources
Diffstat (limited to 'src/main/java/goodgenerator/blocks/regularBlock')
6 files changed, 547 insertions, 0 deletions
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..9e01d783d2 --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/Casing.java @@ -0,0 +1,124 @@ +package goodgenerator.blocks.regularBlock; + +import java.util.List; + +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 cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import goodgenerator.main.GoodGenerator; +import gregtech.api.GregTech_API; + +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..0a0169d0b4 --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/ComplexTextureCasing.java @@ -0,0 +1,58 @@ +package goodgenerator.blocks.regularBlock; + +import java.util.List; + +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 cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +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..b4acb03518 --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/Frame.java @@ -0,0 +1,37 @@ +package goodgenerator.blocks.regularBlock; + +import net.minecraft.block.material.Material; +import net.minecraft.world.IBlockAccess; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +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/ITextureBlock.java b/src/main/java/goodgenerator/blocks/regularBlock/ITextureBlock.java new file mode 100644 index 0000000000..fae196a64b --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/ITextureBlock.java @@ -0,0 +1,18 @@ +package goodgenerator.blocks.regularBlock; + +import net.minecraft.block.Block; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.ITexture; + +public interface ITextureBlock { + + default ITexture[] getTexture(Block aBlock, ForgeDirection side) { + return getTexture(aBlock, 0, side); + } + + ITexture[] getTexture(Block aBlock, ForgeDirection side, IBlockAccess aWorld, int xCoord, int yCoord, int zCoord); + + ITexture[] getTexture(Block aBlock, int aMeta, ForgeDirection side); +} 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..6c13a9c680 --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/TEBlock.java @@ -0,0 +1,207 @@ +package goodgenerator.blocks.regularBlock; + +import java.util.List; + +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 cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import goodgenerator.blocks.tileEntity.EssentiaHatch; +import goodgenerator.blocks.tileEntity.EssentiaOutputHatch; +import goodgenerator.blocks.tileEntity.EssentiaOutputHatch_ME; +import goodgenerator.main.GoodGenerator; +import gregtech.api.GregTech_API; +import gregtech.api.util.GT_Utility; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.IEssentiaContainerItem; + +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) { + switch (index) { + case 1: + return new EssentiaHatch(); + case 2: + return new EssentiaOutputHatch(); + case 3: + return new EssentiaOutputHatch_ME(); + default: + 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 if (index == 2) { + if (tile instanceof EssentiaOutputHatch && player.isSneaking()) { + ItemStack tItemStack = player.getHeldItem(); + if (tItemStack == null) { + ((EssentiaOutputHatch) tile).clear(); + GT_Utility + .sendChatToPlayer(player, StatCollector.translateToLocal("essentiaoutputhatch.chat.0")); + } + 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/regularBlock/TurbineCasing.java b/src/main/java/goodgenerator/blocks/regularBlock/TurbineCasing.java new file mode 100644 index 0000000000..986ab4e0c8 --- /dev/null +++ b/src/main/java/goodgenerator/blocks/regularBlock/TurbineCasing.java @@ -0,0 +1,103 @@ +package goodgenerator.blocks.regularBlock; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import goodgenerator.blocks.tileEntity.base.GT_MetaTileEntity_LargeTurbineBase; +import goodgenerator.client.render.BlockRenderHandler; +import goodgenerator.main.GoodGenerator; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.render.TextureFactory; + +public class TurbineCasing extends Casing implements ITextureBlock { + + public static IIconContainer[][] turbineShape = new IIconContainer[3][9]; + public IIconContainer base; + + static { + for (int i = 0; i < 3; i++) for (int j = 1; j <= 9; j++) + turbineShape[i][j - 1] = new Textures.BlockIcons.CustomIcon("icons/turbines/TURBINE_" + i + "" + j); + } + + public TurbineCasing(String name, String texture) { + super(name, new String[] { GoodGenerator.MOD_ID + ":" + texture }); + base = new Textures.BlockIcons.CustomIcon("icons/" + texture); + } + + private static int isTurbineControllerWithSide(IBlockAccess aWorld, int aX, int aY, int aZ, ForgeDirection side) { + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if (!(tTileEntity instanceof IGregTechTileEntity)) return 0; + IGregTechTileEntity tTile = (IGregTechTileEntity) tTileEntity; + if (tTile.getMetaTileEntity() instanceof GT_MetaTileEntity_LargeTurbineBase && tTile.getFrontFacing() == side) { + if (tTile.isActive()) return 1; + return ((GT_MetaTileEntity_LargeTurbineBase) tTile.getMetaTileEntity()).hasTurbine() ? 2 : 3; + } + return 0; + } + + public ITexture[] getTurbineCasing(int iconIndex, boolean active, boolean hasTurbine) { + int states = active ? 0 : hasTurbine ? 1 : 2; + return new ITexture[] { TextureFactory.of(base), TextureFactory.of(turbineShape[states][iconIndex]) }; + } + + @Override + public ITexture[] getTexture(Block aBlock, ForgeDirection side, IBlockAccess aWorld, int xCoord, int yCoord, + int zCoord) { + final int ordinalSide = side.ordinal(); + int tInvertLeftRightMod = ordinalSide % 2 * 2 - 1; + switch (ordinalSide / 2) { + case 0: + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + int tState; + if ((tState = isTurbineControllerWithSide(aWorld, xCoord + j, yCoord, zCoord + i, side)) != 0) { + return getTurbineCasing(4 - i * 3 - j, tState == 1, tState == 2); + } + } + } + break; + case 1: + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + int tState; + if ((tState = isTurbineControllerWithSide(aWorld, xCoord + j, yCoord + i, zCoord, side)) != 0) { + return getTurbineCasing(4 + i * 3 - j * tInvertLeftRightMod, tState == 1, tState == 2); + } + } + } + break; + case 2: + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + int tState; + if ((tState = isTurbineControllerWithSide(aWorld, xCoord, yCoord + i, zCoord + j, side)) != 0) { + return getTurbineCasing(4 + i * 3 + j * tInvertLeftRightMod, tState == 1, tState == 2); + } + } + } + break; + } + return getTexture(aBlock, side); + } + + @Override + public ITexture[] getTexture(Block aBlock, int aMeta, ForgeDirection side) { + return new ITexture[] { TextureFactory.of(base) }; + } + + @Override + public int getRenderType() { + if (BlockRenderHandler.INSTANCE == null) { + return super.getRenderType(); + } + return BlockRenderHandler.INSTANCE.mRenderID; + } +} |
