use of io.xol.chunkstories.api.world.cell.CellData in project chunkstories by Hugobros3.
the class PhysicsWireframeDebugger method render.
public void render(RenderingInterface renderer) {
Vector3dc cameraPosition = renderer.getCamera().getCameraPosition();
// int id, data;
int drawDebugDist = 6;
// Iterate over nearby voxels
for (int i = ((int) (double) cameraPosition.x()) - drawDebugDist; i <= ((int) (double) cameraPosition.x()) + drawDebugDist; i++) for (int j = ((int) (double) cameraPosition.y()) - drawDebugDist; j <= ((int) (double) cameraPosition.y()) + drawDebugDist; j++) for (int k = ((int) (double) cameraPosition.z()) - drawDebugDist; k <= ((int) (double) cameraPosition.z()) + drawDebugDist; k++) {
// data = world.peekSimple(i, j, k);
// id = VoxelFormat.id(data);
CellData cell = world.peekSafely(i, j, k);
// System.out.println(i+":"+j+":"+k);
// System.out.println(cell.getX() + ":"+cell.getY()+":"+cell.getZ());
CollisionBox[] tboxes = cell.getTranslatedCollisionBoxes();
// System.out.println(tboxes.length);
if (tboxes != null) {
// Draw all their collision boxes
for (CollisionBox box : tboxes) {
if (cell.getVoxel().getDefinition().isSolid())
// Red if solid
FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 0, 0, 1.0f));
else
// Yellow otherwise
FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 1, 0, 0.25f));
}
}
}
// Iterate over each entity
Iterator<Entity> ie = world.getAllLoadedEntities();
while (ie.hasNext()) {
Entity e = ie.next();
// Entities with hitboxes see all of those being drawn
if (e instanceof EntityLiving) {
EntityLiving eli = (EntityLiving) e;
for (HitBox hitbox : eli.getHitBoxes()) {
hitbox.draw(renderer);
}
}
// Get the entity bounding box
if (e.getTranslatedBoundingBox().lineIntersection(cameraPosition, new Vector3d(renderer.getCamera().getViewDirection())) != null)
FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 0, 0.5f, 1.0f));
else
FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 1f, 1f, 1.0f));
// And the collision box
for (CollisionBox box : e.getCollisionBoxes()) {
box.translate(e.getLocation());
FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(0, 1, 0.5f, 1.0f));
}
}
}
use of io.xol.chunkstories.api.world.cell.CellData in project chunkstories by Hugobros3.
the class TaskBuildHeightmap method task.
@Override
protected boolean task(TaskExecutor taskExecutor) {
ConverterWorkerThread cwt = (ConverterWorkerThread) taskExecutor;
// We wait on a bunch of stuff to load everytime
CompoundFence loadRelevantData = new CompoundFence();
HeightmapImplementation summary = csWorld.getRegionsSummariesHolder().aquireHeightmap(cwt, regionX, regionZ);
loadRelevantData.add(summary.waitForLoading());
// Aquires the chunks we want to make the summaries of.
for (int innerCX = 0; innerCX < 8; innerCX++) for (int innerCZ = 0; innerCZ < 8; innerCZ++) for (int chunkY = 0; chunkY < OfflineWorldConverter.mcWorldHeight / 32; chunkY++) {
ChunkHolder holder = csWorld.aquireChunkHolder(cwt, regionX * 8 + innerCX, chunkY, regionZ * 8 + innerCZ);
if (holder != null) {
loadRelevantData.add(holder.waitForLoading());
if (cwt.registeredCS_Holders.add(holder))
cwt.chunksAquired++;
}
}
// Wait until all of that crap loads
loadRelevantData.traverse();
// Descend from top
for (int i = 0; i < 256; i++) for (int j = 0; j < 256; j++) {
for (int h = OfflineWorldConverter.mcWorldHeight; h > 0; h--) {
CellData data = csWorld.peekSafely(regionX * 256 + i, h, regionZ * 256 + j);
if (!data.getVoxel().isAir()) {
Voxel vox = data.getVoxel();
if (vox.getDefinition().isSolid() || vox.getDefinition().isLiquid()) {
summary.setTopCell(data);
break;
}
}
}
}
Fence waitForSummarySave = summary.saveSummary();
// cwt.converter().verbose("Waiting for summary saving...");
waitForSummarySave.traverse();
// cwt.converter().verbose("Done.");
// We don't need the summary anymore
summary.unregisterUser(cwt);
return true;
}
use of io.xol.chunkstories.api.world.cell.CellData in project chunkstories-api by Hugobros3.
the class VoxelItemRenderer method renderItemInWorld.
@Override
public void renderItemInWorld(RenderingInterface renderer, ItemPile pile, World world, Location location, Matrix4f handTransformation) {
/*if (((ItemVoxel) pile.getItem()).getVoxel() instanceof VoxelCustomIcon) {
fallbackRenderer.renderItemInWorld(renderer, pile, world, location, handTransformation);
return;
}*/
Voxel voxel = ((ItemVoxel) pile.getItem()).getVoxel();
if (voxel == null)
return;
CellData fakeCell = new DummyCell(0, 0, 0, voxel, 0, 0, 0) {
CellData air = new DummyCell(0, 1, 0, voxel.store().air(), 0, 0, 0);
@Override
public int getBlocklight() {
return voxel.getEmittedLightLevel(this);
}
@Override
public CellData getNeightbor(int side) {
return air;
}
@Override
public int getMetaData() {
return ((ItemVoxel) pile.getItem()).getVoxelMeta();
}
};
float s = 0.45f;
handTransformation.scale(new Vector3f(s, s, s));
handTransformation.translate(new Vector3f(-0.25f, -0.5f, -0.5f));
renderer.setObjectMatrix(handTransformation);
// Add a light only on the opaque pass
if (fakeCell.getBlocklight() > 0 && renderer.getCurrentPass().name.contains("gBuffers")) {
Vector4f lightposition = new Vector4f(0.0f, 0.0f, 0.0f, 1.0f);
handTransformation.transform(lightposition);
Light heldBlockLight = new Light(new Vector3f(0.6f, 0.50f, 0.4f).mul(0.5f), new Vector3f(lightposition.x(), lightposition.y(), lightposition.z()), 15f);
renderer.getLightsRenderer().queueLight(heldBlockLight);
// If we hold a light source, prepare the shader accordingly
renderer.currentShader().setUniform2f("worldLightIn", Math.max(world.peekSafely(location).getBlocklight(), fakeCell.getBlocklight()), world.peekSafely(location).getSunlight());
}
Texture2D texture = content.voxels().textures().getDiffuseAtlasTexture();
texture.setLinearFiltering(false);
renderer.bindAlbedoTexture(texture);
Texture2D normalTexture = content.voxels().textures().getNormalAtlasTexture();
normalTexture.setLinearFiltering(false);
renderer.bindNormalTexture(normalTexture);
Texture2D materialTexture = content.voxels().textures().getMaterialAtlasTexture();
materialTexture.setLinearFiltering(false);
renderer.bindMaterialTexture(materialTexture);
renderFakeVoxel(renderer, fakeCell);
}
use of io.xol.chunkstories.api.world.cell.CellData in project chunkstories-api by Hugobros3.
the class VoxelItemRenderer method renderItemInInventory.
@Override
public void renderItemInInventory(RenderingInterface renderer, ItemPile pile, float screenPositionX, float screenPositionY, int scaling) {
/*if (((ItemVoxel) pile.getItem()).getVoxel() instanceof VoxelCustomIcon) {
fallbackRenderer.renderItemInInventory(renderer, pile, screenPositionX, screenPositionY, scaling);
return;
}*/
int slotSize = 24 * scaling;
Shader program = renderer.useShader("inventory_blockmodel");
renderer.setCullingMode(CullingMode.COUNTERCLOCKWISE);
renderer.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
program.setUniform2f("screenSize", renderer.getWindow().getWidth(), renderer.getWindow().getHeight());
program.setUniform2f("dekal", screenPositionX + pile.getItem().getDefinition().getSlotsWidth() * slotSize / 2, screenPositionY + pile.getItem().getDefinition().getSlotsHeight() * slotSize / 2);
program.setUniform1f("scaling", slotSize / 1.65f);
transformation.identity();
transformation.scale(new Vector3f(-1f, 1f, 1f));
transformation.rotate(toRad(-22.5f), new Vector3f(1.0f, 0.0f, 0.0f));
transformation.rotate(toRad(45f), new Vector3f(0.0f, 1.0f, 0.0f));
transformation.translate(new Vector3f(-0.5f, -0.5f, -0.5f));
program.setUniformMatrix4f("transformation", transformation);
Voxel voxel = ((ItemVoxel) pile.getItem()).getVoxel();
if (voxel == null) {
int width = slotSize * pile.getItem().getDefinition().getSlotsWidth();
int height = slotSize * pile.getItem().getDefinition().getSlotsHeight();
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(screenPositionX, screenPositionY, width, height, 0, 1, 1, 0, content.textures().getTexture("./items/icons/notex.png"), true, true, null);
return;
}
Texture2D texture = content.voxels().textures().getDiffuseAtlasTexture();
texture.setLinearFiltering(false);
renderer.bindAlbedoTexture(texture);
Texture2D normalTexture = content.voxels().textures().getNormalAtlasTexture();
normalTexture.setLinearFiltering(false);
renderer.bindNormalTexture(normalTexture);
Texture2D materialTexture = content.voxels().textures().getMaterialAtlasTexture();
materialTexture.setLinearFiltering(false);
renderer.bindMaterialTexture(materialTexture);
CellData fakeCell = new DummyCell(0, 0, 0, voxel, 0, 0, 0) {
CellData air = new DummyCell(0, 1, 0, voxel.store().air(), 0, 0, 0);
@Override
public int getBlocklight() {
return voxel.getEmittedLightLevel(this);
}
@Override
public CellData getNeightbor(int side) {
return air;
}
@Override
public int getMetaData() {
return ((ItemVoxel) pile.getItem()).getVoxelMeta();
}
};
renderFakeVoxel(renderer, fakeCell);
}
use of io.xol.chunkstories.api.world.cell.CellData in project chunkstories-api by Hugobros3.
the class ItemVoxel method onControllerInput.
@Override
public boolean onControllerInput(Entity entity, ItemPile pile, Input input, Controller controller) {
try {
if (entity.getWorld() instanceof WorldMaster && input.getName().equals("mouse.right")) {
// Require entities to be of the right kind
if (!(entity instanceof EntityWorldModifier))
return true;
if (!(entity instanceof EntityControllable))
return true;
EntityWorldModifier modifierEntity = (EntityWorldModifier) entity;
EntityControllable playerEntity = (EntityControllable) entity;
boolean isEntityCreativeMode = (entity instanceof EntityCreative) && (((EntityCreative) entity).isCreativeMode());
Location blockLocation = null;
blockLocation = playerEntity.getBlockLookingAt(false);
if (blockLocation != null) {
FutureCell fvc = new FutureCell(entity.getWorld().peekSafely(blockLocation));
fvc.setVoxel(voxel);
// Opaque blocks overwrite the original light with zero.
if (voxel.getDefinition().isOpaque()) {
fvc.setBlocklight(0);
fvc.setSunlight(0);
}
// Glowy stuff should glow
// if(voxel.getDefinition().getEmittedLightLevel() > 0)
fvc.setBlocklight(voxel.getEmittedLightLevel(fvc));
// Player events mod
if (controller instanceof Player) {
Player player = (Player) controller;
CellData ctx = entity.getWorld().peek(blockLocation);
PlayerVoxelModificationEvent event = new PlayerVoxelModificationEvent(ctx, fvc, isEntityCreativeMode ? EntityCreative.CREATIVE_MODE : this, player);
// Anyone has objections ?
entity.getWorld().getGameContext().getPluginManager().fireEvent(event);
if (event.isCancelled())
return true;
entity.getWorld().getSoundManager().playSoundEffect("sounds/gameplay/voxel_place.ogg", Mode.NORMAL, fvc.getLocation(), 1.0f, 1.0f);
}
entity.getWorld().poke(fvc, modifierEntity);
// Decrease stack size
if (!isEntityCreativeMode) {
int currentAmount = pile.getAmount();
currentAmount--;
pile.setAmount(currentAmount);
}
} else {
// No space found :/
return true;
}
}
} catch (WorldException e) {
}
return false;
}
Aggregations