Search in sources :

Example 1 with FutureCell

use of io.xol.chunkstories.api.world.cell.FutureCell in project chunkstories-core by Hugobros3.

the class ItemMiningTool method tickInHand.

@Override
public void tickInHand(Entity owner, ItemPile itemPile) {
    World world = owner.getWorld();
    if (owner instanceof EntityControllable && owner instanceof EntityWorldModifier) {
        EntityControllable entityControllable = (EntityControllable) owner;
        Controller controller = entityControllable.getController();
        if (controller != null && controller instanceof Player) {
            InputsManager inputs = controller.getInputsManager();
            Location lookingAt = entityControllable.getBlockLookingAt(true);
            if (lookingAt != null && lookingAt.distance(owner.getLocation()) > 7f)
                lookingAt = null;
            if (inputs.getInputByName("mouse.left").isPressed() && lookingAt != null) {
                WorldCell cell = world.peekSafely(lookingAt);
                // Cancel mining if looking away or the block changed by itself
                if (lookingAt == null || (progress != null && (lookingAt.distance(progress.loc) > 0 || !cell.getVoxel().sameKind(progress.voxel)))) {
                    progress = null;
                }
                if (progress == null) {
                    // Try starting mining something
                    if (lookingAt != null)
                        progress = new MiningProgress(world.peekSafely(lookingAt));
                } else {
                    // Progress using efficiency / ticks per second
                    progress.progress += ItemMiningTool.this.miningEfficiency / 60f / progress.materialHardnessForThisTool;
                    if (progress.progress >= 1.0f) {
                        if (owner.getWorld() instanceof WorldMaster) {
                            FutureCell future = new FutureCell(cell);
                            future.setVoxel(this.getDefinition().store().parent().voxels().air());
                            // Check no one minds
                            PlayerVoxelModificationEvent event = new PlayerVoxelModificationEvent(cell, future, (WorldModificationCause) entityControllable, (Player) controller);
                            owner.getWorld().getGameContext().getPluginManager().fireEvent(event);
                            // Break the block
                            if (!event.isCancelled()) {
                                Vector3d rnd = new Vector3d();
                                for (int i = 0; i < 40; i++) {
                                    rnd.set(progress.loc);
                                    rnd.add(Math.random() * 0.98, Math.random() * 0.98, Math.random() * 0.98);
                                    world.getParticlesManager().spawnParticleAtPosition("voxel_frag", rnd);
                                }
                                world.getSoundManager().playSoundEffect("sounds/gameplay/voxel_remove.ogg", Mode.NORMAL, progress.loc, 1.0f, 1.0f);
                                Location itemSpawnLocation = new Location(world, progress.loc);
                                itemSpawnLocation.add(0.5, 0.0, 0.5);
                                // ItemPile droppedItemPile = null;
                                for (ItemPile droppedItemPile : cell.getVoxel().getLoot(cell, (WorldModificationCause) entityControllable)) {
                                    EntityGroundItem thrownItem = (EntityGroundItem) getDefinition().store().parent().entities().getEntityDefinition("groundItem").create(itemSpawnLocation);
                                    thrownItem.positionComponent.setPosition(itemSpawnLocation);
                                    thrownItem.velocityComponent.setVelocity(new Vector3d(Math.random() * 0.125 - 0.0625, 0.1, Math.random() * 0.125 - 0.0625));
                                    thrownItem.setItemPile(droppedItemPile);
                                    world.addEntity(thrownItem);
                                }
                                try {
                                    world.poke(future, (WorldModificationCause) entityControllable);
                                } catch (WorldException e) {
                                // Didn't work
                                // TODO make some ingame effect so as to clue in the player why it failed
                                }
                            }
                        }
                        progress = null;
                    }
                }
            } else {
                progress = null;
            }
            Player player = (Player) controller;
            if (player.getContext() instanceof ClientInterface) {
                Player me = ((ClientInterface) player.getContext()).getPlayer();
                if (me.equals(player)) {
                    myProgress = progress;
                }
            }
        }
    }
}
Also used : Player(io.xol.chunkstories.api.player.Player) WorldCell(io.xol.chunkstories.api.world.World.WorldCell) EntityGroundItem(io.xol.chunkstories.core.entity.EntityGroundItem) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) EntityWorldModifier(io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier) ClientInterface(io.xol.chunkstories.api.client.ClientInterface) World(io.xol.chunkstories.api.world.World) Controller(io.xol.chunkstories.api.entity.Controller) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile) FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) PlayerVoxelModificationEvent(io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent) Vector3d(org.joml.Vector3d) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) InputsManager(io.xol.chunkstories.api.input.InputsManager) Location(io.xol.chunkstories.api.Location)

