mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
crouch-clicking is grate
This commit is contained in:
parent
bc1a6e17d3
commit
7eb8900c13
@ -14,6 +14,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.item.EntityXPOrb;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@ -31,8 +32,6 @@ public class BlockGrate extends Block implements ITooltipProvider {
|
||||
|
||||
public BlockGrate(Material material) {
|
||||
super(material);
|
||||
|
||||
//this.maxY = 0.999D;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,16 +64,23 @@ public class BlockGrate extends Block implements ITooltipProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getY(int meta) {
|
||||
if(meta == 9) return -0.125F;
|
||||
return meta * 0.125F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
this.setBlockBounds(0F, meta * 0.125F, 0F, 1F, meta * 0.125F + 0.125F - (this == ModBlocks.steel_grate_wide ? 0.001F : 0), 1F);
|
||||
float fy = getY(meta);
|
||||
this.setBlockBounds(0F, fy, 0F, 1F, fy + 0.125F - (this == ModBlocks.steel_grate_wide ? 0.001F : 0), 1F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
this.setBlockBounds(0F, meta * 0.125F, 0F, 1F, meta * 0.125F + 0.125F - (this == ModBlocks.steel_grate_wide ? 0.001F : 0), 1F);
|
||||
float fy = getY(meta);
|
||||
this.setBlockBounds(0F, fy, 0F, 1F, fy + 0.125F - (this == ModBlocks.steel_grate_wide ? 0.001F : 0), 1F);
|
||||
return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ);
|
||||
}
|
||||
|
||||
@ -96,6 +102,52 @@ public class BlockGrate extends Block implements ITooltipProvider {
|
||||
return (int)Math.floor(hY * 8D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) {
|
||||
if(player.isSneaking()) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if(meta == 0) {
|
||||
// Check that the block below can fit a grate above it
|
||||
AxisAlignedBB bb = world.getBlock(x, y - 1, z).getCollisionBoundingBoxFromPool(world, x, y - 1, z);
|
||||
if(bb == null || (int) ((bb.maxY - (y - 1)) * 100) < 90) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, 9, 3);
|
||||
}
|
||||
} else if(meta == 7) {
|
||||
AxisAlignedBB bb = world.getBlock(x, y + 1, z).getCollisionBoundingBoxFromPool(world, x, y + 1, z);
|
||||
if(bb == null || (int) ((bb.minY - (y + 1)) * 100) > 10) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, 8, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) {
|
||||
if(world.isRemote) return;
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
boolean breakIt = false;
|
||||
|
||||
if(meta == 9) {
|
||||
AxisAlignedBB bb = world.getBlock(x, y - 1, z).getCollisionBoundingBoxFromPool(world, x, y - 1, z);
|
||||
if(bb != null && (int) ((bb.maxY - (y - 1)) * 100) >= 90) {
|
||||
breakIt = true;
|
||||
}
|
||||
} else if(meta == 8) {
|
||||
AxisAlignedBB bb = world.getBlock(x, y + 1, z).getCollisionBoundingBoxFromPool(world, x, y + 1, z);
|
||||
if(bb != null && (int) ((bb.minY - (y + 1)) * 100) <= 10) {
|
||||
breakIt = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(breakIt) {
|
||||
dropBlockAsItem(world, x, y, z, 0, 0);
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB entityBounding, List list, Entity entity) {
|
||||
if(this != ModBlocks.steel_grate_wide || !(entity instanceof EntityItem || entity instanceof EntityXPOrb)) {
|
||||
|
||||
@ -22,7 +22,9 @@ public class RenderGrate implements ISimpleBlockRenderingHandler {
|
||||
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
|
||||
tessellator.setColorOpaque_F(1, 1, 1);
|
||||
|
||||
renderer.setRenderBounds(0.0D, meta * 0.125D, 0D, 1D, meta * 0.125D + 0.125D, 1D);
|
||||
float fy = ((BlockGrate)block).getY(meta);
|
||||
|
||||
renderer.setRenderBounds(0.0D, fy, 0D, 1D, fy + 0.125D, 1D);
|
||||
renderer.renderStandardBlock(block, x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user