use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class EntityMixin method impl$onStepOnCollide.
@Redirect(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;stepOn(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/Entity;)V"))
private void impl$onStepOnCollide(final Block block, final Level world, final BlockPos pos, final Entity entity) {
if (!ShouldFire.COLLIDE_BLOCK_EVENT_STEP_ON || world.isClientSide) {
block.stepOn(world, pos, entity);
return;
}
final BlockState state = world.getBlockState(pos);
final org.spongepowered.api.util.Direction dir = org.spongepowered.api.util.Direction.NONE;
if (!SpongeCommonEventFactory.handleCollideBlockEvent(block, world, pos, state, entity, dir, SpongeCommonEventFactory.CollisionType.STEP_ON)) {
block.stepOn(world, pos, entity);
this.impl$lastCollidedBlockPos = pos;
}
}
use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class ServerPlayerGameModeMixin_Tracker method useItemOn.
/**
* @author Morph
* @reason Fire interact block event.
*/
@Overwrite
public InteractionResult useItemOn(final ServerPlayer playerIn, final Level worldIn, final ItemStack stackIn, final InteractionHand handIn, final BlockHitResult blockRaytraceResultIn) {
final BlockPos blockpos = blockRaytraceResultIn.getBlockPos();
final BlockState blockstate = worldIn.getBlockState(blockpos);
// Sponge start
final BlockSnapshot snapshot = ((ServerWorld) (worldIn)).createSnapshot(VecHelper.toVector3i(blockpos));
final Vector3d hitVec = Vector3d.from(blockRaytraceResultIn.getBlockPos().getX(), blockRaytraceResultIn.getBlockPos().getY(), blockRaytraceResultIn.getBlockPos().getZ());
final org.spongepowered.api.util.Direction direction = DirectionFacingProvider.INSTANCE.getKey(blockRaytraceResultIn.getDirection()).get();
final InteractBlockEvent.Secondary event = SpongeCommonEventFactory.callInteractBlockEventSecondary(playerIn, stackIn, hitVec, snapshot, direction, handIn);
if (event.isCancelled()) {
return InteractionResult.FAIL;
}
final Tristate useItem = event.useItemResult();
final Tristate useBlock = event.useBlockResult();
// Sponge end
if (this.gameModeForPlayer == GameType.SPECTATOR) {
final MenuProvider inamedcontainerprovider = blockstate.getMenuProvider(worldIn, blockpos);
if (inamedcontainerprovider != null) {
playerIn.openMenu(inamedcontainerprovider);
final Vector3i pos = VecHelper.toVector3i(blockRaytraceResultIn.getBlockPos());
final ServerLocation location = ServerLocation.of((ServerWorld) worldIn, pos);
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(playerIn);
frame.addContext(EventContextKeys.BLOCK_HIT, ((ServerWorld) (worldIn)).createSnapshot(pos));
((ContainerBridge) playerIn.containerMenu).bridge$setOpenLocation(location);
if (!InventoryEventFactory.callInteractContainerOpenEvent(playerIn)) {
return InteractionResult.SUCCESS;
}
}
return InteractionResult.SUCCESS;
} else {
return InteractionResult.PASS;
}
} else {
final boolean flag = !playerIn.getMainHandItem().isEmpty() || !playerIn.getOffhandItem().isEmpty();
final boolean flag1 = playerIn.isSecondaryUseActive() && flag;
final ItemStack copiedStack = stackIn.copy();
if (useBlock != Tristate.FALSE && !flag1) {
// Sponge check useBlock
final AbstractContainerMenu lastOpenContainer = playerIn.containerMenu;
final InteractionResult result = blockstate.use(worldIn, playerIn, handIn, blockRaytraceResultIn);
if (result.consumesAction() && lastOpenContainer != playerIn.containerMenu) {
final Vector3i pos = VecHelper.toVector3i(blockRaytraceResultIn.getBlockPos());
final ServerLocation location = ServerLocation.of((ServerWorld) worldIn, pos);
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(playerIn);
frame.addContext(EventContextKeys.BLOCK_HIT, ((ServerWorld) (worldIn)).createSnapshot(pos));
((ContainerBridge) playerIn.containerMenu).bridge$setOpenLocation(location);
if (!InventoryEventFactory.callInteractContainerOpenEvent(playerIn)) {
return InteractionResult.FAIL;
}
}
}
if (result.consumesAction()) {
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger(playerIn, blockpos, copiedStack);
return result;
}
}
if (!stackIn.isEmpty() && !playerIn.getCooldowns().isOnCooldown(stackIn.getItem())) {
// Sponge start
if (useItem == Tristate.FALSE) {
return InteractionResult.PASS;
}
// Sponge end
final UseOnContext itemusecontext = new UseOnContext(playerIn, handIn, blockRaytraceResultIn);
final InteractionResult result;
if (this.isCreative()) {
final int i = stackIn.getCount();
result = stackIn.useOn(itemusecontext);
stackIn.setCount(i);
} else {
result = stackIn.useOn(itemusecontext);
// Sponge start - log change in hand
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
transactor.logPlayerInventoryChange(this.player, PlayerInventoryTransaction.EventCreator.STANDARD);
this.player.inventoryMenu.broadcastChanges();
// Sponge end
}
if (result.consumesAction()) {
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger(playerIn, blockpos, copiedStack);
}
return result;
} else {
return InteractionResult.PASS;
}
}
}
use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class BlockTickContext method source.
@Override
public BlockTickContext source(final Object owner) {
super.source(owner);
if (owner instanceof LocatableBlock) {
final LocatableBlock locatableBlock = (LocatableBlock) owner;
final Block block = ((BlockState) locatableBlock.blockState()).getBlock();
this.tickingBlock = (BlockBridge) block;
this.providesModifier = !(block instanceof LiquidBlock);
this.world = locatableBlock.world();
if (block instanceof TrackableBridge) {
final TrackableBridge trackable = (TrackableBridge) block;
this.setBlockEvents(trackable.bridge$allowsBlockEventCreation()).setBulkBlockCaptures(trackable.bridge$allowsBlockBulkCaptures()).setEntitySpawnEvents(trackable.bridge$allowsEntityEventCreation()).setBulkEntityCaptures(trackable.bridge$allowsEntityBulkCaptures());
}
}
return this;
}
use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class FluidTickContext method source.
@Override
public FluidTickContext source(final Object owner) {
super.source(owner);
if (owner instanceof LocatableBlock) {
final LocatableBlock locatableBlock = (LocatableBlock) owner;
final Block block = ((BlockState) locatableBlock.blockState()).getBlock();
this.providesModifier = !(block instanceof LiquidBlock);
this.world = locatableBlock.world();
if (block instanceof TrackableBridge) {
final TrackableBridge trackable = (TrackableBridge) block;
this.setBlockEvents(trackable.bridge$allowsBlockEventCreation()).setBulkBlockCaptures(trackable.bridge$allowsBlockBulkCaptures()).setEntitySpawnEvents(trackable.bridge$allowsEntityEventCreation()).setBulkEntityCaptures(trackable.bridge$allowsEntityBulkCaptures());
}
}
return this;
}
use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class VolumeStreamUtils method getBlockEntityOrCloneToBackingVolume.
@NonNull
public static BiConsumer<BlockPos, net.minecraft.world.level.block.entity.BlockEntity> getBlockEntityOrCloneToBackingVolume(final boolean shouldCarbonCopy, final ObjectArrayMutableBlockEntityBuffer backingVolume, @Nullable final Level level) {
return shouldCarbonCopy ? (pos, tile) -> {
final CompoundTag nbt = tile.save(new CompoundTag());
final net.minecraft.world.level.block.entity.@Nullable BlockEntity cloned = tile.getType().create();
final BlockState state = tile.getBlockState();
Objects.requireNonNull(cloned, () -> String.format("TileEntityType[%s] creates a null TileEntity!", BlockEntityType.getKey(tile.getType()))).load(state, nbt);
if (level != null) {
((BlockEntityAccessor) cloned).accessor$level(level);
}
backingVolume.addBlockEntity(pos.getX(), pos.getY(), pos.getZ(), (BlockEntity) cloned);
} : (pos, tile) -> {
};
}
Aggregations