Search in sources :

Example 1 with TrackableBridge

use of org.spongepowered.common.bridge.TrackableBridge in project SpongeCommon by SpongePowered.

the class TileEntityTickContext method source.

@Override
public TileEntityTickContext source(final Object owner) {
    super.source(owner);
    if (owner instanceof TrackableBridge) {
        final TrackableBridge mixinTileentity = (TrackableBridge) owner;
        this.setBlockEvents(mixinTileentity.bridge$allowsBlockEventCreation()).setBulkBlockCaptures(mixinTileentity.bridge$allowsBlockBulkCaptures()).setEntitySpawnEvents(mixinTileentity.bridge$allowsEntityEventCreation()).setBulkEntityCaptures(mixinTileentity.bridge$allowsEntityBulkCaptures());
    }
    return this;
}
Also used : TrackableBridge(org.spongepowered.common.bridge.TrackableBridge)

Example 2 with TrackableBridge

use of org.spongepowered.common.bridge.TrackableBridge in project SpongeCommon by SpongePowered.

the class BlockTickContext method source.

@Override
public BlockTickContext source(final Object owner) {
    super.source(owner);
    if (owner instanceof LocatableBlock) {
        final LocatableBlock locatableBlock = (LocatableBlock) owner;
        final Block block = ((BlockState) locatableBlock.blockState()).getBlock();
        this.tickingBlock = (BlockBridge) block;
        this.providesModifier = !(block instanceof LiquidBlock);
        this.world = locatableBlock.world();
        if (block instanceof TrackableBridge) {
            final TrackableBridge trackable = (TrackableBridge) block;
            this.setBlockEvents(trackable.bridge$allowsBlockEventCreation()).setBulkBlockCaptures(trackable.bridge$allowsBlockBulkCaptures()).setEntitySpawnEvents(trackable.bridge$allowsEntityEventCreation()).setBulkEntityCaptures(trackable.bridge$allowsEntityBulkCaptures());
        }
    }
    return this;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Block(net.minecraft.world.level.block.Block) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) LocatableBlock(org.spongepowered.api.world.LocatableBlock) TrackableBridge(org.spongepowered.common.bridge.TrackableBridge) LiquidBlock(net.minecraft.world.level.block.LiquidBlock)

Example 3 with TrackableBridge

use of org.spongepowered.common.bridge.TrackableBridge in project SpongeCommon by SpongePowered.

the class EntityTickContext method source.

@Override
public EntityTickContext source(final Object owner) {
    super.source(owner);
    if (owner instanceof TrackableBridge) {
        final TrackableBridge mixinEntity = (TrackableBridge) owner;
        this.setBulkBlockCaptures(mixinEntity.bridge$allowsBlockBulkCaptures());
        this.setBlockEvents(mixinEntity.bridge$allowsBlockEventCreation());
        this.setBulkEntityCaptures(mixinEntity.bridge$allowsEntityBulkCaptures());
        this.setEntitySpawnEvents(mixinEntity.bridge$allowsEntityEventCreation());
    }
    return super.source(owner);
}
Also used : TrackableBridge(org.spongepowered.common.bridge.TrackableBridge)

Example 4 with TrackableBridge

use of org.spongepowered.common.bridge.TrackableBridge in project SpongeCommon by SpongePowered.

the class FluidTickContext method source.

@Override
public FluidTickContext source(final Object owner) {
    super.source(owner);
    if (owner instanceof LocatableBlock) {
        final LocatableBlock locatableBlock = (LocatableBlock) owner;
        final Block block = ((BlockState) locatableBlock.blockState()).getBlock();
        this.providesModifier = !(block instanceof LiquidBlock);
        this.world = locatableBlock.world();
        if (block instanceof TrackableBridge) {
            final TrackableBridge trackable = (TrackableBridge) block;
            this.setBlockEvents(trackable.bridge$allowsBlockEventCreation()).setBulkBlockCaptures(trackable.bridge$allowsBlockBulkCaptures()).setEntitySpawnEvents(trackable.bridge$allowsEntityEventCreation()).setBulkEntityCaptures(trackable.bridge$allowsEntityBulkCaptures());
        }
    }
    return this;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Block(net.minecraft.world.level.block.Block) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) LocatableBlock(org.spongepowered.api.world.LocatableBlock) TrackableBridge(org.spongepowered.common.bridge.TrackableBridge) LiquidBlock(net.minecraft.world.level.block.LiquidBlock)

Example 5 with TrackableBridge

use of org.spongepowered.common.bridge.TrackableBridge in project SpongeCommon by SpongePowered.

