use of net.minecraft.block.CakeBlock in project Arclight by IzzelAliz.
the class PlayerInteractionManagerMixin_1_15 method func_219441_a.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public ActionResultType func_219441_a(PlayerEntity playerIn, World worldIn, ItemStack stackIn, Hand handIn, BlockRayTraceResult blockRaytraceResultIn) {
BlockPos blockpos = blockRaytraceResultIn.getPos();
BlockState blockstate = worldIn.getBlockState(blockpos);
ActionResultType resultType = ActionResultType.PASS;
boolean cancelledBlock = false;
if (this.gameType == GameType.SPECTATOR) {
INamedContainerProvider provider = blockstate.getContainer(worldIn, blockpos);
cancelledBlock = !(provider instanceof INamedContainerProvider);
}
if (playerIn.getCooldownTracker().hasCooldown(stackIn.getItem())) {
cancelledBlock = true;
}
PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getFace(), stackIn, cancelledBlock, handIn);
bridge$setFiredInteract(true);
bridge$setInteractResult(bukkitEvent.useItemInHand() == Event.Result.DENY);
if (bukkitEvent.useInteractedBlock() == Event.Result.DENY) {
if (blockstate.getBlock() instanceof DoorBlock) {
boolean bottom = blockstate.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockpos.up() : blockpos.down()));
} else if (blockstate.getBlock() instanceof CakeBlock) {
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().sendHealthUpdate();
}
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? ActionResultType.SUCCESS : ActionResultType.PASS);
} else if (this.gameType == GameType.SPECTATOR) {
INamedContainerProvider inamedcontainerprovider = blockstate.getContainer(worldIn, blockpos);
if (inamedcontainerprovider != null) {
playerIn.openContainer(inamedcontainerprovider);
return ActionResultType.SUCCESS;
} else {
return ActionResultType.PASS;
}
} else {
net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(playerIn, handIn, blockpos, blockRaytraceResultIn.getFace());
if (event.isCanceled())
return event.getCancellationResult();
ItemUseContext itemusecontext = new ItemUseContext(playerIn, handIn, blockRaytraceResultIn);
if (event.getUseItem() != net.minecraftforge.eventbus.api.Event.Result.DENY) {
ActionResultType result = stackIn.onItemUseFirst(itemusecontext);
if (result != ActionResultType.PASS)
return result;
}
boolean flag = !playerIn.getHeldItemMainhand().isEmpty() || !playerIn.getHeldItemOffhand().isEmpty();
boolean flag1 = (playerIn.isSecondaryUseActive() && flag) && !(playerIn.getHeldItemMainhand().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getHeldItemOffhand().doesSneakBypassUse(worldIn, blockpos, playerIn));
if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && !flag1) {
resultType = blockstate.onBlockActivated(worldIn, playerIn, handIn, blockRaytraceResultIn);
if (resultType.isSuccessOrConsume()) {
return resultType;
}
}
if (!stackIn.isEmpty() && resultType != ActionResultType.SUCCESS && !bridge$getInteractResult()) {
if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) {
return ActionResultType.PASS;
}
if (this.isCreative()) {
int i = stackIn.getCount();
resultType = stackIn.onItemUse(itemusecontext);
stackIn.setCount(i);
return resultType;
} else {
return stackIn.onItemUse(itemusecontext);
}
} else {
return resultType;
}
}
return resultType;
}
use of net.minecraft.block.CakeBlock in project Arclight by IzzelAliz.
the class PlayerInteractionManagerMixin_1_14 method func_219441_a.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public ActionResultType func_219441_a(PlayerEntity playerIn, World worldIn, ItemStack stackIn, Hand handIn, BlockRayTraceResult blockRaytraceResultIn) {
BlockPos blockpos = blockRaytraceResultIn.getPos();
BlockState blockstate = worldIn.getBlockState(blockpos);
ActionResultType resultType = ActionResultType.PASS;
boolean cancelledBlock = false;
if (this.gameType == GameType.SPECTATOR) {
INamedContainerProvider provider = blockstate.getContainer(worldIn, blockpos);
cancelledBlock = !(provider instanceof INamedContainerProvider);
}
if (playerIn.getCooldownTracker().hasCooldown(stackIn.getItem())) {
cancelledBlock = true;
}
PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getFace(), stackIn, cancelledBlock, handIn);
bridge$setFiredInteract(true);
bridge$setInteractResult(bukkitEvent.useItemInHand() == Event.Result.DENY);
if (bukkitEvent.useInteractedBlock() == Event.Result.DENY) {
if (blockstate.getBlock() instanceof DoorBlock) {
boolean bottom = blockstate.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER;
((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockpos.up() : blockpos.down()));
} else if (blockstate.getBlock() instanceof CakeBlock) {
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().sendHealthUpdate();
}
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? ActionResultType.SUCCESS : ActionResultType.PASS);
} else if (this.gameType == GameType.SPECTATOR) {
INamedContainerProvider inamedcontainerprovider = blockstate.getContainer(worldIn, blockpos);
if (inamedcontainerprovider != null) {
playerIn.openContainer(inamedcontainerprovider);
return ActionResultType.SUCCESS;
} else {
return ActionResultType.PASS;
}
} else {
net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(playerIn, handIn, blockpos, blockRaytraceResultIn.getFace());
if (event.isCanceled())
return event.getCancellationResult();
ItemUseContext itemusecontext = new ItemUseContext(playerIn, handIn, blockRaytraceResultIn);
if (event.getUseItem() != net.minecraftforge.eventbus.api.Event.Result.DENY) {
ActionResultType result = stackIn.onItemUseFirst(itemusecontext);
if (result != ActionResultType.PASS)
return result;
}
boolean flag = !playerIn.getHeldItemMainhand().isEmpty() || !playerIn.getHeldItemOffhand().isEmpty();
boolean flag1 = !(playerIn.isSneaking() && flag) || (playerIn.getHeldItemMainhand().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getHeldItemOffhand().doesSneakBypassUse(worldIn, blockpos, playerIn));
boolean flag2 = blockstate.onBlockActivated(worldIn, playerIn, handIn, blockRaytraceResultIn);
if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && flag1 && flag2) {
return ActionResultType.SUCCESS;
} else {
if (flag1) {
resultType = flag2 ? ActionResultType.SUCCESS : ActionResultType.FAIL;
}
if (!stackIn.isEmpty() && resultType != ActionResultType.SUCCESS && !bridge$getInteractResult()) {
if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) {
return ActionResultType.PASS;
}
if (this.isCreative()) {
int i = stackIn.getCount();
resultType = stackIn.onItemUse(itemusecontext);
stackIn.setCount(i);
return resultType;
} else {
return stackIn.onItemUse(itemusecontext);
}
} else {
return resultType;
}
}
}
return resultType;
}
Aggregations