forked from emilyploszaj/trinkets
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into main
# Conflicts: # build.gradle # gradle.properties # src/main/java/dev/emi/trinkets/SurvivalTrinketSlot.java # src/main/java/dev/emi/trinkets/TrinketScreenManager.java # src/main/java/dev/emi/trinkets/api/TrinketsApi.java # src/main/java/dev/emi/trinkets/mixin/ClickableWidgetMixin.java # src/main/java/dev/emi/trinkets/mixin/ClientPlayNetworkHandlerMixin.java # src/main/java/dev/emi/trinkets/mixin/CreativeInventoryScreenMixin.java # src/main/java/dev/emi/trinkets/mixin/HandledScreenMixin.java # src/main/java/dev/emi/trinkets/mixin/InventoryScreenMixin.java # src/main/java/dev/emi/trinkets/mixin/LivingEntityMixin.java # src/main/java/dev/emi/trinkets/mixin/PlayerScreenHandlerMixin.java # src/main/resources/trinkets.mixins.json
- Loading branch information
Showing
7 changed files
with
243 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/dev/emi/trinkets/mixin/HandledScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package dev.emi.trinkets.mixin; | ||
|
||
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; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.At.Shift; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import dev.emi.trinkets.TrinketSlot; | ||
import dev.emi.trinkets.TrinketsClient; | ||
import dev.emi.trinkets.mixin.accessor.CreativeSlotAccessor; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen.CreativeSlot; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.util.Identifier; | ||
|
||
/** | ||
* Draws trinket slot backs, adjusts z location of draw calls, and makes non-trinket slots un-interactable while a trinket slot group is focused | ||
* | ||
* @author Emi | ||
*/ | ||
@Mixin(HandledScreen.class) | ||
public abstract class HandledScreenMixin extends Screen { | ||
@Unique | ||
private static final Identifier MORE_SLOTS = new Identifier("trinkets", "textures/gui/more_slots.png"); | ||
@Unique | ||
private static final Identifier BLANK_BACK = new Identifier("trinkets", "textures/gui/blank_back.png"); | ||
|
||
private HandledScreenMixin() { | ||
super(null); | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "removed") | ||
private void removed(CallbackInfo info) { | ||
if ((Object)this instanceof InventoryScreen) { | ||
TrinketScreenManager.removeSelections(); | ||
} | ||
} | ||
|
||
@Inject(at = @At(value = "INVOKE", target = "net/minecraft/client/util/math/MatrixStack.translate(FFF)V"), | ||
method = "drawSlot") | ||
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 slotTextureId = ts.getBackgroundIdentifier(); | ||
|
||
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) | ||
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) | ||
context.getMatrices().translate(0, 0, 70); | ||
} else { | ||
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) { | ||
context.getMatrices().translate(0, 0, 70); | ||
} | ||
|
||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "isPointOverSlot", cancellable = true) | ||
private void isPointOverSlot(Slot slot, double pointX, double pointY, CallbackInfoReturnable<Boolean> info) { | ||
if (TrinketsClient.activeGroup != null) { | ||
if (slot instanceof TrinketSlot ts) { | ||
if (!ts.isTrinketFocused()) { | ||
info.setReturnValue(false); | ||
} | ||
} else { | ||
if (slot instanceof CreativeSlot cs) { | ||
if (((CreativeSlotAccessor) cs).getSlot().id != TrinketsClient.activeGroup.getSlotId()) { | ||
info.setReturnValue(false); | ||
} | ||
} else if (slot.id != TrinketsClient.activeGroup.getSlotId()) { | ||
info.setReturnValue(false); | ||
} | ||
} | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/dev/emi/trinkets/mixin/InventoryScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package dev.emi.trinkets.mixin; | ||
|
||
import net.minecraft.client.gui.DrawContext; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import dev.emi.trinkets.Point; | ||
import dev.emi.trinkets.TrinketPlayerScreenHandler; | ||
import dev.emi.trinkets.TrinketScreen; | ||
import dev.emi.trinkets.TrinketScreenManager; | ||
import dev.emi.trinkets.api.SlotGroup; | ||
import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; | ||
import net.minecraft.client.gui.screen.ingame.InventoryScreen; | ||
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.client.util.math.Rect2i; | ||
import net.minecraft.screen.PlayerScreenHandler; | ||
import net.minecraft.screen.slot.Slot; | ||
|
||
/** | ||
* Delegates drawing and slot group selection logic | ||
* | ||
* @author Emi | ||
*/ | ||
@Mixin(InventoryScreen.class) | ||
public abstract class InventoryScreenMixin extends AbstractInventoryScreen<PlayerScreenHandler> implements RecipeBookProvider, TrinketScreen { | ||
|
||
private InventoryScreenMixin() { super(null, null, null); } | ||
|
||
@Inject(at = @At("HEAD"), method = "init") | ||
private void init(CallbackInfo info) { | ||
TrinketScreenManager.init(this); | ||
} | ||
|
||
@Inject(at = @At("TAIL"), method = "handledScreenTick") | ||
private void tick(CallbackInfo info) { | ||
TrinketScreenManager.tick(); | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "render") | ||
private void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo info) { | ||
TrinketScreenManager.update(mouseX, mouseY); | ||
} | ||
|
||
@Inject(at = @At("RETURN"), method = "drawBackground") | ||
private void drawBackground(DrawContext context, float delta, int mouseX, int mouseY, CallbackInfo info) { | ||
TrinketScreenManager.drawExtraGroups(context); | ||
} | ||
|
||
@Inject(at = @At("TAIL"), method = "drawForeground") | ||
private void drawForeground(DrawContext context, int mouseX, int mouseY, CallbackInfo info) { | ||
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 (TrinketScreenManager.isClickInsideTrinketBounds(mouseX, mouseY)) { | ||
info.setReturnValue(false); | ||
} | ||
} | ||
|
||
@Override | ||
public TrinketPlayerScreenHandler trinkets$getHandler() { | ||
return (TrinketPlayerScreenHandler) this.handler; | ||
} | ||
|
||
@Override | ||
public Rect2i trinkets$getGroupRect(SlotGroup group) { | ||
Point pos = ((TrinketPlayerScreenHandler) handler).trinkets$getGroupPos(group); | ||
if (pos != null) { | ||
return new Rect2i(pos.x() - 1, pos.y() - 1, 17, 17); | ||
} | ||
return new Rect2i(0, 0, 0, 0); | ||
} | ||
|
||
@Override | ||
public Slot trinkets$getFocusedSlot() { | ||
return this.focusedSlot; | ||
} | ||
|
||
@Override | ||
public int trinkets$getX() { | ||
return this.x; | ||
} | ||
|
||
@Override | ||
public int trinkets$getY() { | ||
return this.y; | ||
} | ||
|
||
@Override | ||
public boolean trinkets$isRecipeBookOpen() { | ||
return this.getRecipeBookWidget().isOpen(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/dev/emi/trinkets/mixin/LivingEntityRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dev.emi.trinkets.mixin; | ||
|
||
import dev.emi.trinkets.TrinketFeatureRenderer; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.render.entity.EntityRendererFactory; | ||
import net.minecraft.client.render.entity.LivingEntityRenderer; | ||
import net.minecraft.client.render.entity.feature.FeatureRenderer; | ||
import net.minecraft.client.render.entity.model.EntityModel; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
/** | ||
* Adds the trinket feature renderer to the list of living entity features | ||
* | ||
* @author C4 | ||
* @author powerboat9 | ||
*/ | ||
@Environment(EnvType.CLIENT) | ||
@Mixin(LivingEntityRenderer.class) | ||
public abstract class LivingEntityRendererMixin { | ||
@Invoker("addFeature") | ||
public abstract boolean invokeAddFeature(FeatureRenderer<?, ?> feature); | ||
|
||
@Inject(at = @At("RETURN"), method = "<init>") | ||
public void init(EntityRendererFactory.Context ctx, EntityModel<?> model, float shadowRadius, CallbackInfo info) { | ||
this.invokeAddFeature(new TrinketFeatureRenderer<>((LivingEntityRenderer<?, ?>) (Object) this)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/testmod/resources/data/trinkets/entities/trinkets-testmod.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"entities": ["player"], | ||
"entities": ["player", "zombie"], | ||
"slots": [ | ||
"hand/glove", | ||
"hand/ring", | ||
|