use of net.minecraft.nbt.NbtCompound in project Primeval by devs-immortal.
the class VesselItem method addToBundle.
private static int addToBundle(ItemStack bundle, ItemStack stack) {
if (!stack.isEmpty() && stack.getItem().canBeNested() && canAddItem(bundle)) {
NbtCompound nbtCompound = bundle.getOrCreateNbt();
if (!nbtCompound.contains("Items")) {
nbtCompound.put("Items", new NbtList());
}
int i = getBundleOccupancy(bundle);
int j = getItemOccupancy(stack);
int k = Math.min(stack.getCount(), (64 - i) / j);
if (k == 0) {
return 0;
} else {
NbtList nbtList = nbtCompound.getList("Items", 10);
Optional<NbtCompound> optional = canMergeStack(stack, nbtList);
if (optional.isPresent()) {
NbtCompound nbtCompound2 = optional.get();
ItemStack itemStack = ItemStack.fromNbt(nbtCompound2);
itemStack.increment(k);
itemStack.writeNbt(nbtCompound2);
nbtList.remove(nbtCompound2);
nbtList.add(0, nbtCompound2);
} else {
ItemStack nbtCompound2 = stack.copy();
nbtCompound2.setCount(k);
NbtCompound itemStack = new NbtCompound();
nbtCompound2.writeNbt(itemStack);
nbtList.add(0, itemStack);
}
return k;
}
} else {
return 0;
}
}
use of net.minecraft.nbt.NbtCompound in project meteor-rejects by AntiCope.
the class ChatBot method fromTag.
@Override
public Module fromTag(NbtCompound tag) {
commands.clear();
if (tag.contains("commands")) {
NbtCompound msgs = tag.getCompound("commands");
msgs.getKeys().forEach((key) -> {
commands.put(key, msgs.getString(key));
});
}
return super.fromTag(tag);
}
use of net.minecraft.nbt.NbtCompound in project meteor-rejects by AntiCope.
the class NewChunks method onReadPacket.
@EventHandler
private void onReadPacket(PacketEvent.Receive event) {
if (event.packet instanceof ChunkDeltaUpdateS2CPacket) {
ChunkDeltaUpdateS2CPacket packet = (ChunkDeltaUpdateS2CPacket) event.packet;
packet.visitUpdates((pos, state) -> {
if (!state.getFluidState().isEmpty() && !state.getFluidState().isStill()) {
ChunkPos chunkPos = new ChunkPos(pos);
for (Direction dir : searchDirs) {
if (mc.world.getBlockState(pos.offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) {
newChunks.add(chunkPos);
return;
}
}
}
});
} else if (event.packet instanceof BlockUpdateS2CPacket) {
BlockUpdateS2CPacket packet = (BlockUpdateS2CPacket) event.packet;
if (!packet.getState().getFluidState().isEmpty() && !packet.getState().getFluidState().isStill()) {
ChunkPos chunkPos = new ChunkPos(packet.getPos());
for (Direction dir : searchDirs) {
if (mc.world.getBlockState(packet.getPos().offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) {
newChunks.add(chunkPos);
return;
}
}
}
} else if (event.packet instanceof ChunkDataS2CPacket && mc.world != null) {
ChunkDataS2CPacket packet = (ChunkDataS2CPacket) event.packet;
ChunkPos pos = new ChunkPos(packet.getX(), packet.getZ());
if (!newChunks.contains(pos) && mc.world.getChunkManager().getChunk(packet.getX(), packet.getZ()) == null) {
WorldChunk chunk = new WorldChunk(mc.world, pos);
try {
chunk.loadFromPacket(packet.getChunkData().getSectionsDataBuf(), new NbtCompound(), packet.getChunkData().getBlockEntities(packet.getX(), packet.getZ()));
} catch (ArrayIndexOutOfBoundsException e) {
return;
}
for (int x = 0; x < 16; x++) {
for (int y = mc.world.getBottomY(); y < mc.world.getTopY(); y++) {
for (int z = 0; z < 16; z++) {
FluidState fluid = chunk.getFluidState(x, y, z);
if (!fluid.isEmpty() && !fluid.isStill()) {
oldChunks.add(pos);
return;
}
}
}
}
}
}
}
use of net.minecraft.nbt.NbtCompound in project meteor-rejects by AntiCope.
the class HeadScreen method createHeadStack.
private ItemStack createHeadStack(String uuid, String value, String name) {
ItemStack head = Items.PLAYER_HEAD.getDefaultStack();
NbtCompound tag = new NbtCompound();
NbtCompound skullOwner = new NbtCompound();
skullOwner.putUuid("Id", UUID.fromString(uuid));
NbtCompound properties = new NbtCompound();
NbtList textures = new NbtList();
NbtCompound Value = new NbtCompound();
Value.putString("Value", value);
textures.add(Value);
properties.put("textures", textures);
skullOwner.put("Properties", properties);
tag.put("SkullOwner", skullOwner);
head.setNbt(tag);
head.setCustomName(new LiteralText(name));
return head;
}
use of net.minecraft.nbt.NbtCompound in project meteor-rejects by AntiCope.
the class LocateCommand method build.
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("lodestone").executes(ctx -> {
ItemStack stack = mc.player.getInventory().getMainHandStack();
if (stack.getItem() != Items.COMPASS) {
error("You need to hold a lodestone compass");
return SINGLE_SUCCESS;
}
NbtCompound tag = stack.getNbt();
if (tag == null) {
error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
return SINGLE_SUCCESS;
}
NbtCompound nbt1 = tag.getCompound("LodestonePos");
if (nbt1 == null) {
error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
return SINGLE_SUCCESS;
}
Vec3d coords = new Vec3d(nbt1.getDouble("X"), nbt1.getDouble("Y"), nbt1.getDouble("Z"));
BaseText text = new LiteralText("Lodestone located at ");
text.append(ChatUtils.formatCoords(coords));
text.append(".");
info(text);
return SINGLE_SUCCESS;
}));
builder.then(argument("feature", EnumArgumentType.enumArgument(WorldGenUtils.Feature.stronghold)).executes(ctx -> {
WorldGenUtils.Feature feature = EnumArgumentType.getEnum(ctx, "feature", WorldGenUtils.Feature.stronghold);
BlockPos pos = WorldGenUtils.locateFeature(feature, mc.player.getBlockPos());
if (pos != null) {
BaseText text = new LiteralText(String.format("%s located at ", Utils.nameToTitle(feature.toString().replaceAll("_", "-"))));
Vec3d coords = new Vec3d(pos.getX(), pos.getY(), pos.getZ());
text.append(ChatUtils.formatCoords(coords));
text.append(".");
info(text);
return SINGLE_SUCCESS;
}
if (feature == WorldGenUtils.Feature.stronghold) {
FindItemResult eye = InvUtils.findInHotbar(Items.ENDER_EYE);
if (eye.found()) {
BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("follow entity minecraft:eye_of_ender");
firstStart = null;
firstEnd = null;
secondStart = null;
secondEnd = null;
MeteorClient.EVENT_BUS.subscribe(this);
info("Please throw the first Eye of Ender");
}
}
throw NOT_FOUND.create(feature);
}));
builder.then(literal("cancel").executes(s -> {
cancel();
return SINGLE_SUCCESS;
}));
}
Aggregations