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);
}
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
}
}
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();
}
}
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.");
}
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;
}
}
}
}
Aggregations