use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.
the class ToolCommands method setTool.
private static void setTool(Player player, LocalSession session, Tool tool, String translationKey) throws InvalidToolBindException {
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
session.setTool(itemStack.getType(), tool);
player.print(Caption.of(translationKey, itemStack.getRichName()));
sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.
the class FabricWorld method useItem.
@Override
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
ItemStack stack = FabricAdapter.adapt(new BaseItemStack(item.getType(), item.getNbtData(), 1));
ServerWorld world = (ServerWorld) getWorld();
final WorldEditFakePlayer fakePlayer;
try {
fakePlayer = fakePlayers.get(world);
} catch (ExecutionException ignored) {
return false;
}
fakePlayer.setStackInHand(Hand.MAIN_HAND, stack);
fakePlayer.setPositionAndAngles(position.getBlockX(), position.getBlockY(), position.getBlockZ(), (float) face.toVector().toYaw(), (float) face.toVector().toPitch());
final BlockPos blockPos = FabricAdapter.toBlockPos(position);
final BlockHitResult rayTraceResult = new BlockHitResult(FabricAdapter.toVec3(position), FabricAdapter.adapt(face), blockPos, false);
ItemUsageContext itemUseContext = new ItemUsageContext(fakePlayer, Hand.MAIN_HAND, rayTraceResult);
ActionResult used = stack.useOnBlock(itemUseContext);
if (used != ActionResult.SUCCESS) {
// try activating the block
if (getWorld().getBlockState(blockPos).activate(world, fakePlayer, Hand.MAIN_HAND, rayTraceResult)) {
used = ActionResult.SUCCESS;
} else {
used = stack.getItem().use(world, fakePlayer, Hand.MAIN_HAND).getResult();
}
}
return used == ActionResult.SUCCESS;
}
use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.
the class FabricAdapter method adapt.
public static ItemStack adapt(BaseItemStack baseItemStack) {
net.minecraft.nbt.CompoundTag fabricCompound = null;
if (baseItemStack.getNbtData() != null) {
fabricCompound = NBTConverter.toNative(baseItemStack.getNbtData());
}
final ItemStack itemStack = new ItemStack(adapt(baseItemStack.getType()), baseItemStack.getAmount());
itemStack.setTag(fabricCompound);
return itemStack;
}
Aggregations