From 5241ff661bd932ed062179c713e12e959a9a757e Mon Sep 17 00:00:00 2001 From: George Paton Date: Mon, 3 Jun 2024 19:26:38 +1000 Subject: [PATCH] Automatic fence posts --- .../hbm/blocks/generic/BlockMetalFence.java | 136 +++++++++--------- .../com/hbm/render/block/RenderFence.java | 85 +++++------ .../hbm/textures/blocks/fence_metal.png | Bin 596 -> 4488 bytes .../hbm/textures/blocks/fence_metal_post.png | Bin 0 -> 596 bytes 4 files changed, 104 insertions(+), 117 deletions(-) create mode 100644 src/main/resources/assets/hbm/textures/blocks/fence_metal_post.png diff --git a/src/main/java/com/hbm/blocks/generic/BlockMetalFence.java b/src/main/java/com/hbm/blocks/generic/BlockMetalFence.java index 753832e36..1cdfaa2a7 100644 --- a/src/main/java/com/hbm/blocks/generic/BlockMetalFence.java +++ b/src/main/java/com/hbm/blocks/generic/BlockMetalFence.java @@ -10,104 +10,98 @@ import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; import net.minecraft.world.World; public class BlockMetalFence extends BlockFence { - - public BlockMetalFence(Material p_i45406_2_) { - super("", p_i45406_2_); + + public IIcon postIcon; + + public BlockMetalFence(Material mat) { + super("", mat); } - - public static int renderID = RenderingRegistry.getNextAvailableRenderId(); + + public static int renderID = RenderingRegistry.getNextAvailableRenderId(); @Override - public int getRenderType(){ + public int getRenderType() { return renderID; } - + @Override public boolean isOpaqueCube() { return false; } - + @Override public boolean renderAsNormalBlock() { return false; } - @SideOnly(Side.CLIENT) - public void registerBlockIcons(IIconRegister p_149651_1_) - { - this.blockIcon = p_149651_1_.registerIcon(this.getTextureName()); - } - - public void addCollisionBoxesToList(World p_149743_1_, int p_149743_2_, int p_149743_3_, int p_149743_4_, AxisAlignedBB p_149743_5_, List p_149743_6_, Entity p_149743_7_) - { - boolean flag = this.canConnectFenceTo(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_ - 1); - boolean flag1 = this.canConnectFenceTo(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_ + 1); - boolean flag2 = this.canConnectFenceTo(p_149743_1_, p_149743_2_ - 1, p_149743_3_, p_149743_4_); - boolean flag3 = this.canConnectFenceTo(p_149743_1_, p_149743_2_ + 1, p_149743_3_, p_149743_4_); - float f = 0.375F; - float f1 = 0.625F; - float f2 = 0.375F; - float f3 = 0.625F; + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iconRegister) { + this.blockIcon = iconRegister.registerIcon(this.getTextureName()); + this.postIcon = iconRegister.registerIcon(this.getTextureName() + "_post"); + } - if (flag) - { - f2 = 0.0F; - } + @Override + public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) { + boolean flag = this.canConnectFenceTo(world, x, y, z - 1); + boolean flag1 = this.canConnectFenceTo(world, x, y, z + 1); + boolean flag2 = this.canConnectFenceTo(world, x - 1, y, z); + boolean flag3 = this.canConnectFenceTo(world, x + 1, y, z); + float f = 0.375F; + float f1 = 0.625F; + float f2 = 0.375F; + float f3 = 0.625F; - if (flag1) - { - f3 = 1.0F; - } + if(flag) { + f2 = 0.0F; + } - if (flag || flag1) - { - this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); - addCol(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_); - } + if(flag1) { + f3 = 1.0F; + } - f2 = 0.375F; - f3 = 0.625F; + if(flag || flag1) { + this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); + addCol(world, x, y, z, aabb, list, entity); + } - if (flag2) - { - f = 0.0F; - } + f2 = 0.375F; + f3 = 0.625F; - if (flag3) - { - f1 = 1.0F; - } + if(flag2) { + f = 0.0F; + } - if (flag2 || flag3 || !flag && !flag1) - { - this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); - addCol(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_); - } + if(flag3) { + f1 = 1.0F; + } - if (flag) - { - f2 = 0.0F; - } + if(flag2 || flag3 || !flag && !flag1) { + this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); + addCol(world, x, y, z, aabb, list, entity); + } - if (flag1) - { - f3 = 1.0F; - } + if(flag) { + f2 = 0.0F; + } - this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); - } - - public void addCol(World p_149743_1_, int p_149743_2_, int p_149743_3_, int p_149743_4_, AxisAlignedBB p_149743_5_, List p_149743_6_, Entity p_149743_7_) - { - AxisAlignedBB axisalignedbb1 = this.getCollisionBoundingBoxFromPool(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_); + if(flag1) { + f3 = 1.0F; + } - if (axisalignedbb1 != null && p_149743_5_.intersectsWith(axisalignedbb1)) - { - p_149743_6_.add(axisalignedbb1); - } - } + this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); + } + + private void addCol(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) { + AxisAlignedBB axisalignedbb1 = this.getCollisionBoundingBoxFromPool(world, x, y, z); + + if(axisalignedbb1 != null && aabb.intersectsWith(axisalignedbb1)) { + list.add(axisalignedbb1); + } + } } diff --git a/src/main/java/com/hbm/render/block/RenderFence.java b/src/main/java/com/hbm/render/block/RenderFence.java index f86d128cc..5b58fbd89 100644 --- a/src/main/java/com/hbm/render/block/RenderFence.java +++ b/src/main/java/com/hbm/render/block/RenderFence.java @@ -5,7 +5,6 @@ import com.hbm.blocks.generic.BlockMetalFence; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; -import net.minecraft.block.BlockFence; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.world.IBlockAccess; @@ -19,58 +18,52 @@ public class RenderFence implements ISimpleBlockRenderingHandler { @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { - BlockFence fence = (BlockFence) ModBlocks.fence_metal; + BlockMetalFence fence = (BlockMetalFence) ModBlocks.fence_metal; + + boolean xNeg = fence.canConnectFenceTo(world, x - 1, y, z); + boolean xPos = fence.canConnectFenceTo(world, x + 1, y, z); + boolean zNeg = fence.canConnectFenceTo(world, x, y, z - 1); + boolean zPos = fence.canConnectFenceTo(world, x, y, z + 1); + + boolean flag1 = xNeg || xPos; + boolean flag2 = zNeg || zPos; - float f = 0.375F; - float f1 = 0.625F; - renderer.setRenderBounds((double)f, 0.0D, (double)f, (double)f1, 1.0D, (double)f1); - renderer.renderStandardBlock(fence, x, y, z); - boolean flag1 = false; - boolean flag2 = false; + boolean hidePost = (xNeg && xPos) || (zNeg && zPos); - if (fence.canConnectFenceTo(world, x - 1, y, z) || fence.canConnectFenceTo(world, x + 1, y, z)) - { - flag1 = true; - } + if (!flag1 && !flag2) { + flag1 = true; + } - if (fence.canConnectFenceTo(world, x, y, z - 1) || fence.canConnectFenceTo(world, x, y, z + 1)) - { - flag2 = true; - } + float f = 0.4375F; + float f1 = 0.5625F; + float f4 = xNeg ? 0.0F : f; + float f5 = xPos ? 1.0F : f1; + float f6 = zNeg ? 0.0F : f; + float f7 = zPos ? 1.0F : f1; + renderer.field_152631_f = true; - boolean flag3 = fence.canConnectFenceTo(world, x - 1, y, z); - boolean flag4 = fence.canConnectFenceTo(world, x + 1, y, z); - boolean flag5 = fence.canConnectFenceTo(world, x, y, z - 1); - boolean flag6 = fence.canConnectFenceTo(world, x, y, z + 1); + if (flag1) { + renderer.setRenderBounds((double)f4, (double)0, (double)0.5, (double)f5, (double)1, (double)0.5); + renderer.renderStandardBlock(fence, x, y, z); + } - if (!flag1 && !flag2) - { - flag1 = true; - } + if (flag2) { + renderer.setRenderBounds((double)0.5, (double)0, (double)f6, (double)0.5, (double)1, (double)f7); + renderer.renderStandardBlock(fence, x, y, z); + } - f = 0.4375F; - f1 = 0.5625F; - float f4 = flag3 ? 0.0F : f; - float f5 = flag4 ? 1.0F : f1; - float f6 = flag5 ? 0.0F : f; - float f7 = flag6 ? 1.0F : f1; - renderer.field_152631_f = true; + if(!hidePost) { + f = 0.375F; + f1 = 0.625F; + renderer.setOverrideBlockTexture(fence.postIcon); + renderer.setRenderBounds((double)f, 0.0D, (double)f, (double)f1, 1.0D, (double)f1); + renderer.renderStandardBlock(fence, x, y, z); + renderer.clearOverrideBlockTexture(); + } - if (flag1) - { - renderer.setRenderBounds((double)f4, (double)0, (double)0.5, (double)f5, (double)1, (double)0.5); - renderer.renderStandardBlock(fence, x, y, z); - } - - if (flag2) - { - renderer.setRenderBounds((double)0.5, (double)0, (double)f6, (double)0.5, (double)1, (double)f7); - renderer.renderStandardBlock(fence, x, y, z); - } - - renderer.field_152631_f = false; - fence.setBlockBoundsBasedOnState(world, x, y, z); - return true; + renderer.field_152631_f = false; + fence.setBlockBoundsBasedOnState(world, x, y, z); + return true; } @Override diff --git a/src/main/resources/assets/hbm/textures/blocks/fence_metal.png b/src/main/resources/assets/hbm/textures/blocks/fence_metal.png index 12d6faaea426ba17de801a84cd9448c04c0c3db8..40f5411bba5643958554457edfe7235a85e26cf7 100644 GIT binary patch literal 4488 zcmeHKdsGwY6(3XxvcQ6ix~r^?(NYnTOu~@Il&C{=R#E_ulW!SCpKT5a2h>4}zcoU82SSojUmHyI(iOuwD{bbndkOis0rMWyDakFo&8Dm)2}Vd@PBX0hE)*cwS|t4Pu9i9zl;S$u&;2J zI}n!9(;7_T-o zXQT+O*!5fn$^?U^}YDqXJ1_IQ$73W{j*SMVkl9E2Uovw*^-GpDEu0USnSuO z>N*)abyq#-AnB6zCk9XYbJ$n-?^;OXWp@(gUe?(Yf7HB&*-0Zrc}6RNmT%1zi_~B z^6qxQi_Ld#l{6pLDZ)bpby=2PVuJ6ZaTn{X8)mxmx+iol7@wBu&ay(Em415Noq5mq z+dDquDtE~jf|dV-HZQFs6L;Jz4-ffeeeYX^DKp+Y>0OX^>vm?ZvJg7ncC{sdWqp73 z+qv&uY`@iT>2|-m^}7y1L!AB356No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B1CE4ZWWrq1^ zn5gSHihNhq?Yz#;&NB1iaJcL}&-;=+nFwGun`zXK6t{hKJx9NPZ3>`XuM1#29t+_3 z_*gtVJY<-w)qko0{`5jcep4N%rlS2L#av%suX->T3^E=BL7>0WvEsI;j#HOYDGFdT z8VR6WE(^f6m*&#z^;SIS@3z$STs6u?9UL5F=1GzWAP4aH_^7wHH_IsKcDwrc_y9m! zuvjd3etxz#HZ}w>pU?I3@?x#8uZtiEGR*V&T;Ed&n}1Gb58^n^;B)Wq?^e6rmKi=h zJy|B-&(BYCIV%O*wyoFKSId02QmHJ-%o>{-#$5$&UA>m4dZ{22v8mhJ+hu=vcqo8U zsU(0-r=xh+U%3U7ze%lDtBI?ts|@q``MJInMC$Lh6gC^G6}MB&$;rv;9vCAX$4OtB z4EpM|nluWV4ee}wU8_;*x^C)ON^)~^^WR%ADH!>tX0w?9{s9kZ6GU%*->Coq002ov JPDHLkV1je|7%>0< diff --git a/src/main/resources/assets/hbm/textures/blocks/fence_metal_post.png b/src/main/resources/assets/hbm/textures/blocks/fence_metal_post.png new file mode 100644 index 0000000000000000000000000000000000000000..12d6faaea426ba17de801a84cd9448c04c0c3db8 GIT binary patch literal 596 zcmV-a0;~OrP)`XuM1#29t+_3_*gtVJY<-w)v5sg^g=~`Qyr(KqWvSq zTwhSS)ycezrC?HUu!A&-L>1Vy&;Qiy#Ox z%=7tN-%|*iPG%3{IL_d6@9*zcyWN%3f**Vk9ee791mEXm9o zn;OPl1#VrvmZy5DAQQ2v+uPe^e|UH(fKsU>fKI2Qc-LRK1(Ux?tyZgvtE;OF^ZEI? zz7$02@3s^+8>$tzQ_RW9$?6^$BOS*{Uz!a1>b05*n+@%3eO;?j>bh>~SxRzqbMxO@ iFew=Mre?F50R90FX%j?me&4A80000