use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class ServerLevelMixin_Tracker method bridge$startBlockChange.
@Override
public Optional<WorldPipeline.Builder> bridge$startBlockChange(final BlockPos pos, final BlockState newState, final int flags) {
if (net.minecraft.world.level.Level.isOutsideBuildHeight(pos)) {
return Optional.empty();
} else if (this.shadow$isDebug()) {
// isClientSide is always false since this is WorldServer
return Optional.empty();
}
// Sponge Start - Sanity check against the PhaseTracker for instances
if (this.bridge$isFake()) {
return Optional.empty();
}
final PhaseTracker instance = PhaseTracker.getInstance();
if (instance.getSidedThread() != PhaseTracker.SERVER.getSidedThread() && instance != PhaseTracker.SERVER) {
throw new UnsupportedOperationException("Cannot perform a tracked Block Change on a ServerWorld while not on the main thread!");
}
final SpongeBlockChangeFlag spongeFlag = BlockChangeFlagManager.fromNativeInt(flags);
final LevelChunk chunk = this.shadow$getChunkAt(pos);
if (chunk.isEmpty()) {
return Optional.empty();
}
final net.minecraft.world.level.block.state.BlockState currentState = chunk.getBlockState(pos);
return Optional.of(this.bridge$makePipeline(pos, currentState, newState, chunk, spongeFlag, Constants.World.DEFAULT_BLOCK_CHANGE_LIMIT));
}
use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class ServerLevelMixin_Tracker method destroyBlock.
@Override
public boolean destroyBlock(final BlockPos pos, final boolean doDrops, @Nullable final Entity p_241212_3_, final int limit) {
final BlockState currentState = this.shadow$getBlockState(pos);
if (currentState.isAir()) {
return false;
} else {
// Sponge Start - Sanity check against the PhaseTracker for instances
if (this.bridge$isFake()) {
return super.destroyBlock(pos, doDrops, p_241212_3_, limit);
}
final PhaseTracker instance = PhaseTracker.getInstance();
if (instance.getSidedThread() != PhaseTracker.SERVER.getSidedThread() && instance != PhaseTracker.SERVER) {
throw new UnsupportedOperationException("Cannot perform a tracked Block Change on a ServerWorld while not on the main thread!");
}
final FluidState fluidstate = this.shadow$getFluidState(pos);
final BlockState emptyBlock = fluidstate.createLegacyBlock();
final SpongeBlockChangeFlag spongeFlag = BlockChangeFlagManager.fromNativeInt(3);
final LevelChunk chunk = this.shadow$getChunkAt(pos);
if (chunk.isEmpty()) {
return false;
}
final WorldPipeline.Builder pipelineBuilder = this.bridge$makePipeline(pos, currentState, emptyBlock, chunk, spongeFlag, limit).addEffect(WorldDestroyBlockLevelEffect.getInstance());
if (doDrops) {
pipelineBuilder.addEffect(PerformBlockDropsFromDestruction.getInstance());
}
final WorldPipeline pipeline = pipelineBuilder.addEffect(WorldBlockChangeCompleteEffect.getInstance()).build();
return pipeline.processEffects(instance.getPhaseContext(), currentState, emptyBlock, pos, p_241212_3_, spongeFlag, limit);
}
}
use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class BlockGetterMixin_RayTraceChunkLoadOptimizations method clip.
// @formatter:on
/**
* Can be modified later when
* <a href="https://github.com/SpongePowered/Mixin/issues/355">the mixin feature</a>
* is resolved.
* <p>
* Check if a chunk is loaded before attempting to check the state of the block
* return null if the chunk is not loaded. Based on
* <a href="https://github.com/PaperMC/Paper/blob/ver/1.15.2/Spigot-Server-Patches/0331-Prevent-rayTrace-from-loading-chunks.patch#L16">a Paper patch</a>
*
* @author gabizou - Minecraft 1.15.2 - October 16th, 2020
* @reason Because this patch requires a lambda injection, I don't want
* to risk the breakages that can be caused by injecting into an interface.
*/
@Overwrite
default BlockHitResult clip(final ClipContext context) {
return BlockGetter.traverseBlocks(context, (p_217297_1_, p_217297_2_) -> {
// Sponge start - check if the blockstate is loaded/null
// final BlockState blockstate = this.shadow$getBlockState(p_217297_2_); // Vanilla
@Nullable final BlockState lvt_3_1_ = ((BlockGetterBridge) this).bridge$getBlockIfLoaded(p_217297_2_);
if (lvt_3_1_ == null) {
// copied the last function parameter (listed below)
final Vec3 vec3d = p_217297_1_.getFrom().subtract(p_217297_1_.getTo());
return BlockHitResult.miss(context.getTo(), Direction.getNearest(vec3d.x, vec3d.y, vec3d.z), new BlockPos(p_217297_1_.getTo()));
}
// Sponge end
final FluidState lvt_4_1_ = this.shadow$getFluidState(p_217297_2_);
final Vec3 lvt_5_1_ = p_217297_1_.getFrom();
final Vec3 lvt_6_1_ = p_217297_1_.getTo();
final VoxelShape lvt_7_1_ = p_217297_1_.getBlockShape(lvt_3_1_, (BlockGetter) this, p_217297_2_);
final BlockHitResult lvt_8_1_ = this.shadow$clipWithInteractionOverride(lvt_5_1_, lvt_6_1_, p_217297_2_, lvt_7_1_, lvt_3_1_);
final VoxelShape lvt_9_1_ = p_217297_1_.getFluidShape(lvt_4_1_, (BlockGetter) this, p_217297_2_);
final BlockHitResult lvt_10_1_ = lvt_9_1_.clip(lvt_5_1_, lvt_6_1_, p_217297_2_);
final double lvt_11_1_ = lvt_8_1_ == null ? 1.7976931348623157E308D : p_217297_1_.getFrom().distanceToSqr(lvt_8_1_.getLocation());
final double lvt_13_1_ = lvt_10_1_ == null ? 1.7976931348623157E308D : p_217297_1_.getFrom().distanceToSqr(lvt_10_1_.getLocation());
return lvt_11_1_ <= lvt_13_1_ ? lvt_8_1_ : lvt_10_1_;
}, (p_217302_0_) -> {
final Vec3 lvt_1_1_ = p_217302_0_.getFrom().subtract(p_217302_0_.getTo());
return BlockHitResult.miss(p_217302_0_.getTo(), Direction.getNearest(lvt_1_1_.x, lvt_1_1_.y, lvt_1_1_.z), new BlockPos(p_217302_0_.getTo()));
});
}
use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class ServerLocationData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ServerLocation.class).create(Keys.BIOME_TEMPERATURE).get(h -> {
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h);
final Biome biome = world.getBiome(pos);
return (double) biome.getBaseTemperature();
}).create(Keys.BLOCK_LIGHT).get(h -> {
final Level world = (Level) h.world();
return world.getBrightness(LightLayer.BLOCK, VecHelper.toBlockPos(h));
}).create(Keys.BLOCK_TEMPERATURE).get(h -> {
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h);
final Biome biome = world.getBiome(pos);
return (double) biome.getTemperature(pos);
}).create(Keys.SKY_LIGHT).get(h -> {
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h);
return world.getBrightness(LightLayer.SKY, pos);
}).create(Keys.IS_FULL_BLOCK).get(h -> {
final BlockState block = (BlockState) h.block();
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h.position());
return block.isSolidRender(world, pos);
}).create(Keys.IS_INDIRECTLY_POWERED).get(h -> {
final Level world = (Level) h.world();
final BlockPos pos = VecHelper.toBlockPos(h);
return world.getBestNeighborSignal(pos) > 0;
}).create(Keys.DISPLAY_NAME).get(h -> SpongeAdventure.asAdventure(((Nameable) h.blockEntity().get()).getDisplayName())).supports(h -> h.blockEntity().isPresent() && h.blockEntity().get() instanceof NameableBlockEntity).create(Keys.CUSTOM_NAME).get(h -> {
final BlockEntity blockEntity = h.blockEntity().get();
return ((Nameable) blockEntity).hasCustomName() ? SpongeAdventure.asAdventure(((Nameable) blockEntity).getCustomName()) : null;
}).set((h, v) -> (((CustomNameableBridge) h.blockEntity().get())).bridge$setCustomDisplayName(SpongeAdventure.asVanilla(v))).delete(h -> (((CustomNameableBridge) h.blockEntity().get())).bridge$setCustomDisplayName(null)).supports(h -> h.blockEntity().isPresent() && h.blockEntity().get() instanceof NameableBlockEntity).create(Keys.CREATOR).get(h -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$getBlockCreatorUUID(VecHelper.toBlockPos(h.blockPosition())).orElse(null)).set((h, v) -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$setBlockCreator(VecHelper.toBlockPos(h.blockPosition()), v)).delete(h -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$setBlockCreator(VecHelper.toBlockPos(h.blockPosition()), null)).create(Keys.NOTIFIER).get(h -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$getBlockNotifierUUID(VecHelper.toBlockPos(h.blockPosition())).orElse(null)).set((h, v) -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$setBlockNotifier(VecHelper.toBlockPos(h.blockPosition()), v)).delete(h -> ((LevelChunkBridge) h.world().chunk(h.chunkPosition())).bridge$setBlockNotifier(VecHelper.toBlockPos(h.blockPosition()), null));
}
use of net.minecraft.world.level.block.state.BlockState in project SpongeCommon by SpongePowered.
the class UpdateLightSideEffect method processSideEffect.
@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
if (!flag.updateLighting()) {
return EffectResult.NULL_PASS;
}
final int originalOpactiy = oldState.opacity;
final ServerLevel serverWorld = pipeline.getServerWorld();
final BlockState currentState = pipeline.getAffectedChunk().getBlockState(oldState.pos);
// ) {
if (oldState.state != currentState && (currentState.getLightBlock(serverWorld, oldState.pos) != originalOpactiy || currentState.getLightEmission() != oldState.state.getLightEmission() || currentState.useShapeForLightOcclusion() || oldState.state.useShapeForLightOcclusion())) {
// this.profiler.startSection("queueCheckLight");
serverWorld.getProfiler().push("queueCheckLight");
// this.getChunkProvider().getLightManager().checkBlock(pos);
serverWorld.getChunkSource().getLightEngine().checkBlock(oldState.pos);
// this.profiler.endSection();
serverWorld.getProfiler().pop();
}
return EffectResult.NULL_PASS;
}
Aggregations