Skip to content

Conversation

@0hwx
Copy link
Member

@0hwx 0hwx commented Dec 30, 2025

Still missing:

Texture for the buttons

Texture for the elite cabinet

Tweak the GUI to look better

todo:

add upgrade item

and possibility switch to GTNHLib json models

}

@Override
public void setStackInSlot(int slot, ItemStack stack) {
Copy link

@Justxs Justxs Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could reduce nesting here

@Override
public void setStackInSlot(int slot, ItemStack stack) {
    validateSlotIndex(slot);

    if (isEmpty(stack)) {
        super.setStackInSlot(slot, null);
        onContentsChanged(slot);
        return;
    }

    for (int i = 0; i < getSlots() && stack.stackSize > 0; i++) {
        if (i == slot) {
            continue;
        }

        ItemStack existing = getStackInSlot(i);
        if (!canMerge(existing, stack)) {
            continue;
        }

        long transferable = Math.min(
            stack.stackSize,
            Math.min(getSlotLimit(i), getRemainingCapacity())
        );

        if (transferable <= 0) {
            continue;
        }

        existing.stackSize += transferable;
        stack.stackSize -= transferable;
        onContentsChanged(i);
    }

    super.setStackInSlot(slot, stack.stackSize > 0 ? stack : null);
    onContentsChanged(slot);
}

private static boolean isEmpty(ItemStack stack) {
    return stack == null || stack.stackSize <= 0;
}

private static boolean canMerge(ItemStack existing, ItemStack incoming) {
    return existing != null
        && incoming != null
        && ItemHandlerHelper.canItemStacksStack(existing, incoming);
}

updateCounts();
}

public void updateCounts() {
Copy link

@Justxs Justxs Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also nesting can be reduced here too

public void updateCounts() {
    itemCount = 0;
    usedSlotCount = 0;

    ItemStack firstStack = null;

    for (ItemStack stack : stacks) {
        if (!isValidStack(stack)) {
            continue;
        }

        usedSlotCount++;
        itemCount += stack.stackSize;

        if (firstStack == null) {
            firstStack = stack;
        }
    }

    itemMatcher = firstStack == null
        ? null
        : cabinet.extractMatcher(firstStack);
}
private static boolean isValidStack(ItemStack stack) {
    return stack != null && stack.stackSize > 0;
}

isValidStack method could be reused in other places too

this.yaw = yaw;
}

public static FacingRotation calculateFacingRotation(EntityLivingBase placer) {
Copy link

@Justxs Justxs Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be divided more:

public static FacingRotation calculateFacingRotation(EntityLivingBase placer) {
    ForgeDirection yaw = yawFromRotation(placer.rotationYaw);
    ForgeDirection facing = facingFromPitch(placer.rotationPitch, yaw);

    return new FacingRotation(facing, yaw);
}

private static ForgeDirection yawFromRotation(float rotationYaw) {
    int yawIndex =
        MathHelper.floor_double((rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

    switch (yawIndex) {
        case 1: return ForgeDirection.EAST;
        case 2: return ForgeDirection.SOUTH;
        case 3: return ForgeDirection.WEST;
        default: return ForgeDirection.NORTH;
    }
}

private static ForgeDirection facingFromPitch(float pitch, ForgeDirection yaw) {
    if (pitch > 55) {
        return ForgeDirection.UP;
    }
    if (pitch < -45) {
        return ForgeDirection.DOWN;
    }
    return yaw;
}

*
* This rotation value is NOT based on ForgeDirection.ordinal().
*/
default ForgeDirection getRotationForSide(ForgeDirection side, int meta) {
Copy link

@Justxs Justxs Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be a bit simpler

default ForgeDirection getRotationForSide(ForgeDirection side, int meta) {
    if (side != ForgeDirection.UP && side != ForgeDirection.DOWN) {
        return ForgeDirection.NORTH;
    }

    ForgeDirection facing = getFacing();
    if (facing != ForgeDirection.UP && facing != ForgeDirection.DOWN) {
        return ForgeDirection.NORTH;
    }

    ForgeDirection yaw = getYaw();
    return facing == ForgeDirection.UP
        ? yaw.getOpposite()
        : yaw;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants