Skip to content

Commit

Permalink
No longer modify inventory if no slots were added
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewperiut committed May 18, 2024
1 parent bd963d6 commit f91a7d7
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}
dependencies {
modImplementation('com.github.matthewperiut:accessory-api:0.5.1') {
modImplementation('com.github.matthewperiut:accessory-api:0.6.3') {
transitive false
}
}
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ dependencies {
modImplementation("com.github.matthewperiut:spc-babric:${project.spc_version}") {
transitive false
}
modRuntimeOnly ("com.github.matthewperiut:gambac:e2ded011b0") { transitive false }

}

// add test tasks
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.parallel=true
loader_version=0.14.19-babric.1

# Mod Properties
mod_version = 0.6.2
mod_version = 0.6.3
maven_group = com.matthewperiut
archives_base_name = accessoryapi
stapi_version=2.0-alpha.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class AccessoryAPI implements ModInitializer {

@GConfig(value = "config", visibleName = "Accessory API Config")
public static AccessoryAPIConfigFields config = new AccessoryAPIConfigFields();
public static boolean noSlotsAdded = false;

@Override
public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package com.matthewperiut.accessoryapi.config;

import blue.endless.jankson.Comment;
import net.fabricmc.loader.api.FabricLoader;
import net.glasslauncher.mods.api.gcapi.api.ConfigName;
import net.glasslauncher.mods.api.gcapi.api.MultiplayerSynced;

public class AccessoryAPIConfigFields {
@ConfigName("Aether-Style Armor Slots")
@Comment("Essentially whether you want armor slots to the right of the player doll.")
public Boolean aetherStyleArmor = true;
public Boolean aetherStyleArmor = false;

@MultiplayerSynced
@ConfigName("Armor offset")
@Comment("If you don't know what this does, don't touch it!")
public Integer armorOffset = 4;

// @ConfigName("UI Style")
// public Style style = Style.AETHER;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public abstract class PlayerContainerMixin extends ContainerBase {

@ModifyArg(method = "<init>(Lnet/minecraft/entity/player/PlayerInventory;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerContainer;addSlot(Lnet/minecraft/container/slot/Slot;)V"), index = 0)
private Slot changeTopSlots(Slot par1) {
AccessorySlotStorage.initializeCustomAccessoryPositions();
if (AccessoryAPI.noSlotsAdded)
return par1;

if (par1.x == 144) // x of crafting result
{
Expand Down Expand Up @@ -54,9 +57,10 @@ private Slot changeTopSlots(Slot par1) {

@Inject(method = "<init>(Lnet/minecraft/entity/player/PlayerInventory;Z)V", at = @At(value = "TAIL"))
private void addSlots(PlayerInventory inv, boolean par2, CallbackInfo ci) {
int slotnum = 40;
if (AccessoryAPI.noSlotsAdded)
return;

AccessorySlotStorage.initializeCustomAccessoryPositions();
int slotnum = 40;

for (AccessorySlotStorage.PreservedSlot slot : slotOrder) {
addSlot(new AccessorySlot(inv, slotnum, slot.pos.x + 18, slot.pos.z, slot.slotType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ protected void buttonClicked(Button button, CallbackInfo ci) {

@Inject(method = "renderContainerBackground", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glEnable(I)V", ordinal = 0))
public void bindAetherPlayerGuiTexture(float par1, CallbackInfo ci) {
if (AccessoryAPI.noSlotsAdded)
return;

int var2 = minecraft.textureManager.getTextureId("/assets/accessoryapi/inventory.png");
minecraft.textureManager.bindTexture(var2);

Expand Down Expand Up @@ -137,7 +140,7 @@ public void blitButCaptureWindowPos(PlayerInventory instance, int i, int j, int

@Redirect(method = "renderContainerBackground", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glTranslatef(FFF)V"))
public void translateAetherPlayerModel(float x, float y, float z) {
if (!AccessoryAPI.config.aetherStyleArmor) {
if (!AccessoryAPI.config.aetherStyleArmor || AccessoryAPI.noSlotsAdded) {
GL11.glTranslatef(x, y, z);
return;
}
Expand All @@ -150,7 +153,7 @@ public void translateAetherPlayerModel(float x, float y, float z) {
@Redirect(method = "renderContainerBackground", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/AbstractClientPlayer;yaw:F", opcode = Opcodes.PUTFIELD, ordinal = 0))
private void injected(AbstractClientPlayer instance, float value) {
float newValue;
if (!AccessoryAPI.config.aetherStyleArmor) {
if (!AccessoryAPI.config.aetherStyleArmor || AccessoryAPI.noSlotsAdded) {
newValue = value;
} else {
float var9 = (float) (wpx + 33) - mouseX;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.matthewperiut.accessoryapi.impl.slot;

import com.matthewperiut.accessoryapi.AccessoryAPI;
import net.minecraft.entity.player.PlayerContainer;

import static com.matthewperiut.accessoryapi.impl.slot.AccessorySlotStorage.hideOverflowSlots;
Expand All @@ -17,6 +18,9 @@ else if (slotInfo.size() < 5)
}

public static void resetPlayerInv(net.minecraft.container.ContainerBase container) {
if (AccessoryAPI.noSlotsAdded)
return;

if (container instanceof PlayerContainer pc) {
int crafting_offset_x = getCraftingOffset();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.matthewperiut.accessoryapi.impl.slot;

import com.matthewperiut.accessoryapi.AccessoryAPI;
import net.minecraft.container.slot.Slot;
import net.minecraft.entity.player.PlayerContainer;
import net.minecraft.util.maths.Vec2i;
Expand Down Expand Up @@ -89,6 +90,8 @@ public static void initializeCustomAccessoryPositions() {

if (slotOrder.size() > 8)
extraSlots = slotOrder.size() - 8;
if (slotOrder.isEmpty())
AccessoryAPI.noSlotsAdded = true;
}

public static void showOverflowSlots(PlayerContainer container) {
Expand Down

0 comments on commit f91a7d7

Please sign in to comment.