fix converter + doors

This commit is contained in:
Sen 2025-06-28 17:22:41 +02:00
parent 601a331ee3
commit 96fb940087
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
3 changed files with 347 additions and 489 deletions

View file

@ -28,388 +28,273 @@ import common.world.IWorldAccess;
import common.world.State;
import common.world.World;
public class BlockDoor extends Block implements Rotatable
{
public static final PropertyBool OPEN = PropertyBool.create("open");
public static final PropertyEnum<BlockDoor.EnumHingePosition> HINGE = PropertyEnum.<BlockDoor.EnumHingePosition>create("hinge", BlockDoor.EnumHingePosition.class);
public static final PropertyBool POWERED = PropertyBool.create("powered");
public static final PropertyEnum<BlockDoor.EnumDoorHalf> HALF = PropertyEnum.<BlockDoor.EnumDoorHalf>create("half", BlockDoor.EnumDoorHalf.class);
public static final List<BlockDoor> DOORS = Lists.newArrayList();
public class BlockDoor extends Block implements Rotatable {
public static enum EnumDoorHalf implements Identifyable {
UPPER, LOWER;
public BlockDoor(Material materialIn)
{
super(materialIn);
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH).withProperty(OPEN, Boolean.valueOf(false)).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf(false)).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER));
DOORS.add(this);
}
public String toString() {
return this.getName();
}
// /**
// * Gets the localized name of this block. Used for the statistics page.
// */
// public String getLocalizedName()
// {
// return Strs.get((this.getUnlocalizedName() + ".name").replaceAll("tile", "item"));
// }
public String getName() {
return this == UPPER ? "upper" : "lower";
}
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube()
{
return false;
}
public static enum EnumHingePosition implements Identifyable {
LEFT, RIGHT;
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
{
return worldIn.getState(pos).getValue(OPEN);
}
public String toString() {
return this.getName();
}
public boolean isFullCube()
{
return false;
}
public String getName() {
return this == LEFT ? "left" : "right";
}
}
public BoundingBox getSelectedBoundingBox(World worldIn, BlockPos pos)
{
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.getSelectedBoundingBox(worldIn, pos);
}
public static final PropertyBool OPEN = PropertyBool.create("open");
public static final PropertyEnum<EnumHingePosition> HINGE = PropertyEnum.<EnumHingePosition>create("hinge", EnumHingePosition.class);
public static final PropertyBool POWERED = PropertyBool.create("powered");
public static final PropertyEnum<EnumDoorHalf> HALF = PropertyEnum.<EnumDoorHalf>create("half", EnumDoorHalf.class);
public static final List<BlockDoor> DOORS = Lists.newArrayList();
public BoundingBox getCollisionBoundingBox(World worldIn, BlockPos pos, State state)
{
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.getCollisionBoundingBox(worldIn, pos, state);
}
public BlockDoor(Material material) {
super(material);
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH).withProperty(OPEN, false)
.withProperty(HINGE, EnumHingePosition.LEFT).withProperty(POWERED, false)
.withProperty(HALF, EnumDoorHalf.LOWER));
DOORS.add(this);
}
public void setBlockBoundsBasedOnState(IWorldAccess worldIn, BlockPos pos)
{
float f = 0.1875F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
State state = worldIn.getState(pos);
Facing enumfacing = state.getValue(FACING);
boolean flag = state.getValue(OPEN);
boolean flag1 = state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT;
public boolean isOpaqueCube() {
return false;
}
if (flag)
{
if (enumfacing == Facing.EAST)
{
if (!flag1)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
}
else
{
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}
}
else if (enumfacing == Facing.SOUTH)
{
if (!flag1)
{
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
else
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
}
else if (enumfacing == Facing.WEST)
{
if (!flag1)
{
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}
else
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
}
}
else if (enumfacing == Facing.NORTH)
{
if (!flag1)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
else
{
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}
}
else if (enumfacing == Facing.EAST)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
else if (enumfacing == Facing.SOUTH)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
}
else if (enumfacing == Facing.WEST)
{
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
else if (enumfacing == Facing.NORTH)
{
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
}
}
public boolean isPassable(IBlockAccess world, BlockPos pos) {
return world.getState(pos).getValue(OPEN);
}
public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ)
{
if (this.material == Material.SOLID)
{
return true;
}
else
{
BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
State iblockstate = pos.equals(blockpos) ? state : worldIn.getState(blockpos);
public boolean isFullCube() {
return false;
}
if (iblockstate.getBlock() != this)
{
return false;
}
else
{
state = iblockstate.cycleProperty(OPEN);
worldIn.setState(blockpos, state, 2);
worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
worldIn.playAuxSFX(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? 1003 : 1006, pos, 0);
return true;
}
}
}
public BoundingBox getSelectedBoundingBox(World world, BlockPos pos) {
this.setBlockBoundsBasedOnState(world, pos);
return super.getSelectedBoundingBox(world, pos);
}
public void toggleDoor(World worldIn, BlockPos pos, boolean open)
{
State iblockstate = worldIn.getState(pos);
public BoundingBox getCollisionBoundingBox(World world, BlockPos pos, State state) {
this.setBlockBoundsBasedOnState(world, pos);
return super.getCollisionBoundingBox(world, pos, state);
}
if (iblockstate.getBlock() == this)
{
BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
State iblockstate1 = pos == blockpos ? iblockstate : worldIn.getState(blockpos);
public void setBlockBoundsBasedOnState(IWorldAccess world, BlockPos pos) {
float thick = 0.1875F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
State state = world.getState(pos);
Facing facing = state.getValue(FACING);
boolean open = state.getValue(OPEN);
boolean right = state.getValue(HINGE) == EnumHingePosition.RIGHT;
if (iblockstate1.getBlock() == this && ((Boolean)iblockstate1.getValue(OPEN)).booleanValue() != open)
{
worldIn.setState(blockpos, iblockstate1.withProperty(OPEN, Boolean.valueOf(open)), 2);
worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
worldIn.playAuxSFX(open ? 1003 : 1006, pos, 0);
}
}
}
if(open) {
if(facing == Facing.EAST) {
if(!right) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, thick);
}
else {
this.setBlockBounds(0.0F, 0.0F, 1.0F - thick, 1.0F, 1.0F, 1.0F);
}
}
else if(facing == Facing.SOUTH) {
if(!right) {
this.setBlockBounds(1.0F - thick, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
else {
this.setBlockBounds(0.0F, 0.0F, 0.0F, thick, 1.0F, 1.0F);
}
}
else if(facing == Facing.WEST) {
if(!right) {
this.setBlockBounds(0.0F, 0.0F, 1.0F - thick, 1.0F, 1.0F, 1.0F);
}
else {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, thick);
}
}
else if(facing == Facing.NORTH) {
if(!right) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, thick, 1.0F, 1.0F);
}
else {
this.setBlockBounds(1.0F - thick, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}
}
else if(facing == Facing.EAST) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, thick, 1.0F, 1.0F);
}
else if(facing == Facing.SOUTH) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, thick);
}
else if(facing == Facing.WEST) {
this.setBlockBounds(1.0F - thick, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
else if(facing == Facing.NORTH) {
this.setBlockBounds(0.0F, 0.0F, 1.0F - thick, 1.0F, 1.0F, 1.0F);
}
}
/**
* Called when a neighboring block changes.
*/
public void onNeighborBlockChange(World worldIn, BlockPos pos, State state, Block neighborBlock)
{
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
{
BlockPos blockpos = pos.down();
State iblockstate = worldIn.getState(blockpos);
public boolean onBlockActivated(World world, BlockPos pos, State state, EntityNPC player, Facing side, float hitX, float hitY, float hitZ) {
if(this.material == Material.SOLID)
return true;
BlockPos lower = state.getValue(HALF) == EnumDoorHalf.LOWER ? pos : pos.down();
BlockPos upper = state.getValue(HALF) == EnumDoorHalf.UPPER ? pos : pos.up();
State bottom = pos.equals(lower) ? state : world.getState(lower);
State top = pos.equals(upper) ? state : world.getState(upper);
if(bottom.getBlock() != this || top.getBlock() != this)
return false;
boolean open = !state.getValue(OPEN);
world.setState(lower, bottom.withProperty(OPEN, open), 2);
world.setState(upper, top.withProperty(OPEN, open), 2);
world.markBlockRangeForRenderUpdate(lower, upper);
world.playAuxSFX(player, open ? 1003 : 1006, pos, 0);
return true;
}
if (iblockstate.getBlock() != this)
{
worldIn.setBlockToAir(pos);
}
else if (neighborBlock != this)
{
this.onNeighborBlockChange(worldIn, blockpos, iblockstate, neighborBlock);
}
}
else
{
boolean flag1 = false;
BlockPos blockpos1 = pos.up();
State iblockstate1 = worldIn.getState(blockpos1);
public void toggleDoor(World world, BlockPos pos, boolean open) {
State state = world.getState(pos);
if(state.getBlock() == this) {
BlockPos lower = state.getValue(HALF) == EnumDoorHalf.LOWER ? pos : pos.down();
BlockPos upper = state.getValue(HALF) == EnumDoorHalf.UPPER ? pos : pos.up();
State bottom = pos.equals(lower) ? state : world.getState(lower);
State top = pos.equals(upper) ? state : world.getState(upper);
if(bottom.getBlock() == this && top.getBlock() == this && ((open != bottom.getValue(OPEN)) || (open != top.getValue(OPEN)))) {
world.setState(lower, bottom.withProperty(OPEN, open), 2);
world.setState(upper, top.withProperty(OPEN, open), 2);
world.markBlockRangeForRenderUpdate(lower, upper);
world.playAuxSFX(open ? 1003 : 1006, pos, 0);
}
}
}
if (iblockstate1.getBlock() != this)
{
worldIn.setBlockToAir(pos);
flag1 = true;
}
public void onNeighborBlockChange(World world, BlockPos pos, State state, Block neighbor) {
if(state.getValue(HALF) == EnumDoorHalf.UPPER) {
BlockPos lower = pos.down();
State bottom = world.getState(lower);
if (!worldIn.isBlockSolid(pos.down()))
{
worldIn.setBlockToAir(pos);
flag1 = true;
if(bottom.getBlock() != this) {
world.setBlockToAir(pos);
}
else if(neighbor != this) {
this.onNeighborBlockChange(world, lower, bottom, neighbor);
}
}
else {
boolean wrong = false;
BlockPos upper = pos.up();
State top = world.getState(upper);
if (iblockstate1.getBlock() == this)
{
worldIn.setBlockToAir(blockpos1);
}
}
if(top.getBlock() != this) {
world.setBlockToAir(pos);
wrong = true;
}
if (flag1)
{
if (!worldIn.client)
{
this.dropBlockAsItem(worldIn, pos, state, 0);
}
}
else
{
boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
if(!world.isBlockSolid(pos.down())) {
world.setBlockToAir(pos);
wrong = true;
if ((flag || neighborBlock.canProvidePower()) && neighborBlock != this && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue())
{
worldIn.setState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);
if(top.getBlock() == this) {
world.setBlockToAir(upper);
}
}
if (flag != ((Boolean)state.getValue(OPEN)).booleanValue())
{
worldIn.setState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
worldIn.playAuxSFX(flag ? 1003 : 1006, pos, 0);
}
}
}
}
}
if(wrong) {
if(!world.client) {
this.dropBlockAsItem(world, pos, state, 0);
}
}
else {
boolean power = world.isBlockPowered(pos) || world.isBlockPowered(upper);
/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(State state, Random rand, int fortune)
{
return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? null : this.getItem();
}
if((power || neighbor.canProvidePower()) && neighbor != this) {
world.setState(pos, state.withProperty(POWERED, power), 2);
world.setState(upper, top.withProperty(POWERED, power), 2);
/**
* Ray traces through the blocks collision from start vector to end vector returning a ray trace hit.
*/
public HitPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end)
{
this.setBlockBoundsBasedOnState(worldIn, pos);
return super.collisionRayTrace(worldIn, pos, start, end);
}
if((power != state.getValue(OPEN)) || (power != top.getValue(OPEN))) {
world.setState(pos, state.withProperty(OPEN, power), 2);
world.setState(upper, top.withProperty(OPEN, power), 2);
world.markBlockRangeForRenderUpdate(pos, upper);
world.playAuxSFX(power ? 1003 : 1006, pos, 0);
}
}
}
}
}
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return pos.getY() >= World.MAX_SIZE_Y - 1 ? false : worldIn.isBlockSolid(pos.down()) && super.canPlaceBlockAt(worldIn, pos) && super.canPlaceBlockAt(worldIn, pos.up());
}
public Item getItemDropped(State state, Random rand, int fortune) {
return state.getValue(HALF) == EnumDoorHalf.UPPER ? null : this.getItem();
}
public int getMobilityFlag()
{
return 1;
}
public HitPosition collisionRayTrace(World world, BlockPos pos, Vec3 start, Vec3 end) {
this.setBlockBoundsBasedOnState(world, pos);
return super.collisionRayTrace(world, pos, start, end);
}
public Item getItem(World worldIn, BlockPos pos)
{
return this.getItem();
}
public boolean canPlaceBlockAt(World world, BlockPos pos) {
return pos.getY() < World.MAX_SIZE_Y - 1 && world.isBlockSolid(pos.down()) && super.canPlaceBlockAt(world, pos) && super.canPlaceBlockAt(world, pos.up());
}
// public void onBlockHarvested(World worldIn, BlockPos pos, State state, EntityNPC player)
// {
// BlockPos blockpos = pos.down();
//
// if (player.creative && state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER && worldIn.getState(blockpos).getBlock() == this)
// {
// worldIn.setBlockToAir(blockpos);
// }
// }
public int getMobilityFlag() {
return 1;
}
public BlockLayer getBlockLayer()
{
return BlockLayer.CUTOUT;
}
public Item getItem(World world, BlockPos pos) {
return this.getItem();
}
public static Facing getFacing(IBlockAccess worldIn, BlockPos pos)
{
return worldIn.getState(pos).getValue(FACING);
}
public BlockLayer getBlockLayer() {
return BlockLayer.CUTOUT;
}
protected Property[] getProperties()
{
return new Property[] {HALF, FACING, OPEN, HINGE, POWERED};
}
private static ModelRotation getRotation(Facing rot, int offset) {
return ModelRotation.getEastRot(Facing.getHorizontal(rot.getHorizontalIndex() + offset), false);
}
public static Facing getFacing(IBlockAccess world, BlockPos pos) {
return world.getState(pos).getValue(FACING);
}
public Model getModel(ModelProvider provider, String name, State state) {
String bottom = name + "_bottom";
String top = name + "_top";
if(state.getValue(HALF) == EnumDoorHalf.LOWER) {
if(state.getValue(HINGE) == EnumHingePosition.LEFT == state.getValue(OPEN))
return provider.getModel(bottom)
.add(0, 0, 0, 3, 16, 16)
.d().uv(13, 0, 16, 16)
.n().uv(3, 0, 0, 16)
.s().uv(0, 0, 3, 16)
.w().uv(16, 0, 0, 16)
.e().uv(0, 0, 16, 16).noCull()
.rotate(getRotation(state.getValue(FACING), state.getValue(OPEN) ? 1 : 0));
else
return provider.getModel(bottom)
.add(0, 0, 0, 3, 16, 16)
.d().uv(13, 0, 16, 16)
.n().uv(3, 0, 0, 16)
.s().uv(0, 0, 3, 16)
.w().uv(0, 0, 16, 16)
.e().uv(16, 0, 0, 16).noCull()
.rotate(getRotation(state.getValue(FACING), state.getValue(OPEN) ? 3 : 0));
}
else {
if(state.getValue(HINGE) == EnumHingePosition.LEFT == state.getValue(OPEN))
return provider.getModel(top)
.add(0, 0, 0, 3, 16, 16)
.u(bottom).uv(13, 0, 16, 16)
.n().uv(3, 0, 0, 16)
.s().uv(0, 0, 3, 16)
.w().uv(16, 0, 0, 16)
.e().uv(0, 0, 16, 16).noCull()
.rotate(getRotation(state.getValue(FACING), state.getValue(OPEN) ? 1 : 0));
else
return provider.getModel(top)
.add(0, 0, 0, 3, 16, 16)
.u(bottom).uv(13, 0, 16, 16)
.n().uv(3, 0, 0, 16)
.s().uv(0, 0, 3, 16)
.w().uv(0, 0, 16, 16)
.e().uv(16, 0, 0, 16).noCull()
.rotate(getRotation(state.getValue(FACING), state.getValue(OPEN) ? 3 : 0));
}
}
protected Property[] getProperties() {
return new Property[] {HALF, FACING, OPEN, HINGE, POWERED};
}
private static ModelRotation getRotation(Facing rot, int offset) {
return ModelRotation.getEastRot(Facing.getHorizontal(rot.getHorizontalIndex() + offset), false);
}
public Model getModel(ModelProvider provider, String name, State state) {
String bottom = name + "_bottom";
String top = name + "_top";
if(state.getValue(HALF) == EnumDoorHalf.LOWER) {
if(state.getValue(HINGE) == EnumHingePosition.LEFT == state.getValue(OPEN))
return provider.getModel(bottom).add(0, 0, 0, 3, 16, 16).d().uv(13, 0, 16, 16).n().uv(3, 0, 0, 16).s().uv(0, 0, 3, 16).w()
.uv(16, 0, 0, 16).e().uv(0, 0, 16, 16).noCull().rotate(getRotation(state.getValue(FACING), state.getValue(OPEN) ? 1 : 0));
else
return provider.getModel(bottom).add(0, 0, 0, 3, 16, 16).d().uv(13, 0, 16, 16).n().uv(3, 0, 0, 16).s().uv(0, 0, 3, 16).w()
.uv(0, 0, 16, 16).e().uv(16, 0, 0, 16).noCull().rotate(getRotation(state.getValue(FACING), state.getValue(OPEN) ? 3 : 0));
}
else {
if(state.getValue(HINGE) == EnumHingePosition.LEFT == state.getValue(OPEN))
return provider.getModel(top).add(0, 0, 0, 3, 16, 16).u(bottom).uv(13, 0, 16, 16).n().uv(3, 0, 0, 16).s().uv(0, 0, 3, 16).w()
.uv(16, 0, 0, 16).e().uv(0, 0, 16, 16).noCull().rotate(getRotation(state.getValue(FACING), state.getValue(OPEN) ? 1 : 0));
else
return provider.getModel(top).add(0, 0, 0, 3, 16, 16).u(bottom).uv(13, 0, 16, 16).n().uv(3, 0, 0, 16).s().uv(0, 0, 3, 16).w()
.uv(0, 0, 16, 16).e().uv(16, 0, 0, 16).noCull().rotate(getRotation(state.getValue(FACING), state.getValue(OPEN) ? 3 : 0));
}
}
public Property<?>[] getIgnoredProperties() {
return new Property[] {POWERED};
}
public Property<?>[] getIgnoredProperties() {
return new Property[] {POWERED};
}
protected Item getItemToRegister() {
return new ItemDoor(this);
}
public static enum EnumDoorHalf implements Identifyable
{
UPPER,
LOWER;
public String toString()
{
return this.getName();
}
public String getName()
{
return this == UPPER ? "upper" : "lower";
}
}
public static enum EnumHingePosition implements Identifyable
{
LEFT,
RIGHT;
public String toString()
{
return this.getName();
}
public String getName()
{
return this == LEFT ? "left" : "right";
}
}
}