Search in sources :

Example 1 with World

use of io.xol.chunkstories.api.world.World 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 World

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

the class SmoothStepVoxelRenderer method bakeInto.

@Override
public int bakeInto(ChunkRenderer chunkRenderer, ChunkRenderContext bakingContext, Chunk chunk, CellData voxelInformations) {
    int x = bakingContext.getRenderedVoxelPositionInChunkX();
    int y = bakingContext.getRenderedVoxelPositionInChunkY();
    int z = bakingContext.getRenderedVoxelPositionInChunkZ();
    // Check we have 8 neighbours
    World world = voxelInformations.getWorld();
    int wx = x + chunk.getChunkX() * 32;
    int wy = y + chunk.getChunkY() * 32;
    int wz = z + chunk.getChunkZ() * 32;
    // bakingContext.getCurrentVoxelLighter().getSunlightLevelInterpolated(x + 0.5f, y + 0.5f, z + 0.5f);
    byte sunlight = 0;
    // bakingContext.getCurrentVoxelLighter().getBlocklightLevelInterpolated(x + 0.5f, y + 0.5f, z + 0.5f);
    byte blockLight = 15;
    byte ao = bakingContext.getCurrentVoxelLighter().getAoLevelInterpolated(x + 0.5f, y + 0.5f, z + 0.5f);
    VoxelBakerHighPoly baker = chunkRenderer.getHighpolyBakerFor(LodLevel.ANY, ShadingType.OPAQUE);
    /*for(int a = wx - 1; a <= wx + 1; a++)
			for(int b = wz - 1; b <= wz + 1; b ++) {
				//If a single one is fucky
				if(VoxelFormat.id(world.getVoxelData(a, wy, b)) != voxel.getId())
					return old(voxelInformations).renderInto(chunkRenderer, bakingContext, chunk, voxelInformations);
			}*/
    // if(true)
    // return old(voxelInformations).renderInto(chunkRenderer, bakingContext, chunk, voxelInformations);
    VoxelTexture texture = voxel.getVoxelTexture(VoxelSide.TOP, voxelInformations);
    baker.usingTexture(texture);
    // int offset = texture.getAtlasOffset() / texture.getTextureScale();
    // int textureS = texture.getAtlasS() + (x % texture.getTextureScale()) * offset;
    // int textureT = texture.getAtlasT() + (z % texture.getTextureScale()) * offset;
    // final int max_step = 8;
    float[] height = new float[9];
    for (int a = wx - 1; a <= wx + 1; a++) bLoop: for (int b = wz - 1; b <= wz + 1; b++) {
        for (int h = wy + 1; h >= wy - 1; h--) {
            Voxel peek = world.peekSimple(a, h, b);
            int raw = world.peekRaw(a, h, b);
            if (voxel.sameKind(peek)) {
                height[(a - wx + 1) * 3 + b - wz + 1] = h - chunk.getChunkY() * 32 + 1 / 8f + VoxelFormat.meta(raw) / 8f;
                continue bLoop;
            }
        }
        return old(voxelInformations).bakeInto(chunkRenderer, bakingContext, chunk, voxelInformations);
    }
    // X --->
    // 036
    // 147
    // 258
    float corner00 = (height[0] + height[3] + height[1] + height[4]) / 4f;
    float corner10 = (height[3] + height[4] + height[7] + height[6]) / 4f;
    float corner01 = (height[1] + height[4] + height[2] + height[5]) / 4f;
    float corner11 = (height[4] + height[7] + height[5] + height[8]) / 4f;
    /*float corner00, corner01, corner10, corner11;
		int data00, data01, data10, data11;
		
		data00 = world.getVoxelData(wx, wy, wz);
		corner00 = 1/8f + y + VoxelFormat.meta(data00) / 8f;
		
		//Merge with left/top upper lip
		int dataN0p  = world.getVoxelData(wx - 1, wy + 1, wz);
		int data0Np  = world.getVoxelData(wx, wy + 1, wz - 1);
		int dataNNp  = world.getVoxelData(wx - 1, wy + 1, wz - 1);
		if(VoxelFormat.id(dataN0p) == voxel.getId()) {
			int meta = VoxelFormat.meta(dataN0p);
			if(meta < max_step)
				corner00 = Math.max(0, 1/8f + y + 1 + meta / 8f);
		}
		else if(VoxelFormat.id(data0Np) == voxel.getId()) {
			int meta = VoxelFormat.meta(data0Np);
			if(meta < max_step)
				corner00 = Math.max(0, 1/8f + y + 1 + meta / 8f);
		}
		else if(VoxelFormat.id(dataNNp) == voxel.getId()) {
			int meta = VoxelFormat.meta(dataNNp);
			if(meta < max_step)
				corner00 = Math.max(0, 1/8f + y + 1 + meta / 8f);
		}
		
		int data01p = world.getVoxelData(wx, wy + 1, wz + 1);
		if(VoxelFormat.id(data01p) == voxel.getId()) {
			corner01 = 1/8f + y + 1 +VoxelFormat.meta(data01p) / 8f;
		}
		else {
			data01 = world.getVoxelData(wx, wy, wz + 1);
			if(VoxelFormat.id(data01) == voxel.getId()) {
				corner01 = 1/8f + y +VoxelFormat.meta(data01) / 8f;
			}
			else {
				corner01 = corner00;
			}
		}
		
		if(VoxelFormat.id(dataN0p) == voxel.getId()) {
			int meta = VoxelFormat.meta(dataN0p);
			if(meta < max_step)
				corner01 = Math.max(0, 1/8f + y + 1 + meta / 8f);
		}
		
		int data10p = world.getVoxelData(wx + 1, wy + 1, wz);
		if(VoxelFormat.id(data10p) == voxel.getId()) {
			corner10 = 1/8f + y + 1 +VoxelFormat.meta(data10p) / 8f;
		}
		else {
			data10 = world.getVoxelData(wx + 1, wy, wz);
			if(VoxelFormat.id(data10) == voxel.getId()) {
				corner10 = 1/8f + y +VoxelFormat.meta(data10) / 8f;
			}
			else {
				corner10 = corner00;
			}
		}
		
		if(VoxelFormat.id(data0Np) == voxel.getId()) {
			int meta = VoxelFormat.meta(data0Np);
			if(meta < max_step)
				corner10 = Math.max(0, 1/8f + y + 1 + meta / 8f);
		}
		
		int data11p = world.getVoxelData(wx + 1, wy + 1, wz + 1);
		if(VoxelFormat.id(data11p) == voxel.getId()) {
			corner11 = 1/8f + y + 1 +VoxelFormat.meta(data11p) / 8f;
		}
		else {
			data11 = world.getVoxelData(wx + 1, wy, wz + 1);
			if(VoxelFormat.id(data11) == voxel.getId()) {
				corner11 = 1/8f + y +VoxelFormat.meta(data11) / 8f;
			}
			else {
				corner11 = corner00;
			}
		}
		
		/*float corner00 = 1/8f + y + VoxelFormat.meta(world.getVoxelData(wx, wy, wz)) / 8f;
		int dataN0p  = world.getVoxelData(wx - 1, wy + 1, wz);
		int data0Np  = world.getVoxelData(wx, wy + 1, wz - 1);
		int dataNNp  = world.getVoxelData(wx - 1, wy + 1, wz - 1);
		if(VoxelFormat.id(dataN0p) == voxel.getId()) {
			int meta = VoxelFormat.meta(dataN0p);
			if(meta < max_step)
				corner00 = Math.max(corner00, 1/8f + y + 1 + meta / 8f);
		}
		else if(VoxelFormat.id(data0Np) == voxel.getId()) {
			int meta = VoxelFormat.meta(data0Np);
			if(meta < max_step)
				corner00 = Math.max(corner00, 1/8f + y + 1 + meta / 8f);
		}
		else if(VoxelFormat.id(dataNNp) == voxel.getId()) {
			int meta = VoxelFormat.meta(dataNNp);
			if(meta < max_step)
				corner00 = Math.max(corner00, 1/8f + y + 1 + meta / 8f);
		}
		
		int data01 = world.getVoxelData(wx, wy, wz + 1);
		float corner01;
		if(VoxelFormat.id(data01) == voxel.getId()) {
			corner01 = 1/8f + y + VoxelFormat.meta(data01) / 8f;
		}
		else {
			corner01 = corner00;
			int data01p = world.getVoxelData(wx, wy + 1, wz + 1);
			if(VoxelFormat.id(data01p) == voxel.getId()) {
				int meta = VoxelFormat.meta(data01p);
				if(meta < max_step)
					corner01 = 1/8f + y + 1 + meta / 8f;
			}
		}
		
		int dataN1p = world.getVoxelData(wx - 1, wy + 1, wz);
		if(VoxelFormat.id(dataN1p) == voxel.getId()) {
			int meta = VoxelFormat.meta(dataN1p);
			if(meta < max_step)
				corner01 = Math.max(corner01, 1/8f + y + 1 + meta / 8f);
		}
		
		//float corner01 = VoxelFormat.id(data01) == voxel.getId() ? 1/8f + y + VoxelFormat.meta(data01) / 8f : corner00;
		
		int data10 = world.getVoxelData(wx + 1, wy, wz);
		float corner10;
		if(VoxelFormat.id(data10) == voxel.getId()) {
			corner10 = 1/8f + y + VoxelFormat.meta(data10) / 8f;
		}
		else {
			corner10 = corner00;
			int data10p = world.getVoxelData(wx + 1, wy + 1, wz);
			if(VoxelFormat.id(data10p) == voxel.getId()) {
				int meta = VoxelFormat.meta(data10p);
				if(meta < max_step)
					corner10 = 1/8f + y + 1 + meta / 8f;
			}
		}
		//float corner10 = VoxelFormat.id(data10) == voxel.getId() ? 1/8f + y + VoxelFormat.meta(data10) / 8f : corner00;
		
		int data1Np = world.getVoxelData(wx, wy + 1, wz - 1);
		if(VoxelFormat.id(data1Np) == voxel.getId()) {
			int meta = VoxelFormat.meta(data1Np);
			if(meta < max_step)
				corner10 = Math.max(corner10, 1/8f + y + 1 + meta / 8f);
		}
		
		int data11 = world.getVoxelData(wx + 1, wy, wz + 1);
		float corner11;
		if(VoxelFormat.id(data11) == voxel.getId()) {
			corner11 = 1/8f + y + VoxelFormat.meta(data11) / 8f;
		}
		else {
			corner11 =  Math.max(corner10, corner01);
			int data11p = world.getVoxelData(wx + 1, wy + 1, wz + 1);
			if(VoxelFormat.id(data11p) == voxel.getId()) {
				int meta = VoxelFormat.meta(data11p);
				if(meta < max_step)
					corner11 = 1/8f + y + 1 + meta / 8f;
			}
		}*/
    // float corner11 = VoxelFormat.id(data11) == voxel.getId() ? 1/8f + y + VoxelFormat.meta(data11) / 8f : Math.min(corner10, corner01);
    baker.setNormal(0f, 1f, 0f);
    baker.beginVertex(x, corner00, z);
    baker.setTextureCoordinates(0, 0);
    baker.setVoxelLight(sunlight, blockLight, ao);
    // baker.addNormalsInt(511, 1023, 511, (byte)0);
    baker.endVertex();
    baker.beginVertex(x + 1, corner11, z + 1);
    baker.setTextureCoordinates(0 + 1, 0 + 1);
    baker.setVoxelLight(sunlight, blockLight, ao);
    // baker.addNormalsInt(511, 1023, 511, (byte)0);
    baker.endVertex();
    baker.beginVertex(x + 1, corner10, z);
    baker.setTextureCoordinates(0 + 1, 0);
    baker.setVoxelLight(sunlight, blockLight, ao);
    // baker.addNormalsInt(511, 1023, 511, (byte)0);
    baker.endVertex();
    // <- ------------------- ->
    baker.beginVertex(x, corner01, z + 1);
    baker.setTextureCoordinates(0, 0 + 1);
    baker.setVoxelLight(sunlight, blockLight, ao);
    // baker.addNormalsInt(511, 1023, 511, (byte)0);
    baker.endVertex();
    baker.beginVertex(x + 1, corner11, z + 1);
    baker.setTextureCoordinates(0 + 1, 0 + 1);
    baker.setVoxelLight(sunlight, blockLight, ao);
    // baker.addNormalsInt(511, 1023, 511, (byte)0);
    baker.endVertex();
    baker.beginVertex(x, corner00, z);
    baker.setTextureCoordinates(0, 0);
    baker.setVoxelLight(sunlight, blockLight, ao);
    // baker.addNormalsInt(511, 1023, 511, (byte)0);
    baker.endVertex();
    return 6;
}
Also used : VoxelBakerHighPoly(io.xol.chunkstories.api.rendering.voxel.VoxelBakerHighPoly) Voxel(io.xol.chunkstories.api.voxel.Voxel) World(io.xol.chunkstories.api.world.World) VoxelTexture(io.xol.chunkstories.api.voxel.textures.VoxelTexture)

