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);
}
}
}
}
}
}
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);
}
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()));
}
}
}
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);
}
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);
}
Aggregations