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);
}
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());
}
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);
}
}
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);
}
});
}
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;
}
Aggregations