Example 2 with FutureCell

use of io.xol.chunkstories.api.world.cell.FutureCell in project chunkstories-core by Hugobros3.

the class Chest method output.

@Override
public void output(World csWorld, int csX, int csY, int csZ, int minecraftBlockId, int minecraftMetaData, MinecraftRegion region, int minecraftCuurrentChunkXinsideRegion, int minecraftCuurrentChunkZinsideRegion, int x, int y, int z) {
    Chunk chunk = csWorld.getChunkWorldCoordinates(csX, csY, csZ);
    assert chunk != null;
    /*int baked = voxelID;
		
		if (voxel instanceof VoxelChest)
			try {
				baked = ((VoxelChest) voxel).onPlace(chunk.peek(csX, csY, csZ), baked, null);
			} catch (WorldException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		else
			System.out.println("fuck you 666");
		
		csWorld.pokeRawSilently(csX, csY, csZ, baked);*/
    csWorld.pokeSimpleSilently(new FutureCell(csWorld, csX, csY, csZ, voxel));
}
Also used : FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) Chunk(io.xol.chunkstories.api.world.chunk.Chunk)

Example 3 with FutureCell

use of io.xol.chunkstories.api.world.cell.FutureCell in project chunkstories-core by Hugobros3.

the class Sign method output.

@Override
public void output(World csWorld, int csX, int csY, int csZ, int minecraftBlockId, int minecraftMetaData, MinecraftRegion region, int minecraftCuurrentChunkXinsideRegion, int minecraftCuurrentChunkZinsideRegion, int x, int y, int z) {
    Chunk chunk = csWorld.getChunkWorldCoordinates(csX, csY, csZ);
    assert chunk != null;
    if (voxel instanceof VoxelSign) {
        if (!voxel.getName().endsWith("_post")) {
            if (minecraftMetaData == 2)
                minecraftMetaData = 8;
            else if (minecraftMetaData == 3)
                minecraftMetaData = 0;
            else if (minecraftMetaData == 4)
                minecraftMetaData = 4;
            else if (minecraftMetaData == 5)
                minecraftMetaData = 12;
        }
        /*baked = VoxelFormat.changeMeta(baked, minecraftMetaData);
			
			try {
				baked = ((VoxelSign) voxel).onPlace(chunk.peek(csX, csY, csZ), baked, null);
			} catch (WorldException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			csWorld.pokeRawSilently(csX, csY, csZ, baked);*/
        FutureCell future = new FutureCell(csWorld, csX, csY, csZ, voxel);
        future.setMetaData(minecraftMetaData);
        csWorld.pokeSimple(future);
        try {
            translateSignText(csWorld.peek(csX, csY, csZ).components().get("signData"), region.getChunk(minecraftCuurrentChunkXinsideRegion, minecraftCuurrentChunkZinsideRegion), x, y, z);
        } catch (WorldException e) {
            e.printStackTrace();
        }
    // TODO Move Sign text getting here ?
    } else
        System.out.println("fuck you 666");
}
Also used : FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) MinecraftChunk(io.xol.enklume.MinecraftChunk) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) VoxelSign(io.xol.chunkstories.core.voxel.VoxelSign)

Example 4 with FutureCell

use of io.xol.chunkstories.api.world.cell.FutureCell in project chunkstories by Hugobros3.

the class TaskConvertMcChunk method task.

