use of thpmc.engine.api.world.cache.EngineWorld in project THP-Engine by TheHollowPlanetMC.
the class TestListener method onPlayerClick.
@EventHandler
public void onPlayerClick(PlayerAnimationEvent event) {
Player player = event.getPlayer();
if (!player.isSneaking())
return;
/*
List<EngineBoundingBox> list = new ArrayList<>();
EngineWorld world = AsyncWorldCache.getAsyncWorld(player.getWorld().getName());
Location loc = player.getLocation();
INMSHandler nmsHandler = THPEngineAPI.getInstance().getNMSHandler();
for(int x = loc.getBlockX() - 10; x < loc.getBlockX() + 10; x++){
for(int y = loc.getBlockY() - 10; y < loc.getBlockY() + 10; y++){
for(int z = loc.getBlockZ() - 10; z < loc.getBlockZ() + 10; z++){
EngineChunk chunk = world.getChunkAt(x >> 4, z >> 4);
Object iBlockData = chunk.getNMSBlockData(x, y, z);
if(iBlockData == null) continue;
EngineBlock block = new EngineBlock(world, chunk, x, y, z, iBlockData);
nmsHandler.collectBlockCollisions(block, list, new CollideOption(FluidCollisionMode.ALWAYS, true));
}
}
}
for(EngineBoundingBox boundingBox : list){
player.spawnParticle(Particle.FLAME, boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), 0);
player.spawnParticle(Particle.FLAME, boundingBox.getMinX(), boundingBox.getMaxY(), boundingBox.getMinZ(), 0);
player.spawnParticle(Particle.FLAME, boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMaxZ(), 0);
player.spawnParticle(Particle.FLAME, boundingBox.getMinX(), boundingBox.getMaxY(), boundingBox.getMaxZ(), 0);
player.spawnParticle(Particle.FLAME, boundingBox.getMaxX(), boundingBox.getMinY(), boundingBox.getMinZ(), 0);
player.spawnParticle(Particle.FLAME, boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMinZ(), 0);
player.spawnParticle(Particle.FLAME, boundingBox.getMaxX(), boundingBox.getMinY(), boundingBox.getMaxZ(), 0);
player.spawnParticle(Particle.FLAME, boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ(), 0);
}*/
TaskHandler.runAsync(() -> {
EngineWorld world = AsyncWorldCache.getAsyncWorld(player.getWorld().getName());
CollideOption collideOption = new CollideOption(FluidCollisionMode.ALWAYS, false);
collideOption.setCollideBlockFunction(engineBlock -> {
return engineBlock.getMaterial() != Material.OAK_LEAVES;
});
collideOption.setBoundingBoxGrow(0.2);
EngineRayTraceResult rayTraceResult = world.rayTraceEntities(player.getEyeLocation().toVector(), player.getEyeLocation().getDirection(), 20, collideOption);
if (rayTraceResult == null) {
player.sendMessage("NOT HIT!");
} else {
Vector hitPosition = rayTraceResult.getHitPosition();
BlockFace hitFace = rayTraceResult.getHitFace();
player.spawnParticle(Particle.FLAME, hitPosition.getX(), hitPosition.getY(), hitPosition.getZ(), 0);
player.sendMessage("Hit face : " + hitFace);
}
});
/*
for (int index = 0; index < 100; index++) {
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "NPC");
NMSEntity entityPlayer = nmsHandler.createNMSEntity(location.getWorld(), location.getX(), location.getY(), location.getZ(), EntityType.PLAYER, gameProfile);
entityPlayer.setPositionRaw(location.getX(), location.getY(), location.getZ());
THPEngineAPI.getInstance().getTickRunnerPool().spawn(tickRunner -> {
EnginePlayerEntity npc = new EnginePlayerEntity(tickRunner.getThreadLocalCache().getWorld(location.getWorld().getName()), (NMSEntityPlayer) entityPlayer, tickRunner, true);
npc.getGoalSelector().registerGoal(0, new EntityFollowGoal(player));
tickRunner.addEntity(npc);
});
count++;
player.sendMessage("PlayerNPC -> " + count);
}*/
}
use of thpmc.engine.api.world.cache.EngineWorld in project THP-Engine by TheHollowPlanetMC.
the class EntityFollowGoal method run.
@Override
public void run(GoalSelector goalSelector, Navigator navigator) {
tick++;
if (tick % TRACK_INTERVAL != 0) {
goalSelector.setFinished(true);
return;
}
INMSHandler nmsHandler = THPEngineAPI.getInstance().getNMSHandler();
EngineWorld world = navigator.getEntity().getWorld();
if (!world.getName().equals(target.getWorld().getName()))
return;
Location location = target.getLocation();
EngineChunk chunk = world.getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);
if (chunk == null)
return;
for (int dy = 0; dy < 5; dy++) {
Location l = location.clone().add(new Vector(0, -dy, 0));
Object nmsBlockData = world.getNMSBlockData(l.getBlockX(), l.getBlockY(), l.getBlockZ());
if (nmsBlockData == null)
continue;
if (nmsHandler.hasCollision(new EngineBlock(world, chunk, l.getBlockX(), l.getBlockY(), l.getBlockZ(), nmsBlockData), navigator.getEntity().getMovementCollideOption())) {
// Goal set
navigator.setNavigationGoal(new BlockPosition(l.getBlockX(), l.getBlockY() + 1, l.getBlockZ()));
break;
}
}
goalSelector.setFinished(true);
}
use of thpmc.engine.api.world.cache.EngineWorld in project THP-Engine by TheHollowPlanetMC.
the class NMSHandler method checkUpperBlockHasFluid.
private boolean checkUpperBlockHasFluid(Fluid fluid, EngineBlock block) {
EngineWorld world = block.getWorld();
IBlockData upperBlockData = (IBlockData) world.getNMSBlockData(block.getX(), block.getY() + 1, block.getZ());
if (upperBlockData == null)
return false;
return fluid.getType().a(upperBlockData.getFluid().getType());
}
Aggregations