Search in sources :

Example 1 with IMixinBlockPos

use of org.spongepowered.common.interfaces.util.math.IMixinBlockPos in project SpongeCommon by SpongePowered.

the class MixinWorld method collidesWithAnyBlock.

/**
 * @author gabizou - August 4th, 2016
 * @reason Inlines the isValidXZPosition check to BlockPos.
 *
 * @param bbox The AABB to check
 * @return True if the AABB collides with a block
 */
@Overwrite
public boolean collidesWithAnyBlock(AxisAlignedBB bbox) {
    List<AxisAlignedBB> list = Lists.<AxisAlignedBB>newArrayList();
    int i = MathHelper.floor(bbox.minX) - 1;
    int j = MathHelper.ceil(bbox.maxX) + 1;
    int k = MathHelper.floor(bbox.minY) - 1;
    int l = MathHelper.ceil(bbox.maxY) + 1;
    int i1 = MathHelper.floor(bbox.minZ) - 1;
    int j1 = MathHelper.ceil(bbox.maxZ) + 1;
    BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
    try {
        for (int k1 = i; k1 < j; ++k1) {
            for (int l1 = i1; l1 < j1; ++l1) {
                int i2 = (k1 != i && k1 != j - 1 ? 0 : 1) + (l1 != i1 && l1 != j1 - 1 ? 0 : 1);
                if (i2 != 2 && this.isBlockLoaded(blockpos$pooledmutableblockpos.setPos(k1, 64, l1))) {
                    for (int j2 = k; j2 < l; ++j2) {
                        if (i2 <= 0 || j2 != k && j2 != l - 1) {
                            blockpos$pooledmutableblockpos.setPos(k1, j2, l1);
                            // if (k1 < -30000000 || k1 >= 30000000 || l1 < -30000000 || l1 >= 30000000) // Vanilla
                            if (!((IMixinBlockPos) (Object) blockpos$pooledmutableblockpos).isValidXZPosition()) {
                                // Sponge End
                                boolean flag1 = true;
                                return flag1;
                            }
                            IBlockState iblockstate = this.getBlockState(blockpos$pooledmutableblockpos);
                            iblockstate.addCollisionBoxToList((net.minecraft.world.World) (Object) this, blockpos$pooledmutableblockpos, bbox, list, (net.minecraft.entity.Entity) null, false);
                            if (!list.isEmpty()) {
                                boolean flag = true;
                                return flag;
                            }
                        }
                    }
                }
            }
        }
        return false;
    } finally {
        blockpos$pooledmutableblockpos.release();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with IMixinBlockPos

use of org.spongepowered.common.interfaces.util.math.IMixinBlockPos in project SpongeCommon by SpongePowered.

the class MixinWorldServer_Async_Lighting method setLightForAsync.

public void setLightForAsync(EnumSkyBlock type, BlockPos pos, int lightValue, Chunk currentChunk, List<Chunk> neighbors) {
    if (((IMixinBlockPos) pos).isValidPosition()) {
        final Chunk chunk = this.getLightChunk(pos, currentChunk, neighbors);
        if (chunk != null && !chunk.unloadQueued) {
            chunk.setLightFor(type, pos, lightValue);
            this.notifyLightSet(pos);
        }
    }
}
Also used : IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk)

Example 3 with IMixinBlockPos

use of org.spongepowered.common.interfaces.util.math.IMixinBlockPos in project SpongeCommon by SpongePowered.

the class MixinWorldServer method spongeLoadEntities.

/**
 * @author gabizou - February 7th, 2016
 * @author gabizou - September 3rd, 2016 - Moved from MixinWorld since WorldServer overrides the method.
 *
 * This will short circuit all other patches such that we control the
 * entities being loaded by chunkloading and can throw our bulk entity
 * event. This will bypass Forge's hook for individual entity events,
 * but the SpongeModEventManager will still successfully throw the
 * appropriate event and cancel the entities otherwise contained.
 *
 * @param entities The entities being loaded
 * @param callbackInfo The callback info
 */
@Final
@Inject(method = "loadEntities", at = @At("HEAD"), cancellable = true)
private void spongeLoadEntities(Collection<net.minecraft.entity.Entity> entities, CallbackInfo callbackInfo) {
    if (entities.isEmpty()) {
        // just return, no entities to load!
        callbackInfo.cancel();
        return;
    }
    List<Entity> entityList = new ArrayList<>();
    for (net.minecraft.entity.Entity entity : entities) {
        // Make sure no entities load in invalid positions
        if (((IMixinBlockPos) entity.getPosition()).isInvalidYPosition()) {
            entity.setDead();
            continue;
        }
        if (this.canAddEntity(entity)) {
            entityList.add((Entity) entity);
        }
    }
    try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CHUNK_LOAD);
        Sponge.getCauseStackManager().pushCause(this);
        SpawnEntityEvent.ChunkLoad chunkLoad = SpongeEventFactory.createSpawnEntityEventChunkLoad(Sponge.getCauseStackManager().getCurrentCause(), Lists.newArrayList(entityList));
        SpongeImpl.postEvent(chunkLoad);
        if (!chunkLoad.isCancelled() && chunkLoad.getEntities().size() > 0) {
            for (Entity successful : chunkLoad.getEntities()) {
                this.loadedEntityList.add((net.minecraft.entity.Entity) successful);
                this.onEntityAdded((net.minecraft.entity.Entity) successful);
            }
        }
        // This prevents invisible entities from loading into the world and blocking the position.
        for (Entity entity : entityList) {
            if (!chunkLoad.getEntities().contains(entity)) {
                ((net.minecraft.world.World) (Object) this).removeEntityDangerously((net.minecraft.entity.Entity) entity);
            }
        }
        callbackInfo.cancel();
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) ArrayList(java.util.ArrayList) NonNullArrayList(org.spongepowered.common.util.NonNullArrayList) World(net.minecraft.world.World) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Inject(org.spongepowered.asm.mixin.injection.Inject) Final(org.spongepowered.asm.mixin.Final)

