Search in sources :

Example 1 with ClientInterface

use of io.xol.chunkstories.api.client.ClientInterface 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 ClientInterface

use of io.xol.chunkstories.api.client.ClientInterface in project chunkstories by Hugobros3.

the class ReloadContentCommand method reloadShaders.

private void reloadShaders(CommandEmitter emitter) {
    if (this.gameContext instanceof ClientInterface) {
        ClientInterface client = (ClientInterface) gameContext;
        client.getContent().shaders().reloadAll();
        emitter.sendMessage("#00FFD0" + "Reloaded shaders.");
    }
}
Also used : ClientInterface(io.xol.chunkstories.api.client.ClientInterface)

Example 3 with ClientInterface

use of io.xol.chunkstories.api.client.ClientInterface in project chunkstories by Hugobros3.

the class ReloadContentCommand method reloadTextures.

private void reloadTextures(CommandEmitter emitter) {
    if (this.gameContext instanceof ClientInterface) {
        ClientInterface client = (ClientInterface) gameContext;
        client.getContent().textures().reloadAll();
        emitter.sendMessage("#00FFD0" + "Reloaded textures.");
    }
}
Also used : ClientInterface(io.xol.chunkstories.api.client.ClientInterface)

Example 4 with ClientInterface

use of io.xol.chunkstories.api.client.ClientInterface in project chunkstories by Hugobros3.

the class JavaCrashesUploader method run.

@Override
public void run() {
    File folder = new File(GameDirectory.getGameFolderPath());
    if (!folder.exists() || !folder.isDirectory()) {
        logger().error("JavaCrashesUploader: .chunkstories unfit");
    } else {
        // Carry on
        logger().debug("JavaCrashesUploader: Looking for java crashes dumps");
        for (File file : folder.listFiles()) {
            if (!file.isDirectory() && file.getName().startsWith("hs_err_pid")) {
                System.out.println("We've got ourselves a client !");
                try {
                    String str = "not-client";
                    if (context instanceof ClientInterface)
                        str = ((ClientInterface) context).username();
                    logger().info("JavaCrashesUploader: Found crashfile " + file.getName() + ", uploading (30s max)");
                    ReportThread reportThread = new ReportThread("crash-report-found-" + str, file);
                    reportThread.start();
                    synchronized (reportThread) {
                        reportThread.join(30 * 1000);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                file.renameTo(new File(GameDirectory.getGameFolderPath() + "/logs/sent_" + file.getName()));
            }
        }
    }
}
Also used : ClientInterface(io.xol.chunkstories.api.client.ClientInterface) File(java.io.File)

Example 5 with ClientInterface

use of io.xol.chunkstories.api.client.ClientInterface in project chunkstories-api by Hugobros3.

the class PacketOpenInventory method process.

@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
    inventory = InventoryTranslator.obtainInventoryHandle(in, processor);
    if (processor.getContext() instanceof ClientInterface) {
        ClientInterface client = (ClientInterface) processor.getContext();
        Entity currentControlledEntity = client.getPlayer().getControlledEntity();
        if (currentControlledEntity != null && currentControlledEntity instanceof EntityWithInventory)
            client.openInventories(((EntityWithInventory) currentControlledEntity).getInventory(), inventory);
        else
            client.openInventories(inventory);
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) EntityWithInventory(io.xol.chunkstories.api.entity.interfaces.EntityWithInventory) ClientInterface(io.xol.chunkstories.api.client.ClientInterface)

Aggregations

ClientInterface (io.xol.chunkstories.api.client.ClientInterface)8 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)2 Player (io.xol.chunkstories.api.player.Player)2 File (java.io.File)2 Location (io.xol.chunkstories.api.Location)1 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 Asset (io.xol.chunkstories.api.content.Asset)1 AssetHierarchy (io.xol.chunkstories.api.content.mods.AssetHierarchy)1 Controller (io.xol.chunkstories.api.entity.Controller)1 Entity (io.xol.chunkstories.api.entity.Entity)1 EntityWithInventory (io.xol.chunkstories.api.entity.interfaces.EntityWithInventory)1 EntityWorldModifier (io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier)1 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)1 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)1 InputsManager (io.xol.chunkstories.api.input.InputsManager)1 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)1 World (io.xol.chunkstories.api.world.World)1 WorldCell (io.xol.chunkstories.api.world.World.WorldCell)1 WorldClientNetworkedRemote (io.xol.chunkstories.api.world.WorldClientNetworkedRemote)1 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)1