Search in sources :

Example 6 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerClone.

@SubscribeEvent
public static void onPlayerClone(PlayerEvent.Clone event) {
    PlayerEntity oldPlayer = event.getOriginal();
    PlayerEntity newPlayer = event.getPlayer();
    IInventory oldInventory = oldPlayer.inventory;
    IInventory newInventory = newPlayer.inventory;
    if (event.isWasDeath()) {
        ItemStack mirrorStack = ItemStack.EMPTY;
        for (int i = 0; i < oldInventory.getSizeInventory(); i++) {
            ItemStack stack = oldInventory.getStackInSlot(i);
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                NBTHelper.ensureTagExists(stack);
                if (stack.getTag().contains("SpawnPoint") && (stack.getDamage() < (stack.getMaxDamage() - 1))) {
                    stack.damageItem(1, newPlayer, entity -> {
                    });
                }
                newInventory.setInventorySlotContents(i, stack);
                mirrorStack = stack;
                break;
            }
        }
        if (!mirrorStack.isEmpty()) {
            if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
                CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
                if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                    DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                    BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                    if (spawnDimension != null) {
                        newPlayer.setSpawnDimenion(spawnDimension);
                        newPlayer.setSpawnPoint(spawnPoint, true, false, spawnDimension);
                    }
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 7 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project NetherEx by LogicTechCorp.

the class DullMirrorItem method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote) {
        if (stack.getDamage() < stack.getMaxDamage() && player.isShiftKeyDown()) {
            DimensionType spawnDimension = world.getDimension().getType();
            BlockPos spawnPoint = player.getPosition();
            CompoundNBT compound = NBTHelper.ensureTagExists(stack);
            if (!compound.contains("SpawnDimension") || !compound.contains("SpawnPoint")) {
                DimensionType bedDimension = player.getSpawnDimension();
                BlockPos bedPos = player.getBedLocation(bedDimension);
                if (bedPos == null) {
                    bedPos = world.getServer().getWorld(bedDimension).getSpawnPoint();
                }
                compound.putString("BedDimension", bedDimension.getRegistryName().toString());
                compound.put("BedPoint", NBTUtil.writeBlockPos(bedPos));
                compound.putString("SpawnDimension", spawnDimension.getRegistryName().toString());
                compound.put("SpawnPoint", NBTUtil.writeBlockPos(spawnPoint));
                player.setSpawnDimenion(spawnDimension);
                player.setSpawnPoint(spawnPoint, true, false, spawnDimension);
                player.sendMessage(new TranslationTextComponent("tooltip.netherex.dull_mirror.spawn_point_set", spawnPoint.getX() + " " + spawnPoint.getY() + " " + spawnPoint.getZ()));
                world.playSound((double) spawnPoint.getX() + 0.5D, (double) spawnPoint.getY() + 0.5D, (double) spawnPoint.getZ() + 0.5D, SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 0.5F, world.rand.nextFloat() * 0.4F + 0.8F, false);
            } else {
                DimensionType bedDimension = DimensionType.byName(new ResourceLocation(compound.getString("BedDimension")));
                if (bedDimension != null) {
                    compound.remove("SpawnDimension");
                    compound.remove("SpawnPoint");
                    player.setSpawnDimenion(bedDimension);
                    player.setSpawnPoint(NBTUtil.readBlockPos(compound.getCompound("BedPoint")), true, false, bedDimension);
                    player.sendMessage(new TranslationTextComponent("tooltip.netherex.dull_mirror.spawn_point_removed", spawnPoint.getX() + " " + spawnPoint.getY() + " " + spawnPoint.getZ()));
                    world.playSound((double) spawnPoint.getX() + 0.5D, (double) spawnPoint.getY() + 0.5D, (double) spawnPoint.getZ() + 0.5D, SoundEvents.BLOCK_FIRE_AMBIENT, SoundCategory.BLOCKS, 0.5F, world.rand.nextFloat() * 0.4F + 0.8F, false);
                }
            }
            return new ActionResult<>(ActionResultType.SUCCESS, stack);
        }
    }
    return new ActionResult<>(ActionResultType.FAIL, stack);
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 8 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project NetherEx by LogicTechCorp.

the class DullMirrorItem method addInformation.

@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
    CompoundNBT compound = stack.getTag();
    if (compound != null) {
        if (compound.contains("SpawnDimension")) {
            DimensionType type = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
            tooltip.add(new TranslationTextComponent("tooltip.netherex.dull_mirror.spawn_dimension", StringUtils.capitalize(type.getRegistryName().getPath().replace("_", " "))));
        }
        if (compound.contains("SpawnPoint")) {
            BlockPos spawnPos = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
            tooltip.add(new TranslationTextComponent("tooltip.netherex.dull_mirror.spawn_point", spawnPos.getX() + " " + spawnPos.getY() + " " + spawnPos.getZ()));
        }
        if (compound.contains("DeathPoint")) {
            BlockPos deathPos = NBTUtil.readBlockPos(compound.getCompound("DeathPoint"));
            tooltip.add(new TranslationTextComponent("tooltip.netherex.dull_mirror.death_point", deathPos.getX() + " " + deathPos.getY() + " " + deathPos.getZ()));
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 9 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class ItemLinkingCard method appendHoverText.

@OnlyIn(Dist.CLIENT)
@Override
public void appendHoverText(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
    CompoundNBT tag = stack.getTag();
    if (tag != null && tag.contains("TYPE")) {
        String type = tag.getString("TYPE");
        int x = tag.getInt("X");
        int y = tag.getInt("Y");
        int z = tag.getInt("Z");
        String worldID = tag.getString("WORLD");
        tooltip.add(new StringTextComponent(String.format("Bound to %s at %s: %d,%d,%d", type, worldID, x, y, z)));
    }
    super.appendHoverText(stack, worldIn, tooltip, flagIn);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) StringTextComponent(net.minecraft.util.text.StringTextComponent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 10 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method getSelectedBlockItemStack.

@Nonnull
public ItemStack getSelectedBlockItemStack(ItemStack multiTool) {
    CompoundNBT tagCompound = multiTool.getTag();
    if (tagCompound == null || !tagCompound.contains("Item")) {
        return ItemStack.EMPTY;
    }
    CompoundNBT itemTag = tagCompound.getCompound("Item");
    return ItemStack.of(itemTag);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Nonnull(javax.annotation.Nonnull)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)127 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)19 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 BlockPos (net.minecraft.util.math.BlockPos)10 ResourceLocation (net.minecraft.util.ResourceLocation)9 BlockState (net.minecraft.block.BlockState)8 TileEntity (net.minecraft.tileentity.TileEntity)7 StringTextComponent (net.minecraft.util.text.StringTextComponent)7 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 DimensionType (net.minecraft.world.dimension.DimensionType)6 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)5 Block (net.minecraft.block.Block)5 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 SUpdateTileEntityPacket (net.minecraft.network.play.server.SUpdateTileEntityPacket)4 LongItemStack (com.cjm721.overloaded.storage.stacks.intint.LongItemStack)3 Nullable (javax.annotation.Nullable)3 IItemProvider (net.minecraft.util.IItemProvider)3