use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.
the class ItemDuctListener method isDuctInteraction.
private static boolean isDuctInteraction(InteractBlockEvent event) {
if (!(event instanceof InteractBlockEvent.Primary.MainHand) && !(event instanceof InteractBlockEvent.Secondary.MainHand)) {
return false;
}
if (!event.getTargetBlock().getLocation().isPresent()) {
return false;
}
Location<World> loc = event.getTargetBlock().getLocation().get();
BlockType type = loc.getBlockType();
if (!isEndPointType(type)) {
return false;
}
Direction dir = loc.get(Keys.DIRECTION).orElse(Direction.NONE);
Optional<TileEntity> te = loc.getRelative(dir).getTileEntity();
return te.isPresent() && te.get() instanceof Carrier;
}
use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.
the class ItemDuctListener method onBreak.
@Listener
public void onBreak(ChangeBlockEvent.Break event) {
for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
if (!trans.getOriginal().getLocation().isPresent()) {
continue;
}
BlockType type = trans.getOriginal().getState().getType();
Location<World> loc = trans.getOriginal().getLocation().get();
if (isEndPointType(type)) {
Direction dir = trans.getOriginal().get(Keys.DIRECTION).orElse(Direction.NONE);
Optional<DuctData> data = loc.getRelative(dir).get(DuctData.class);
if (data.isPresent()) {
data.get().remove(dir.getOpposite());
if (data.get().getFilters().isEmpty()) {
loc.getRelative(dir).remove(DuctData.class);
} else {
loc.getRelative(dir).offer(data.get());
}
}
}
}
}
use of org.spongepowered.api.block.BlockType 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.block.BlockType in project modules-extra by CubeEngine.
the class MarketSignListener method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockSnapshot orig = transaction.getOriginal();
BlockType type = orig.getState().getType();
if (type == STANDING_SIGN || type == WALL_SIGN) {
Optional<ImmutableMarketSignData> signData = orig.get(ImmutableMarketSignData.class);
if (signData.isPresent()) {
if (signData.get().getSignType() != null) {
event.setCancelled(true);
return;
}
}
}
Location<World> origLoc = orig.getLocation().get();
for (Direction blockFace : BlockUtil.BLOCK_FACES) {
if (blockFace == DOWN) {
continue;
}
Location<World> relative = origLoc.getRelative(blockFace);
if (!relative.get(MarketSignData.class).isPresent()) {
continue;
}
if (blockFace == UP) {
if (relative.getBlockType() == STANDING_SIGN) {
event.setCancelled(true);
return;
}
} else {
if (relative.getBlockType() == WALL_SIGN && relative.get(Keys.DIRECTION).get() == blockFace) {
event.setCancelled(true);
return;
}
}
}
}
}
use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.
the class MarketSignListener method onSignPlace.
@Listener(order = Order.POST)
public void onSignPlace(ChangeBlockEvent.Place event, @First Player player) {
if (event.getTransactions().size() > 1 || !module.getEditModeCommand().hasUser(player)) {
return;
}
for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
BlockType type = trans.getFinal().getState().getType();
if (// placed sign
type == BlockTypes.STANDING_SIGN || type == BlockTypes.WALL_SIGN) {
if (!player.hasPermission(module.perms().EDIT_USE.getId())) {
event.setCancelled(true);
i18n.send(player, NEGATIVE, "You are not allowed to create market signs!");
return;
}
MarketSignData data = new MarketSignData();
data.setID(UUID.randomUUID());
data.setOwner(player.getUniqueId());
Location<World> loc = trans.getFinal().getLocation().get();
loc.offer(data);
manager.setSign(loc, player);
Sponge.getCauseStackManager().pushCause(player);
player.closeInventory();
}
}
}
Aggregations