|
|
|
@ -9,6 +9,7 @@ import net.minecraft.client.item.TooltipContext;
|
|
|
|
|
import net.minecraft.entity.damage.DamageSource;
|
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemGroup;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
|
|
@ -33,7 +34,7 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class TargetedEnderPearlItem extends Item {
|
|
|
|
|
public TargetedEnderPearlItem() {
|
|
|
|
|
super(new Settings().rarity(Rarity.UNCOMMON).maxCount(16));
|
|
|
|
|
super(new Settings().rarity(Rarity.UNCOMMON).group(ItemGroup.MISC).maxCount(16));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -48,7 +49,7 @@ public class TargetedEnderPearlItem extends Item {
|
|
|
|
|
if (!world.isClient()) {
|
|
|
|
|
CompoundTag tag = stack.getTag();
|
|
|
|
|
if (tag == null) {
|
|
|
|
|
tag = new CompoundTag();
|
|
|
|
|
return new TypedActionResult<>(ActionResult.FAIL, stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlockPos target = new BlockPos(tag.getInt("TargetX"), tag.getInt("TargetY"), tag.getInt("TargetZ"));
|
|
|
|
@ -57,29 +58,31 @@ public class TargetedEnderPearlItem extends Item {
|
|
|
|
|
|
|
|
|
|
if (user.dimension != dimension || dimension == null) {
|
|
|
|
|
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_in_different_dimension"));
|
|
|
|
|
return new TypedActionResult<>(ActionResult.FAIL, stack);
|
|
|
|
|
} else if (((TeleportationRestrictorBlock.TeleportingEntity) user).cannotTeleport()) {
|
|
|
|
|
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_restricted"));
|
|
|
|
|
return new TypedActionResult<>(ActionResult.FAIL, stack);
|
|
|
|
|
} else if (world.getBlockState(target).getBlock() != RelicCraft.TELEPORTATION_BEACON_BLOCK || !world.getBlockState(target).get(AbstractDragonEggHolderBlock.ACTIVE)) {
|
|
|
|
|
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".missing_teleportation_beacon"));
|
|
|
|
|
return new TypedActionResult<>(ActionResult.FAIL, stack);
|
|
|
|
|
} else {
|
|
|
|
|
if (((TeleportationRestrictorBlock.TeleportingEntity) user).cannotTeleport()) {
|
|
|
|
|
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_restricted"));
|
|
|
|
|
} else if (world.getBlockState(target).getBlock() != RelicCraft.TELEPORTATION_BEACON_BLOCK || !world.getBlockState(target).get(AbstractDragonEggHolderBlock.ACTIVE)) {
|
|
|
|
|
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".missing_teleportation_beacon"));
|
|
|
|
|
} else {
|
|
|
|
|
Vec3d oldPos = user.getPos();
|
|
|
|
|
if (user.teleport(teleportTarget.getX(), teleportTarget.getY(), teleportTarget.getZ(), true)) {
|
|
|
|
|
world.playSound(null, oldPos.getX(), oldPos.getY(), oldPos.getZ(), SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
|
|
|
|
world.playSound(null, teleportTarget.getX(), teleportTarget.getY(), teleportTarget.getZ(), SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
|
|
|
|
Vec3d oldPos = user.getPos();
|
|
|
|
|
if (user.teleport(teleportTarget.getX(), teleportTarget.getY(), teleportTarget.getZ(), true)) {
|
|
|
|
|
world.playSound(null, oldPos.getX(), oldPos.getY(), oldPos.getZ(), SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
|
|
|
|
world.playSound(null, teleportTarget.getX(), teleportTarget.getY(), teleportTarget.getZ(), SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
RelicCraft.USE_TARGETED_ENDER_PEARL.trigger((ServerPlayerEntity) user);
|
|
|
|
|
RelicCraft.USE_TARGETED_ENDER_PEARL.trigger((ServerPlayerEntity) user);
|
|
|
|
|
|
|
|
|
|
user.damage(DamageSource.FALL, 16.0f);
|
|
|
|
|
user.damage(DamageSource.FALL, 16.0f);
|
|
|
|
|
|
|
|
|
|
user.fallDistance = 0f;
|
|
|
|
|
user.fallDistance = 0f;
|
|
|
|
|
|
|
|
|
|
if (!user.isCreative()) {
|
|
|
|
|
stack.decrement(1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_obstructed"));
|
|
|
|
|
if (!user.isCreative()) {
|
|
|
|
|
stack.decrement(1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_obstructed"));
|
|
|
|
|
return new TypedActionResult<>(ActionResult.FAIL, stack);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -94,8 +97,9 @@ public class TargetedEnderPearlItem extends Item {
|
|
|
|
|
|
|
|
|
|
CompoundTag tag = stack.getTag();
|
|
|
|
|
if (tag == null) {
|
|
|
|
|
tag = new CompoundTag();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tooltip.add(new TranslatableText("item." + RelicCraft.NAMESPACE + ".tooltip.targeted_ender_pearl.x", new LiteralText(String.valueOf(tag.getInt("TargetX"))).formatted(Formatting.GRAY)).formatted(Formatting.WHITE));
|
|
|
|
|
tooltip.add(new TranslatableText("item." + RelicCraft.NAMESPACE + ".tooltip.targeted_ender_pearl.y", new LiteralText(String.valueOf(tag.getInt("TargetY"))).formatted(Formatting.GRAY)).formatted(Formatting.WHITE));
|
|
|
|
|
tooltip.add(new TranslatableText("item." + RelicCraft.NAMESPACE + ".tooltip.targeted_ender_pearl.z", new LiteralText(String.valueOf(tag.getInt("TargetZ"))).formatted(Formatting.GRAY)).formatted(Formatting.WHITE));
|
|
|
|
|