Horizontal scaffolding

This commit is contained in:
George Paton 2024-09-19 14:32:57 +10:00
parent 8bbed76758
commit b36cf4213f
2 changed files with 52 additions and 25 deletions

View File

@ -16,6 +16,7 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockScaffold extends BlockMulti { public class BlockScaffold extends BlockMulti {
@ -59,22 +60,34 @@ public class BlockScaffold extends BlockMulti {
public IIcon getIcon(int side, int meta) { public IIcon getIcon(int side, int meta) {
return this.icons[this.damageDropped(meta)]; return this.icons[this.damageDropped(meta)];
} }
@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float fx, float fy, float fz, int meta) {
return side;
}
@Override @Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; ForgeDirection placed = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
int meta = stack.getItemDamage(); int meta = stack.getItemDamage();
if(i % 2 == 0) { if(placed == ForgeDirection.UP || placed == ForgeDirection.DOWN) {
world.setBlockMetadataWithNotify(x, y, z, meta, 2); int rot = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if(rot % 2 == 0) {
world.setBlockMetadataWithNotify(x, y, z, meta, 2);
} else {
world.setBlockMetadataWithNotify(x, y, z, meta + 8, 2);
}
} else if(placed == ForgeDirection.NORTH || placed == ForgeDirection.SOUTH) {
world.setBlockMetadataWithNotify(x, y, z, meta + 4, 2);
} else { } else {
world.setBlockMetadataWithNotify(x, y, z, meta + 8, 2); world.setBlockMetadataWithNotify(x, y, z, meta + 12, 2);
} }
} }
@Override @Override
public int damageDropped(int meta) { public int damageDropped(int meta) {
return rectify(meta) & 7; return rectify(meta);
} }
@Override @Override
@ -83,27 +96,24 @@ public class BlockScaffold extends BlockMulti {
} }
@Override @Override
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) { public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
int te = p_149719_1_.getBlockMetadata(p_149719_2_, p_149719_3_, p_149719_4_); int meta = world.getBlockMetadata(x, y, z);
float f = 0.0625F; float f = 0.0625F;
if((te & 8) != 0) if(meta >= 12) {
this.setBlockBounds(0.0F, 2 * f, 0.0F, 1.0F, 14 * f, 1.0F);
} else if(meta >= 8) {
this.setBlockBounds(2 * f, 0.0F, 0.0F, 14 * f, 1.0F, 1.0F); this.setBlockBounds(2 * f, 0.0F, 0.0F, 14 * f, 1.0F, 1.0F);
else } else if(meta >= 4) {
this.setBlockBounds(0.0F, 2 * f, 0.0F, 1.0F, 14 * f, 1.0F);
} else {
this.setBlockBounds(0.0F, 0.0F, 2 * f, 1.0F, 1.0F, 14 * f); this.setBlockBounds(0.0F, 0.0F, 2 * f, 1.0F, 1.0F, 14 * f);
}
} }
@Override @Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
setBlockBoundsBasedOnState(world, x, y, z);
int te = world.getBlockMetadata(x, y, z);
float f = 0.0625F;
if((te & 8) != 0)
this.setBlockBounds(2 * f, 0.0F, 0.0F, 14 * f, 1.0F, 1.0F);
else
this.setBlockBounds(0.0F, 0.0F, 2 * f, 1.0F, 1.0F, 14 * f);
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
} }
} }

View File

@ -49,14 +49,31 @@ public class RenderScaffoldBlock implements ISimpleBlockRenderingHandler {
iicon = renderer.overrideBlockTexture; iicon = renderer.overrideBlockTexture;
} }
float rotation = (float) -Math.PI; float ox = x + 0.5F;
float oy = y;
float oz = z + 0.5F;
if((world.getBlockMetadata(x, y, z) & 8) == 0) float rotation = (float) Math.PI * -0.5F;
rotation = -90F / 180F * (float) Math.PI; float pitch = 0;
tessellator.addTranslation(x + 0.5F, y, z + 0.5F); int meta = world.getBlockMetadata(x, y, z);
ObjUtil.renderWithIcon((WavefrontObject) ResourceManager.scaffold, iicon, tessellator, rotation, true);
tessellator.addTranslation(-x - 0.5F, -y, -z - 0.5F); if(meta >= 12) {
pitch = (float) Math.PI * 0.5F;
rotation = (float) -Math.PI;
ox = x + 1.0F;
oy = y + 0.5F;
} else if(meta >= 8) {
rotation = (float) -Math.PI;
} else if(meta >= 4) {
pitch = (float) Math.PI * 0.5F;
oy = y + 0.5F;
oz = z;
}
tessellator.addTranslation(ox, oy, oz);
ObjUtil.renderWithIcon((WavefrontObject) ResourceManager.scaffold, iicon, tessellator, rotation, pitch, true);
tessellator.addTranslation(-ox, -oy, -oz);
return true; return true;
} }