@Override
protected boolean task(TaskExecutor taskExecutor) {
    ConverterWorkerThread cwt = (ConverterWorkerThread) taskExecutor;
    WorldTool csWorld = cwt.world();
    // Is it within our borders ?
    // if (chunkStoriesCurrentChunkX >= 0 && chunkStoriesCurrentChunkX < cwt.size().sizeInChunks * 32 && chunkStoriesCurrentChunkZ >= 0 && chunkStoriesCurrentChunkZ < cwt.size().sizeInChunks * 32)
    {
        // MinecraftChunk minecraftChunk = null;
        try {
            if (minecraftChunk != null) {
                // If it succeed, we first require to load the corresponding chunkstories stuff
                // Ignore the summaries for now
                /*Heightmap summary = csWorld.getRegionsSummariesHolder().aquireRegionSummaryWorldCoordinates(this, chunkStoriesCurrentChunkX, chunkStoriesCurrentChunkZ);
					if(summary != null)
						registeredCS_Summaries.add(summary);*/
                CompoundFence loadRelevantData = new CompoundFence();
                // Then the chunks
                for (int y = 0; y < OfflineWorldConverter.mcWorldHeight; y += 32) {
                    ChunkHolder holder = csWorld.aquireChunkHolderWorldCoordinates(cwt, chunkStoriesCurrentChunkX, y, chunkStoriesCurrentChunkZ);
                    if (holder != null) {
                        loadRelevantData.add(holder.waitForLoading());
                        if (cwt.registeredCS_Holders.add(holder))
                            cwt.chunksAquired++;
                    }
                }
                // Wait for them to actually load
                loadRelevantData.traverse();
                for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) for (int y = 0; y < OfflineWorldConverter.mcWorldHeight; y++) {
                    // Translate each block
                    int mcId = minecraftChunk.getBlockID(x, y, z) & 0xFFF;
                    byte meta = (byte) (minecraftChunk.getBlockMeta(x, y, z) & 0xF);
                    // Ignore air blocks
                    if (mcId != 0) {
                        Mapper mapper = this.mappers.getMapper(mcId, meta);
                        if (mapper == null)
                            continue;
                        if (mapper instanceof NonTrivialMapper) {
                            ((NonTrivialMapper) mapper).output(csWorld, chunkStoriesCurrentChunkX + x, y, chunkStoriesCurrentChunkZ + z, mcId, meta, minecraftRegion, minecraftCurrentChunkXinsideRegion, minecraftCuurrentChunkZinsideRegion, x, y, z);
                        } else {
                            FutureCell future = new FutureCell(csWorld, chunkStoriesCurrentChunkX + x, y, chunkStoriesCurrentChunkZ + z, csWorld.getContent().voxels().air());
                            // Directly set trivial blocks
                            mapper.output(mcId, meta, future);
                            if (!future.getVoxel().isAir())
                                csWorld.pokeSimpleSilently(future);
                        }
                    }
                }
            // Converts external data such as signs
            // SpecialBlocksHandler.processAdditionalStuff(minecraftChunk, csWorld, chunkStoriesCurrentChunkX, 0, chunkStoriesCurrentChunkZ);
            }
        } catch (Exception e) {
            cwt.converter().verbose("Issue with chunk " + minecraftCurrentChunkXinsideRegion + " " + minecraftCuurrentChunkZinsideRegion + " of region " + minecraftRegionX + " " + minecraftRegionZ + ".");
            e.printStackTrace();
        }
    }
    return true;
}
Also used : Mapper(io.xol.chunkstories.api.converter.mappings.Mapper) NonTrivialMapper(io.xol.chunkstories.api.converter.mappings.NonTrivialMapper) FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) WorldTool(io.xol.chunkstories.world.WorldTool) ChunkHolder(io.xol.chunkstories.api.world.chunk.ChunkHolder) ConverterWorkerThread(io.xol.chunkstories.converter.ConverterWorkers.ConverterWorkerThread) NonTrivialMapper(io.xol.chunkstories.api.converter.mappings.NonTrivialMapper)

Example 5 with FutureCell

use of io.xol.chunkstories.api.world.cell.FutureCell 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;
}
Also used : FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) Player(io.xol.chunkstories.api.player.Player) PlayerVoxelModificationEvent(io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) EntityWorldModifier(io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier) EntityCreative(io.xol.chunkstories.api.entity.interfaces.EntityCreative) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) CellData(io.xol.chunkstories.api.world.cell.CellData) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) Location(io.xol.chunkstories.api.Location)

Aggregations

FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)6 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)4 Location (io.xol.chunkstories.api.Location)3 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)3 Player (io.xol.chunkstories.api.player.Player)3 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)3 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)2 EntityWorldModifier (io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier)2 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)2 WorldCell (io.xol.chunkstories.api.world.World.WorldCell)2 CellData (io.xol.chunkstories.api.world.cell.CellData)2 Chunk (io.xol.chunkstories.api.world.chunk.Chunk)2 Vector3d (org.joml.Vector3d)2 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)1 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 Mapper (io.xol.chunkstories.api.converter.mappings.Mapper)1 NonTrivialMapper (io.xol.chunkstories.api.converter.mappings.NonTrivialMapper)1 Controller (io.xol.chunkstories.api.entity.Controller)1 Entity (io.xol.chunkstories.api.entity.Entity)1 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)1