/** * Gets the location next to this one in the given direction. * Always moves by a unit amount, even diagonally. * * @param direction The direction to move in * @return The location in that direction */ public Location<E> getRelative(Direction direction) { return add(direction.asOffset()); }
/** * Gets the location next to this one in the given direction. * Always moves by a unit amount, even diagonally. * * @param direction The direction to move in * @return The location in that direction */ public Location<E> getRelative(Direction direction) { return add(direction.asOffset()); }
@Override public boolean doAction(Dispenser dispenser, ItemStack[] recipe) { Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE); if (face != Direction.NONE) { Location<World> offset = dispenser.getLocation().getRelative(face); int distance = 0; while (offset.getBlockType() == BlockTypes.AIR && distance < 5) { for (Entity e : LocationUtil.getEntitiesAtLocation(offset)) { e.setVelocity(face.asOffset().mul(5 - distance)); } distance ++; offset = offset.getRelative(face); } return true; } return false; } }
@Override public boolean doAction(Dispenser dispenser, ItemStack[] recipe) { Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE); if (face != Direction.NONE) { Location<World> offset = dispenser.getLocation().getRelative(face); int distance = 0; while (offset.getBlockType() == BlockTypes.AIR && distance < 5) { for (Entity e : LocationUtil.getEntitiesAtLocation(offset)) { e.setVelocity(face.asOffset().mul(5 - distance).mul(-1.0)); } distance ++; offset = offset.getRelative(face); } return true; } return false; } }
@Override public boolean doAction(Dispenser dispenser, ItemStack[] recipe) { Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE); if (face != Direction.NONE) { Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5); Snowball snowball = (Snowball) dispenser.getWorld().createEntityNaturally(EntityTypes.SNOWBALL, location.getPosition()); Vector3d arrowVelocity = face.asOffset().add(0, 0.1f, 0).normalize().mul(1.5f); snowball.setVelocity(arrowVelocity); try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CUSTOM); dispenser.getWorld().spawnEntity(snowball); } return true; } return false; } }
@Override public boolean doAction(Dispenser dispenser, ItemStack[] recipe) { Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE); if (face != Direction.NONE) { Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5); ThrownExpBottle bottle = (ThrownExpBottle) dispenser.getWorld().createEntity(EntityTypes.THROWN_EXP_BOTTLE, location.getPosition()); Vector3d bottleVelocity = face.asOffset().add(0, 0.1f, 0).normalize().mul(1.5f); bottle.setVelocity(bottleVelocity); try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CUSTOM); dispenser.getWorld().spawnEntity(bottle); } return true; } return false; } }
@Override public boolean doAction(Dispenser dispenser, ItemStack[] recipe) { Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE); if (face != Direction.NONE) { Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5); PrimedTNT tnt = (PrimedTNT) dispenser.getWorld().createEntity(EntityTypes.PRIMED_TNT, location.getPosition()); Vector3d tntVelocity = face.asOffset().add(0, 0.1f, 0).normalize().mul(2f); tnt.setVelocity(tntVelocity); try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CUSTOM); dispenser.getWorld().spawnEntity(tnt); } return true; } return false; } }
@Override public boolean doAction(Dispenser dispenser, ItemStack[] recipe) { Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE); if (face != Direction.NONE) { Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5); TippedArrow arrow = (TippedArrow) dispenser.getWorld().createEntityNaturally(EntityTypes.TIPPED_ARROW, location.getPosition()); arrow.offer(Keys.FIRE_TICKS, 5000); Vector3d arrowVelocity = face.asOffset().add(0, 0.1f, 0).normalize().mul(1.5f); arrow.setVelocity(arrowVelocity); try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CUSTOM); dispenser.getWorld().spawnEntity(arrow); } return true; } return false; } }
@Listener public void onEntityMove(MoveEntityEvent event, @Getter("getTargetEntity") Minecart minecart) { Location<World> toBlock = event.getToTransform().getLocation(); if (intersectionRails.getValue()) { if (toBlock.getBlockType() == BlockTypes.STONE_PRESSURE_PLATE || toBlock.getBlockType() == BlockTypes.WOODEN_PRESSURE_PLATE || toBlock.getBlockType() == BlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE || toBlock.getBlockType() == BlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE) { minecart.setVelocity(minecart.getVelocity().normalize().mul(4d)); } } if (verticalRails.getValue()) { if (toBlock.getBlockType() == BlockTypes.VINE || toBlock.getBlockType() == BlockTypes.LADDER) { Vector3d velocity = new Vector3d(0, verticalVelocity.getValue(), 0); if (toBlock.getBlockType() == BlockTypes.VINE) { Vector3d directionVelocity = new Vector3d(); for (Direction direction : toBlock.get(Keys.CONNECTED_DIRECTIONS).get()) { directionVelocity = directionVelocity.add(direction.asOffset()); } if (directionVelocity.length() == 0) return; velocity = velocity.add(directionVelocity.normalize()); } else { velocity = velocity.add(toBlock.get(Keys.DIRECTION).get().asOffset().mul(-1)); } minecart.setVelocity(minecart.getVelocity().add(velocity)); } } }
private void addChair(Player player, Location<World> location) { Entity entity = location.getExtent().createEntity(EntityTypes.ARMOR_STAND, location.getBlockPosition().toDouble().sub(-0.5, 1.2, -0.5)); entity.offer(Keys.INVISIBLE, true); entity.offer(Keys.HAS_GRAVITY, false); if (faceCorrectDirection.getValue() && location.supports(Keys.DIRECTION)) { Vector3d euler = LocationUtil.cartesianToEuler(location.get(Keys.DIRECTION).orElse(Direction.NONE).getOpposite().asOffset()); entity.setRotation(euler); player.setRotation(euler); } Sponge.getCauseStackManager().pushCause(player); location.getExtent().spawnEntity(entity); Sponge.getCauseStackManager().popCause(); Chair<?> chair = new Chair<>((ArmorStand) entity, location, player.getLocation()); entity.addPassenger(player); player.sendMessage(Text.of(TextColors.YELLOW, "You sit down!")); chairs.put(player.getUniqueId(), chair); }