use of com.ichorpowered.guardianapi.util.item.value.mutable.MapValue in project guardian by ichorpowered.
the class MaterialCapture method update.
@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
return;
final Player player = entry.getEntity(Player.class).get();
final Location<World> location = player.getLocation();
final MapValue<String, Integer> activeMaterials = GuardianMapValue.builder(MaterialCapture.ACTIVE_MATERIAL_TICKS).defaultElement(Maps.newHashMap()).element(Maps.newHashMap()).create();
activeMaterials.put(GAS, 0);
activeMaterials.put(LIQUID, 0);
activeMaterials.put(SOLID, 0);
captureContainer.offerIfEmpty(activeMaterials);
captureContainer.offerIfEmpty(GuardianValue.builder(MaterialCapture.SPEED_MODIFIER).defaultElement(1d).element(1d).create());
final Value<Double> playerBoxWidth = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_WIDTH, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final Value<Double> playerBoxHeight = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_HEIGHT, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final Value<Double> playerBoxSafety = ContentUtil.getFirst(ContentKeys.BOX_PLAYER_SAFETY, entry, this.getDetection().getContentContainer()).orElse(GuardianValue.empty());
final double playerWidth = playerBoxWidth.getDirect().orElse(1.2) + playerBoxSafety.getDirect().orElse(0.05);
final double playerHeight = playerBoxHeight.getDirect().orElse(1.8) + playerBoxSafety.getDirect().orElse(0.05);
final boolean isSneaking = player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get();
final BoundingBox playerBox = WorldUtil.getBoundingBox(playerWidth, isSneaking ? (playerHeight - 0.15) : playerHeight);
if (!WorldUtil.containsBlocksUnder(location, playerBox, 1.25)) {
final double gasSpeed = this.matterSpeed.get(GAS);
captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * gasSpeed));
captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(GAS, value.get().get(GAS) + 1));
} else if (WorldUtil.anyLiquidAtDepth(location, playerBox, 1d) || WorldUtil.anyLiquidAtDepth(location, playerBox, 0) || WorldUtil.anyLiquidAtDepth(location, playerBox, isSneaking ? -(playerHeight - 0.25) : -playerHeight)) {
final double liquidSpeed = this.matterSpeed.get(LIQUID);
captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * liquidSpeed));
captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(LIQUID, value.get().get(LIQUID) + 1));
} else {
final List<BlockType> surroundingBlockTypes = WorldUtil.getBlocksUnder(location, playerBox, 1.25);
for (final BlockType blockType : surroundingBlockTypes) {
final double speedModifier = this.materialSpeed.getOrDefault(blockType.getName().toLowerCase(), this.matterSpeed.get(SOLID));
captureContainer.getValue(MaterialCapture.SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original * speedModifier));
}
captureContainer.getValue(MaterialCapture.ACTIVE_MATERIAL_TICKS).ifPresent(value -> value.put(SOLID, value.get().get(SOLID) + 1));
}
}
use of com.ichorpowered.guardianapi.util.item.value.mutable.MapValue in project guardian by ichorpowered.
the class ControlCapture method update.
@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
return;
final Player player = entry.getEntity(Player.class).get();
final MapValue<String, Integer> activeControls = GuardianMapValue.builder(ControlCapture.ACTIVE_CONTROL_TICKS).defaultElement(Maps.newHashMap()).element(Maps.newHashMap()).create();
activeControls.put(FLY, 0);
activeControls.put(WALK, 0);
activeControls.put(SNEAK, 0);
activeControls.put(SPRINT, 0);
captureContainer.offerIfEmpty(activeControls);
captureContainer.offerIfEmpty(GuardianValue.builder(ControlCapture.HORIZONTAL_DISTANCE).defaultElement(1d).element(1d).create());
captureContainer.offerIfEmpty(GuardianValue.builder(ControlCapture.VERTICAL_DISTANCE).defaultElement(1d).element(1d).create());
double walkSpeedData = player.get(Keys.WALKING_SPEED).orElse(1d) * 10;
double flySpeedData = player.get(Keys.FLYING_SPEED).orElse(0.5) * 10;
if (player.getLocation().getY() != captureContainer.get(GuardianSequence.INITIAL_LOCATION).get().getY()) {
captureContainer.getValue(ControlCapture.VERTICAL_DISTANCE).ifPresent(value -> value.transform(original -> original * this.liftOffset));
}
if ((player.get(Keys.IS_FLYING).isPresent() && player.get(Keys.IS_FLYING).get())) {
captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.flyOffset * flySpeedData)));
captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(FLY, value.get().get(FLY) + 1));
} else if (player.get(Keys.IS_SPRINTING).isPresent() && player.get(Keys.IS_SPRINTING).get()) {
captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.sprintOffset * walkSpeedData)));
captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(SPRINT, value.get().get(SPRINT) + 1));
} else if (player.get(Keys.IS_SNEAKING).isPresent() && player.get(Keys.IS_SNEAKING).get()) {
captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.sneakOffset * walkSpeedData)));
captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(SNEAK, value.get().get(SNEAK) + 1));
} else {
captureContainer.getValue(ControlCapture.HORIZONTAL_DISTANCE).ifPresent(value -> value.transform(original -> original * (this.walkOffset * walkSpeedData)));
captureContainer.getValue(ControlCapture.ACTIVE_CONTROL_TICKS).ifPresent(value -> value.put(WALK, value.get().get(WALK) + 1));
}
}
Aggregations