use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.
the class RepairBlockManager method removePlayer.
public void removePlayer(final Player player) {
if (player == null) {
return;
}
RepairBlockInventory inventory;
for (RepairBlock repairBlock : this.repairBlocks.values()) {
inventory = repairBlock.removeInventory(player);
if (inventory != null) {
final World world = player.getWorld();
final Location loc = player.getLocation();
Sponge.getCauseStackManager().pushCause(player);
for (Inventory slot : inventory.inventory) {
if (slot.peek().isPresent()) {
Entity drop = world.createEntity(EntityTypes.ITEM, loc.getPosition());
drop.offer(Keys.REPRESENTED_ITEM, slot.peek().get().createSnapshot());
world.spawnEntity(drop);
}
}
}
}
}
use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.
the class ItemDuctTransferListener method activate.
private void activate() {
List<Network> networks = new ArrayList<>();
for (Iterator<Location<World>> it = this.promptedActivations.keySet().iterator(); it.hasNext(); ) {
Location<World> loc = it.next();
if (this.promptedActivations.get(loc) - 1000 > System.currentTimeMillis()) {
promptedActivations.clear();
continue;
}
it.remove();
// Check if data is still present
Optional<DuctData> data = loc.get(DuctData.class);
if (data.isPresent()) {
for (Direction dir : Direction.values()) {
if (dir.isCardinal() || dir.isUpright()) {
BlockType type = loc.getRelative(dir).getBlockType();
if (STICKY_PISTON.equals(type) || OBSERVER.equals(type)) {
Optional<List<ItemStack>> filters = data.get().get(dir);
if (filters.isPresent()) {
Network network = manager.findNetwork(loc.getRelative(dir));
TileEntity te = loc.getTileEntity().get();
Inventory inventory = ((Carrier) te).getInventory();
if (te instanceof Chest) {
inventory = ((Chest) te).getDoubleChestInventory().orElse(inventory);
}
network.activate(inventory, filters.get());
networks.add(network);
}
}
}
}
}
}
for (Network network : networks) {
for (Location<World> exitLoc : network.exitPoints.keySet()) {
Direction exitDir = exitLoc.get(Keys.DIRECTION).orElse(Direction.NONE).getOpposite();
exitLoc = exitLoc.getRelative(exitDir.getOpposite());
promptActivation(exitLoc.getTileEntity().filter(t -> t instanceof Carrier).map(Carrier.class::cast).orElse(null), true, null);
}
}
if (promptedActivations.isEmpty()) {
task.cancel();
}
}
use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.
the class Network method activate.
public void activate(Inventory inventory, List<ItemStack> filters) {
if (isStorage()) {
pullFromStorage(inventory, filters);
return;
}
for (Map.Entry<Location<World>, DuctData> entry : exitPoints.entrySet()) {
Inventory pollFrom = inventory;
Location<World> loc = entry.getKey();
DuctData data = entry.getValue();
Direction dir = loc.get(Keys.DIRECTION).orElse(Direction.NONE).getOpposite();
Location<World> targetLoc = loc.getRelative(dir.getOpposite());
TileEntity te = targetLoc.getTileEntity().get();
Inventory target = ((Carrier) te).getInventory();
if (te instanceof Dropper) {
Network nw = manager.findNetwork(targetLoc);
nw.transferToStorage(queryFiltered(filters, inventory), data.get(dir).get());
continue;
}
if (te instanceof Chest) {
target = ((Chest) te).getDoubleChestInventory().orElse(target);
}
Optional<List<ItemStack>> targetFilter = data.get(dir);
if (targetFilter.isPresent()) {
if (// Only allow to extract items in the filter
!filters.isEmpty()) {
// TODO more filters
pollFrom = queryFiltered(filters, inventory);
}
Inventory pollFromTo = pollFrom;
if (// Only allow to insert items in the filter
!targetFilter.get().isEmpty()) {
// TODO more filters
pollFromTo = queryFiltered(targetFilter.get(), inventory);
}
// For all filtered slots
doTransfer(pollFromTo, target);
}
}
}
use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.
the class Preview method send.
public void send(User user) {
// test limit preview changes to 1k
Location location = new Location(null, 0, 0, 0);
for (int i = 0; i < 1000; i++) {
if (states.isEmpty())
return;
Object poll = states.poll();
if (poll instanceof BlockState) {
((BlockState) poll).getLocation(location);
user.sendBlockChange(location, ((BlockState) poll).getType(), ((BlockState) poll).getRawData());
} else if (poll instanceof SignChange) {
user.sendSignChange(((SignChange) poll).loc, ((SignChange) poll).lines);
}
}
}
use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.
the class ListenerBlock method onBlockFall.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFall(final BlockPhysicsEvent event) {
if (!this.isActive(BlockFall.class, event.getBlock().getWorld())) {
return;
}
BlockState state = event.getBlock().getState();
if (state.getType().hasGravity() || state.getType() == DRAGON_EGG) {
if (event.getBlock().getRelative(DOWN).getType() == AIR) {
Location loc = state.getLocation();
BlockFall action = this.set(BlockFall.class, state, null);
ActionBlock cause = this.plannedFall.remove(loc);
if (cause instanceof ActionPlayerBlock) {
action.cause = this.reference((ActionPlayerBlock) cause);
}
action.setNewBlock(AIR);
this.logAction(action);
Block onTop = state.getBlock().getRelative(UP);
if (onTop.getType().hasGravity() || onTop.getType() == DRAGON_EGG) {
this.preplanBlockFall(new BlockPreFallEvent(onTop.getLocation(), cause));
}
}
}
}
Aggregations