Skip to content

Commit

Permalink
Separate ItemSlot & ItemSlotLong implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
miozune committed Aug 16, 2024
1 parent 34e4f46 commit 829e1b9
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

import net.minecraft.item.ItemStack;

import javax.annotation.Nullable;

public interface IItemHandlerLong extends IItemHandlerModifiable {

void setStackInSlotLong(int slot, IItemStackLong stack);

@Override
default void setStackInSlot(int slot, ItemStack stack) {
setStackInSlotLong(slot, new ItemStackLong(stack));
default void setStackInSlot(int slot, @Nullable ItemStack stack) {
setStackInSlotLong(slot, stack == null ? null : new ItemStackLong(stack));
}

IItemStackLong extractItemLong(int slot, long amount, boolean simulate);
Expand Down Expand Up @@ -51,8 +53,8 @@ default List<IItemStackLong> getStacksLong() {
IItemStackLong insertItemLong(int slot, IItemStackLong stack, boolean simulate);

@Override
default ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
IItemStackLong item = insertItemLong(slot, new ItemStackLong(stack), simulate);
default ItemStack insertItem(int slot, @Nullable ItemStack stack, boolean simulate) {
IItemStackLong item = insertItemLong(slot, stack == null ? null : new ItemStackLong(stack), simulate);
return item == null ? null : item.getAsItemStack();
}

Expand All @@ -61,8 +63,8 @@ default boolean isItemValidLong(int slot, IItemStackLong stack) {
}

@Override
default boolean isItemValid(int slot, ItemStack stack) {
return isItemValidLong(slot, new ItemStackLong(stack));
default boolean isItemValid(int slot, @Nullable ItemStack stack) {
return isItemValidLong(slot, stack == null ? null : new ItemStackLong(stack));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;

// Changes made here probably should also be made to FluidSlotSyncHandler
public class FluidSlotLongSyncHandler extends ValueSyncHandler<IFluidTankLong> {

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

// Changes made here probably should also be made to FluidSlotLongSyncHandler
public class FluidSlotSyncHandler extends ValueSyncHandler<FluidStack> {

public static boolean isFluidEmpty(@Nullable FluidStack fluidStack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;

// Changes made here probably should also be made to ItemSlotSH
public class ItemSlotLongSH extends SyncHandler {

private final ModularSlotLong slot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Wraps a slot and handles interactions for phantom slots.
* Use {@link ModularSlot} directly.
*/
// Changes made here probably should also be made to ItemSlotLongSH
public class ItemSlotSH extends SyncHandler {

private final ModularSlot slot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import static com.cleanroommc.modularui.ModularUI.isGT5ULoaded;

// Changes made here probably should also be made to FluidSlotLong
public class FluidSlot extends Widget<FluidSlot> implements Interactable, NEIDragAndDropHandler, NEIIngredientProvider {

public static final int DEFAULT_SIZE = 18;
Expand Down Expand Up @@ -225,23 +226,23 @@ public IFluidTank getFluidTank() {
public FluidSlot contentOffset(int x, int y) {
this.contentOffsetX = x;
this.contentOffsetY = y;
return getThis();
return this;
}

/**
* @param alwaysShowFull if the fluid should be rendered as full or as the partial amount.
*/
public FluidSlot alwaysShowFull(boolean alwaysShowFull) {
this.alwaysShowFull = alwaysShowFull;
return getThis();
return this;
}

/**
* @param overlayTexture texture that is rendered on top of the fluid
*/
public FluidSlot overlayTexture(@Nullable IDrawable overlayTexture) {
this.overlayTexture = overlayTexture;
return getThis();
return this;
}

public FluidSlot syncHandler(IFluidTank fluidTank) {
Expand All @@ -251,7 +252,7 @@ public FluidSlot syncHandler(IFluidTank fluidTank) {
public FluidSlot syncHandler(FluidSlotSyncHandler syncHandler) {
setSyncHandler(syncHandler);
this.syncHandler = syncHandler;
return getThis();
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import static com.cleanroommc.modularui.ModularUI.isGT5ULoaded;

// Changes made here probably should also be made to FluidSlot
public class FluidSlotLong extends Widget<FluidSlotLong> implements Interactable, NEIDragAndDropHandler, NEIIngredientProvider {

public static final int DEFAULT_SIZE = 18;
Expand Down Expand Up @@ -235,23 +236,23 @@ public IFluidTankLong getFluidTankLong() {
public FluidSlotLong contentOffset(int x, int y) {
this.contentOffsetX = x;
this.contentOffsetY = y;
return getThis();
return this;
}

/**
* @param alwaysShowFull if the fluid should be rendered as full or as the partial amount.
*/
public FluidSlotLong alwaysShowFull(boolean alwaysShowFull) {
this.alwaysShowFull = alwaysShowFull;
return getThis();
return this;
}

/**
* @param overlayTexture texture that is rendered on top of the fluid
*/
public FluidSlotLong overlayTexture(@Nullable IDrawable overlayTexture) {
this.overlayTexture = overlayTexture;
return getThis();
return this;
}

public FluidSlotLong syncHandler(IFluidTank fluidTank) {
Expand All @@ -268,7 +269,7 @@ public FluidSlotLong syncHandler(IFluidTankLong fluidTank) {
public FluidSlotLong syncHandler(FluidSlotLongSyncHandler syncHandler) {
setSyncHandler(syncHandler);
this.syncHandler = syncHandler;
return getThis();
return this;
}

@Override
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@

import static com.cleanroommc.modularui.ModularUI.isNEILoaded;

public class ItemSlot<W extends ItemSlot<W>> extends Widget<W> implements IVanillaSlot, Interactable, NEIDragAndDropHandler, NEIIngredientProvider {
// Changes made here probably should also be made to ItemSlotLong
public class ItemSlot extends Widget<ItemSlot> implements IVanillaSlot, Interactable, NEIDragAndDropHandler, NEIIngredientProvider {

public static final int SIZE = 18;

Expand Down Expand Up @@ -174,13 +175,13 @@ protected List<String> getItemTooltip(ItemStack stack) {
return tooltips;
}

public W slot(ModularSlot slot) {
public ItemSlot slot(ModularSlot slot) {
this.syncHandler = new ItemSlotSH(slot);
setSyncHandler(this.syncHandler);
return getThis();
return this;
}

public W slot(IItemHandlerModifiable itemHandler, int index) {
public ItemSlot slot(IItemHandlerModifiable itemHandler, int index) {
return slot(new ModularSlot(itemHandler, index));
}

Expand All @@ -192,7 +193,7 @@ private void drawSlot(ModularSlot slotIn) {
boolean flag = false;
boolean flag1 = slotIn == accessor.getClickedSlot() && accessor.getDraggedStack() != null && !accessor.getIsRightMouseClick();
ItemStack itemstack1 = guiScreen.mc.thePlayer.inventory.getItemStack();
long amount = -1;
int amount = -1;
String format = null;

if (slotIn == accessor.getClickedSlot() && accessor.getDraggedStack() != null && accessor.getIsRightMouseClick() && itemstack != null) {
Expand Down
Loading

0 comments on commit 829e1b9

Please sign in to comment.