Search in sources :

Example 26 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories-api by Hugobros3.

the class EntityComponentInventory method push.

@Override
protected void push(StreamTarget destinator, DataOutputStream stream) throws IOException {
    // Check that person has permission
    if (destinator instanceof Player) {
        Player player = (Player) destinator;
        Entity entity = player.getControlledEntity();
        // Abort if the entity don't have access
        if (!this.actualInventory.isAccessibleTo(entity)) {
            // System.out.println(player + "'s " + entity + " don't have access to "+this);
            stream.writeByte(UpdateMode.NEVERMIND.ordinal());
            return;
        }
    }
    stream.writeByte(UpdateMode.TOTAL_REFRESH.ordinal());
    actualInventory.pushInventory(destinator, stream);
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player)

Example 27 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class ServerPlayer method updateTrackedEntities.

// Entity tracking
public void updateTrackedEntities() {
    EntityControllable controlledEntity = this.controlledEntity;
    if (controlledEntity == null)
        return;
    // Cache (idk if HotSpot makes it redudant but whatever)
    double world_size = controlledEntity.getWorld().getWorldSize();
    Location controlledEntityLocation = controlledEntity.getLocation();
    double ENTITY_VISIBILITY_SIZE = 192;
    Iterator<Entity> inRangeEntitiesIterator = controlledEntity.getWorld().getEntitiesInBox(controlledEntityLocation, new Vector3d(ENTITY_VISIBILITY_SIZE, ENTITY_VISIBILITY_SIZE, ENTITY_VISIBILITY_SIZE));
    while (inRangeEntitiesIterator.hasNext()) {
        Entity e = inRangeEntitiesIterator.next();
        // && chunk != null;
        boolean shouldTrack = e.shouldBeTrackedBy(this);
        boolean contains = subscribedEntities.contains(e);
        if (shouldTrack && !contains)
            this.subscribe(e);
        if (!shouldTrack && contains)
            this.unsubscribe(e);
    }
    Iterator<Entity> subscribedEntitiesIterator = subscribedEntities.iterator();
    while (subscribedEntitiesIterator.hasNext()) {
        Entity e = subscribedEntitiesIterator.next();
        Location loc = e.getLocation();
        // Distance calculations
        double dx = LoopingMathHelper.moduloDistance(controlledEntityLocation.x(), loc.x(), world_size);
        double dy = Math.abs(controlledEntityLocation.y() - loc.y());
        double dz = LoopingMathHelper.moduloDistance(controlledEntityLocation.z(), loc.z(), world_size);
        boolean inRange = (dx < ENTITY_VISIBILITY_SIZE && dz < ENTITY_VISIBILITY_SIZE && dy < ENTITY_VISIBILITY_SIZE);
        // Reasons other than distance to stop tracking this entity
        if (!e.shouldBeTrackedBy(this) || !inRange)
            this.unsubscribe(e);
    // No need to do anything as the component system handles the updates
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Vector3d(org.joml.Vector3d) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) Location(io.xol.chunkstories.api.Location)

Example 28 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class ServerPlayer method unsubscribeAll.

@Override
public void unsubscribeAll() {
    Iterator<Entity> iterator = getSubscribedToList();
    while (iterator.hasNext()) {
        Entity entity = iterator.next();
        // If one of the entities is controllable ...
        if (entity instanceof EntityControllable) {
            EntityControllable controllableEntity = (EntityControllable) entity;
            Controller entityController = controllableEntity.getControllerComponent().getController();
            // If said entity is controlled by this subscriber/player
            if (entityController == this) {
                // Set the controller to null
                controllableEntity.getControllerComponent().setController(null);
            }
        }
        ((EntityBase) entity).unsubscribe(this);
        iterator.remove();
    }
}
Also used : EntityBase(io.xol.chunkstories.api.entity.EntityBase) Entity(io.xol.chunkstories.api.entity.Entity) Controller(io.xol.chunkstories.api.entity.Controller) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Example 29 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class ServerPlayer method openInventory.

@Override
public void openInventory(Inventory inventory) {
    Entity entity = this.getControlledEntity();
    if (inventory.isAccessibleTo(entity)) {
        if (inventory instanceof EntityComponentInventory.EntityInventory) {
            // this.sendMessage("Notice: Pushing this inventory to you so you can see the
            // contents");
            EntityComponentInventory.EntityInventory i = (EntityComponentInventory.EntityInventory) inventory;
            i.asComponent().pushComponent(this);
        }
        // this.sendMessage("Sending you the open inventory request.");
        PacketOpenInventory open = new PacketOpenInventory(getWorld(), inventory);
        this.pushPacket(open);
    }
// else
// this.sendMessage("Notice: You don't have access to this inventory.");
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) PacketOpenInventory(io.xol.chunkstories.api.net.packets.PacketOpenInventory) EntityComponentInventory(io.xol.chunkstories.api.entity.components.EntityComponentInventory)

Example 30 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class DefaultWeatherEffectsRenderer method tick.

@Override
public void tick() {
    // Spawn some snow arround
    float snowPresence = getSnowPresence();
    Entity e = world.getClient().getPlayer().getControlledEntity();
    if (e != null && world.getWorldRenderer() != null) {
        Location loc = e.getLocation();
        for (int i = 0; i < snowPresence * 10; i++) world.getParticlesManager().spawnParticleAtPosition("snow", loc.add(Math.random() * 20 - 10, Math.random() * 20, Math.random() * 20 - 10));
    }
    // TODO server-side
    if (world.getWeather() > 0.9) {
        if (world.getWorldInfo().resolveProperty("thunderEnabled", "true").equals("true")) {
            // noThunderUntil = 0;
            if (System.currentTimeMillis() > noThunderUntil) {
                long maxDelay = Long.parseLong(world.getWorldInfo().resolveProperty("maxThunderDelayInMs", "30000"));
                long delay = Math.max(0, random.nextLong() % maxDelay);
                if (noThunderUntil != 0) {
                    int worldX = random.nextInt(world.getSizeInChunks() * 32);
                    int worldZ = random.nextInt(world.getSizeInChunks() * 32);
                    // Spawn the strike
                    world.getParticlesManager().spawnParticleAtPosition("lightning_strike_illumination", new Location(world, worldX, 0, worldZ));
                }
                noThunderUntil = System.currentTimeMillis() + delay;
            }
        }
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Location(io.xol.chunkstories.api.Location)

Aggregations

Entity (io.xol.chunkstories.api.entity.Entity)44 Location (io.xol.chunkstories.api.Location)17 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)12 Vector3d (org.joml.Vector3d)11 Player (io.xol.chunkstories.api.player.Player)9 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)7 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)5 Voxel (io.xol.chunkstories.api.voxel.Voxel)4 World (io.xol.chunkstories.api.world.World)4 EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)4 IOException (java.io.IOException)4 EntityBase (io.xol.chunkstories.api.entity.EntityBase)3 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)3 EntityComponentInventory (io.xol.chunkstories.api.entity.components.EntityComponentInventory)3 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)3 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)3 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)3 CellData (io.xol.chunkstories.api.world.cell.CellData)3 Vector3dc (org.joml.Vector3dc)3 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)2