diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 02680b3..d4859ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,9 +10,9 @@ jobs: strategy: matrix: minecraftVersion: - - 1.19 - - 1.19.1 - - 1.19.2 + - 1.20 + - 1.20.1 + - 1.20.2 runs-on: ubuntu-20.04 steps: diff --git a/gradle.properties b/gradle.properties index 4303c1a..2b75c55 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,13 +3,13 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # Check these on https://fabricmc.net/develop - minecraft_version=1.19.2 - yarn_mappings=1.19.2+build.3 - loader_version=0.14.9 + minecraft_version=1.20.2 + yarn_mappings=1.20.2+build.4 + loader_version=0.14.23 # Dependencies - fabric_version=0.59.0+1.19.2 - modmenu_version=4.0.6 + fabric_version=0.90.0+1.20.2 + modmenu_version=8.0.0 # Mod Properties mod_id = villagerbefriending diff --git a/src/main/java/io/github/offsetmonkey538/villagerbefriending/entity/goal/VillagerFollowOwnerGoal.java b/src/main/java/io/github/offsetmonkey538/villagerbefriending/entity/goal/VillagerFollowOwnerGoal.java index 331fc99..1cee59c 100644 --- a/src/main/java/io/github/offsetmonkey538/villagerbefriending/entity/goal/VillagerFollowOwnerGoal.java +++ b/src/main/java/io/github/offsetmonkey538/villagerbefriending/entity/goal/VillagerFollowOwnerGoal.java @@ -25,7 +25,7 @@ public class VillagerFollowOwnerGoal extends AbstractVillagerGoal { public VillagerFollowOwnerGoal(VillagerEntity villager, double speed, float minDistance, float maxDistance, boolean leavesAllowed) { super(villager); - this.world = this.villager.world; + this.world = this.villager.getWorld(); this.speed = speed; this.minDistance = minDistance; this.maxDistance = maxDistance; diff --git a/src/main/java/io/github/offsetmonkey538/villagerbefriending/item/ModItems.java b/src/main/java/io/github/offsetmonkey538/villagerbefriending/item/ModItems.java index 9c4242f..8fbcf98 100644 --- a/src/main/java/io/github/offsetmonkey538/villagerbefriending/item/ModItems.java +++ b/src/main/java/io/github/offsetmonkey538/villagerbefriending/item/ModItems.java @@ -1,28 +1,31 @@ package io.github.offsetmonkey538.villagerbefriending.item; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; +import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemGroups; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; import net.minecraft.util.Rarity; -import net.minecraft.util.registry.Registry; -import static io.github.offsetmonkey538.villagerbefriending.entrypoint.VillagerBefriendingMain.MOD_ID; +import static io.github.offsetmonkey538.villagerbefriending.entrypoint.VillagerBefriendingMain.*; public class ModItems { public static final TotemOfBefriendingItem TOTEM_OF_BEFRIENDING_ITEM = register( new TotemOfBefriendingItem(new FabricItemSettings() - .group(ItemGroup.MISC) .rarity(Rarity.RARE) .maxCount(1)), "totem_of_befriending"); private static T register(T item, String id) { - return Registry.register(Registry.ITEM, new Identifier(MOD_ID, id), item); + return Registry.register(Registries.ITEM, new Identifier(MOD_ID, id), item); } public static void register() { // Loads all items because the class gets loaded + + ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register(entries -> entries.add(TOTEM_OF_BEFRIENDING_ITEM)); } } diff --git a/src/main/java/io/github/offsetmonkey538/villagerbefriending/mixin/VillagerEntityMixin.java b/src/main/java/io/github/offsetmonkey538/villagerbefriending/mixin/VillagerEntityMixin.java index b7eef17..58b54bc 100644 --- a/src/main/java/io/github/offsetmonkey538/villagerbefriending/mixin/VillagerEntityMixin.java +++ b/src/main/java/io/github/offsetmonkey538/villagerbefriending/mixin/VillagerEntityMixin.java @@ -3,6 +3,7 @@ import io.github.offsetmonkey538.villagerbefriending.entity.IVillagerData; import io.github.offsetmonkey538.villagerbefriending.entity.goal.VillagerFollowOwnerGoal; import io.github.offsetmonkey538.villagerbefriending.item.ModItems; +import io.github.offsetmonkey538.villagerbefriending.mixin.accessor.ItemEntityAccessor; import io.github.offsetmonkey538.villagerbefriending.screen.tamedvillager.TamedVillagerScreenHandler; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.entity.EntityStatuses; @@ -86,16 +87,19 @@ private static E[] changeGatherableItems(E[] original) { ) private void tame(ItemEntity item, CallbackInfo ci) { if (!item.getStack().isOf(TAMING_ITEM)) return; - PlayerEntity player = item.getWorld().getPlayerByUuid(item.getThrower()); + + ItemEntityAccessor itemEntityAccessor = (ItemEntityAccessor) item; + + PlayerEntity player = item.getWorld().getPlayerByUuid(itemEntityAccessor.getThrower()); if (player == null || hasOwner() || isBaby() || !player.hasStatusEffect(StatusEffects.HERO_OF_THE_VILLAGE)) { ci.cancel(); return; } - this.setOwnerUuid(item.getThrower()); + this.setOwnerUuid(itemEntityAccessor.getThrower()); this.setStanding(false); this.setFollowingOwner(true); - this.world.sendEntityStatus((VillagerEntity)(Object)this, EntityStatuses.ADD_VILLAGER_HEART_PARTICLES); + this.getWorld().sendEntityStatus((VillagerEntity)(Object)this, EntityStatuses.ADD_VILLAGER_HEART_PARTICLES); } @Inject( @@ -121,7 +125,7 @@ public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity pl return new TamedVillagerScreenHandler(syncId, inv, (VillagerEntity) (Object) VillagerEntityMixin.this); } }); - cir.setReturnValue(ActionResult.success(this.world.isClient)); + cir.setReturnValue(ActionResult.success(this.getWorld().isClient)); } @Inject( @@ -210,7 +214,7 @@ public LivingEntity getOwner() { if (UUID == null) { return null; } - return this.world.getPlayerByUuid(UUID); + return this.getWorld().getPlayerByUuid(UUID); } catch (IllegalArgumentException illegalArgumentException) { return null; } diff --git a/src/main/java/io/github/offsetmonkey538/villagerbefriending/mixin/accessor/ItemEntityAccessor.java b/src/main/java/io/github/offsetmonkey538/villagerbefriending/mixin/accessor/ItemEntityAccessor.java new file mode 100644 index 0000000..90ee9cc --- /dev/null +++ b/src/main/java/io/github/offsetmonkey538/villagerbefriending/mixin/accessor/ItemEntityAccessor.java @@ -0,0 +1,13 @@ +package io.github.offsetmonkey538.villagerbefriending.mixin.accessor; + +import java.util.UUID; +import net.minecraft.entity.ItemEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ItemEntity.class) +public interface ItemEntityAccessor { + + @Accessor + UUID getThrower(); +} diff --git a/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/ModScreenHandlers.java b/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/ModScreenHandlers.java index e588a63..0015303 100644 --- a/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/ModScreenHandlers.java +++ b/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/ModScreenHandlers.java @@ -2,10 +2,11 @@ import io.github.offsetmonkey538.villagerbefriending.screen.tamedvillager.TamedVillagerScreenHandler; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import static io.github.offsetmonkey538.villagerbefriending.entrypoint.VillagerBefriendingMain.MOD_ID; @@ -13,7 +14,7 @@ public final class ModScreenHandlers { public static final ExtendedScreenHandlerType TAMED_VILLAGER = register("tamed_villager", new ExtendedScreenHandlerType<>(TamedVillagerScreenHandler::new)); private static > H register(String id, H type) { - return Registry.register(Registry.SCREEN_HANDLER, new Identifier(MOD_ID, id), type); + return Registry.register(Registries.SCREEN_HANDLER, new Identifier(MOD_ID, id), type); } public static void register() { diff --git a/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/tamedvillager/TamedVillagerScreen.java b/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/tamedvillager/TamedVillagerScreen.java index 81de78e..3e78619 100644 --- a/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/tamedvillager/TamedVillagerScreen.java +++ b/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/tamedvillager/TamedVillagerScreen.java @@ -1,15 +1,13 @@ package io.github.offsetmonkey538.villagerbefriending.screen.tamedvillager; -import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import static io.github.offsetmonkey538.villagerbefriending.entrypoint.VillagerBefriendingMain.MOD_ID; +import static io.github.offsetmonkey538.villagerbefriending.entrypoint.VillagerBefriendingMain.*; import static io.github.offsetmonkey538.villagerbefriending.screen.tamedvillager.Buttons.*; public class TamedVillagerScreen extends HandledScreen { @@ -22,18 +20,15 @@ public TamedVillagerScreen(TamedVillagerScreenHandler handler, PlayerInventory i } @Override - protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, TEXTURE_PATH); + protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { int x = (width - backgroundWidth) / 2; int y = (height - backgroundHeight) / 2; - drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight); + context.drawTexture(TEXTURE_PATH, x, y, 0, 0, backgroundWidth, backgroundHeight); } @Override - protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) { - this.textRenderer.draw(matrices, this.title, (float)this.titleX, (float)this.titleY, 0x404040); + protected void drawForeground(DrawContext context, int mouseX, int mouseY) { + context.drawText(this.textRenderer, this.title, this.titleX, this.titleY, 4210752, false); } @Override @@ -46,19 +41,43 @@ protected void init() { int buttonHeight = 20; // Stay here - addDrawableChild(new ButtonWidget(x + 6, middleY - buttonHeight / 2, buttonWidth, buttonHeight, Text.translatable(String.format("entity.%s.villager.command_menu.button.stay", MOD_ID)), button -> - sendButtonPressedPacket(STAND) - )); + addDrawableChild(ButtonWidget + .builder( + Text.translatable("entity.villagerbefriending.villager.command_menu.button.stay"), button -> sendButtonPressedPacket(STAND) + ) + .dimensions( + x + 6, + middleY - buttonHeight / 2, + buttonWidth, buttonHeight + ) + .build() + ); // Follow me - addDrawableChild(new ButtonWidget(x + (backgroundWidth / 2) - buttonWidth / 2, middleY - buttonHeight / 2, buttonWidth, buttonHeight, Text.translatable(String.format("entity.%s.villager.command_menu.button.follow", MOD_ID)), button -> - sendButtonPressedPacket(FOLLOW) - )); + addDrawableChild(ButtonWidget + .builder( + Text.translatable("entity.villagerbefriending.villager.command_menu.button.follow"), button -> sendButtonPressedPacket(FOLLOW) + ) + .dimensions( + x + backgroundWidth / 2 - buttonWidth / 2, + middleY - buttonHeight / 2, + buttonWidth, buttonHeight + ) + .build() + ); // Wander around - addDrawableChild(new ButtonWidget((x + (backgroundWidth) - 6) - buttonWidth, middleY - buttonHeight / 2, buttonWidth, buttonHeight, Text.translatable(String.format("entity.%s.villager.command_menu.button.wander", MOD_ID)), button -> - sendButtonPressedPacket(WANDER) - )); + addDrawableChild(ButtonWidget + .builder( + Text.translatable("entity.villagerbefriending.villager.command_menu.button.wander"), button -> sendButtonPressedPacket(WANDER) + ) + .dimensions( + x + backgroundWidth - 6 - buttonWidth, + middleY - buttonHeight / 2, + buttonWidth, buttonHeight + ) + .build() + ); } private void sendButtonPressedPacket(int buttonId) { diff --git a/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/tamedvillager/TamedVillagerScreenHandler.java b/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/tamedvillager/TamedVillagerScreenHandler.java index 35aecc5..73bbfc0 100644 --- a/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/tamedvillager/TamedVillagerScreenHandler.java +++ b/src/main/java/io/github/offsetmonkey538/villagerbefriending/screen/tamedvillager/TamedVillagerScreenHandler.java @@ -19,7 +19,7 @@ public class TamedVillagerScreenHandler extends ScreenHandler { private final IVillagerData villagerData; public TamedVillagerScreenHandler(int syncId, PlayerInventory inventory, PacketByteBuf buf) { - this(syncId, inventory, (inventory.player.world.getEntityById(buf.readVarInt()) instanceof VillagerEntity villager ? villager : null)); + this(syncId, inventory, (inventory.player.getWorld().getEntityById(buf.readVarInt()) instanceof VillagerEntity villager ? villager : null)); } public TamedVillagerScreenHandler(int syncId, PlayerInventory inventory, VillagerEntity villager) { @@ -29,7 +29,7 @@ public TamedVillagerScreenHandler(int syncId, PlayerInventory inventory, Village } @Override - public ItemStack transferSlot(PlayerEntity player, int index) { + public ItemStack quickMove(PlayerEntity player, int index) { return null; } diff --git a/src/main/resources/villagerbefriending.mixins.json b/src/main/resources/villagerbefriending.mixins.json index 98bf1e4..9a83bd9 100644 --- a/src/main/resources/villagerbefriending.mixins.json +++ b/src/main/resources/villagerbefriending.mixins.json @@ -1,13 +1,14 @@ { - "required": true, - "minVersion": "0.8", - "package": "io.github.offsetmonkey538.villagerbefriending.mixin", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "LivingEntityMixin", - "VillagerEntityMixin" - ], - "injectors": { - "defaultRequire": 1 + "required": true, + "minVersion": "0.8", + "package": "io.github.offsetmonkey538.villagerbefriending.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "LivingEntityMixin", + "VillagerEntityMixin", + "accessor.ItemEntityAccessor" + ], + "injectors": { + "defaultRequire": 1 } }