Skip to content

Commit

Permalink
Update to 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
OffsetMonkey538 committed Oct 21, 2023
1 parent 8e20b57 commit b92ba8b
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 53 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 extends Item> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,16 +87,19 @@ private static <E> 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(
Expand All @@ -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(
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

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;

public final class ModScreenHandlers {
public static final ExtendedScreenHandlerType<TamedVillagerScreenHandler> TAMED_VILLAGER = register("tamed_villager", new ExtendedScreenHandlerType<>(TamedVillagerScreenHandler::new));

private static <T extends ScreenHandler, H extends ScreenHandlerType<T>> 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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TamedVillagerScreenHandler> {
Expand All @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
21 changes: 11 additions & 10 deletions src/main/resources/villagerbefriending.mixins.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit b92ba8b

Please sign in to comment.