Skip to content

Commit

Permalink
1.20 (#252)
Browse files Browse the repository at this point in the history
* 1.20

* Remove ideConfigGenerated

Co-authored-by: modmuss <[email protected]>

* Fix inversion

* fix slot background texture rendering

* Rename CI

---------

Co-authored-by: modmuss <[email protected]>
Co-authored-by: glisco <[email protected]>
  • Loading branch information
3 people authored Jun 8, 2023
1 parent 47072fb commit 1a3f70f
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 85 deletions.
14 changes: 11 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ version = project.mod_version
group = project.maven_group


loom {
accessWidenerPath = file("src/main/resources/trinkets.accesswidener")
}

repositories {
maven { url = "https://maven.terraformersmc.com" }
Expand All @@ -31,6 +28,17 @@ sourceSets {
}
}

loom {
accessWidenerPath = file("src/main/resources/trinkets.accesswidener")

runs {
testmodClient {
client()
name = "Testmod Client"
source sourceSets.testmod
}
}
}
dependencies {
// Base Fabric dependencies
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G

minecraft_version=1.19.4
yarn_mappings=1.19.4+build.1
loader_version=0.14.17
minecraft_version=1.20-pre6
yarn_mappings=1.20-pre6+build.2
loader_version=0.14.21

mod_version = 3.6.0
maven_group = dev.emi
archives_base_name = trinkets

fabric_version=0.76.0+1.19.4
cca_version=5.1.0
fabric_version=0.82.1+1.20
cca_version=5.2.0
mod_menu_version=5.0.2
2 changes: 1 addition & 1 deletion src/main/java/dev/emi/trinkets/SurvivalTrinketSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean canTakeItems(PlayerEntity player) {
public boolean isEnabled() {
if (alwaysVisible) {
if (x < 0) {
if (trinketInventory.getComponent().getEntity().world.isClient) {
if (trinketInventory.getComponent().getEntity().getWorld().isClient) {
MinecraftClient client = MinecraftClient.getInstance();
Screen s = client.currentScreen;
if (s instanceof InventoryScreen screen) {
Expand Down
69 changes: 33 additions & 36 deletions src/main/java/dev/emi/trinkets/TrinketScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dev.emi.trinkets.api.SlotType;
import dev.emi.trinkets.api.TrinketsApi;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Rect2i;
import net.minecraft.screen.slot.Slot;
Expand Down Expand Up @@ -182,11 +182,11 @@ public static void tick() {
}
}

public static void drawGroup(DrawableHelper helper, MatrixStack matrices, SlotGroup group, SlotType type) {
public static void drawGroup(DrawContext context, SlotGroup group, SlotType type) {
TrinketPlayerScreenHandler handler = currentScreen.trinkets$getHandler();
RenderSystem.enableDepthTest();
matrices.push();
matrices.translate(0, 0, 305);
context.getMatrices().push();
context.getMatrices().translate(0, 0, 305);

Rect2i r = currentScreen.trinkets$getGroupRect(group);
int slotsWidth = handler.trinkets$getSlotWidth(group) + 1;
Expand All @@ -195,16 +195,14 @@ public static void drawGroup(DrawableHelper helper, MatrixStack matrices, SlotGr
if (group.getSlotId() == -1) slotsWidth -= 1;
int x = r.getX() - 4 - (slotsWidth - 1) / 2 * 18;
int y = r.getY() - 4;
RenderSystem.setShaderTexture(0, MORE_SLOTS);

if (slotsWidth > 1 || type != null) {
helper.drawTexture(matrices, x, y, 0, 0, 4, 26);
context.drawTexture(MORE_SLOTS, x, y, 0, 0, 4, 26);

for (int i = 0; i < slotsWidth; i++) {
helper.drawTexture(matrices, x + i * 18 + 4, y, 4, 0, 18, 26);
context.drawTexture(MORE_SLOTS, x + i * 18 + 4, y, 4, 0, 18, 26);
}

helper.drawTexture(matrices, x + slotsWidth * 18 + 4, y, 22, 0, 4, 26);
context.drawTexture(MORE_SLOTS, x + slotsWidth * 18 + 4, y, 22, 0, 4, 26);
for (int s = 0; s < slotHeights.size() && s < slotTypes.size(); s++) {
if (slotTypes.get(s) != type) {
continue;
Expand All @@ -216,18 +214,18 @@ public static void drawGroup(DrawableHelper helper, MatrixStack matrices, SlotGr
int bottom = height / 2;
int slotX = slotHeight.x() - 4 + r.getX();
if (height > 2) {
helper.drawTexture(matrices, slotX, y - top * 18, 0, 0, 26, 4);
context.drawTexture(MORE_SLOTS, slotX, y - top * 18, 0, 0, 26, 4);
}

for (int i = 1; i < top + 1; i++) {
helper.drawTexture(matrices, slotX, y - i * 18 + 4, 0, 4, 26, 18);
context.drawTexture(MORE_SLOTS, slotX, y - i * 18 + 4, 0, 4, 26, 18);
}

for (int i = 1; i < bottom + 1; i++) {
helper.drawTexture(matrices, slotX, y + i * 18 + 4, 0, 4, 26, 18);
context.drawTexture(MORE_SLOTS, slotX, y + i * 18 + 4, 0, 4, 26, 18);
}

helper.drawTexture(matrices, slotX, y + 18 + bottom * 18 + 4, 0, 22, 26, 4);
context.drawTexture(MORE_SLOTS, slotX, y + 18 + bottom * 18 + 4, 0, 22, 26, 4);
}
}

Expand All @@ -243,32 +241,32 @@ public static void drawGroup(DrawableHelper helper, MatrixStack matrices, SlotGr
int slotX = slotHeight.x() + r.getX() + 1;
int top = (height - 1) / 2;
int bottom = height / 2;
helper.drawTexture(matrices, slotX, y - top * 18 + 1, 4, 1, 16, 3);
helper.drawTexture(matrices, slotX, y + (bottom + 1) * 18 + 4, 4, 22, 16, 3);
context.drawTexture(MORE_SLOTS, slotX, y - top * 18 + 1, 4, 1, 16, 3);
context.drawTexture(MORE_SLOTS, slotX, y + (bottom + 1) * 18 + 4, 4, 22, 16, 3);
}

// Because pre-existing slots are not part of the slotHeights list
if (group.getSlotId() != -1) {
helper.drawTexture(matrices, r.getX() + 1, y + 1, 4, 1, 16, 3);
helper.drawTexture(matrices, r.getX() + 1, y + 22, 4, 22, 16, 3);
context.drawTexture(MORE_SLOTS, r.getX() + 1, y + 1, 4, 1, 16, 3);
context.drawTexture(MORE_SLOTS, r.getX() + 1, y + 22, 4, 22, 16, 3);
}
} else {
helper.drawTexture(matrices, x + 4, y + 4, 4, 4, 18, 18);
context.drawTexture(MORE_SLOTS, x + 4, y + 4, 4, 4, 18, 18);
}

matrices.pop();
context.getMatrices().pop();
RenderSystem.disableDepthTest();
}

public static void drawActiveGroup(DrawableHelper helper, MatrixStack matrices) {
public static void drawActiveGroup(DrawContext context) {
if (TrinketsClient.activeGroup != null) {
TrinketScreenManager.drawGroup(helper, matrices, TrinketsClient.activeGroup, TrinketsClient.activeType);
TrinketScreenManager.drawGroup(context, TrinketsClient.activeGroup, TrinketsClient.activeType);
} else if (TrinketsClient.quickMoveGroup != null) {
TrinketScreenManager.drawGroup(helper, matrices, TrinketsClient.quickMoveGroup, TrinketsClient.quickMoveType);
TrinketScreenManager.drawGroup(context, TrinketsClient.quickMoveGroup, TrinketsClient.quickMoveType);
}
}

public static void drawExtraGroups(DrawableHelper helper, MatrixStack matrices) {
public static void drawExtraGroups(DrawContext context) {
TrinketPlayerScreenHandler handler = currentScreen.trinkets$getHandler();
int x = currentScreen.trinkets$getX();
int y = currentScreen.trinkets$getY();
Expand All @@ -282,38 +280,37 @@ public static void drawExtraGroups(DrawableHelper helper, MatrixStack matrices)
height = 4;
width--;
}
RenderSystem.setShaderTexture(0, MORE_SLOTS);
helper.drawTexture(matrices, x + 3, y, 7, 26, 1, 7);
context.drawTexture(MORE_SLOTS, x + 3, y, 7, 26, 1, 7);
// Repeated tops and bottoms
for (int i = 0; i < width; i++) {
helper.drawTexture(matrices, x - 15 - 18 * i, y, 7, 26, 18, 7);
helper.drawTexture(matrices, x - 15 - 18 * i, y + 79, 7, 51, 18, 7);
context.drawTexture(MORE_SLOTS, x - 15 - 18 * i, y, 7, 26, 18, 7);
context.drawTexture(MORE_SLOTS, x - 15 - 18 * i, y + 79, 7, 51, 18, 7);
}
// Top and bottom
helper.drawTexture(matrices, x - 15 - 18 * width, y, 7, 26, 18, 7);
helper.drawTexture(matrices, x - 15 - 18 * width, y + 7 + 18 * height, 7, 51, 18, 7);
context.drawTexture(MORE_SLOTS, x - 15 - 18 * width, y, 7, 26, 18, 7);
context.drawTexture(MORE_SLOTS, x - 15 - 18 * width, y + 7 + 18 * height, 7, 51, 18, 7);
// Corners
helper.drawTexture(matrices, x - 22 - 18 * width, y, 0, 26, 7, 7);
helper.drawTexture(matrices, x - 22 - 18 * width, y + 7 + 18 * height, 0, 51, 7, 7);
context.drawTexture(MORE_SLOTS, x - 22 - 18 * width, y, 0, 26, 7, 7);
context.drawTexture(MORE_SLOTS, x - 22 - 18 * width, y + 7 + 18 * height, 0, 51, 7, 7);
// Outer sides
for (int i = 0; i < height; i++) {
helper.drawTexture(matrices, x - 22 - 18 * width, y + 7 + 18 * i, 0, 34, 7, 18);
context.drawTexture(MORE_SLOTS, x - 22 - 18 * width, y + 7 + 18 * i, 0, 34, 7, 18);
}
// Inner sides
if (width > 0) {
for (int i = height; i < 4; i++) {
helper.drawTexture(matrices, x - 4 - 18 * width, y + 7 + 18 * i, 0, 34, 7, 18);
context.drawTexture(MORE_SLOTS, x - 4 - 18 * width, y + 7 + 18 * i, 0, 34, 7, 18);
}
}
if (width > 0 && height < 4) {
// Bottom corner
helper.drawTexture(matrices, x - 4 - 18 * width, y + 79, 0, 51, 7, 7);
context.drawTexture(MORE_SLOTS, x - 4 - 18 * width, y + 79, 0, 51, 7, 7);
// Inner corner
helper.drawTexture(matrices, x - 4 - 18 * width, y + 7 + 18 * height, 0, 58, 7, 7);
context.drawTexture(MORE_SLOTS, x - 4 - 18 * width, y + 7 + 18 * height, 0, 58, 7, 7);
}
if (width > 0 || height == 4) {
// Inner corner
helper.drawTexture(matrices, x, y + 79, 0, 58, 3, 7);
context.drawTexture(MORE_SLOTS, x, y + 79, 0, 58, 3, 7);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/emi/trinkets/api/TrinketsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static Optional<TrinketComponent> getTrinketComponent(LivingEntity living
* called in the callback of {@link ItemStack#damage(int, LivingEntity, Consumer)}
*/
public static void onTrinketBroken(ItemStack stack, SlotReference ref, LivingEntity entity) {
if (!entity.world.isClient) {
if (!entity.getWorld().isClient) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(entity.getId());
buf.writeString(ref.inventory().getSlotType().getGroup() + "/" + ref.inventory().getSlotType().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.emi.trinkets.mixin;

import dev.emi.trinkets.TrinketsClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.util.math.MatrixStack;
import org.objectweb.asm.Opcodes;
Expand All @@ -25,7 +26,7 @@ public abstract class ClickableWidgetMixin {

@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/widget/ClickableWidget;hovered:Z",
opcode = Opcodes.PUTFIELD, ordinal = 0, shift = Shift.AFTER), method = "render")
private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
private void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo info) {
if (TrinketsClient.activeGroup != null) {
hovered = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class ClientPlayNetworkHandlerMixin {

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setId(I)V"), method = "onPlayerRespawn", locals = LocalCapture.CAPTURE_FAILSOFT)
private void onPlayerRespawn(PlayerRespawnS2CPacket packet, CallbackInfo ci, RegistryKey<?> registryKey, RegistryEntry<?> registryEntry, ClientPlayerEntity clientPlayerEntity, int i, String string, ClientPlayerEntity clientPlayerEntity2) {
private void onPlayerRespawn(PlayerRespawnS2CPacket packet, CallbackInfo info, RegistryKey<?> registryKey, RegistryEntry<?> registryEntry, ClientPlayerEntity clientPlayerEntity, int i, String string, ClientPlayerEntity clientPlayerEntity2) {
if (packet.hasFlag(PlayerRespawnS2CPacket.KEEP_ATTRIBUTES)) {
TrinketInventory.copyFrom(clientPlayerEntity, clientPlayerEntity2);
((TrinketPlayerScreenHandler) clientPlayerEntity2.playerScreenHandler).trinkets$updateTrinketSlots(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.emi.trinkets.mixin;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemGroups;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -51,7 +52,7 @@ private int size(DefaultedList<ItemStack> list) {

@Inject(at = @At("HEAD"), method = "setSelectedTab")
private void setSelectedTab(ItemGroup g, CallbackInfo info) {
if (g != ItemGroups.INVENTORY) {
if (g.getType() != ItemGroup.Type.INVENTORY) {
TrinketScreenManager.removeSelections();
}
}
Expand Down Expand Up @@ -91,29 +92,29 @@ private void tick(CallbackInfo info) {
}

@Inject(at = @At("HEAD"), method = "render")
private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
if (selectedTab == ItemGroups.INVENTORY) {
private void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo info) {
if (selectedTab.getType() == ItemGroup.Type.INVENTORY) {
TrinketScreenManager.update(mouseX, mouseY);
}
}

@Inject(at = @At("RETURN"), method = "drawBackground")
private void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY, CallbackInfo info) {
if (selectedTab == ItemGroups.INVENTORY) {
TrinketScreenManager.drawExtraGroups(this, matrices);
private void drawBackground(DrawContext context, float delta, int mouseX, int mouseY, CallbackInfo info) {
if (selectedTab.getType() == ItemGroup.Type.INVENTORY) {
TrinketScreenManager.drawExtraGroups(context);
}
}

@Inject(at = @At("TAIL"), method = "drawForeground")
private void drawForeground(MatrixStack matrices, int mouseX, int mouseY, CallbackInfo info) {
if (selectedTab == ItemGroups.INVENTORY) {
TrinketScreenManager.drawActiveGroup(this, matrices);
private void drawForeground(DrawContext context, int mouseX, int mouseY, CallbackInfo info) {
if (selectedTab.getType() == ItemGroup.Type.INVENTORY) {
TrinketScreenManager.drawActiveGroup(context);
}
}

@Inject(at = @At("HEAD"), method = "isClickOutsideBounds", cancellable = true)
private void isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int button, CallbackInfoReturnable<Boolean> info) {
if (selectedTab == ItemGroups.INVENTORY && TrinketScreenManager.isClickInsideTrinketBounds(mouseX, mouseY)) {
if (selectedTab.getType() == ItemGroup.Type.INVENTORY && TrinketScreenManager.isClickInsideTrinketBounds(mouseX, mouseY)) {
info.setReturnValue(false);
}
}
Expand All @@ -126,7 +127,7 @@ private void isClickInTab(ItemGroup group, double mouseX, double mouseY, Callbac
}

@Inject(at = @At("HEAD"), method = "renderTabTooltipIfHovered", cancellable = true)
private void renderTabTooltipIfHovered(MatrixStack matrices, ItemGroup group, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> info) {
private void renderTabTooltipIfHovered(DrawContext context, ItemGroup group, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> info) {
if (TrinketsClient.activeGroup != null) {
info.setReturnValue(false);
}
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/dev/emi/trinkets/mixin/HandledScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;

import dev.emi.trinkets.TrinketScreenManager;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -48,35 +49,32 @@ private void removed(CallbackInfo info) {

@Inject(at = @At(value = "INVOKE", target = "net/minecraft/client/util/math/MatrixStack.translate(FFF)V"),
method = "drawSlot")
private void changeZ(MatrixStack matrices, Slot slot, CallbackInfo info) {
private void changeZ(DrawContext context, Slot slot, CallbackInfo info) {
// Items are drawn at z + 150 (normal items are drawn at 250)
// Item tooltips (count, item bar) are drawn at z + 200 (normal itmes are drawn at 300)
// Inventory tooltip is drawn at 400
if (slot instanceof TrinketSlot ts) {
assert this.client != null;
Identifier id = ts.getBackgroundIdentifier();
Identifier slotTextureId = ts.getBackgroundIdentifier();

if (slot.getStack().isEmpty() && id != null) {
RenderSystem.setShaderTexture(0, id);
} else {
RenderSystem.setShaderTexture(0, BLANK_BACK);
if (!slot.getStack().isEmpty() || slotTextureId == null) {
slotTextureId = BLANK_BACK;
}

RenderSystem.enableDepthTest();

if (ts.isTrinketFocused()) {
// Thus, I need to draw trinket slot backs over normal items at z 300 (310 was chosen)
drawTexture(matrices, slot.x, slot.y, 310, 0, 0, 16, 16, 16, 16);
context.drawTexture(slotTextureId, slot.x, slot.y, 310, 0, 0, 16, 16, 16, 16);
// I also need to draw items in trinket slots *above* 310 but *below* 400, (320 for items and 370 for tooltips was chosen)
matrices.translate(0, 0, 70);
context.getMatrices().translate(0, 0, 70);
} else {
drawTexture(matrices, slot.x, slot.y, 0, 0, 0, 16, 16, 16, 16);
RenderSystem.setShaderTexture(0, MORE_SLOTS);
drawTexture(matrices, slot.x - 1, slot.y - 1, 0, 4, 4, 18, 18, 256, 256);
context.drawTexture(slotTextureId, slot.x, slot.y, 0, 0, 0, 16, 16, 16, 16);
context.drawTexture(MORE_SLOTS, slot.x - 1, slot.y - 1, 0, 4, 4, 18, 18, 256, 256);
}
}
if (TrinketsClient.activeGroup != null && TrinketsClient.activeGroup.getSlotId() == slot.id) {
matrices.translate(0, 0, 70);
context.getMatrices().translate(0, 0, 70);
}

}
Expand Down
Loading

0 comments on commit 1a3f70f

Please sign in to comment.