Example 4 with IMixinBlockPos

use of org.spongepowered.common.interfaces.util.math.IMixinBlockPos in project SpongeCommon by SpongePowered.

the class MixinWorldServer method getBlockState.

/**
 * @author gabizou - August 4th, 2016
 * @author blood - May 11th, 2017 - Forces chunk requests if TE is ticking.
 * @reason Rewrites the check to be inlined to {@link IMixinBlockPos}.
 *
 * @param pos The position
 * @return The block state at the desired position
 */
@Override
public IBlockState getBlockState(BlockPos pos) {
    // if (this.isOutsideBuildHeight(pos)) // Vanilla
    if (((IMixinBlockPos) pos).isInvalidYPosition()) {
        // Sponge end
        return Blocks.AIR.getDefaultState();
    } else {
        // ExtraUtilities 2 expects to get the proper chunk while mining or it gets stuck in infinite loop
        // TODO add TE config to disable/enable chunk loads
        final boolean forceChunkRequests = this.mixinChunkProviderServer.getForceChunkRequests();
        final PhaseTracker phaseTracker = PhaseTracker.getInstance();
        final IPhaseState currentState = phaseTracker.getCurrentState();
        if (currentState == TickPhase.Tick.TILE_ENTITY) {
            ((IMixinChunkProviderServer) this.getChunkProvider()).setForceChunkRequests(true);
        }
        net.minecraft.world.chunk.Chunk chunk = this.getChunkFromBlockCoords(pos);
        this.mixinChunkProviderServer.setForceChunkRequests(forceChunkRequests);
        return chunk.getBlockState(pos);
    }
}
Also used : IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Aggregations

IMixinBlockPos (org.spongepowered.common.interfaces.util.math.IMixinBlockPos)4 Chunk (net.minecraft.world.chunk.Chunk)2 ArrayList (java.util.ArrayList)1 IBlockState (net.minecraft.block.state.IBlockState)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 Entity (org.spongepowered.api.entity.Entity)1 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)1 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)1 Final (org.spongepowered.asm.mixin.Final)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)1 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)1 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)1 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)1 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)1 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)1