Search in sources :

Example 11 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class MixinWorld_Tracker method setNotifier.

@Override
public void setNotifier(int x, int y, int z, @Nullable UUID uuid) {
    final Chunk chunk = ((IMixinChunkProviderServer) this.chunkProvider).getLoadedChunkWithoutMarkingActive(x >> 4, z >> 4);
    if (chunk == null) {
        return;
    }
    BlockPos pos = new BlockPos(x, y, z);
    ((IMixinChunk) chunk).setBlockNotifier(pos, uuid);
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Example 12 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class PacketState method associateNeighborStateNotifier.

@Override
public void associateNeighborStateNotifier(P unwindingContext, BlockPos sourcePos, Block block, BlockPos notifyPos, WorldServer minecraftWorld, PlayerTracker.Type notifier) {
    final Player player = unwindingContext.getSpongePlayer();
    Chunk chunk = minecraftWorld.getChunkFromBlockCoords(notifyPos);
    ((IMixinChunk) chunk).setBlockNotifier(notifyPos, player.getUniqueId());
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk)

Example 13 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class BlockEventTickPhaseState method handleBlockChangeWithUser.

@Override
public void handleBlockChangeWithUser(@Nullable BlockChange blockChange, Transaction<BlockSnapshot> snapshotTransaction, BlockEventTickContext context) {
    final Block block = (Block) snapshotTransaction.getOriginal().getState().getType();
    final Location<World> changedLocation = snapshotTransaction.getOriginal().getLocation().get();
    final Vector3d changedPosition = changedLocation.getPosition();
    final BlockPos changedBlockPos = VecHelper.toBlockPos(changedPosition);
    final IMixinChunk changedMixinChunk = (IMixinChunk) ((WorldServer) changedLocation.getExtent()).getChunkFromBlockCoords(changedBlockPos);
    changedMixinChunk.getBlockOwner(changedBlockPos).ifPresent(owner -> changedMixinChunk.addTrackedBlockPosition(block, changedBlockPos, owner, PlayerTracker.Type.OWNER));
    final User user = TrackingUtil.getNotifierOrOwnerFromBlock(changedLocation);
    if (user != null) {
        changedMixinChunk.addTrackedBlockPosition(block, changedBlockPos, user, PlayerTracker.Type.NOTIFIER);
    }
}
Also used : User(org.spongepowered.api.entity.living.player.User) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Vector3d(com.flowpowered.math.vector.Vector3d) Block(net.minecraft.block.Block) LocatableBlock(org.spongepowered.api.world.LocatableBlock) BlockPos(net.minecraft.util.math.BlockPos) World(org.spongepowered.api.world.World)

Example 14 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class MixinTileEntityHopper method onPutDrop.

@Inject(method = "putDropInInventoryAllSlots", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/EntityItem;getItem()Lnet/minecraft/item/ItemStack;"))
private static void onPutDrop(IInventory inventory, IInventory hopper, EntityItem entityItem, CallbackInfoReturnable<Boolean> callbackInfo) {
    ((IMixinEntity) entityItem).getCreatorUser().ifPresent(owner -> {
        if (inventory instanceof TileEntity) {
            TileEntity te = (TileEntity) inventory;
            BlockPos pos = te.getPos();
            IMixinChunk spongeChunk = (IMixinChunk) te.getWorld().getChunkFromBlockCoords(pos);
            spongeChunk.addTrackedBlockPosition(te.getBlockType(), pos, owner, PlayerTracker.Type.NOTIFIER);
        }
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) BlockPos(net.minecraft.util.math.BlockPos) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 15 with IMixinChunk

use of org.spongepowered.common.interfaces.IMixinChunk in project SpongeCommon by SpongePowered.

the class MixinChunk method setBlockState.

/**
 * @author blood - November 2015
 * @author gabizou - updated April 10th, 2016 - Add cause tracking refactor changes
 *
 * @param pos The position changing
 * @param newState The new state
 * @param currentState The current state - passed in from either chunk or world
 * @param newBlockSnapshot The new snapshot. This can be null when calling {@link MixinChunk#setBlockState(BlockPos, IBlockState)} directly,
 *      as there's no block snapshot to change.
 * @return The changed block state if not null
 */
@Override
@Nullable
public IBlockState setBlockState(BlockPos pos, IBlockState newState, IBlockState currentState, @Nullable BlockSnapshot newBlockSnapshot, BlockChangeFlag flag) {
    int xPos = pos.getX() & 15;
    int yPos = pos.getY();
    int zPos = pos.getZ() & 15;
    int combinedPos = zPos << 4 | xPos;
    if (yPos >= this.precipitationHeightMap[combinedPos] - 1) {
        this.precipitationHeightMap[combinedPos] = -999;
    }
    int currentHeight = this.heightMap[combinedPos];
    // Sponge Start - remove blockstate check as we handle it in world.setBlockState
    // IBlockState iblockstate = this.getBlockState(pos);
    // 
    // if (iblockstate == state) {
    // return null;
    // } else {
    Block newBlock = newState.getBlock();
    Block currentBlock = currentState.getBlock();
    // Sponge End
    ExtendedBlockStorage extendedblockstorage = this.storageArrays[yPos >> 4];
    // Sponge - make this final so we don't change it later
    final boolean requiresNewLightCalculations;
    // Sponge - Forge moves this from
    int newBlockLightOpacity = SpongeImplHooks.getBlockLightOpacity(newState, this.world, pos);
    if (extendedblockstorage == net.minecraft.world.chunk.Chunk.NULL_BLOCK_STORAGE) {
        if (newBlock == Blocks.AIR) {
            return null;
        }
        extendedblockstorage = this.storageArrays[yPos >> 4] = new ExtendedBlockStorage(yPos >> 4 << 4, this.world.provider.hasSkyLight());
        requiresNewLightCalculations = yPos >= currentHeight;
    // Sponge Start - properly initialize variable
    } else {
        requiresNewLightCalculations = false;
    }
    // Sponge end
    // Sponge Start
    final int modifiedY = yPos & 15;
    extendedblockstorage.set(xPos, modifiedY, zPos, newState);
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final PhaseData peek = phaseTracker.getCurrentPhaseData();
    final boolean requiresCapturing = peek.state.requiresBlockCapturing();
    // if (block1 != block) // Sponge - Forge removes this change.
    {
        if (!this.world.isRemote) {
            // Sponge - Forge adds this change for block changes to only fire events when necessary
            if (currentState.getBlock() != newState.getBlock()) {
                currentBlock.breakBlock(this.world, pos, currentState);
            }
            // Sponge - Add several tile entity hook checks. Mainly for forge added hooks, but these
            // still work by themselves in vanilla.
            TileEntity te = this.getTileEntity(pos, EnumCreateEntityType.CHECK);
            if (te != null && SpongeImplHooks.shouldRefresh(te, this.world, pos, currentState, newState)) {
                this.world.removeTileEntity(pos);
            }
        // } else if (currentBlock instanceof ITileEntityProvider) { // Sponge - remove since forge has a special hook we need to add here
        } else if (SpongeImplHooks.hasBlockTileEntity(currentBlock, currentState)) {
            TileEntity tileEntity = this.getTileEntity(pos, EnumCreateEntityType.CHECK);
            // Sponge - Add hook for refreshing, because again, forge hooks.
            if (tileEntity != null && SpongeImplHooks.shouldRefresh(tileEntity, this.world, pos, currentState, newState)) {
                this.world.removeTileEntity(pos);
            }
        }
    }
    final IBlockState blockAfterSet = extendedblockstorage.get(xPos, modifiedY, zPos);
    if (blockAfterSet.getBlock() != newBlock) {
        return null;
    }
    // } else { // Sponge - remove unnecessary else
    if (requiresNewLightCalculations) {
        this.generateSkylightMap();
    } else {
        // int newBlockLightOpacity = state.getLightOpacity(); - Sponge Forge moves this all the way up before tile entities are removed.
        // int postNewBlockLightOpacity = newState.getLightOpacity(this.worldObj, pos); - Sponge use the SpongeImplHooks for forge compatibility
        int postNewBlockLightOpacity = SpongeImplHooks.getBlockLightOpacity(newState, this.world, pos);
        if (newBlockLightOpacity > 0) {
            if (yPos >= currentHeight) {
                this.relightBlock(xPos, yPos + 1, zPos);
            }
        } else if (yPos == currentHeight - 1) {
            this.relightBlock(xPos, yPos, zPos);
        }
        if (newBlockLightOpacity != postNewBlockLightOpacity && (newBlockLightOpacity < postNewBlockLightOpacity || this.getLightFor(EnumSkyBlock.SKY, pos) > 0 || this.getLightFor(EnumSkyBlock.BLOCK, pos) > 0)) {
            this.propagateSkylightOcclusion(xPos, zPos);
        }
    }
    if (!this.world.isRemote && currentBlock != newBlock) {
        // a BlockContainer. Prevents blocks such as TNT from activating when cancelled.
        if (!requiresCapturing || SpongeImplHooks.hasBlockTileEntity(newBlock, newState)) {
            // If it is null, then directly call the onBlockAdded logic.
            if (flag.performBlockPhysics()) {
                newBlock.onBlockAdded(this.world, pos, newState);
            }
        }
    // Sponge end
    }
    // if (block instanceof ITileEntityProvider) { // Sponge
    if (SpongeImplHooks.hasBlockTileEntity(newBlock, newState)) {
        // Sponge End
        TileEntity tileentity = this.getTileEntity(pos, EnumCreateEntityType.CHECK);
        if (tileentity == null) {
            // Sponge Start - use SpongeImplHooks for forge compatibility
            // tileentity = ((ITileEntityProvider)block).createNewTileEntity(this.worldObj, block.getMetaFromState(state)); // Sponge
            tileentity = SpongeImplHooks.createTileEntity(newBlock, this.world, newState);
            final User owner = peek.context.getOwner().orElse(null);
            // This is required for TE's that get created during move such as pistons and ComputerCraft turtles.
            if (owner != null) {
                IMixinChunk spongeChunk = (IMixinChunk) this;
                spongeChunk.addTrackedBlockPosition(newBlock, pos, owner, PlayerTracker.Type.OWNER);
            }
            // Sponge End
            this.world.setTileEntity(pos, tileentity);
        }
        if (tileentity != null) {
            tileentity.updateContainingBlockInfo();
        }
    }
    this.dirty = true;
    return currentState;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) PhaseData(org.spongepowered.common.event.tracking.PhaseData) IBlockState(net.minecraft.block.state.IBlockState) User(org.spongepowered.api.entity.living.player.User) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Block(net.minecraft.block.Block) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) Nullable(javax.annotation.Nullable)

Aggregations

IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)49 Chunk (net.minecraft.world.chunk.Chunk)21 BlockPos (net.minecraft.util.math.BlockPos)18 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)12 User (org.spongepowered.api.entity.living.player.User)11 Inject (org.spongepowered.asm.mixin.injection.Inject)8 IBlockState (net.minecraft.block.state.IBlockState)7 World (org.spongepowered.api.world.World)7 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)7 LocatableBlock (org.spongepowered.api.world.LocatableBlock)6 Vector3i (com.flowpowered.math.vector.Vector3i)5 Block (net.minecraft.block.Block)5 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)5 Direction (org.spongepowered.api.util.Direction)5 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 PhaseData (org.spongepowered.common.event.tracking.PhaseData)4 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)4 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)4 Vector3d (com.flowpowered.math.vector.Vector3d)3