forked from CleanroomMC/ModularUI
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement long versions of ItemStack and FluidTanks (#6)
* Convert dropdown to use new non-deprecated methods * Initial work for item and fluids to long * Implement FluidTankHandlers * Working guis with transition to new itemstacks * Transfer more methods to IItemStackLong * port FluidStackTank * Make fluids slots functional * Revert ItemSlot to ItemStack will be making new ones to be like FluidSlot. * Implement ListItemHandler * Implement ItemStackLong handlers * First implementation of ItemSlotLong * Add method for slot and disable others * Add missed comments * Address reviews and fix style changes accidents * Add some annotations * Remove forgotten reference * convert the last classes using delegate * add new lines on end of file * remove saved type nbt and move methods * address reviews about style and errors * missed enhanced forloop * remove cache null check
- Loading branch information
Showing
42 changed files
with
2,830 additions
and
214 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
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
72 changes: 72 additions & 0 deletions
72
src/main/java/com/cleanroommc/modularui/api/IFluidTankLong.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,72 @@ | ||
package com.cleanroommc.modularui.api; | ||
|
||
import static com.google.common.primitives.Ints.saturatedCast; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraftforge.fluids.Fluid; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import net.minecraftforge.fluids.FluidTankInfo; | ||
import net.minecraftforge.fluids.IFluidTank; | ||
|
||
public interface IFluidTankLong extends IFluidTank { | ||
|
||
/** | ||
* @param maxDrain The max amount to be drained | ||
* @param doDrain Do we actually drain the tank | ||
* @return The amount of fluid drained | ||
*/ | ||
long drainLong(long maxDrain, boolean doDrain); | ||
|
||
/** | ||
* @param fluid The fluid we want to put in | ||
* @param amount The amount we want to put in | ||
* @param doFill Do we actually fill the tank | ||
* @return The amount of fluid filled into the tank | ||
*/ | ||
long fillLong(@Nullable Fluid fluid, long amount, boolean doFill); | ||
|
||
long getCapacityLong(); | ||
|
||
long getFluidAmountLong(); | ||
|
||
Fluid getRealFluid(); | ||
|
||
void setFluid(@Nullable Fluid fluid, long amount); | ||
|
||
@Override | ||
default FluidStack drain(int maxDrain, boolean doDrain) { | ||
final FluidStack fluid = new FluidStack(getRealFluid(), 0); | ||
fluid.amount = saturatedCast(drainLong(maxDrain, doDrain)); | ||
return fluid; | ||
} | ||
|
||
@Override | ||
default int fill(FluidStack resource, boolean doFill) { | ||
return saturatedCast(fillLong(resource.getFluid(), resource.amount, doFill)); | ||
} | ||
|
||
@Override | ||
default int getCapacity() { | ||
return saturatedCast(getCapacityLong()); | ||
} | ||
|
||
@Override | ||
default FluidStack getFluid() { | ||
if (getRealFluid() == null) return null; | ||
return new FluidStack(getRealFluid(), getFluidAmount()); | ||
} | ||
|
||
@Override | ||
default int getFluidAmount() { | ||
return saturatedCast(getFluidAmountLong()); | ||
} | ||
|
||
@Override | ||
default FluidTankInfo getInfo() { | ||
return new FluidTankInfo(getFluid(), getCapacity()); | ||
} | ||
|
||
IFluidTankLong copy(); | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/cleanroommc/modularui/api/IItemStackLong.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,62 @@ | ||
package com.cleanroommc.modularui.api; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
import com.cleanroommc.modularui.utils.item.ItemStackLong; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
|
||
public interface IItemStackLong { | ||
|
||
/** | ||
* @return The stacksize the item has currently | ||
*/ | ||
long getStackSize(); | ||
|
||
/** | ||
* @return The max stacksize of the item | ||
*/ | ||
long getMaxStackSize(); | ||
|
||
/** | ||
* @return The item it was created from | ||
*/ | ||
Item getItem(); | ||
|
||
/** | ||
* @return The damage the item has. Its meta id | ||
*/ | ||
int getItemDamage(); | ||
|
||
/** | ||
* @return NBT data the item holds | ||
*/ | ||
@Nullable NBTTagCompound getTagCompound(); | ||
|
||
/** | ||
* @param newStackSize The new stacksize the itemstack should have | ||
*/ | ||
void setStackSize(long newStackSize); | ||
|
||
/** | ||
* @return The current ItemStackLong as a ItemStack, this stack shouldn't be edited as it won't reflect upon the real one | ||
*/ | ||
@Nonnull ItemStack getAsItemStack(); | ||
|
||
boolean isItemEqual(@Nullable IItemStackLong other); | ||
|
||
boolean hasTagCompound(); | ||
|
||
boolean isStackable(); | ||
|
||
boolean getHasSubtypes(); | ||
|
||
@Nonnull IItemStackLong copy(); | ||
|
||
@Nonnull IItemStackLong splitStack(long toSplit); | ||
|
||
@Nonnull NBTTagCompound writeToNBT(@Nonnull NBTTagCompound nbt); | ||
} |
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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/cleanroommc/modularui/future/IItemHandlerLong.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,69 @@ | ||
package com.cleanroommc.modularui.future; | ||
|
||
import static com.google.common.primitives.Ints.saturatedCast; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.cleanroommc.modularui.api.IItemStackLong; | ||
import com.cleanroommc.modularui.utils.item.ItemStackLong; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
public interface IItemHandlerLong extends IItemHandlerModifiable { | ||
|
||
void setStackInSlotLong(int slot, IItemStackLong stack); | ||
|
||
@Override | ||
default void setStackInSlot(int slot, ItemStack stack) { | ||
setStackInSlotLong(slot, new ItemStackLong(stack)); | ||
} | ||
|
||
IItemStackLong extractItemLong(int slot, long amount, boolean simulate); | ||
|
||
@Override | ||
default ItemStack extractItem(int slot, int amount, boolean simulate) { | ||
IItemStackLong item = extractItemLong(slot, amount, simulate); | ||
return item == null ? null : item.getAsItemStack(); | ||
} | ||
|
||
long getSlotLimitLong(int slot); | ||
|
||
@Override | ||
default int getSlotLimit(int slot) { | ||
return saturatedCast(getSlotLimitLong(slot)); | ||
} | ||
|
||
IItemStackLong getStackInSlotLong(int slot); | ||
|
||
@Override | ||
default ItemStack getStackInSlot(int slot) { | ||
IItemStackLong item = getStackInSlotLong(slot); | ||
return item == null ? null : item.getAsItemStack(); | ||
} | ||
|
||
default List<IItemStackLong> getStacksLong() { | ||
List<IItemStackLong> ret = new ArrayList<>(); for (int i = 0; i < getSlots(); i++) { | ||
ret.add(getStackInSlotLong(i)); | ||
} | ||
return ret; | ||
} | ||
|
||
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); | ||
return item == null ? null : item.getAsItemStack(); | ||
} | ||
|
||
default boolean isItemValidLong(int slot, IItemStackLong stack) { | ||
return true; | ||
} | ||
|
||
@Override | ||
default boolean isItemValid(int slot, ItemStack stack) { | ||
return isItemValidLong(slot, new ItemStackLong(stack)); | ||
} | ||
|
||
} |
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
Oops, something went wrong.