use of org.spongepowered.api.block.BlockType 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.BlockType 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);
}
}
use of org.spongepowered.api.block.BlockType in project TotalEconomy by Erigitic.
the class ShopManager method onChestPlace.
/**
* Prevents chests from being placed next to chest shops.
*
* @param event Place block
*/
@Listener
public void onChestPlace(ChangeBlockEvent.Place event) {
BlockSnapshot blockSnapshot = event.getTransactions().get(0).getDefault();
BlockType blockType = blockSnapshot.getState().getType();
Location location = blockSnapshot.getLocation().get();
if (blockType.equals(BlockTypes.CHEST) && isPlacedNextToShop(location)) {
event.setCancelled(true);
}
}
use of org.spongepowered.api.block.BlockType in project core by CubeEngine.
the class BlockTypeParser method parse.
@Override
public BlockType parse(Class aClass, CommandInvocation invocation) throws ParserException {
String arg = invocation.consume(1);
BlockType item = Sponge.getRegistry().getType(BlockType.class, arg.toLowerCase()).orElse(null);
if (item == null) {
throw new TranslatedParserException(i18n.translate(invocation.getContext(Locale.class), NEGATIVE, "ItemType {input#item} not found!", arg));
}
return item;
}
use of org.spongepowered.api.block.BlockType in project core by CubeEngine.
the class BlockTypeParser method suggest.
@Override
public List<String> suggest(Class type, CommandInvocation invocation) {
ArrayList<String> list = new ArrayList<>();
String token = invocation.currentToken().toLowerCase();
if (MINECRAFT.startsWith(token)) {
list.add(MINECRAFT);
}
boolean startMc = token.startsWith(MINECRAFT);
for (BlockType bType : Sponge.getRegistry().getAllOf(BlockType.class)) {
if (bType.getId().startsWith(token)) {
if (!bType.getId().startsWith(MINECRAFT) || startMc) {
list.add(bType.getId());
}
}
if (bType.getId().startsWith(MINECRAFT + token)) {
list.add(bType.getId().substring(MINECRAFT.length()));
}
}
return list;
}
Aggregations