-
Notifications
You must be signed in to change notification settings - Fork 7
Cabinet #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| } | ||
|
|
||
| @Override | ||
| public void setStackInSlot(int slot, ItemStack stack) { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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;
}
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