Search in sources :

Example 86 with Location

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);
    }
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) Location(org.spongepowered.api.world.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 87 with Location

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);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) PhaseData(org.spongepowered.common.event.tracking.PhaseData) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) Location(org.spongepowered.api.world.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 88 with Location

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;
    }
}
Also used : ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Location(org.spongepowered.api.world.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 89 with Location

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);
}
Also used : GroundLuminanceProperty(org.spongepowered.api.data.property.block.GroundLuminanceProperty) Chunk(net.minecraft.world.chunk.Chunk) Location(org.spongepowered.api.world.Location) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation)

Example 90 with Location

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);
}
Also used : UUID(java.util.UUID) Location(org.spongepowered.api.world.Location)

Aggregations

Location (org.spongepowered.api.world.Location)166 World (org.spongepowered.api.world.World)96 Listener (org.spongepowered.api.event.Listener)44 Player (org.spongepowered.api.entity.living.player.Player)40 Vector3d (com.flowpowered.math.vector.Vector3d)38 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)32 Vector3i (com.flowpowered.math.vector.Vector3i)31 Optional (java.util.Optional)28 Entity (org.spongepowered.api.entity.Entity)27 BlockType (org.spongepowered.api.block.BlockType)24 BlockState (org.spongepowered.api.block.BlockState)23 ItemStack (org.spongepowered.api.item.inventory.ItemStack)23 Direction (org.spongepowered.api.util.Direction)21 ArrayList (java.util.ArrayList)20 Keys (org.spongepowered.api.data.key.Keys)20 List (java.util.List)19 Text (org.spongepowered.api.text.Text)19 BlockPos (net.minecraft.util.math.BlockPos)18 Sponge (org.spongepowered.api.Sponge)15 Map (java.util.Map)14