Automatic fence posts

This commit is contained in:
George Paton 2024-06-03 19:26:38 +10:00
parent bdbe821d9d
commit 5241ff661b
4 changed files with 104 additions and 117 deletions

View File

@ -10,18 +10,21 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockMetalFence extends BlockFence { public class BlockMetalFence extends BlockFence {
public BlockMetalFence(Material p_i45406_2_) { public IIcon postIcon;
super("", p_i45406_2_);
public BlockMetalFence(Material mat) {
super("", mat);
} }
public static int renderID = RenderingRegistry.getNextAvailableRenderId(); public static int renderID = RenderingRegistry.getNextAvailableRenderId();
@Override @Override
public int getRenderType(){ public int getRenderType() {
return renderID; return renderID;
} }
@ -35,79 +38,70 @@ public class BlockMetalFence extends BlockFence {
return false; return false;
} }
@SideOnly(Side.CLIENT) @Override
public void registerBlockIcons(IIconRegister p_149651_1_) @SideOnly(Side.CLIENT)
{ public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = p_149651_1_.registerIcon(this.getTextureName()); this.blockIcon = iconRegister.registerIcon(this.getTextureName());
} this.postIcon = iconRegister.registerIcon(this.getTextureName() + "_post");
}
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_) @Override
{ public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) {
boolean flag = this.canConnectFenceTo(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_ - 1); boolean flag = this.canConnectFenceTo(world, x, y, z - 1);
boolean flag1 = this.canConnectFenceTo(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_ + 1); boolean flag1 = this.canConnectFenceTo(world, x, y, z + 1);
boolean flag2 = this.canConnectFenceTo(p_149743_1_, p_149743_2_ - 1, p_149743_3_, p_149743_4_); boolean flag2 = this.canConnectFenceTo(world, x - 1, y, z);
boolean flag3 = this.canConnectFenceTo(p_149743_1_, p_149743_2_ + 1, p_149743_3_, p_149743_4_); boolean flag3 = this.canConnectFenceTo(world, x + 1, y, z);
float f = 0.375F; float f = 0.375F;
float f1 = 0.625F; float f1 = 0.625F;
float f2 = 0.375F; float f2 = 0.375F;
float f3 = 0.625F; float f3 = 0.625F;
if (flag) if(flag) {
{ f2 = 0.0F;
f2 = 0.0F; }
}
if (flag1) if(flag1) {
{ f3 = 1.0F;
f3 = 1.0F; }
}
if (flag || flag1) if(flag || flag1) {
{ this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3);
this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); addCol(world, x, y, z, aabb, list, entity);
addCol(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_); }
}
f2 = 0.375F; f2 = 0.375F;
f3 = 0.625F; f3 = 0.625F;
if (flag2) if(flag2) {
{ f = 0.0F;
f = 0.0F; }
}
if (flag3) if(flag3) {
{ f1 = 1.0F;
f1 = 1.0F; }
}
if (flag2 || flag3 || !flag && !flag1) if(flag2 || flag3 || !flag && !flag1) {
{ this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3);
this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); addCol(world, x, y, z, aabb, list, entity);
addCol(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_); }
}
if (flag) if(flag) {
{ f2 = 0.0F;
f2 = 0.0F; }
}
if (flag1) if(flag1) {
{ f3 = 1.0F;
f3 = 1.0F; }
}
this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3); 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_) 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);
AxisAlignedBB axisalignedbb1 = this.getCollisionBoundingBoxFromPool(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_);
if (axisalignedbb1 != null && p_149743_5_.intersectsWith(axisalignedbb1)) if(axisalignedbb1 != null && aabb.intersectsWith(axisalignedbb1)) {
{ list.add(axisalignedbb1);
p_149743_6_.add(axisalignedbb1); }
} }
}
} }

View File

@ -5,7 +5,6 @@ import com.hbm.blocks.generic.BlockMetalFence;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFence;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
@ -19,58 +18,52 @@ public class RenderFence implements ISimpleBlockRenderingHandler {
@Override @Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { 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;
float f = 0.375F; boolean xNeg = fence.canConnectFenceTo(world, x - 1, y, z);
float f1 = 0.625F; boolean xPos = fence.canConnectFenceTo(world, x + 1, y, z);
renderer.setRenderBounds((double)f, 0.0D, (double)f, (double)f1, 1.0D, (double)f1); boolean zNeg = fence.canConnectFenceTo(world, x, y, z - 1);
renderer.renderStandardBlock(fence, x, y, z); boolean zPos = fence.canConnectFenceTo(world, x, y, z + 1);
boolean flag1 = false;
boolean flag2 = false;
if (fence.canConnectFenceTo(world, x - 1, y, z) || fence.canConnectFenceTo(world, x + 1, y, z)) boolean flag1 = xNeg || xPos;
{ boolean flag2 = zNeg || zPos;
flag1 = true;
}
if (fence.canConnectFenceTo(world, x, y, z - 1) || fence.canConnectFenceTo(world, x, y, z + 1)) boolean hidePost = (xNeg && xPos) || (zNeg && zPos);
{
flag2 = true;
}
boolean flag3 = fence.canConnectFenceTo(world, x - 1, y, z); if (!flag1 && !flag2) {
boolean flag4 = fence.canConnectFenceTo(world, x + 1, y, z); flag1 = true;
boolean flag5 = fence.canConnectFenceTo(world, x, y, z - 1); }
boolean flag6 = fence.canConnectFenceTo(world, x, y, z + 1);
if (!flag1 && !flag2) float f = 0.4375F;
{ float f1 = 0.5625F;
flag1 = true; 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;
f = 0.4375F; if (flag1) {
f1 = 0.5625F; renderer.setRenderBounds((double)f4, (double)0, (double)0.5, (double)f5, (double)1, (double)0.5);
float f4 = flag3 ? 0.0F : f; renderer.renderStandardBlock(fence, x, y, z);
float f5 = flag4 ? 1.0F : f1; }
float f6 = flag5 ? 0.0F : f;
float f7 = flag6 ? 1.0F : f1;
renderer.field_152631_f = true;
if (flag1) if (flag2) {
{ renderer.setRenderBounds((double)0.5, (double)0, (double)f6, (double)0.5, (double)1, (double)f7);
renderer.setRenderBounds((double)f4, (double)0, (double)0.5, (double)f5, (double)1, (double)0.5); renderer.renderStandardBlock(fence, x, y, z);
renderer.renderStandardBlock(fence, x, y, z); }
}
if (flag2) if(!hidePost) {
{ f = 0.375F;
renderer.setRenderBounds((double)0.5, (double)0, (double)f6, (double)0.5, (double)1, (double)f7); f1 = 0.625F;
renderer.renderStandardBlock(fence, x, y, z); 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();
}
renderer.field_152631_f = false; renderer.field_152631_f = false;
fence.setBlockBoundsBasedOnState(world, x, y, z); fence.setBlockBoundsBasedOnState(world, x, y, z);
return true; return true;
} }
@Override @Override

Binary file not shown.

Before

Width:  |  Height:  |  Size: 596 B

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B