-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/main/java/com/blueweabo/mutecore/api/host/FluidInventoryLogicHost.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.blueweabo.mutecore.api.host; | ||
|
||
import com.blueweabo.mutecore.api.logic.FluidInventoryLogic; | ||
import com.cleanroommc.modularui.api.IFluidTankLong; | ||
import com.cleanroommc.modularui.utils.fluid.FluidTankLong; | ||
|
||
import net.minecraftforge.common.util.ForgeDirection; | ||
import net.minecraftforge.fluids.Fluid; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import net.minecraftforge.fluids.FluidTankInfo; | ||
import net.minecraftforge.fluids.IFluidHandler; | ||
import net.minecraftforge.fluids.IFluidTank; | ||
|
||
public interface FluidInventoryLogicHost extends IFluidHandler { | ||
|
||
default FluidInventoryLogic getFluidLogic() { | ||
return getFluidLogic(ForgeDirection.UNKNOWN); | ||
} | ||
|
||
FluidInventoryLogic getFluidLogic(ForgeDirection side); | ||
|
||
@Override | ||
default boolean canDrain(ForgeDirection from, Fluid fluid) { | ||
FluidInventoryLogic logic = getFluidLogic(from); | ||
if (logic == null) return false; | ||
return logic.extract(new FluidTankLong(fluid), 1, false) != null; | ||
} | ||
|
||
@Override | ||
default boolean canFill(ForgeDirection from, Fluid fluid) { | ||
FluidInventoryLogic logic = getFluidLogic(from); | ||
if (logic == null) return false; | ||
return logic.insert(new FluidTankLong(fluid), 1, false) != null; | ||
} | ||
|
||
@Override | ||
default FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { | ||
FluidInventoryLogic logic = getFluidLogic(from); | ||
if (logic == null) return null; | ||
IFluidTankLong toDrain = new FluidTankLong(resource.getFluid()); | ||
IFluidTankLong drainTry = logic.extract(toDrain, resource.amount, doDrain); | ||
return drainTry == null ? null : drainTry.getFluid(); | ||
} | ||
|
||
@Override | ||
default FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { | ||
FluidInventoryLogic logic = getFluidLogic(from); | ||
if (logic == null) return null; | ||
IFluidTankLong drainTry = logic.extract(null, maxDrain, doDrain); | ||
return drainTry == null ? null : drainTry.getFluid(); | ||
} | ||
|
||
@Override | ||
default int fill(ForgeDirection from, FluidStack resource, boolean doFill) { | ||
FluidInventoryLogic logic = getFluidLogic(from); | ||
if (logic == null) return 0; | ||
IFluidTankLong toFill = new FluidTankLong(resource.getFluid()); | ||
IFluidTankLong fillTry = logic.insert(toFill, resource.amount, doFill); | ||
return fillTry == null ? 0 : fillTry.getFluidAmount(); | ||
} | ||
|
||
@Override | ||
default FluidTankInfo[] getTankInfo(ForgeDirection from) { | ||
FluidInventoryLogic logic = getFluidLogic(from); | ||
if (logic == null) return new FluidTankInfo[0]; | ||
FluidTankInfo[] infos = new FluidTankInfo[logic.getSlots()]; | ||
for (int i = 0; i < infos.length; i++) { | ||
|
||
} | ||
return infos; | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
src/main/java/com/blueweabo/mutecore/api/host/ItemInventoryLogicHost.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,119 @@ | ||
package com.blueweabo.mutecore.api.host; | ||
|
||
import com.blueweabo.mutecore.api.logic.ItemInventoryLogic; | ||
import com.cleanroommc.modularui.api.IItemStackLong; | ||
import com.cleanroommc.modularui.utils.item.ItemStackLongDelegate; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.inventory.ISidedInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.common.util.ForgeDirection; | ||
|
||
public interface ItemInventoryLogicHost extends ISidedInventory { | ||
|
||
default ItemInventoryLogic getItemLogic() { | ||
return getItemLogic(ForgeDirection.UNKNOWN); | ||
} | ||
|
||
ItemInventoryLogic getItemLogic(ForgeDirection side); | ||
|
||
@Override | ||
default boolean canExtractItem(int slot, ItemStack item, int side) { | ||
ItemInventoryLogic logic = getItemLogic(ForgeDirection.getOrientation(side)); | ||
return logic != null && logic.extract(new ItemStackLongDelegate(item), item.stackSize, false) != null; | ||
} | ||
|
||
@Override | ||
default boolean canInsertItem(int slot, ItemStack item, int side) { | ||
ItemInventoryLogic logic = getItemLogic(ForgeDirection.getOrientation(side)); | ||
return logic != null && logic.extract(new ItemStackLongDelegate(item), item.stackSize, false) != null; | ||
} | ||
|
||
@Override | ||
default int[] getAccessibleSlotsFromSide(int side) { | ||
ItemInventoryLogic logic = getItemLogic(ForgeDirection.getOrientation(side)); | ||
if (logic == null) { | ||
return new int[0]; | ||
} | ||
int arr[] = new int[logic.getSlots()]; | ||
for (int i = 0; i < arr.length; i++) { | ||
arr[i] = i; | ||
} | ||
return arr; | ||
} | ||
|
||
@Override | ||
default void closeInventory() {} | ||
|
||
@Override | ||
default ItemStack decrStackSize(int index, int count) { | ||
ItemInventoryLogic logic = getItemLogic(); | ||
if (logic == null) return null; | ||
IItemStackLong stack = logic.get(index); | ||
if (stack == null) return null; | ||
IItemStackLong extractTry = logic.extract(stack, count, false); | ||
if (extractTry == null || extractTry.getStackSize() < count) return null; | ||
IItemStackLong extract = logic.extract(stack, count, true); | ||
return extract.getAsItemStack(); | ||
} | ||
|
||
@Override | ||
default String getInventoryName() { | ||
ItemInventoryLogic logic = getItemLogic(); | ||
if (logic == null) return ""; | ||
return logic.getName(); | ||
} | ||
|
||
@Override | ||
default int getInventoryStackLimit() { | ||
ItemInventoryLogic logic = getItemLogic(); | ||
if (logic == null) return 0; | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
default int getSizeInventory() { | ||
ItemInventoryLogic logic = getItemLogic(); | ||
if (logic == null) return 0; | ||
return logic.getSlots(); | ||
} | ||
|
||
@Override | ||
default ItemStack getStackInSlot(int slotIn) { | ||
ItemInventoryLogic logic = getItemLogic(); | ||
if (logic == null) return null; | ||
return logic.get(slotIn) == null ? null : logic.get(slotIn).getAsItemStack(); | ||
} | ||
|
||
@Override | ||
default ItemStack getStackInSlotOnClosing(int index) { | ||
ItemInventoryLogic logic = getItemLogic(); | ||
if (logic == null) return null; | ||
return logic.get(index) == null ? null : logic.get(index).getAsItemStack(); | ||
} | ||
|
||
@Override | ||
default boolean hasCustomInventoryName() { | ||
return true; | ||
} | ||
|
||
@Override | ||
default boolean isItemValidForSlot(int index, ItemStack stack) { | ||
return true; | ||
} | ||
|
||
@Override | ||
default boolean isUseableByPlayer(EntityPlayer player) { | ||
return true; | ||
} | ||
|
||
@Override | ||
default void markDirty() {} | ||
|
||
@Override | ||
default void openInventory() {} | ||
|
||
@Override | ||
default void setInventorySlotContents(int index, ItemStack stack) {} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/blueweabo/mutecore/api/host/PowerLogicHost.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,14 @@ | ||
package com.blueweabo.mutecore.api.host; | ||
|
||
import com.blueweabo.mutecore.api.logic.interfaces.PowerLogic; | ||
|
||
import net.minecraftforge.common.util.ForgeDirection; | ||
|
||
public interface PowerLogicHost { | ||
|
||
default PowerLogic getPowerLogic() { | ||
return getPowerLogic(ForgeDirection.UNKNOWN); | ||
} | ||
|
||
PowerLogic getPowerLogic(ForgeDirection side); | ||
} |
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