use of org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier in project AdamantineShield by Karanum.
the class PlayerInspectListener method onBlockSecondaryInteract.
@Listener
public void onBlockSecondaryInteract(InteractBlockEvent.Secondary.MainHand e, @First Player p) {
if (!plugin.getInspectManager().isInspector(p))
return;
e.setCancelled(true);
BlockSnapshot block = e.getTargetBlock();
if (!block.getLocation().isPresent())
return;
Location<World> loc = block.getLocation().get();
p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
Runnable task = null;
if (loc.getTileEntity().isPresent()) {
if (loc.getTileEntity().get() instanceof MultiBlockCarrier) {
task = () -> {
MultiBlockCarrier carrier = (MultiBlockCarrier) loc.getTileEntity().get();
plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), carrier.getLocation().getBlockPosition());
};
} else if (loc.getTileEntity().get() instanceof TileEntityCarrier) {
task = () -> plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), loc.getBlockPosition());
}
} else {
task = () -> plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition().add(e.getTargetSide().asBlockOffset()));
}
if (task != null)
plugin.getThreadPool().execute(task);
}
use of org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier in project AdamantineShield by Karanum.
the class RollbackManager method performAddition.
// TODO: Set proper causes for block changes caused by rollback/undo
private void performAddition(LookupLine line) {
World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
if (w == null)
return;
if (line.getTarget() instanceof ItemType) {
Optional<TileEntity> te = w.getTileEntity(line.getPos());
if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
TileEntityCarrier c = (TileEntityCarrier) te.get();
Inventory i = c.getInventory();
ItemType type = (ItemType) line.getTarget();
ItemStack stack = ItemStack.builder().fromContainer(line.getDataAsView()).itemType(type).quantity(line.getCount()).build();
Inventory slot = i.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(line.getSlot())));
slot.set(stack);
}
} else if (line.getTarget() instanceof BlockType) {
BlockState block = null;
if (line.getDataAsView() == null) {
block = BlockState.builder().blockType((BlockType) line.getTarget()).build();
w.setBlock(line.getPos(), block);
} else {
DataView blockData = line.getDataAsView();
DataView blockState = blockData.getView(DataQuery.of("BlockState")).orElse(null);
block = BlockState.builder().build(blockState).orElse(null);
if (block != null)
w.setBlock(line.getPos(), block);
}
}
}
use of org.spongepowered.api.block.tileentity.carrier.TileEntityCarrier in project AdamantineShield by Karanum.
the class RollbackManager method performRemoval.
private void performRemoval(LookupLine line) {
World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
if (w == null)
return;
if (line.getTarget() instanceof ItemType) {
Optional<TileEntity> te = w.getTileEntity(line.getPos());
if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
TileEntityCarrier c = (TileEntityCarrier) te.get();
Inventory i = c.getInventory();
Inventory slot = i.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(line.getSlot())));
slot.set(ItemStack.of(ItemTypes.NONE, 0));
}
} else if (line.getTarget() instanceof BlockType) {
BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
w.setBlock(line.getPos(), block);
}
}
Aggregations