use of com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType in project InteractionVisualizer by LOOHP.
the class V1_16_2 method getTileEntities.
@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
if (!chunk.isLoaded() && !load) {
return null;
}
World world = chunk.getWorld();
return new NMSTileEntitySet<net.minecraft.server.v1_16_R2.BlockPosition, net.minecraft.server.v1_16_R2.TileEntity>(((CraftChunk) chunk.getChunk()).getHandle().tileEntities, entry -> {
net.minecraft.server.v1_16_R2.BlockPosition pos = entry.getKey();
Material type = CraftMagicNumbers.getMaterial(entry.getValue().getBlock().getBlock());
TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
if (tileEntityType != null) {
return new TileEntity(world, pos.getX(), pos.getY(), pos.getZ(), tileEntityType);
} else {
return null;
}
});
}
use of com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType in project InteractionVisualizer by LOOHP.
the class V1_17 method getTileEntities.
@SuppressWarnings("unchecked")
@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
if (!chunk.isLoaded() && !load) {
return null;
}
World world = chunk.getWorld();
try {
return new NMSTileEntitySet<net.minecraft.core.BlockPosition, net.minecraft.world.level.block.entity.TileEntity>((Map<net.minecraft.core.BlockPosition, net.minecraft.world.level.block.entity.TileEntity>) nmsChunkL.get(((CraftChunk) chunk.getChunk()).getHandle()), entry -> {
net.minecraft.core.BlockPosition pos = entry.getKey();
try {
Material type = CraftMagicNumbers.getMaterial((net.minecraft.world.level.block.Block) blockDataGetBlock.invoke(tileEntityGetBlock.invoke(entry.getValue())));
TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
if (tileEntityType != null) {
return new TileEntity(world, (int) blockPositionGetX.invoke(pos), (int) blockPositionGetY.invoke(pos), (int) blockPositionGetZ.invoke(pos), tileEntityType);
} else {
return null;
}
} catch (Exception e) {
return null;
}
});
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
}
use of com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType in project InteractionVisualizer by LOOHP.
the class V1_18 method getTileEntities.
@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
if (!chunk.isLoaded() && !load) {
return null;
}
World world = chunk.getWorld();
return new NMSTileEntitySet<net.minecraft.core.BlockPosition, net.minecraft.world.level.block.entity.TileEntity>(((CraftChunk) chunk.getChunk()).getHandle().E(), entry -> {
net.minecraft.core.BlockPosition pos = entry.getKey();
Material type = CraftMagicNumbers.getMaterial(entry.getValue().q().b());
TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
if (tileEntityType != null) {
return new TileEntity(world, pos.u(), pos.v(), pos.w(), tileEntityType);
} else {
return null;
}
});
}
use of com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType in project InteractionVisualizer by LOOHP.
the class V1_18_2 method getTileEntities.
@Override
public NMSTileEntitySet<?, ?> getTileEntities(ChunkPosition chunk, boolean load) {
if (!chunk.isLoaded() && !load) {
return null;
}
World world = chunk.getWorld();
return new NMSTileEntitySet<net.minecraft.core.BlockPosition, net.minecraft.world.level.block.entity.TileEntity>(((CraftChunk) chunk.getChunk()).getHandle().E(), entry -> {
net.minecraft.core.BlockPosition pos = entry.getKey();
Material type = CraftMagicNumbers.getMaterial(entry.getValue().q().b());
TileEntityType tileEntityType = TileEntity.getTileEntityType(type);
if (tileEntityType != null) {
return new TileEntity(world, pos.u(), pos.v(), pos.w(), tileEntityType);
} else {
return null;
}
});
}
use of com.loohp.interactionvisualizer.objectholders.TileEntity.TileEntityType in project InteractionVisualizer by LOOHP.
the class TileEntityManager method _init_.
public static void _init_() {
for (TileEntityType type : tileEntityTypes) {
active.put(type, Collections.newSetFromMap(new ConcurrentHashMap<>()));
}
TileEntityManager instance = new TileEntityManager();
Bukkit.getPluginManager().registerEvents(instance, plugin);
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
for (TileEntityType type : tileEntityTypes) {
Set<Block> blocks = active.get(type);
Iterator<Block> itr = blocks.iterator();
while (itr.hasNext()) {
Block block = itr.next();
if (!PlayerLocationManager.hasPlayerNearby(block.getLocation())) {
itr.remove();
}
}
}
}, 0, InteractionVisualizerAPI.getGCPeriod());
for (Player player : Bukkit.getOnlinePlayers()) {
instance.onJoin(new PlayerJoinEvent(player, ""));
}
}
Aggregations