use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method leftClickOnBlockServer.
public static void leftClickOnBlockServer(@Nonnull ServerPlayerEntity player, LeftClickBlockMessage message) {
BlockPos pos = message.getPos();
ServerWorld world = player.getLevel();
ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
if (itemStack.getItem() != ModItems.multiTool || world.isEmptyBlock(pos)) {
return;
}
player.startUsingItem(Hand.MAIN_HAND);
if (player.isShiftKeyDown()) {
CompoundNBT tag = itemStack.getTag();
if (tag == null) {
tag = new CompoundNBT();
}
BlockState state = world.getBlockState(pos);
Item item = Item.byBlock(state.getBlock());
ItemStack stackToPlace = new ItemStack(() -> item, 1);
CompoundNBT blockTag = new CompoundNBT();
stackToPlace.save(blockTag);
tag.put("Item", blockTag);
itemStack.setTag(tag);
ITextComponent component = stackToPlace.getDisplayName();
player.displayClientMessage(new StringTextComponent("Bound tool to ").append(component), true);
} else {
LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
if (!opEnergy.isPresent()) {
Overloaded.logger.warn("MultiTool has no Energy Capability? NBT: " + itemStack.getTag());
return;
}
// Used to catch item spawn to teleport
RegistryKey<World> worldId = world.dimension();
CommonSideEvents.enabled = true;
CommonSideEvents.world = worldId;
CommonSideEvents.pos = pos;
CommonSideEvents.uuid = player.getUUID();
IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Error"));
int efficiency = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_EFFICIENCY, itemStack);
int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, itemStack);
switch(breakAndUseEnergy(world, pos, energy, player, efficiency, unbreaking)) {
case FAIL_REMOVE:
player.displayClientMessage(new StringTextComponent("Unable to break block, reason unknown"), true);
break;
case FAIL_ENERGY:
player.displayClientMessage(new StringTextComponent("Unable to break block, not enough energy"), true);
break;
case FAIL_UNBREAKABLE:
player.displayClientMessage(new StringTextComponent("Block is unbreakable"), true);
break;
case FAIL_RANGE:
player.displayClientMessage(new StringTextComponent("Block is out of range."), true);
break;
case SUCCESS:
break;
}
CommonSideEvents.enabled = false;
}
}
use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class AbstractBlockHyperReceiver method use.
@Override
@Nonnull
public ActionResultType use(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult rayTraceResult) {
ItemStack heldItem = player.getItemInHand(hand);
if (heldItem.getItem().equals(ModItems.linkingCard)) {
CompoundNBT tag = heldItem.getTag();
if (tag == null) {
tag = new CompoundNBT();
}
ResourceLocation worldId = world.dimension().location();
writeNodeData(tag, worldId, pos);
heldItem.setTag(tag);
if (world.isClientSide) {
player.displayClientMessage(new StringTextComponent(String.format("Recorded: World: %s Position: %s", worldId, pos.toShortString())), false);
}
return ActionResultType.CONSUME;
} else {
return super.use(state, world, pos, player, hand, rayTraceResult);
}
}
use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class PlayerInterfaceRenderer method render.
@Override
public void render(@Nonnull TilePlayerInterface te, float v, @Nonnull MatrixStack matrixStack, @Nonnull IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
UUID uuid = te.getPlacer();
if (uuid == null)
return;
PlayerEntity player = te.getLevel().getPlayerByUUID(uuid);
if (player == null) {
if (!uuid.equals(uuidCache)) {
uuidCache = uuid;
CompoundNBT tag = new CompoundNBT();
tag.putString("SkullOwner", uuid.toString());
stackCache = new ItemStack(Items.PLAYER_HEAD, 1, tag);
}
renderItem(te, stackCache, matrixStack, iRenderTypeBuffer);
return;
}
renderPlayer(te, player, matrixStack, iRenderTypeBuffer, combinedLightIn);
}
use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class EnergyInventoryBasedRecipeProcessor method serializeNBT.
@Override
public CompoundNBT serializeNBT() {
CompoundNBT storage = new CompoundNBT();
storage.put("Input", NBTHelper.serializeItems(input));
storage.put("Output", NBTHelper.serializeItems(output));
storage.putInt("Energy", currentEnergy);
return storage;
}
use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class BigIntEnergyStorage method serializeNBT.
@Override
public CompoundNBT serializeNBT() {
CompoundNBT compound = new CompoundNBT();
compound.putByteArray("Count", energy.amount.toByteArray());
return compound;
}
Aggregations