use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinBlockLeaves method onUpdateDecayState.
@Redirect(method = "updateTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;I)Z"))
public boolean onUpdateDecayState(net.minecraft.world.World worldIn, BlockPos pos, IBlockState state, int flags) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final boolean isBlockAlready = phaseTracker.getCurrentState().getPhase() != TrackingPhases.BLOCK;
final IPhaseState currentState = phaseTracker.getCurrentPhaseData().state;
final boolean isWorldGen = currentState.isWorldGeneration();
try (PhaseContext<?> context = isBlockAlready && !isWorldGen ? BlockPhase.State.BLOCK_DECAY.createPhaseContext().source(LocatableBlock.builder().location(new Location<World>((World) worldIn, pos.getX(), pos.getY(), pos.getZ())).state((BlockState) state).build()).buildAndSwitch() : null) {
return worldIn.setBlockState(pos, state, flags);
}
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinBlockLeaves method destroy.
/**
* @author gabizou - August 2nd, 2016
* @reason Rewrite to handle both drops and the change state for leaves
* that are considered to be decaying, so the drops do not leak into
* whatever previous phase is being handled in. Since the issue is that
* the block change takes place in a different phase (more than likely),
* the drops are either "lost" or not considered for drops because the
* blocks didn't change according to whatever previous phase.
*
* @param worldIn The world in
* @param pos The position
*/
@Overwrite
private void destroy(net.minecraft.world.World worldIn, BlockPos pos) {
final IBlockState state = worldIn.getBlockState(pos);
// Sponge Start - Cause tracking
if (!((IMixinWorld) worldIn).isFake()) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final PhaseData peek = phaseTracker.getCurrentPhaseData();
final IPhaseState currentState = peek.state;
final boolean isWorldGen = currentState.isWorldGeneration();
final boolean isBlockAlready = phaseTracker.getCurrentState().getPhase() != TrackingPhases.BLOCK;
try (PhaseContext<?> context = isBlockAlready && !isWorldGen ? BlockPhase.State.BLOCK_DECAY.createPhaseContext().source(LocatableBlock.builder().location(new Location<World>((World) worldIn, pos.getX(), pos.getY(), pos.getZ())).state((BlockState) state).build()).buildAndSwitch() : null) {
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
return;
}
// Sponge End
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinBlockStaticLiquid method onSpreadFire.
@Redirect(method = "updateTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)Z"))
private boolean onSpreadFire(World world, BlockPos pos, IBlockState blockState) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final PhaseContext<?> context = phaseTracker.getCurrentPhaseData().context;
try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(pos);
frame.pushCause(this);
context.getOwner().ifPresent(owner -> frame.addContext(EventContextKeys.OWNER, owner));
context.getNotifier().ifPresent(notifier -> frame.addContext(EventContextKeys.NOTIFIER, notifier));
ChangeBlockEvent.Pre event = SpongeEventFactory.createChangeBlockEventPre(frame.getCurrentCause(), Collections.singletonList(new Location<>((org.spongepowered.api.world.World) world, VecHelper.toVector3i(pos))));
if (!SpongeImpl.postEvent(event)) {
phaseTracker.setBlockState((IMixinWorldServer) world, pos, blockState, BlockChangeFlags.ALL);
return true;
}
return false;
}
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class GroundLuminancePropertyStore method getFor.
@Override
public Optional<GroundLuminanceProperty> getFor(PropertyHolder propertyHolder) {
if (propertyHolder instanceof Location && ((Location<?>) propertyHolder).getExtent() instanceof Chunk) {
final Chunk chunk = (Chunk) ((Location<?>) propertyHolder).getExtent();
final float light = chunk.getLightFor(EnumSkyBlock.BLOCK, ((IMixinLocation) propertyHolder).getBlockPos());
return Optional.of(new GroundLuminanceProperty(light));
}
return super.getFor(propertyHolder);
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class DataUtil method getLocation.
public static Location<World> getLocation(DataView view, boolean castToInt) {
final UUID worldUuid = UUID.fromString(view.getString(Queries.WORLD_ID).get());
final double x = view.getDouble(Queries.POSITION_X).get();
final double y = view.getDouble(Queries.POSITION_Y).get();
final double z = view.getDouble(Queries.POSITION_Z).get();
if (castToInt) {
return new Location<>(SpongeImpl.getGame().getServer().getWorld(worldUuid).get(), (int) x, (int) y, (int) z);
}
return new Location<>(SpongeImpl.getGame().getServer().getWorld(worldUuid).get(), x, y, z);
}
Aggregations