use of net.minecraft.network.play.server.SChangeBlockPacket in project Overloaded by CJ-MC-Mods.
the class PlayerInteractionUtil method tryHarvestBlock.
public static boolean tryHarvestBlock(ServerPlayerEntity player, ServerWorld world, BlockPos pos) {
int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, player.gameMode.getGameModeForPlayer(), player, pos);
if (exp == -1) {
return false;
} else {
BlockState iblockstate = world.getBlockState(pos);
TileEntity tileentity = world.getBlockEntity(pos);
Block block = iblockstate.getBlock();
if ((block instanceof CommandBlockBlock || block instanceof StructureBlock) && !player.canUseGameMasterBlocks()) {
world.sendBlockUpdated(pos, iblockstate, iblockstate, 3);
return false;
} else {
world.levelEvent(null, 2001, pos, Block.getId(iblockstate));
boolean flag1;
if (player.abilities.instabuild) {
flag1 = removeBlock(world, pos, player, false);
player.connection.send(new SChangeBlockPacket(world, pos));
} else {
ItemStack itemstack1 = player.getMainHandItem();
ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
boolean flag = iblockstate.canHarvestBlock(world, pos, player);
itemstack1.mineBlock(world, iblockstate, pos, player);
flag1 = removeBlock(world, pos, player, flag);
if (flag1 && flag) {
iblockstate.getBlock().playerDestroy(world, player, pos, iblockstate, tileentity, itemstack2);
}
}
// Drop experience
if (!player.isCreative() && flag1 && exp > 0) {
iblockstate.getBlock().popExperience(world, player.blockPosition(), exp);
}
return flag1;
}
}
}
use of net.minecraft.network.play.server.SChangeBlockPacket 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.network.play.server.SChangeBlockPacket in project FastAsyncWorldEdit by IntellectualSites.
the class ForgePlayer method sendFakeBlock.
@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
World world = getWorld();
if (!(world instanceof ForgeWorld)) {
return;
}
BlockPos loc = ForgeAdapter.toBlockPos(pos);
if (block == null) {
final SChangeBlockPacket packetOut = new SChangeBlockPacket(((ForgeWorld) world).getWorld(), loc);
player.connection.sendPacket(packetOut);
} else {
final SChangeBlockPacket packetOut = new SChangeBlockPacket();
PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
buf.writeBlockPos(loc);
buf.writeVarInt(Block.getStateId(ForgeAdapter.adapt(block.toImmutableState())));
try {
packetOut.readPacketData(buf);
} catch (IOException e) {
return;
}
player.connection.sendPacket(packetOut);
if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
final BaseBlock baseBlock = (BaseBlock) block;
final CompoundTag nbtData = baseBlock.getNbtData();
if (nbtData != null) {
player.connection.sendPacket(new SUpdateTileEntityPacket(new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), STRUCTURE_BLOCK_PACKET_ID, NBTConverter.toNative(nbtData)));
}
}
}
}
use of net.minecraft.network.play.server.SChangeBlockPacket in project Arclight by IzzelAliz.
the class BucketItemMixin method arclight$bucketFill.
// @formatter:on
@Inject(method = "onItemRightClick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/IBucketPickupHandler;pickupFluid(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/fluid/Fluid;"))
private void arclight$bucketFill(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable<ActionResult<ItemStack>> cir, ItemStack stack, RayTraceResult result) {
BlockPos pos = ((BlockRayTraceResult) result).getPos();
BlockState state = worldIn.getBlockState(pos);
Fluid dummyFluid = ((IBucketPickupHandler) state.getBlock()).pickupFluid(DummyGeneratorAccess.INSTANCE, pos, state);
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(worldIn, playerIn, pos, pos, ((BlockRayTraceResult) result).getFace(), stack, dummyFluid.getFilledBucket());
if (event.isCancelled()) {
((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(worldIn, pos));
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
cir.setReturnValue(new ActionResult<>(ActionResultType.FAIL, stack));
} else {
arclight$captureItem = event.getItemStack();
}
}
use of net.minecraft.network.play.server.SChangeBlockPacket in project Arclight by IzzelAliz.
the class BucketItemMixin method arclight$bucketEmpty.
@Inject(method = "tryPlaceContainedLiquid", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;doesWaterVaporize()Z"))
private void arclight$bucketEmpty(PlayerEntity player, World worldIn, BlockPos posIn, BlockRayTraceResult p_180616_4_, CallbackInfoReturnable<Boolean> cir) {
if (player != null) {
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(worldIn, player, posIn, arclight$click, arclight$direction, arclight$stack);
if (event.isCancelled()) {
((ServerPlayerEntity) player).connection.sendPacket(new SChangeBlockPacket(worldIn, posIn));
((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().updateInventory();
cir.setReturnValue(false);
}
}
}
Aggregations