use of com.bergerkiller.generated.net.minecraft.core.BlockPositionHandle in project BKCommonLib by bergerhealer.
the class BlockStateConversion_1_12_2 method tileEntityToBlockState.
@Override
public synchronized BlockState tileEntityToBlockState(org.bukkit.Chunk chunk, Object nmsTileEntity) {
if (nmsTileEntity == null) {
throw new IllegalArgumentException("Tile Entity is null");
}
BlockPositionHandle pos = TileEntityHandle.T.getPosition.invoke(nmsTileEntity);
Block block;
if (chunk == null) {
Object world = TileEntityHandle.T.getWorld.raw.invoke(nmsTileEntity);
if (world == null) {
throw new IllegalArgumentException("Tile Entity has no world set");
}
block = WrapperConversion.toWorld(world).getBlockAt(pos.getX(), pos.getY(), pos.getZ());
} else {
block = chunk.getBlock(pos.getX(), pos.getY(), pos.getZ());
}
return tileEntityToBlockState(block, nmsTileEntity);
}
use of com.bergerkiller.generated.net.minecraft.core.BlockPositionHandle in project BKCommonLib by bergerhealer.
the class WrapperConversion method getBlockFromTileEntity.
@ConverterMethod(input = "net.minecraft.world.level.block.entity.TileEntity")
public static org.bukkit.block.Block getBlockFromTileEntity(Object nmsTileEntityHandle) {
TileEntityHandle handle = TileEntityHandle.createHandle(nmsTileEntityHandle);
BlockPositionHandle pos = handle.getPosition();
return handle.getWorld().getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
}
use of com.bergerkiller.generated.net.minecraft.core.BlockPositionHandle in project BKCommonLib by bergerhealer.
the class NMSTileEntity method getBlock.
public static Block getBlock(Object tileEntity) {
TileEntityHandle handle = TileEntityHandle.createHandle(tileEntity);
BlockPositionHandle pos = handle.getPosition();
return handle.getWorld().getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
}
use of com.bergerkiller.generated.net.minecraft.core.BlockPositionHandle in project BKCommonLib by bergerhealer.
the class BlockUtil method getBlockStates.
public static Collection<BlockState> getBlockStates(org.bukkit.World world, int x, int y, int z, int radiusX, int radiusY, int radiusZ) {
try {
if (radiusX == 0 && radiusY == 0 && radiusZ == 0) {
// find a single BlockState at this position
Object blockPosition = BlockPositionHandle.T.constr_x_y_z.raw.newInstance(x, y, z);
Object tile = WorldHandle.T.getTileEntity.raw.invoke(HandleConversion.toWorldHandle(world), blockPosition);
if (tile != null) {
blockStateBuff.add(WrapperConversion.toBlockState(tile));
}
} else {
// loop through tile entity list
int xMin = x - radiusX;
int yMin = y - radiusY;
int zMin = z - radiusZ;
int xMax = x + radiusX;
int yMax = y + radiusY;
int zMax = z + radiusZ;
// find range of chunk coordinates to look in
int chunk_xMin = MathUtil.toChunk(xMin);
int chunk_zMin = MathUtil.toChunk(zMin);
int chunk_xMax = MathUtil.toChunk(xMax);
int chunk_zMax = MathUtil.toChunk(zMax);
for (int cx = chunk_xMin; cx <= chunk_xMax; cx++) {
for (int cz = chunk_zMin; cz <= chunk_zMax; cz++) {
// Find chunk if loaded
org.bukkit.Chunk chunk = WorldUtil.getChunk(world, cx, cz);
if (chunk == null) {
continue;
}
// Check tile entities held inside
ChunkBlockStateConverter converter = null;
Collection<?> rawTiles = ChunkHandle.T.getRawTileEntities.invoke(HandleConversion.toChunkHandle(chunk));
for (Object tile : rawTiles) {
BlockPositionHandle blockPosition;
blockPosition = BlockPositionHandle.createHandle(TileEntityHandle.T.position_field.raw.get(tile));
if (blockPosition.isPositionInBox(xMin, yMin, zMin, xMax, yMax, zMax)) {
if (converter == null) {
converter = new ChunkBlockStateConverter(chunk);
}
blockStateBuff.add(converter.convert(tile));
}
}
}
}
}
return new ArrayList<BlockState>(blockStateBuff);
} finally {
blockStateBuff.clear();
}
}
use of com.bergerkiller.generated.net.minecraft.core.BlockPositionHandle in project BKCommonLib by bergerhealer.
the class CreaturePreSpawnHandler_Spigot method handleMobsFor.
private static List<Object> handleMobsFor(World world, Object blockposition, List<Object> mobs) {
try {
// There is no use wasting CPU time when no one handles the event!
if (LogicUtil.nullOrEmpty(mobs) || !CommonUtil.hasHandlers(CreaturePreSpawnEvent.getHandlerList())) {
return mobs;
}
// Wrap the parameters and send the event along
BlockPositionHandle pos = BlockPositionHandle.createHandle(blockposition);
// Check all instances of SpawnRateHandle if they need to be cancelled
// If they're cancelled, initialize a new List with those entries omitted
CommonEventFactory eventFactory = CommonPlugin.getInstance().getEventFactory();
List<Object> result = mobs;
int numMobs = mobs.size();
for (int n = 0; n < numMobs; n++) {
SpawnRateHandle handle = SpawnRateHandle.createHandle(mobs.get(n));
EntityType entityType = CommonEntityType.byNMSEntityClass(handle.getEntityClass()).entityType;
if (eventFactory.handleCreaturePreSpawn(world, pos.getX(), pos.getY(), pos.getZ(), entityType)) {
// add this entry to the list.
if (result != mobs) {
result.add(handle.getRaw());
}
} else if (result == mobs) {
// Create a new List of stuff, omit the entry that was cancelled
result = new ArrayList<Object>();
result.addAll(mobs.subList(0, n));
}
}
return result;
} catch (Throwable t) {
Logging.LOGGER.log(Level.SEVERE, "Failed to handle mob pre-spawn event", t);
return mobs;
}
}
Aggregations