the class ServerLevelMixin_Tracker method tracker$associatePhaseContextDataWithBlockEvent.

@Redirect(method = "blockEvent", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/ObjectLinkedOpenHashSet;add(Ljava/lang/Object;)Z", remap = false))
private boolean tracker$associatePhaseContextDataWithBlockEvent(final ObjectLinkedOpenHashSet<BlockEventData> list, final Object data, final BlockPos pos, final Block blockIn, final int eventID, final int eventParam) {
    final PhaseContext<@NonNull ?> currentContext = PhaseTracker.getInstance().getPhaseContext();
    final BlockEventData blockEventData = (BlockEventData) data;
    final TrackableBlockEventDataBridge blockEvent = (TrackableBlockEventDataBridge) blockEventData;
    // Short circuit phase states who do not track during block events
    if (currentContext.ignoresBlockEvent()) {
        return list.add(blockEventData);
    }
    final BlockState state = this.shadow$getBlockState(pos);
    if (((TrackableBridge) blockIn).bridge$allowsBlockEventCreation()) {
        blockEvent.bridge$setSourceUserUUID(currentContext.getActiveUserUUID());
        if (((BlockStateBridge) state).bridge$hasTileEntity()) {
            blockEvent.bridge$setTileEntity((BlockEntity) this.shadow$getBlockEntity(pos));
        }
        if (blockEvent.bridge$getTileEntity() == null) {
            final LocatableBlock locatable = new SpongeLocatableBlockBuilder().world((org.spongepowered.api.world.server.ServerWorld) this).position(pos.getX(), pos.getY(), pos.getZ()).state((org.spongepowered.api.block.BlockState) state).build();
            blockEvent.bridge$setTickingLocatable(locatable);
        }
    }
    // allow tracking to take place for other/future phases
    if (!((TrackableBridge) blockIn).bridge$allowsBlockEventCreation()) {
        return list.add((BlockEventData) data);
    }
    // In pursuant with our block updates management, we chose to
    // effectively allow the block event get added to the list, but
    // we log the transaction so that we can call the change block event
    // pre, and if needed, undo the add to the list.
    currentContext.appendNotifierToBlockEvent(this, pos, blockEvent);
    // This is very common with pistons as they add block events while blocks are being notified.
    if (ShouldFire.CHANGE_BLOCK_EVENT_PRE) {
        if (blockIn instanceof PistonBaseBlock) {
            // We only fire pre events for pistons
            if (SpongeCommonEventFactory.handlePistonEvent(this, pos, state, eventID)) {
                return false;
            }
        } else {
            if (SpongeCommonEventFactory.callChangeBlockEventPre((ServerLevelBridge) this, pos).isCancelled()) {
                return false;
            }
        }
    }
    currentContext.getTransactor().logBlockEvent(state, this, pos, blockEvent);
    return list.add(blockEventData);
}
Also used : SpongeLocatableBlockBuilder(org.spongepowered.common.world.server.SpongeLocatableBlockBuilder) TrackableBlockEventDataBridge(org.spongepowered.common.bridge.world.level.TrackableBlockEventDataBridge) TrackableBridge(org.spongepowered.common.bridge.TrackableBridge) PistonBaseBlock(net.minecraft.world.level.block.piston.PistonBaseBlock) BlockState(net.minecraft.world.level.block.state.BlockState) LocatableBlock(org.spongepowered.api.world.LocatableBlock) ServerLevelBridge(org.spongepowered.common.bridge.server.level.ServerLevelBridge) BlockEventData(net.minecraft.world.level.BlockEventData) BlockStateBridge(org.spongepowered.common.bridge.world.level.block.state.BlockStateBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

TrackableBridge (org.spongepowered.common.bridge.TrackableBridge)5 BlockState (net.minecraft.world.level.block.state.BlockState)3 LocatableBlock (org.spongepowered.api.world.LocatableBlock)3 Block (net.minecraft.world.level.block.Block)2 LiquidBlock (net.minecraft.world.level.block.LiquidBlock)2 BlockEventData (net.minecraft.world.level.BlockEventData)1 PistonBaseBlock (net.minecraft.world.level.block.piston.PistonBaseBlock)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 ServerLevelBridge (org.spongepowered.common.bridge.server.level.ServerLevelBridge)1 TrackableBlockEventDataBridge (org.spongepowered.common.bridge.world.level.TrackableBlockEventDataBridge)1 BlockStateBridge (org.spongepowered.common.bridge.world.level.block.state.BlockStateBridge)1 SpongeLocatableBlockBuilder (org.spongepowered.common.world.server.SpongeLocatableBlockBuilder)1