Example 3 with World

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

the class HeightmapArrayTexture method update.

public void update() {
    Player player = client.getPlayer();
    Location playerPosition = player.getLocation();
    if (playerPosition == null)
        // We won't do shit with that going on
        return;
    World world = playerPosition.getWorld();
    int chunkX = (int) Math.floor(playerPosition.x / 32.0);
    int chunkZ = (int) Math.floor(playerPosition.z / 32.0);
    int regionX = chunkX / 8;
    int regionZ = chunkZ / 8;
    // Remap the array
    if (lastRegionX != regionX || lastRegionZ != regionZ || redo.compareAndSet(true, false)) {
        WriteLock writeLock = lock.writeLock();
        writeLock.lock();
        // We may need this
        ByteBuffer bb = MemoryUtil.memAlloc(4 * 256 * 256);
        bb.order(ByteOrder.LITTLE_ENDIAN);
        // Clear unused slots
        for (int i = 0; i < 81; i++) {
            ArrayTextureSlot slot = arrayTextureContents[i];
            if (slot == null)
                continue;
            // Frees slots immediately once out of the area we care about
            if (Math.abs(slot.regionX - regionX) >= 5 || Math.abs(slot.regionZ - regionZ) >= 5)
                arrayTextureContents[i] = null;
        }
        for (int i = -4; i <= 4; i++) for (int j = -4; j <= 4; j++) {
            int regionI = regionX + i;
            int regionJ = regionZ + j;
            // Wrap arround the world!
            if (regionI < 0)
                regionI += world.getSizeInChunks() / 256;
            if (regionJ < 0)
                regionJ += world.getSizeInChunks() / 256;
            // Look for a slot already containing our wanted textures
            int free = -1;
            int good = -1;
            for (int k = 0; k < 81; k++) {
                ArrayTextureSlot slot = arrayTextureContents[k];
                if (slot == null) {
                    if (free == -1)
                        free = k;
                } else {
                    if (slot.regionX == regionI && slot.regionZ == regionJ) {
                        good = k;
                        break;
                    }
                }
            }
            int slot;
            // If no good slot was found :(
            if (good == -1) {
                arrayTextureContents[free] = new ArrayTextureSlot();
                arrayTextureContents[free].regionX = regionI;
                arrayTextureContents[free].regionZ = regionJ;
                slot = free;
            } else {
                slot = good;
            }
            // If data is not yet in the slot, check if the world has data for it
            if (!arrayTextureContents[slot].hasData) {
                Heightmap sum = world.getRegionsSummariesHolder().getHeightmap(arrayTextureContents[slot].regionX, arrayTextureContents[slot].regionZ);
                if (sum != null && sum.isLoaded()) {
                    loadHeights((HeightmapImplementation) sum, bb, 0);
                    heights.uploadTextureData(slot, 0, bb);
                    for (int lod = 1; lod <= 8; lod++) {
                        loadHeights((HeightmapImplementation) sum, bb, lod);
                        heights.uploadTextureData(slot, lod, bb);
                    }
                    heights.setMipMapping(true);
                    heights.setMipmapLevelsRange(0, 8);
                    loadTopVoxels((HeightmapImplementation) sum, bb, 0);
                    topVoxels.uploadTextureData(slot, 0, bb);
                    for (int lod = 1; lod <= 8; lod++) {
                        loadTopVoxels((HeightmapImplementation) sum, bb, lod);
                        topVoxels.uploadTextureData(slot, lod, bb);
                    }
                    topVoxels.setMipMapping(true);
                    topVoxels.setMipmapLevelsRange(0, 8);
                    arrayTextureContents[slot].hasData = true;
                }
            }
            arrayTextureReference[i + 4][j + 4] = slot;
        }
        MemoryUtil.memFree(bb);
        lastRegionX = regionX;
        lastRegionZ = regionZ;
        writeLock.unlock();
    }
}
Also used : WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Player(io.xol.chunkstories.api.player.Player) Heightmap(io.xol.chunkstories.api.world.heightmap.Heightmap) HeightmapImplementation(io.xol.chunkstories.world.summary.HeightmapImplementation) World(io.xol.chunkstories.api.world.World) ByteBuffer(java.nio.ByteBuffer) Location(io.xol.chunkstories.api.Location)

