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