mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-28 07:55:59 +00:00
Added fluid support in recipes (#1020)
This commit is contained in:
1 parent
3f38e6f39b
commit
fda7688807
31 files changed
+831
-127
No files matched your search
@@ -29,6 +29,15 @@ import codechicken.nei.util.NEIMouseUtils;
|
||||
|
||||
public class GuiOverlayButton extends GuiRecipeButton {
|
||||
|
||||
protected static DrawableResource notPresent = new DrawableBuilder(
|
||||
"nei:textures/nei_tabbed_sprites.png",
|
||||
0,
|
||||
40,
|
||||
8,
|
||||
8).build();
|
||||
protected static DrawableResource present = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 8, 40, 8, 8)
|
||||
.build();
|
||||
|
||||
public enum ItemOverlayFormat {
|
||||
|
||||
BACKGROUND,
|
||||
@@ -58,11 +67,23 @@ public class GuiOverlayButton extends GuiRecipeButton {
|
||||
}
|
||||
|
||||
public void draw(ItemOverlayFormat format) {
|
||||
LayoutManager.drawItemPresenceOverlay(
|
||||
this.slot.relx,
|
||||
this.slot.rely,
|
||||
this.isPresent,
|
||||
format == ItemOverlayFormat.BACKGROUND);
|
||||
|
||||
if (format == ItemOverlayFormat.BACKGROUND) {
|
||||
NEIClientUtils.gl2DRenderContext(
|
||||
() -> drawRect(
|
||||
this.slot.relx,
|
||||
this.slot.rely,
|
||||
this.slot.width,
|
||||
this.slot.height,
|
||||
isPresent ? 0x8000AA00 : 0x80AA0000));
|
||||
} else {
|
||||
final DrawableResource icon = isPresent ? present : notPresent;
|
||||
LayoutManager.drawIcon(
|
||||
this.slot.relx + this.slot.width - icon.width,
|
||||
this.slot.rely + this.slot.height - icon.height,
|
||||
icon);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,6 +277,11 @@ public class GuiOverlayButton extends GuiRecipeButton {
|
||||
return this.itemPresenceCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermutationsChanged() {
|
||||
this.itemPresenceCache.clear();
|
||||
}
|
||||
|
||||
public void setRequireShiftForOverlayRecipe(boolean require) {
|
||||
this.requireShiftForOverlayRecipe = require;
|
||||
updateEnabled();
|
||||
@@ -291,30 +317,15 @@ public class GuiOverlayButton extends GuiRecipeButton {
|
||||
}
|
||||
|
||||
protected List<ItemOverlayState> presenceOverlay(List<PositionedStack> ingredients) {
|
||||
final List<ItemOverlayState> states = new ArrayList<>();
|
||||
final List<ItemStack> invStacks = this.firstGui.inventorySlots.inventorySlots.stream()
|
||||
.filter(
|
||||
s -> s != null && s.getStack() != null
|
||||
&& s.getStack().stackSize > 0
|
||||
&& s.isItemValid(s.getStack())
|
||||
&& s.canTakeStack(this.firstGui.mc.thePlayer))
|
||||
.map(s -> s.getStack().copy()).collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
for (PositionedStack stack : ingredients) {
|
||||
boolean found = false;
|
||||
|
||||
for (ItemStack is : invStacks) {
|
||||
if (is.stackSize > 0 && stack.contains(is)) {
|
||||
is.stackSize--;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
states.add(new ItemOverlayState(stack, found));
|
||||
}
|
||||
|
||||
return states;
|
||||
return NEIClientUtils.presenceOverlay(
|
||||
ingredients,
|
||||
this.firstGui.inventorySlots.inventorySlots.stream()
|
||||
.filter(
|
||||
s -> s != null && s.getStack() != null
|
||||
&& s.getStack().stackSize > 0
|
||||
&& s.isItemValid(s.getStack())
|
||||
&& s.canTakeStack(this.firstGui.mc.thePlayer))
|
||||
.map(s -> s.getStack().copy()).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public void overlayRecipe(boolean shift) {
|
||||
|
||||
@@ -65,6 +65,10 @@ public abstract class GuiRecipeButton extends GuiNEIButton {
|
||||
|
||||
}
|
||||
|
||||
public void onPermutationsChanged() {
|
||||
|
||||
}
|
||||
|
||||
public boolean mouseScrolled(int scroll) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -175,6 +175,10 @@ public class NEIRecipeWidget extends Widget {
|
||||
if (!NEIClientUtils.shiftKey() && ((this.cycleticks++) / 20) != this.lastcycle || this.lastcycle == -1) {
|
||||
this.lastcycle = this.cycleticks / 20;
|
||||
updatePermutations();
|
||||
|
||||
for (GuiRecipeButton button : getRecipeButtonsIfInit()) {
|
||||
button.onPermutationsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
for (GuiRecipeButton button : getRecipeButtons()) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import codechicken.nei.LRUCache;
|
||||
import codechicken.nei.api.IStackStringifyHandler;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.recipe.stackinfo.DefaultStackStringifyHandler;
|
||||
import codechicken.nei.recipe.stackinfo.FluidDisplayStackStringifyHandler;
|
||||
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
|
||||
import codechicken.nei.util.ItemStackKey;
|
||||
import codechicken.nei.util.NBTHelper;
|
||||
@@ -36,6 +37,7 @@ public class StackInfo {
|
||||
|
||||
static {
|
||||
stackStringifyHandlers.add(new DefaultStackStringifyHandler());
|
||||
stackStringifyHandlers.add(new FluidDisplayStackStringifyHandler());
|
||||
stackStringifyHandlers.add(new GTFluidStackStringifyHandler());
|
||||
}
|
||||
|
||||
@@ -86,6 +88,19 @@ public class StackInfo {
|
||||
return result == null ? stack : result;
|
||||
}
|
||||
|
||||
public static boolean isFluidDisplayItem(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = stackStringifyHandlers.size() - 1; i >= 0; i--) {
|
||||
if (stackStringifyHandlers.get(i).isFluidDisplayItem(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void pauseItemDamageSound(boolean pause) {
|
||||
if (isPausedItemDamageSound != (isPausedItemDamageSound = pause)) {
|
||||
for (IStackStringifyHandler handler : stackStringifyHandlers) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class LabelWidget extends Widget implements IUpdatableWidget {
|
||||
@Override
|
||||
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
|
||||
|
||||
if (contains(mx, my)) {
|
||||
if (contains(mx, my) && this.value != null) {
|
||||
tooltip.add(this.value);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package codechicken.nei.recipe.stackinfo;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
@@ -49,8 +54,24 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler {
|
||||
public FluidStack getFluid(ItemStack stack) {
|
||||
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
|
||||
|
||||
if (fluidStack == null && stack.getItem() instanceof IFluidContainerItem) {
|
||||
fluidStack = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
|
||||
if (fluidStack == null && stack.getItem() instanceof IFluidContainerItem container) {
|
||||
fluidStack = container.getFluid(stack);
|
||||
}
|
||||
|
||||
if (fluidStack == null && Block.getBlockFromItem(stack.getItem()) instanceof BlockLiquid liquidBlock) {
|
||||
Fluid fluid = FluidRegistry.lookupFluidForBlock(liquidBlock);
|
||||
|
||||
if (fluid == null) {
|
||||
if (liquidBlock.getMaterial() == Material.water) {
|
||||
fluid = FluidRegistry.WATER;
|
||||
} else if (liquidBlock.getMaterial() == Material.lava) {
|
||||
fluid = FluidRegistry.LAVA;
|
||||
}
|
||||
}
|
||||
|
||||
if (fluid != null) {
|
||||
fluidStack = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME);
|
||||
}
|
||||
}
|
||||
|
||||
return fluidStack;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package codechicken.nei.recipe.stackinfo;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import codechicken.nei.api.IStackStringifyHandler;
|
||||
import codechicken.nei.item.ItemFluidDisplay;
|
||||
|
||||
public class FluidDisplayStackStringifyHandler implements IStackStringifyHandler {
|
||||
|
||||
public static final String NBT_FLUID_NAME = "neiFluidName";
|
||||
|
||||
@Override
|
||||
public boolean isFluidDisplayItem(ItemStack stack) {
|
||||
return stack.getItem() instanceof ItemFluidDisplay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) {
|
||||
|
||||
if (!(stack.getItem() instanceof ItemFluidDisplay)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final FluidStack fluidStack = ((ItemFluidDisplay) stack.getItem()).getFluid(stack);
|
||||
|
||||
if (fluidStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final NBTTagCompound nbTag = new NBTTagCompound();
|
||||
nbTag.setString(NBT_FLUID_NAME, fluidStack.getFluid().getName());
|
||||
nbTag.setInteger("Count", saveStackSize ? fluidStack.amount : 1);
|
||||
|
||||
if (fluidStack.tag != null) {
|
||||
nbTag.setTag("FluidTag", fluidStack.tag.copy());
|
||||
}
|
||||
|
||||
return nbTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag) {
|
||||
|
||||
if (!nbtTag.hasKey(NBT_FLUID_NAME)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Fluid fluid = FluidRegistry.getFluid(nbtTag.getString(NBT_FLUID_NAME));
|
||||
|
||||
if (fluid == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final FluidStack fluidStack = new FluidStack(fluid, nbtTag.getInteger("Count"));
|
||||
|
||||
if (nbtTag.hasKey("FluidTag")) {
|
||||
fluidStack.tag = nbtTag.getCompoundTag("FluidTag");
|
||||
}
|
||||
|
||||
return ItemFluidDisplay.createStack(fluidStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid(ItemStack stack) {
|
||||
|
||||
if (stack.getItem() instanceof ItemFluidDisplay fluidDisplay) {
|
||||
return fluidDisplay.getFluid(stack);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,13 +11,13 @@ import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import codechicken.nei.api.IStackStringifyHandler;
|
||||
import codechicken.nei.item.ItemFluidDisplay;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
|
||||
protected static Class<?> itemFluidDisplay = null;
|
||||
protected static Method getFluidDisplayStack = null;
|
||||
protected static Method getFluidFromDisplayStack = null;
|
||||
protected static Class<?> gtMetaGeneratedTool = null;
|
||||
protected static Field playSound = null;
|
||||
@@ -33,7 +33,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
"gregtech.common.items.ItemFluidDisplay",
|
||||
"gregtech.common.items.GT_FluidDisplayItem");
|
||||
getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class);
|
||||
getFluidDisplayStack = gtUtility.getMethod("getFluidDisplayStack", FluidStack.class, boolean.class);
|
||||
|
||||
gtMetaGeneratedTool = ReflectionHelper.getClass(
|
||||
loader,
|
||||
@@ -45,14 +44,15 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) {
|
||||
|
||||
if (stack.getItem() != GameRegistry.findItem("ae2fc", "fluid_drop")) {
|
||||
if (stack != null && isFluidDisplayItem(stack)) {
|
||||
final FluidStack fluidStack = getFluid(stack);
|
||||
|
||||
if (fluidStack != null) {
|
||||
final NBTTagCompound nbTag = new NBTTagCompound();
|
||||
nbTag.setString("gtFluidName", fluidStack.getFluid().getName());
|
||||
nbTag.setString(FluidDisplayStackStringifyHandler.NBT_FLUID_NAME, fluidStack.getFluid().getName());
|
||||
nbTag.setInteger("Count", saveStackSize ? fluidStack.amount : 144);
|
||||
return nbTag;
|
||||
}
|
||||
@@ -61,23 +61,23 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag) {
|
||||
|
||||
if (getFluidDisplayStack != null && nbtTag.hasKey("gtFluidName")) {
|
||||
if (nbtTag.hasKey("gtFluidName")) {
|
||||
final String fluidName = nbtTag.getString("gtFluidName");
|
||||
final Fluid fluid = FluidRegistry.getFluid(fluidName);
|
||||
final int amount = nbtTag.getInteger("Count");
|
||||
|
||||
if (fluid != null) {
|
||||
try {
|
||||
return (ItemStack) getFluidDisplayStack.invoke(null, new FluidStack(fluid, amount), true);
|
||||
} catch (Exception e) {}
|
||||
return ItemFluidDisplay.createStack(new FluidStack(fluid, amount));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid(ItemStack stack) {
|
||||
final Item item = stack.getItem();
|
||||
|
||||
@@ -110,6 +110,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack normalizeRecipeQueryStack(ItemStack stack) {
|
||||
|
||||
if (stack.getItem() == GameRegistry.findItem("ae2fc", "fluid_drop")
|
||||
@@ -117,9 +118,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
final FluidStack fluidStack = getFluid(stack);
|
||||
|
||||
if (fluidStack != null) {
|
||||
try {
|
||||
return (ItemStack) getFluidDisplayStack.invoke(null, fluidStack, true);
|
||||
} catch (Exception e) {}
|
||||
return ItemFluidDisplay.createStack(fluidStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,4 +135,11 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidDisplayItem(ItemStack stack) {
|
||||
final Item item = stack.getItem();
|
||||
return (itemFluidDisplay != null && itemFluidDisplay.isInstance(item))
|
||||
|| item == GameRegistry.findItem("ae2fc", "fluid_packet");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user