From f4813489effd2aa64683c7310377ba6573e5d694 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Wed, 28 Aug 2024 22:53:07 -0500 Subject: [PATCH 01/14] Getting there --- .../net/malisis/core/block/MalisisBlock.java | 9 +- .../java/net/malisis/doors/MalisisDoors.java | 1 + .../java/net/malisis/doors/Registers.java | 15 ++ .../net/malisis/doors/door/block/BigDoor.java | 24 ++- .../door/block/CollisionHelperBlock.java | 169 ++++++++++++++++++ .../door/tileentity/BigDoorTileEntity.java | 58 +++++- .../tileentity/CollisionHelperTileEntity.java | 66 +++++++ .../doors/door/tileentity/IMultiDoor.java | 29 +++ .../door/tileentity/MultiCollisionTile.java | 10 ++ 9 files changed, 377 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java create mode 100644 src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java create mode 100644 src/main/java/net/malisis/doors/door/tileentity/IMultiDoor.java create mode 100644 src/main/java/net/malisis/doors/door/tileentity/MultiCollisionTile.java diff --git a/src/main/java/net/malisis/core/block/MalisisBlock.java b/src/main/java/net/malisis/core/block/MalisisBlock.java index 760fcd5..5bf6590 100644 --- a/src/main/java/net/malisis/core/block/MalisisBlock.java +++ b/src/main/java/net/malisis/core/block/MalisisBlock.java @@ -70,7 +70,6 @@ public void registerBlockIcons(IIconRegister reg) { super.registerBlockIcons(reg); } - @Override public AxisAlignedBB[] getBoundingBox(IBlockAccess world, int x, int y, int z, BoundingBoxType type) { return new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ) }; } @@ -85,9 +84,17 @@ public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAligne @Override public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 src, Vec3 dest) { + this.setBlockBoundsBasedOnState(world, x, y, z); return new RaytraceBlock(world, src, dest, x, y, z).trace(); } + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World worldIn, int x, int y, int z) + { + this.setBlockBoundsBasedOnState(worldIn, x, y, z); + return super.getCollisionBoundingBoxFromPool(worldIn, x, y, z); + } + @Override public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { AxisAlignedBB[] aabbs = getBoundingBox(world, x, y, z, BoundingBoxType.SELECTION); diff --git a/src/main/java/net/malisis/doors/MalisisDoors.java b/src/main/java/net/malisis/doors/MalisisDoors.java index 2441f3e..ac378f8 100644 --- a/src/main/java/net/malisis/doors/MalisisDoors.java +++ b/src/main/java/net/malisis/doors/MalisisDoors.java @@ -130,6 +130,7 @@ public static class Blocks { public static Block ironTrapDoor; public static Block slidingTrapDoor; public static Block saloonDoor; + public static Block collisionHelperBlock; } public static class Items { diff --git a/src/main/java/net/malisis/doors/Registers.java b/src/main/java/net/malisis/doors/Registers.java index b90987c..4e6ea83 100644 --- a/src/main/java/net/malisis/doors/Registers.java +++ b/src/main/java/net/malisis/doors/Registers.java @@ -27,6 +27,7 @@ import net.malisis.doors.block.VanishingDiamondBlock; import net.malisis.doors.door.DoorDescriptor; import net.malisis.doors.door.block.BigDoor; +import net.malisis.doors.door.block.CollisionHelperBlock; import net.malisis.doors.door.block.CustomDoor; import net.malisis.doors.door.block.FenceGate; import net.malisis.doors.door.block.FenceGate.Type; @@ -46,6 +47,7 @@ import net.malisis.doors.door.item.DoorItem; import net.malisis.doors.door.item.ForcefieldItem; import net.malisis.doors.door.tileentity.BigDoorTileEntity; +import net.malisis.doors.door.tileentity.CollisionHelperTileEntity; import net.malisis.doors.door.tileentity.CustomDoorTileEntity; import net.malisis.doors.door.tileentity.DoorTileEntity; import net.malisis.doors.door.tileentity.FenceGateTileEntity; @@ -114,6 +116,8 @@ public static void init() { registerForcefieldDoor(); + registerCollisionHelperBlocks(); + GameRegistry.registerTileEntity(DoorTileEntity.class, "doorTileEntity"); GameRegistry.registerTileEntity(TrapDoorTileEntity.class, "trapDoorTileEntity"); GameRegistry.registerTileEntity(FenceGateTileEntity.class, "fenceGateTileEntity"); @@ -463,4 +467,15 @@ private static void registerForcefieldDoor() { 'E', Items.comparator); } + + private static void registerCollisionHelperBlocks() + { + collisionHelperBlock = new CollisionHelperBlock(BigDoor.Type.MEDIEVAL); + GameRegistry.registerBlock(collisionHelperBlock, collisionHelperBlock.getUnlocalizedName() + .substring(5)); + + GameRegistry.registerTileEntity(CollisionHelperTileEntity.class, "collisionHelperTileEntity"); + + + } } diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index cfd8a95..cee0438 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -33,6 +33,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -99,7 +100,19 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase p world.setBlockMetadataWithNotify(x, y, z, metadata, 2); BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); - if (te != null) te.setFrameState(BlockState.fromNBT(itemStack.getTagCompound())); + if (te != null) + { + te.setFrameState(BlockState.fromNBT(itemStack.getTagCompound())); + if (checkAreaClearForDoor(world, x, y, z, metadata)) + { + te.onCreate(x, y, z, metadata); + } + } + } + + private boolean checkAreaClearForDoor(World world, int x, int y, int z, int metadata) + { + return true; } @Override @@ -125,7 +138,7 @@ public AxisAlignedBB[] getBoundingBox(IBlockAccess world, int x, int y, int z, B if (type == BoundingBoxType.RENDER) { aabbs[0].minZ = -.5F; } else if ((type == BoundingBoxType.COLLISION || type == BoundingBoxType.CHUNKCOLLISION - || type == BoundingBoxType.RAYTRACE) && (te.isOpened() || te.isMoving())) { + || type == BoundingBoxType.RAYTRACE || type == BoundingBoxType.SELECTION) && (te.isOpened() || te.isMoving())) { aabbs = new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox(0, 0, -0.5F, 0.5F, 4, 1), AxisAlignedBB.getBoundingBox(3.5F, 0, -0.5F, 4, 4, 1), AxisAlignedBB.getBoundingBox(0, 4, 1 - Door.DOOR_WIDTH, 4, 5, 1) }; @@ -169,6 +182,13 @@ public int getRenderType() { return renderId; } + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) + { + //BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); + this.setBlockBounds((float) defaultBoundingBox.minX, (float) defaultBoundingBox.minY, (float) defaultBoundingBox.minZ, (float) defaultBoundingBox.maxX, (float) defaultBoundingBox.maxY, (float) defaultBoundingBox.maxZ); + } + @Override public int getRenderBlockPass() { return 1; diff --git a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java new file mode 100644 index 0000000..cdaf28b --- /dev/null +++ b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java @@ -0,0 +1,169 @@ +package net.malisis.doors.door.block; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.malisis.doors.MalisisDoors; +import net.malisis.doors.door.tileentity.CollisionHelperTileEntity; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.world.Explosion; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.List; +import java.util.Random; + +public class CollisionHelperBlock extends BlockContainer implements ITileEntityProvider { + + + BigDoor.Type type; + + // This class serves at the invisible collision blocks to help BigDoor with collisions + public CollisionHelperBlock(BigDoor.Type type) { + super(Material.wood); + this.setHardness(1.0F); + this.setStepSound(Block.soundTypeWood); + this.setBlockTextureName(type.name + "_collisionHelper"); + this.type = type; + this.setBlockName(type.name + "_collisionHelper"); + } + + @Override + public boolean canDropFromExplosion(Explosion par1Explosion) { + return false; + } + + @Override + public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side) { + if (side != 1) return false; + + ForgeDirection dir = ForgeDirection.getOrientation(side) + .getOpposite(); + return world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) + .isSideSolid(world, x, y, z, dir); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer EntityPlayer, int par6, + float subx, float suby, float subz) + { + if (!world.isRemote) + { + final CollisionHelperTileEntity tileEntity = ((CollisionHelperTileEntity) world.getTileEntity(x, y, z)); + return tileEntity.onBlockActivated(world, x, y, z, EntityPlayer); + } + return true; + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block block, int meta) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof CollisionHelperTileEntity) { + ((CollisionHelperTileEntity) tileEntity).onBlockRemoval(); + } + super.breakBlock(world, x, y, z, block, meta); + } + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { + final int meta = world.getBlockMetadata(x, y, z); + + if (meta == 0) + { + this.setBlockBounds(1.0F - Door.DOOR_WIDTH, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + if (meta == 1) + { + this.setBlockBounds(0.0F, 0.0F, 1.0F - Door.DOOR_WIDTH, 1.0F, 1.0F, 1.0F); + } + if (meta == 2) + { + this.setBlockBounds(0.0F, 0.0F, 0.0F, Door.DOOR_WIDTH, 1.0F, 1.0F); + } + if (meta == 3) + { + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, Door.DOOR_WIDTH); + } + } + + @Override + public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, + List list, Entity entity) { + setBlockBoundsBasedOnState(world, x, y, z); + super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { + this.setBlockBoundsBasedOnState(world, x, y, z); + return super.getCollisionBoundingBoxFromPool(world, x, y, z); + } + + @Override + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { + this.setBlockBoundsBasedOnState(world, x, y, z); + return super.getSelectedBoundingBoxFromPool(world, x, y, z); + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta) { + return new CollisionHelperTileEntity(); + } + + @Override + public float getBlockHardness(World world, int x, int y, int z) { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + + if (tileEntity instanceof CollisionHelperTileEntity) { + final int mainX = ((CollisionHelperTileEntity) tileEntity).mainBlockX; + final int mainY = ((CollisionHelperTileEntity) tileEntity).mainBlockY; + final int mainZ = ((CollisionHelperTileEntity) tileEntity).mainBlockZ; + + if (world.getTileEntity(x,y,z) != null) { + return world.getBlock(mainX, mainY, mainZ).getBlockHardness(world, mainX, mainY, mainZ); + } + } + + return this.blockHardness; + } + + @Override + public int quantityDropped(Random par1Random) { + return 0; + } + + @Override + public int getRenderType() { + return -1; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean shouldSideBeRendered(IBlockAccess worldIn, int x, int y, int z, int side) { + return false; + } + + public void makeCollisionHelperBlock(World world, int x, int y, int z, int xMain, int yMain, int zMain, int meta) + { + world.setBlock(x, y, z, this, meta, 3); + ((CollisionHelperTileEntity) world.getTileEntity(x, y, z)).setMainBlock(xMain, yMain, zMain); + } +} diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index 290c378..f81322c 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -17,26 +17,32 @@ import net.malisis.core.block.BoundingBoxType; import net.malisis.core.util.BlockState; import net.malisis.core.util.MultiBlock; +import net.malisis.doors.MalisisDoors; import net.malisis.doors.door.DoorDescriptor; import net.malisis.doors.door.DoorRegistry; import net.malisis.doors.door.DoorState; import net.malisis.doors.door.block.BigDoor; +import net.malisis.doors.door.block.CollisionHelperBlock; import net.malisis.doors.door.block.Door; import net.malisis.doors.door.movement.CarriageDoorMovement; import net.malisis.doors.door.sound.CarriageDoorSound; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; import com.google.common.base.Objects; +import static net.minecraft.util.MathHelper.abs; + /** * @author Ordinastie * */ -public class BigDoorTileEntity extends DoorTileEntity { +public class BigDoorTileEntity extends DoorTileEntity implements IMultiDoor { private boolean delete = false; private boolean processed = true; @@ -139,4 +145,54 @@ public AxisAlignedBB getRenderBoundingBox() { .getBoundingBox(getWorldObj(), xCoord, yCoord, zCoord, BoundingBoxType.RENDER)[0] .offset(xCoord, yCoord, zCoord); } + + @Override + public boolean onActivated(EntityPlayer entityPlayer) { + return false; + } + + @Override + public void onCreate(int x, int y, int z, int meta) { + this.markDirty(); + final int buildHeight = this.worldObj.getHeight() - 6; // No reason to have the door right at world height + + if (y > buildHeight) + { + return; + } + + // 4 states based on the meta of the main + // meta 0: going South to North on the East side of the block - facing west + // meta 1: going West to East on the South side of the block - facing north + // meta 2: going North to South on the West side of the block - facing east + // meta 3: going East to West on the North side of the block - facing south + + boolean widthDirectionFlag = meta % 2 == 0; + + int xStep = meta == 3 ? -1 : 1; + int zStep = meta == 0 ? -1 : 1; + + int xMax = widthDirectionFlag ? 1 : 4; + int zMax = widthDirectionFlag ? 4 : 1; + + for (int yLoc = 0; yLoc < 5; yLoc++) + { + for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) + { + for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) + { + if (!(yLoc == 0 && zLoc == 0 && xLoc == 0)) + { + ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlock).makeCollisionHelperBlock(this.worldObj, x + xLoc, y + yLoc, z + zLoc, x, y, z, meta); + } + } + } + } + } + + @Override + public void onDestroy(TileEntity callingBlock) + { + + } } diff --git a/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java new file mode 100644 index 0000000..789c3c6 --- /dev/null +++ b/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java @@ -0,0 +1,66 @@ +package net.malisis.doors.door.tileentity; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class CollisionHelperTileEntity extends MultiCollisionTile +{ + public void setMainBlock(int x, int y, int z) + { + this.mainBlockX = x; + this.mainBlockY = y; + this.mainBlockZ = z; + this.markDirty(); + if (!this.worldObj.isRemote) + { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + } + + public void onBlockRemoval() + { + TileEntity mainBlock = getMainBlockTile(); + if (mainBlock != null) + { + if (mainBlock instanceof IMultiDoor) + { + ((IMultiDoor) mainBlock).onDestroy(this); + } + } + } + + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer) { + TileEntity mainBlock = getMainBlockTile(); + if (mainBlock != null) { + final TileEntity tileEntity = this.worldObj + .getTileEntity(this.mainBlockX, this.mainBlockY, this.mainBlockZ); + if (tileEntity instanceof IMultiDoor) { + return ((IMultiDoor) tileEntity).onActivated(par5EntityPlayer); + } + } + return false; + } + + public TileEntity getMainBlockTile() { + + return this.worldObj.getTileEntity(this.mainBlockX, this.mainBlockY, this.mainBlockZ); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setInteger("mainBlockX", this.mainBlockX); + nbt.setInteger("mainBlockY", this.mainBlockY); + nbt.setInteger("mainBlockZ", this.mainBlockZ); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.mainBlockX = nbt.getInteger("mainBlockX"); + this.mainBlockY = nbt.getInteger("mainBlockY"); + this.mainBlockZ = nbt.getInteger("mainBlockZ"); + } +} diff --git a/src/main/java/net/malisis/doors/door/tileentity/IMultiDoor.java b/src/main/java/net/malisis/doors/door/tileentity/IMultiDoor.java new file mode 100644 index 0000000..b5b550f --- /dev/null +++ b/src/main/java/net/malisis/doors/door/tileentity/IMultiDoor.java @@ -0,0 +1,29 @@ +package net.malisis.doors.door.tileentity; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; + +public interface IMultiDoor { + + /** + * Called when activated + */ + boolean onActivated(EntityPlayer entityPlayer); + + /** + * Called when this multiblock is created + * + * @param x - placed x coord + * @param y - placed y coord + * @param z - placed z coord' + * @param meta - meta of the placed door + */ + void onCreate(int x, int y, int z, int meta); + + /** + * Called when one of the multiblocks of this block is destroyed + * + * @param callingBlock - The tile entity who called the onDestroy function + */ + void onDestroy(TileEntity callingBlock); +} diff --git a/src/main/java/net/malisis/doors/door/tileentity/MultiCollisionTile.java b/src/main/java/net/malisis/doors/door/tileentity/MultiCollisionTile.java new file mode 100644 index 0000000..5d9c91f --- /dev/null +++ b/src/main/java/net/malisis/doors/door/tileentity/MultiCollisionTile.java @@ -0,0 +1,10 @@ +package net.malisis.doors.door.tileentity; + + +import net.minecraft.tileentity.TileEntity; + +public class MultiCollisionTile extends TileEntity { + public int mainBlockX; + public int mainBlockY; + public int mainBlockZ; +} From ff7a1ed370f8791aea32455a628a894f65b2b07e Mon Sep 17 00:00:00 2001 From: rjnasers Date: Sat, 31 Aug 2024 18:56:41 -0500 Subject: [PATCH 02/14] Lots of work done --- .../util/ComplexAxisAlignedBoundingBox.java | 112 ++++++++++++++++++ .../java/net/malisis/doors/MalisisDoors.java | 13 ++ .../net/malisis/doors/door/block/BigDoor.java | 63 +++++++++- .../door/block/CollisionHelperBlock.java | 42 ++++++- .../doors/door/renderer/BigDoorRenderer.java | 2 +- .../door/tileentity/BigDoorTileEntity.java | 7 +- .../tileentity/CollisionHelperTileEntity.java | 22 +++- .../malisis/doors/event/DoorEventHandler.java | 46 +++++++ .../CustomDoorBoundingBoxRenderer.java | 103 ++++++++++++++++ 9 files changed, 400 insertions(+), 10 deletions(-) create mode 100644 src/main/java/net/malisis/core/util/ComplexAxisAlignedBoundingBox.java create mode 100644 src/main/java/net/malisis/doors/event/DoorEventHandler.java create mode 100644 src/main/java/net/malisis/doors/renderer/CustomDoorBoundingBoxRenderer.java diff --git a/src/main/java/net/malisis/core/util/ComplexAxisAlignedBoundingBox.java b/src/main/java/net/malisis/core/util/ComplexAxisAlignedBoundingBox.java new file mode 100644 index 0000000..6604b6e --- /dev/null +++ b/src/main/java/net/malisis/core/util/ComplexAxisAlignedBoundingBox.java @@ -0,0 +1,112 @@ +package net.malisis.core.util; +import net.minecraft.util.Vec3; +import net.minecraftforge.common.util.ForgeDirection; +import org.apache.commons.lang3.tuple.Pair; + +import static net.minecraft.util.Vec3.createVectorHelper; + +public class ComplexAxisAlignedBoundingBox +{ + public enum Axis { + X, + Y, + Z + }; + + private static final int[] cos = { 1, 0, -1, 0 }; + private static final int[] sin = { 0, 1, 0, -1 }; + + + public Vec3[][] flatSurfaces; + public Pair[] verticals; + + public static ComplexAxisAlignedBoundingBox defaultComplexBoundingBox = new ComplexAxisAlignedBoundingBox( + new Vec3[][] { + { createVectorHelper(0,0,0), createVectorHelper(0,0,1), createVectorHelper(1,0,1), createVectorHelper(1,0,0) }, // bottom face + { createVectorHelper(0,1,0), createVectorHelper(0,1,1), createVectorHelper(1,1,1), createVectorHelper(1,1,0) }, // top face + }, + new Pair[] { + Pair.of(createVectorHelper(0,0,0), createVectorHelper(0,1,0)), + Pair.of(createVectorHelper(1,0,0), createVectorHelper(1,1,0)), + Pair.of(createVectorHelper(0,0,1), createVectorHelper(0,1,1)), + Pair.of(createVectorHelper(1,0,1), createVectorHelper(1,1,1)) + } + ); + + public ComplexAxisAlignedBoundingBox(Vec3[][] flatSurfaces, Pair[] verticals ) + { + this.flatSurfaces = flatSurfaces; + this.verticals = verticals; + } + + public void addOffset(double x, double y, double z) + { + for (Vec3[] face : flatSurfaces) { + for (Vec3 vec : face) { + vec.xCoord += x; + vec.yCoord += y; + vec.zCoord += z; + } + } + + for (Pair vertical : verticals) { + Vec3 start = vertical.getLeft(); + Vec3 end = vertical.getRight(); + + start.xCoord += x; + start.yCoord += y; + start.zCoord += z; + + end.xCoord += x; + end.yCoord += y; + end.zCoord += z; + } + } + + /** + * Rotates the ComplexAxisAlignedBoundingBox by the given angle around the specified axis. + */ + public void rotate(ForgeDirection dir, Axis axis) { + int angle = getAngle(dir); + // Rotate flat surfaces + for (int i = 0; i < flatSurfaces.length; i++) { + for (int j = 0; j < flatSurfaces[i].length; j++) { + flatSurfaces[i][j] = rotateVec(flatSurfaces[i][j], angle, axis); + } + } + + // Rotate verticals + for (int i = 0; i < verticals.length; i++) { + Vec3 start = verticals[i].getLeft(); + Vec3 end = verticals[i].getRight(); + verticals[i] = Pair.of(rotateVec(start, angle, axis), rotateVec(end, angle, axis)); + } + } + + private Vec3 rotateVec(Vec3 vec, int angle, Axis axis) { + int a = angle % 4; + if (a < 0) a += 4; + int s = sin[a]; + int c = cos[a]; + + double x = vec.xCoord; + double y = vec.yCoord; + double z = vec.zCoord; + + return switch (axis) { + case X -> createVectorHelper(x, y * c - z * s, y * s + z * c); + case Y -> createVectorHelper(x * c - z * s, y, x * s + z * c); + case Z -> createVectorHelper(x * c - y * s, x * s + y * c, z); + }; + } + + private static int getAngle(ForgeDirection dir) { + return switch (dir) { + case EAST -> 1; + case SOUTH -> 2; + case WEST -> 3; + default -> 0; + }; + } + +} diff --git a/src/main/java/net/malisis/doors/MalisisDoors.java b/src/main/java/net/malisis/doors/MalisisDoors.java index ac378f8..b3a709c 100644 --- a/src/main/java/net/malisis/doors/MalisisDoors.java +++ b/src/main/java/net/malisis/doors/MalisisDoors.java @@ -2,6 +2,9 @@ import static net.malisis.doors.Tags.VERSION; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.malisis.core.IMalisisMod; import net.malisis.core.MalisisCore; import net.malisis.core.configuration.Settings; @@ -20,6 +23,7 @@ import net.malisis.doors.door.block.ForcefieldDoor; import net.malisis.doors.door.block.RustyHatch; import net.malisis.doors.door.item.ForcefieldItem; +import net.malisis.doors.event.DoorEventHandler; import net.malisis.doors.proxy.IProxy; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; @@ -30,6 +34,7 @@ import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.common.MinecraftForge; @Mod( modid = MalisisDoors.modid, @@ -77,6 +82,7 @@ public Settings getSettings() { return settings; } + @EventHandler public void preInit(FMLPreInitializationEvent event) { settings = new MalisisDoorsSettings(event.getSuggestedConfigurationFile()); @@ -86,6 +92,13 @@ public void preInit(FMLPreInitializationEvent event) { proxy.initRenderers(); } + @SideOnly(Side.CLIENT) + @EventHandler + public void init(FMLInitializationEvent event) + { + MinecraftForge.EVENT_BUS.register(new DoorEventHandler()); + } + @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.initFonts(); diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index cee0438..1533bad 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -19,6 +19,7 @@ import net.malisis.core.block.MalisisBlock; import net.malisis.core.util.AABBUtils; import net.malisis.core.util.BlockState; +import net.malisis.core.util.ComplexAxisAlignedBoundingBox; import net.malisis.core.util.EntityUtils; import net.malisis.core.util.TileEntityUtils; import net.malisis.doors.MalisisDoors; @@ -37,6 +38,9 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import org.apache.commons.lang3.tuple.Pair; + +import static net.minecraft.util.Vec3.createVectorHelper; /** * @author Ordinastie @@ -58,6 +62,27 @@ private Type(String name, Item door) { } } + private final Vec3[][] selectionOpenHoriztonalFaces = new Vec3[][] { + { createVectorHelper(0,5,1), createVectorHelper(0,5,1 - Door.DOOR_WIDTH), createVectorHelper(4,5,1 - Door.DOOR_WIDTH), createVectorHelper(4,5,1) }, // bottom face + { createVectorHelper(.5,4,1), createVectorHelper(.5,4,1 - Door.DOOR_WIDTH), createVectorHelper(3.5,4,1 - Door.DOOR_WIDTH), createVectorHelper(3.5,4,1) }, // top face + { createVectorHelper(0,4,1 - Door.DOOR_WIDTH), createVectorHelper(0, 4, -.5), createVectorHelper(.5,4,-.5), createVectorHelper(.5,4,1 - Door.DOOR_WIDTH) }, + { createVectorHelper(3.5, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 4, -.5), createVectorHelper(3.5, 4, -.5) }, + { createVectorHelper(0,0,1), createVectorHelper(0, 0, -.5), createVectorHelper(.5,0,-.5), createVectorHelper(.5,0,1) }, + { createVectorHelper(3.5, 0, 1), createVectorHelper(4, 0, 1), createVectorHelper(4, 0, -.5), createVectorHelper(3.5, 0, -.5) } + }; + private final Pair[] selectionOpenVerticals = new Pair[] { + Pair.of(createVectorHelper(0,0,1), createVectorHelper(0,5,1)), + Pair.of(createVectorHelper(4,0,1), createVectorHelper(4,5,1)), + Pair.of(createVectorHelper(.5,0,1), createVectorHelper(.5,4,1)), + Pair.of(createVectorHelper(3.5,0,1), createVectorHelper(3.5,4,1)), + Pair.of(createVectorHelper(0,0,-.5), createVectorHelper(0,4,-.5)), + Pair.of(createVectorHelper(.5,0,-.5), createVectorHelper(.5,4,-.5)), + Pair.of(createVectorHelper(3.5,0,-.5), createVectorHelper(3.5,4,-.5)), + Pair.of(createVectorHelper(4,0,-.5), createVectorHelper(4,4,-.5)), + Pair.of(createVectorHelper(0,4,1 - Door.DOOR_WIDTH), createVectorHelper(0,5,1 - Door.DOOR_WIDTH)), + Pair.of(createVectorHelper(4,4,1 - Door.DOOR_WIDTH), createVectorHelper(4, 5, 1 - Door.DOOR_WIDTH)) + }; + public static int renderId; public static int renderPass = -1; private AxisAlignedBB defaultBoundingBox = AxisAlignedBB.getBoundingBox(0, 0, 1 - Door.DOOR_WIDTH, 4, 5, 1); @@ -147,6 +172,43 @@ public AxisAlignedBB[] getBoundingBox(IBlockAccess world, int x, int y, int z, B return AABBUtils.rotate(aabbs, Door.intToDir(te.getDirection())); } + public ComplexAxisAlignedBoundingBox getComplexBoundingBoxWithOffset(IBlockAccess world, int x, int y, int z, BoundingBoxType type) + { + BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); + if (te == null) return ComplexAxisAlignedBoundingBox.defaultComplexBoundingBox; + + if (type == BoundingBoxType.SELECTION && (te.isOpened() || te.isMoving())) + { + Vec3[][] clonedFlatSurfaces = new Vec3[selectionOpenHoriztonalFaces.length][]; + for (int i = 0; i < selectionOpenHoriztonalFaces.length; i++) { + clonedFlatSurfaces[i] = new Vec3[selectionOpenHoriztonalFaces[i].length]; + for (int j = 0; j < selectionOpenHoriztonalFaces[i].length; j++) { + Vec3 vec = selectionOpenHoriztonalFaces[i][j]; + clonedFlatSurfaces[i][j] = createVectorHelper(vec.xCoord, vec.yCoord, vec.zCoord); + } + } + + Pair[] clonedVerticals = new Pair[selectionOpenVerticals.length]; + for (int i = 0; i < selectionOpenVerticals.length; i++) { + Vec3 left = selectionOpenVerticals[i].getLeft(); + Vec3 right = selectionOpenVerticals[i].getRight(); + clonedVerticals[i] = Pair.of(createVectorHelper(left.xCoord, left.yCoord, left.zCoord), + createVectorHelper(right.xCoord, right.yCoord, right.zCoord)); + } + + ComplexAxisAlignedBoundingBox CAABB = new ComplexAxisAlignedBoundingBox(clonedFlatSurfaces, clonedVerticals); + CAABB.rotate(Door.intToDir(te.getDirection()) ,ComplexAxisAlignedBoundingBox.Axis.Y); + switch (Door.intToDir(te.getDirection())) { + case EAST -> CAABB.addOffset(x + 1, y, z); + case NORTH -> CAABB.addOffset(x, y, z); + case SOUTH -> CAABB.addOffset(x + 1, y, z + 1); + case WEST -> CAABB.addOffset(x, y, z + 1); + } + return CAABB; + } + return ComplexAxisAlignedBoundingBox.defaultComplexBoundingBox; + } + @Override public TileEntity createNewTileEntity(World world, int metadata) { return new BigDoorTileEntity(); @@ -185,7 +247,6 @@ public int getRenderType() { @Override public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { - //BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); this.setBlockBounds((float) defaultBoundingBox.minX, (float) defaultBoundingBox.minY, (float) defaultBoundingBox.minZ, (float) defaultBoundingBox.maxX, (float) defaultBoundingBox.maxY, (float) defaultBoundingBox.maxZ); } diff --git a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java index cdaf28b..5c8418f 100644 --- a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java +++ b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java @@ -2,7 +2,10 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.malisis.core.block.BoundingBoxType; +import net.malisis.core.util.ComplexAxisAlignedBoundingBox; import net.malisis.doors.MalisisDoors; +import net.malisis.doors.door.tileentity.BigDoorTileEntity; import net.malisis.doors.door.tileentity.CollisionHelperTileEntity; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; @@ -56,12 +59,8 @@ public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side) { public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer EntityPlayer, int par6, float subx, float suby, float subz) { - if (!world.isRemote) - { - final CollisionHelperTileEntity tileEntity = ((CollisionHelperTileEntity) world.getTileEntity(x, y, z)); - return tileEntity.onBlockActivated(world, x, y, z, EntityPlayer); - } - return true; + final CollisionHelperTileEntity tileEntity = ((CollisionHelperTileEntity) world.getTileEntity(x, y, z)); + return tileEntity.onBlockActivated(world, x, y, z, EntityPlayer); } @Override @@ -111,9 +110,40 @@ public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, @Override public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); + CollisionHelperTileEntity thisTE = ((CollisionHelperTileEntity) world.getTileEntity(x,y,z)); + Block mainBlock = world.getBlock(thisTE.mainBlockX, thisTE.mainBlockY, thisTE.mainBlockZ); + if (mainBlock instanceof BigDoor) + { + return mainBlock.getSelectedBoundingBoxFromPool(world, thisTE.mainBlockX, thisTE.mainBlockY, thisTE.mainBlockZ); + } return super.getSelectedBoundingBoxFromPool(world, x, y, z); } + public ComplexAxisAlignedBoundingBox getComplexBoundingBox(World world, int x, int y, int z) + { + this.setBlockBoundsBasedOnState(world, x, y, z); + CollisionHelperTileEntity TE = getTileEntity(world, x, y, z); + BigDoor mainBlock = getMainBlock(world, x, y, z); + return mainBlock.getComplexBoundingBoxWithOffset(world, TE.mainBlockX, TE.mainBlockY, TE.mainBlockZ, BoundingBoxType.SELECTION); + } + + public BigDoor getMainBlock(World world, int x, int y, int z) + { + CollisionHelperTileEntity cTE = this.getTileEntity(world, x, y, z); + return (BigDoor) world.getBlock(cTE.mainBlockX, cTE.mainBlockY, cTE.mainBlockZ); + } + + public BigDoorTileEntity getMainTileEntity(World world, int x, int y, int z) + { + CollisionHelperTileEntity cTE = this.getTileEntity(world, x, y, z); + return (BigDoorTileEntity) world.getTileEntity(cTE.mainBlockX, cTE.mainBlockY, cTE.mainBlockZ); + } + + public CollisionHelperTileEntity getTileEntity(World world, int x, int y, int z) + { + return (CollisionHelperTileEntity) world.getTileEntity(x,y,z); + } + @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new CollisionHelperTileEntity(); diff --git a/src/main/java/net/malisis/doors/door/renderer/BigDoorRenderer.java b/src/main/java/net/malisis/doors/door/renderer/BigDoorRenderer.java index 370b98e..63a8090 100644 --- a/src/main/java/net/malisis/doors/door/renderer/BigDoorRenderer.java +++ b/src/main/java/net/malisis/doors/door/renderer/BigDoorRenderer.java @@ -94,7 +94,7 @@ private void renderTileEntity() { tileEntity.getTimer() .getStart()); - if (tileEntity.getMovement() != null) { + if (tileEntity.getMovement() != null && (tileEntity.isMoving() || tileEntity.isOpened())) { Animation[] anims = tileEntity.getMovement() .getAnimations(tileEntity, model, rp); ar.animate(anims); diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index f81322c..fbbd4e0 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -17,6 +17,7 @@ import net.malisis.core.block.BoundingBoxType; import net.malisis.core.util.BlockState; import net.malisis.core.util.MultiBlock; +import net.malisis.core.util.TileEntityUtils; import net.malisis.doors.MalisisDoors; import net.malisis.doors.door.DoorDescriptor; import net.malisis.doors.door.DoorRegistry; @@ -148,7 +149,11 @@ public AxisAlignedBB getRenderBoundingBox() { @Override public boolean onActivated(EntityPlayer entityPlayer) { - return false; + + if (this.worldObj.isRemote) return true; + + this.openOrCloseDoor(); + return true; } @Override diff --git a/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java index 789c3c6..fa38ba6 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java @@ -2,6 +2,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -32,6 +35,7 @@ public void onBlockRemoval() } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer) { + world.markBlockForUpdate(x, y, z); TileEntity mainBlock = getMainBlockTile(); if (mainBlock != null) { final TileEntity tileEntity = this.worldObj @@ -40,7 +44,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p return ((IMultiDoor) tileEntity).onActivated(par5EntityPlayer); } } - return false; + return true; } public TileEntity getMainBlockTile() { @@ -48,6 +52,22 @@ public TileEntity getMainBlockTile() { return this.worldObj.getTileEntity(this.mainBlockX, this.mainBlockY, this.mainBlockZ); } + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbtTag = new NBTTagCompound(); + this.writeToNBT(nbtTag); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) + { + NBTTagCompound packetData = pkt.func_148857_g(); + this.mainBlockX = packetData.getInteger("mainBlockX"); + this.mainBlockY = packetData.getInteger("mainBlockY"); + this.mainBlockZ = packetData.getInteger("mainBlockZ"); + } + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); diff --git a/src/main/java/net/malisis/doors/event/DoorEventHandler.java b/src/main/java/net/malisis/doors/event/DoorEventHandler.java new file mode 100644 index 0000000..6a788a7 --- /dev/null +++ b/src/main/java/net/malisis/doors/event/DoorEventHandler.java @@ -0,0 +1,46 @@ +package net.malisis.doors.event; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.malisis.doors.door.DoorState; +import net.malisis.doors.door.block.BigDoor; +import net.malisis.doors.door.block.CollisionHelperBlock; +import net.malisis.doors.door.tileentity.CollisionHelperTileEntity; +import net.malisis.doors.door.tileentity.DoorTileEntity; +import net.malisis.doors.renderer.CustomDoorBoundingBoxRenderer; +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import net.minecraftforge.client.event.DrawBlockHighlightEvent; + +public class DoorEventHandler { + + public CustomDoorBoundingBoxRenderer cdbbRenderer = new CustomDoorBoundingBoxRenderer(); + @SubscribeEvent + public void onDrawBlockHighlight(DrawBlockHighlightEvent event) { + World world = event.player.worldObj; + MovingObjectPosition target = event.target; + + if (target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + int x = target.blockX; + int y = target.blockY; + int z = target.blockZ; + Block block = world.getBlock(x, y, z); + + if (block instanceof CollisionHelperBlock) + { + CollisionHelperTileEntity cTE = ((CollisionHelperTileEntity) world.getTileEntity(x, y, z)); + TileEntity mainDoorTE = cTE.getMainBlockTile(); + if (mainDoorTE instanceof DoorTileEntity) + { + DoorState state = ((DoorTileEntity) mainDoorTE).getState(); + if (state == DoorState.OPENED || state == DoorState.OPENING || state == DoorState.CLOSING) + { + event.setCanceled(true); + cdbbRenderer.renderOpenDoorBoundingBox(world, (CollisionHelperBlock) block, event.player, event.partialTicks, target); + } + } + } + } + } +} diff --git a/src/main/java/net/malisis/doors/renderer/CustomDoorBoundingBoxRenderer.java b/src/main/java/net/malisis/doors/renderer/CustomDoorBoundingBoxRenderer.java new file mode 100644 index 0000000..1dedfdf --- /dev/null +++ b/src/main/java/net/malisis/doors/renderer/CustomDoorBoundingBoxRenderer.java @@ -0,0 +1,103 @@ +package net.malisis.doors.renderer; + +import net.malisis.core.block.BoundingBoxType; +import net.malisis.core.util.ComplexAxisAlignedBoundingBox; +import net.malisis.doors.door.block.BigDoor; +import net.malisis.doors.door.block.CollisionHelperBlock; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.opengl.GL11; + +import static net.minecraft.client.renderer.RenderGlobal.drawOutlinedBoundingBox; + +public class CustomDoorBoundingBoxRenderer +{ + public void renderOpenDoorBoundingBox(World world, CollisionHelperBlock block, EntityPlayer player, float partialTicks, MovingObjectPosition target) + { + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F); + GL11.glLineWidth(2.0F); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDepthMask(false); + float f1 = 0.002F; + + block.setBlockBoundsBasedOnState(world, target.blockX, target.blockY, target.blockZ); + double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks; + double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks; + double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks; + + ComplexAxisAlignedBoundingBox CAABB = block.getComplexBoundingBox(world, target.blockX, target.blockY, target.blockZ); + + CAABB.addOffset(-d0, -d1, -d2); + + renderComplexAABB(CAABB, -1); + + GL11.glDepthMask(true); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_BLEND); + } + + public static void renderComplexAABB(ComplexAxisAlignedBoundingBox CAABB, int color) + { + Tessellator tessellator = Tessellator.instance; + if (color != -1) + { + tessellator.setColorOpaque_I(color); + } + renderHorizontalFaces(CAABB.flatSurfaces, tessellator); + renderVerticals(CAABB.verticals, tessellator); + } + + private static void renderVerticals(Pair[] lines, Tessellator tessellator) + { + tessellator.startDrawing(1); + for (Pair line : lines) + { + tessellator.addVertex(line.getRight().xCoord, line.getRight().yCoord, line.getRight().zCoord); + tessellator.addVertex(line.getLeft().xCoord, line.getLeft().yCoord, line.getLeft().zCoord); + } + tessellator.draw(); + } + + private static void renderHorizontalFaces(Vec3[][] faces, Tessellator tessellator) + { + for(Vec3[] face : faces) + { + tessellator.startDrawing(3); + for (Vec3 vertex : face) + { + tessellator.addVertex(vertex.xCoord,vertex.yCoord,vertex.zCoord); + } + tessellator.addVertex(face[0].xCoord, face[0].yCoord, face[0].zCoord); + tessellator.draw(); + } + } + + public static void drawOutlineBoundingBoxWithMultipleBoxes(AxisAlignedBB AABB, int color) + { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawing(3); + + if (color != -1) + { + tessellator.setColorOpaque_I(color); + } + + tessellator.addVertex(AABB.minX, AABB.minY, AABB.minZ); + tessellator.addVertex(AABB.maxX, AABB.minY, AABB.minZ); + tessellator.addVertex(AABB.maxX, AABB.minY, AABB.maxZ); + tessellator.addVertex(AABB.minX, AABB.minY, AABB.maxZ); + tessellator.addVertex(AABB.minX, AABB.minY, AABB.minZ); + tessellator.draw(); + } +} From bca70ac5298b29172eb176fcc2cf4be660fa9616 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Wed, 4 Sep 2024 00:28:08 -0500 Subject: [PATCH 03/14] Lot more working. Just need to now do the open door collision blocks and the open door block removal. --- .../malisis/core/client/gui/GuiRenderer.java | 15 +-- .../core/renderer/MalisisRenderer.java | 67 ++++++----- .../java/net/malisis/doors/MalisisDoors.java | 1 - .../java/net/malisis/doors/Registers.java | 4 +- .../net/malisis/doors/door/block/BigDoor.java | 107 ++++++++++++++++-- .../door/block/CollisionHelperBlock.java | 103 +++++++++++++---- .../door/tileentity/BigDoorTileEntity.java | 78 ++++++++++--- .../doors/door/tileentity/DoorTileEntity.java | 4 + .../{IMultiDoor.java => IMultiBlock.java} | 2 +- .../door/tileentity/MultiCollisionTile.java | 10 -- ...onHelperTileEntity.java => MultiTile.java} | 62 ++++++++-- .../malisis/doors/event/DoorEventHandler.java | 82 +++++++++++--- .../doors/network/FrameUpdateMessage.java | 80 +++++++++++++ 13 files changed, 488 insertions(+), 127 deletions(-) rename src/main/java/net/malisis/doors/door/tileentity/{IMultiDoor.java => IMultiBlock.java} (95%) delete mode 100644 src/main/java/net/malisis/doors/door/tileentity/MultiCollisionTile.java rename src/main/java/net/malisis/doors/door/tileentity/{CollisionHelperTileEntity.java => MultiTile.java} (61%) create mode 100644 src/main/java/net/malisis/doors/network/FrameUpdateMessage.java diff --git a/src/main/java/net/malisis/core/client/gui/GuiRenderer.java b/src/main/java/net/malisis/core/client/gui/GuiRenderer.java index 0ec1b5b..1cf3a3d 100644 --- a/src/main/java/net/malisis/core/client/gui/GuiRenderer.java +++ b/src/main/java/net/malisis/core/client/gui/GuiRenderer.java @@ -29,6 +29,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; @@ -294,9 +295,9 @@ public void drawRectangle(float x, float y, float z, float width, float height, */ public void drawTooltip(UITooltip tooltip) { if (tooltip != null) { - t.startDrawingQuads(); + this.tessellator.startDrawingQuads(); tooltip.draw(this, mouseX, mouseY, partialTick); - t.draw(); + this.tessellator.draw(); } } @@ -445,7 +446,7 @@ public void drawItemStack(ItemStack itemStack, int x, int y, String label, EnumC if (label == null) label = ""; if (format != null) label = format + label; - t.draw(); + this.tessellator.draw(); RenderHelper.enableGUIStandardItemLighting(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); @@ -471,7 +472,7 @@ public void drawItemStack(ItemStack itemStack, int x, int y, String label, EnumC currentTexture = null; bindDefaultTexture(); - t.startDrawingQuads(); + this.tessellator.startDrawingQuads(); } /** @@ -481,9 +482,9 @@ public void drawItemStack(ItemStack itemStack, int x, int y, String label, EnumC */ public void renderPickedItemStack(ItemStack itemStack) { if (itemStack == null) return; - + this.tessellator = Tessellator.instance; itemRenderer.zLevel = 100; - t.startDrawingQuads(); + this.tessellator.startDrawingQuads(); drawItemStack( itemStack, mouseX - 8, @@ -491,7 +492,7 @@ public void renderPickedItemStack(ItemStack itemStack) { null, itemStack.stackSize == 0 ? EnumChatFormatting.YELLOW : null, false); - t.draw(); + this.tessellator.draw(); itemRenderer.zLevel = 0; } diff --git a/src/main/java/net/malisis/core/renderer/MalisisRenderer.java b/src/main/java/net/malisis/core/renderer/MalisisRenderer.java index df6d82e..78c7381 100644 --- a/src/main/java/net/malisis/core/renderer/MalisisRenderer.java +++ b/src/main/java/net/malisis/core/renderer/MalisisRenderer.java @@ -25,6 +25,7 @@ import net.malisis.core.renderer.font.FontRenderOptions; import net.malisis.core.renderer.font.MalisisFont; import net.malisis.core.renderer.icon.MalisisIcon; +import net.malisis.doors.door.tileentity.DoorTileEntity; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; @@ -78,7 +79,7 @@ public class MalisisRenderer extends TileEntitySpecialRenderer /** Id of this {@link MalisisRenderer}. */ protected int renderId = -1; /** Tessellator reference. */ - protected Tessellator t = Tessellator.instance; + protected Tessellator tessellator = Tessellator.instance; /** Current world reference (ISBRH/TESR/IRWL). */ protected IBlockAccess world; /** RenderBlocks reference (ISBRH). */ @@ -131,7 +132,6 @@ public class MalisisRenderer extends TileEntitySpecialRenderer */ public MalisisRenderer() { this.renderId = RenderingRegistry.getNextAvailableRenderId(); - this.t = Tessellator.instance; } /** @@ -264,6 +264,7 @@ public void set(ItemRenderType type, ItemStack itemStack) { */ @Override public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { + this.tessellator = Tessellator.instance; set(block, metadata); renderBlocks = renderer; prepare(RenderType.ISBRH_INVENTORY); @@ -286,6 +287,7 @@ public void renderInventoryBlock(Block block, int metadata, int modelId, RenderB @Override public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { + this.tessellator = Tessellator.instance; set(world, block, x, y, z, world.getBlockMetadata(x, y, z)); tileEntity = world.getTileEntity(x, y, z); renderBlocks = renderer; @@ -347,6 +349,7 @@ public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRe */ @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + this.tessellator = Tessellator.instance; set(type, item); prepare(RenderType.ITEM_INVENTORY); render(); @@ -367,26 +370,30 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) { */ @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick) { - set(te, partialTick); - prepare(RenderType.TESR_WORLD, x, y, z); - render(); - if (getBlockDamage) { - destroyBlockProgress = getBlockDestroyProgress(); - if (destroyBlockProgress != null) { - next(); - - GL11.glEnable(GL11.GL_BLEND); - OpenGlHelper.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_SRC_COLOR, GL11.GL_ONE, GL11.GL_ZERO); - GL11.glAlphaFunc(GL11.GL_GREATER, 0); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F); - - t.disableColor(); - renderDestroyProgress(); - next(); - GL11.glDisable(GL11.GL_BLEND); + if (te instanceof DoorTileEntity && ((DoorTileEntity) te).shouldRender()) { + this.tessellator = Tessellator.instance; + set(te, partialTick); + prepare(RenderType.TESR_WORLD, x, y, z); + render(); + if (getBlockDamage) { + destroyBlockProgress = getBlockDestroyProgress(); + if (destroyBlockProgress != null) { + + next(); + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_SRC_COLOR, GL11.GL_ONE, GL11.GL_ZERO); + GL11.glAlphaFunc(GL11.GL_GREATER, 0); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F); + + this.tessellator.disableColor(); + renderDestroyProgress(); + next(); + GL11.glDisable(GL11.GL_BLEND); + } } + clean(); } - clean(); } // #end TESR @@ -404,6 +411,7 @@ public boolean shouldRender(RenderWorldLastEvent event, IBlockAccess world) { @Override public void renderWorldLastEvent(RenderWorldLastEvent event, IBlockAccess world) { + this.tessellator = Tessellator.instance; set(world); partialTick = event.partialTicks; renderGlobal = event.context; @@ -486,7 +494,7 @@ public void startDrawing() { */ public void startDrawing(int drawMode) { if (isDrawing()) draw(); - t.startDrawing(drawMode); + this.tessellator.startDrawing(drawMode); this.drawMode = drawMode; } @@ -520,7 +528,7 @@ public void next(int drawMode) { * Triggers a draw. */ public void draw() { - if (isDrawing()) t.draw(); + if (isDrawing()) this.tessellator.draw(); } /** @@ -554,7 +562,7 @@ public void tessellatorShift() { if (isShifted) return; isShifted = true; - t.addTranslation(x, y, z); + this.tessellator.addTranslation(x, y, z); } /** @@ -564,7 +572,7 @@ public void tessellatorUnshift() { if (!isShifted) return; isShifted = false; - t.addTranslation(-x, -y, -z); + this.tessellator.addTranslation(-x, -y, -z); } /** @@ -656,6 +664,7 @@ public void render() { public void renderDestroyProgress() { if (destroyBlockProgress != null) overrideTexture = damagedIcons[destroyBlockProgress.getPartialBlockDamage()]; // enableBlending(); + this.tessellator = Tessellator.instance; render(); } @@ -731,7 +740,7 @@ protected void drawFace(Face f, RenderParameters faceParams) { // use normals if available if ((renderType == RenderType.ITEM_INVENTORY || renderType == RenderType.ISBRH_INVENTORY || params.useNormals.get()) && params.direction.get() != null) - t.setNormal(params.direction.get().offsetX, params.direction.get().offsetY, params.direction.get().offsetZ); + this.tessellator.setNormal(params.direction.get().offsetX, params.direction.get().offsetY, params.direction.get().offsetZ); baseBrightness = getBaseBrightness(); @@ -772,12 +781,12 @@ protected void drawVertex(Vertex vertex, int number) { // alpha if (!params.usePerVertexAlpha.get()) vertex.setAlpha(params.alpha.get()); - t.setColorRGBA_I(vertex.getColor(), vertex.getAlpha()); - t.setBrightness(vertex.getBrightness()); + this.tessellator.setColorRGBA_I(vertex.getColor(), vertex.getAlpha()); + this.tessellator.setBrightness(vertex.getBrightness()); if (params.useTexture.get()) - t.addVertexWithUV(vertex.getX(), vertex.getY(), vertex.getZ(), vertex.getU(), vertex.getV()); - else t.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); + this.tessellator.addVertexWithUV(vertex.getX(), vertex.getY(), vertex.getZ(), vertex.getU(), vertex.getV()); + else this.tessellator.addVertex(vertex.getX(), vertex.getY(), vertex.getZ()); vertexDrawn = true; } diff --git a/src/main/java/net/malisis/doors/MalisisDoors.java b/src/main/java/net/malisis/doors/MalisisDoors.java index b3a709c..370eb07 100644 --- a/src/main/java/net/malisis/doors/MalisisDoors.java +++ b/src/main/java/net/malisis/doors/MalisisDoors.java @@ -92,7 +92,6 @@ public void preInit(FMLPreInitializationEvent event) { proxy.initRenderers(); } - @SideOnly(Side.CLIENT) @EventHandler public void init(FMLInitializationEvent event) { diff --git a/src/main/java/net/malisis/doors/Registers.java b/src/main/java/net/malisis/doors/Registers.java index 4e6ea83..096b7d7 100644 --- a/src/main/java/net/malisis/doors/Registers.java +++ b/src/main/java/net/malisis/doors/Registers.java @@ -47,11 +47,11 @@ import net.malisis.doors.door.item.DoorItem; import net.malisis.doors.door.item.ForcefieldItem; import net.malisis.doors.door.tileentity.BigDoorTileEntity; -import net.malisis.doors.door.tileentity.CollisionHelperTileEntity; import net.malisis.doors.door.tileentity.CustomDoorTileEntity; import net.malisis.doors.door.tileentity.DoorTileEntity; import net.malisis.doors.door.tileentity.FenceGateTileEntity; import net.malisis.doors.door.tileentity.ForcefieldTileEntity; +import net.malisis.doors.door.tileentity.MultiTile; import net.malisis.doors.door.tileentity.RustyHatchTileEntity; import net.malisis.doors.door.tileentity.SaloonDoorTileEntity; import net.malisis.doors.entity.BlockMixerTileEntity; @@ -474,7 +474,7 @@ private static void registerCollisionHelperBlocks() GameRegistry.registerBlock(collisionHelperBlock, collisionHelperBlock.getUnlocalizedName() .substring(5)); - GameRegistry.registerTileEntity(CollisionHelperTileEntity.class, "collisionHelperTileEntity"); + GameRegistry.registerTileEntity(MultiTile.class, "collisionHelperTileEntity"); } diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index 1533bad..aeb809b 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -25,21 +25,27 @@ import net.malisis.doors.MalisisDoors; import net.malisis.doors.MalisisDoors.Items; import net.malisis.doors.door.tileentity.BigDoorTileEntity; +import net.malisis.doors.door.tileentity.IMultiBlock; +import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import org.apache.commons.lang3.tuple.Pair; +import static net.minecraft.util.MathHelper.abs; import static net.minecraft.util.Vec3.createVectorHelper; /** @@ -83,6 +89,8 @@ private Type(String name, Item door) { Pair.of(createVectorHelper(4,4,1 - Door.DOOR_WIDTH), createVectorHelper(4, 5, 1 - Door.DOOR_WIDTH)) }; + private final int DoorBlockWidth = 4; + private final int DoorBlockHeight = 5; public static int renderId; public static int renderPass = -1; private AxisAlignedBB defaultBoundingBox = AxisAlignedBB.getBoundingBox(0, 0, 1 - Door.DOOR_WIDTH, 4, 5, 1); @@ -119,8 +127,8 @@ public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side) { } @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) { - ForgeDirection dir = EntityUtils.getEntityFacing(player); + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase livingEntity, ItemStack itemStack) { + ForgeDirection dir = EntityUtils.getEntityFacing(livingEntity); int metadata = Door.dirToInt(dir); world.setBlockMetadataWithNotify(x, y, z, metadata, 2); @@ -132,22 +140,101 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase p { te.onCreate(x, y, z, metadata); } + else + { + world.setBlockToAir(x, y, z); + if (!world.isRemote && livingEntity instanceof EntityPlayerMP player) { + player.addChatMessage( + new ChatComponentText("There's no room for the door!")); + if (!player.capabilities.isCreativeMode) { + final ItemStack doorBlock = new ItemStack(this, 1, 0); + final EntityItem entityitem = player.dropPlayerItemWithRandomChoice(doorBlock, false); + entityitem.delayBeforeCanPickup = 0; + entityitem.func_145797_a(player.getCommandSenderName()); + } + } + } } } - private boolean checkAreaClearForDoor(World world, int x, int y, int z, int metadata) + private boolean checkAreaClearForDoor(World world, int x, int y, int z, int meta) { - return true; + boolean validSpot = true; + boolean widthDirectionFlag = meta % 2 == 0; + int xStep = meta == 3 ? -1 : 1; + int zStep = meta == 0 ? -1 : 1; + int xMax = widthDirectionFlag ? 1 : 4; + int zMax = widthDirectionFlag ? 4 : 1; + + for (int yLoc = 0; yLoc < 5; yLoc++) + { + for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) + { + for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) + { + if (!(yLoc == 0 && zLoc == 0 && xLoc == 0)) + { + final Block potentialSpot = world.getBlock(x + xLoc, y + yLoc, z + zLoc); + if (!potentialSpot.getMaterial().isReplaceable()) + { + validSpot = false; + } + } + } + } + } + return validSpot; + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block block, int meta) + { + int fakeBlockCount = 0; + + final int buildHeight = world.getHeight() - 6; // No reason to have the door right at world height + + if (y > buildHeight) + { + return; + } + + boolean widthDirectionFlag = meta % 2 == 0; + int xStep = meta == 3 ? -1 : 1; + int zStep = meta == 0 ? -1 : 1; + int xMax = widthDirectionFlag ? 1 : 4; + int zMax = widthDirectionFlag ? 4 : 1; + + for (int yLoc = 0; yLoc < 5; yLoc++) + { + for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) + { + for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) + { + if (!(yLoc == 0 && zLoc == 0 && xLoc == 0)) + { + if (world.getBlock(x + xLoc, y + yLoc, z + zLoc) == MalisisDoors.Blocks.collisionHelperBlock) + { + fakeBlockCount++; + } + } + } + } + } + + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (fakeBlockCount >= 18 && tileEntity instanceof IMultiBlock) + { + ((IMultiBlock) tileEntity).onDestroy(tileEntity); + } + super.breakBlock(world, x, y, z, block, meta); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (world.isRemote) return true; - BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); if (te == null) return true; - te.openOrCloseDoor(); return true; } @@ -224,10 +311,10 @@ public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, i return super.removedByPlayer(world, player, x, y, z); } - @Override - public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { - return new ArrayList(); - } +// @Override +// public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { +// return new ArrayList(); +// } @Override public boolean isOpaqueCube() { diff --git a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java index 5c8418f..18d5e02 100644 --- a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java +++ b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java @@ -6,17 +6,21 @@ import net.malisis.core.util.ComplexAxisAlignedBoundingBox; import net.malisis.doors.MalisisDoors; import net.malisis.doors.door.tileentity.BigDoorTileEntity; -import net.malisis.doors.door.tileentity.CollisionHelperTileEntity; +import net.malisis.doors.door.tileentity.MultiTile; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; +import net.minecraft.client.particle.EffectRenderer; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -30,6 +34,8 @@ public class CollisionHelperBlock extends BlockContainer implements ITileEntityP BigDoor.Type type; + private IIcon[] fakeIcons; + // This class serves at the invisible collision blocks to help BigDoor with collisions public CollisionHelperBlock(BigDoor.Type type) { super(Material.wood); @@ -40,6 +46,25 @@ public CollisionHelperBlock(BigDoor.Type type) { this.setBlockName(type.name + "_collisionHelper"); } + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister register) { + this.fakeIcons = new IIcon[2]; + this.fakeIcons[0] = register.registerIcon(MalisisDoors.modid + ":" + BigDoor.Type.CARRIAGE); + this.fakeIcons[1] = register.registerIcon(MalisisDoors.modid + ":" + BigDoor.Type.MEDIEVAL); + + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) { + return switch (meta) { + case 0 -> this.fakeIcons[0]; + case 1 -> this.fakeIcons[1]; + default -> this.fakeIcons[0]; + }; + } + @Override public boolean canDropFromExplosion(Explosion par1Explosion) { return false; @@ -59,15 +84,15 @@ public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side) { public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer EntityPlayer, int par6, float subx, float suby, float subz) { - final CollisionHelperTileEntity tileEntity = ((CollisionHelperTileEntity) world.getTileEntity(x, y, z)); + final MultiTile tileEntity = ((MultiTile) world.getTileEntity(x, y, z)); return tileEntity.onBlockActivated(world, x, y, z, EntityPlayer); } @Override public void breakBlock(World world, int x, int y, int z, Block block, int meta) { final TileEntity tileEntity = world.getTileEntity(x, y, z); - if (tileEntity instanceof CollisionHelperTileEntity) { - ((CollisionHelperTileEntity) tileEntity).onBlockRemoval(); + if (tileEntity instanceof MultiTile) { + ((MultiTile) tileEntity).onBlockRemoval(); } super.breakBlock(world, x, y, z, block, meta); } @@ -110,7 +135,7 @@ public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, @Override public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); - CollisionHelperTileEntity thisTE = ((CollisionHelperTileEntity) world.getTileEntity(x,y,z)); + MultiTile thisTE = ((MultiTile) world.getTileEntity(x,y,z)); Block mainBlock = world.getBlock(thisTE.mainBlockX, thisTE.mainBlockY, thisTE.mainBlockZ); if (mainBlock instanceof BigDoor) { @@ -122,47 +147,42 @@ public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, i public ComplexAxisAlignedBoundingBox getComplexBoundingBox(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); - CollisionHelperTileEntity TE = getTileEntity(world, x, y, z); + MultiTile TE = getTileEntity(world, x, y, z); BigDoor mainBlock = getMainBlock(world, x, y, z); return mainBlock.getComplexBoundingBoxWithOffset(world, TE.mainBlockX, TE.mainBlockY, TE.mainBlockZ, BoundingBoxType.SELECTION); } public BigDoor getMainBlock(World world, int x, int y, int z) { - CollisionHelperTileEntity cTE = this.getTileEntity(world, x, y, z); + MultiTile cTE = this.getTileEntity(world, x, y, z); return (BigDoor) world.getBlock(cTE.mainBlockX, cTE.mainBlockY, cTE.mainBlockZ); } public BigDoorTileEntity getMainTileEntity(World world, int x, int y, int z) { - CollisionHelperTileEntity cTE = this.getTileEntity(world, x, y, z); + MultiTile cTE = this.getTileEntity(world, x, y, z); return (BigDoorTileEntity) world.getTileEntity(cTE.mainBlockX, cTE.mainBlockY, cTE.mainBlockZ); } - public CollisionHelperTileEntity getTileEntity(World world, int x, int y, int z) + public MultiTile getTileEntity(World world, int x, int y, int z) { - return (CollisionHelperTileEntity) world.getTileEntity(x,y,z); + return (MultiTile) world.getTileEntity(x,y,z); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { - return new CollisionHelperTileEntity(); + return new MultiTile(); } @Override public float getBlockHardness(World world, int x, int y, int z) { final TileEntity tileEntity = world.getTileEntity(x, y, z); - - if (tileEntity instanceof CollisionHelperTileEntity) { - final int mainX = ((CollisionHelperTileEntity) tileEntity).mainBlockX; - final int mainY = ((CollisionHelperTileEntity) tileEntity).mainBlockY; - final int mainZ = ((CollisionHelperTileEntity) tileEntity).mainBlockZ; - - if (world.getTileEntity(x,y,z) != null) { - return world.getBlock(mainX, mainY, mainZ).getBlockHardness(world, mainX, mainY, mainZ); - } + if (tileEntity instanceof MultiTile) { + final int mainX = ((MultiTile) tileEntity).mainBlockX; + final int mainY = ((MultiTile) tileEntity).mainBlockY; + final int mainZ = ((MultiTile) tileEntity).mainBlockZ; + return world.getBlock(mainX, mainY, mainZ).getBlockHardness(world, mainX, mainY, mainZ); } - return this.blockHardness; } @@ -194,6 +214,45 @@ public boolean shouldSideBeRendered(IBlockAccess worldIn, int x, int y, int z, i public void makeCollisionHelperBlock(World world, int x, int y, int z, int xMain, int yMain, int zMain, int meta) { world.setBlock(x, y, z, this, meta, 3); - ((CollisionHelperTileEntity) world.getTileEntity(x, y, z)).setMainBlock(xMain, yMain, zMain); + ((MultiTile) world.getTileEntity(x, y, z)).setMainBlock(xMain, yMain, zMain); + } + + @SuppressWarnings("deprecation") + @Override + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) + { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof MultiTile multiTileEntity) + { + if (multiTileEntity.mainBlockSet) + { + final Block mainBlock = world.getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ); + if (Blocks.air != mainBlock) + { + return mainBlock.getPickBlock(target, world, multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ); + } + } + } + + return null; + } + + @SideOnly(Side.CLIENT) + @Override + public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) + { + final TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof MultiTile multiTileEntity) + { + if (multiTileEntity.mainBlockSet) + { + final Block mainBlock = world.getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ); + if (Blocks.air != mainBlock) + { + return world.getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ).addDestroyEffects(world, x, y, z, meta, effectRenderer); + } + } + } + return super.addDestroyEffects(world, x, y, z, meta, effectRenderer); } } diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index fbbd4e0..5a220eb 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -17,7 +17,6 @@ import net.malisis.core.block.BoundingBoxType; import net.malisis.core.util.BlockState; import net.malisis.core.util.MultiBlock; -import net.malisis.core.util.TileEntityUtils; import net.malisis.doors.MalisisDoors; import net.malisis.doors.door.DoorDescriptor; import net.malisis.doors.door.DoorRegistry; @@ -27,10 +26,14 @@ import net.malisis.doors.door.block.Door; import net.malisis.doors.door.movement.CarriageDoorMovement; import net.malisis.doors.door.sound.CarriageDoorSound; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; @@ -43,13 +46,13 @@ * @author Ordinastie * */ -public class BigDoorTileEntity extends DoorTileEntity implements IMultiDoor { +public class BigDoorTileEntity extends MultiTile implements IMultiBlock { private boolean delete = false; private boolean processed = true; private ForgeDirection direction = ForgeDirection.NORTH; - - private BlockState frameState; + private final Block defaultBorderBlock = Blocks.stonebrick; + private BlockState frameState = new BlockState(defaultBorderBlock); public BigDoorTileEntity() { DoorDescriptor descriptor = new DoorDescriptor(); @@ -58,8 +61,6 @@ public BigDoorTileEntity() { descriptor.setDoubleDoor(false); descriptor.setOpeningTime(20); setDescriptor(descriptor); - - frameState = new BlockState(Blocks.quartz_block); } public BlockState getFrameState() { @@ -68,6 +69,13 @@ public BlockState getFrameState() { public void setFrameState(BlockState state) { if (state != null) frameState = state; + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + + @Override + public void setFrameState (Block block) + { + this.setFrameState(new BlockState(block)); } @Override @@ -87,12 +95,6 @@ public boolean isPowered() { @Override public void setDoorState(DoorState newState) { - boolean moving = this.moving; - BlockState state = null; - if (getWorldObj() != null) { - state = new BlockState(xCoord, yCoord, zCoord, getBlockType()); - } - super.setDoorState(newState); } @@ -130,13 +132,12 @@ public void readFromNBT(NBTTagCompound tag) { processed = false; } - frameState = Objects.firstNonNull(BlockState.fromNBT(tag), new BlockState(Blocks.quartz_block)); + frameState = Objects.firstNonNull(BlockState.fromNBT(tag), new BlockState(defaultBorderBlock)); } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - BlockState.toNBT(nbt, frameState); } @@ -149,9 +150,7 @@ public AxisAlignedBB getRenderBoundingBox() { @Override public boolean onActivated(EntityPlayer entityPlayer) { - if (this.worldObj.isRemote) return true; - this.openOrCloseDoor(); return true; } @@ -198,6 +197,53 @@ public void onCreate(int x, int y, int z, int meta) { @Override public void onDestroy(TileEntity callingBlock) { + int meta = this.getBlockMetadata(); + boolean widthDirectionFlag = meta % 2 == 0; + + if (meta < 4) { + + + int xStep = meta == 3 ? -1 : 1; + int zStep = meta == 0 ? -1 : 1; + + int xMax = widthDirectionFlag ? 1 : 4; + int zMax = widthDirectionFlag ? 4 : 1; + + for (int yLoc = 0; yLoc < 5; yLoc++) { + for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) { + for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) { + if (xLoc == 0 && yLoc == 0 && zLoc == 0) { + ((MultiTile) callingBlock).dropMainBlockAtLocation(); + } + this.worldObj.setBlockToAir(xLoc + this.xCoord, yLoc + this.yCoord, zLoc + this.zCoord); + } + } + } + } + else + { + // Need to remove blocks if we're in the open state. + } + } + + @Override + public boolean shouldRender() + { + return true; + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbtTag = new NBTTagCompound(); + this.writeToNBT(nbtTag); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); + } + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) + { + super.onDataPacket(net, pkt); + NBTTagCompound packetData = pkt.func_148857_g(); + this.setFrameState(BlockState.fromNBT(packetData)); } } diff --git a/src/main/java/net/malisis/doors/door/tileentity/DoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/DoorTileEntity.java index 5e93714..e982443 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/DoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/DoorTileEntity.java @@ -111,6 +111,10 @@ public boolean isReversed() { return (getBlockMetadata() & Door.FLAG_REVERSED) != 0; } + public boolean shouldRender() + { + return true; + } public boolean isPowered() { return getWorldObj().isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) || getWorldObj().isBlockIndirectlyGettingPowered(xCoord, yCoord + 1, zCoord); diff --git a/src/main/java/net/malisis/doors/door/tileentity/IMultiDoor.java b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java similarity index 95% rename from src/main/java/net/malisis/doors/door/tileentity/IMultiDoor.java rename to src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java index b5b550f..2999002 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IMultiDoor.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java @@ -3,7 +3,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; -public interface IMultiDoor { +public interface IMultiBlock { /** * Called when activated diff --git a/src/main/java/net/malisis/doors/door/tileentity/MultiCollisionTile.java b/src/main/java/net/malisis/doors/door/tileentity/MultiCollisionTile.java deleted file mode 100644 index 5d9c91f..0000000 --- a/src/main/java/net/malisis/doors/door/tileentity/MultiCollisionTile.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.malisis.doors.door.tileentity; - - -import net.minecraft.tileentity.TileEntity; - -public class MultiCollisionTile extends TileEntity { - public int mainBlockX; - public int mainBlockY; - public int mainBlockZ; -} diff --git a/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java similarity index 61% rename from src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java rename to src/main/java/net/malisis/doors/door/tileentity/MultiTile.java index fa38ba6..6b292ae 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/CollisionHelperTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java @@ -1,5 +1,8 @@ package net.malisis.doors.door.tileentity; + +import net.malisis.core.util.BlockState; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; @@ -8,13 +11,18 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -public class CollisionHelperTileEntity extends MultiCollisionTile -{ +public class MultiTile extends DoorTileEntity { + public int mainBlockX; + public int mainBlockY; + public int mainBlockZ; + public boolean mainBlockSet; + public void setMainBlock(int x, int y, int z) { this.mainBlockX = x; this.mainBlockY = y; this.mainBlockZ = z; + this.mainBlockSet = true; this.markDirty(); if (!this.worldObj.isRemote) { @@ -27,22 +35,18 @@ public void onBlockRemoval() TileEntity mainBlock = getMainBlockTile(); if (mainBlock != null) { - if (mainBlock instanceof IMultiDoor) + if (mainBlock instanceof IMultiBlock) { - ((IMultiDoor) mainBlock).onDestroy(this); + ((IMultiBlock) mainBlock).onDestroy(this); } } } - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer) { + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player) { world.markBlockForUpdate(x, y, z); TileEntity mainBlock = getMainBlockTile(); - if (mainBlock != null) { - final TileEntity tileEntity = this.worldObj - .getTileEntity(this.mainBlockX, this.mainBlockY, this.mainBlockZ); - if (tileEntity instanceof IMultiDoor) { - return ((IMultiDoor) tileEntity).onActivated(par5EntityPlayer); - } + if (mainBlock instanceof IMultiBlock) { + return ((IMultiBlock) mainBlock).onActivated(player); } return true; } @@ -62,6 +66,7 @@ public Packet getDescriptionPacket() { @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + super.onDataPacket(net, pkt); NBTTagCompound packetData = pkt.func_148857_g(); this.mainBlockX = packetData.getInteger("mainBlockX"); this.mainBlockY = packetData.getInteger("mainBlockY"); @@ -83,4 +88,39 @@ public void readFromNBT(NBTTagCompound nbt) { this.mainBlockY = nbt.getInteger("mainBlockY"); this.mainBlockZ = nbt.getInteger("mainBlockZ"); } + + @Override + public boolean shouldRender() + { + return false; + } + + public void setFrameState(Block block) + { + TileEntity mainTile = this.getMainBlockTile(); + if (mainTile instanceof BigDoorTileEntity bigDoorMainTile) + { + bigDoorMainTile.setFrameState(block); + } + } + + public void setFrameState(BlockState blockState) + { + TileEntity mainTile = this.getMainBlockTile(); + if (mainTile instanceof BigDoorTileEntity bigDoorTileEntity) + { + bigDoorTileEntity.setFrameState(blockState); + } + } + + public void dropMainBlockAtLocation() + { + if (mainBlockSet) + { + Block block = this.worldObj.getBlock(mainBlockX, mainBlockY, mainBlockZ); + int meta = this.getBlockMetadata(); + block.dropBlockAsItem(this.worldObj, xCoord, yCoord, zCoord, meta, 0); + } + + } } diff --git a/src/main/java/net/malisis/doors/event/DoorEventHandler.java b/src/main/java/net/malisis/doors/event/DoorEventHandler.java index 6a788a7..6d9fc76 100644 --- a/src/main/java/net/malisis/doors/event/DoorEventHandler.java +++ b/src/main/java/net/malisis/doors/event/DoorEventHandler.java @@ -2,45 +2,91 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.malisis.doors.door.DoorState; -import net.malisis.doors.door.block.BigDoor; import net.malisis.doors.door.block.CollisionHelperBlock; -import net.malisis.doors.door.tileentity.CollisionHelperTileEntity; import net.malisis.doors.door.tileentity.DoorTileEntity; +import net.malisis.doors.door.tileentity.MultiTile; +import net.malisis.doors.network.FrameUpdateMessage; import net.malisis.doors.renderer.CustomDoorBoundingBoxRenderer; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.client.event.DrawBlockHighlightEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import org.lwjgl.input.Keyboard; public class DoorEventHandler { public CustomDoorBoundingBoxRenderer cdbbRenderer = new CustomDoorBoundingBoxRenderer(); + @SubscribeEvent public void onDrawBlockHighlight(DrawBlockHighlightEvent event) { World world = event.player.worldObj; - MovingObjectPosition target = event.target; + if (world.isRemote) { + MovingObjectPosition target = event.target; + + if (target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + int x = target.blockX; + int y = target.blockY; + int z = target.blockZ; + Block block = world.getBlock(x, y, z); - if (target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { - int x = target.blockX; - int y = target.blockY; - int z = target.blockZ; - Block block = world.getBlock(x, y, z); + if (block instanceof CollisionHelperBlock) { + MultiTile cTE = ((MultiTile) world.getTileEntity(x, y, z)); + TileEntity mainDoorTE = cTE.getMainBlockTile(); + if (mainDoorTE instanceof DoorTileEntity) { + DoorState state = ((DoorTileEntity) mainDoorTE).getState(); + if (state == DoorState.OPENED || state == DoorState.OPENING || state == DoorState.CLOSING) { + event.setCanceled(true); + cdbbRenderer.renderOpenDoorBoundingBox(world, (CollisionHelperBlock) block, event.player, event.partialTicks, target); + } + } + } + } + } + } - if (block instanceof CollisionHelperBlock) + @SubscribeEvent + public void PlayerInteractEvent(PlayerInteractEvent event) + { + TileEntity tileEntity = getTileEntityLookingAt(event.entityPlayer); + if (event.entityPlayer.isSneaking() && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && tileEntity instanceof MultiTile multiTile && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) + { + ItemStack heldStack = event.entityPlayer.getHeldItem(); + if (heldStack != null) { - CollisionHelperTileEntity cTE = ((CollisionHelperTileEntity) world.getTileEntity(x, y, z)); - TileEntity mainDoorTE = cTE.getMainBlockTile(); - if (mainDoorTE instanceof DoorTileEntity) + Block block = Block.getBlockFromItem(heldStack.getItem()); + int damageValue = heldStack.getItemDamage(); + if (block != null) { - DoorState state = ((DoorTileEntity) mainDoorTE).getState(); - if (state == DoorState.OPENED || state == DoorState.OPENING || state == DoorState.CLOSING) - { - event.setCanceled(true); - cdbbRenderer.renderOpenDoorBoundingBox(world, (CollisionHelperBlock) block, event.player, event.partialTicks, target); - } + event.setCanceled(true); + FrameUpdateMessage.SendFrameUpdateMessage(multiTile, block, damageValue); } } } } + + private TileEntity getTileEntityLookingAt(EntityPlayer player) { + Minecraft mc = Minecraft.getMinecraft(); + double maxReach = mc.playerController.getBlockReachDistance(); + Vec3 eyePosition = player.getPosition(1.0F); + Vec3 lookVector = player.getLook(1.0F); + Vec3 endPosition = eyePosition.addVector( + lookVector.xCoord * maxReach, + lookVector.yCoord * maxReach, + lookVector.zCoord * maxReach + ); + MovingObjectPosition rayTraceResult = mc.theWorld.rayTraceBlocks(eyePosition, endPosition); + if (rayTraceResult != null && rayTraceResult.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + int blockX = rayTraceResult.blockX; + int blockY = rayTraceResult.blockY; + int blockZ = rayTraceResult.blockZ; + return mc.theWorld.getTileEntity(blockX, blockY, blockZ); + } + return null; + } } diff --git a/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java b/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java new file mode 100644 index 0000000..14049e6 --- /dev/null +++ b/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java @@ -0,0 +1,80 @@ +package net.malisis.doors.network; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.Side; +import io.netty.buffer.ByteBuf; +import net.malisis.core.network.MalisisMessage; +import net.malisis.core.util.BlockState; +import net.malisis.doors.MalisisDoors; +import net.malisis.doors.door.tileentity.MultiTile; +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import java.awt.*; + +@MalisisMessage +public class FrameUpdateMessage implements IMessageHandler { + + public FrameUpdateMessage() { + MalisisDoors.network.registerMessage(this, FrameUpdateMessage.Packet.class, Side.SERVER); + } + + @Override + public IMessage onMessage(FrameUpdateMessage.Packet message, MessageContext ctx) { + World world = ctx.getServerHandler().playerEntity.worldObj; + TileEntity tileEntity = world.getTileEntity(message.blockX, message.blockY, message.blockZ); + BlockState blockState = new BlockState(message.blockX, message.blockY, message.blockZ, message.block, message.blockDamage); + if (tileEntity instanceof MultiTile bigDoorTE) + { + bigDoorTE.setFrameState(blockState); + } + return null; + } + + public static void SendFrameUpdateMessage(TileEntity te, Block block, int damage) + { + FrameUpdateMessage.Packet packet = new FrameUpdateMessage.Packet(block, te.xCoord, te.yCoord, te.zCoord, damage); + MalisisDoors.network.sendToServer(packet); + } + + public static class Packet implements IMessage { + + private int blockX; + private int blockY; + private int blockZ; + private Block block; + private int blockDamage; + + public Packet() {} + public Packet(Block block, int x, int y, int z, int damage) + { + this.block = block; + this.blockX = x; + this.blockY = y; + this.blockZ = z; + this.blockDamage = damage; + } + @Override + public void fromBytes(ByteBuf buf) + { + this.blockX = buf.readInt(); + this.blockY = buf.readInt(); + this.blockZ = buf.readInt(); + this.block = Block.getBlockById(buf.readInt()); + this.blockDamage = buf.readInt(); + } + + @Override + public void toBytes(ByteBuf buf) + { + buf.writeInt(this.blockX); + buf.writeInt(this.blockY); + buf.writeInt(this.blockZ); + buf.writeInt(Block.getIdFromBlock(this.block)); + buf.writeInt(this.blockDamage); + } + } +} From 88325e839f0bf290a58f7a6cf5f2485520d7318b Mon Sep 17 00:00:00 2001 From: rjnasers Date: Sun, 8 Sep 2024 00:40:08 -0500 Subject: [PATCH 04/14] Lots of shit done --- .../net/malisis/doors/door/block/BigDoor.java | 6 +- .../door/block/CollisionHelperBlock.java | 51 +++-- .../doors/door/multiBlock/MultiBlueprint.java | 153 ++++++++++++++ .../doors/door/tests/MultiBlueprintTest.java | 23 +++ .../door/tileentity/BigDoorTileEntity.java | 187 ++++++++++++++---- .../doors/door/tileentity/IBluePrint.java | 9 + .../doors/door/tileentity/IMultiBlock.java | 2 + .../doors/door/tileentity/MultiTile.java | 5 +- 8 files changed, 382 insertions(+), 54 deletions(-) create mode 100644 src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java create mode 100644 src/main/java/net/malisis/doors/door/tests/MultiBlueprintTest.java create mode 100644 src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index aeb809b..6408347 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -285,6 +285,7 @@ public ComplexAxisAlignedBoundingBox getComplexBoundingBoxWithOffset(IBlockAcces ComplexAxisAlignedBoundingBox CAABB = new ComplexAxisAlignedBoundingBox(clonedFlatSurfaces, clonedVerticals); CAABB.rotate(Door.intToDir(te.getDirection()) ,ComplexAxisAlignedBoundingBox.Axis.Y); + // Offset needed post-rotation switch (Door.intToDir(te.getDirection())) { case EAST -> CAABB.addOffset(x + 1, y, z); case NORTH -> CAABB.addOffset(x, y, z); @@ -311,11 +312,6 @@ public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, i return super.removedByPlayer(world, player, x, y, z); } -// @Override -// public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { -// return new ArrayList(); -// } - @Override public boolean isOpaqueCube() { return false; diff --git a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java index 18d5e02..003318e 100644 --- a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java +++ b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java @@ -101,21 +101,44 @@ public void breakBlock(World world, int x, int y, int z, Block block, int meta) public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { final int meta = world.getBlockMetadata(x, y, z); - if (meta == 0) + switch (meta) { - this.setBlockBounds(1.0F - Door.DOOR_WIDTH, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); - } - if (meta == 1) - { - this.setBlockBounds(0.0F, 0.0F, 1.0F - Door.DOOR_WIDTH, 1.0F, 1.0F, 1.0F); - } - if (meta == 2) - { - this.setBlockBounds(0.0F, 0.0F, 0.0F, Door.DOOR_WIDTH, 1.0F, 1.0F); - } - if (meta == 3) - { - this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, Door.DOOR_WIDTH); + case 0: // 3 Pixels wide on the east side of the block + this.setBlockBounds(1.0F - Door.DOOR_WIDTH, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + break; + case 1: // 3 Pixels wide on the south side of the block + this.setBlockBounds(0.0F, 0.0F, 1.0F - Door.DOOR_WIDTH, 1.0F, 1.0F, 1.0F); + break; + case 2: // 3 Pixels wide on the west side of the block + this.setBlockBounds(0.0F, 0.0F, 0.0F, Door.DOOR_WIDTH, 1.0F, 1.0F); + break; + case 3: // 3 Pixels wide on the north side of the block + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, Door.DOOR_WIDTH); + break; + case 4: // 8 Pixels wide on the east side of the block + this.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + break; + case 5: // 8 Pixels wide on the south side of the block + this.setBlockBounds(0.0F, 0.0F, 0.5F, 1.0F, 1.0F, 1.0F); + break; + case 6: // 8 Pixels wide on the west side of the block + this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F); + break; + case 7: // 8 Pixels wide on the north side of the block + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F); + break; + case 8: // Quarter of a block on north-west corner of the block + this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 0.5F); + break; + case 9: // Quarter of a block on north-east corner of the block + this.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F); + break; + case 10: // Quarter of a block on south-east corner of the block + this.setBlockBounds(0.5F, 0.0F, 0.5F, 1.0F, 1.0F, 1.0F); + break; + case 11: // Quarter of a block on the south-west corner of the block + this.setBlockBounds(0.0F, 0.0F, 0.5F, 0.5F, 1.0F, 1.0F); + break; } } diff --git a/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java b/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java new file mode 100644 index 0000000..2acd04d --- /dev/null +++ b/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java @@ -0,0 +1,153 @@ +package net.malisis.doors.door.multiBlock; + +import org.joml.Vector3i; + +import java.util.Map; + +public class MultiBlueprint +{ + + public enum RotationDegrees + { + ROT90, + ROT180, + ROT270, + } + + public final static int MB = Integer.MAX_VALUE; // Main Block + public final static int EMPTY = -1; + public final static int RM = Integer.MIN_VALUE; // Shouldn't ever be used for a state that can get placed. Only for + // blocks that need to be removed on state change. + + public int[][][] bluePrint; + public Vector3i startingLocation; + public int yLength; + public int xLength; + public int zLength; + private Map metaMap; + + public MultiBlueprint(int[][][] print, Map metaMap, Vector3i startingLocation) + { + this.yLength = print.length; + this.xLength = print[0].length; + this.zLength = print[0][0].length; + this.bluePrint = print; + this.metaMap = metaMap; + this.startingLocation = startingLocation; + } + + public void rotate(RotationDegrees angle) + { + int[][][] rotatedPrint = new int[bluePrint.length][bluePrint.length][bluePrint.length]; + switch (angle) + { + case ROT90 -> { + for (int i = 0; i < bluePrint.length; i++) { + rotatedPrint[i] = rotate90Clockwise(bluePrint[i]); + } + } + case ROT180 -> { + for (int i = 0; i < bluePrint.length; i++) { + rotatedPrint[i] = rotate180Clockwise(bluePrint[i]); + } + } + case ROT270 -> { + for (int i = 0; i < bluePrint.length; i++) { + rotatedPrint[i] = rotate270Clockwise(bluePrint[i]); + + } + } + } + convertMeta(rotatedPrint, angle); + this.bluePrint = rotatedPrint; + } + + private int[][] rotate90Clockwise(int[][] matrix) + { + return transpose(reverseColumns(matrix)); + } + + private int[][] rotate180Clockwise(int[][] matrix) + { + return reverseColumns(reverseRows(matrix)); + } + + private int[][] rotate270Clockwise(int[][] matrix) + { + return transpose(reverseRows(matrix)); + } + + private void convertMeta(int[][][] mat, RotationDegrees angle) + { + int conversionInfo = angle.ordinal(); + for (int i = 0; i < mat.length; i++) + { + for (int j = 0; j < mat[i].length; j++) + { + for (int k = 0; k < mat[i][j].length; k++) { + int[] newState = metaMap.get(mat[i][j][k]); + if (newState == null) { + if (mat[i][j][k] == MB) + { + this.startingLocation = new Vector3i(j,i,k); + } + } else { + mat[i][j][k] = newState[conversionInfo]; + } + } + } + } + } + + private int[][] transpose(int[][] matrix) { + int rows = matrix.length; + int cols = matrix[0].length; + int[][] transposed = new int[cols][rows]; + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + transposed[j][i] = matrix[i][j]; + } + } + return transposed; + } + + private int[][] reverseColumns(int[][] matrix) + { + return multiplyMatrices(generateRowReversalMatrix(matrix.length), matrix); + } + + private int[][] reverseRows(int[][] matrix) + { + return multiplyMatrices(matrix, generateRowReversalMatrix(matrix[0].length)); + } + + private int[][] generateRowReversalMatrix(int size) { + int[][] matrix = new int[size][size]; + for (int i = 0; i < size; i++) { + matrix[i][size - 1 - i] = 1; + } + return matrix; + } + + private int[][] multiplyMatrices(int[][] A, int[][] B) { + int rowsA = A.length; + int rowsB = B.length; + int colsA = A[0].length; + int colsB = B[0].length; + + if (colsA != rowsB) { + throw new IllegalArgumentException("Number of columns in Matrix A must be equal to number of rows in Matrix B."); + } + + int[][] result = new int[rowsA][colsB]; + for (int i = 0; i < rowsA; i++) { + for (int j = 0; j < colsB; j++) { + result[i][j] = 0; + for (int k = 0; k < colsA; k++) { + result[i][j] += A[i][k] * B[k][j]; + } + } + } + return result; + } +} diff --git a/src/main/java/net/malisis/doors/door/tests/MultiBlueprintTest.java b/src/main/java/net/malisis/doors/door/tests/MultiBlueprintTest.java new file mode 100644 index 0000000..74d6bc0 --- /dev/null +++ b/src/main/java/net/malisis/doors/door/tests/MultiBlueprintTest.java @@ -0,0 +1,23 @@ +//package net.malisis.doors.door.tests; +// +// +//import net.malisis.doors.door.multiBlock.MultiBlueprint; +// +//public class MultiBlueprintTest { +// +// private MultiBlueprint blueprint; +// +// @BeforeEach +// public void setUp() {// Set up before each test +// } +// +// @Test +// public void testAddition() { +// +// } +// +// @Test +// public void testSubtraction() { +// +// } +//} diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index 5a220eb..631bb4b 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -21,6 +21,7 @@ import net.malisis.doors.door.DoorDescriptor; import net.malisis.doors.door.DoorRegistry; import net.malisis.doors.door.DoorState; +import net.malisis.doors.door.multiBlock.MultiBlueprint; import net.malisis.doors.door.block.BigDoor; import net.malisis.doors.door.block.CollisionHelperBlock; import net.malisis.doors.door.block.Door; @@ -36,23 +37,99 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import com.google.common.base.Objects; +import org.joml.Vector3i; +import java.util.HashMap; +import java.util.Map; + +import static net.malisis.doors.door.multiBlock.MultiBlueprint.MB; +import static net.malisis.doors.door.multiBlock.MultiBlueprint.RM; import static net.minecraft.util.MathHelper.abs; /** * @author Ordinastie * */ -public class BigDoorTileEntity extends MultiTile implements IMultiBlock { +public class BigDoorTileEntity extends MultiTile implements IMultiBlock, IBluePrint { private boolean delete = false; private boolean processed = true; private ForgeDirection direction = ForgeDirection.NORTH; private final Block defaultBorderBlock = Blocks.stonebrick; private BlockState frameState = new BlockState(defaultBorderBlock); + private Boolean changingState = false; + private final int[][][] openPrint = + { + { + {10, -1, -1, 9}, + {MB, RM, RM, 7}, + }, + { + {10, -1, -1, 9}, + { 5, RM, RM, 7}, + }, + { + {10, -1, -1, 9}, + { 5, RM, RM, 7}, + }, + { + {10, -1, -1, 9}, + { 5, RM, RM, 7}, + }, + { + {-1, -1, -1, -1}, + { 0, 0, 0, 0}, + } + }; + + private final int[][][] closedPrint = + { + { + {RM, -1, -1, RM}, + {MB, 0, 0, 0}, + }, + { + {RM, -1, -1, RM}, + { 0, 0, 0, 0}, + }, + { + {RM, -1, -1, RM}, + { 0, 0, 0, 0}, + }, + { + {RM, -1, -1, RM}, + { 0, 0, 0, 0}, + }, + { + {RM, -1, -1, RM}, + { 0, 0, 0, 0}, + } + }; + + + + // This map defines how to choose the next meta based on a rotation. + Map metaMap = new HashMap<>() {{ + put(0, new int[]{1, 2, 3}); + put(1, new int[]{2, 3, 0}); + put(2, new int[]{3, 0, 1}); + put(3, new int[]{0, 1, 2}); + put(4, new int[]{5, 6, 7}); + put(5, new int[]{6, 7, 4}); + put(6, new int[]{7, 4, 5}); + put(7, new int[]{4, 5, 6}); + put(8, new int[]{9, 10, 11}); + put(9, new int[]{10, 11, 8}); + put(10, new int[]{ 11, 8, 9}); + put(11, new int[]{8, 9, 10}); + }}; + + private final MultiBlueprint closedBlueprint = new MultiBlueprint(closedPrint, metaMap, new Vector3i(1,0,0)); + private final MultiBlueprint openBlueprint = new MultiBlueprint(openPrint, metaMap, new Vector3i(1, 0, 0)); public BigDoorTileEntity() { DoorDescriptor descriptor = new DoorDescriptor(); @@ -150,8 +227,11 @@ public AxisAlignedBB getRenderBoundingBox() { @Override public boolean onActivated(EntityPlayer entityPlayer) { - if (this.worldObj.isRemote) return true; - this.openOrCloseDoor(); + if (!this.worldObj.isRemote) + { + this.openOrCloseDoor(); + } + this.onStateChange(); return true; } @@ -160,38 +240,10 @@ public void onCreate(int x, int y, int z, int meta) { this.markDirty(); final int buildHeight = this.worldObj.getHeight() - 6; // No reason to have the door right at world height - if (y > buildHeight) - { + if (y > buildHeight) { return; } - - // 4 states based on the meta of the main - // meta 0: going South to North on the East side of the block - facing west - // meta 1: going West to East on the South side of the block - facing north - // meta 2: going North to South on the West side of the block - facing east - // meta 3: going East to West on the North side of the block - facing south - - boolean widthDirectionFlag = meta % 2 == 0; - - int xStep = meta == 3 ? -1 : 1; - int zStep = meta == 0 ? -1 : 1; - - int xMax = widthDirectionFlag ? 1 : 4; - int zMax = widthDirectionFlag ? 4 : 1; - - for (int yLoc = 0; yLoc < 5; yLoc++) - { - for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) - { - for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) - { - if (!(yLoc == 0 && zLoc == 0 && xLoc == 0)) - { - ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlock).makeCollisionHelperBlock(this.worldObj, x + xLoc, y + yLoc, z + zLoc, x, y, z, meta); - } - } - } - } + placeBluePrint(this.worldObj, x, y, z, meta, false); } @Override @@ -202,7 +254,6 @@ public void onDestroy(TileEntity callingBlock) if (meta < 4) { - int xStep = meta == 3 ? -1 : 1; int zStep = meta == 0 ? -1 : 1; @@ -226,6 +277,18 @@ public void onDestroy(TileEntity callingBlock) } } + @Override + public boolean isChangingState() { + return this.changingState; + } + + public void onStateChange() + { + this.changingState = true; + int meta = this.getBlockMetadata(); + placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, (meta + 4) % 8, true); + changingState = false; + } @Override public boolean shouldRender() { @@ -246,4 +309,60 @@ public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) NBTTagCompound packetData = pkt.func_148857_g(); this.setFrameState(BlockState.fromNBT(packetData)); } + + @Override + public void placeBluePrint(World world, int x, int y, int z, int meta, boolean removeBlockInWay) + { + MultiBlueprint print = (meta < 4 ? this.closedBlueprint : this.openBlueprint); + switch (meta) + { + case 0, 4: + this.bluePrintPlacerHelper(world, x, y, z, print, removeBlockInWay); + break; + case 1, 5: + print.rotate(MultiBlueprint.RotationDegrees.ROT90); + this.bluePrintPlacerHelper(world, x, y, z, print, removeBlockInWay); + print.rotate(MultiBlueprint.RotationDegrees.ROT270); + break; + case 2, 6: + print.rotate(MultiBlueprint.RotationDegrees.ROT180); + this.bluePrintPlacerHelper(world, x, y, z, print, removeBlockInWay); + print.rotate(MultiBlueprint.RotationDegrees.ROT180); + break; + case 3, 7: + print.rotate(MultiBlueprint.RotationDegrees.ROT270); + this.bluePrintPlacerHelper(world, x, y, z, print, removeBlockInWay); + print.rotate(MultiBlueprint.RotationDegrees.ROT90); + break; + } + } + + private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBlueprint print, boolean removeBlockInWay) + { + int mainBlockRelativeX = print.startingLocation.x; + int mainBlockRelativeY = print.startingLocation.y; + int mainBlockRelativeZ = print.startingLocation.z; + for (int j = 0; j < print.bluePrint.length; j++) // y + { + for (int i = 0; i < print.bluePrint[0].length; i++) // x + { + for (int k = 0; k < print.bluePrint[0][0].length; k++) // z + { + if (!(i == print.startingLocation.x && j == print.startingLocation.y && k == print.startingLocation.z) && print.bluePrint[j][i][k] > -1) + { + ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlock).makeCollisionHelperBlock(world, x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, z + mainBlockRelativeZ - k, this.xCoord, this.yCoord, this.zCoord, print.bluePrint[j][i][k]); + } + else if(print.bluePrint[j][i][k] == Integer.MIN_VALUE && removeBlockInWay) + { + world.setBlockToAir(x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, z + mainBlockRelativeZ - k); + } + } + } + } + } + + @Override + public void removeBluePrint(World world, int x, int y, int z, int meta) { + return; + } } diff --git a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java new file mode 100644 index 0000000..b0c5184 --- /dev/null +++ b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java @@ -0,0 +1,9 @@ +package net.malisis.doors.door.tileentity; + +import net.minecraft.world.World; + +public interface IBluePrint +{ + public void placeBluePrint(World world, int x, int y, int z, int meta, boolean removeBlockInWay); + public void removeBluePrint(World world, int x, int y, int z, int meta); +} diff --git a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java index 2999002..76f3c02 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java @@ -26,4 +26,6 @@ public interface IMultiBlock { * @param callingBlock - The tile entity who called the onDestroy function */ void onDestroy(TileEntity callingBlock); + + boolean isChangingState(); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java index 6b292ae..c8b6cac 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java +++ b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java @@ -37,7 +37,10 @@ public void onBlockRemoval() { if (mainBlock instanceof IMultiBlock) { - ((IMultiBlock) mainBlock).onDestroy(this); + if (!(((IMultiBlock) mainBlock).isChangingState())) + { + ((IMultiBlock) mainBlock).onDestroy(this); + } } } } From 185241b136d00ca984c3e563dad883a332963788 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Mon, 9 Sep 2024 09:39:36 -0500 Subject: [PATCH 05/14] Need to figure out what the hell is going on with meta data on world load --- .../net/malisis/doors/door/block/BigDoor.java | 31 +---- .../doors/door/multiBlock/MultiBlueprint.java | 3 +- .../door/tileentity/BigDoorTileEntity.java | 111 ++++++++++++------ .../doors/door/tileentity/IBluePrint.java | 3 +- .../doors/door/tileentity/IMultiBlock.java | 1 - .../doors/door/tileentity/MultiTile.java | 11 +- 6 files changed, 84 insertions(+), 76 deletions(-) diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index 6408347..6279e0c 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -189,40 +189,13 @@ private boolean checkAreaClearForDoor(World world, int x, int y, int z, int meta @Override public void breakBlock(World world, int x, int y, int z, Block block, int meta) { - int fakeBlockCount = 0; - final int buildHeight = world.getHeight() - 6; // No reason to have the door right at world height - if (y > buildHeight) { return; } - - boolean widthDirectionFlag = meta % 2 == 0; - int xStep = meta == 3 ? -1 : 1; - int zStep = meta == 0 ? -1 : 1; - int xMax = widthDirectionFlag ? 1 : 4; - int zMax = widthDirectionFlag ? 4 : 1; - - for (int yLoc = 0; yLoc < 5; yLoc++) - { - for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) - { - for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) - { - if (!(yLoc == 0 && zLoc == 0 && xLoc == 0)) - { - if (world.getBlock(x + xLoc, y + yLoc, z + zLoc) == MalisisDoors.Blocks.collisionHelperBlock) - { - fakeBlockCount++; - } - } - } - } - } - TileEntity tileEntity = world.getTileEntity(x, y, z); - if (fakeBlockCount >= 18 && tileEntity instanceof IMultiBlock) + if (tileEntity instanceof IMultiBlock) { ((IMultiBlock) tileEntity).onDestroy(tileEntity); } @@ -235,7 +208,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p if (world.isRemote) return true; BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); if (te == null) return true; - te.openOrCloseDoor(); + te.onBlockActivated(world, x, y, z, player); return true; } diff --git a/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java b/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java index 2acd04d..a6e1931 100644 --- a/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java +++ b/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java @@ -16,8 +16,7 @@ public enum RotationDegrees public final static int MB = Integer.MAX_VALUE; // Main Block public final static int EMPTY = -1; - public final static int RM = Integer.MIN_VALUE; // Shouldn't ever be used for a state that can get placed. Only for - // blocks that need to be removed on state change. + public final static int RM = Integer.MIN_VALUE; public int[][][] bluePrint; public Vector3i startingLocation; diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index 631bb4b..aab12b4 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -173,6 +173,10 @@ public boolean isPowered() { @Override public void setDoorState(DoorState newState) { super.setDoorState(newState); + if (!this.worldObj.isRemote) + { + this.onStateChange(newState); + } } @Override @@ -231,7 +235,6 @@ public boolean onActivated(EntityPlayer entityPlayer) { { this.openOrCloseDoor(); } - this.onStateChange(); return true; } @@ -243,52 +246,43 @@ public void onCreate(int x, int y, int z, int meta) { if (y > buildHeight) { return; } + this.setMainBlock(x,y,z); + this.mainBlockSet = true; placeBluePrint(this.worldObj, x, y, z, meta, false); + } @Override public void onDestroy(TileEntity callingBlock) { - int meta = this.getBlockMetadata(); - boolean widthDirectionFlag = meta % 2 == 0; - - if (meta < 4) { - - int xStep = meta == 3 ? -1 : 1; - int zStep = meta == 0 ? -1 : 1; - - int xMax = widthDirectionFlag ? 1 : 4; - int zMax = widthDirectionFlag ? 4 : 1; - - for (int yLoc = 0; yLoc < 5; yLoc++) { - for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) { - for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) { - if (xLoc == 0 && yLoc == 0 && zLoc == 0) { - ((MultiTile) callingBlock).dropMainBlockAtLocation(); - } - this.worldObj.setBlockToAir(xLoc + this.xCoord, yLoc + this.yCoord, zLoc + this.zCoord); - } - } - } - } - else + if (!this.changingState) { - // Need to remove blocks if we're in the open state. + this.changingState = true; + removeBluePrint(this.worldObj, xCoord, yCoord, zCoord, getBlockMetadata(), callingBlock); + this.changingState = false; } } - @Override - public boolean isChangingState() { - return this.changingState; - } - - public void onStateChange() + // This method is a little complex because unless the door is fully closed I want players to be able to go through + // the door. + public void onStateChange(DoorState newState) { - this.changingState = true; int meta = this.getBlockMetadata(); - placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, (meta + 4) % 8, true); - changingState = false; + if (newState == DoorState.OPENING && meta < 4) + { + this.changingState = true; + placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, (meta + 4) % 8, true); + this.changingState = false; + } + else if (newState == DoorState.CLOSED) + { + this.changingState = true; + placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, meta, true); + this.changingState = false; + } } + + @Override public boolean shouldRender() { @@ -362,7 +356,52 @@ else if(print.bluePrint[j][i][k] == Integer.MIN_VALUE && removeBlockInWay) } @Override - public void removeBluePrint(World world, int x, int y, int z, int meta) { - return; + public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock) { + MultiBlueprint print = (meta < 4 ? this.closedBlueprint : this.openBlueprint); + switch (meta) + { + case 0, 4: + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); + break; + case 1, 5: + print.rotate(MultiBlueprint.RotationDegrees.ROT90); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); + print.rotate(MultiBlueprint.RotationDegrees.ROT270); + break; + case 2, 6: + print.rotate(MultiBlueprint.RotationDegrees.ROT180); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); + print.rotate(MultiBlueprint.RotationDegrees.ROT180); + break; + case 3, 7: + print.rotate(MultiBlueprint.RotationDegrees.ROT270); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); + print.rotate(MultiBlueprint.RotationDegrees.ROT90); + break; + } + } + + private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, TileEntity callingBlock) + { + int mainBlockRelativeX = print.startingLocation.x; + int mainBlockRelativeY = print.startingLocation.y; + int mainBlockRelativeZ = print.startingLocation.z; + for (int j = 0; j < print.bluePrint.length; j++) // y + { + for (int i = 0; i < print.bluePrint[0].length; i++) // x + { + for (int k = 0; k < print.bluePrint[0][0].length; k++) // z + { + if (print.bluePrint[j][i][k] == MB) + { + ((MultiTile) callingBlock).dropMainBlockAtLocation(this.getBlockType()); + } + if (print.bluePrint[j][i][k] > -1) + { + world.setBlockToAir(x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, z + mainBlockRelativeZ - k); + } + } + } + } } } diff --git a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java index b0c5184..5d5847c 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java @@ -1,9 +1,10 @@ package net.malisis.doors.door.tileentity; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public interface IBluePrint { public void placeBluePrint(World world, int x, int y, int z, int meta, boolean removeBlockInWay); - public void removeBluePrint(World world, int x, int y, int z, int meta); + public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java index 76f3c02..4459339 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java @@ -27,5 +27,4 @@ public interface IMultiBlock { */ void onDestroy(TileEntity callingBlock); - boolean isChangingState(); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java index c8b6cac..56c4b77 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java +++ b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java @@ -37,10 +37,7 @@ public void onBlockRemoval() { if (mainBlock instanceof IMultiBlock) { - if (!(((IMultiBlock) mainBlock).isChangingState())) - { - ((IMultiBlock) mainBlock).onDestroy(this); - } + ((IMultiBlock) mainBlock).onDestroy(this); } } } @@ -82,6 +79,7 @@ public void writeToNBT(NBTTagCompound nbt) { nbt.setInteger("mainBlockX", this.mainBlockX); nbt.setInteger("mainBlockY", this.mainBlockY); nbt.setInteger("mainBlockZ", this.mainBlockZ); + nbt.setBoolean("mainBlockSet", this.mainBlockSet); } @Override @@ -90,6 +88,7 @@ public void readFromNBT(NBTTagCompound nbt) { this.mainBlockX = nbt.getInteger("mainBlockX"); this.mainBlockY = nbt.getInteger("mainBlockY"); this.mainBlockZ = nbt.getInteger("mainBlockZ"); + this.mainBlockSet = nbt.getBoolean("mainBlockSet"); } @Override @@ -116,14 +115,12 @@ public void setFrameState(BlockState blockState) } } - public void dropMainBlockAtLocation() + public void dropMainBlockAtLocation(Block block) { if (mainBlockSet) { - Block block = this.worldObj.getBlock(mainBlockX, mainBlockY, mainBlockZ); int meta = this.getBlockMetadata(); block.dropBlockAsItem(this.worldObj, xCoord, yCoord, zCoord, meta, 0); } - } } From 54747c8c5befd983a04b020e17fa52171225a545 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Mon, 9 Sep 2024 17:58:26 -0500 Subject: [PATCH 06/14] Should be pretty much working now --- gradle.properties | 13 ++++++- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 2 +- .../net/malisis/doors/door/block/BigDoor.java | 2 +- .../door/block/CollisionHelperBlock.java | 8 +++-- .../door/tileentity/BigDoorTileEntity.java | 36 +++++++++++-------- .../doors/door/tileentity/IBluePrint.java | 3 +- .../doors/door/tileentity/IMultiBlock.java | 3 +- .../doors/door/tileentity/MultiTile.java | 13 +++++-- 9 files changed, 56 insertions(+), 26 deletions(-) diff --git a/gradle.properties b/gradle.properties index 96153bb..e077b8c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -85,6 +85,11 @@ accessTransformersFile = malisisdoors_at.cfg # Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled! usesMixins = false +# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main. +# This can speed up compile times thanks to not running the mixin annotation processor on all input sources. +# Mixin classes will have access to "main" classes, but not the other way around. +separateMixinSourceSet = + # Adds some debug arguments like verbose output and class export. usesMixinDebug = false @@ -117,9 +122,15 @@ minimizeShadowedDependencies = true # If disabled, won't rename the shadowed classes. relocateShadowedDependencies = true -# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories. +# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories. includeWellKnownRepositories = true +# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated +# list of strings, with the acceptable keys being(case does not matter): +# cursemaven +# modrinth +excludeWellKnownRepositories = + # Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven. # Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables. # If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a80b22c..09523c0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle index c52d518..242692e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.19' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.26' } diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index 6279e0c..2a2864a 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -197,7 +197,7 @@ public void breakBlock(World world, int x, int y, int z, Block block, int meta) TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity instanceof IMultiBlock) { - ((IMultiBlock) tileEntity).onDestroy(tileEntity); + ((IMultiBlock) tileEntity).onDestroy(block, tileEntity, meta); } super.breakBlock(world, x, y, z, block, meta); } diff --git a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java index 003318e..20d58ca 100644 --- a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java +++ b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java @@ -92,7 +92,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer E public void breakBlock(World world, int x, int y, int z, Block block, int meta) { final TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity instanceof MultiTile) { - ((MultiTile) tileEntity).onBlockRemoval(); + ((MultiTile) tileEntity).onBlockRemoval(type == BigDoor.Type.MEDIEVAL ? MalisisDoors.Blocks.medievalDoor : MalisisDoors.Blocks.carriageDoor); } super.breakBlock(world, x, y, z, block, meta); } @@ -234,10 +234,12 @@ public boolean shouldSideBeRendered(IBlockAccess worldIn, int x, int y, int z, i return false; } - public void makeCollisionHelperBlock(World world, int x, int y, int z, int xMain, int yMain, int zMain, int meta) + public void makeCollisionHelperBlock(World world, int x, int y, int z, int meta, int xMain, int yMain, int zMain, int metaMain) { world.setBlock(x, y, z, this, meta, 3); - ((MultiTile) world.getTileEntity(x, y, z)).setMainBlock(xMain, yMain, zMain); + MultiTile tile = (MultiTile) world.getTileEntity(x, y, z); + tile.setMainBlock(xMain, yMain, zMain); + tile.setMainBlockMeta(metaMain); } @SuppressWarnings("deprecation") diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index aab12b4..5f16778 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -173,10 +173,10 @@ public boolean isPowered() { @Override public void setDoorState(DoorState newState) { super.setDoorState(newState); - if (!this.worldObj.isRemote) - { - this.onStateChange(newState); - } +// if (!this.worldObj.isRemote) +// { + this.onStateChange(newState); +// } } @Override @@ -253,12 +253,17 @@ public void onCreate(int x, int y, int z, int meta) { } @Override - public void onDestroy(TileEntity callingBlock) + public void onDestroy(Block blockToDrop, TileEntity callingBlock, int meta) { if (!this.changingState) { + int metaToUse = meta; + if (this.state == DoorState.OPENING && metaToUse < 4) + { + metaToUse += 4; + } this.changingState = true; - removeBluePrint(this.worldObj, xCoord, yCoord, zCoord, getBlockMetadata(), callingBlock); + removeBluePrint(this.worldObj, xCoord, yCoord, zCoord, metaToUse, callingBlock, blockToDrop); this.changingState = false; } } @@ -267,7 +272,8 @@ public void onDestroy(TileEntity callingBlock) // the door. public void onStateChange(DoorState newState) { - int meta = this.getBlockMetadata(); + if (this.state == newState) return; + int meta = this.mainBlockMeta; if (newState == DoorState.OPENING && meta < 4) { this.changingState = true; @@ -344,7 +350,7 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr { if (!(i == print.startingLocation.x && j == print.startingLocation.y && k == print.startingLocation.z) && print.bluePrint[j][i][k] > -1) { - ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlock).makeCollisionHelperBlock(world, x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, z + mainBlockRelativeZ - k, this.xCoord, this.yCoord, this.zCoord, print.bluePrint[j][i][k]); + ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlock).makeCollisionHelperBlock(world, x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, z + mainBlockRelativeZ - k, print.bluePrint[j][i][k] , this.xCoord, this.yCoord, this.zCoord, this.getBlockMetadata()); } else if(print.bluePrint[j][i][k] == Integer.MIN_VALUE && removeBlockInWay) { @@ -356,32 +362,32 @@ else if(print.bluePrint[j][i][k] == Integer.MIN_VALUE && removeBlockInWay) } @Override - public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock) { + public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock, Block blockToDrop) { MultiBlueprint print = (meta < 4 ? this.closedBlueprint : this.openBlueprint); switch (meta) { case 0, 4: - this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); break; case 1, 5: print.rotate(MultiBlueprint.RotationDegrees.ROT90); - this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); print.rotate(MultiBlueprint.RotationDegrees.ROT270); break; case 2, 6: print.rotate(MultiBlueprint.RotationDegrees.ROT180); - this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); print.rotate(MultiBlueprint.RotationDegrees.ROT180); break; case 3, 7: print.rotate(MultiBlueprint.RotationDegrees.ROT270); - this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); print.rotate(MultiBlueprint.RotationDegrees.ROT90); break; } } - private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, TileEntity callingBlock) + private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, TileEntity callingBlock, Block blockToDrop) { int mainBlockRelativeX = print.startingLocation.x; int mainBlockRelativeY = print.startingLocation.y; @@ -394,7 +400,7 @@ private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBluep { if (print.bluePrint[j][i][k] == MB) { - ((MultiTile) callingBlock).dropMainBlockAtLocation(this.getBlockType()); + ((MultiTile) callingBlock).dropMainBlockAtLocation(blockToDrop); } if (print.bluePrint[j][i][k] > -1) { diff --git a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java index 5d5847c..3c07784 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java @@ -1,10 +1,11 @@ package net.malisis.doors.door.tileentity; +import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public interface IBluePrint { public void placeBluePrint(World world, int x, int y, int z, int meta, boolean removeBlockInWay); - public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock); + public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock, Block blockToDrop); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java index 4459339..e84d230 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java @@ -1,5 +1,6 @@ package net.malisis.doors.door.tileentity; +import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; @@ -25,6 +26,6 @@ public interface IMultiBlock { * * @param callingBlock - The tile entity who called the onDestroy function */ - void onDestroy(TileEntity callingBlock); + void onDestroy(Block block, TileEntity callingBlock, int meta); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java index 56c4b77..d29846c 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java +++ b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java @@ -15,6 +15,7 @@ public class MultiTile extends DoorTileEntity { public int mainBlockX; public int mainBlockY; public int mainBlockZ; + public int mainBlockMeta; public boolean mainBlockSet; public void setMainBlock(int x, int y, int z) @@ -30,14 +31,14 @@ public void setMainBlock(int x, int y, int z) } } - public void onBlockRemoval() + public void onBlockRemoval(Block block) { TileEntity mainBlock = getMainBlockTile(); if (mainBlock != null) { if (mainBlock instanceof IMultiBlock) { - ((IMultiBlock) mainBlock).onDestroy(this); + ((IMultiBlock) mainBlock).onDestroy(block, this, this.mainBlockMeta); } } } @@ -79,7 +80,9 @@ public void writeToNBT(NBTTagCompound nbt) { nbt.setInteger("mainBlockX", this.mainBlockX); nbt.setInteger("mainBlockY", this.mainBlockY); nbt.setInteger("mainBlockZ", this.mainBlockZ); + nbt.setInteger("mainBlockMeta", this.mainBlockMeta); nbt.setBoolean("mainBlockSet", this.mainBlockSet); + } @Override @@ -88,6 +91,7 @@ public void readFromNBT(NBTTagCompound nbt) { this.mainBlockX = nbt.getInteger("mainBlockX"); this.mainBlockY = nbt.getInteger("mainBlockY"); this.mainBlockZ = nbt.getInteger("mainBlockZ"); + this.mainBlockMeta = nbt.getInteger("mainBlockMeta"); this.mainBlockSet = nbt.getBoolean("mainBlockSet"); } @@ -123,4 +127,9 @@ public void dropMainBlockAtLocation(Block block) block.dropBlockAsItem(this.worldObj, xCoord, yCoord, zCoord, meta, 0); } } + + public void setMainBlockMeta(int meta) + { + this.mainBlockMeta = meta; + } } From d7ffffbd11404327fb5a150d7a870de76a4faa32 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Mon, 9 Sep 2024 18:12:49 -0500 Subject: [PATCH 07/14] Spotless --- .../net/malisis/core/block/MalisisBlock.java | 3 +- .../core/renderer/MalisisRenderer.java | 5 +- .../util/ComplexAxisAlignedBoundingBox.java | 33 ++- .../java/net/malisis/doors/MalisisDoors.java | 10 +- .../java/net/malisis/doors/Registers.java | 10 +- .../net/malisis/doors/door/block/BigDoor.java | 120 ++++++----- .../door/block/CollisionHelperBlock.java | 100 ++++----- .../doors/door/multiBlock/MultiBlueprint.java | 51 ++--- .../doors/door/tests/MultiBlueprintTest.java | 28 +-- .../door/tileentity/BigDoorTileEntity.java | 196 +++++++----------- .../doors/door/tileentity/DoorTileEntity.java | 4 +- .../doors/door/tileentity/IBluePrint.java | 5 +- .../doors/door/tileentity/IMultiBlock.java | 6 +- .../doors/door/tileentity/MultiTile.java | 44 ++-- .../malisis/doors/event/DoorEventHandler.java | 32 +-- .../doors/network/FrameUpdateMessage.java | 46 ++-- .../CustomDoorBoundingBoxRenderer.java | 52 ++--- 17 files changed, 334 insertions(+), 411 deletions(-) diff --git a/src/main/java/net/malisis/core/block/MalisisBlock.java b/src/main/java/net/malisis/core/block/MalisisBlock.java index 5bf6590..ade35aa 100644 --- a/src/main/java/net/malisis/core/block/MalisisBlock.java +++ b/src/main/java/net/malisis/core/block/MalisisBlock.java @@ -89,8 +89,7 @@ public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, } @Override - public AxisAlignedBB getCollisionBoundingBoxFromPool(World worldIn, int x, int y, int z) - { + public AxisAlignedBB getCollisionBoundingBoxFromPool(World worldIn, int x, int y, int z) { this.setBlockBoundsBasedOnState(worldIn, x, y, z); return super.getCollisionBoundingBoxFromPool(worldIn, x, y, z); } diff --git a/src/main/java/net/malisis/core/renderer/MalisisRenderer.java b/src/main/java/net/malisis/core/renderer/MalisisRenderer.java index 78c7381..4f1e479 100644 --- a/src/main/java/net/malisis/core/renderer/MalisisRenderer.java +++ b/src/main/java/net/malisis/core/renderer/MalisisRenderer.java @@ -740,7 +740,10 @@ protected void drawFace(Face f, RenderParameters faceParams) { // use normals if available if ((renderType == RenderType.ITEM_INVENTORY || renderType == RenderType.ISBRH_INVENTORY || params.useNormals.get()) && params.direction.get() != null) - this.tessellator.setNormal(params.direction.get().offsetX, params.direction.get().offsetY, params.direction.get().offsetZ); + this.tessellator.setNormal( + params.direction.get().offsetX, + params.direction.get().offsetY, + params.direction.get().offsetZ); baseBrightness = getBaseBrightness(); diff --git a/src/main/java/net/malisis/core/util/ComplexAxisAlignedBoundingBox.java b/src/main/java/net/malisis/core/util/ComplexAxisAlignedBoundingBox.java index 6604b6e..a45b69d 100644 --- a/src/main/java/net/malisis/core/util/ComplexAxisAlignedBoundingBox.java +++ b/src/main/java/net/malisis/core/util/ComplexAxisAlignedBoundingBox.java @@ -1,12 +1,14 @@ package net.malisis.core.util; + +import static net.minecraft.util.Vec3.createVectorHelper; + import net.minecraft.util.Vec3; import net.minecraftforge.common.util.ForgeDirection; + import org.apache.commons.lang3.tuple.Pair; -import static net.minecraft.util.Vec3.createVectorHelper; +public class ComplexAxisAlignedBoundingBox { -public class ComplexAxisAlignedBoundingBox -{ public enum Axis { X, Y, @@ -16,31 +18,27 @@ public enum Axis { private static final int[] cos = { 1, 0, -1, 0 }; private static final int[] sin = { 0, 1, 0, -1 }; - public Vec3[][] flatSurfaces; public Pair[] verticals; public static ComplexAxisAlignedBoundingBox defaultComplexBoundingBox = new ComplexAxisAlignedBoundingBox( new Vec3[][] { - { createVectorHelper(0,0,0), createVectorHelper(0,0,1), createVectorHelper(1,0,1), createVectorHelper(1,0,0) }, // bottom face - { createVectorHelper(0,1,0), createVectorHelper(0,1,1), createVectorHelper(1,1,1), createVectorHelper(1,1,0) }, // top face + { createVectorHelper(0, 0, 0), createVectorHelper(0, 0, 1), createVectorHelper(1, 0, 1), + createVectorHelper(1, 0, 0) }, // bottom face + { createVectorHelper(0, 1, 0), createVectorHelper(0, 1, 1), createVectorHelper(1, 1, 1), + createVectorHelper(1, 1, 0) }, // top face }, - new Pair[] { - Pair.of(createVectorHelper(0,0,0), createVectorHelper(0,1,0)), - Pair.of(createVectorHelper(1,0,0), createVectorHelper(1,1,0)), - Pair.of(createVectorHelper(0,0,1), createVectorHelper(0,1,1)), - Pair.of(createVectorHelper(1,0,1), createVectorHelper(1,1,1)) - } - ); + new Pair[] { Pair.of(createVectorHelper(0, 0, 0), createVectorHelper(0, 1, 0)), + Pair.of(createVectorHelper(1, 0, 0), createVectorHelper(1, 1, 0)), + Pair.of(createVectorHelper(0, 0, 1), createVectorHelper(0, 1, 1)), + Pair.of(createVectorHelper(1, 0, 1), createVectorHelper(1, 1, 1)) }); - public ComplexAxisAlignedBoundingBox(Vec3[][] flatSurfaces, Pair[] verticals ) - { + public ComplexAxisAlignedBoundingBox(Vec3[][] flatSurfaces, Pair[] verticals) { this.flatSurfaces = flatSurfaces; this.verticals = verticals; } - public void addOffset(double x, double y, double z) - { + public void addOffset(double x, double y, double z) { for (Vec3[] face : flatSurfaces) { for (Vec3 vec : face) { vec.xCoord += x; @@ -108,5 +106,4 @@ private static int getAngle(ForgeDirection dir) { default -> 0; }; } - } diff --git a/src/main/java/net/malisis/doors/MalisisDoors.java b/src/main/java/net/malisis/doors/MalisisDoors.java index 370eb07..e3bbb5b 100644 --- a/src/main/java/net/malisis/doors/MalisisDoors.java +++ b/src/main/java/net/malisis/doors/MalisisDoors.java @@ -2,9 +2,6 @@ import static net.malisis.doors.Tags.VERSION; -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.malisis.core.IMalisisMod; import net.malisis.core.MalisisCore; import net.malisis.core.configuration.Settings; @@ -28,13 +25,14 @@ import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; +import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.common.MinecraftForge; @Mod( modid = MalisisDoors.modid, @@ -82,7 +80,6 @@ public Settings getSettings() { return settings; } - @EventHandler public void preInit(FMLPreInitializationEvent event) { settings = new MalisisDoorsSettings(event.getSuggestedConfigurationFile()); @@ -93,8 +90,7 @@ public void preInit(FMLPreInitializationEvent event) { } @EventHandler - public void init(FMLInitializationEvent event) - { + public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new DoorEventHandler()); } diff --git a/src/main/java/net/malisis/doors/Registers.java b/src/main/java/net/malisis/doors/Registers.java index 096b7d7..d1a8717 100644 --- a/src/main/java/net/malisis/doors/Registers.java +++ b/src/main/java/net/malisis/doors/Registers.java @@ -468,14 +468,14 @@ private static void registerForcefieldDoor() { Items.comparator); } - private static void registerCollisionHelperBlocks() - { + private static void registerCollisionHelperBlocks() { collisionHelperBlock = new CollisionHelperBlock(BigDoor.Type.MEDIEVAL); - GameRegistry.registerBlock(collisionHelperBlock, collisionHelperBlock.getUnlocalizedName() - .substring(5)); + GameRegistry.registerBlock( + collisionHelperBlock, + collisionHelperBlock.getUnlocalizedName() + .substring(5)); GameRegistry.registerTileEntity(MultiTile.class, "collisionHelperTileEntity"); - } } diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index 2a2864a..7ebce37 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -13,7 +13,8 @@ package net.malisis.doors.door.block; -import java.util.ArrayList; +import static net.minecraft.util.MathHelper.abs; +import static net.minecraft.util.Vec3.createVectorHelper; import net.malisis.core.block.BoundingBoxType; import net.malisis.core.block.MalisisBlock; @@ -43,10 +44,8 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import org.apache.commons.lang3.tuple.Pair; -import static net.minecraft.util.MathHelper.abs; -import static net.minecraft.util.Vec3.createVectorHelper; +import org.apache.commons.lang3.tuple.Pair; /** * @author Ordinastie @@ -69,25 +68,29 @@ private Type(String name, Item door) { } private final Vec3[][] selectionOpenHoriztonalFaces = new Vec3[][] { - { createVectorHelper(0,5,1), createVectorHelper(0,5,1 - Door.DOOR_WIDTH), createVectorHelper(4,5,1 - Door.DOOR_WIDTH), createVectorHelper(4,5,1) }, // bottom face - { createVectorHelper(.5,4,1), createVectorHelper(.5,4,1 - Door.DOOR_WIDTH), createVectorHelper(3.5,4,1 - Door.DOOR_WIDTH), createVectorHelper(3.5,4,1) }, // top face - { createVectorHelper(0,4,1 - Door.DOOR_WIDTH), createVectorHelper(0, 4, -.5), createVectorHelper(.5,4,-.5), createVectorHelper(.5,4,1 - Door.DOOR_WIDTH) }, - { createVectorHelper(3.5, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 4, -.5), createVectorHelper(3.5, 4, -.5) }, - { createVectorHelper(0,0,1), createVectorHelper(0, 0, -.5), createVectorHelper(.5,0,-.5), createVectorHelper(.5,0,1) }, - { createVectorHelper(3.5, 0, 1), createVectorHelper(4, 0, 1), createVectorHelper(4, 0, -.5), createVectorHelper(3.5, 0, -.5) } - }; + { createVectorHelper(0, 5, 1), createVectorHelper(0, 5, 1 - Door.DOOR_WIDTH), + createVectorHelper(4, 5, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 5, 1) }, // bottom face + { createVectorHelper(.5, 4, 1), createVectorHelper(.5, 4, 1 - Door.DOOR_WIDTH), + createVectorHelper(3.5, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(3.5, 4, 1) }, // top face + { createVectorHelper(0, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(0, 4, -.5), createVectorHelper(.5, 4, -.5), + createVectorHelper(.5, 4, 1 - Door.DOOR_WIDTH) }, + { createVectorHelper(3.5, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 4, 1 - Door.DOOR_WIDTH), + createVectorHelper(4, 4, -.5), createVectorHelper(3.5, 4, -.5) }, + { createVectorHelper(0, 0, 1), createVectorHelper(0, 0, -.5), createVectorHelper(.5, 0, -.5), + createVectorHelper(.5, 0, 1) }, + { createVectorHelper(3.5, 0, 1), createVectorHelper(4, 0, 1), createVectorHelper(4, 0, -.5), + createVectorHelper(3.5, 0, -.5) } }; private final Pair[] selectionOpenVerticals = new Pair[] { - Pair.of(createVectorHelper(0,0,1), createVectorHelper(0,5,1)), - Pair.of(createVectorHelper(4,0,1), createVectorHelper(4,5,1)), - Pair.of(createVectorHelper(.5,0,1), createVectorHelper(.5,4,1)), - Pair.of(createVectorHelper(3.5,0,1), createVectorHelper(3.5,4,1)), - Pair.of(createVectorHelper(0,0,-.5), createVectorHelper(0,4,-.5)), - Pair.of(createVectorHelper(.5,0,-.5), createVectorHelper(.5,4,-.5)), - Pair.of(createVectorHelper(3.5,0,-.5), createVectorHelper(3.5,4,-.5)), - Pair.of(createVectorHelper(4,0,-.5), createVectorHelper(4,4,-.5)), - Pair.of(createVectorHelper(0,4,1 - Door.DOOR_WIDTH), createVectorHelper(0,5,1 - Door.DOOR_WIDTH)), - Pair.of(createVectorHelper(4,4,1 - Door.DOOR_WIDTH), createVectorHelper(4, 5, 1 - Door.DOOR_WIDTH)) - }; + Pair.of(createVectorHelper(0, 0, 1), createVectorHelper(0, 5, 1)), + Pair.of(createVectorHelper(4, 0, 1), createVectorHelper(4, 5, 1)), + Pair.of(createVectorHelper(.5, 0, 1), createVectorHelper(.5, 4, 1)), + Pair.of(createVectorHelper(3.5, 0, 1), createVectorHelper(3.5, 4, 1)), + Pair.of(createVectorHelper(0, 0, -.5), createVectorHelper(0, 4, -.5)), + Pair.of(createVectorHelper(.5, 0, -.5), createVectorHelper(.5, 4, -.5)), + Pair.of(createVectorHelper(3.5, 0, -.5), createVectorHelper(3.5, 4, -.5)), + Pair.of(createVectorHelper(4, 0, -.5), createVectorHelper(4, 4, -.5)), + Pair.of(createVectorHelper(0, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(0, 5, 1 - Door.DOOR_WIDTH)), + Pair.of(createVectorHelper(4, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 5, 1 - Door.DOOR_WIDTH)) }; private final int DoorBlockWidth = 4; private final int DoorBlockHeight = 5; @@ -133,19 +136,14 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase l world.setBlockMetadataWithNotify(x, y, z, metadata, 2); BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); - if (te != null) - { + if (te != null) { te.setFrameState(BlockState.fromNBT(itemStack.getTagCompound())); - if (checkAreaClearForDoor(world, x, y, z, metadata)) - { + if (checkAreaClearForDoor(world, x, y, z, metadata)) { te.onCreate(x, y, z, metadata); - } - else - { + } else { world.setBlockToAir(x, y, z); if (!world.isRemote && livingEntity instanceof EntityPlayerMP player) { - player.addChatMessage( - new ChatComponentText("There's no room for the door!")); + player.addChatMessage(new ChatComponentText("There's no room for the door!")); if (!player.capabilities.isCreativeMode) { final ItemStack doorBlock = new ItemStack(this, 1, 0); final EntityItem entityitem = player.dropPlayerItemWithRandomChoice(doorBlock, false); @@ -157,8 +155,7 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase l } } - private boolean checkAreaClearForDoor(World world, int x, int y, int z, int meta) - { + private boolean checkAreaClearForDoor(World world, int x, int y, int z, int meta) { boolean validSpot = true; boolean widthDirectionFlag = meta % 2 == 0; int xStep = meta == 3 ? -1 : 1; @@ -166,17 +163,13 @@ private boolean checkAreaClearForDoor(World world, int x, int y, int z, int meta int xMax = widthDirectionFlag ? 1 : 4; int zMax = widthDirectionFlag ? 4 : 1; - for (int yLoc = 0; yLoc < 5; yLoc++) - { - for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) - { - for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) - { - if (!(yLoc == 0 && zLoc == 0 && xLoc == 0)) - { + for (int yLoc = 0; yLoc < 5; yLoc++) { + for (int xLoc = 0; abs(xLoc) < xMax; xLoc += xStep) { + for (int zLoc = 0; abs(zLoc) < zMax; zLoc += zStep) { + if (!(yLoc == 0 && zLoc == 0 && xLoc == 0)) { final Block potentialSpot = world.getBlock(x + xLoc, y + yLoc, z + zLoc); - if (!potentialSpot.getMaterial().isReplaceable()) - { + if (!potentialSpot.getMaterial() + .isReplaceable()) { validSpot = false; } } @@ -187,16 +180,13 @@ private boolean checkAreaClearForDoor(World world, int x, int y, int z, int meta } @Override - public void breakBlock(World world, int x, int y, int z, Block block, int meta) - { + public void breakBlock(World world, int x, int y, int z, Block block, int meta) { final int buildHeight = world.getHeight() - 6; // No reason to have the door right at world height - if (y > buildHeight) - { + if (y > buildHeight) { return; } TileEntity tileEntity = world.getTileEntity(x, y, z); - if (tileEntity instanceof IMultiBlock) - { + if (tileEntity instanceof IMultiBlock) { ((IMultiBlock) tileEntity).onDestroy(block, tileEntity, meta); } super.breakBlock(world, x, y, z, block, meta); @@ -223,7 +213,8 @@ public AxisAlignedBB[] getBoundingBox(IBlockAccess world, int x, int y, int z, B if (type == BoundingBoxType.RENDER) { aabbs[0].minZ = -.5F; } else if ((type == BoundingBoxType.COLLISION || type == BoundingBoxType.CHUNKCOLLISION - || type == BoundingBoxType.RAYTRACE || type == BoundingBoxType.SELECTION) && (te.isOpened() || te.isMoving())) { + || type == BoundingBoxType.RAYTRACE + || type == BoundingBoxType.SELECTION) && (te.isOpened() || te.isMoving())) { aabbs = new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox(0, 0, -0.5F, 0.5F, 4, 1), AxisAlignedBB.getBoundingBox(3.5F, 0, -0.5F, 4, 4, 1), AxisAlignedBB.getBoundingBox(0, 4, 1 - Door.DOOR_WIDTH, 4, 5, 1) }; @@ -232,13 +223,12 @@ public AxisAlignedBB[] getBoundingBox(IBlockAccess world, int x, int y, int z, B return AABBUtils.rotate(aabbs, Door.intToDir(te.getDirection())); } - public ComplexAxisAlignedBoundingBox getComplexBoundingBoxWithOffset(IBlockAccess world, int x, int y, int z, BoundingBoxType type) - { + public ComplexAxisAlignedBoundingBox getComplexBoundingBoxWithOffset(IBlockAccess world, int x, int y, int z, + BoundingBoxType type) { BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); if (te == null) return ComplexAxisAlignedBoundingBox.defaultComplexBoundingBox; - if (type == BoundingBoxType.SELECTION && (te.isOpened() || te.isMoving())) - { + if (type == BoundingBoxType.SELECTION && (te.isOpened() || te.isMoving())) { Vec3[][] clonedFlatSurfaces = new Vec3[selectionOpenHoriztonalFaces.length][]; for (int i = 0; i < selectionOpenHoriztonalFaces.length; i++) { clonedFlatSurfaces[i] = new Vec3[selectionOpenHoriztonalFaces[i].length]; @@ -252,19 +242,22 @@ public ComplexAxisAlignedBoundingBox getComplexBoundingBoxWithOffset(IBlockAcces for (int i = 0; i < selectionOpenVerticals.length; i++) { Vec3 left = selectionOpenVerticals[i].getLeft(); Vec3 right = selectionOpenVerticals[i].getRight(); - clonedVerticals[i] = Pair.of(createVectorHelper(left.xCoord, left.yCoord, left.zCoord), + clonedVerticals[i] = Pair.of( + createVectorHelper(left.xCoord, left.yCoord, left.zCoord), createVectorHelper(right.xCoord, right.yCoord, right.zCoord)); } - ComplexAxisAlignedBoundingBox CAABB = new ComplexAxisAlignedBoundingBox(clonedFlatSurfaces, clonedVerticals); - CAABB.rotate(Door.intToDir(te.getDirection()) ,ComplexAxisAlignedBoundingBox.Axis.Y); + ComplexAxisAlignedBoundingBox CAABB = new ComplexAxisAlignedBoundingBox( + clonedFlatSurfaces, + clonedVerticals); + CAABB.rotate(Door.intToDir(te.getDirection()), ComplexAxisAlignedBoundingBox.Axis.Y); // Offset needed post-rotation switch (Door.intToDir(te.getDirection())) { case EAST -> CAABB.addOffset(x + 1, y, z); case NORTH -> CAABB.addOffset(x, y, z); case SOUTH -> CAABB.addOffset(x + 1, y, z + 1); case WEST -> CAABB.addOffset(x, y, z + 1); - } + } return CAABB; } return ComplexAxisAlignedBoundingBox.defaultComplexBoundingBox; @@ -301,9 +294,14 @@ public int getRenderType() { } @Override - public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) - { - this.setBlockBounds((float) defaultBoundingBox.minX, (float) defaultBoundingBox.minY, (float) defaultBoundingBox.minZ, (float) defaultBoundingBox.maxX, (float) defaultBoundingBox.maxY, (float) defaultBoundingBox.maxZ); + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { + this.setBlockBounds( + (float) defaultBoundingBox.minX, + (float) defaultBoundingBox.minY, + (float) defaultBoundingBox.minZ, + (float) defaultBoundingBox.maxX, + (float) defaultBoundingBox.maxY, + (float) defaultBoundingBox.maxZ); } @Override diff --git a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java index 20d58ca..1ff4a3e 100644 --- a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java +++ b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java @@ -1,7 +1,8 @@ package net.malisis.doors.door.block; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import java.util.List; +import java.util.Random; + import net.malisis.core.block.BoundingBoxType; import net.malisis.core.util.ComplexAxisAlignedBoundingBox; import net.malisis.doors.MalisisDoors; @@ -26,12 +27,11 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import java.util.List; -import java.util.Random; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class CollisionHelperBlock extends BlockContainer implements ITileEntityProvider { - BigDoor.Type type; private IIcon[] fakeIcons; @@ -81,9 +81,8 @@ public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side) { } @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer EntityPlayer, int par6, - float subx, float suby, float subz) - { + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer EntityPlayer, int par6, float subx, + float suby, float subz) { final MultiTile tileEntity = ((MultiTile) world.getTileEntity(x, y, z)); return tileEntity.onBlockActivated(world, x, y, z, EntityPlayer); } @@ -92,7 +91,8 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer E public void breakBlock(World world, int x, int y, int z, Block block, int meta) { final TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity instanceof MultiTile) { - ((MultiTile) tileEntity).onBlockRemoval(type == BigDoor.Type.MEDIEVAL ? MalisisDoors.Blocks.medievalDoor : MalisisDoors.Blocks.carriageDoor); + ((MultiTile) tileEntity).onBlockRemoval( + type == BigDoor.Type.MEDIEVAL ? MalisisDoors.Blocks.medievalDoor : MalisisDoors.Blocks.carriageDoor); } super.breakBlock(world, x, y, z, block, meta); } @@ -101,8 +101,7 @@ public void breakBlock(World world, int x, int y, int z, Block block, int meta) public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { final int meta = world.getBlockMetadata(x, y, z); - switch (meta) - { + switch (meta) { case 0: // 3 Pixels wide on the east side of the block this.setBlockBounds(1.0F - Door.DOOR_WIDTH, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); break; @@ -144,7 +143,7 @@ public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) @Override public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, - List list, Entity entity) { + List list, Entity entity) { setBlockBoundsBasedOnState(world, x, y, z); super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity); } @@ -158,38 +157,39 @@ public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, @Override public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); - MultiTile thisTE = ((MultiTile) world.getTileEntity(x,y,z)); + MultiTile thisTE = ((MultiTile) world.getTileEntity(x, y, z)); Block mainBlock = world.getBlock(thisTE.mainBlockX, thisTE.mainBlockY, thisTE.mainBlockZ); - if (mainBlock instanceof BigDoor) - { - return mainBlock.getSelectedBoundingBoxFromPool(world, thisTE.mainBlockX, thisTE.mainBlockY, thisTE.mainBlockZ); + if (mainBlock instanceof BigDoor) { + return mainBlock + .getSelectedBoundingBoxFromPool(world, thisTE.mainBlockX, thisTE.mainBlockY, thisTE.mainBlockZ); } return super.getSelectedBoundingBoxFromPool(world, x, y, z); } - public ComplexAxisAlignedBoundingBox getComplexBoundingBox(World world, int x, int y, int z) - { + public ComplexAxisAlignedBoundingBox getComplexBoundingBox(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); MultiTile TE = getTileEntity(world, x, y, z); BigDoor mainBlock = getMainBlock(world, x, y, z); - return mainBlock.getComplexBoundingBoxWithOffset(world, TE.mainBlockX, TE.mainBlockY, TE.mainBlockZ, BoundingBoxType.SELECTION); + return mainBlock.getComplexBoundingBoxWithOffset( + world, + TE.mainBlockX, + TE.mainBlockY, + TE.mainBlockZ, + BoundingBoxType.SELECTION); } - public BigDoor getMainBlock(World world, int x, int y, int z) - { + public BigDoor getMainBlock(World world, int x, int y, int z) { MultiTile cTE = this.getTileEntity(world, x, y, z); return (BigDoor) world.getBlock(cTE.mainBlockX, cTE.mainBlockY, cTE.mainBlockZ); } - public BigDoorTileEntity getMainTileEntity(World world, int x, int y, int z) - { + public BigDoorTileEntity getMainTileEntity(World world, int x, int y, int z) { MultiTile cTE = this.getTileEntity(world, x, y, z); return (BigDoorTileEntity) world.getTileEntity(cTE.mainBlockX, cTE.mainBlockY, cTE.mainBlockZ); } - public MultiTile getTileEntity(World world, int x, int y, int z) - { - return (MultiTile) world.getTileEntity(x,y,z); + public MultiTile getTileEntity(World world, int x, int y, int z) { + return (MultiTile) world.getTileEntity(x, y, z); } @Override @@ -204,7 +204,8 @@ public float getBlockHardness(World world, int x, int y, int z) { final int mainX = ((MultiTile) tileEntity).mainBlockX; final int mainY = ((MultiTile) tileEntity).mainBlockY; final int mainZ = ((MultiTile) tileEntity).mainBlockZ; - return world.getBlock(mainX, mainY, mainZ).getBlockHardness(world, mainX, mainY, mainZ); + return world.getBlock(mainX, mainY, mainZ) + .getBlockHardness(world, mainX, mainY, mainZ); } return this.blockHardness; } @@ -234,8 +235,8 @@ public boolean shouldSideBeRendered(IBlockAccess worldIn, int x, int y, int z, i return false; } - public void makeCollisionHelperBlock(World world, int x, int y, int z, int meta, int xMain, int yMain, int zMain, int metaMain) - { + public void makeCollisionHelperBlock(World world, int x, int y, int z, int meta, int xMain, int yMain, int zMain, + int metaMain) { world.setBlock(x, y, z, this, meta, 3); MultiTile tile = (MultiTile) world.getTileEntity(x, y, z); tile.setMainBlock(xMain, yMain, zMain); @@ -244,17 +245,19 @@ public void makeCollisionHelperBlock(World world, int x, int y, int z, int meta, @SuppressWarnings("deprecation") @Override - public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) - { + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { final TileEntity tileEntity = world.getTileEntity(x, y, z); - if (tileEntity instanceof MultiTile multiTileEntity) - { - if (multiTileEntity.mainBlockSet) - { - final Block mainBlock = world.getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ); - if (Blocks.air != mainBlock) - { - return mainBlock.getPickBlock(target, world, multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ); + if (tileEntity instanceof MultiTile multiTileEntity) { + if (multiTileEntity.mainBlockSet) { + final Block mainBlock = world + .getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ); + if (Blocks.air != mainBlock) { + return mainBlock.getPickBlock( + target, + world, + multiTileEntity.mainBlockX, + multiTileEntity.mainBlockY, + multiTileEntity.mainBlockZ); } } } @@ -264,17 +267,16 @@ public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, i @SideOnly(Side.CLIENT) @Override - public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) - { + public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) { final TileEntity tileEntity = world.getTileEntity(x, y, z); - if (tileEntity instanceof MultiTile multiTileEntity) - { - if (multiTileEntity.mainBlockSet) - { - final Block mainBlock = world.getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ); - if (Blocks.air != mainBlock) - { - return world.getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ).addDestroyEffects(world, x, y, z, meta, effectRenderer); + if (tileEntity instanceof MultiTile multiTileEntity) { + if (multiTileEntity.mainBlockSet) { + final Block mainBlock = world + .getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ); + if (Blocks.air != mainBlock) { + return world + .getBlock(multiTileEntity.mainBlockX, multiTileEntity.mainBlockY, multiTileEntity.mainBlockZ) + .addDestroyEffects(world, x, y, z, meta, effectRenderer); } } } diff --git a/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java b/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java index a6e1931..3cbf3c1 100644 --- a/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java +++ b/src/main/java/net/malisis/doors/door/multiBlock/MultiBlueprint.java @@ -1,14 +1,12 @@ package net.malisis.doors.door.multiBlock; -import org.joml.Vector3i; - import java.util.Map; -public class MultiBlueprint -{ +import org.joml.Vector3i; + +public class MultiBlueprint { - public enum RotationDegrees - { + public enum RotationDegrees { ROT90, ROT180, ROT270, @@ -25,8 +23,7 @@ public enum RotationDegrees public int zLength; private Map metaMap; - public MultiBlueprint(int[][][] print, Map metaMap, Vector3i startingLocation) - { + public MultiBlueprint(int[][][] print, Map metaMap, Vector3i startingLocation) { this.yLength = print.length; this.xLength = print[0].length; this.zLength = print[0][0].length; @@ -35,11 +32,9 @@ public MultiBlueprint(int[][][] print, Map metaMap, Vector3i sta this.startingLocation = startingLocation; } - public void rotate(RotationDegrees angle) - { + public void rotate(RotationDegrees angle) { int[][][] rotatedPrint = new int[bluePrint.length][bluePrint.length][bluePrint.length]; - switch (angle) - { + switch (angle) { case ROT90 -> { for (int i = 0; i < bluePrint.length; i++) { rotatedPrint[i] = rotate90Clockwise(bluePrint[i]); @@ -61,34 +56,27 @@ public void rotate(RotationDegrees angle) this.bluePrint = rotatedPrint; } - private int[][] rotate90Clockwise(int[][] matrix) - { + private int[][] rotate90Clockwise(int[][] matrix) { return transpose(reverseColumns(matrix)); } - private int[][] rotate180Clockwise(int[][] matrix) - { + private int[][] rotate180Clockwise(int[][] matrix) { return reverseColumns(reverseRows(matrix)); } - private int[][] rotate270Clockwise(int[][] matrix) - { + private int[][] rotate270Clockwise(int[][] matrix) { return transpose(reverseRows(matrix)); } - private void convertMeta(int[][][] mat, RotationDegrees angle) - { + private void convertMeta(int[][][] mat, RotationDegrees angle) { int conversionInfo = angle.ordinal(); - for (int i = 0; i < mat.length; i++) - { - for (int j = 0; j < mat[i].length; j++) - { + for (int i = 0; i < mat.length; i++) { + for (int j = 0; j < mat[i].length; j++) { for (int k = 0; k < mat[i][j].length; k++) { int[] newState = metaMap.get(mat[i][j][k]); if (newState == null) { - if (mat[i][j][k] == MB) - { - this.startingLocation = new Vector3i(j,i,k); + if (mat[i][j][k] == MB) { + this.startingLocation = new Vector3i(j, i, k); } } else { mat[i][j][k] = newState[conversionInfo]; @@ -110,13 +98,11 @@ private int[][] transpose(int[][] matrix) { return transposed; } - private int[][] reverseColumns(int[][] matrix) - { + private int[][] reverseColumns(int[][] matrix) { return multiplyMatrices(generateRowReversalMatrix(matrix.length), matrix); } - private int[][] reverseRows(int[][] matrix) - { + private int[][] reverseRows(int[][] matrix) { return multiplyMatrices(matrix, generateRowReversalMatrix(matrix[0].length)); } @@ -135,7 +121,8 @@ private int[][] multiplyMatrices(int[][] A, int[][] B) { int colsB = B[0].length; if (colsA != rowsB) { - throw new IllegalArgumentException("Number of columns in Matrix A must be equal to number of rows in Matrix B."); + throw new IllegalArgumentException( + "Number of columns in Matrix A must be equal to number of rows in Matrix B."); } int[][] result = new int[rowsA][colsB]; diff --git a/src/main/java/net/malisis/doors/door/tests/MultiBlueprintTest.java b/src/main/java/net/malisis/doors/door/tests/MultiBlueprintTest.java index 74d6bc0..1175ef7 100644 --- a/src/main/java/net/malisis/doors/door/tests/MultiBlueprintTest.java +++ b/src/main/java/net/malisis/doors/door/tests/MultiBlueprintTest.java @@ -1,23 +1,23 @@ -//package net.malisis.doors.door.tests; +// package net.malisis.doors.door.tests; // // -//import net.malisis.doors.door.multiBlock.MultiBlueprint; +// import net.malisis.doors.door.multiBlock.MultiBlueprint; // -//public class MultiBlueprintTest { +// public class MultiBlueprintTest { // -// private MultiBlueprint blueprint; +// private MultiBlueprint blueprint; // -// @BeforeEach -// public void setUp() {// Set up before each test -// } +// @BeforeEach +// public void setUp() {// Set up before each test +// } // -// @Test -// public void testAddition() { +// @Test +// public void testAddition() { // -// } +// } // -// @Test -// public void testSubtraction() { +// @Test +// public void testSubtraction() { // -// } -//} +// } +// } diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index 5f16778..eef1090 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -13,6 +13,12 @@ package net.malisis.doors.door.tileentity; +import static net.malisis.doors.door.multiBlock.MultiBlueprint.MB; +import static net.malisis.doors.door.multiBlock.MultiBlueprint.RM; + +import java.util.HashMap; +import java.util.Map; + import net.malisis.core.MalisisCore; import net.malisis.core.block.BoundingBoxType; import net.malisis.core.util.BlockState; @@ -21,11 +27,11 @@ import net.malisis.doors.door.DoorDescriptor; import net.malisis.doors.door.DoorRegistry; import net.malisis.doors.door.DoorState; -import net.malisis.doors.door.multiBlock.MultiBlueprint; import net.malisis.doors.door.block.BigDoor; import net.malisis.doors.door.block.CollisionHelperBlock; import net.malisis.doors.door.block.Door; import net.malisis.doors.door.movement.CarriageDoorMovement; +import net.malisis.doors.door.multiBlock.MultiBlueprint; import net.malisis.doors.door.sound.CarriageDoorSound; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -40,15 +46,9 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import com.google.common.base.Objects; import org.joml.Vector3i; -import java.util.HashMap; -import java.util.Map; - -import static net.malisis.doors.door.multiBlock.MultiBlueprint.MB; -import static net.malisis.doors.door.multiBlock.MultiBlueprint.RM; -import static net.minecraft.util.MathHelper.abs; +import com.google.common.base.Objects; /** * @author Ordinastie @@ -62,73 +62,34 @@ public class BigDoorTileEntity extends MultiTile implements IMultiBlock, IBluePr private final Block defaultBorderBlock = Blocks.stonebrick; private BlockState frameState = new BlockState(defaultBorderBlock); private Boolean changingState = false; - private final int[][][] openPrint = - { - { - {10, -1, -1, 9}, - {MB, RM, RM, 7}, - }, - { - {10, -1, -1, 9}, - { 5, RM, RM, 7}, - }, - { - {10, -1, -1, 9}, - { 5, RM, RM, 7}, - }, - { - {10, -1, -1, 9}, - { 5, RM, RM, 7}, - }, - { - {-1, -1, -1, -1}, - { 0, 0, 0, 0}, - } - }; + private final int[][][] openPrint = { { { 10, -1, -1, 9 }, { MB, RM, RM, 7 }, }, + { { 10, -1, -1, 9 }, { 5, RM, RM, 7 }, }, { { 10, -1, -1, 9 }, { 5, RM, RM, 7 }, }, + { { 10, -1, -1, 9 }, { 5, RM, RM, 7 }, }, { { -1, -1, -1, -1 }, { 0, 0, 0, 0 }, } }; + + private final int[][][] closedPrint = { { { RM, -1, -1, RM }, { MB, 0, 0, 0 }, }, + { { RM, -1, -1, RM }, { 0, 0, 0, 0 }, }, { { RM, -1, -1, RM }, { 0, 0, 0, 0 }, }, + { { RM, -1, -1, RM }, { 0, 0, 0, 0 }, }, { { RM, -1, -1, RM }, { 0, 0, 0, 0 }, } }; + + // This map defines how to choose the next meta based on a rotation. + Map metaMap = new HashMap<>() { - private final int[][][] closedPrint = - { - { - {RM, -1, -1, RM}, - {MB, 0, 0, 0}, - }, - { - {RM, -1, -1, RM}, - { 0, 0, 0, 0}, - }, - { - {RM, -1, -1, RM}, - { 0, 0, 0, 0}, - }, - { - {RM, -1, -1, RM}, - { 0, 0, 0, 0}, - }, { - {RM, -1, -1, RM}, - { 0, 0, 0, 0}, + put(0, new int[] { 1, 2, 3 }); + put(1, new int[] { 2, 3, 0 }); + put(2, new int[] { 3, 0, 1 }); + put(3, new int[] { 0, 1, 2 }); + put(4, new int[] { 5, 6, 7 }); + put(5, new int[] { 6, 7, 4 }); + put(6, new int[] { 7, 4, 5 }); + put(7, new int[] { 4, 5, 6 }); + put(8, new int[] { 9, 10, 11 }); + put(9, new int[] { 10, 11, 8 }); + put(10, new int[] { 11, 8, 9 }); + put(11, new int[] { 8, 9, 10 }); } }; - - - // This map defines how to choose the next meta based on a rotation. - Map metaMap = new HashMap<>() {{ - put(0, new int[]{1, 2, 3}); - put(1, new int[]{2, 3, 0}); - put(2, new int[]{3, 0, 1}); - put(3, new int[]{0, 1, 2}); - put(4, new int[]{5, 6, 7}); - put(5, new int[]{6, 7, 4}); - put(6, new int[]{7, 4, 5}); - put(7, new int[]{4, 5, 6}); - put(8, new int[]{9, 10, 11}); - put(9, new int[]{10, 11, 8}); - put(10, new int[]{ 11, 8, 9}); - put(11, new int[]{8, 9, 10}); - }}; - - private final MultiBlueprint closedBlueprint = new MultiBlueprint(closedPrint, metaMap, new Vector3i(1,0,0)); + private final MultiBlueprint closedBlueprint = new MultiBlueprint(closedPrint, metaMap, new Vector3i(1, 0, 0)); private final MultiBlueprint openBlueprint = new MultiBlueprint(openPrint, metaMap, new Vector3i(1, 0, 0)); public BigDoorTileEntity() { @@ -150,8 +111,7 @@ public void setFrameState(BlockState state) { } @Override - public void setFrameState (Block block) - { + public void setFrameState(Block block) { this.setFrameState(new BlockState(block)); } @@ -173,10 +133,10 @@ public boolean isPowered() { @Override public void setDoorState(DoorState newState) { super.setDoorState(newState); -// if (!this.worldObj.isRemote) -// { + // if (!this.worldObj.isRemote) + // { this.onStateChange(newState); -// } + // } } @Override @@ -231,8 +191,7 @@ public AxisAlignedBB getRenderBoundingBox() { @Override public boolean onActivated(EntityPlayer entityPlayer) { - if (!this.worldObj.isRemote) - { + if (!this.worldObj.isRemote) { this.openOrCloseDoor(); } return true; @@ -246,20 +205,17 @@ public void onCreate(int x, int y, int z, int meta) { if (y > buildHeight) { return; } - this.setMainBlock(x,y,z); + this.setMainBlock(x, y, z); this.mainBlockSet = true; placeBluePrint(this.worldObj, x, y, z, meta, false); } @Override - public void onDestroy(Block blockToDrop, TileEntity callingBlock, int meta) - { - if (!this.changingState) - { + public void onDestroy(Block blockToDrop, TileEntity callingBlock, int meta) { + if (!this.changingState) { int metaToUse = meta; - if (this.state == DoorState.OPENING && metaToUse < 4) - { + if (this.state == DoorState.OPENING && metaToUse < 4) { metaToUse += 4; } this.changingState = true; @@ -270,28 +226,22 @@ public void onDestroy(Block blockToDrop, TileEntity callingBlock, int meta) // This method is a little complex because unless the door is fully closed I want players to be able to go through // the door. - public void onStateChange(DoorState newState) - { + public void onStateChange(DoorState newState) { if (this.state == newState) return; int meta = this.mainBlockMeta; - if (newState == DoorState.OPENING && meta < 4) - { + if (newState == DoorState.OPENING && meta < 4) { this.changingState = true; placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, (meta + 4) % 8, true); this.changingState = false; - } - else if (newState == DoorState.CLOSED) - { + } else if (newState == DoorState.CLOSED) { this.changingState = true; placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, meta, true); this.changingState = false; } } - @Override - public boolean shouldRender() - { + public boolean shouldRender() { return true; } @@ -303,19 +253,16 @@ public Packet getDescriptionPacket() { } @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) - { + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { super.onDataPacket(net, pkt); NBTTagCompound packetData = pkt.func_148857_g(); this.setFrameState(BlockState.fromNBT(packetData)); } @Override - public void placeBluePrint(World world, int x, int y, int z, int meta, boolean removeBlockInWay) - { + public void placeBluePrint(World world, int x, int y, int z, int meta, boolean removeBlockInWay) { MultiBlueprint print = (meta < 4 ? this.closedBlueprint : this.openBlueprint); - switch (meta) - { + switch (meta) { case 0, 4: this.bluePrintPlacerHelper(world, x, y, z, print, removeBlockInWay); break; @@ -337,8 +284,8 @@ public void placeBluePrint(World world, int x, int y, int z, int meta, boolean r } } - private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBlueprint print, boolean removeBlockInWay) - { + private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBlueprint print, + boolean removeBlockInWay) { int mainBlockRelativeX = print.startingLocation.x; int mainBlockRelativeY = print.startingLocation.y; int mainBlockRelativeZ = print.startingLocation.z; @@ -348,13 +295,23 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr { for (int k = 0; k < print.bluePrint[0][0].length; k++) // z { - if (!(i == print.startingLocation.x && j == print.startingLocation.y && k == print.startingLocation.z) && print.bluePrint[j][i][k] > -1) - { - ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlock).makeCollisionHelperBlock(world, x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, z + mainBlockRelativeZ - k, print.bluePrint[j][i][k] , this.xCoord, this.yCoord, this.zCoord, this.getBlockMetadata()); - } - else if(print.bluePrint[j][i][k] == Integer.MIN_VALUE && removeBlockInWay) - { - world.setBlockToAir(x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, z + mainBlockRelativeZ - k); + if (!(i == print.startingLocation.x && j == print.startingLocation.y + && k == print.startingLocation.z) && print.bluePrint[j][i][k] > -1) { + ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlock).makeCollisionHelperBlock( + world, + x - mainBlockRelativeX + i, + y - mainBlockRelativeY + j, + z + mainBlockRelativeZ - k, + print.bluePrint[j][i][k], + this.xCoord, + this.yCoord, + this.zCoord, + this.getBlockMetadata()); + } else if (print.bluePrint[j][i][k] == Integer.MIN_VALUE && removeBlockInWay) { + world.setBlockToAir( + x - mainBlockRelativeX + i, + y - mainBlockRelativeY + j, + z + mainBlockRelativeZ - k); } } } @@ -362,10 +319,10 @@ else if(print.bluePrint[j][i][k] == Integer.MIN_VALUE && removeBlockInWay) } @Override - public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock, Block blockToDrop) { + public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock, + Block blockToDrop) { MultiBlueprint print = (meta < 4 ? this.closedBlueprint : this.openBlueprint); - switch (meta) - { + switch (meta) { case 0, 4: this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); break; @@ -387,8 +344,8 @@ public void removeBluePrint(World world, int x, int y, int z, int meta, TileEnti } } - private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, TileEntity callingBlock, Block blockToDrop) - { + private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, TileEntity callingBlock, + Block blockToDrop) { int mainBlockRelativeX = print.startingLocation.x; int mainBlockRelativeY = print.startingLocation.y; int mainBlockRelativeZ = print.startingLocation.z; @@ -398,13 +355,14 @@ private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBluep { for (int k = 0; k < print.bluePrint[0][0].length; k++) // z { - if (print.bluePrint[j][i][k] == MB) - { + if (print.bluePrint[j][i][k] == MB) { ((MultiTile) callingBlock).dropMainBlockAtLocation(blockToDrop); } - if (print.bluePrint[j][i][k] > -1) - { - world.setBlockToAir(x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, z + mainBlockRelativeZ - k); + if (print.bluePrint[j][i][k] > -1) { + world.setBlockToAir( + x - mainBlockRelativeX + i, + y - mainBlockRelativeY + j, + z + mainBlockRelativeZ - k); } } } diff --git a/src/main/java/net/malisis/doors/door/tileentity/DoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/DoorTileEntity.java index e982443..e4fc58b 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/DoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/DoorTileEntity.java @@ -111,10 +111,10 @@ public boolean isReversed() { return (getBlockMetadata() & Door.FLAG_REVERSED) != 0; } - public boolean shouldRender() - { + public boolean shouldRender() { return true; } + public boolean isPowered() { return getWorldObj().isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) || getWorldObj().isBlockIndirectlyGettingPowered(xCoord, yCoord + 1, zCoord); diff --git a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java index 3c07784..0649bdc 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java @@ -4,8 +4,9 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -public interface IBluePrint -{ +public interface IBluePrint { + public void placeBluePrint(World world, int x, int y, int z, int meta, boolean removeBlockInWay); + public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock, Block blockToDrop); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java index e84d230..db18519 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java @@ -14,9 +14,9 @@ public interface IMultiBlock { /** * Called when this multiblock is created * - * @param x - placed x coord - * @param y - placed y coord - * @param z - placed z coord' + * @param x - placed x coord + * @param y - placed y coord + * @param z - placed z coord' * @param meta - meta of the placed door */ void onCreate(int x, int y, int z, int meta); diff --git a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java index d29846c..0991e0c 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java +++ b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java @@ -1,6 +1,5 @@ package net.malisis.doors.door.tileentity; - import net.malisis.core.util.BlockState; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -12,32 +11,28 @@ import net.minecraft.world.World; public class MultiTile extends DoorTileEntity { + public int mainBlockX; public int mainBlockY; public int mainBlockZ; public int mainBlockMeta; public boolean mainBlockSet; - public void setMainBlock(int x, int y, int z) - { + public void setMainBlock(int x, int y, int z) { this.mainBlockX = x; this.mainBlockY = y; this.mainBlockZ = z; this.mainBlockSet = true; this.markDirty(); - if (!this.worldObj.isRemote) - { + if (!this.worldObj.isRemote) { this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); } } - public void onBlockRemoval(Block block) - { + public void onBlockRemoval(Block block) { TileEntity mainBlock = getMainBlockTile(); - if (mainBlock != null) - { - if (mainBlock instanceof IMultiBlock) - { + if (mainBlock != null) { + if (mainBlock instanceof IMultiBlock) { ((IMultiBlock) mainBlock).onDestroy(block, this, this.mainBlockMeta); } } @@ -65,8 +60,7 @@ public Packet getDescriptionPacket() { } @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) - { + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { super.onDataPacket(net, pkt); NBTTagCompound packetData = pkt.func_148857_g(); this.mainBlockX = packetData.getInteger("mainBlockX"); @@ -96,40 +90,32 @@ public void readFromNBT(NBTTagCompound nbt) { } @Override - public boolean shouldRender() - { + public boolean shouldRender() { return false; } - public void setFrameState(Block block) - { + public void setFrameState(Block block) { TileEntity mainTile = this.getMainBlockTile(); - if (mainTile instanceof BigDoorTileEntity bigDoorMainTile) - { + if (mainTile instanceof BigDoorTileEntity bigDoorMainTile) { bigDoorMainTile.setFrameState(block); } } - public void setFrameState(BlockState blockState) - { + public void setFrameState(BlockState blockState) { TileEntity mainTile = this.getMainBlockTile(); - if (mainTile instanceof BigDoorTileEntity bigDoorTileEntity) - { + if (mainTile instanceof BigDoorTileEntity bigDoorTileEntity) { bigDoorTileEntity.setFrameState(blockState); } } - public void dropMainBlockAtLocation(Block block) - { - if (mainBlockSet) - { + public void dropMainBlockAtLocation(Block block) { + if (mainBlockSet) { int meta = this.getBlockMetadata(); block.dropBlockAsItem(this.worldObj, xCoord, yCoord, zCoord, meta, 0); } } - public void setMainBlockMeta(int meta) - { + public void setMainBlockMeta(int meta) { this.mainBlockMeta = meta; } } diff --git a/src/main/java/net/malisis/doors/event/DoorEventHandler.java b/src/main/java/net/malisis/doors/event/DoorEventHandler.java index 6d9fc76..336a19b 100644 --- a/src/main/java/net/malisis/doors/event/DoorEventHandler.java +++ b/src/main/java/net/malisis/doors/event/DoorEventHandler.java @@ -1,6 +1,5 @@ package net.malisis.doors.event; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.malisis.doors.door.DoorState; import net.malisis.doors.door.block.CollisionHelperBlock; import net.malisis.doors.door.tileentity.DoorTileEntity; @@ -17,8 +16,11 @@ import net.minecraft.world.World; import net.minecraftforge.client.event.DrawBlockHighlightEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; + import org.lwjgl.input.Keyboard; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + public class DoorEventHandler { public CustomDoorBoundingBoxRenderer cdbbRenderer = new CustomDoorBoundingBoxRenderer(); @@ -42,7 +44,12 @@ public void onDrawBlockHighlight(DrawBlockHighlightEvent event) { DoorState state = ((DoorTileEntity) mainDoorTE).getState(); if (state == DoorState.OPENED || state == DoorState.OPENING || state == DoorState.CLOSING) { event.setCanceled(true); - cdbbRenderer.renderOpenDoorBoundingBox(world, (CollisionHelperBlock) block, event.player, event.partialTicks, target); + cdbbRenderer.renderOpenDoorBoundingBox( + world, + (CollisionHelperBlock) block, + event.player, + event.partialTicks, + target); } } } @@ -51,18 +58,16 @@ public void onDrawBlockHighlight(DrawBlockHighlightEvent event) { } @SubscribeEvent - public void PlayerInteractEvent(PlayerInteractEvent event) - { + public void PlayerInteractEvent(PlayerInteractEvent event) { TileEntity tileEntity = getTileEntityLookingAt(event.entityPlayer); - if (event.entityPlayer.isSneaking() && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) && tileEntity instanceof MultiTile multiTile && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) - { + if (event.entityPlayer.isSneaking() && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) + && tileEntity instanceof MultiTile multiTile + && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { ItemStack heldStack = event.entityPlayer.getHeldItem(); - if (heldStack != null) - { + if (heldStack != null) { Block block = Block.getBlockFromItem(heldStack.getItem()); int damageValue = heldStack.getItemDamage(); - if (block != null) - { + if (block != null) { event.setCanceled(true); FrameUpdateMessage.SendFrameUpdateMessage(multiTile, block, damageValue); } @@ -75,11 +80,8 @@ private TileEntity getTileEntityLookingAt(EntityPlayer player) { double maxReach = mc.playerController.getBlockReachDistance(); Vec3 eyePosition = player.getPosition(1.0F); Vec3 lookVector = player.getLook(1.0F); - Vec3 endPosition = eyePosition.addVector( - lookVector.xCoord * maxReach, - lookVector.yCoord * maxReach, - lookVector.zCoord * maxReach - ); + Vec3 endPosition = eyePosition + .addVector(lookVector.xCoord * maxReach, lookVector.yCoord * maxReach, lookVector.zCoord * maxReach); MovingObjectPosition rayTraceResult = mc.theWorld.rayTraceBlocks(eyePosition, endPosition); if (rayTraceResult != null && rayTraceResult.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { int blockX = rayTraceResult.blockX; diff --git a/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java b/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java index 14049e6..a1975c9 100644 --- a/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java +++ b/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java @@ -1,10 +1,7 @@ package net.malisis.doors.network; -import cpw.mods.fml.common.network.simpleimpl.IMessage; -import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; -import cpw.mods.fml.common.network.simpleimpl.MessageContext; -import cpw.mods.fml.relauncher.Side; -import io.netty.buffer.ByteBuf; +import java.awt.*; + import net.malisis.core.network.MalisisMessage; import net.malisis.core.util.BlockState; import net.malisis.doors.MalisisDoors; @@ -13,10 +10,14 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import java.awt.*; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.Side; +import io.netty.buffer.ByteBuf; @MalisisMessage -public class FrameUpdateMessage implements IMessageHandler { +public class FrameUpdateMessage implements IMessageHandler { public FrameUpdateMessage() { MalisisDoors.network.registerMessage(this, FrameUpdateMessage.Packet.class, Side.SERVER); @@ -26,17 +27,25 @@ public FrameUpdateMessage() { public IMessage onMessage(FrameUpdateMessage.Packet message, MessageContext ctx) { World world = ctx.getServerHandler().playerEntity.worldObj; TileEntity tileEntity = world.getTileEntity(message.blockX, message.blockY, message.blockZ); - BlockState blockState = new BlockState(message.blockX, message.blockY, message.blockZ, message.block, message.blockDamage); - if (tileEntity instanceof MultiTile bigDoorTE) - { + BlockState blockState = new BlockState( + message.blockX, + message.blockY, + message.blockZ, + message.block, + message.blockDamage); + if (tileEntity instanceof MultiTile bigDoorTE) { bigDoorTE.setFrameState(blockState); } return null; } - public static void SendFrameUpdateMessage(TileEntity te, Block block, int damage) - { - FrameUpdateMessage.Packet packet = new FrameUpdateMessage.Packet(block, te.xCoord, te.yCoord, te.zCoord, damage); + public static void SendFrameUpdateMessage(TileEntity te, Block block, int damage) { + FrameUpdateMessage.Packet packet = new FrameUpdateMessage.Packet( + block, + te.xCoord, + te.yCoord, + te.zCoord, + damage); MalisisDoors.network.sendToServer(packet); } @@ -49,17 +58,17 @@ public static class Packet implements IMessage { private int blockDamage; public Packet() {} - public Packet(Block block, int x, int y, int z, int damage) - { + + public Packet(Block block, int x, int y, int z, int damage) { this.block = block; this.blockX = x; this.blockY = y; this.blockZ = z; this.blockDamage = damage; } + @Override - public void fromBytes(ByteBuf buf) - { + public void fromBytes(ByteBuf buf) { this.blockX = buf.readInt(); this.blockY = buf.readInt(); this.blockZ = buf.readInt(); @@ -68,8 +77,7 @@ public void fromBytes(ByteBuf buf) } @Override - public void toBytes(ByteBuf buf) - { + public void toBytes(ByteBuf buf) { buf.writeInt(this.blockX); buf.writeInt(this.blockY); buf.writeInt(this.blockZ); diff --git a/src/main/java/net/malisis/doors/renderer/CustomDoorBoundingBoxRenderer.java b/src/main/java/net/malisis/doors/renderer/CustomDoorBoundingBoxRenderer.java index 1dedfdf..b746acd 100644 --- a/src/main/java/net/malisis/doors/renderer/CustomDoorBoundingBoxRenderer.java +++ b/src/main/java/net/malisis/doors/renderer/CustomDoorBoundingBoxRenderer.java @@ -1,28 +1,22 @@ package net.malisis.doors.renderer; -import net.malisis.core.block.BoundingBoxType; import net.malisis.core.util.ComplexAxisAlignedBoundingBox; -import net.malisis.doors.door.block.BigDoor; import net.malisis.doors.door.block.CollisionHelperBlock; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderGlobal; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; + import org.apache.commons.lang3.tuple.Pair; import org.lwjgl.opengl.GL11; -import static net.minecraft.client.renderer.RenderGlobal.drawOutlinedBoundingBox; +public class CustomDoorBoundingBoxRenderer { -public class CustomDoorBoundingBoxRenderer -{ - public void renderOpenDoorBoundingBox(World world, CollisionHelperBlock block, EntityPlayer player, float partialTicks, MovingObjectPosition target) - { + public void renderOpenDoorBoundingBox(World world, CollisionHelperBlock block, EntityPlayer player, + float partialTicks, MovingObjectPosition target) { GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F); @@ -32,11 +26,12 @@ public void renderOpenDoorBoundingBox(World world, CollisionHelperBlock block, E float f1 = 0.002F; block.setBlockBoundsBasedOnState(world, target.blockX, target.blockY, target.blockZ); - double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks; - double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks; - double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks; + double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks; + double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks; + double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks; - ComplexAxisAlignedBoundingBox CAABB = block.getComplexBoundingBox(world, target.blockX, target.blockY, target.blockZ); + ComplexAxisAlignedBoundingBox CAABB = block + .getComplexBoundingBox(world, target.blockX, target.blockY, target.blockZ); CAABB.addOffset(-d0, -d1, -d2); @@ -47,49 +42,40 @@ public void renderOpenDoorBoundingBox(World world, CollisionHelperBlock block, E GL11.glDisable(GL11.GL_BLEND); } - public static void renderComplexAABB(ComplexAxisAlignedBoundingBox CAABB, int color) - { + public static void renderComplexAABB(ComplexAxisAlignedBoundingBox CAABB, int color) { Tessellator tessellator = Tessellator.instance; - if (color != -1) - { + if (color != -1) { tessellator.setColorOpaque_I(color); } renderHorizontalFaces(CAABB.flatSurfaces, tessellator); renderVerticals(CAABB.verticals, tessellator); } - private static void renderVerticals(Pair[] lines, Tessellator tessellator) - { + private static void renderVerticals(Pair[] lines, Tessellator tessellator) { tessellator.startDrawing(1); - for (Pair line : lines) - { + for (Pair line : lines) { tessellator.addVertex(line.getRight().xCoord, line.getRight().yCoord, line.getRight().zCoord); tessellator.addVertex(line.getLeft().xCoord, line.getLeft().yCoord, line.getLeft().zCoord); } tessellator.draw(); } - private static void renderHorizontalFaces(Vec3[][] faces, Tessellator tessellator) - { - for(Vec3[] face : faces) - { + private static void renderHorizontalFaces(Vec3[][] faces, Tessellator tessellator) { + for (Vec3[] face : faces) { tessellator.startDrawing(3); - for (Vec3 vertex : face) - { - tessellator.addVertex(vertex.xCoord,vertex.yCoord,vertex.zCoord); + for (Vec3 vertex : face) { + tessellator.addVertex(vertex.xCoord, vertex.yCoord, vertex.zCoord); } tessellator.addVertex(face[0].xCoord, face[0].yCoord, face[0].zCoord); tessellator.draw(); } } - public static void drawOutlineBoundingBoxWithMultipleBoxes(AxisAlignedBB AABB, int color) - { + public static void drawOutlineBoundingBoxWithMultipleBoxes(AxisAlignedBB AABB, int color) { Tessellator tessellator = Tessellator.instance; tessellator.startDrawing(3); - if (color != -1) - { + if (color != -1) { tessellator.setColorOpaque_I(color); } From 22a602cd811c699534bdc0cf5db91a23b86b6a0a Mon Sep 17 00:00:00 2001 From: rjnasers Date: Wed, 11 Sep 2024 21:28:37 -0500 Subject: [PATCH 08/14] Need to figure out some more stuff with registration and block drops. Also need to check for blocks that are in the door opening or behind the door. --- .../java/net/malisis/doors/Registers.java | 8 ++++++- .../door/tileentity/BigDoorTileEntity.java | 22 ++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/malisis/doors/Registers.java b/src/main/java/net/malisis/doors/Registers.java index d1a8717..3a4aef5 100644 --- a/src/main/java/net/malisis/doors/Registers.java +++ b/src/main/java/net/malisis/doors/Registers.java @@ -473,7 +473,13 @@ private static void registerCollisionHelperBlocks() { GameRegistry.registerBlock( collisionHelperBlock, collisionHelperBlock.getUnlocalizedName() - .substring(5)); + .substring(5) + "_" + BigDoor.Type.MEDIEVAL); + + collisionHelperBlock = new CollisionHelperBlock(BigDoor.Type.CARRIAGE); + GameRegistry.registerBlock( + collisionHelperBlock, + collisionHelperBlock.getUnlocalizedName() + .substring(5) + "_" + BigDoor.Type.CARRIAGE); GameRegistry.registerTileEntity(MultiTile.class, "collisionHelperTileEntity"); diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index eef1090..ca13e53 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -132,11 +132,8 @@ public boolean isPowered() { @Override public void setDoorState(DoorState newState) { - super.setDoorState(newState); - // if (!this.worldObj.isRemote) - // { this.onStateChange(newState); - // } + super.setDoorState(newState); } @Override @@ -211,13 +208,19 @@ public void onCreate(int x, int y, int z, int meta) { } + // This blocks meta is not to be trusted for state. I eventually need to look into why this is but it breaks stuff + // to try to use the meta. Use this.state instead. @Override public void onDestroy(Block blockToDrop, TileEntity callingBlock, int meta) { if (!this.changingState) { int metaToUse = meta; - if (this.state == DoorState.OPENING && metaToUse < 4) { + if ((this.state == DoorState.OPENING || this.state == DoorState.CLOSING || this.state == DoorState.OPENED ) && metaToUse < 4) { metaToUse += 4; } + else if (this.state == DoorState.CLOSED && metaToUse > 3) + { + metaToUse -= 4; + } this.changingState = true; removeBluePrint(this.worldObj, xCoord, yCoord, zCoord, metaToUse, callingBlock, blockToDrop); this.changingState = false; @@ -228,13 +231,16 @@ public void onDestroy(Block blockToDrop, TileEntity callingBlock, int meta) { // the door. public void onStateChange(DoorState newState) { if (this.state == newState) return; - int meta = this.mainBlockMeta; - if (newState == DoorState.OPENING && meta < 4) { + if (getWorldObj() == null) return; // On startup the worldObj is null for some reason + int meta = this.getBlockMetadata(); + if (newState == DoorState.OPENING) { this.changingState = true; - placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, (meta + 4) % 8, true); + if (meta < 4) meta = (meta + 4) % 8; + placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, meta, true); this.changingState = false; } else if (newState == DoorState.CLOSED) { this.changingState = true; + if (meta > 3) meta -= 4; placeBluePrint(this.worldObj, xCoord, yCoord, zCoord, meta, true); this.changingState = false; } From d7e1e8eb824c1340e5bcf035a0bb22647f5a5f56 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Thu, 12 Sep 2024 20:35:53 -0500 Subject: [PATCH 09/14] More done --- .../java/net/malisis/doors/MalisisDoors.java | 3 +- .../java/net/malisis/doors/Registers.java | 12 ++-- .../net/malisis/doors/door/block/BigDoor.java | 8 ++- .../door/block/CollisionHelperBlock.java | 5 +- .../door/tileentity/BigDoorTileEntity.java | 61 ++++++++++++------- .../doors/door/tileentity/IBluePrint.java | 2 +- .../doors/door/tileentity/IMultiBlock.java | 2 +- .../doors/door/tileentity/MultiTile.java | 4 +- 8 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/main/java/net/malisis/doors/MalisisDoors.java b/src/main/java/net/malisis/doors/MalisisDoors.java index e3bbb5b..5863086 100644 --- a/src/main/java/net/malisis/doors/MalisisDoors.java +++ b/src/main/java/net/malisis/doors/MalisisDoors.java @@ -138,7 +138,8 @@ public static class Blocks { public static Block ironTrapDoor; public static Block slidingTrapDoor; public static Block saloonDoor; - public static Block collisionHelperBlock; + public static Block collisionHelperBlockMedieval; + public static Block collisionHelperBlockCarriage; } public static class Items { diff --git a/src/main/java/net/malisis/doors/Registers.java b/src/main/java/net/malisis/doors/Registers.java index 3a4aef5..4344a32 100644 --- a/src/main/java/net/malisis/doors/Registers.java +++ b/src/main/java/net/malisis/doors/Registers.java @@ -469,16 +469,16 @@ private static void registerForcefieldDoor() { } private static void registerCollisionHelperBlocks() { - collisionHelperBlock = new CollisionHelperBlock(BigDoor.Type.MEDIEVAL); + collisionHelperBlockMedieval = new CollisionHelperBlock(BigDoor.Type.MEDIEVAL); GameRegistry.registerBlock( - collisionHelperBlock, - collisionHelperBlock.getUnlocalizedName() + collisionHelperBlockMedieval, + collisionHelperBlockMedieval.getUnlocalizedName() .substring(5) + "_" + BigDoor.Type.MEDIEVAL); - collisionHelperBlock = new CollisionHelperBlock(BigDoor.Type.CARRIAGE); + collisionHelperBlockCarriage = new CollisionHelperBlock(BigDoor.Type.CARRIAGE); GameRegistry.registerBlock( - collisionHelperBlock, - collisionHelperBlock.getUnlocalizedName() + collisionHelperBlockCarriage, + collisionHelperBlockCarriage.getUnlocalizedName() .substring(5) + "_" + BigDoor.Type.CARRIAGE); GameRegistry.registerTileEntity(MultiTile.class, "collisionHelperTileEntity"); diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index 7ebce37..4b3aef4 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -187,7 +187,7 @@ public void breakBlock(World world, int x, int y, int z, Block block, int meta) } TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity instanceof IMultiBlock) { - ((IMultiBlock) tileEntity).onDestroy(block, tileEntity, meta); + ((IMultiBlock) tileEntity).onDestroy(tileEntity, meta); } super.breakBlock(world, x, y, z, block, meta); } @@ -265,7 +265,7 @@ public ComplexAxisAlignedBoundingBox getComplexBoundingBoxWithOffset(IBlockAcces @Override public TileEntity createNewTileEntity(World world, int metadata) { - return new BigDoorTileEntity(); + return new BigDoorTileEntity(this.type); } @SuppressWarnings("deprecation") @@ -293,6 +293,10 @@ public int getRenderType() { return renderId; } + public BigDoor.Type getType() + { + return type; + } @Override public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { this.setBlockBounds( diff --git a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java index 1ff4a3e..9e22cf8 100644 --- a/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java +++ b/src/main/java/net/malisis/doors/door/block/CollisionHelperBlock.java @@ -32,7 +32,7 @@ public class CollisionHelperBlock extends BlockContainer implements ITileEntityProvider { - BigDoor.Type type; + public BigDoor.Type type; private IIcon[] fakeIcons; @@ -91,8 +91,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer E public void breakBlock(World world, int x, int y, int z, Block block, int meta) { final TileEntity tileEntity = world.getTileEntity(x, y, z); if (tileEntity instanceof MultiTile) { - ((MultiTile) tileEntity).onBlockRemoval( - type == BigDoor.Type.MEDIEVAL ? MalisisDoors.Blocks.medievalDoor : MalisisDoors.Blocks.carriageDoor); + ((MultiTile) tileEntity).onBlockRemoval(); } super.breakBlock(world, x, y, z, block, meta); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index ca13e53..7536234 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -91,8 +91,9 @@ public class BigDoorTileEntity extends MultiTile implements IMultiBlock, IBluePr private final MultiBlueprint closedBlueprint = new MultiBlueprint(closedPrint, metaMap, new Vector3i(1, 0, 0)); private final MultiBlueprint openBlueprint = new MultiBlueprint(openPrint, metaMap, new Vector3i(1, 0, 0)); - - public BigDoorTileEntity() { + private final BigDoor.Type type; + public BigDoorTileEntity(BigDoor.Type type) { + this.type = type; DoorDescriptor descriptor = new DoorDescriptor(); descriptor.setMovement(DoorRegistry.getMovement(CarriageDoorMovement.class)); descriptor.setSound(DoorRegistry.getSound(CarriageDoorSound.class)); @@ -211,7 +212,7 @@ public void onCreate(int x, int y, int z, int meta) { // This blocks meta is not to be trusted for state. I eventually need to look into why this is but it breaks stuff // to try to use the meta. Use this.state instead. @Override - public void onDestroy(Block blockToDrop, TileEntity callingBlock, int meta) { + public void onDestroy(TileEntity callingBlock, int meta) { if (!this.changingState) { int metaToUse = meta; if ((this.state == DoorState.OPENING || this.state == DoorState.CLOSING || this.state == DoorState.OPENED ) && metaToUse < 4) { @@ -222,7 +223,7 @@ else if (this.state == DoorState.CLOSED && metaToUse > 3) metaToUse -= 4; } this.changingState = true; - removeBluePrint(this.worldObj, xCoord, yCoord, zCoord, metaToUse, callingBlock, blockToDrop); + removeBluePrint(this.worldObj, xCoord, yCoord, zCoord, metaToUse, callingBlock); this.changingState = false; } } @@ -303,16 +304,32 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr { if (!(i == print.startingLocation.x && j == print.startingLocation.y && k == print.startingLocation.z) && print.bluePrint[j][i][k] > -1) { - ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlock).makeCollisionHelperBlock( - world, - x - mainBlockRelativeX + i, - y - mainBlockRelativeY + j, - z + mainBlockRelativeZ - k, - print.bluePrint[j][i][k], - this.xCoord, - this.yCoord, - this.zCoord, - this.getBlockMetadata()); + + switch(this.type) + { + case CARRIAGE -> + ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockCarriage).makeCollisionHelperBlock( + world, + x - mainBlockRelativeX + i, + y - mainBlockRelativeY + j, + z + mainBlockRelativeZ - k, + print.bluePrint[j][i][k], + this.xCoord, + this.yCoord, + this.zCoord, + this.getBlockMetadata()); + case MEDIEVAL -> + ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockMedieval).makeCollisionHelperBlock( + world, + x - mainBlockRelativeX + i, + y - mainBlockRelativeY + j, + z + mainBlockRelativeZ - k, + print.bluePrint[j][i][k], + this.xCoord, + this.yCoord, + this.zCoord, + this.getBlockMetadata()); + } } else if (print.bluePrint[j][i][k] == Integer.MIN_VALUE && removeBlockInWay) { world.setBlockToAir( x - mainBlockRelativeX + i, @@ -325,33 +342,33 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr } @Override - public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock, - Block blockToDrop) { + public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock) { MultiBlueprint print = (meta < 4 ? this.closedBlueprint : this.openBlueprint); switch (meta) { case 0, 4: - this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); break; case 1, 5: print.rotate(MultiBlueprint.RotationDegrees.ROT90); - this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); print.rotate(MultiBlueprint.RotationDegrees.ROT270); break; case 2, 6: print.rotate(MultiBlueprint.RotationDegrees.ROT180); - this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); print.rotate(MultiBlueprint.RotationDegrees.ROT180); break; case 3, 7: print.rotate(MultiBlueprint.RotationDegrees.ROT270); - this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock, blockToDrop); + this.bluePrintRemovalHelper(world, x, y, z, print, callingBlock); print.rotate(MultiBlueprint.RotationDegrees.ROT90); break; } } - private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, TileEntity callingBlock, - Block blockToDrop) { + private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, TileEntity callingBlock) { + + Block blockToDrop = this.type == BigDoor.Type.CARRIAGE ? MalisisDoors.Blocks.carriageDoor : MalisisDoors.Blocks.medievalDoor; int mainBlockRelativeX = print.startingLocation.x; int mainBlockRelativeY = print.startingLocation.y; int mainBlockRelativeZ = print.startingLocation.z; diff --git a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java index 0649bdc..9e00435 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java @@ -8,5 +8,5 @@ public interface IBluePrint { public void placeBluePrint(World world, int x, int y, int z, int meta, boolean removeBlockInWay); - public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock, Block blockToDrop); + public void removeBluePrint(World world, int x, int y, int z, int meta, TileEntity callingBlock); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java index db18519..b17baae 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java @@ -26,6 +26,6 @@ public interface IMultiBlock { * * @param callingBlock - The tile entity who called the onDestroy function */ - void onDestroy(Block block, TileEntity callingBlock, int meta); + void onDestroy(TileEntity callingBlock, int meta); } diff --git a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java index 0991e0c..57f9dd0 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java +++ b/src/main/java/net/malisis/doors/door/tileentity/MultiTile.java @@ -29,11 +29,11 @@ public void setMainBlock(int x, int y, int z) { } } - public void onBlockRemoval(Block block) { + public void onBlockRemoval() { TileEntity mainBlock = getMainBlockTile(); if (mainBlock != null) { if (mainBlock instanceof IMultiBlock) { - ((IMultiBlock) mainBlock).onDestroy(block, this, this.mainBlockMeta); + ((IMultiBlock) mainBlock).onDestroy(this, this.mainBlockMeta); } } } From 3561d4a09e4d2c155c2b97b81fa70a9c8e1d8959 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Thu, 12 Sep 2024 22:40:25 -0500 Subject: [PATCH 10/14] Finished I think --- .../door/tileentity/BigDoorTileEntity.java | 142 +++++++++++++++++- 1 file changed, 141 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index 7536234..6435c96 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -43,6 +43,7 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -106,6 +107,7 @@ public BlockState getFrameState() { return frameState; } + @Override public void setFrameState(BlockState state) { if (state != null) frameState = state; this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); @@ -190,7 +192,145 @@ public AxisAlignedBB getRenderBoundingBox() { @Override public boolean onActivated(EntityPlayer entityPlayer) { if (!this.worldObj.isRemote) { - this.openOrCloseDoor(); + if (hasRoomToOpenOrClose()) + { + this.openOrCloseDoor(); + } + else + { + entityPlayer.addChatMessage(new ChatComponentText("There's no room for the door to open or close!")); + } + } + return true; + } + + private boolean hasRoomToOpenOrClose() + { + int meta = this.getBlockMetadata() % 4; // We don't care if it's closed or open we just want to know what direction it's facing + return switch (this.state) { + case CLOSED -> doorsCanSwingOpen(meta); + case OPENED, OPENING -> doorsCanClose(meta); + case CLOSING -> true; + }; + } + + // Check if there's nothing inside of the doors. + private boolean doorsCanClose(int meta) + { + switch (meta) + { + case 0: + for (int yRel = 0; yRel < 4; yRel++) + { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 1) != Blocks.air) + { + return false; + } + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 2) != Blocks.air) + { + return false; + } + } + break; + case 1: + for (int yRel = 0; yRel < 4; yRel++) + { + if (worldObj.getBlock(xCoord + 1,yCoord + yRel,zCoord) != Blocks.air) + { + return false; + } + if (worldObj.getBlock(xCoord + 2,yCoord + yRel,zCoord) != Blocks.air) + { + return false; + } + } + break; + case 2: + for (int yRel = 0; yRel < 4; yRel++) + { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 1) != Blocks.air) + { + return false; + } + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 2) != Blocks.air) + { + return false; + } + } + break; + case 3: + for (int yRel = 0; yRel < 4; yRel++) + { + if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord) != Blocks.air) + { + return false; + } + if (worldObj.getBlock(xCoord - 2, yCoord + yRel, zCoord) != Blocks.air) + { + return false; + } + } + break; + } + return true; + } + + private boolean doorsCanSwingOpen(int meta) + { + switch (meta) + { + case 0: + for (int yRel = 0; yRel < 4; yRel++) + { + if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord) != Blocks.air) + { + return false; + } + if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord - 3) != Blocks.air) + { + return false; + } + } + break; + case 1: + for (int yRel = 0; yRel < 4; yRel++) + { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 1) != Blocks.air) + { + return false; + } + if (worldObj.getBlock(xCoord + 3, yCoord + yRel, zCoord - 1) != Blocks.air) + { + return false; + } + } + break; + case 2: + for (int yRel = 0; yRel < 4; yRel++) + { + if (worldObj.getBlock(xCoord + 1, yCoord + yRel, zCoord) != Blocks.air) + { + return false; + } + if (worldObj.getBlock(xCoord + 1, yCoord + yRel, zCoord + 3) != Blocks.air) + { + return false; + } + } + break; + case 3: + for (int yRel = 0; yRel < 4; yRel++) + { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 1) != Blocks.air) + { + return false; + } + if (worldObj.getBlock(xCoord + 3, yCoord + yRel, zCoord + 1) != Blocks.air) + { + return false; + } + } + break; } return true; } From 3946ce983cd799f8b508f57b6c3627636aaf070a Mon Sep 17 00:00:00 2001 From: rjnasers Date: Thu, 12 Sep 2024 22:43:12 -0500 Subject: [PATCH 11/14] spotless --- .../java/net/malisis/doors/Registers.java | 6 +- .../net/malisis/doors/door/block/BigDoor.java | 4 +- .../door/tileentity/BigDoorTileEntity.java | 122 +++++++----------- .../doors/door/tileentity/IBluePrint.java | 1 - .../doors/door/tileentity/IMultiBlock.java | 1 - 5 files changed, 52 insertions(+), 82 deletions(-) diff --git a/src/main/java/net/malisis/doors/Registers.java b/src/main/java/net/malisis/doors/Registers.java index 4344a32..595df2b 100644 --- a/src/main/java/net/malisis/doors/Registers.java +++ b/src/main/java/net/malisis/doors/Registers.java @@ -473,13 +473,15 @@ private static void registerCollisionHelperBlocks() { GameRegistry.registerBlock( collisionHelperBlockMedieval, collisionHelperBlockMedieval.getUnlocalizedName() - .substring(5) + "_" + BigDoor.Type.MEDIEVAL); + .substring(5) + "_" + + BigDoor.Type.MEDIEVAL); collisionHelperBlockCarriage = new CollisionHelperBlock(BigDoor.Type.CARRIAGE); GameRegistry.registerBlock( collisionHelperBlockCarriage, collisionHelperBlockCarriage.getUnlocalizedName() - .substring(5) + "_" + BigDoor.Type.CARRIAGE); + .substring(5) + "_" + + BigDoor.Type.CARRIAGE); GameRegistry.registerTileEntity(MultiTile.class, "collisionHelperTileEntity"); diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index 4b3aef4..86eeb6a 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -293,10 +293,10 @@ public int getRenderType() { return renderId; } - public BigDoor.Type getType() - { + public BigDoor.Type getType() { return type; } + @Override public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { this.setBlockBounds( diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index 6435c96..bbff62f 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -93,6 +93,7 @@ public class BigDoorTileEntity extends MultiTile implements IMultiBlock, IBluePr private final MultiBlueprint closedBlueprint = new MultiBlueprint(closedPrint, metaMap, new Vector3i(1, 0, 0)); private final MultiBlueprint openBlueprint = new MultiBlueprint(openPrint, metaMap, new Vector3i(1, 0, 0)); private final BigDoor.Type type; + public BigDoorTileEntity(BigDoor.Type type) { this.type = type; DoorDescriptor descriptor = new DoorDescriptor(); @@ -192,21 +193,18 @@ public AxisAlignedBB getRenderBoundingBox() { @Override public boolean onActivated(EntityPlayer entityPlayer) { if (!this.worldObj.isRemote) { - if (hasRoomToOpenOrClose()) - { + if (hasRoomToOpenOrClose()) { this.openOrCloseDoor(); - } - else - { + } else { entityPlayer.addChatMessage(new ChatComponentText("There's no room for the door to open or close!")); } } return true; } - private boolean hasRoomToOpenOrClose() - { - int meta = this.getBlockMetadata() % 4; // We don't care if it's closed or open we just want to know what direction it's facing + private boolean hasRoomToOpenOrClose() { + int meta = this.getBlockMetadata() % 4; // We don't care if it's closed or open we just want to know what + // direction it's facing return switch (this.state) { case CLOSED -> doorsCanSwingOpen(meta); case OPENED, OPENING -> doorsCanClose(meta); @@ -215,58 +213,44 @@ private boolean hasRoomToOpenOrClose() } // Check if there's nothing inside of the doors. - private boolean doorsCanClose(int meta) - { - switch (meta) - { + private boolean doorsCanClose(int meta) { + switch (meta) { case 0: - for (int yRel = 0; yRel < 4; yRel++) - { - if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 1) != Blocks.air) - { + for (int yRel = 0; yRel < 4; yRel++) { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 1) != Blocks.air) { return false; } - if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 2) != Blocks.air) - { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 2) != Blocks.air) { return false; } } break; case 1: - for (int yRel = 0; yRel < 4; yRel++) - { - if (worldObj.getBlock(xCoord + 1,yCoord + yRel,zCoord) != Blocks.air) - { + for (int yRel = 0; yRel < 4; yRel++) { + if (worldObj.getBlock(xCoord + 1, yCoord + yRel, zCoord) != Blocks.air) { return false; } - if (worldObj.getBlock(xCoord + 2,yCoord + yRel,zCoord) != Blocks.air) - { + if (worldObj.getBlock(xCoord + 2, yCoord + yRel, zCoord) != Blocks.air) { return false; } } break; case 2: - for (int yRel = 0; yRel < 4; yRel++) - { - if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 1) != Blocks.air) - { + for (int yRel = 0; yRel < 4; yRel++) { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 1) != Blocks.air) { return false; } - if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 2) != Blocks.air) - { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 2) != Blocks.air) { return false; } } break; case 3: - for (int yRel = 0; yRel < 4; yRel++) - { - if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord) != Blocks.air) - { + for (int yRel = 0; yRel < 4; yRel++) { + if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord) != Blocks.air) { return false; } - if (worldObj.getBlock(xCoord - 2, yCoord + yRel, zCoord) != Blocks.air) - { + if (worldObj.getBlock(xCoord - 2, yCoord + yRel, zCoord) != Blocks.air) { return false; } } @@ -275,58 +259,44 @@ private boolean doorsCanClose(int meta) return true; } - private boolean doorsCanSwingOpen(int meta) - { - switch (meta) - { + private boolean doorsCanSwingOpen(int meta) { + switch (meta) { case 0: - for (int yRel = 0; yRel < 4; yRel++) - { - if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord) != Blocks.air) - { + for (int yRel = 0; yRel < 4; yRel++) { + if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord) != Blocks.air) { return false; } - if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord - 3) != Blocks.air) - { + if (worldObj.getBlock(xCoord - 1, yCoord + yRel, zCoord - 3) != Blocks.air) { return false; } } break; case 1: - for (int yRel = 0; yRel < 4; yRel++) - { - if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 1) != Blocks.air) - { + for (int yRel = 0; yRel < 4; yRel++) { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord - 1) != Blocks.air) { return false; } - if (worldObj.getBlock(xCoord + 3, yCoord + yRel, zCoord - 1) != Blocks.air) - { + if (worldObj.getBlock(xCoord + 3, yCoord + yRel, zCoord - 1) != Blocks.air) { return false; } } break; case 2: - for (int yRel = 0; yRel < 4; yRel++) - { - if (worldObj.getBlock(xCoord + 1, yCoord + yRel, zCoord) != Blocks.air) - { + for (int yRel = 0; yRel < 4; yRel++) { + if (worldObj.getBlock(xCoord + 1, yCoord + yRel, zCoord) != Blocks.air) { return false; } - if (worldObj.getBlock(xCoord + 1, yCoord + yRel, zCoord + 3) != Blocks.air) - { + if (worldObj.getBlock(xCoord + 1, yCoord + yRel, zCoord + 3) != Blocks.air) { return false; } } break; case 3: - for (int yRel = 0; yRel < 4; yRel++) - { - if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 1) != Blocks.air) - { + for (int yRel = 0; yRel < 4; yRel++) { + if (worldObj.getBlock(xCoord, yCoord + yRel, zCoord + 1) != Blocks.air) { return false; } - if (worldObj.getBlock(xCoord + 3, yCoord + yRel, zCoord + 1) != Blocks.air) - { + if (worldObj.getBlock(xCoord + 3, yCoord + yRel, zCoord + 1) != Blocks.air) { return false; } } @@ -355,11 +325,10 @@ public void onCreate(int x, int y, int z, int meta) { public void onDestroy(TileEntity callingBlock, int meta) { if (!this.changingState) { int metaToUse = meta; - if ((this.state == DoorState.OPENING || this.state == DoorState.CLOSING || this.state == DoorState.OPENED ) && metaToUse < 4) { + if ((this.state == DoorState.OPENING || this.state == DoorState.CLOSING || this.state == DoorState.OPENED) + && metaToUse < 4) { metaToUse += 4; - } - else if (this.state == DoorState.CLOSED && metaToUse > 3) - { + } else if (this.state == DoorState.CLOSED && metaToUse > 3) { metaToUse -= 4; } this.changingState = true; @@ -445,10 +414,9 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr if (!(i == print.startingLocation.x && j == print.startingLocation.y && k == print.startingLocation.z) && print.bluePrint[j][i][k] > -1) { - switch(this.type) - { - case CARRIAGE -> - ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockCarriage).makeCollisionHelperBlock( + switch (this.type) { + case CARRIAGE -> ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockCarriage) + .makeCollisionHelperBlock( world, x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, @@ -458,8 +426,8 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr this.yCoord, this.zCoord, this.getBlockMetadata()); - case MEDIEVAL -> - ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockMedieval).makeCollisionHelperBlock( + case MEDIEVAL -> ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockMedieval) + .makeCollisionHelperBlock( world, x - mainBlockRelativeX + i, y - mainBlockRelativeY + j, @@ -506,9 +474,11 @@ public void removeBluePrint(World world, int x, int y, int z, int meta, TileEnti } } - private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, TileEntity callingBlock) { + private void bluePrintRemovalHelper(World world, int x, int y, int z, MultiBlueprint print, + TileEntity callingBlock) { - Block blockToDrop = this.type == BigDoor.Type.CARRIAGE ? MalisisDoors.Blocks.carriageDoor : MalisisDoors.Blocks.medievalDoor; + Block blockToDrop = this.type == BigDoor.Type.CARRIAGE ? MalisisDoors.Blocks.carriageDoor + : MalisisDoors.Blocks.medievalDoor; int mainBlockRelativeX = print.startingLocation.x; int mainBlockRelativeY = print.startingLocation.y; int mainBlockRelativeZ = print.startingLocation.z; diff --git a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java index 9e00435..3858888 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IBluePrint.java @@ -1,6 +1,5 @@ package net.malisis.doors.door.tileentity; -import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; diff --git a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java index b17baae..375d078 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java +++ b/src/main/java/net/malisis/doors/door/tileentity/IMultiBlock.java @@ -1,6 +1,5 @@ package net.malisis.doors.door.tileentity; -import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; From ae725d7ee0877f3862312535fec3f13fd901b369 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Sat, 14 Sep 2024 16:14:13 -0500 Subject: [PATCH 12/14] Spotless for real this time. --- src/main/java/net/malisis/doors/network/FrameUpdateMessage.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java b/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java index a1975c9..7433506 100644 --- a/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java +++ b/src/main/java/net/malisis/doors/network/FrameUpdateMessage.java @@ -1,7 +1,5 @@ package net.malisis.doors.network; -import java.awt.*; - import net.malisis.core.network.MalisisMessage; import net.malisis.core.util.BlockState; import net.malisis.doors.MalisisDoors; From d631ba5d3761a99b4f62659d869d0713cb752462 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Sat, 14 Sep 2024 20:28:29 -0500 Subject: [PATCH 13/14] Fixing a bunch of shit I fucked up and fixing rendering on server on accident --- .../java/net/malisis/doors/MalisisDoors.java | 4 +- .../net/malisis/doors/door/block/BigDoor.java | 13 +---- .../door/tileentity/BigDoorTileEntity.java | 31 +++++++++-- ...ndler.java => DoorEventHandlerClient.java} | 37 +------------- .../doors/event/DoorEventHandlerCommon.java | 51 +++++++++++++++++++ .../net/malisis/doors/proxy/ClientProxy.java | 8 +++ .../java/net/malisis/doors/proxy/IProxy.java | 6 ++- .../net/malisis/doors/proxy/ServerProxy.java | 8 +++ 8 files changed, 101 insertions(+), 57 deletions(-) rename src/main/java/net/malisis/doors/event/{DoorEventHandler.java => DoorEventHandlerClient.java} (57%) create mode 100644 src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java diff --git a/src/main/java/net/malisis/doors/MalisisDoors.java b/src/main/java/net/malisis/doors/MalisisDoors.java index 5863086..5345412 100644 --- a/src/main/java/net/malisis/doors/MalisisDoors.java +++ b/src/main/java/net/malisis/doors/MalisisDoors.java @@ -20,7 +20,7 @@ import net.malisis.doors.door.block.ForcefieldDoor; import net.malisis.doors.door.block.RustyHatch; import net.malisis.doors.door.item.ForcefieldItem; -import net.malisis.doors.event.DoorEventHandler; +import net.malisis.doors.event.DoorEventHandlerClient; import net.malisis.doors.proxy.IProxy; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; @@ -91,7 +91,7 @@ public void preInit(FMLPreInitializationEvent event) { @EventHandler public void init(FMLInitializationEvent event) { - MinecraftForge.EVENT_BUS.register(new DoorEventHandler()); + proxy.initEventHandlers(); } @EventHandler diff --git a/src/main/java/net/malisis/doors/door/block/BigDoor.java b/src/main/java/net/malisis/doors/door/block/BigDoor.java index 86eeb6a..6e15404 100644 --- a/src/main/java/net/malisis/doors/door/block/BigDoor.java +++ b/src/main/java/net/malisis/doors/door/block/BigDoor.java @@ -55,6 +55,7 @@ public class BigDoor extends MalisisBlock implements ITileEntityProvider { public enum Type { + DEFAULT("carriage_door", net.minecraft.init.Items.wooden_door), CARRIAGE("carriage_door", net.minecraft.init.Items.wooden_door), MEDIEVAL("medieval_door", Items.doorSpruceItem); @@ -92,8 +93,6 @@ private Type(String name, Item door) { Pair.of(createVectorHelper(0, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(0, 5, 1 - Door.DOOR_WIDTH)), Pair.of(createVectorHelper(4, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 5, 1 - Door.DOOR_WIDTH)) }; - private final int DoorBlockWidth = 4; - private final int DoorBlockHeight = 5; public static int renderId; public static int renderPass = -1; private AxisAlignedBB defaultBoundingBox = AxisAlignedBB.getBoundingBox(0, 0, 1 - Door.DOOR_WIDTH, 4, 5, 1); @@ -268,16 +267,6 @@ public TileEntity createNewTileEntity(World world, int metadata) { return new BigDoorTileEntity(this.type); } - @SuppressWarnings("deprecation") - @Override - public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) { - if (!player.capabilities.isCreativeMode) { - BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z); - if (te != null) dropBlockAsItem(world, x, y, z, te.getDroppedItemStack()); - } - return super.removedByPlayer(world, player, x, y, z); - } - @Override public boolean isOpaqueCube() { return false; diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index bbff62f..d96dd4d 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -92,7 +92,17 @@ public class BigDoorTileEntity extends MultiTile implements IMultiBlock, IBluePr private final MultiBlueprint closedBlueprint = new MultiBlueprint(closedPrint, metaMap, new Vector3i(1, 0, 0)); private final MultiBlueprint openBlueprint = new MultiBlueprint(openPrint, metaMap, new Vector3i(1, 0, 0)); - private final BigDoor.Type type; + private BigDoor.Type type; + + public BigDoorTileEntity() { + this.type = BigDoor.Type.DEFAULT; + DoorDescriptor descriptor = new DoorDescriptor(); + descriptor.setMovement(DoorRegistry.getMovement(CarriageDoorMovement.class)); + descriptor.setSound(DoorRegistry.getSound(CarriageDoorSound.class)); + descriptor.setDoubleDoor(false); + descriptor.setOpeningTime(20); + setDescriptor(descriptor); + } public BigDoorTileEntity(BigDoor.Type type) { this.type = type; @@ -112,6 +122,7 @@ public BlockState getFrameState() { public void setFrameState(BlockState state) { if (state != null) frameState = state; this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + this.markDirty(); } @Override @@ -173,13 +184,23 @@ public void readFromNBT(NBTTagCompound tag) { direction = mb.getDirection(); processed = false; } - - frameState = Objects.firstNonNull(BlockState.fromNBT(tag), new BlockState(defaultBorderBlock)); + int typeInt = tag.getInteger("type"); + switch (typeInt) + { + case 0,1: + this.type = BigDoor.Type.CARRIAGE; + break; + case 2: + this.type = BigDoor.Type.MEDIEVAL; + break; + } + this.frameState = Objects.firstNonNull(BlockState.fromNBT(tag), new BlockState(defaultBorderBlock)); } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); + nbt.setInteger("type", this.type.ordinal()); BlockState.toNBT(nbt, frameState); } @@ -411,8 +432,8 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr { for (int k = 0; k < print.bluePrint[0][0].length; k++) // z { - if (!(i == print.startingLocation.x && j == print.startingLocation.y - && k == print.startingLocation.z) && print.bluePrint[j][i][k] > -1) { + if (!(i == mainBlockRelativeX && j == mainBlockRelativeY + && k == mainBlockRelativeZ) && print.bluePrint[j][i][k] > -1) { switch (this.type) { case CARRIAGE -> ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockCarriage) diff --git a/src/main/java/net/malisis/doors/event/DoorEventHandler.java b/src/main/java/net/malisis/doors/event/DoorEventHandlerClient.java similarity index 57% rename from src/main/java/net/malisis/doors/event/DoorEventHandler.java rename to src/main/java/net/malisis/doors/event/DoorEventHandlerClient.java index 336a19b..024210f 100644 --- a/src/main/java/net/malisis/doors/event/DoorEventHandler.java +++ b/src/main/java/net/malisis/doors/event/DoorEventHandlerClient.java @@ -21,7 +21,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; -public class DoorEventHandler { +public class DoorEventHandlerClient extends DoorEventHandlerCommon { public CustomDoorBoundingBoxRenderer cdbbRenderer = new CustomDoorBoundingBoxRenderer(); @@ -56,39 +56,4 @@ public void onDrawBlockHighlight(DrawBlockHighlightEvent event) { } } } - - @SubscribeEvent - public void PlayerInteractEvent(PlayerInteractEvent event) { - TileEntity tileEntity = getTileEntityLookingAt(event.entityPlayer); - if (event.entityPlayer.isSneaking() && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) - && tileEntity instanceof MultiTile multiTile - && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { - ItemStack heldStack = event.entityPlayer.getHeldItem(); - if (heldStack != null) { - Block block = Block.getBlockFromItem(heldStack.getItem()); - int damageValue = heldStack.getItemDamage(); - if (block != null) { - event.setCanceled(true); - FrameUpdateMessage.SendFrameUpdateMessage(multiTile, block, damageValue); - } - } - } - } - - private TileEntity getTileEntityLookingAt(EntityPlayer player) { - Minecraft mc = Minecraft.getMinecraft(); - double maxReach = mc.playerController.getBlockReachDistance(); - Vec3 eyePosition = player.getPosition(1.0F); - Vec3 lookVector = player.getLook(1.0F); - Vec3 endPosition = eyePosition - .addVector(lookVector.xCoord * maxReach, lookVector.yCoord * maxReach, lookVector.zCoord * maxReach); - MovingObjectPosition rayTraceResult = mc.theWorld.rayTraceBlocks(eyePosition, endPosition); - if (rayTraceResult != null && rayTraceResult.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { - int blockX = rayTraceResult.blockX; - int blockY = rayTraceResult.blockY; - int blockZ = rayTraceResult.blockZ; - return mc.theWorld.getTileEntity(blockX, blockY, blockZ); - } - return null; - } } diff --git a/src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java b/src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java new file mode 100644 index 0000000..d8663a9 --- /dev/null +++ b/src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java @@ -0,0 +1,51 @@ +package net.malisis.doors.event; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.malisis.doors.door.tileentity.MultiTile; +import net.malisis.doors.network.FrameUpdateMessage; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import org.lwjgl.input.Keyboard; + +public class DoorEventHandlerCommon { + @SubscribeEvent + public void PlayerInteractEvent(PlayerInteractEvent event) { + TileEntity tileEntity = getTileEntityLookingAt(event.entityPlayer); + if (event.entityPlayer.isSneaking() && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) + && tileEntity instanceof MultiTile multiTile + && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { + ItemStack heldStack = event.entityPlayer.getHeldItem(); + if (heldStack != null) { + Block block = Block.getBlockFromItem(heldStack.getItem()); + int damageValue = heldStack.getItemDamage(); + if (block != null) { + event.setCanceled(true); + FrameUpdateMessage.SendFrameUpdateMessage(multiTile, block, damageValue); + } + } + } + } + + private TileEntity getTileEntityLookingAt(EntityPlayer player) { + Minecraft mc = Minecraft.getMinecraft(); + double maxReach = mc.playerController.getBlockReachDistance(); + Vec3 eyePosition = player.getPosition(1.0F); + Vec3 lookVector = player.getLook(1.0F); + Vec3 endPosition = eyePosition + .addVector(lookVector.xCoord * maxReach, lookVector.yCoord * maxReach, lookVector.zCoord * maxReach); + MovingObjectPosition rayTraceResult = mc.theWorld.rayTraceBlocks(eyePosition, endPosition); + if (rayTraceResult != null && rayTraceResult.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + int blockX = rayTraceResult.blockX; + int blockY = rayTraceResult.blockY; + int blockZ = rayTraceResult.blockZ; + return mc.theWorld.getTileEntity(blockX, blockY, blockZ); + } + return null; + } +} diff --git a/src/main/java/net/malisis/doors/proxy/ClientProxy.java b/src/main/java/net/malisis/doors/proxy/ClientProxy.java index 035955d..73dbb3c 100644 --- a/src/main/java/net/malisis/doors/proxy/ClientProxy.java +++ b/src/main/java/net/malisis/doors/proxy/ClientProxy.java @@ -28,6 +28,7 @@ import net.malisis.doors.door.tileentity.SaloonDoorTileEntity; import net.malisis.doors.entity.GarageDoorTileEntity; import net.malisis.doors.entity.VanishingTileEntity; +import net.malisis.doors.event.DoorEventHandlerClient; import net.malisis.doors.renderer.GarageDoorRenderer; import net.malisis.doors.renderer.MixedBlockRenderer; import net.malisis.doors.renderer.RustyLadderRenderer; @@ -37,6 +38,7 @@ import net.malisis.doors.trapdoor.tileentity.TrapDoorTileEntity; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.MinecraftForge; public class ClientProxy implements IProxy { @@ -100,4 +102,10 @@ public void initFonts() { ResourceLocation rl = new ResourceLocation(MalisisDoors.modid + ":fonts/digital-7 (mono).ttf"); MalisisDoors.digitalFont = new MalisisFont(rl); } + + @Override + public void initEventHandlers() + { + MinecraftForge.EVENT_BUS.register(new DoorEventHandlerClient()); + } } diff --git a/src/main/java/net/malisis/doors/proxy/IProxy.java b/src/main/java/net/malisis/doors/proxy/IProxy.java index 61f6c74..93512f0 100644 --- a/src/main/java/net/malisis/doors/proxy/IProxy.java +++ b/src/main/java/net/malisis/doors/proxy/IProxy.java @@ -19,7 +19,9 @@ */ public interface IProxy { - public void initRenderers(); + void initRenderers(); - public void initFonts(); + void initFonts(); + + void initEventHandlers(); } diff --git a/src/main/java/net/malisis/doors/proxy/ServerProxy.java b/src/main/java/net/malisis/doors/proxy/ServerProxy.java index 6549236..b433e40 100644 --- a/src/main/java/net/malisis/doors/proxy/ServerProxy.java +++ b/src/main/java/net/malisis/doors/proxy/ServerProxy.java @@ -13,6 +13,9 @@ package net.malisis.doors.proxy; +import net.malisis.doors.event.DoorEventHandlerCommon; +import net.minecraftforge.common.MinecraftForge; + /** * @author Ordinastie * @@ -24,4 +27,9 @@ public void initRenderers() {} @Override public void initFonts() {} + + @Override + public void initEventHandlers() { + MinecraftForge.EVENT_BUS.register(new DoorEventHandlerCommon()); + } } From 515487b8732cc2c0843ffd9bc912e6838d3b6a17 Mon Sep 17 00:00:00 2001 From: rjnasers Date: Sat, 14 Sep 2024 20:34:16 -0500 Subject: [PATCH 14/14] spot --- src/main/java/net/malisis/doors/MalisisDoors.java | 2 -- .../malisis/doors/door/tileentity/BigDoorTileEntity.java | 9 ++++----- .../net/malisis/doors/event/DoorEventHandlerClient.java | 8 -------- .../net/malisis/doors/event/DoorEventHandlerCommon.java | 5 ++++- src/main/java/net/malisis/doors/proxy/ClientProxy.java | 3 +-- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/malisis/doors/MalisisDoors.java b/src/main/java/net/malisis/doors/MalisisDoors.java index 5345412..7484b9b 100644 --- a/src/main/java/net/malisis/doors/MalisisDoors.java +++ b/src/main/java/net/malisis/doors/MalisisDoors.java @@ -20,12 +20,10 @@ import net.malisis.doors.door.block.ForcefieldDoor; import net.malisis.doors.door.block.RustyHatch; import net.malisis.doors.door.item.ForcefieldItem; -import net.malisis.doors.event.DoorEventHandlerClient; import net.malisis.doors.proxy.IProxy; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; -import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; diff --git a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java index d96dd4d..a45e129 100644 --- a/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java +++ b/src/main/java/net/malisis/doors/door/tileentity/BigDoorTileEntity.java @@ -185,9 +185,8 @@ public void readFromNBT(NBTTagCompound tag) { processed = false; } int typeInt = tag.getInteger("type"); - switch (typeInt) - { - case 0,1: + switch (typeInt) { + case 0, 1: this.type = BigDoor.Type.CARRIAGE; break; case 2: @@ -432,8 +431,8 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr { for (int k = 0; k < print.bluePrint[0][0].length; k++) // z { - if (!(i == mainBlockRelativeX && j == mainBlockRelativeY - && k == mainBlockRelativeZ) && print.bluePrint[j][i][k] > -1) { + if (!(i == mainBlockRelativeX && j == mainBlockRelativeY && k == mainBlockRelativeZ) + && print.bluePrint[j][i][k] > -1) { switch (this.type) { case CARRIAGE -> ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockCarriage) diff --git a/src/main/java/net/malisis/doors/event/DoorEventHandlerClient.java b/src/main/java/net/malisis/doors/event/DoorEventHandlerClient.java index 024210f..eb2a011 100644 --- a/src/main/java/net/malisis/doors/event/DoorEventHandlerClient.java +++ b/src/main/java/net/malisis/doors/event/DoorEventHandlerClient.java @@ -4,20 +4,12 @@ import net.malisis.doors.door.block.CollisionHelperBlock; import net.malisis.doors.door.tileentity.DoorTileEntity; import net.malisis.doors.door.tileentity.MultiTile; -import net.malisis.doors.network.FrameUpdateMessage; import net.malisis.doors.renderer.CustomDoorBoundingBoxRenderer; import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.client.event.DrawBlockHighlightEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; - -import org.lwjgl.input.Keyboard; import cpw.mods.fml.common.eventhandler.SubscribeEvent; diff --git a/src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java b/src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java index d8663a9..1da6263 100644 --- a/src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java +++ b/src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java @@ -1,6 +1,5 @@ package net.malisis.doors.event; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.malisis.doors.door.tileentity.MultiTile; import net.malisis.doors.network.FrameUpdateMessage; import net.minecraft.block.Block; @@ -11,9 +10,13 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraftforge.event.entity.player.PlayerInteractEvent; + import org.lwjgl.input.Keyboard; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + public class DoorEventHandlerCommon { + @SubscribeEvent public void PlayerInteractEvent(PlayerInteractEvent event) { TileEntity tileEntity = getTileEntityLookingAt(event.entityPlayer); diff --git a/src/main/java/net/malisis/doors/proxy/ClientProxy.java b/src/main/java/net/malisis/doors/proxy/ClientProxy.java index 73dbb3c..8f7e522 100644 --- a/src/main/java/net/malisis/doors/proxy/ClientProxy.java +++ b/src/main/java/net/malisis/doors/proxy/ClientProxy.java @@ -104,8 +104,7 @@ public void initFonts() { } @Override - public void initEventHandlers() - { + public void initEventHandlers() { MinecraftForge.EVENT_BUS.register(new DoorEventHandlerClient()); } }