Example 4 with World

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

the class Lwjgl3ClientInputsManager method onInputPressed.

public boolean onInputPressed(Input input) {
    if (input.equals("fullscreen")) {
        gameWindow.toggleFullscreen();
        return true;
    }
    // System.out.println("Input pressed "+input.getName());
    // Try the client-side event press
    ClientInputPressedEvent event = new ClientInputPressedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
        if (event.isCancelled())
            return false;
    }
    // Try the GUI handling
    Layer layer = gameWindow.getLayer();
    if (layer.handleInput(input))
        return true;
    // System.out.println("wasn't handled");
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        // MouseScroll inputs are strictly client-side
        if (!(input instanceof MouseScroll)) {
            ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
            PacketInput packet = new PacketInput(world);
            packet.input = input;
            packet.isPressed = true;
            connection.pushPacket(packet);
        }
        return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
    } else {
        PlayerInputPressedEvent event2 = new PlayerInputPressedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        if (event2.isCancelled())
            return false;
    // entity.handleInteraction(input, entity.getControllerComponent().getController());
    }
    // Handle interaction locally
    return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) ClientInputPressedEvent(io.xol.chunkstories.api.events.client.ClientInputPressedEvent) World(io.xol.chunkstories.api.world.World) Layer(io.xol.chunkstories.api.gui.Layer) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) MouseScroll(io.xol.chunkstories.api.input.Mouse.MouseScroll) PlayerInputPressedEvent(io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)

