Skip to content

Commit

Permalink
align some ender helmet code parts to 1.15/1.14 code #15
Browse files Browse the repository at this point in the history
  • Loading branch information
cech12 committed Nov 10, 2020
1 parent a0ab5d4 commit 5b24fb5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main/java/cech12/usefulhats/item/EnderHelmetItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public void addInformation(@Nonnull ItemStack stack, @Nullable World worldIn, @N
BlockPos pos = getPosition(stack);
this.addTextLineToTooltip(tooltip, new TranslationTextComponent("item.usefulhats.ender_helmet.desc.teleport").mergeStyle(TextFormatting.BLUE));
this.addTextLineToTooltip(tooltip, new TranslationTextComponent("item.usefulhats.ender_helmet.desc.teleport_position", pos.getX(), pos.getY(), pos.getZ()).mergeStyle(TextFormatting.BLUE));
if (worldIn == null || !isRightDimension(worldIn, stack)) {
this.addTextLineToTooltip(tooltip, new StringTextComponent(getDimensionString(stack)).mergeStyle(TextFormatting.BLUE));
}
this.addTextLineToTooltip(tooltip, new StringTextComponent(getDimensionString(stack)).mergeStyle(TextFormatting.BLUE));
}
}

Expand All @@ -61,7 +59,7 @@ private static void setPosition(@Nonnull ItemStack stack, @Nonnull World world,
positionNBT.putInt("Y", pos.getY());
positionNBT.putInt("Z", pos.getZ());
positionNBT.putString("dimKey", world.func_234923_W_().getRegistryName().toString()); //dimension registry key
positionNBT.putString("dimValue", world.func_234923_W_().func_240901_a_().toString()); //dimension name
positionNBT.putString("dimName", world.func_234923_W_().func_240901_a_().toString()); //dimension name
nbt.put(TELEPORT_POSITION_ID, positionNBT);
stack.setTag(nbt);
}
Expand All @@ -82,14 +80,15 @@ private static BlockPos getPosition(@Nonnull ItemStack stack) {
@OnlyIn(Dist.CLIENT)
private String getDimensionString(@Nonnull ItemStack stack) {
if (hasPosition(stack)) {
return stack.getOrCreateTag().getCompound(TELEPORT_POSITION_ID).getString("dimValue");
return stack.getOrCreateTag().getCompound(TELEPORT_POSITION_ID).getString("dimName");
}
return "?";
}

private static boolean equalsWorldAndNBT(World world, CompoundNBT positionNBT) {
return world.func_234923_W_().getRegistryName().toString().equals(positionNBT.getString("dimKey"))
&& world.func_234923_W_().func_240901_a_().toString().equals(positionNBT.getString("dimValue"));
return (!positionNBT.contains("dimKey") //to be compatible with older versions
|| world.func_234923_W_().getRegistryName().toString().equals(positionNBT.getString("dimKey")))
&& world.func_234923_W_().func_240901_a_().toString().equals(positionNBT.getString("dimName"));
}

private ServerWorld getWorld(@Nonnull MinecraftServer server, @Nonnull ItemStack stack) {
Expand Down

0 comments on commit 5b24fb5

Please sign in to comment.