use of io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell in project chunkstories-api by Hugobros3.
the class PacketVoxelUpdate method process.
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException {
if (processor instanceof ClientPacketsProcessor) {
ClientPacketsProcessor cpp = (ClientPacketsProcessor) processor;
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
int data = in.readInt();
Voxel voxel = world.getContentTranslator().getVoxelForId(VoxelFormat.id(data));
byte nextComponent = in.readByte();
try {
ChunkCell context = cpp.getWorld().getChunkWorldCoordinates(x, y, z).poke(x, y, z, voxel, VoxelFormat.sunlight(data), VoxelFormat.blocklight(data), VoxelFormat.meta(data), null);
while (nextComponent != 0) {
String componentName = in.readUTF();
context.components().get(componentName).pull(sender, in);
nextComponent = in.readByte();
}
} catch (WorldException e) {
// Maybe the world wasn't ready ?
// Edge case: what happens we receive an update for a chunk we haven't received the data yet ?
// The best option would be to delay the process but this is complicated for a rare instance
// Maybe one day
}
} else {
// Fail hard
}
}
use of io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell 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.world.chunk.Chunk.ChunkCell in project chunkstories by Hugobros3.
the class ChunkRenderDataHolder method renderExtras.
public void renderExtras(RenderingInterface renderingInterface) {
noDrawDeleteConflicts.acquireUninterruptibly();
if (this.currentData != null) {
// For each type of voxel that requires dynamic rendering...
for (DynamicallyRenderedVoxelType drvt : this.currentData.dynamicVoxelTypes) {
VoxelDynamicRenderer voxelDynamicRenderer = drvt.renderer;
// Build an iterator for the list of indexes that use that renderer
IterableIterator<ChunkCell> relevantCellsIterator = new IterableIterator<ChunkCell>() {
Iterator<Integer> iindex = drvt.indexes.iterator();
ChunkCell cvc = null;
@Override
public boolean hasNext() {
while (iindex.hasNext()) {
if (cvc != null)
return true;
int index = iindex.next();
cvc = chunk.peek(index / 1024, (index / 32) % 32, index % 32);
}
if (cvc != null)
return true;
return false;
}
@Override
public ChunkCell next() {
ChunkCell cvr = cvc;
cvc = null;
return cvr;
}
};
// And we call the renderer
voxelDynamicRenderer.renderVoxels(renderingInterface, relevantCellsIterator);
}
}
noDrawDeleteConflicts.release();
}
use of io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell in project chunkstories-core by Hugobros3.
the class SignRenderer method renderVoxels.
@Override
public void renderVoxels(RenderingInterface renderingContext, IterableIterator<ChunkCell> renderableEntitiesIterator) {
setupRender(renderingContext);
renderingContext.setObjectMatrix(null);
for (// .getElementsInFrustrumOnly())
ChunkCell context : // .getElementsInFrustrumOnly())
renderableEntitiesIterator) {
if (renderingContext.getCamera().getCameraPosition().distance(context.getLocation()) > 32)
continue;
Texture2D diffuse = renderingContext.textures().getTexture("./models/sign.png");
diffuse.setLinearFiltering(false);
renderingContext.bindAlbedoTexture(diffuse);
renderingContext.bindNormalTexture(renderingContext.textures().getTexture("./textures/normalnormal.png"));
renderingContext.currentShader().setUniform2f("worldLightIn", context.getBlocklight(), context.getSunlight());
boolean isPost = context.getVoxel().getName().endsWith("_post");
int facing = context.getMetaData();
Matrix4f mutrix = new Matrix4f();
mutrix.translate(new Vector3f(0.5f, 0.0f, 0.5f));
Location loc = context.getLocation();
mutrix.translate((float) loc.x, (float) loc.y, (float) loc.z);
mutrix.rotate((float) Math.PI * 2.0f * (-facing) / 16f, new Vector3f(0, 1, 0));
if (!isPost)
mutrix.translate(new Vector3f(0.0f, 0.0f, -0.5f));
renderingContext.setObjectMatrix(mutrix);
if (!isPost)
renderingContext.meshes().getRenderableMeshByName("./models/sign_post.obj").render(renderingContext);
else
renderingContext.meshes().getRenderableMeshByName("./models/sign.obj").render(renderingContext);
VoxelComponentSignText signTextComponent = (VoxelComponentSignText) context.components().get("signData");
if (signTextComponent == null)
continue;
// bake sign mesh
if (signTextComponent.cachedText == null || !signTextComponent.cachedText.equals(signTextComponent.getSignText())) {
// entitySign.renderData = new TextMeshObject(entitySign.signText.getSignText());
signTextComponent.cachedText = signTextComponent.getSignText();
signTextComponent.renderData = renderingContext.getFontRenderer().newTextMeshObject(renderingContext.getFontRenderer().defaultFont(), signTextComponent.cachedText);
}
// signTextComponent.setSignText("fuck");
// System.out.println("cachedText:"+signTextComponent.getSignText());
// Display it
mutrix.translate(new Vector3f(0.0f, 1.15f, 0.055f));
renderingContext.setObjectMatrix(mutrix);
signTextComponent.renderData.render(renderingContext);
}
}
Aggregations