Example 5 with World

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

the class Lwjgl3ClientInputsManager method onInputReleased.

@Override
public boolean onInputReleased(Input input) {
    ClientInputReleasedEvent event = new ClientInputReleasedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
    }
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
        PacketInput packet = new PacketInput(world);
        packet.input = input;
        packet.isPressed = false;
        connection.pushPacket(packet);
        return true;
    } else {
        PlayerInputReleasedEvent event2 = new PlayerInputReleasedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        return true;
    }
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) ClientInputReleasedEvent(io.xol.chunkstories.api.events.client.ClientInputReleasedEvent) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) PlayerInputReleasedEvent(io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent) World(io.xol.chunkstories.api.world.World) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Aggregations

World (io.xol.chunkstories.api.world.World)9 Location (io.xol.chunkstories.api.Location)5 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)5 Entity (io.xol.chunkstories.api.entity.Entity)4 Player (io.xol.chunkstories.api.player.Player)4 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)3 Voxel (io.xol.chunkstories.api.voxel.Voxel)3 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)2 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)2 ClientPluginManager (io.xol.chunkstories.api.plugin.ClientPluginManager)2 ServerConnection (io.xol.chunkstories.client.net.ServerConnection)2 PacketInput (io.xol.chunkstories.net.packets.PacketInput)2 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)2 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)1 ClientPacketsProcessor (io.xol.chunkstories.api.client.net.ClientPacketsProcessor)1 Controller (io.xol.chunkstories.api.entity.Controller)1 EntityWorldModifier (io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier)1 ClientInputPressedEvent (io.xol.chunkstories.api.events.client.ClientInputPressedEvent)1 ClientInputReleasedEvent (io.xol.chunkstories.api.events.client.ClientInputReleasedEvent)1 EventItemDroppedToWorld (io.xol.chunkstories.api.events.item.EventItemDroppedToWorld)1