mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 10:06:11 +03:00
542 lines
27 KiB
Diff
542 lines
27 KiB
Diff
--- ../src-base/minecraft/net/minecraft/server/management/PlayerInteractionManager.java
|
|
+++ ../src-work/minecraft/net/minecraft/server/management/PlayerInteractionManager.java
|
|
@@ -1,15 +1,16 @@
|
|
package net.minecraft.server.management;
|
|
|
|
import javax.annotation.Nullable;
|
|
-import net.minecraft.block.Block;
|
|
-import net.minecraft.block.BlockChest;
|
|
-import net.minecraft.block.BlockCommandBlock;
|
|
-import net.minecraft.block.BlockStructure;
|
|
+
|
|
+import net.minecraft.block.*;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
+import net.minecraft.init.Blocks;
|
|
+import net.minecraft.inventory.ContainerPlayer;
|
|
import net.minecraft.inventory.IInventory;
|
|
+import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemBlock;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.ItemSword;
|
|
@@ -26,7 +27,21 @@
|
|
import net.minecraft.world.ILockableContainer;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.WorldServer;
|
|
+//CraftBukkit start
|
|
+import net.minecraftforge.event.ForgeEventFactory;
|
|
+import net.minecraftforge.fml.common.FMLCommonHandler;
|
|
+import org.bukkit.craftbukkit.inventory.CraftInventory;
|
|
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
|
+import org.bukkit.event.block.BlockBreakEvent;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.event.Event;
|
|
+import org.bukkit.event.block.Action;
|
|
+import org.bukkit.event.inventory.InventoryType;
|
|
+import org.bukkit.event.player.PlayerInteractEvent;
|
|
+// CraftBukkit end
|
|
|
|
+import luohuayu.CatServer.capture.WorldCapture;
|
|
+
|
|
public class PlayerInteractionManager
|
|
{
|
|
/** Forge reach distance */
|
|
@@ -42,6 +57,10 @@
|
|
private BlockPos delayedDestroyPos = BlockPos.ORIGIN;
|
|
private int initialBlockDamage;
|
|
private int durabilityRemainingOnBlock = -1;
|
|
+ // CraftBukkit start
|
|
+ public boolean interactResult = false;
|
|
+ public boolean firedInteract = false;
|
|
+ // CraftBukkit end
|
|
|
|
public PlayerInteractionManager(World worldIn)
|
|
{
|
|
@@ -142,91 +161,117 @@
|
|
|
|
public void onBlockClicked(BlockPos pos, EnumFacing side)
|
|
{
|
|
- net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(thisPlayerMP, pos, side, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(thisPlayerMP, getBlockReachDistance() + 1));
|
|
- if (event.isCanceled())
|
|
- {
|
|
- // Restore block and te data
|
|
- thisPlayerMP.connection.sendPacket(new SPacketBlockChange(theWorld, pos));
|
|
- theWorld.notifyBlockUpdate(pos, theWorld.getBlockState(pos), theWorld.getBlockState(pos), 3);
|
|
- return;
|
|
- }
|
|
-
|
|
- if (this.isCreative())
|
|
- {
|
|
- if (!this.theWorld.extinguishFire((EntityPlayer)null, pos, side))
|
|
+ if(!this.gameType.isAdventure()){
|
|
+ PlayerInteractEvent eventCB = CraftEventFactory.callPlayerInteractEvent(this.thisPlayerMP, Action.LEFT_CLICK_BLOCK, pos, side, this.thisPlayerMP.inventory.getCurrentItem(), EnumHand.MAIN_HAND);
|
|
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event = null;
|
|
+ boolean isCancelled = eventCB.isCancelled();
|
|
+ if(!isCancelled) {
|
|
+ event = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(thisPlayerMP, pos, side, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(thisPlayerMP, getBlockReachDistance() + 1));
|
|
+ isCancelled = event.isCanceled();
|
|
+ }
|
|
+ if (isCancelled)
|
|
{
|
|
- this.tryHarvestBlock(pos);
|
|
+ // Restore block and te data
|
|
+ this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(theWorld, pos));
|
|
+ //theWorld.notifyBlockUpdate(pos, theWorld.getBlockState(pos), theWorld.getBlockState(pos), 3);
|
|
+ TileEntity tileEntity = this.theWorld.getTileEntity(pos);
|
|
+ if(tileEntity != null) {
|
|
+ this.thisPlayerMP.connection.sendPacket(tileEntity.getUpdatePacket());
|
|
+ }
|
|
+
|
|
+ return;
|
|
}
|
|
- }
|
|
- else
|
|
- {
|
|
- IBlockState iblockstate = this.theWorld.getBlockState(pos);
|
|
- Block block = iblockstate.getBlock();
|
|
|
|
- if (this.gameType.isAdventure())
|
|
+ if (this.isCreative())
|
|
{
|
|
- if (this.gameType == GameType.SPECTATOR)
|
|
+ if (!this.theWorld.extinguishFire((EntityPlayer)null, pos, side))
|
|
{
|
|
- return;
|
|
+ this.tryHarvestBlock(pos);
|
|
}
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ IBlockState iblockstate = this.theWorld.getBlockState(pos);
|
|
+ Block block = iblockstate.getBlock();
|
|
|
|
- if (!this.thisPlayerMP.isAllowEdit())
|
|
+ if (this.gameType.isAdventure())
|
|
{
|
|
- ItemStack itemstack = this.thisPlayerMP.getHeldItemMainhand();
|
|
-
|
|
- if (itemstack == null)
|
|
+ if (this.gameType == GameType.SPECTATOR)
|
|
{
|
|
return;
|
|
}
|
|
|
|
- if (!itemstack.canDestroy(block))
|
|
+ if (!this.thisPlayerMP.isAllowEdit())
|
|
{
|
|
- return;
|
|
+ ItemStack itemstack = this.thisPlayerMP.getHeldItemMainhand();
|
|
+
|
|
+ if (itemstack == null)
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (!itemstack.canDestroy(block))
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- this.initialDamage = this.curblockDamage;
|
|
- float f = 1.0F;
|
|
+ this.initialDamage = this.curblockDamage;
|
|
+ float f = 1.0F;
|
|
|
|
- if (!iblockstate.getBlock().isAir(iblockstate, theWorld, pos))
|
|
- {
|
|
- if (event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
|
|
+ // CraftBukkit start - Swings at air do *NOT* exist.
|
|
+ if (eventCB.useInteractedBlock() == Event.Result.DENY) {
|
|
+ // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
|
|
+ IBlockState data = this.theWorld.getBlockState(pos);
|
|
+ if (block == Blocks.OAK_DOOR) {
|
|
+ // For some reason *BOTH* the bottom/top part have to be marked updated.
|
|
+ boolean bottom = data.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER;
|
|
+ this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
|
|
+ this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, bottom ? pos.up() : pos.down()));
|
|
+ } else if (block == Blocks.TRAPDOOR) {
|
|
+ this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
|
|
+ }
|
|
+ } else if (!block.isAir(iblockstate, theWorld, pos))
|
|
{
|
|
block.onBlockClicked(this.theWorld, pos, this.thisPlayerMP);
|
|
- this.theWorld.extinguishFire((EntityPlayer)null, pos, side);
|
|
+ f = block.getPlayerRelativeBlockHardness(iblockstate,this.thisPlayerMP, this.thisPlayerMP.worldObj, pos);
|
|
+ // Allow fire punching to be blocked
|
|
+ this.theWorld.extinguishFire((EntityPlayer) null, pos, side);
|
|
}
|
|
- else
|
|
+ if (eventCB.useItemInHand() == Event.Result.DENY || event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
|
|
{
|
|
- // Restore block and te data
|
|
- thisPlayerMP.connection.sendPacket(new SPacketBlockChange(theWorld, pos));
|
|
- theWorld.notifyBlockUpdate(pos, theWorld.getBlockState(pos), theWorld.getBlockState(pos), 3);
|
|
+ if (f >= 1.0F)
|
|
+ {
|
|
+ // Restore block and te data
|
|
+ thisPlayerMP.connection.sendPacket(new SPacketBlockChange(theWorld, pos));
|
|
+ theWorld.notifyBlockUpdate(pos, theWorld.getBlockState(pos), theWorld.getBlockState(pos), 3);
|
|
+ }
|
|
+ return;
|
|
+ }// CB
|
|
+ org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.thisPlayerMP, pos.getX(), pos.getY(), pos.getZ(), this.thisPlayerMP.inventory.getCurrentItem(), f >= 1.0f);
|
|
+ if(blockEvent.isCancelled()) {
|
|
+ // Let the client know the block still exists
|
|
+ this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
|
|
+ return;
|
|
}
|
|
- f = iblockstate.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.worldObj, pos);
|
|
- }
|
|
- if (event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
|
|
- {
|
|
- if (f >= 1.0F)
|
|
+ if(blockEvent.getInstaBreak()) {
|
|
+ f = 2.0F;
|
|
+ }// CB end
|
|
+
|
|
+ if (!iblockstate.getBlock().isAir(iblockstate, theWorld, pos) && f >= 1.0F)
|
|
{
|
|
- // Restore block and te data
|
|
- thisPlayerMP.connection.sendPacket(new SPacketBlockChange(theWorld, pos));
|
|
- theWorld.notifyBlockUpdate(pos, theWorld.getBlockState(pos), theWorld.getBlockState(pos), 3);
|
|
+ this.tryHarvestBlock(pos);
|
|
}
|
|
- return;
|
|
+ else
|
|
+ {
|
|
+ this.isDestroyingBlock = true;
|
|
+ this.destroyPos = pos;
|
|
+ int i = (int)(f * 10.0F);
|
|
+ this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), pos, i);
|
|
+ this.durabilityRemainingOnBlock = i;
|
|
+ }
|
|
}
|
|
-
|
|
- if (!iblockstate.getBlock().isAir(iblockstate, theWorld, pos) && f >= 1.0F)
|
|
- {
|
|
- this.tryHarvestBlock(pos);
|
|
- }
|
|
- else
|
|
- {
|
|
- this.isDestroyingBlock = true;
|
|
- this.destroyPos = pos;
|
|
- int i = (int)(f * 10.0F);
|
|
- this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), pos, i);
|
|
- this.durabilityRemainingOnBlock = i;
|
|
- }
|
|
}
|
|
}
|
|
|
|
@@ -255,6 +300,10 @@
|
|
this.initialBlockDamage = this.initialDamage;
|
|
}
|
|
}
|
|
+ } // CraftBukkit start - Force block reset to client
|
|
+ else {
|
|
+ this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
@@ -283,7 +332,50 @@
|
|
}
|
|
|
|
public boolean tryHarvestBlock(BlockPos pos)
|
|
- {
|
|
+ {// CB
|
|
+ BlockBreakEvent event = null;
|
|
+ org.bukkit.block.Block blockCB = this.theWorld.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
|
|
+ boolean isSwordNoBreak = this.isCreative() && this.thisPlayerMP.getActiveItemStack() != null && this.thisPlayerMP.getActiveItemStack().getItem() instanceof ItemSword;
|
|
+ // Tell client the block is gone immediately then process events
|
|
+ // Don't tell the client if its a creative sword break because its not broken!
|
|
+ if (theWorld.getTileEntity(pos) == null && !isSwordNoBreak) {
|
|
+ SPacketBlockChange packet = new SPacketBlockChange(this.theWorld, pos);
|
|
+ packet.blockState = Blocks.AIR.getDefaultState();
|
|
+ ((EntityPlayerMP) this.thisPlayerMP).connection.sendPacket(packet);
|
|
+ }
|
|
+ event = new BlockBreakEvent(blockCB, this.thisPlayerMP.getBukkitEntity());
|
|
+ // Sword + Creative mode pre-cancel
|
|
+ event.setCancelled(isSwordNoBreak);
|
|
+ // Calculate default block experience
|
|
+ IBlockState nmsData = this.theWorld.getBlockState(pos);
|
|
+ Block nmsBlock = nmsData.getBlock();
|
|
+ ItemStack itemstack = this.thisPlayerMP.getHeldItem(EnumHand.MAIN_HAND);
|
|
+ /*if (nmsBlock != null && !event.isCancelled() && !this.isCreative() && this.player.hasBlock(nmsBlock.getBlockData())) {
|
|
+ // Copied from block.a(World world, EntityHuman entityhuman, BlockPosition blockposition, IBlockData iblockdata, TileEntity tileentity)
|
|
+ // PAIL: checkme each update
|
|
+ if (!(nmsBlock.p() && EnchantmentManager.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemstack) > 0)) {
|
|
+ int data = block.getData();
|
|
+ int bonusLevel = EnchantmentManager.getEnchantmentLevel(Enchantments.LOOT_BONUS_BLOCKS, itemstack);
|
|
+
|
|
+ event.setExpToDrop(nmsBlock.getExpDrop(nmsData, this.theWorld, pos, bonusLevel));
|
|
+ }
|
|
+ }*/ // TODO
|
|
+ this.theWorld.getServer().getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ if (isSwordNoBreak) {
|
|
+ return false;
|
|
+ }
|
|
+ // Let the client know the block still exists
|
|
+ ((EntityPlayerMP) this.thisPlayerMP).connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
|
|
+ // Update any tile entity data for this block
|
|
+ TileEntity tileentity = this.theWorld.getTileEntity(pos);
|
|
+ if (tileentity != null) {
|
|
+ this.thisPlayerMP.connection.sendPacket(tileentity.getUpdatePacket());
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ // Forge
|
|
int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(theWorld, gameType, thisPlayerMP, pos);
|
|
if (exp == -1)
|
|
{
|
|
@@ -338,15 +430,16 @@
|
|
}
|
|
|
|
// Drop experience
|
|
- if (!this.isCreative() && flag1 && exp > 0)
|
|
+ if (!this.isCreative() && flag1)
|
|
{
|
|
- iblockstate.getBlock().dropXpOnBlockBreak(theWorld, pos, exp);
|
|
+ iblockstate.getBlock().dropXpOnBlockBreak(theWorld, pos, exp > 0 ? exp : event.getExpToDrop() > 0 ? event.getExpToDrop() : 0); // Svarka
|
|
}
|
|
return flag1;
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
public EnumActionResult processRightClick(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand)
|
|
{
|
|
if (this.gameType == GameType.SPECTATOR)
|
|
@@ -385,8 +478,8 @@
|
|
|
|
if (itemstack.stackSize == 0)
|
|
{
|
|
- player.setHeldItem(hand, (ItemStack)null);
|
|
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, itemstack, hand);
|
|
+ player.setHeldItem(hand, (ItemStack)null);
|
|
}
|
|
|
|
if (!player.isHandActive())
|
|
@@ -399,102 +492,146 @@
|
|
}
|
|
}
|
|
|
|
+
|
|
public EnumActionResult processRightClickBlock(EntityPlayer player, World worldIn, @Nullable ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
|
|
{
|
|
- if (this.gameType == GameType.SPECTATOR)
|
|
- {
|
|
- TileEntity tileentity = worldIn.getTileEntity(pos);
|
|
+ // CatServer - fire PlayerInteractEvent
|
|
+ IBlockState blockdata = worldIn.getBlockState(pos);
|
|
|
|
- if (tileentity instanceof ILockableContainer)
|
|
- {
|
|
- Block block1 = worldIn.getBlockState(pos).getBlock();
|
|
- ILockableContainer ilockablecontainer = (ILockableContainer)tileentity;
|
|
+ if (blockdata.getBlock() != Blocks.AIR) {
|
|
+ boolean cancelledBlock = false;
|
|
|
|
- if (ilockablecontainer instanceof TileEntityChest && block1 instanceof BlockChest)
|
|
- {
|
|
- ilockablecontainer = ((BlockChest)block1).getLockableContainer(worldIn, pos);
|
|
- }
|
|
+ if (this.gameType == GameType.SPECTATOR) {
|
|
+ TileEntity tileentity = worldIn.getTileEntity(pos);
|
|
+ cancelledBlock = !(tileentity instanceof ILockableContainer || tileentity instanceof IInventory);
|
|
+ }
|
|
|
|
- if (ilockablecontainer != null)
|
|
- {
|
|
- player.displayGUIChest(ilockablecontainer);
|
|
- return EnumActionResult.SUCCESS;
|
|
+ if (!player.getBukkitEntity().isOp() && stack != null && Block.getBlockFromItem(stack.getItem()) instanceof BlockCommandBlock) {
|
|
+ cancelledBlock = true;
|
|
+ }
|
|
+
|
|
+ PlayerInteractEvent cbEvent = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, pos, facing, stack, cancelledBlock, hand);
|
|
+ firedInteract = true;
|
|
+ interactResult = cbEvent.useItemInHand() == Event.Result.DENY;
|
|
+
|
|
+ if (cbEvent.useInteractedBlock() == Event.Result.DENY) {
|
|
+ // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
|
|
+ if (blockdata.getBlock() instanceof BlockDoor) {
|
|
+ boolean bottom = blockdata.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER;
|
|
+ ((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(worldIn, bottom ? pos.up() : pos.down()));
|
|
+ } else if (blockdata.getBlock() instanceof BlockCake) {
|
|
+ ((EntityPlayerMP) player).getBukkitEntity().sendHealthUpdate(); // SPIGOT-1341 - reset health for cake
|
|
}
|
|
+ return (cbEvent.useItemInHand() != Event.Result.ALLOW) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
|
|
}
|
|
- else if (tileentity instanceof IInventory)
|
|
+ else if (this.gameType == GameType.SPECTATOR)
|
|
{
|
|
- player.displayGUIChest((IInventory)tileentity);
|
|
- return EnumActionResult.SUCCESS;
|
|
- }
|
|
+ TileEntity tileentity = worldIn.getTileEntity(pos);
|
|
|
|
- return EnumActionResult.PASS;
|
|
- }
|
|
- else
|
|
- {
|
|
- net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = net.minecraftforge.common.ForgeHooks
|
|
- .onRightClickBlock(player, hand, stack, pos, facing, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(thisPlayerMP, getBlockReachDistance() + 1));
|
|
- if (event.isCanceled()) return EnumActionResult.PASS;
|
|
+ if (tileentity instanceof ILockableContainer)
|
|
+ {
|
|
+ Block block1 = worldIn.getBlockState(pos).getBlock();
|
|
+ ILockableContainer ilockablecontainer = (ILockableContainer)tileentity;
|
|
|
|
- net.minecraft.item.Item item = stack == null ? null : stack.getItem();
|
|
- EnumActionResult ret = item == null ? EnumActionResult.PASS : item.onItemUseFirst(stack, player, worldIn, pos, facing, hitX, hitY, hitZ, hand);
|
|
- if (ret != EnumActionResult.PASS) return ret;
|
|
+ if (ilockablecontainer instanceof TileEntityChest && block1 instanceof BlockChest)
|
|
+ {
|
|
+ ilockablecontainer = ((BlockChest)block1).getLockableContainer(worldIn, pos);
|
|
+ }
|
|
|
|
- boolean bypass = true;
|
|
- for (ItemStack s : new ItemStack[]{player.getHeldItemMainhand(), player.getHeldItemOffhand()}) //TODO: Expand to more hands? player.inv.getHands()?
|
|
- bypass = bypass && (s == null || s.getItem().doesSneakBypassUse(s, worldIn, pos, player));
|
|
- EnumActionResult result = EnumActionResult.PASS;
|
|
-
|
|
- if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW)
|
|
- {
|
|
- IBlockState iblockstate = worldIn.getBlockState(pos);
|
|
- if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
|
|
- if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, stack, facing, hitX, hitY, hitZ))
|
|
+ if (ilockablecontainer != null)
|
|
+ {
|
|
+ player.displayGUIChest(ilockablecontainer);
|
|
+ return EnumActionResult.SUCCESS;
|
|
+ }
|
|
+ }
|
|
+ else if (tileentity instanceof IInventory)
|
|
{
|
|
- result = EnumActionResult.SUCCESS;
|
|
+ player.displayGUIChest((IInventory)tileentity);
|
|
+ return EnumActionResult.SUCCESS;
|
|
}
|
|
- }
|
|
|
|
- if (stack == null)
|
|
- {
|
|
return EnumActionResult.PASS;
|
|
}
|
|
- else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
|
|
+ else if (!interactResult)
|
|
{
|
|
- return EnumActionResult.PASS;
|
|
- }
|
|
- else
|
|
- {
|
|
- if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
|
|
- {
|
|
- Block block = ((ItemBlock)stack.getItem()).getBlock();
|
|
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = net.minecraftforge.common.ForgeHooks
|
|
+ .onRightClickBlock(player, hand, stack, pos, facing, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(thisPlayerMP, getBlockReachDistance() + 1));
|
|
|
|
- if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
|
|
- {
|
|
- return EnumActionResult.FAIL;
|
|
+ net.minecraft.item.Item item = stack == null ? null : stack.getItem();
|
|
+ EnumActionResult ret;
|
|
+ if (item == null) ret = EnumActionResult.PASS;
|
|
+ else {
|
|
+ WorldCapture tCapture=player.worldObj.mCapture;
|
|
+ tCapture.startCapture(player,stack);
|
|
+ ret = item.onItemUseFirst(stack, player, worldIn, pos, facing, hitX, hitY, hitZ, hand);
|
|
+ tCapture.endCapture();
|
|
+ if(ret == EnumActionResult.SUCCESS) ret = tCapture.handleCapture(stack);
|
|
+ }
|
|
+ if (ret != EnumActionResult.PASS) return ret;
|
|
+
|
|
+ boolean bypass = true;
|
|
+ for (ItemStack s : new ItemStack[]{player.getHeldItemMainhand(), player.getHeldItemOffhand()}) //TODO: Expand to more hands? player.inv.getHands()?
|
|
+ bypass = bypass && (s == null || s.getItem().doesSneakBypassUse(s, worldIn, pos, player));
|
|
+ EnumActionResult result = EnumActionResult.PASS;
|
|
+
|
|
+ if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW)
|
|
+ {
|
|
+ IBlockState iblockstate = worldIn.getBlockState(pos);
|
|
+ if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY){
|
|
+ WorldCapture tCapture=player.worldObj.mCapture;
|
|
+ tCapture.startCapture(player,stack);
|
|
+ if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, stack, facing, hitX, hitY, hitZ))
|
|
+ {
|
|
+ result = EnumActionResult.SUCCESS;
|
|
+ }
|
|
+ tCapture.endCapture();
|
|
+ if(result==EnumActionResult.SUCCESS) result=tCapture.handleCapture(stack);
|
|
}
|
|
}
|
|
|
|
- if (this.isCreative())
|
|
+ if (stack == null)
|
|
{
|
|
- int j = stack.getMetadata();
|
|
- int i = stack.stackSize;
|
|
- if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
|
|
- || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
|
|
- EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
|
|
- stack.setItemDamage(j);
|
|
- stack.stackSize = i;
|
|
- return enumactionresult;
|
|
- } else return result;
|
|
+ return EnumActionResult.PASS;
|
|
}
|
|
+ else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
|
|
+ {
|
|
+ return EnumActionResult.PASS;
|
|
+ }
|
|
else
|
|
{
|
|
- if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
|
|
- || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW)
|
|
- return stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
|
|
- else return result;
|
|
+ if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
|
|
+ {
|
|
+ Block block = ((ItemBlock)stack.getItem()).getBlock();
|
|
+
|
|
+ if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
|
|
+ {
|
|
+ return EnumActionResult.FAIL;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (this.isCreative())
|
|
+ {
|
|
+ int j = stack.getMetadata();
|
|
+ int i = stack.stackSize;
|
|
+ if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
|
|
+ || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
|
|
+ EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
|
|
+ stack.setItemDamage(j);
|
|
+ stack.stackSize = i;
|
|
+ return enumactionresult;
|
|
+ } else return result;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
|
|
+ || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW)
|
|
+ return stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
|
|
+ else return result;
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
+ return EnumActionResult.FAIL;
|
|
}
|
|
|
|
public void setWorld(WorldServer serverWorld)
|