diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index 919fdbd2a..cae754dd2 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -40,6 +40,7 @@ import kamkeel.npcs.network.packets.request.faction.*; import kamkeel.npcs.network.packets.request.feather.DimensionTeleportPacket; import kamkeel.npcs.network.packets.request.item.ColorBrushPacket; import kamkeel.npcs.network.packets.request.item.ColorSetPacket; +import kamkeel.npcs.network.packets.request.item.HammerPacket; import kamkeel.npcs.network.packets.request.jobs.JobGetPacket; import kamkeel.npcs.network.packets.request.jobs.JobSavePacket; import kamkeel.npcs.network.packets.request.jobs.JobSpawnerAddPacket; @@ -313,6 +314,7 @@ public class PacketHandler { // Tool Packets REQUEST_PACKET.registerPacket(new ColorBrushPacket()); REQUEST_PACKET.registerPacket(new ColorSetPacket()); + REQUEST_PACKET.registerPacket(new HammerPacket()); // Custom Effect Packets REQUEST_PACKET.registerPacket(new EffectGetPacket()); diff --git a/src/main/java/kamkeel/npcs/network/PacketUtil.java b/src/main/java/kamkeel/npcs/network/PacketUtil.java index 684be11d6..f6bc22e8b 100644 --- a/src/main/java/kamkeel/npcs/network/PacketUtil.java +++ b/src/main/java/kamkeel/npcs/network/PacketUtil.java @@ -93,6 +93,13 @@ public class PacketUtil { return false; } break; + case HAMMER: + if (item.getItem() != CustomItems.tool || item.getItemDamage() != 0) { + LogWriter.error(String.format("%s attempted to utilize a %s Packet without a Pather, they could be a hacker", + player.getCommandSenderName(), type)); + return false; + } + break; } return true; } @@ -149,6 +156,8 @@ public class PacketUtil { || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)); case BRUSH: return item.getItem() == CustomItems.tool && item.getItemDamage() == 1; + case HAMMER: + return item.getItem() == CustomItems.tool && item.getItemDamage() == 0; default: return false; } @@ -186,6 +195,8 @@ public class PacketUtil { return "valid Block"; case BRUSH: return "Paintbrush"; + case HAMMER: + return "Hammer"; default: return type.toString(); } diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumItemPacketType.java b/src/main/java/kamkeel/npcs/network/enums/EnumItemPacketType.java index 14b1a4236..f4c25e7f0 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumItemPacketType.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumItemPacketType.java @@ -8,5 +8,6 @@ public enum EnumItemPacketType { SCRIPTER, PATHER, BLOCK, - BRUSH + BRUSH, + HAMMER } diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java index 026a9f049..5503a8d24 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java @@ -192,5 +192,5 @@ public enum EnumRequestPacket { MagicGet, MagicSave, NpcMagicGet, - NpcMagicSave, + NpcMagicSave, Hammer, } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/item/HammerPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/item/HammerPacket.java new file mode 100644 index 000000000..ff0f8788b --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/packets/request/item/HammerPacket.java @@ -0,0 +1,84 @@ +package kamkeel.npcs.network.packets.request.item; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.PacketUtil; +import kamkeel.npcs.network.enums.EnumItemPacketType; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.blocks.tiles.TileBanner; +import noppes.npcs.blocks.tiles.TileChair; +import noppes.npcs.blocks.tiles.TileColorable; +import noppes.npcs.blocks.tiles.TileWallBanner; + +import java.io.IOException; + +import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG; +import static noppes.npcs.items.ItemNpcTool.getColor; + +public final class HammerPacket extends AbstractPacket { + public static String packetName = "Request|Hammer"; + + private int x; + private int y; + private int z; + + public HammerPacket(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public HammerPacket() {} + + @Override + public Enum getType() { + return EnumRequestPacket.Hammer; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @Override + public CustomNpcsPermissions.Permission getPermission() { + return CustomNpcsPermissions.NPC_BUILD; + } + + @SideOnly(Side.CLIENT) + @Override + public void sendData(ByteBuf out) throws IOException { + out.writeInt(this.x); + out.writeInt(this.y); + out.writeInt(this.z); + } + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + if (!PacketUtil.verifyItemPacket(EnumItemPacketType.HAMMER, player)) + return; + + int x = in.readInt(); + int y = in.readInt(); + int z = in.readInt(); + + TileEntity tile = player.worldObj.getTileEntity(x, y, z); + if(tile instanceof TileChair) { + ((TileChair) tile).push(); + } else if (tile instanceof TileBanner || tile instanceof TileWallBanner){ + + } + } +} diff --git a/src/main/java/noppes/npcs/blocks/BlockChair.java b/src/main/java/noppes/npcs/blocks/BlockChair.java index 0027b870a..4c63d0588 100644 --- a/src/main/java/noppes/npcs/blocks/BlockChair.java +++ b/src/main/java/noppes/npcs/blocks/BlockChair.java @@ -9,32 +9,88 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import noppes.npcs.blocks.tiles.TileChair; +import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.entity.EntityChairMount; import noppes.npcs.entity.EntityCustomNpc; +import noppes.npcs.items.ItemNpcTool; import java.util.List; public class BlockChair extends BlockRotated{ - + public BlockChair() { super(Blocks.planks); setBlockBounds(0.1f, 0, 0.1f, 0.9f, 1, 0.9f); } - @Override + @Override public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){ super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack); par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2); } - @Override - public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int x, int y, int z){ - return AxisAlignedBB.getBoundingBox(x + 0.1f, y, z + 0.1f, x + 0.9f, y + 0.5f, z + 0.9f); + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof TileChair && ((TileChair) te).isPushed()) { + // Use the rotation to set a vertical slab hitbox on the pushed side. + int rotation = ((TileVariant) te).rotation; + switch(rotation) { + case 0: // North: slab from z to z+0.3. + return AxisAlignedBB.getBoundingBox(x + 0.1, y, z, x + 0.9, y + 1, z + 0.3); + case 1: // East: slab from x+0.7 to x+1. + return AxisAlignedBB.getBoundingBox(x + 0.7, y, z + 0.1, x + 1.0, y + 1, z + 0.9); + case 2: // South: slab from z+0.7 to z+1. + return AxisAlignedBB.getBoundingBox(x + 0.1, y, z + 0.7, x + 0.9, y + 1, z + 1.0); + case 3: // West: slab from x to x+0.3. + return AxisAlignedBB.getBoundingBox(x, y, z + 0.1, x + 0.3, y + 1, z + 0.9); + default: + return AxisAlignedBB.getBoundingBox(x + 0.1, y, z + 0.1, x + 0.9, y + 1, z + 0.9); + } + } + // Default collision box (half-height) when not pushed. + return AxisAlignedBB.getBoundingBox(x + 0.1, y, z + 0.1, x + 0.9, y + 0.5, z + 0.9); } - - @Override + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { + TileEntity tileentity = world.getTileEntity(x, y, z); + if (!(tileentity instanceof TileChair)) { + super.setBlockBoundsBasedOnState(world, x, y, z); + return; + } + TileChair tile = (TileChair) tileentity; + if (tile.isPushed()) { + // Pushed state: set a thicker vertical slab on the pushed side. + switch (tile.rotation) { + case 0: // North. + setBlockBounds(0.1f, 0, 0, 0.9f, 1.0f, 0.3f); + break; + case 1: // East. + setBlockBounds(0.7f, 0, 0.1f, 1.0f, 1.0f, 0.9f); + break; + case 2: // South. + setBlockBounds(0.1f, 0, 0.7f, 0.9f, 1.0f, 1.0f); + break; + case 3: // West. + setBlockBounds(0, 0, 0.1f, 0.3f, 1.0f, 0.9f); + break; + default: + setBlockBounds(0.1f, 0, 0.1f, 0.9f, 1.0f, 0.9f); + break; + } + } else { + // Not pushed: default chair bounds. + setBlockBounds(0.1f, 0, 0.1f, 0.9f, 1.0f, 0.9f); + } + } + + + + + @Override public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){ par3List.add(new ItemStack(par1, 1, 0)); par3List.add(new ItemStack(par1, 1, 1)); @@ -44,7 +100,7 @@ public class BlockChair extends BlockRotated{ par3List.add(new ItemStack(par1, 1, 5)); } - @Override + @Override public int damageDropped(int par1){ return par1; } @@ -53,25 +109,43 @@ public class BlockChair extends BlockRotated{ public TileEntity createNewTileEntity(World var1, int var2) { return new TileChair(); } - + @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_){ + ItemStack item = player.inventory.getCurrentItem(); + if(item != null && item.getItem() != null && item.getItem() instanceof ItemNpcTool) + return false; + return MountBlock(world, x, y, z, player); } - - public static boolean MountBlock(World world, int x, int y, int z, EntityPlayer player){ - if(world.isRemote) - return true; - List list = world.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1)); - for(Entity entity : list){ - if(entity instanceof EntityChairMount || entity instanceof EntityCustomNpc) - return false; - } - EntityChairMount mount = new EntityChairMount(world); - mount.setPosition(x + 0.5f, y, z + 0.5); - player.mountEntity(mount); - world.spawnEntityInWorld(mount); - player.mountEntity(mount); - return true; - } + + public static boolean MountBlock(World world, int x, int y, int z, EntityPlayer player) { + if (world.isRemote) + return true; + + // Do not allow mounting if the player is holding the NpcTool. + if (player.getCurrentEquippedItem() != null && + player.getCurrentEquippedItem().getItem() instanceof noppes.npcs.items.ItemNpcTool) { + return false; + } + + // Check if the chair is pushed. + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof TileChair && ((TileChair) te).isPushed()) { + return false; + } + + // Existing check to prevent mounting if an entity is already there. + List list = world.getEntitiesWithinAABB(Entity.class, + AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1)); + for (Entity entity : list) { + if (entity instanceof EntityChairMount || entity instanceof EntityCustomNpc) + return false; + } + EntityChairMount mount = new EntityChairMount(world); + mount.setPosition(x + 0.5f, y, z + 0.5f); + world.spawnEntityInWorld(mount); + player.mountEntity(mount); + return true; + } } diff --git a/src/main/java/noppes/npcs/blocks/tiles/TileChair.java b/src/main/java/noppes/npcs/blocks/tiles/TileChair.java index dfc85f300..93fc8be3d 100644 --- a/src/main/java/noppes/npcs/blocks/tiles/TileChair.java +++ b/src/main/java/noppes/npcs/blocks/tiles/TileChair.java @@ -1,5 +1,39 @@ package noppes.npcs.blocks.tiles; +import net.minecraft.util.AxisAlignedBB; + public class TileChair extends TileVariant { + public boolean isPushed(){ + return this.variant == 1; + } + + public void push(){ + // Variant 14 is not pushed, 1 is pushed + this.variant = this.variant == 14 ? 1 : 14; + this.markDirty(); + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + + @Override + public AxisAlignedBB getRenderBoundingBox(){ + if (isPushed()){ + // When pushed, return a thicker vertical slab based on rotation. + switch(this.rotation) { + case 0: // North. + return AxisAlignedBB.getBoundingBox(xCoord + 0.1, yCoord, zCoord, xCoord + 0.9, yCoord + 1, zCoord + 0.3); + case 1: // East. + return AxisAlignedBB.getBoundingBox(xCoord + 0.7, yCoord, zCoord + 0.1, xCoord + 1, yCoord + 1, zCoord + 0.9); + case 2: // South. + return AxisAlignedBB.getBoundingBox(xCoord + 0.1, yCoord, zCoord + 0.7, xCoord + 0.9, yCoord + 1, zCoord + 1); + case 3: // West. + return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord + 0.1, xCoord + 0.3, yCoord + 1, zCoord + 0.9); + default: + return AxisAlignedBB.getBoundingBox(xCoord, yCoord - 1, zCoord, xCoord + 1, yCoord + 1, zCoord + 1); + } + } else { + // Default render bounding box. + return AxisAlignedBB.getBoundingBox(xCoord, yCoord - 1, zCoord, xCoord + 1, yCoord + 1, zCoord + 1); + } + } } diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockChairRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockChairRenderer.java index b7dd1b738..7e196df09 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockChairRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockChairRenderer.java @@ -9,6 +9,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomItems; import noppes.npcs.blocks.BlockChair; +import noppes.npcs.blocks.tiles.TileChair; import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.client.model.blocks.chair.ModelChair; import noppes.npcs.client.model.blocks.chair.ModelChairSpoof; @@ -45,7 +46,31 @@ public class BlockChairRenderer extends BlockRendererInterface{ GL11.glTranslatef((float)var2 + 0.5f, (float)var4 + 1.5f, (float)var6 + 0.5f); // GL11.glScalef(1.2f, 1.1f, 1.2f); GL11.glRotatef(180, 0, 0, 1); + + // Apply push translation if this is a pushed chair. + if(tile instanceof TileChair) { + TileChair chairTile = (TileChair) tile; + if(chairTile.isPushed()) { + float pushDistance = 0.6f; // adjust as needed for visual effect + switch(tile.rotation) { + case 0: // Facing north – push the model backwards. + GL11.glTranslatef(0, 0, -pushDistance); + break; + case 1: // Facing east – push right. + GL11.glTranslatef(-pushDistance, 0, 0); + break; + case 2: // Facing south – push forwards. + GL11.glTranslatef(0, 0, pushDistance); + break; + case 3: // Facing west – push left. + GL11.glTranslatef(pushDistance, 0, 0); + break; + } + } + } + GL11.glRotatef(90 * tile.rotation, 0, 1, 0); + GL11.glColor3f(1, 1, 1); GL11.glEnable(GL11.GL_ALPHA_TEST); diff --git a/src/main/java/noppes/npcs/items/ItemNpcTool.java b/src/main/java/noppes/npcs/items/ItemNpcTool.java index 673441671..9f4e95168 100644 --- a/src/main/java/noppes/npcs/items/ItemNpcTool.java +++ b/src/main/java/noppes/npcs/items/ItemNpcTool.java @@ -6,6 +6,7 @@ import cpw.mods.fml.relauncher.SideOnly; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.item.ColorBrushPacket; import kamkeel.npcs.network.packets.request.item.ColorSetPacket; +import kamkeel.npcs.network.packets.request.item.HammerPacket; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -20,7 +21,9 @@ import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.blocks.BlockBanner; +import noppes.npcs.blocks.BlockChair; import noppes.npcs.blocks.BlockTallLamp; +import noppes.npcs.blocks.tiles.TileChair; import noppes.npcs.blocks.tiles.TileColorable; import noppes.npcs.client.NoppesUtil; import noppes.npcs.constants.EnumGuiType; @@ -90,6 +93,15 @@ public class ItemNpcTool extends Item { PacketClient.sendClient(new ColorSetPacket(x, y, z)); return true; } + } else if (isHammer(stack)){ + Block block = player.worldObj.getBlock(x, y, z); + if(block instanceof BlockChair){ + TileEntity tile = player.worldObj.getTileEntity(x, y, z); + if(tile instanceof TileChair) { + PacketClient.sendClient(new HammerPacket(x, y, z)); + return true; + } + } } return false; @@ -122,6 +134,10 @@ public class ItemNpcTool extends Item { return itemStack.getItemDamage() == 1; } + public static boolean isHammer(ItemStack itemStack){ + return itemStack.getItemDamage() == 0; + } + @Override public Item setUnlocalizedName(String name){ GameRegistry.registerItem(this, name);