use of io.xol.chunkstories.api.entity.Entity in project chunkstories-core by Hugobros3.
the class VoxelSign method onPlace.
@Override
public void onPlace(FutureCell cell, WorldModificationCause cause) throws IllegalBlockModificationException {
// We don't create the components here, as the cell isn't actually changed yet!
int x = cell.getX();
int y = cell.getY();
int z = cell.getZ();
if (cause != null && cause instanceof Entity) {
Vector3d blockLocation = new Vector3d(x + 0.5, y, z + 0.5);
blockLocation.sub(((Entity) cause).getLocation());
blockLocation.negate();
Vector2f direction = new Vector2f((float) (double) blockLocation.x(), (float) (double) blockLocation.z());
direction.normalize();
// System.out.println("x:"+direction.x+"y:"+direction.y);
double asAngle = Math.acos(direction.y()) / Math.PI * 180;
asAngle *= -1;
if (direction.x() < 0)
asAngle *= -1;
// asAngle += 180.0;
asAngle %= 360.0;
asAngle += 360.0;
asAngle %= 360.0;
// System.out.println(asAngle);
int meta = (int) (16 * asAngle / 360);
cell.setMetaData(meta);
}
}
use of io.xol.chunkstories.api.entity.Entity in project chunkstories-core by Hugobros3.
the class VoxelStairs method onPlace.
@Override
public void onPlace(FutureCell cell, WorldModificationCause cause) {
// id+dir of slope
// 0LEFT x-
// 1RIGHT x+
// 2BACK z-
// 3FRONT z+
int stairsSide = 0;
if (cause != null && cause instanceof Entity) {
Entity entity = (Entity) cause;
Location loc = entity.getLocation();
double dx = loc.x() - (cell.getX() + 0.5);
double dz = loc.z() - (cell.getZ() + 0.5);
if (Math.abs(dx) > Math.abs(dz)) {
if (dx > 0)
stairsSide = 1;
else
stairsSide = 0;
} else {
if (dz > 0)
stairsSide = 3;
else
stairsSide = 2;
}
if (entity instanceof EntityPlayer) {
if (((EntityPlayer) entity).getEntityRotationComponent().getVerticalRotation() < 0)
stairsSide += 4;
}
cell.setMetaData(stairsSide);
}
}
use of io.xol.chunkstories.api.entity.Entity in project chunkstories-api by Hugobros3.
the class InventoryTranslator method obtainInventoryHandle.
public static Inventory obtainInventoryHandle(DataInputStream in, PacketReceptionContext context) throws IOException {
byte holderType = in.readByte();
if (holderType == 0x01) {
long uuid = in.readLong();
short componentId = in.readShort();
Entity entity = context.getWorld().getEntityByUUID(uuid);
EntityComponent cpn = entity.getComponents().getComponentById(componentId);
if (cpn != null && cpn instanceof EntityComponentInventory) {
return ((EntityComponentInventory) cpn).getInventory();
}
} else if (holderType == 0x03) {
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
String componentName = in.readUTF();
try {
ChunkCell voxelContext = context.getWorld().peek(x, y, z);
VoxelComponent com = voxelContext.components().get(componentName);
if (com != null && com instanceof VoxelInventoryComponent) {
VoxelInventoryComponent comp = (VoxelInventoryComponent) com;
return comp.getInventory();
}
} catch (WorldException e) {
// TODO log as warning
// Ignore and return null
}
}
return null;
}
use of io.xol.chunkstories.api.entity.Entity in project chunkstories-api by Hugobros3.
the class InventoryTranslator method writeInventoryHandle.
public static void writeInventoryHandle(DataOutputStream out, Inventory inventory) throws IOException {
/*if(inventory instanceof InventoryLocalCreativeMenu)
out.writeByte(0x02); else */
if (inventory == null || inventory.getHolder() == null)
out.writeByte(0x00);
else if (inventory instanceof EntityComponentInventory.EntityInventory) {
EntityComponentInventory.EntityInventory entityInventory = (EntityComponentInventory.EntityInventory) inventory;
out.writeByte(0x01);
out.writeLong(((Entity) inventory.getHolder()).getUUID());
out.writeShort(entityInventory.asComponent().getEntityComponentId());
} else if (inventory.getHolder() instanceof VoxelInventoryComponent) {
VoxelInventoryComponent component = (VoxelInventoryComponent) inventory.getHolder();
out.writeByte(0x03);
out.writeInt(component.holder().getX());
out.writeInt(component.holder().getY());
out.writeInt(component.holder().getZ());
out.writeUTF(component.holder().name(component));
} else
out.writeByte(0x00);
// throw new RuntimeException("Untranslatable and Unknown Inventory : "+inventory+", can't describe it in outgoing packets");
}
use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.
the class DebugInfoRenderer method drawF3debugMenu.
public void drawF3debugMenu(RenderingInterface renderingInterface) {
CameraInterface camera = renderingInterface.getCamera();
Entity playerEntity = client.getPlayer().getControlledEntity();
/*int timeTook = Client.profiler.timeTook();
String debugInfo = Client.profiler.reset("gui").toString();
if (timeTook > 400)
System.out.println("Lengty frame, printing debug information : \n" + debugInfo);*/
// Memory usage
long total = Runtime.getRuntime().totalMemory();
long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
// By default use the camera position
int bx = ((int) camera.getCameraPosition().x());
int by = ((int) camera.getCameraPosition().y());
int bz = ((int) camera.getCameraPosition().z());
int lx = bx, ly = by, lz = bz;
// If the player can look use that
if (playerEntity != null && playerEntity instanceof EntityControllable) {
Location loc = ((EntityControllable) playerEntity).getBlockLookingAt(true);
if (loc != null) {
lx = (int) loc.x();
ly = (int) loc.y();
lz = (int) loc.z();
}
}
int raw_data = world.peekRaw(lx, ly, lz);
CellData cell = world.peekSafely(lx, ly, lz);
// System.out.println(VoxelFormat.id(raw_data));
int cx = bx / 32;
int cy = by / 32;
int cz = bz / 32;
int csh = world.getRegionsSummariesHolder().getHeightAtWorldCoordinates(bx, bz);
// Obtain the angle the player is facing
VoxelSide side = VoxelSide.TOP;
float angleX = -1;
if (playerEntity != null && playerEntity instanceof EntityLiving)
angleX = Math.round(((EntityLiving) playerEntity).getEntityRotationComponent().getHorizontalRotation());
double dx = Math.sin(angleX / 360 * 2.0 * Math.PI);
double dz = Math.cos(angleX / 360 * 2.0 * Math.PI);
if (Math.abs(dx) > Math.abs(dz)) {
if (dx > 0)
side = VoxelSide.RIGHT;
else
side = VoxelSide.LEFT;
} else {
if (dz > 0)
side = VoxelSide.FRONT;
else
side = VoxelSide.BACK;
}
// Count all the entities
int ec = 0;
IterableIterator<Entity> i = world.getAllLoadedEntities();
while (i.hasNext()) {
i.next();
ec++;
}
Chunk current = world.getChunk(cx, cy, cz);
int x_top = renderingInterface.getWindow().getHeight() - 16;
Font font = null;
font = renderingInterface.getFontRenderer().getFont("LiberationSans-Regular", 12);
if (font == null)
font = renderingInterface.getFontRenderer().getFont("LiberationSans-Regular", 12);
int lineHeight = font.getLineHeight();
int posx, posy;
String text;
posx = 8;
posy = x_top - posx;
text = GLCalls.getStatistics() + " Chunks in view : " + world.getWorldRenderer().getChunksRenderer().getChunksVisible() + " Entities " + ec + " Particles :" + ((ClientParticlesRenderer) world.getParticlesManager()).count() + " #FF0000Render FPS: " + Client.getInstance().getGameWindow().getFPS() + " avg: " + Math.floor(10000.0 / Client.getInstance().getGameWindow().getFPS()) / 10.0 + " #00FFFFSimulation FPS: " + world.getWorldRenderer().getWorld().getGameLogic().getSimulationFps();
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "RAM usage : " + used / 1024 / 1024 + " / " + total / 1024 / 1024 + " MB used, chunks loaded in ram: " + world.getRegionsHolder().countChunksWithData() + "/" + world.getRegionsHolder().countChunks() + " " + Math.floor(world.getRegionsHolder().countChunksWithData() * 4 * 32 * 32 * 32 / (1024L * 1024 / 100f)) / 100f + "MB used by chunks";
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
long totalVram = (renderingInterface.getTotalVramUsage()) / 1024 / 1024;
posy -= lineHeight;
text = "VRAM usage : " + totalVram + "MB as " + Texture2DGL.getTotalNumberOfTextureObjects() + " textures using " + Texture2DGL.getTotalVramUsage() / 1024 / 1024 + "MB + " + VertexBufferGL.getTotalNumberOfVerticesObjects() + " vbos using " + renderingInterface.getVertexDataVramUsage() / 1024 / 1024 + " MB";
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "Worker threads: " + world.getGameContext().tasks() + " - " + world.ioHandler.toString();
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "Position : x:" + bx + " y:" + by + " z:" + bz + " dir: " + angleX + " side: " + side + " #FF0000Block looking at#FFFFFF : pos: " + lx + ": " + ly + ": " + lz + " data: " + raw_data + " voxel_type: " + cell.getVoxel().getName() + " sl:" + cell.getSunlight() + " bl: " + cell.getBlocklight() + " meta:" + cell.getMetaData() + " csh:" + csh;
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "Current Summary : " + world.getRegionsSummariesHolder().getHeightmapChunkCoordinates(cx, cz);
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
posy -= lineHeight;
text = "Current Region : " + world.getRegionChunkCoordinates(cx, cy, cz);
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
if (current == null) {
posy -= lineHeight;
text = "Current chunk null";
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
} else if (current instanceof ChunkRenderable) {
ChunkRenderDataHolder chunkRenderData = ((ClientChunk) current).getChunkRenderData();
if (chunkRenderData != null) {
posy -= lineHeight;
text = "Current Chunk : " + current + " - " + chunkRenderData.toString();
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
} else {
posy -= lineHeight;
text = "Current Chunk : " + current + " - No rendering data";
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
}
}
if (playerEntity != null && playerEntity instanceof Entity) {
posy -= lineHeight;
text = "Controlled Entity : " + playerEntity;
renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
}
}
Aggregations