From 6f6bc6e12803530f4e378897dae491a64d3d38d7 Mon Sep 17 00:00:00 2001 From: Samarium <28302241+Samarium150@users.noreply.github.com> Date: Thu, 29 Jul 2021 18:46:35 +0800 Subject: [PATCH] feat: implement basic functionalities in 1.17.1 --- build.gradle | 8 +- .../structurescompass/command/GetCompass.java | 24 ++--- .../gui/StructureSearchEntry.java | 43 +++++---- .../gui/StructureSearchList.java | 16 ++-- .../gui/StructuresCompassGUI.java | 2 +- .../gui/StructuresCompassHUD.java | 26 +++--- .../gui/StructuresCompassScreen.java | 77 ++++++++-------- .../gui/TransparentButton.java | 17 ++-- .../gui/TransparentTextField.java | 44 +++++---- .../init/ItemPropertyRegistry.java | 10 +-- .../structurescompass/init/ItemRegistry.java | 4 +- .../item/StructuresCompassItem.java | 90 +++++++++---------- ...ava => StructuresCompassItemProperty.java} | 62 ++++++------- .../network/StructuresCompassNetwork.java | 6 +- .../network/packet/CompassSearchPacket.java | 24 ++--- .../CompassSkipExistingChunksPacket.java | 16 ++-- .../network/packet/Packet.java | 8 +- .../network/packet/RequestSyncPacket.java | 20 ++--- .../network/packet/SyncPacket.java | 16 ++-- .../structurescompass/util/ItemUtils.java | 22 ++--- .../structurescompass/util/RenderUtils.java | 27 +++--- .../util/StructureUtils.java | 40 ++++----- .../structurescompass/util/sort/Category.java | 6 +- .../util/sort/DimensionCategory.java | 6 +- .../util/sort/NameCategory.java | 6 +- .../util/sort/SourceCategory.java | 6 +- src/main/resources/META-INF/mods.toml | 2 +- src/main/resources/pack.mcmeta | 2 +- 28 files changed, 314 insertions(+), 316 deletions(-) rename src/main/java/com/github/samarium150/structurescompass/item/{StructuresCompassItemPropertyGetter.java => StructuresCompassItemProperty.java} (60%) diff --git a/build.gradle b/build.gradle index 99f10a1..fa864f5 100644 --- a/build.gradle +++ b/build.gradle @@ -18,12 +18,12 @@ apply plugin: 'net.minecraftforge.gradle' def previousVersion = '1.2.0' def baseVersion = '1.2.1' -def minecraftVersion = '1.16.5' +def minecraftVersion = '1.17.1' version = "${minecraftVersion}-${baseVersion}" as Object group = 'com.github.samarium150' archivesBaseName = 'structurescompass' -java.toolchain.languageVersion = JavaLanguageVersion.of(8) +java.toolchain.languageVersion = JavaLanguageVersion.of(16) logger.quiet('Java: {} JVM: {}({}) Arch: {}', System.getProperty('java.version'), @@ -42,7 +42,7 @@ sourceSets { def mainSourceSet = sourceSets.main minecraft { - mappings channel: 'official', version: '1.16.5' + mappings channel: 'official', version: minecraftVersion // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') runs { @@ -73,7 +73,7 @@ minecraft { // sourceSets.main.resources { srcDir 'src/generated/resources' } dependencies { - minecraft 'net.minecraftforge:forge:1.16.5-36.2.2' + minecraft 'net.minecraftforge:forge:1.17.1-37.0.13' } compileJava { diff --git a/src/main/java/com/github/samarium150/structurescompass/command/GetCompass.java b/src/main/java/com/github/samarium150/structurescompass/command/GetCompass.java index 20f1832..80449dd 100644 --- a/src/main/java/com/github/samarium150/structurescompass/command/GetCompass.java +++ b/src/main/java/com/github/samarium150/structurescompass/command/GetCompass.java @@ -6,13 +6,13 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.registries.ForgeRegistries; import javax.annotation.Nonnull; @@ -28,13 +28,13 @@ public final class GetCompass { private GetCompass() { } - private static int getTaggedCompass(@Nonnull CommandSource source, String feature) throws CommandSyntaxException { + private static int getTaggedCompass(@Nonnull CommandSourceStack source, String feature) throws CommandSyntaxException { ItemStack structures_compass = new ItemStack(ItemRegistry.STRUCTURES_COMPASS.get()); giveItem(source.getPlayerOrException(), StructuresCompassItem.setStructureName(feature, structures_compass)); return Command.SINGLE_SUCCESS; } - private static void giveItem(@Nonnull ServerPlayerEntity player, ItemStack structures_compass) { + private static void giveItem(@Nonnull ServerPlayer player, ItemStack structures_compass) { ItemEntity itemEntity = player.drop(structures_compass, false); if (itemEntity != null) { itemEntity.setNoPickUpDelay(); @@ -46,11 +46,11 @@ private static void giveItem(@Nonnull ServerPlayerEntity player, ItemStack struc * Register this command * @param dispatcher CommandDispatcher */ - public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder structures_compass = Commands.literal("structures_compass") + public static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder structures_compass = Commands.literal("structures_compass") .requires((commandSource) -> commandSource.hasPermission(2)); - for (Structure structureFeature : ForgeRegistries.STRUCTURE_FEATURES) { + for (StructureFeature structureFeature : ForgeRegistries.STRUCTURE_FEATURES) { ResourceLocation res = structureFeature.getRegistryName(); if (res == null) continue; String structure = res.toString(); diff --git a/src/main/java/com/github/samarium150/structurescompass/gui/StructureSearchEntry.java b/src/main/java/com/github/samarium150/structurescompass/gui/StructureSearchEntry.java index 1534d5c..8f5ed1e 100644 --- a/src/main/java/com/github/samarium150/structurescompass/gui/StructureSearchEntry.java +++ b/src/main/java/com/github/samarium150/structurescompass/gui/StructureSearchEntry.java @@ -1,16 +1,17 @@ package com.github.samarium150.structurescompass.gui; import com.github.samarium150.structurescompass.util.StructureUtils; -import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.Util; import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.SimpleSound; -import net.minecraft.client.gui.widget.list.ExtendedList.AbstractListEntry; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.Util; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.client.gui.components.ObjectSelectionList.Entry; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -27,15 +28,15 @@ * . */ @OnlyIn(Dist.CLIENT) -public final class StructureSearchEntry extends AbstractListEntry { +public final class StructureSearchEntry extends Entry { private final Minecraft minecraft; private final StructureSearchList list; - private final Structure structure; + private final StructureFeature structure; private final StructuresCompassScreen screen; private long lastTickTime; - public StructureSearchEntry(@Nonnull StructureSearchList list, Structure structure) { + public StructureSearchEntry(@Nonnull StructureSearchList list, StructureFeature structure) { minecraft = Minecraft.getInstance(); this.list = list; this.structure = structure; @@ -43,18 +44,17 @@ public StructureSearchEntry(@Nonnull StructureSearchList list, Structure stru } public void search() { - minecraft.getSoundManager().play(SimpleSound.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); screen.search(structure); } - public Structure getStructure() { + public StructureFeature getStructure() { return structure; } - @SuppressWarnings("deprecation") @Override public void render( - @Nonnull MatrixStack matrixStack, + @Nonnull PoseStack matrixStack, int index, int top, int left, int width, int height, int mouseX, int mouseY, boolean isMouseOver, float partialTicks ) { @@ -63,16 +63,16 @@ public void render( left + 1, top + 1, 0xffffff ); minecraft.font.draw(matrixStack, - new StringTextComponent(I18n.get("string.structurescompass.source") + ": " + new TextComponent(I18n.get("string.structurescompass.source") + ": " + StructureUtils.getStructureSource(structure)), left + 1, top + minecraft.font.lineHeight + 3, 0x808080 ); minecraft.font.draw(matrixStack, - new StringTextComponent(I18n.get("string.structurescompass.dimension") + ": " + new TextComponent(I18n.get("string.structurescompass.dimension") + ": " + StructureUtils.getDimensions(structure)), left + 1, top + minecraft.font.lineHeight + 14, 0x808080 ); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } @Override @@ -87,4 +87,11 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } return false; } + + @Nonnull + @Override + public Component getNarration() { + return new TextComponent(I18n.get("string.structurescompass.source") + ": " + + StructureUtils.getStructureSource(structure)); + } } diff --git a/src/main/java/com/github/samarium150/structurescompass/gui/StructureSearchList.java b/src/main/java/com/github/samarium150/structurescompass/gui/StructureSearchList.java index 4c973fa..012e59f 100644 --- a/src/main/java/com/github/samarium150/structurescompass/gui/StructureSearchList.java +++ b/src/main/java/com/github/samarium150/structurescompass/gui/StructureSearchList.java @@ -2,10 +2,10 @@ import com.github.samarium150.structurescompass.util.RenderUtils; import com.github.samarium150.structurescompass.util.StructureUtils; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.widget.list.ExtendedList; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.client.gui.components.ObjectSelectionList; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -24,7 +24,7 @@ * . */ @OnlyIn(Dist.CLIENT) -public final class StructureSearchList extends ExtendedList { +public final class StructureSearchList extends ObjectSelectionList { private final StructuresCompassScreen screen; private final HashMap map = new HashMap<>(); @@ -45,13 +45,13 @@ public void selectStructure(StructureSearchEntry entry) { screen.selectStructure(entry); } - public void selectStructure(Structure structure) { + public void selectStructure(StructureFeature structure) { selectStructure(map.get(StructureUtils.getStructureName(structure))); } public void refresh() { clearEntries(); - for (Structure structure : screen.sortStructures()) { + for (StructureFeature structure : screen.sortStructures()) { StructureSearchEntry entry = new StructureSearchEntry(this, structure); addEntry(entry); map.put(StructureUtils.getStructureName(structure), entry); @@ -84,7 +84,7 @@ protected boolean isSelectedItem(int index) { } @Override - protected void renderList(@Nonnull MatrixStack matrixStack, int x, int y, int mouseX, int mouseY, float partialTicks) { + protected void renderList(@Nonnull PoseStack matrixStack, int x, int y, int mouseX, int mouseY, float partialTicks) { for (int i = 0; i < getItemCount(); ++i) { int top = getRowTop(i); int bottom = top + itemHeight; @@ -107,7 +107,7 @@ protected void renderList(@Nonnull MatrixStack matrixStack, int x, int y, int mo } @Override - public void render(@Nonnull MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public void render(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { renderList(matrixStack, getRowLeft(), y0 + 4 - (int) getScrollAmount(), mouseX, mouseY, partialTicks); } } diff --git a/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassGUI.java b/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassGUI.java index 64e18d9..dacea0a 100644 --- a/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassGUI.java +++ b/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassGUI.java @@ -1,7 +1,7 @@ package com.github.samarium150.structurescompass.gui; import net.minecraft.client.Minecraft; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassHUD.java b/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassHUD.java index 3421d59..406e500 100644 --- a/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassHUD.java +++ b/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassHUD.java @@ -5,30 +5,30 @@ import com.github.samarium150.structurescompass.item.StructuresCompassItem; import com.github.samarium150.structurescompass.util.RenderUtils; import com.github.samarium150.structurescompass.util.StructureUtils; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.AbstractGui; -import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.screens.ChatScreen; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; /** * The HUD of the compass */ -public final class StructuresCompassHUD extends AbstractGui { +public final class StructuresCompassHUD extends GuiComponent { private static final Minecraft minecraft = Minecraft.getInstance(); - private final MatrixStack matrixStack; + private final PoseStack matrixStack; /** * Initializer of the HUD * @param matrixStack MatrixStack from RenderGameOverlayEvent * @see net.minecraftforge.client.event.RenderGameOverlayEvent */ - public StructuresCompassHUD(MatrixStack matrixStack) { + public StructuresCompassHUD(PoseStack matrixStack) { this.matrixStack = matrixStack; } @@ -47,7 +47,7 @@ public void render() { if (StructuresCompassConfig.HUD_Level.get() != 0 && (minecraft.screen == null || (StructuresCompassConfig.displayWithChatOpen.get() && minecraft.screen instanceof ChatScreen))) { - final PlayerEntity player = minecraft.player; + final Player player = minecraft.player; final ItemStack stack; assert player != null; if (!player.getMainHandItem().isEmpty() @@ -98,7 +98,7 @@ else if (!player.getOffhandItem().isEmpty() if (player.getCommandSenderWorld().dimension().location().toString().equals(dim)) { - Vector3d dis = StructureUtils.getDistance(pos, player); + Vec3 dis = StructureUtils.getDistance(pos, player); double disX = dis.x(); double disY = dis.y(); double disZ = dis.z(); diff --git a/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassScreen.java b/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassScreen.java index 5e1517c..cc1abcc 100644 --- a/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassScreen.java +++ b/src/main/java/com/github/samarium150/structurescompass/gui/StructuresCompassScreen.java @@ -7,16 +7,16 @@ import com.github.samarium150.structurescompass.util.StructureUtils; import com.github.samarium150.structurescompass.util.sort.Category; import com.github.samarium150.structurescompass.util.sort.NameCategory; -import com.mojang.blaze3d.matrix.MatrixStack; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.client.resources.I18n; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.gen.feature.structure.Structure; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.item.ItemStack; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -37,20 +37,20 @@ @OnlyIn(Dist.CLIENT) public final class StructuresCompassScreen extends Screen { - private final List> allowedStructures = StructureUtils.allowedStructures; + private final List> allowedStructures = StructureUtils.allowedStructures; private final ItemStack stack; - private List> structuresMatchingSearch; + private List> structuresMatchingSearch; private StructureSearchList selectionList; private Category category; private Button startSearchButton; private Button sortByButton; private Button skipExistingChunksButton; - private TextFieldWidget searchTextField; + private EditBox searchTextField; private boolean skip; - private Structure selected; + private StructureFeature selected; public StructuresCompassScreen(@Nonnull ItemStack stack) { - super(new TranslationTextComponent("string.structurescompass.select_structure")); + super(new TranslatableComponent("string.structurescompass.select_structure")); this.stack = stack; structuresMatchingSearch = new ArrayList<>(allowedStructures); category = new NameCategory(); @@ -58,55 +58,54 @@ public StructuresCompassScreen(@Nonnull ItemStack stack) { } private void setup() { - buttons.clear(); - startSearchButton = addButton(new TransparentButton( + renderables.clear(); + startSearchButton = addRenderableWidget(new TransparentButton( 10, 40, 110, 20, - new TranslationTextComponent("string.structurescompass.start_searching"), + new TranslatableComponent("string.structurescompass.start_searching"), (onPress) -> { StructureSearchEntry entry = selectionList.getSelected(); if (entry != null) entry.search(); } )); - sortByButton = addButton(new TransparentButton( + sortByButton = addRenderableWidget(new TransparentButton( 10, 65, 110, 20, - new StringTextComponent( + new TextComponent( I18n.get("string.structurescompass.sort_by") + ": " + category.getLocalizedName() ), (onPress) -> { category = category.next(); - sortByButton.setMessage(new StringTextComponent( + sortByButton.setMessage(new TextComponent( I18n.get("string.structurescompass.sort_by") + ": " + category.getLocalizedName()) ); selectionList.refresh(); restoreSelected(); } )); - skipExistingChunksButton = addButton(new TransparentButton( + skipExistingChunksButton = addRenderableWidget(new TransparentButton( 10, 90, 110, 20, - new StringTextComponent( + new TextComponent( I18n.get("string.structurescompass.skip_existing_chunks") + ": " + skip ), (onPress) -> { skip = !skip; - skipExistingChunksButton.setMessage(new StringTextComponent( + skipExistingChunksButton.setMessage(new TextComponent( I18n.get("string.structurescompass.skip_existing_chunks") + ": " + skip) ); } )); - addButton(new TransparentButton( + addRenderableWidget(new TransparentButton( 10, height - 30, 110, 20, - new TranslationTextComponent("gui.cancel"), + new TranslatableComponent("gui.cancel"), (onPress) -> { assert minecraft != null; minecraft.setScreen(null); } )); - searchTextField = new TransparentTextField( + searchTextField = addWidget(new TransparentTextField( font, 130, 10, 140, 20, - new TranslationTextComponent("string.structurescompass.search") - ); - children.add(searchTextField); + new TranslatableComponent("string.structurescompass.search") + )); } public void selectStructure(StructureSearchEntry entry) { @@ -114,14 +113,14 @@ public void selectStructure(StructureSearchEntry entry) { if (entry != null) selected = entry.getStructure(); } - public List> sortStructures() { - final List> structures = structuresMatchingSearch; + public List> sortStructures() { + final List> structures = structuresMatchingSearch; structures.sort(new NameCategory()); structures.sort(category); return structuresMatchingSearch; } - public void search(@Nonnull Structure structure) { + public void search(@Nonnull StructureFeature structure) { assert minecraft != null; StructuresCompassNetwork.channel.sendToServer(new CompassSkipExistingChunksPacket(skip)); StructuresCompassNetwork.channel.sendToServer(new CompassSearchPacket(structure.getRegistryName())); @@ -130,19 +129,19 @@ public void search(@Nonnull Structure structure) { public void processSearchTerm() { structuresMatchingSearch = new ArrayList<>(); - for (Structure structure : allowedStructures) { + for (StructureFeature structure : allowedStructures) { String temp = ""; if (!searchTextField.getValue().isEmpty() && searchTextField.getValue().charAt(0) == '#') temp = StructureUtils.getDimensions(structure); if ((!searchTextField.getValue().isEmpty() && - //source search + // source search (searchTextField.getValue().charAt(0) == '@' && StructureUtils.getStructureSource(structure).toLowerCase() .contains(searchTextField.getValue().substring(1).toLowerCase())) || - //dim search + // dim search (!temp.isEmpty() && temp.toLowerCase() .contains(searchTextField.getValue().substring(1).toLowerCase()))) || - //normal search + // normal search (StructureUtils.getLocalizedStructureName(structure).toLowerCase() .contains(searchTextField.getValue().toLowerCase()))) { structuresMatchingSearch.add(structure); @@ -173,7 +172,7 @@ protected void init() { selectionList.changeFocus(true); selectionList.restoreScrollAmount(); } - children.add(selectionList); + addWidget(selectionList); } @Override @@ -182,7 +181,7 @@ public void tick() { } @Override - public void render(@Nonnull MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public void render(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { renderBackground(matrixStack); selectionList.render(matrixStack, mouseX, mouseY, partialTicks); searchTextField.render(matrixStack, mouseX, mouseY, partialTicks); diff --git a/src/main/java/com/github/samarium150/structurescompass/gui/TransparentButton.java b/src/main/java/com/github/samarium150/structurescompass/gui/TransparentButton.java index e5f9116..1c901c8 100644 --- a/src/main/java/com/github/samarium150/structurescompass/gui/TransparentButton.java +++ b/src/main/java/com/github/samarium150/structurescompass/gui/TransparentButton.java @@ -1,11 +1,11 @@ package com.github.samarium150.structurescompass.gui; import com.github.samarium150.structurescompass.util.RenderUtils; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.components.Button; +import net.minecraft.network.chat.Component; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -24,7 +24,7 @@ @OnlyIn(Dist.CLIENT) public class TransparentButton extends Button { - public TransparentButton(int x, int y, int width, int height, ITextComponent title, IPressable pressedAction) { + public TransparentButton(int x, int y, int width, int height, Component title, OnPress pressedAction) { super(x, y, width, height, title, pressedAction); } @@ -33,17 +33,16 @@ protected int getHoverState(boolean mouseOver) { } /** - * "Override" static method in AbstractGui to draw centered string without shadow + * draw centered string without shadow * @param matrixStack MatrixStack * @param fontRenderer FontRenderer * @param text ITextComponent * @param x x position * @param y y position * @param color color of the text - * @see net.minecraft.client.gui.AbstractGui#drawCenteredString */ public static void drawCenteredString( - @Nonnull MatrixStack matrixStack, @Nonnull FontRenderer fontRenderer, @Nonnull ITextComponent text, + @Nonnull PoseStack matrixStack, @Nonnull Font fontRenderer, @Nonnull Component text, int x, int y, int color ) { fontRenderer.draw( @@ -53,7 +52,7 @@ public static void drawCenteredString( } @Override - public void render(@Nonnull MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public void render(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { if (visible) { Minecraft minecraft = Minecraft.getInstance(); float state = getHoverState(isHovered()); diff --git a/src/main/java/com/github/samarium150/structurescompass/gui/TransparentTextField.java b/src/main/java/com/github/samarium150/structurescompass/gui/TransparentTextField.java index d3bba32..d38302e 100644 --- a/src/main/java/com/github/samarium150/structurescompass/gui/TransparentTextField.java +++ b/src/main/java/com/github/samarium150/structurescompass/gui/TransparentTextField.java @@ -2,15 +2,15 @@ import com.github.samarium150.structurescompass.util.GeneralUtils; import com.github.samarium150.structurescompass.util.RenderUtils; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.components.EditBox; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.Tesselator; +import net.minecraft.util.Mth; +import net.minecraft.network.chat.Component; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -27,10 +27,10 @@ * . */ @OnlyIn(Dist.CLIENT) -public class TransparentTextField extends TextFieldWidget { +public class TransparentTextField extends EditBox { - private final FontRenderer fontRenderer; - private ITextComponent label; + private final Font fontRenderer; + private Component label; private int labelColor = 0x808080; private boolean pseudoIsEnabled = true; @@ -42,14 +42,14 @@ public class TransparentTextField extends TextFieldWidget { private int pseudoCursorCounter; private int pseudoSelectionEnd; - public TransparentTextField(FontRenderer fontRenderer, int x, int y, int width, int height, ITextComponent label) { + public TransparentTextField(Font fontRenderer, int x, int y, int width, int height, Component label) { super(fontRenderer, x, y, width, height, label); this.fontRenderer = fontRenderer; this.label = label; } @Override - public void render(@Nonnull MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public void render(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { if (isVisible()) { if (pseudoEnableBackgroundDrawing) { final int color = (int) (255.0F * 1.7F); @@ -153,7 +153,7 @@ public void tick() { public void setHighlightPos(int position) { super.setHighlightPos(position); int i = getValue().length(); - pseudoSelectionEnd = MathHelper.clamp(position, 0, i); + pseudoSelectionEnd = Mth.clamp(position, 0, i); if (fontRenderer != null) { if (pseudoLineScrollOffset > i) { pseudoLineScrollOffset = i; @@ -172,19 +172,18 @@ public void setHighlightPos(int position) { pseudoLineScrollOffset -= pseudoLineScrollOffset - pseudoSelectionEnd; } - pseudoLineScrollOffset = MathHelper.clamp(pseudoLineScrollOffset, 0, i); + pseudoLineScrollOffset = Mth.clamp(pseudoLineScrollOffset, 0, i); } } - public void setLabel(ITextComponent label) { + public void setLabel(Component label) { this.label = label; } public void setLabelColor(int labelColor) { this.labelColor = labelColor; } - - @SuppressWarnings("deprecation") + private void drawSelectionBox(int startX, int startY, int endX, int endY) { if (startX < endX) startX = GeneralUtils.swap(endX, endX = startX); @@ -194,17 +193,16 @@ private void drawSelectionBox(int startX, int startY, int endX, int endY) { endX = x + width; if (startX > x + width) startX = x + width; - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuilder(); - - // Annotated as deprecated but no replacement - RenderSystem.color4f(0.0F, 0.0F, 255.0F, 255.0F); + Tesselator tesselator = Tesselator.getInstance(); + BufferBuilder buffer = tesselator.getBuilder(); + + RenderSystem.setShaderColor(0.0F, 0.0F, 255.0F, 255.0F); RenderSystem.disableTexture(); RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); RenderUtils.updateBuffer(buffer, startX, startY, endX, endY); - tessellator.end(); + tesselator.end(); RenderSystem.disableColorLogicOp(); RenderSystem.enableTexture(); } diff --git a/src/main/java/com/github/samarium150/structurescompass/init/ItemPropertyRegistry.java b/src/main/java/com/github/samarium150/structurescompass/init/ItemPropertyRegistry.java index b0b01c6..3b93888 100644 --- a/src/main/java/com/github/samarium150/structurescompass/init/ItemPropertyRegistry.java +++ b/src/main/java/com/github/samarium150/structurescompass/init/ItemPropertyRegistry.java @@ -1,8 +1,8 @@ package com.github.samarium150.structurescompass.init; -import com.github.samarium150.structurescompass.item.StructuresCompassItemPropertyGetter; -import net.minecraft.item.ItemModelsProperties; -import net.minecraft.util.ResourceLocation; +import com.github.samarium150.structurescompass.item.StructuresCompassItemProperty; +import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -24,10 +24,10 @@ private ItemPropertyRegistry() { } */ @SubscribeEvent public static void register(@Nonnull final FMLClientSetupEvent event) { - event.enqueueWork(() -> ItemModelsProperties.register( + event.enqueueWork(() -> ItemProperties.register( ItemRegistry.STRUCTURES_COMPASS.get(), new ResourceLocation("angle"), - new StructuresCompassItemPropertyGetter() + new StructuresCompassItemProperty() )); } } diff --git a/src/main/java/com/github/samarium150/structurescompass/init/ItemRegistry.java b/src/main/java/com/github/samarium150/structurescompass/init/ItemRegistry.java index 70d071c..c2afd16 100644 --- a/src/main/java/com/github/samarium150/structurescompass/init/ItemRegistry.java +++ b/src/main/java/com/github/samarium150/structurescompass/init/ItemRegistry.java @@ -2,8 +2,8 @@ import com.github.samarium150.structurescompass.item.StructuresCompassItem; import com.github.samarium150.structurescompass.util.GeneralUtils; -import net.minecraft.item.Item; -import net.minecraftforge.fml.RegistryObject; +import net.minecraft.world.item.Item; +import net.minecraftforge.fmllegacy.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; diff --git a/src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItem.java b/src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItem.java index 609ee32..503b9c6 100644 --- a/src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItem.java +++ b/src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItem.java @@ -6,26 +6,26 @@ import com.github.samarium150.structurescompass.network.packet.RequestSyncPacket; import com.github.samarium150.structurescompass.util.ItemUtils; import com.github.samarium150.structurescompass.util.StructureUtils; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Rarity; -import net.minecraft.nbt.ByteNBT; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.LongNBT; -import net.minecraft.nbt.StringNBT; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.World; -import net.minecraft.world.gen.feature.structure.Structure; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Rarity; +import net.minecraft.nbt.ByteTag; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.LongTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.InteractionHand; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.server.level.ServerLevel; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.util.Constants; @@ -48,7 +48,7 @@ public final class StructuresCompassItem extends Item { * Initializer of the item */ public StructuresCompassItem() { - super(new Item.Properties().tab(ItemGroup.TAB_TOOLS).stacksTo(1).rarity(Rarity.COMMON)); + super(new Item.Properties().tab(CreativeModeTab.TAB_TOOLS).stacksTo(1).rarity(Rarity.COMMON)); } /** @@ -59,9 +59,9 @@ public StructuresCompassItem() { */ @Nonnull public static ItemStack setStructureName(String name, @Nonnull ItemStack stack) { - CompoundNBT tag = ItemUtils.getOrCreateItemTag(stack); + CompoundTag tag = ItemUtils.getOrCreateItemTag(stack); if (tag != null) { - tag.put(STRUCTURE_TAG, StringNBT.valueOf(name)); + tag.put(STRUCTURE_TAG, StringTag.valueOf(name)); stack.setTag(tag); } return stack; @@ -74,7 +74,7 @@ public static ItemStack setStructureName(String name, @Nonnull ItemStack stack) */ @Nullable public static String getStructureName(@Nonnull ItemStack stack) { - CompoundNBT tag = ItemUtils.getItemTag(stack); + CompoundTag tag = ItemUtils.getItemTag(stack); return (tag != null) ? tag.getString(STRUCTURE_TAG) : null; } @@ -84,9 +84,9 @@ public static String getStructureName(@Nonnull ItemStack stack) { * @param stack ItemStack */ public static void setPos(BlockPos pos, @Nonnull ItemStack stack) { - CompoundNBT tag = ItemUtils.getOrCreateItemTag(stack); + CompoundTag tag = ItemUtils.getOrCreateItemTag(stack); if (tag != null) { - tag.put(POS_TAG, LongNBT.valueOf(pos.asLong())); + tag.put(POS_TAG, LongTag.valueOf(pos.asLong())); stack.setTag(tag); } } @@ -98,7 +98,7 @@ public static void setPos(BlockPos pos, @Nonnull ItemStack stack) { */ @Nullable public static BlockPos getPos(@Nonnull ItemStack stack) { - CompoundNBT tag = ItemUtils.getItemTag(stack); + CompoundTag tag = ItemUtils.getItemTag(stack); return (tag != null && tag.contains(POS_TAG, Constants.NBT.TAG_LONG)) ? BlockPos.of(tag.getLong(POS_TAG)) : null; } @@ -109,9 +109,9 @@ public static BlockPos getPos(@Nonnull ItemStack stack) { * @param stack ItemStack */ public static void setDimension(String dimension, @Nonnull ItemStack stack) { - CompoundNBT tag = ItemUtils.getOrCreateItemTag(stack); + CompoundTag tag = ItemUtils.getOrCreateItemTag(stack); if (tag != null) { - tag.put(DIM_TAG, StringNBT.valueOf(dimension)); + tag.put(DIM_TAG, StringTag.valueOf(dimension)); stack.setTag(tag); } } @@ -123,7 +123,7 @@ public static void setDimension(String dimension, @Nonnull ItemStack stack) { */ @Nullable public static String getDimension(@Nonnull ItemStack stack) { - CompoundNBT tag = ItemUtils.getItemTag(stack); + CompoundTag tag = ItemUtils.getItemTag(stack); return (tag != null) ? tag.getString(DIM_TAG) : null; } @@ -133,13 +133,13 @@ public static String getDimension(@Nonnull ItemStack stack) { * @param stack ItemStack */ public static void setSkip(Boolean skip, @Nonnull ItemStack stack) { - CompoundNBT tag = ItemUtils.getOrCreateItemTag(stack); + CompoundTag tag = ItemUtils.getOrCreateItemTag(stack); if (tag != null) { if (!skip) { ItemUtils.removeTag(stack, SKIP_TAG); return; } - tag.put(SKIP_TAG, ByteNBT.valueOf(true)); + tag.put(SKIP_TAG, ByteTag.valueOf(true)); stack.setTag(tag); } } @@ -150,7 +150,7 @@ public static void setSkip(Boolean skip, @Nonnull ItemStack stack) { * @return SkipExistingChunks property */ public static boolean isSkip(@Nonnull ItemStack stack) { - CompoundNBT tag = ItemUtils.getItemTag(stack); + CompoundTag tag = ItemUtils.getItemTag(stack); return tag != null && tag.getBoolean(SKIP_TAG); } @@ -160,9 +160,9 @@ public static boolean isSkip(@Nonnull ItemStack stack) { * @param player PlayerEntity * @param structure Structure * @param stack ItemStack - * @see ServerWorld#findNearestMapFeature + * @see ServerLevel#findNearestMapFeature */ - public static void search(@Nonnull ServerWorld world, PlayerEntity player, @Nonnull Structure structure, ItemStack stack) { + public static void search(@Nonnull ServerLevel world, Player player, @Nonnull StructureFeature structure, ItemStack stack) { ResourceLocation registry = structure.getRegistryName(); assert registry != null; setStructureName(registry.toString(), stack); @@ -175,7 +175,7 @@ public static void search(@Nonnull ServerWorld world, PlayerEntity player, @Nonn ItemUtils.removeTag(stack, DIM_TAG); ItemUtils.removeTag(stack, POS_TAG); } else { - Vector3d dis = StructureUtils.getDistance(pos, player); + Vec3 dis = StructureUtils.getDistance(pos, player); double distance = (double) Math.round(dis.length() * 100) / 100; if (distance > StructuresCompassConfig.maxDistance.get()) { ItemUtils.removeTag(stack, DIM_TAG); @@ -188,12 +188,12 @@ public static void search(@Nonnull ServerWorld world, PlayerEntity player, @Nonn } @OnlyIn(Dist.CLIENT) - private static void sendMessage(String msg, @Nonnull PlayerEntity entity) { - entity.sendMessage(new StringTextComponent(msg), entity.getUUID()); + private static void sendMessage(String msg, @Nonnull Player entity) { + entity.sendMessage(new TextComponent(msg), entity.getUUID()); } - private static void sendTranslatedMessage(String translationKey, @Nonnull PlayerEntity entity) { - entity.sendMessage(new TranslationTextComponent(translationKey), entity.getUUID()); + private static void sendTranslatedMessage(String translationKey, @Nonnull Player entity) { + entity.sendMessage(new TranslatableComponent(translationKey), entity.getUUID()); } /** @@ -210,10 +210,10 @@ private static void sendTranslatedMessage(String translationKey, @Nonnull Player */ @Override @Nonnull - public ActionResult use( - @Nonnull World world, - @Nonnull PlayerEntity player, - @Nonnull Hand hand + public InteractionResultHolder use( + @Nonnull Level world, + @Nonnull Player player, + @Nonnull InteractionHand hand ) { ItemStack stack = player.getMainHandItem(); if (world.isClientSide) @@ -225,7 +225,7 @@ public ActionResult use( sendMessage(I18n.get("string.structurescompass.msg_no_target"), player); return super.use(world, player, hand); } - Structure structure = Structure.STRUCTURES_REGISTRY.get(name.replace("minecraft:", "")); + StructureFeature structure = StructureFeature.STRUCTURES_REGISTRY.get(name.replace("minecraft:", "")); if (structure == null) { sendMessage(I18n.get("string.structurescompass.msg_error_name") + name, player); return super.use(world, player, hand); diff --git a/src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItemPropertyGetter.java b/src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItemProperty.java similarity index 60% rename from src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItemPropertyGetter.java rename to src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItemProperty.java index 5ad4282..926dfa3 100644 --- a/src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItemPropertyGetter.java +++ b/src/main/java/com/github/samarium150/structurescompass/item/StructuresCompassItemProperty.java @@ -1,17 +1,17 @@ package com.github.samarium150.structurescompass.item; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.item.ItemFrameEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.IItemPropertyGetter; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.decoration.ItemFrame; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -20,10 +20,10 @@ /** * Class for setting the property of the compass' model - * @see net.minecraft.item.ItemModelsProperties + * @see net.minecraft.client.renderer.item.ItemProperties */ @OnlyIn(Dist.CLIENT) -public final class StructuresCompassItemPropertyGetter implements IItemPropertyGetter { +public final class StructuresCompassItemProperty implements ClampedItemPropertyFunction { private static class Angle { @@ -37,14 +37,14 @@ private boolean isOutdated(long lastUpdateTick) { return this.lastUpdateTick != lastUpdateTick; } - private double wobble(ClientWorld world, double amount) { + private double wobble(ClientLevel world, double amount) { if (world != null && isOutdated(world.getGameTime())) { lastUpdateTick = world.getGameTime(); double d0 = amount - rotation; - d0 = MathHelper.positiveModulo(d0 + 0.5D, 1.0D) - 0.5D; + d0 = Mth.positiveModulo(d0 + 0.5D, 1.0D) - 0.5D; delta += d0 * 0.1D; delta *= 0.8D; - rotation = MathHelper.positiveModulo(rotation + delta, 1.0D); + rotation = Mth.positiveModulo(rotation + delta, 1.0D); } return rotation; } @@ -53,10 +53,10 @@ private double wobble(ClientWorld world, double amount) { private final Angle r1 = new Angle(); private final Angle r2 = new Angle(); - private double getFrameRotation(@Nonnull ItemFrameEntity frameEntity) { + private double getFrameRotation(@Nonnull ItemFrame frameEntity) { Direction direction = frameEntity.getDirection(); int i = direction.getAxis().isVertical() ? 90 * direction.getAxisDirection().getStep() : 0; - return MathHelper.wrapDegrees(180 + direction.get2DDataValue() * 90 + frameEntity.getRotation() * 45 + i); + return Mth.wrapDegrees(180 + direction.get2DDataValue() * 90 + frameEntity.getRotation() * 45 + i); } private static boolean closeEnough(@Nonnull Entity entity, @Nonnull BlockPos pos) { @@ -67,7 +67,7 @@ private static boolean closeEnough(@Nonnull Entity entity, @Nonnull BlockPos pos ) < (double)1.0E-5F; } - private static double getAngle(@Nonnull Vector3d vector, @Nonnull Entity entity) { + private static double getAngle(@Nonnull Vec3 vector, @Nonnull Entity entity) { return Math.atan2(vector.z() - entity.getZ(), vector.x() - entity.getX()); } @@ -82,34 +82,34 @@ private static double getAngle(@Nonnull Vector3d vector, @Nonnull Entity entity) * @return the angle of the needle */ @Override - public float call(@Nonnull ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity livingEntity) { + public float unclampedCall(@Nonnull ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity livingEntity, int p) { Entity entity = livingEntity != null ? livingEntity : stack.getEntityRepresentation(); if (entity == null) return 0F; - if (world == null && entity.level instanceof ClientWorld) - world = (ClientWorld) entity.level; + if (world == null && entity.level instanceof ClientLevel) + world = (ClientLevel) entity.level; if (world == null) return 0F; BlockPos pos = StructuresCompassItem.getPos(stack); if (pos != null && world.dimension().location().toString().equals(StructuresCompassItem.getDimension(stack)) && !closeEnough(entity, pos)) { - boolean flag = entity instanceof PlayerEntity && ((PlayerEntity)entity).isLocalPlayer(); + boolean flag = entity instanceof Player && ((Player)entity).isLocalPlayer(); double d1 = 0.0D; if (flag) { - d1 = entity.yRot; - } else if (entity instanceof ItemFrameEntity) { - d1 = this.getFrameRotation((ItemFrameEntity)entity); + d1 = entity.getYRot(); + } else if (entity instanceof ItemFrame) { + d1 = this.getFrameRotation((ItemFrame)entity); } else if (entity instanceof ItemEntity) { d1 = (180.0F - ((ItemEntity)entity).getSpin(0.5F) / ((float)Math.PI * 2F) * 360.0F); } else if (livingEntity != null) { d1 = livingEntity.yBodyRot; } - d1 = MathHelper.positiveModulo(d1 / 360.0D, 1.0D); - double d2 = getAngle(Vector3d.atCenterOf(pos), entity) / (double)((float)Math.PI * 2F); + d1 = Mth.positiveModulo(d1 / 360.0D, 1.0D); + double d2 = getAngle(Vec3.atCenterOf(pos), entity) / (double)((float)Math.PI * 2F); double d3 = (flag) ? d2 + r1.wobble(world, 0.5D - (d1 - 0.25D)) : 0.5D - (d1 - 0.25D - d2); - return MathHelper.positiveModulo((float)d3, 1.0F); + return Mth.positiveModulo((float)d3, 1.0F); } - return MathHelper.positiveModulo( + return Mth.positiveModulo( (float)(r2.wobble(world, Math.random()) + (double)((float)stack.hashCode() / 2.14748365E9F)), 1.0F ); diff --git a/src/main/java/com/github/samarium150/structurescompass/network/StructuresCompassNetwork.java b/src/main/java/com/github/samarium150/structurescompass/network/StructuresCompassNetwork.java index fcaa262..6b9e214 100644 --- a/src/main/java/com/github/samarium150/structurescompass/network/StructuresCompassNetwork.java +++ b/src/main/java/com/github/samarium150/structurescompass/network/StructuresCompassNetwork.java @@ -5,9 +5,9 @@ import com.github.samarium150.structurescompass.network.packet.RequestSyncPacket; import com.github.samarium150.structurescompass.network.packet.SyncPacket; import com.github.samarium150.structurescompass.util.GeneralUtils; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.network.NetworkRegistry; -import net.minecraftforge.fml.network.simple.SimpleChannel; +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.fmllegacy.network.NetworkRegistry; +import net.minecraftforge.fmllegacy.network.simple.SimpleChannel; /** * Class for handling network events diff --git a/src/main/java/com/github/samarium150/structurescompass/network/packet/CompassSearchPacket.java b/src/main/java/com/github/samarium150/structurescompass/network/packet/CompassSearchPacket.java index 2463cf2..4f27c55 100644 --- a/src/main/java/com/github/samarium150/structurescompass/network/packet/CompassSearchPacket.java +++ b/src/main/java/com/github/samarium150/structurescompass/network/packet/CompassSearchPacket.java @@ -3,13 +3,13 @@ import com.github.samarium150.structurescompass.item.StructuresCompassItem; import com.github.samarium150.structurescompass.util.ItemUtils; import com.github.samarium150.structurescompass.util.StructureUtils; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.gen.feature.structure.Structure; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.fml.network.NetworkEvent.Context; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.server.level.ServerLevel; +import net.minecraftforge.fmllegacy.network.NetworkEvent.Context; import javax.annotation.Nonnull; import java.util.function.Supplier; @@ -34,22 +34,22 @@ public CompassSearchPacket(ResourceLocation resource) { * Decoder of the packet * @param buffer PacketBuffer */ - public CompassSearchPacket(@Nonnull PacketBuffer buffer) { + public CompassSearchPacket(@Nonnull FriendlyByteBuf buffer) { resource = buffer.readResourceLocation(); } - public void toBytes(@Nonnull PacketBuffer buffer) { + public void toBytes(@Nonnull FriendlyByteBuf buffer) { buffer.writeResourceLocation(resource); } public void handle(@Nonnull Supplier ctx) { Context context = ctx.get(); context.enqueueWork(() -> { - ServerPlayerEntity player = context.getSender(); + ServerPlayer player = context.getSender(); final ItemStack stack = ItemUtils.getHeldStructuresCompass(player); if (!stack.isEmpty() && player != null) { - final ServerWorld world = (ServerWorld)player.level; - Structure structure = StructureUtils.getStructureForResource(resource); + final ServerLevel world = (ServerLevel)player.level; + StructureFeature structure = StructureUtils.getStructureForResource(resource); if (structure != null) new Thread(() -> StructuresCompassItem.search(world, player, structure, stack)).start(); } diff --git a/src/main/java/com/github/samarium150/structurescompass/network/packet/CompassSkipExistingChunksPacket.java b/src/main/java/com/github/samarium150/structurescompass/network/packet/CompassSkipExistingChunksPacket.java index b7b2a80..cdf7665 100644 --- a/src/main/java/com/github/samarium150/structurescompass/network/packet/CompassSkipExistingChunksPacket.java +++ b/src/main/java/com/github/samarium150/structurescompass/network/packet/CompassSkipExistingChunksPacket.java @@ -2,17 +2,17 @@ import com.github.samarium150.structurescompass.item.StructuresCompassItem; import com.github.samarium150.structurescompass.util.ItemUtils; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraftforge.fml.network.NetworkEvent.Context; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fmllegacy.network.NetworkEvent.Context; import javax.annotation.Nonnull; import java.util.function.Supplier; /** * Class for the compass to set the SkipExistingChunks property - * @see net.minecraft.world.server.ServerWorld#getStructureLocation + * @see net.minecraft.server.level.ServerLevel#findNearestMapFeature */ public final class CompassSkipExistingChunksPacket implements Packet { @@ -30,18 +30,18 @@ public CompassSkipExistingChunksPacket(Boolean skip) { * Decoder of the packet * @param buffer PacketBuffer */ - public CompassSkipExistingChunksPacket(@Nonnull PacketBuffer buffer) { + public CompassSkipExistingChunksPacket(@Nonnull FriendlyByteBuf buffer) { skip = buffer.readBoolean(); } - public void toBytes(@Nonnull PacketBuffer buffer) { + public void toBytes(@Nonnull FriendlyByteBuf buffer) { buffer.writeBoolean(skip); } public void handle(@Nonnull Supplier ctx) { Context context = ctx.get(); context.enqueueWork(() -> { - ServerPlayerEntity player = context.getSender(); + ServerPlayer player = context.getSender(); final ItemStack stack = ItemUtils.getHeldStructuresCompass(player); if (!stack.isEmpty() && player != null) StructuresCompassItem.setSkip(skip, stack); }); diff --git a/src/main/java/com/github/samarium150/structurescompass/network/packet/Packet.java b/src/main/java/com/github/samarium150/structurescompass/network/packet/Packet.java index fe7d90e..e560689 100644 --- a/src/main/java/com/github/samarium150/structurescompass/network/packet/Packet.java +++ b/src/main/java/com/github/samarium150/structurescompass/network/packet/Packet.java @@ -1,7 +1,7 @@ package com.github.samarium150.structurescompass.network.packet; -import net.minecraft.network.PacketBuffer; -import net.minecraftforge.fml.network.NetworkEvent.Context; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.fmllegacy.network.NetworkEvent.Context; import javax.annotation.Nonnull; import java.util.function.Supplier; @@ -14,9 +14,9 @@ public interface Packet { /** * Encoder of the packet * @param buffer PacketBuffer - * @see PacketBuffer + * @see FriendlyByteBuf */ - void toBytes(@Nonnull PacketBuffer buffer); + void toBytes(@Nonnull FriendlyByteBuf buffer); /** * Consumer of the packet diff --git a/src/main/java/com/github/samarium150/structurescompass/network/packet/RequestSyncPacket.java b/src/main/java/com/github/samarium150/structurescompass/network/packet/RequestSyncPacket.java index 61944e9..80b41a4 100644 --- a/src/main/java/com/github/samarium150/structurescompass/network/packet/RequestSyncPacket.java +++ b/src/main/java/com/github/samarium150/structurescompass/network/packet/RequestSyncPacket.java @@ -3,12 +3,12 @@ import com.github.samarium150.structurescompass.network.StructuresCompassNetwork; import com.github.samarium150.structurescompass.util.ItemUtils; import com.github.samarium150.structurescompass.util.StructureUtils; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraft.world.gen.feature.structure.Structure; -import net.minecraftforge.fml.network.NetworkEvent.Context; -import net.minecraftforge.fml.network.PacketDistributor; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraftforge.fmllegacy.network.NetworkEvent.Context; +import net.minecraftforge.fmllegacy.network.PacketDistributor; import javax.annotation.Nonnull; import java.util.HashMap; @@ -30,17 +30,17 @@ public RequestSyncPacket() { } * @param buffer PacketBuffer */ @SuppressWarnings("unused") - public RequestSyncPacket(PacketBuffer buffer) { } + public RequestSyncPacket(FriendlyByteBuf buffer) { } - public void toBytes(@Nonnull PacketBuffer buffer) { } + public void toBytes(@Nonnull FriendlyByteBuf buffer) { } public void handle(@Nonnull Supplier ctx) { Context context = ctx.get(); context.enqueueWork(() -> { - final ServerPlayerEntity player = context.getSender(); + final ServerPlayer player = context.getSender(); final ItemStack stack = ItemUtils.getHeldStructuresCompass(player); if (!stack.isEmpty() && player != null) { - final List> allowed = StructureUtils.getAllowedStructures(); + final List> allowed = StructureUtils.getAllowedStructures(); final HashMap> map = new HashMap<>(); allowed.forEach(structure -> map.put( StructureUtils.getStructureName(structure), diff --git a/src/main/java/com/github/samarium150/structurescompass/network/packet/SyncPacket.java b/src/main/java/com/github/samarium150/structurescompass/network/packet/SyncPacket.java index 284d9b3..5ba1479 100644 --- a/src/main/java/com/github/samarium150/structurescompass/network/packet/SyncPacket.java +++ b/src/main/java/com/github/samarium150/structurescompass/network/packet/SyncPacket.java @@ -4,12 +4,12 @@ import com.github.samarium150.structurescompass.util.GeneralUtils; import com.github.samarium150.structurescompass.util.Serializer; import com.github.samarium150.structurescompass.util.StructureUtils; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.network.NetworkEvent.Context; +import net.minecraftforge.fmllegacy.network.NetworkEvent.Context; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -24,7 +24,7 @@ public final class SyncPacket implements Packet, Serializer>> { private final ItemStack stack; - private final List> allowed; + private final List> allowed; private final HashMap> map; /** @@ -35,7 +35,7 @@ public final class SyncPacket implements Packet, Serializer> allowed, HashMap> map) { + public SyncPacket(ItemStack stack, List> allowed, HashMap> map) { this.stack = stack; this.allowed = allowed; this.map = map; @@ -45,7 +45,7 @@ public SyncPacket(ItemStack stack, List> allowed, HashMap(); int size = buffer.readInt(); @@ -66,7 +66,7 @@ public SyncPacket(@Nonnull PacketBuffer buffer) { } @Override - public void toBytes(@Nonnull PacketBuffer buffer) { + public void toBytes(@Nonnull FriendlyByteBuf buffer) { buffer.writeItem(stack); buffer.writeInt(allowed.size()); allowed.forEach(structure -> buffer.writeResourceLocation(StructureUtils.getResourceForStructure(structure))); diff --git a/src/main/java/com/github/samarium150/structurescompass/util/ItemUtils.java b/src/main/java/com/github/samarium150/structurescompass/util/ItemUtils.java index 8585b98..22074a7 100644 --- a/src/main/java/com/github/samarium150/structurescompass/util/ItemUtils.java +++ b/src/main/java/com/github/samarium150/structurescompass/util/ItemUtils.java @@ -1,10 +1,10 @@ package com.github.samarium150.structurescompass.util; import com.github.samarium150.structurescompass.init.ItemRegistry; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -33,10 +33,10 @@ public static boolean isStackItemStructuresCompass(@Nonnull ItemStack stack) { * null otherwise */ @Nullable - public static CompoundNBT getOrCreateItemTag(@Nonnull ItemStack stack) { + public static CompoundTag getOrCreateItemTag(@Nonnull ItemStack stack) { if (isStackItemStructuresCompass(stack)) { - CompoundNBT tag = stack.getTag(); - return (tag == null) ? new CompoundNBT() : tag; + CompoundTag tag = stack.getTag(); + return (tag == null) ? new CompoundTag() : tag; } return null; } @@ -48,7 +48,7 @@ public static CompoundNBT getOrCreateItemTag(@Nonnull ItemStack stack) { * null otherwise */ @Nullable - public static CompoundNBT getItemTag(@Nonnull ItemStack stack) { + public static CompoundTag getItemTag(@Nonnull ItemStack stack) { return isStackItemStructuresCompass(stack) ? stack.getTag() : null; } @@ -59,7 +59,7 @@ public static CompoundNBT getItemTag(@Nonnull ItemStack stack) { */ public static void removeTag(@Nonnull ItemStack stack, String TAG_NAME) { if (stack.getItem() == ItemRegistry.STRUCTURES_COMPASS.get()) { - CompoundNBT tag = stack.getTag(); + CompoundTag tag = stack.getTag(); if (tag == null) return; tag.remove(TAG_NAME); stack.setTag(tag); @@ -72,7 +72,7 @@ public static void removeTag(@Nonnull ItemStack stack, String TAG_NAME) { * @param item the item to get * @return the ItemStack of the given item */ - public static ItemStack getHeldItem(PlayerEntity player, Item item) { + public static ItemStack getHeldItem(Player player, Item item) { if (player == null) return ItemStack.EMPTY; if (!player.getMainHandItem().isEmpty() && player.getMainHandItem().getItem() == item) return player.getMainHandItem(); @@ -86,7 +86,7 @@ else if (!player.getOffhandItem().isEmpty() && player.getOffhandItem().getItem() * @param player the player entity * @return the ItemStack of the compass */ - public static ItemStack getHeldStructuresCompass(PlayerEntity player) { + public static ItemStack getHeldStructuresCompass(Player player) { return getHeldItem(player, ItemRegistry.STRUCTURES_COMPASS.get()); } } diff --git a/src/main/java/com/github/samarium150/structurescompass/util/RenderUtils.java b/src/main/java/com/github/samarium150/structurescompass/util/RenderUtils.java index 256eab5..0e571f5 100644 --- a/src/main/java/com/github/samarium150/structurescompass/util/RenderUtils.java +++ b/src/main/java/com/github/samarium150/structurescompass/util/RenderUtils.java @@ -2,14 +2,11 @@ import com.github.samarium150.structurescompass.config.HUDPosition; import com.github.samarium150.structurescompass.config.StructuresCompassConfig; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.*; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.gui.Font; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -29,20 +26,20 @@ public abstract class RenderUtils { private static final Minecraft minecraft = Minecraft.getInstance(); - private static final FontRenderer fontRenderer = minecraft.font; + private static final Font fontRenderer = minecraft.font; private RenderUtils() { } - private static void drawStringLeft(MatrixStack matrixStack, String string, int x, int y, int color) { + private static void drawStringLeft(PoseStack matrixStack, String string, int x, int y, int color) { fontRenderer.draw(matrixStack, string, x, y, color); } - private static void drawStringRight(MatrixStack matrixStack, String string, int x, int y, int color) { + private static void drawStringRight(PoseStack matrixStack, String string, int x, int y, int color) { fontRenderer.draw(matrixStack, string, x, y, color); } public static void drawConfiguredStringOnHUD( - MatrixStack matrixStack, String string, + PoseStack matrixStack, String string, int xOffset, int yOffset, int color, int relLineOffset ) { yOffset += (relLineOffset + StructuresCompassConfig.overlayLineOffset.get()) * 9; @@ -58,14 +55,13 @@ public static void drawConfiguredStringOnHUD( } public static void updateBuffer(@Nonnull BufferBuilder buffer, int startX, int startY, int endX, int endY) { - buffer.begin(7, DefaultVertexFormats.POSITION); + buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); buffer.vertex(startX, endY, 0.0D).endVertex(); buffer.vertex(endX, endY, 0.0D).endVertex(); buffer.vertex(endX, startY, 0.0D).endVertex(); buffer.vertex(startX, startY, 0.0D).endVertex(); } - @SuppressWarnings("deprecation") public static void drawRect(int left, int top, int right, int bottom, int color) { if (left < right) left = GeneralUtils.swap(right, right = left); @@ -77,8 +73,8 @@ public static void drawRect(int left, int top, int right, int bottom, int color) final float blue = (float) (color & 255) / 255.0F; final float alpha = (float) (color >> 24 & 255) / 255.0F; - final Tessellator tessellator = Tessellator.getInstance(); - final BufferBuilder buffer = tessellator.getBuilder(); + final Tesselator tesselator = Tesselator.getInstance(); + final BufferBuilder buffer = tesselator.getBuilder(); RenderSystem.enableBlend(); RenderSystem.disableTexture(); RenderSystem.blendFuncSeparate( @@ -88,11 +84,10 @@ public static void drawRect(int left, int top, int right, int bottom, int color) GlStateManager.DestFactor.ZERO ); - // Annotated as deprecated but no replacement - RenderSystem.color4f(red, green, blue, alpha); + RenderSystem.setShaderColor(red, green, blue, alpha); updateBuffer(buffer, left, top, right, bottom); - tessellator.end(); + tesselator.end(); RenderSystem.enableTexture(); RenderSystem.disableBlend(); } diff --git a/src/main/java/com/github/samarium150/structurescompass/util/StructureUtils.java b/src/main/java/com/github/samarium150/structurescompass/util/StructureUtils.java index ff75b09..b287999 100644 --- a/src/main/java/com/github/samarium150/structurescompass/util/StructureUtils.java +++ b/src/main/java/com/github/samarium150/structurescompass/util/StructureUtils.java @@ -1,14 +1,14 @@ package com.github.samarium150.structurescompass.util; import com.github.samarium150.structurescompass.config.StructuresCompassConfig; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.Entity; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.entity.Entity; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.gen.feature.structure.Structure; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.server.level.ServerLevel; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.ModContainer; @@ -27,7 +27,7 @@ */ public abstract class StructureUtils { - public static List> allowedStructures; + public static List> allowedStructures; public static HashMap> structuresDimensionMap; @@ -38,7 +38,7 @@ public abstract class StructureUtils { * @param structure the given structure * @return the corresponding ResourceLocation */ - public static ResourceLocation getResourceForStructure(@Nonnull Structure structure) { + public static ResourceLocation getResourceForStructure(@Nonnull StructureFeature structure) { return ForgeRegistries.STRUCTURE_FEATURES.getKey(structure); } @@ -48,7 +48,7 @@ public static ResourceLocation getResourceForStructure(@Nonnull Structure str * @return the corresponding structure */ @Nullable - public static Structure getStructureForResource(ResourceLocation resource) { + public static StructureFeature getStructureForResource(ResourceLocation resource) { return ForgeRegistries.STRUCTURE_FEATURES.getValue(resource); } @@ -57,9 +57,9 @@ public static Structure getStructureForResource(ResourceLocation resource) { * @return a list of allowed structures */ @Nonnull - public static List> getAllowedStructures() { - final List> result = new ArrayList<>(); - for (Structure structureFeature : ForgeRegistries.STRUCTURE_FEATURES) { + public static List> getAllowedStructures() { + final List> result = new ArrayList<>(); + for (StructureFeature structureFeature : ForgeRegistries.STRUCTURE_FEATURES) { ResourceLocation res = structureFeature.getRegistryName(); if (res == null || isStructureBanned(res.toString())) continue; @@ -83,7 +83,7 @@ public static boolean isStructureBanned(String name) { * @return the name of the structure */ @Nonnull - public static String getStructureName(@Nonnull Structure structure) { + public static String getStructureName(@Nonnull StructureFeature structure) { ResourceLocation registry = structure.getRegistryName(); return (registry == null) ? "" : registry.toString(); } @@ -111,7 +111,7 @@ public static String getLocalizedStructureName(@Nonnull String resource) { */ @Nonnull @OnlyIn(Dist.CLIENT) - public static String getLocalizedStructureName(@Nonnull Structure structure) { + public static String getLocalizedStructureName(@Nonnull StructureFeature structure) { return getLocalizedStructureName(getStructureName(structure)); } @@ -122,7 +122,7 @@ public static String getLocalizedStructureName(@Nonnull Structure structure) * @return a list of dimensions */ @Nonnull - public static List getDimensions(@Nonnull ServerWorld world, Structure structure) { + public static List getDimensions(@Nonnull ServerLevel world, StructureFeature structure) { final List dims = new ArrayList<>(); MinecraftServer server = world.getServer(); server.getAllLevels().forEach(w->{ @@ -138,7 +138,7 @@ public static List getDimensions(@Nonnull ServerWorld world, Structure structure) { + public static String getDimensions(@Nonnull StructureFeature structure) { List dims = StructureUtils.structuresDimensionMap.getOrDefault( StructureUtils.getResourceForStructure(structure).toString(), new ArrayList<>() @@ -166,7 +166,7 @@ public static String getLocalizedDimensionName(@Nonnull String resource) { * @param structure the given structure * @return the name of the mod */ - public static String getStructureSource(@Nonnull Structure structure) { + public static String getStructureSource(@Nonnull StructureFeature structure) { if (getResourceForStructure(structure) == null) return ""; String registry = getResourceForStructure(structure).toString(); @@ -186,10 +186,10 @@ public static String getStructureSource(@Nonnull Structure structure) { * @return the distance vector */ @Nonnull - public static Vector3d getDistance(@Nonnull BlockPos pos, @Nonnull Entity entity) { + public static Vec3 getDistance(@Nonnull BlockPos pos, @Nonnull Entity entity) { double disX = (double) Math.round((pos.getX() - entity.getX()) * 100) / 100; double disY = pos.getY() == 0 ? 0 : (double) Math.round((pos.getY() - entity.getY()) * 100) / 100; double disZ = (double) Math.round((pos.getZ() - entity.getZ()) * 100) / 100; - return new Vector3d(disX, disY, disZ); + return new Vec3(disX, disY, disZ); } } diff --git a/src/main/java/com/github/samarium150/structurescompass/util/sort/Category.java b/src/main/java/com/github/samarium150/structurescompass/util/sort/Category.java index 398ae8d..3ae36b7 100644 --- a/src/main/java/com/github/samarium150/structurescompass/util/sort/Category.java +++ b/src/main/java/com/github/samarium150/structurescompass/util/sort/Category.java @@ -1,6 +1,6 @@ package com.github.samarium150.structurescompass.util.sort; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -11,7 +11,7 @@ * The interface for sorting structures in GUI */ @OnlyIn(Dist.CLIENT) -public interface Category extends Comparator> { +public interface Category extends Comparator> { /** * The comparison function for structures @@ -21,7 +21,7 @@ public interface Category extends Comparator> { * @return order of the two structures */ @Override - int compare(Structure s1, Structure s2); + int compare(StructureFeature s1, StructureFeature s2); /** * @return the next Category after clicking diff --git a/src/main/java/com/github/samarium150/structurescompass/util/sort/DimensionCategory.java b/src/main/java/com/github/samarium150/structurescompass/util/sort/DimensionCategory.java index 359d66a..8efcc8b 100644 --- a/src/main/java/com/github/samarium150/structurescompass/util/sort/DimensionCategory.java +++ b/src/main/java/com/github/samarium150/structurescompass/util/sort/DimensionCategory.java @@ -1,8 +1,8 @@ package com.github.samarium150.structurescompass.util.sort; import com.github.samarium150.structurescompass.util.StructureUtils; -import net.minecraft.client.resources.I18n; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -15,7 +15,7 @@ public final class DimensionCategory implements Category { @Override - public int compare(Structure s1, Structure s2) { + public int compare(StructureFeature s1, StructureFeature s2) { return StructureUtils.getDimensions(s1).compareTo(StructureUtils.getDimensions(s2)); } diff --git a/src/main/java/com/github/samarium150/structurescompass/util/sort/NameCategory.java b/src/main/java/com/github/samarium150/structurescompass/util/sort/NameCategory.java index ecdaf8b..358ed31 100644 --- a/src/main/java/com/github/samarium150/structurescompass/util/sort/NameCategory.java +++ b/src/main/java/com/github/samarium150/structurescompass/util/sort/NameCategory.java @@ -1,8 +1,8 @@ package com.github.samarium150.structurescompass.util.sort; import com.github.samarium150.structurescompass.util.StructureUtils; -import net.minecraft.client.resources.I18n; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -15,7 +15,7 @@ public final class NameCategory implements Category { @Override - public int compare(Structure s1, Structure s2) { + public int compare(StructureFeature s1, StructureFeature s2) { return StructureUtils.getLocalizedStructureName(s1).compareTo(StructureUtils.getLocalizedStructureName(s2)); } diff --git a/src/main/java/com/github/samarium150/structurescompass/util/sort/SourceCategory.java b/src/main/java/com/github/samarium150/structurescompass/util/sort/SourceCategory.java index a321b3b..459528d 100644 --- a/src/main/java/com/github/samarium150/structurescompass/util/sort/SourceCategory.java +++ b/src/main/java/com/github/samarium150/structurescompass/util/sort/SourceCategory.java @@ -1,8 +1,8 @@ package com.github.samarium150.structurescompass.util.sort; import com.github.samarium150.structurescompass.util.StructureUtils; -import net.minecraft.client.resources.I18n; -import net.minecraft.world.gen.feature.structure.Structure; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -15,7 +15,7 @@ public final class SourceCategory implements Category { @Override - public int compare(Structure s1, Structure s2) { + public int compare(StructureFeature s1, StructureFeature s2) { return StructureUtils.getStructureSource(s1).compareTo(StructureUtils.getStructureSource(s2)); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 6e8acb5..0928be4 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[36,)" +loaderVersion="[37,)" issueTrackerURL="https://github.com/Samarium150/StructuresCompass/issues" license="GNU GENERAL PUBLIC LICENSE Version 3" diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index e8c742b..29e4822 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { "description": "Structures' Compass mod resources", - "pack_format": 6 + "pack_format": 7 } }