Render improvements for CraftingMonitorElements and CraftingPreviewElements (#477)
* add fluids to the preview and tons of fixes regarding the rendering of CraftingMonitorElements and CraftingPreviewElements * name changes to please @raoulvdberge
This commit is contained in:
@@ -3,6 +3,7 @@ package refinedstorage.api;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementRegistry;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElementRegistry;
|
||||
import refinedstorage.api.autocrafting.registry.ICraftingTaskRegistry;
|
||||
import refinedstorage.api.solderer.ISoldererRegistry;
|
||||
import refinedstorage.api.util.IComparer;
|
||||
@@ -40,6 +41,12 @@ public interface IRSAPI {
|
||||
@Nonnull
|
||||
ICraftingMonitorElementRegistry getCraftingMonitorElementRegistry();
|
||||
|
||||
/**
|
||||
* @return the crafting preview element registry
|
||||
*/
|
||||
@Nonnull
|
||||
ICraftingPreviewElementRegistry getCraftingPreviewElementRegistry();
|
||||
|
||||
/**
|
||||
* @return an empty item stack list
|
||||
*/
|
||||
|
||||
@@ -38,6 +38,12 @@ public interface ICraftingPattern {
|
||||
*/
|
||||
List<ItemStack> getInputs();
|
||||
|
||||
/**
|
||||
* @param took the items took
|
||||
* @return the outputs based on the items took
|
||||
*/
|
||||
List<ItemStack> getOutputs(ItemStack[] took);
|
||||
|
||||
/**
|
||||
* @return the outputs
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
package refinedstorage.api.autocrafting.craftingmonitor;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
|
||||
/**
|
||||
* Represents a crafting monitor element.
|
||||
*/
|
||||
public interface ICraftingMonitorElement<T> {
|
||||
/**
|
||||
* @param gui the gui
|
||||
* @param x position on the x axis to render
|
||||
* @param y position on the y axis to render
|
||||
* @param itemDrawer a drawer for {@link ItemStack}s
|
||||
* @param fluidDrawer a drawer for {@link FluidStack}s
|
||||
* @param stringDrawer a drawer for {@link String}s
|
||||
*/
|
||||
void draw(T gui, int x, int y);
|
||||
@SideOnly(Side.CLIENT)
|
||||
void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer);
|
||||
|
||||
/**
|
||||
* Returns the position where the corresponding task is in the crafting task list.
|
||||
|
||||
@@ -12,7 +12,7 @@ public interface ICraftingMonitorElementRegistry {
|
||||
/**
|
||||
* Adds a factory to the registry.
|
||||
*
|
||||
* @param id the id, as specified in {@link ICraftingMonitorElement#getTaskId()}
|
||||
* @param id the id, as specified in {@link ICraftingMonitorElement#getId()}
|
||||
* @param factory the factory
|
||||
*/
|
||||
void add(String id, Function<ByteBuf, ICraftingMonitorElement> factory);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package refinedstorage.api.autocrafting.preview;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
|
||||
public interface ICraftingPreviewElement<T> {
|
||||
/**
|
||||
* @return the underlying element to display
|
||||
*/
|
||||
T getElement();
|
||||
|
||||
/**
|
||||
* @param x position on the x axis to render
|
||||
* @param y position on the y axis to render
|
||||
* @param itemDrawer a drawer for {@link ItemStack}s
|
||||
* @param fluidDrawer a drawer for {@link FluidStack}s
|
||||
* @param stringDrawer a drawer for {@link String}s
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer);
|
||||
|
||||
/**
|
||||
* @return available amount of the {@link #getElement()}
|
||||
*/
|
||||
int getAvailable();
|
||||
|
||||
/**
|
||||
* @return toCraft or missing (depends on {@link #hasMissing()} amount of the {@link #getElement()}
|
||||
*/
|
||||
int getToCraft();
|
||||
|
||||
/**
|
||||
* When this is true {@link #getToCraft()} will be the missing items
|
||||
*
|
||||
* @return true when items are missing
|
||||
*/
|
||||
boolean hasMissing();
|
||||
|
||||
/**
|
||||
* @param buf byte buf to write to
|
||||
*/
|
||||
void writeToByteBuf(ByteBuf buf);
|
||||
|
||||
/**
|
||||
* Returns the id of this element, used for serialization and deserialization over the network.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
String getId();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package refinedstorage.api.autocrafting.preview;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* This registry holds factories for crafting preview elements (for deserialization from the network).
|
||||
*/
|
||||
public interface ICraftingPreviewElementRegistry {
|
||||
/**
|
||||
* Adds a factory to the registry.
|
||||
*
|
||||
* @param id the id, as specified in {@link ICraftingPreviewElement#getId()}
|
||||
* @param factory the factory
|
||||
*/
|
||||
void add(String id, Function<ByteBuf, ICraftingPreviewElement> factory);
|
||||
|
||||
/**
|
||||
* Returns a factory from the registry.
|
||||
*
|
||||
* @param id the id, as specified in {@link ICraftingPreviewElement#getId()}
|
||||
* @return the factory, or null if no factory was found
|
||||
*/
|
||||
@Nullable
|
||||
Function<ByteBuf, ICraftingPreviewElement> getFactory(String id);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package refinedstorage.api.autocrafting.preview;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface ICraftingPreviewStack {
|
||||
/**
|
||||
* @return the stack to display
|
||||
*/
|
||||
ItemStack getStack();
|
||||
|
||||
/**
|
||||
* @return available amount of the {@link #getStack()}
|
||||
*/
|
||||
int getAvailable();
|
||||
|
||||
/**
|
||||
* @return toCraft or missing (depends on {@link #hasMissing()} amount of the {@link #getStack()}
|
||||
*/
|
||||
int getToCraft();
|
||||
|
||||
/**
|
||||
* When this is true {@link #getToCraft()} will be the missing items
|
||||
*
|
||||
* @return true when items are missing
|
||||
*/
|
||||
boolean hasMissing();
|
||||
|
||||
/**
|
||||
* @param buf byte buf to write to
|
||||
*/
|
||||
void writeToByteBuf(ByteBuf buf);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package refinedstorage.api.autocrafting.task;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewStack;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -78,7 +78,7 @@ public interface ICraftingTask {
|
||||
/**
|
||||
* {@link ICraftingTask#calculate()} must be run before this
|
||||
*
|
||||
* @return get a list of {@link ICraftingPreviewStack}s
|
||||
* @return get a list of {@link ICraftingPreviewElement}s
|
||||
*/
|
||||
List<ICraftingPreviewStack> getPreviewStacks();
|
||||
List<ICraftingPreviewElement> getPreviewStacks();
|
||||
}
|
||||
|
||||
16
src/main/java/refinedstorage/api/render/IElementDrawer.java
Normal file
16
src/main/java/refinedstorage/api/render/IElementDrawer.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package refinedstorage.api.render;
|
||||
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
|
||||
/**
|
||||
* This {@link FunctionalInterface} is used to define a draw/render function
|
||||
* This function use x and y coords and the element to be draw
|
||||
* Used in {@link ICraftingPreviewElement#draw(int, int, IElementDrawer, IElementDrawer, IElementDrawer)} and
|
||||
* {@link refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement#draw(int, int, IElementDrawer, IElementDrawer, IElementDrawer)}
|
||||
*
|
||||
* @param <T> The element to draw, usually {@link String}, {@link net.minecraft.item.ItemStack} or {@link net.minecraftforge.fluids.FluidStack}
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IElementDrawer<T> {
|
||||
void draw(int x, int y, T element);
|
||||
}
|
||||
@@ -6,12 +6,14 @@ import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import refinedstorage.api.IRSAPI;
|
||||
import refinedstorage.api.RSAPIInject;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementRegistry;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElementRegistry;
|
||||
import refinedstorage.api.autocrafting.registry.ICraftingTaskRegistry;
|
||||
import refinedstorage.api.solderer.ISoldererRegistry;
|
||||
import refinedstorage.api.util.IComparer;
|
||||
import refinedstorage.api.util.IFluidStackList;
|
||||
import refinedstorage.api.util.IItemStackList;
|
||||
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementRegistry;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementRegistry;
|
||||
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskRegistry;
|
||||
import refinedstorage.apiimpl.solderer.SoldererRegistry;
|
||||
import refinedstorage.apiimpl.util.Comparer;
|
||||
@@ -29,6 +31,7 @@ public class API implements IRSAPI {
|
||||
private ISoldererRegistry soldererRegistry = new SoldererRegistry();
|
||||
private ICraftingTaskRegistry craftingTaskRegistry = new CraftingTaskRegistry();
|
||||
private ICraftingMonitorElementRegistry craftingMonitorElementRegistry = new CraftingMonitorElementRegistry();
|
||||
private ICraftingPreviewElementRegistry craftingPreviewElementRegistry = new CraftingPreviewElementRegistry();
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@@ -54,6 +57,12 @@ public class API implements IRSAPI {
|
||||
return craftingMonitorElementRegistry;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ICraftingPreviewElementRegistry getCraftingPreviewElementRegistry() {
|
||||
return craftingPreviewElementRegistry;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IItemStackList createItemStackList() {
|
||||
|
||||
@@ -90,6 +90,26 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getOutputs(ItemStack[] took) {
|
||||
List<ItemStack> outputs = new ArrayList<>();
|
||||
|
||||
InventoryCrafting inv = new InventoryCrafting(new Container() {
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
}, 3, 3);
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
inv.setInventorySlotContents(i, took[i]);
|
||||
}
|
||||
|
||||
outputs.add(CraftingManager.getInstance().findMatchingRecipe(inv, world));
|
||||
|
||||
return outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getOutputs() {
|
||||
return outputs;
|
||||
|
||||
@@ -2,12 +2,16 @@ package refinedstorage.apiimpl.autocrafting.craftingmonitor;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.RSUtils;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingMonitorElementFluidRender implements ICraftingMonitorElement<GuiBase> {
|
||||
public class CraftingMonitorElementFluidRender implements ICraftingMonitorElement<FluidStack> {
|
||||
public static final String ID = "fluid_render";
|
||||
|
||||
private int taskId;
|
||||
@@ -21,15 +25,16 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiBase gui, int x, int y) {
|
||||
GuiBase.FLUID_RENDERER.draw(gui.mc, x + 2 + offset, y + 1, stack);
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
|
||||
fluidDrawer.draw(x + 2 + offset, y + 1, stack);
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
gui.drawString(gui.calculateOffsetOnScale(x + 21 + offset, scale), gui.calculateOffsetOnScale(y + 7, scale), RSUtils.formatFluidStackQuantity(stack) + " " + stack.getLocalizedName());
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 21 + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), RSUtils.formatFluidStackQuantity(stack) + " " + stack.getLocalizedName());
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,15 @@ package refinedstorage.apiimpl.autocrafting.craftingmonitor;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingMonitorElementItemRender implements ICraftingMonitorElement<GuiBase> {
|
||||
public class CraftingMonitorElementItemRender implements ICraftingMonitorElement<ItemStack> {
|
||||
public static final String ID = "item_render";
|
||||
|
||||
private int taskId;
|
||||
@@ -23,15 +27,16 @@ public class CraftingMonitorElementItemRender implements ICraftingMonitorElement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiBase gui, int x, int y) {
|
||||
gui.drawItem(x + 2 + offset, y + 1, stack);
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
|
||||
itemDrawer.draw(x + 2 + offset, y + 1, stack);
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
gui.drawString(gui.calculateOffsetOnScale(x + 21 + offset, scale), gui.calculateOffsetOnScale(y + 7, scale), quantity + " " + stack.getDisplayName());
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 21 + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), quantity + " " + stack.getDisplayName());
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,16 @@ package refinedstorage.apiimpl.autocrafting.craftingmonitor;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingMonitorElementText implements ICraftingMonitorElement<GuiBase> {
|
||||
public class CraftingMonitorElementText implements ICraftingMonitorElement<String> {
|
||||
public static final String ID = "text";
|
||||
|
||||
private String text;
|
||||
@@ -27,13 +32,14 @@ public class CraftingMonitorElementText implements ICraftingMonitorElement<GuiBa
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiBase gui, int x, int y) {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
|
||||
float scale = 0.5f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
gui.drawString(gui.calculateOffsetOnScale(x + offset, scale), gui.calculateOffsetOnScale(y + 7, scale), I18n.format(text));
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + offset, scale), GuiBase.calculateOffsetOnScale(y + 7, scale), I18n.format(text));
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package refinedstorage.apiimpl.autocrafting.preview;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
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 net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingPreviewElementFluidStack implements ICraftingPreviewElement<FluidStack> {
|
||||
public static final String ID = "fluid_renderer";
|
||||
|
||||
private FluidStack stack;
|
||||
private int available;
|
||||
private boolean missing;
|
||||
private int toCraft;
|
||||
// if missing is true then toCraft is the missing amount
|
||||
|
||||
public CraftingPreviewElementFluidStack(FluidStack stack) {
|
||||
this.stack = stack.copy();
|
||||
this.available = stack.amount;
|
||||
}
|
||||
|
||||
public CraftingPreviewElementFluidStack(FluidStack stack, int available, boolean missing, int toCraft) {
|
||||
this.stack = stack.copy();
|
||||
this.available = available;
|
||||
this.missing = missing;
|
||||
this.toCraft = toCraft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToByteBuf(ByteBuf buf) {
|
||||
ByteBufUtils.writeUTF8String(buf, FluidRegistry.getFluidName(stack));
|
||||
ByteBufUtils.writeTag(buf, stack.tag);
|
||||
buf.writeInt(available);
|
||||
buf.writeBoolean(missing);
|
||||
buf.writeInt(toCraft);
|
||||
}
|
||||
|
||||
public static CraftingPreviewElementFluidStack fromByteBuf(ByteBuf buf) {
|
||||
Fluid fluid = FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf));
|
||||
NBTTagCompound tag = ByteBufUtils.readTag(buf);
|
||||
int available = buf.readInt();
|
||||
boolean missing = buf.readBoolean();
|
||||
int toCraft = buf.readInt();
|
||||
|
||||
return new CraftingPreviewElementFluidStack(new FluidStack(fluid, 1, tag), available, missing, toCraft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getElement() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
|
||||
fluidDrawer.draw(x, y, getElement());
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y + 3, scale), GuiBase.t("gui.refinedstorage:crafting_preview.available", ""));
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y + 9, scale), getAvailable() + " mB");
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
public void addAvailable(int amount) {
|
||||
this.available += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void addToCraft(int amount) {
|
||||
this.toCraft += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToCraft() {
|
||||
return this.toCraft;
|
||||
}
|
||||
|
||||
public void setMissing(boolean missing) {
|
||||
this.missing = missing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMissing() {
|
||||
return missing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package refinedstorage.apiimpl.autocrafting.preview;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
|
||||
public class CraftingPreviewElementItemStack implements ICraftingPreviewElement<ItemStack> {
|
||||
public static final String ID = "item_renderer";
|
||||
|
||||
private ItemStack stack;
|
||||
private int available;
|
||||
private boolean missing;
|
||||
private int toCraft;
|
||||
// if missing is true then toCraft is the missing amount
|
||||
|
||||
public CraftingPreviewElementItemStack(ItemStack stack) {
|
||||
this.stack = ItemHandlerHelper.copyStackWithSize(stack, 1);
|
||||
}
|
||||
|
||||
public CraftingPreviewElementItemStack(ItemStack stack, int available, boolean missing, int toCraft) {
|
||||
this.stack = stack;
|
||||
this.available = available;
|
||||
this.missing = missing;
|
||||
this.toCraft = toCraft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToByteBuf(ByteBuf buf) {
|
||||
buf.writeInt(Item.getIdFromItem(stack.getItem()));
|
||||
buf.writeInt(stack.getMetadata());
|
||||
ByteBufUtils.writeTag(buf, stack.getTagCompound());
|
||||
buf.writeInt(available);
|
||||
buf.writeBoolean(missing);
|
||||
buf.writeInt(toCraft);
|
||||
}
|
||||
|
||||
public static CraftingPreviewElementItemStack fromByteBuf(ByteBuf buf) {
|
||||
Item item = Item.getItemById(buf.readInt());
|
||||
int meta = buf.readInt();
|
||||
NBTTagCompound tag = ByteBufUtils.readTag(buf);
|
||||
int available = buf.readInt();
|
||||
boolean missing = buf.readBoolean();
|
||||
int toCraft = buf.readInt();
|
||||
|
||||
ItemStack stack = new ItemStack(item, 1, meta);
|
||||
stack.setTagCompound(tag);
|
||||
return new CraftingPreviewElementItemStack(stack, available, missing, toCraft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getElement() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(int x, int y, IElementDrawer<ItemStack> itemDrawer, IElementDrawer<FluidStack> fluidDrawer, IElementDrawer<String> stringDrawer) {
|
||||
itemDrawer.draw(x, y, getElement());
|
||||
|
||||
float scale = 0.5f;
|
||||
y += 2;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
if (getToCraft() > 0) {
|
||||
String format = hasMissing() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft";
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y, scale), GuiBase.t(format, getToCraft()));
|
||||
|
||||
y += 7;
|
||||
}
|
||||
|
||||
if (getAvailable() > 0) {
|
||||
stringDrawer.draw(GuiBase.calculateOffsetOnScale(x + 23, scale), GuiBase.calculateOffsetOnScale(y, scale), GuiBase.t("gui.refinedstorage:crafting_preview.available", getAvailable()));
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
public void addAvailable(int amount) {
|
||||
this.available += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void addToCraft(int amount) {
|
||||
this.toCraft += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToCraft() {
|
||||
return this.toCraft;
|
||||
}
|
||||
|
||||
public void setMissing(boolean missing) {
|
||||
this.missing = missing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMissing() {
|
||||
return missing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package refinedstorage.apiimpl.autocrafting.preview;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElementRegistry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CraftingPreviewElementRegistry implements ICraftingPreviewElementRegistry {
|
||||
private Map<String, Function<ByteBuf, ICraftingPreviewElement>> registry = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void add(String id, Function<ByteBuf, ICraftingPreviewElement> factory) {
|
||||
registry.put(id, factory);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Function<ByteBuf, ICraftingPreviewElement> getFactory(String id) {
|
||||
return registry.get(id);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package refinedstorage.apiimpl.autocrafting.preview;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewStack;
|
||||
|
||||
public class CraftingPreviewStack implements ICraftingPreviewStack {
|
||||
private ItemStack stack;
|
||||
private int available;
|
||||
private boolean missing;
|
||||
private int toCraft;
|
||||
// if missing is true then toCraft is the missing amount
|
||||
|
||||
public CraftingPreviewStack(ItemStack stack) {
|
||||
this.stack = ItemHandlerHelper.copyStackWithSize(stack, 1);
|
||||
}
|
||||
|
||||
public CraftingPreviewStack(ItemStack stack, int available, boolean missing, int toCraft) {
|
||||
this.stack = stack;
|
||||
this.available = available;
|
||||
this.missing = missing;
|
||||
this.toCraft = toCraft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToByteBuf(ByteBuf buf) {
|
||||
buf.writeInt(Item.getIdFromItem(stack.getItem()));
|
||||
buf.writeInt(stack.getMetadata());
|
||||
buf.writeInt(available);
|
||||
buf.writeBoolean(missing);
|
||||
buf.writeInt(toCraft);
|
||||
}
|
||||
|
||||
public static CraftingPreviewStack fromByteBuf(ByteBuf buf) {
|
||||
Item item = Item.getItemById(buf.readInt());
|
||||
int meta = buf.readInt();
|
||||
int available = buf.readInt();
|
||||
boolean missing = buf.readBoolean();
|
||||
int toCraft = buf.readInt();
|
||||
|
||||
return new CraftingPreviewStack(new ItemStack(item, 1, meta), available, missing, toCraft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public void addAvailable(int amount) {
|
||||
this.available += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void addToCraft(int amount) {
|
||||
this.toCraft += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToCraft() {
|
||||
return this.toCraft;
|
||||
}
|
||||
|
||||
public void setMissing(boolean missing) {
|
||||
this.missing = missing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMissing() {
|
||||
return missing;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import refinedstorage.RSUtils;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewStack;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.api.autocrafting.task.IProcessable;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
@@ -19,7 +19,8 @@ import refinedstorage.apiimpl.API;
|
||||
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
|
||||
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
|
||||
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewStack;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -48,7 +49,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
this.quantity = quantity;
|
||||
|
||||
if (pattern.isOredict()) {
|
||||
this.compare = IComparer.COMPARE_OREDICT;
|
||||
this.compare |= IComparer.COMPARE_OREDICT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +68,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
if (!recurseFound) {
|
||||
this.toInsert.addAll(toInsert.getStacks());
|
||||
}
|
||||
|
||||
usedPatterns.clear();
|
||||
}
|
||||
|
||||
@@ -120,7 +122,10 @@ public class CraftingTask implements ICraftingTask {
|
||||
// Calculate added all the crafted outputs toInsert
|
||||
// So we remove the ones we use from toInsert
|
||||
toInsert.remove(inputCrafted, true);
|
||||
} else if (!doFluidCalculation(networkList, input, toInsert)) {
|
||||
} else if (doFluidCalculation(networkList, input, toInsert)) {
|
||||
actualInputs.add(ItemHandlerHelper.copyStackWithSize(input, 1));
|
||||
input.stackSize -= 1;
|
||||
} else {
|
||||
missing.add(input.copy());
|
||||
input.stackSize = 0;
|
||||
}
|
||||
@@ -138,15 +143,16 @@ public class CraftingTask implements ICraftingTask {
|
||||
actualInputs.remove(taken, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack byproduct : (pattern.isOredict() ? pattern.getByproducts(took) : pattern.getByproducts())) {
|
||||
for (ItemStack byproduct : (pattern.isOredict() && missing.isEmpty() ? pattern.getByproducts(took) : pattern.getByproducts())) {
|
||||
toInsert.add(byproduct.copy());
|
||||
}
|
||||
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
for (ItemStack output : (pattern.isOredict() && missing.isEmpty() ? pattern.getOutputs(took) : pattern.getOutputs())) {
|
||||
toInsert.add(output.copy());
|
||||
}
|
||||
}
|
||||
|
||||
usedPatterns.remove(pattern);
|
||||
}
|
||||
|
||||
@@ -358,45 +364,49 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICraftingPreviewStack> getPreviewStacks() {
|
||||
public List<ICraftingPreviewElement> getPreviewStacks() {
|
||||
if (!isValid()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Map<Integer, CraftingPreviewStack> map = new LinkedHashMap<>();
|
||||
Map<Integer, CraftingPreviewElementItemStack> map = new LinkedHashMap<>();
|
||||
|
||||
for (ItemStack stack : toCraft.getStacks()) {
|
||||
int hash = API.instance().getItemStackHashCode(stack);
|
||||
CraftingPreviewStack previewStack = map.get(hash);
|
||||
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
||||
if (previewStack == null) {
|
||||
previewStack = new CraftingPreviewStack(stack);
|
||||
previewStack = new CraftingPreviewElementItemStack(stack);
|
||||
}
|
||||
previewStack.addToCraft(stack.stackSize);
|
||||
map.put(hash, previewStack);
|
||||
}
|
||||
|
||||
for (ItemStack stack : toTake.getStacks()) {
|
||||
int hash = API.instance().getItemStackHashCode(stack);
|
||||
CraftingPreviewStack previewStack = map.get(hash);
|
||||
if (previewStack == null) {
|
||||
previewStack = new CraftingPreviewStack(stack);
|
||||
}
|
||||
previewStack.addAvailable(stack.stackSize);
|
||||
map.put(hash, previewStack);
|
||||
}
|
||||
|
||||
for (ItemStack stack : missing.getStacks()) {
|
||||
int hash = API.instance().getItemStackHashCode(stack);
|
||||
CraftingPreviewStack previewStack = map.get(hash);
|
||||
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
||||
if (previewStack == null) {
|
||||
previewStack = new CraftingPreviewStack(stack);
|
||||
previewStack = new CraftingPreviewElementItemStack(stack);
|
||||
}
|
||||
previewStack.setMissing(true);
|
||||
previewStack.addToCraft(stack.stackSize);
|
||||
map.put(hash, previewStack);
|
||||
}
|
||||
|
||||
return new ArrayList<>(map.values());
|
||||
for (ItemStack stack : toTake.getStacks()) {
|
||||
int hash = API.instance().getItemStackHashCode(stack);
|
||||
CraftingPreviewElementItemStack previewStack = map.get(hash);
|
||||
if (previewStack == null) {
|
||||
previewStack = new CraftingPreviewElementItemStack(stack);
|
||||
}
|
||||
previewStack.addAvailable(stack.stackSize);
|
||||
map.put(hash, previewStack);
|
||||
}
|
||||
|
||||
List<ICraftingPreviewElement> elements = new ArrayList<>(map.values());
|
||||
|
||||
toTakeFluids.getStacks().stream().map(CraftingPreviewElementFluidStack::new).forEach(elements::add);
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
private boolean isFinished() {
|
||||
|
||||
@@ -18,7 +18,9 @@ public class Comparer implements IComparer {
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_OREDICT) == COMPARE_OREDICT) {
|
||||
return isEqualOredict(left, right);
|
||||
if (isEqualOredict(left, right)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (left.getItem() != right.getItem()) {
|
||||
|
||||
@@ -265,7 +265,7 @@ public abstract class GuiBase extends GuiContainer {
|
||||
drawTexturedModalRect(x, y, textureX, textureY, width, height);
|
||||
}
|
||||
|
||||
public String t(String name, Object... format) {
|
||||
public static String t(String name, Object... format) {
|
||||
return I18n.format(name, format);
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ public abstract class GuiBase extends GuiContainer {
|
||||
return guiTop;
|
||||
}
|
||||
|
||||
public int calculateOffsetOnScale(int pos, float scale) {
|
||||
public static int calculateOffsetOnScale(int pos, float scale) {
|
||||
float multiplier = (pos / scale);
|
||||
|
||||
return (int) multiplier;
|
||||
|
||||
@@ -2,8 +2,11 @@ package refinedstorage.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import refinedstorage.RS;
|
||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.container.ContainerCraftingMonitor;
|
||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||
import refinedstorage.network.MessageCraftingMonitorCancel;
|
||||
@@ -28,6 +31,10 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
private int itemSelectedX = -1;
|
||||
private int itemSelectedY = -1;
|
||||
|
||||
private IElementDrawer<String> stringDrawer = this::drawString;
|
||||
private IElementDrawer<ItemStack> itemDrawer = this::drawItem;
|
||||
private IElementDrawer<FluidStack> fluidDrawer = (x, y, element) -> FLUID_RENDERER.draw(mc, x, y, element);
|
||||
|
||||
public GuiCraftingMonitor(ContainerCraftingMonitor container, TileCraftingMonitor craftingMonitor) {
|
||||
super(container, 176, 230);
|
||||
|
||||
@@ -99,7 +106,7 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
itemSelectedY = y;
|
||||
}
|
||||
|
||||
element.draw(this, x, y);
|
||||
element.draw(x, y, itemDrawer, fluidDrawer, stringDrawer);
|
||||
|
||||
x = ox;
|
||||
y += ITEM_HEIGHT;
|
||||
|
||||
@@ -8,10 +8,14 @@ import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import refinedstorage.RS;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewStack;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.api.render.IElementDrawer;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
||||
import refinedstorage.network.MessageGridCraftingStart;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -21,7 +25,7 @@ import java.util.List;
|
||||
public class GuiCraftingPreview extends GuiBase {
|
||||
private static final int VISIBLE_ROWS = 4;
|
||||
|
||||
private List<ICraftingPreviewStack> stacks;
|
||||
private List<ICraftingPreviewElement> stacks;
|
||||
private GuiScreen parent;
|
||||
|
||||
private int hash;
|
||||
@@ -30,7 +34,11 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
private GuiButton startButton;
|
||||
private GuiButton cancelButton;
|
||||
|
||||
public GuiCraftingPreview(GuiScreen parent, List<ICraftingPreviewStack> stacks, int hash, int quantity) {
|
||||
private IElementDrawer<String> stringDrawer = this::drawString;
|
||||
private IElementDrawer<ItemStack> itemDrawer = this::drawItem;
|
||||
private IElementDrawer<FluidStack> fluidDrawer = (x, y, element) -> FLUID_RENDERER.draw(mc, x, y, element);
|
||||
|
||||
public GuiCraftingPreview(GuiScreen parent, List<ICraftingPreviewElement> stacks, int hash, int quantity) {
|
||||
super(new Container() {
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
@@ -51,7 +59,7 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
public void init(int x, int y) {
|
||||
cancelButton = addButton(x + 16, y + 144, 50, 20, t("gui.cancel"));
|
||||
startButton = addButton(x + 85, y + 144, 50, 20, t("misc.refinedstorage:start"));
|
||||
startButton.enabled = !stacks.isEmpty();
|
||||
startButton.enabled = stacks.stream().filter(ICraftingPreviewElement::hasMissing).count() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +85,7 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if (slot < stacks.size()) {
|
||||
ICraftingPreviewStack stack = stacks.get(slot);
|
||||
ICraftingPreviewElement stack = stacks.get(slot);
|
||||
|
||||
if (stack.hasMissing()) {
|
||||
drawTexture(x, y, 189, 0, 67, 29);
|
||||
@@ -119,33 +127,19 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
ItemStack hoveringStack = null;
|
||||
FluidStack hoveringFluid = null;
|
||||
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if (slot < stacks.size()) {
|
||||
ICraftingPreviewStack stack = stacks.get(slot);
|
||||
ICraftingPreviewElement stack = stacks.get(slot);
|
||||
|
||||
drawItem(x, y + 5, stack.getStack());
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
|
||||
int yy = y + 8;
|
||||
|
||||
if (stack.getToCraft() > 0) {
|
||||
String format = stack.hasMissing() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft";
|
||||
drawString(calculateOffsetOnScale(x + 23, scale), calculateOffsetOnScale(yy, scale), t(format, stack.getToCraft()));
|
||||
|
||||
yy += 7;
|
||||
}
|
||||
|
||||
if (stack.getAvailable() > 0) {
|
||||
drawString(calculateOffsetOnScale(x + 23, scale), calculateOffsetOnScale(yy, scale), t("gui.refinedstorage:crafting_preview.available", stack.getAvailable()));
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
stack.draw(x, y + 5, itemDrawer, fluidDrawer, stringDrawer);
|
||||
|
||||
if (inBounds(x, y, 16, 16, mouseX, mouseY)) {
|
||||
hoveringStack = stack.getStack();
|
||||
hoveringStack = stack.getId().equals(CraftingPreviewElementItemStack.ID) ? (ItemStack) stack.getElement() : null;
|
||||
if (hoveringStack == null) {
|
||||
hoveringFluid = stack.getId().equals(CraftingPreviewElementFluidStack.ID) ? (FluidStack) stack.getElement() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,6 +155,8 @@ public class GuiCraftingPreview extends GuiBase {
|
||||
|
||||
if (hoveringStack != null) {
|
||||
drawTooltip(mouseX, mouseY, hoveringStack.getTooltip(Minecraft.getMinecraft().thePlayer, false));
|
||||
} else if (hoveringFluid != null) {
|
||||
drawTooltip(mouseX, mouseY, hoveringFluid.getLocalizedName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class SideButtonAccessType extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.RED + gui.t("sidebutton.refinedstorage:access_type") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:access_type." + parameter.getValue().getId());
|
||||
return TextFormatting.RED + GuiBase.t("sidebutton.refinedstorage:access_type") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:access_type." + parameter.getValue().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,12 +19,12 @@ public class SideButtonCompare extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
String tooltip = TextFormatting.YELLOW + gui.t("sidebutton.refinedstorage:compare." + mask) + TextFormatting.RESET + "\n";
|
||||
String tooltip = TextFormatting.YELLOW + GuiBase.t("sidebutton.refinedstorage:compare." + mask) + TextFormatting.RESET + "\n";
|
||||
|
||||
if ((parameter.getValue() & mask) == mask) {
|
||||
tooltip += gui.t("gui.yes");
|
||||
tooltip += GuiBase.t("gui.yes");
|
||||
} else {
|
||||
tooltip += gui.t("gui.no");
|
||||
tooltip += GuiBase.t("gui.no");
|
||||
}
|
||||
|
||||
return tooltip;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SideButtonConstuctorDrop extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:constructor.drop") + TextFormatting.RESET + "\n" + gui.t(TileConstructor.DROP.getValue() ? "gui.yes" : "gui.no");
|
||||
return TextFormatting.GREEN + GuiBase.t("sidebutton.refinedstorage:constructor.drop") + TextFormatting.RESET + "\n" + GuiBase.t(TileConstructor.DROP.getValue() ? "gui.yes" : "gui.no");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ public class SideButtonCrafterTriggeredAutocrafting extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:crafter.triggered_autocrafting") + TextFormatting.RESET + "\n" + gui.t("gui." + (TileCrafter.TRIGGERED_AUTOCRAFTING.getValue() ? "yes" : "no"));
|
||||
return TextFormatting.GREEN + GuiBase.t("sidebutton.refinedstorage:crafter.triggered_autocrafting") + TextFormatting.RESET + "\n" + GuiBase.t("gui." + (TileCrafter.TRIGGERED_AUTOCRAFTING.getValue() ? "yes" : "no"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ public class SideButtonDetectorMode extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:detector.mode") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:detector.mode." + TileDetector.MODE.getValue());
|
||||
return TextFormatting.GREEN + GuiBase.t("sidebutton.refinedstorage:detector.mode") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:detector.mode." + TileDetector.MODE.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package refinedstorage.gui.sidebutton;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
import refinedstorage.gui.grid.GuiGrid;
|
||||
import refinedstorage.integration.jei.IntegrationJEI;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
@@ -12,7 +13,7 @@ public class SideButtonGridSearchBoxMode extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.YELLOW + gui.t("sidebutton.refinedstorage:grid.search_box_mode") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:grid.search_box_mode." + ((GuiGrid) gui).getGrid().getSearchBoxMode());
|
||||
return TextFormatting.YELLOW + GuiBase.t("sidebutton.refinedstorage:grid.search_box_mode") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:grid.search_box_mode." + ((GuiGrid) gui).getGrid().getSearchBoxMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SideButtonGridSortingDirection extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.YELLOW + gui.t("sidebutton.refinedstorage:grid.sorting.direction") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:grid.sorting.direction." + grid.getSortingDirection());
|
||||
return TextFormatting.YELLOW + GuiBase.t("sidebutton.refinedstorage:grid.sorting.direction") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:grid.sorting.direction." + grid.getSortingDirection());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SideButtonGridSortingType extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.YELLOW + gui.t("sidebutton.refinedstorage:grid.sorting.type") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:grid.sorting.type." + grid.getSortingType());
|
||||
return TextFormatting.YELLOW + GuiBase.t("sidebutton.refinedstorage:grid.sorting.type") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:grid.sorting.type." + grid.getSortingType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SideButtonGridViewType extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.YELLOW + gui.t("sidebutton.refinedstorage:grid.view_type") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:grid.view_type." + grid.getViewType());
|
||||
return TextFormatting.YELLOW + GuiBase.t("sidebutton.refinedstorage:grid.view_type") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:grid.view_type." + grid.getViewType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SideButtonIOMode extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:iomode") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:iomode." + (parameter.getValue() == TileDiskManipulator.IO_MODE_INSERT ? "insert" : "extract"));
|
||||
return TextFormatting.GREEN + GuiBase.t("sidebutton.refinedstorage:iomode") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:iomode." + (parameter.getValue() == TileDiskManipulator.IO_MODE_INSERT ? "insert" : "extract"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SideButtonMode extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:mode") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:mode." + (parameter.getValue() == IFilterable.WHITELIST ? "whitelist" : "blacklist"));
|
||||
return TextFormatting.GREEN + GuiBase.t("sidebutton.refinedstorage:mode") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:mode." + (parameter.getValue() == IFilterable.WHITELIST ? "whitelist" : "blacklist"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SideButtonPickup extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:destructor.pickup") + TextFormatting.RESET + "\n" + gui.t(TileDestructor.PICKUP.getValue() ? "gui.yes" : "gui.no");
|
||||
return TextFormatting.GREEN + GuiBase.t("sidebutton.refinedstorage:destructor.pickup") + TextFormatting.RESET + "\n" + GuiBase.t(TileDestructor.PICKUP.getValue() ? "gui.yes" : "gui.no");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SideButtonRedstoneMode extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.RED + gui.t("sidebutton.refinedstorage:redstone_mode") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:redstone_mode." + parameter.getValue());
|
||||
return TextFormatting.RED + GuiBase.t("sidebutton.refinedstorage:redstone_mode") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:redstone_mode." + parameter.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SideButtonType extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.GREEN + gui.t("sidebutton.refinedstorage:type") + TextFormatting.RESET + "\n" + gui.t("sidebutton.refinedstorage:type." + type.getValue());
|
||||
return TextFormatting.GREEN + GuiBase.t("sidebutton.refinedstorage:type") + TextFormatting.RESET + "\n" + GuiBase.t("sidebutton.refinedstorage:type." + type.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ public class SideButtonVoidExcess extends SideButton {
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return TextFormatting.LIGHT_PURPLE + gui.t("sidebutton.refinedstorage:void_excess." + type) + TextFormatting.RESET + "\n" + gui.t(parameter.getValue() ? "gui.yes" : "gui.no");
|
||||
return TextFormatting.LIGHT_PURPLE + GuiBase.t("sidebutton.refinedstorage:void_excess." + type) + TextFormatting.RESET + "\n" + GuiBase.t(parameter.getValue() ? "gui.yes" : "gui.no");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
package refinedstorage.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewStack;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewStack;
|
||||
import refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import refinedstorage.apiimpl.API;
|
||||
import refinedstorage.proxy.ProxyClient;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHandler<MessageGridCraftingPreviewResponse, IMessage> {
|
||||
public List<ICraftingPreviewStack> stacks;
|
||||
public List<ICraftingPreviewElement> stacks;
|
||||
public int hash;
|
||||
public int quantity;
|
||||
|
||||
public MessageGridCraftingPreviewResponse() {
|
||||
}
|
||||
|
||||
public MessageGridCraftingPreviewResponse(List<ICraftingPreviewStack> stacks, int hash, int quantity) {
|
||||
public MessageGridCraftingPreviewResponse(List<ICraftingPreviewElement> stacks, int hash, int quantity) {
|
||||
this.stacks = stacks;
|
||||
this.hash = hash;
|
||||
this.quantity = quantity;
|
||||
@@ -35,7 +36,7 @@ public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHan
|
||||
int size = buf.readInt();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
this.stacks.add(CraftingPreviewStack.fromByteBuf(buf));
|
||||
this.stacks.add(API.instance().getCraftingPreviewElementRegistry().getFactory(ByteBufUtils.readUTF8String(buf)).apply(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +47,8 @@ public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHan
|
||||
|
||||
buf.writeInt(stacks.size());
|
||||
|
||||
for (ICraftingPreviewStack stack : stacks) {
|
||||
for (ICraftingPreviewElement stack : stacks) {
|
||||
ByteBufUtils.writeUTF8String(buf, stack.getId());
|
||||
stack.writeToByteBuf(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import refinedstorage.apiimpl.API;
|
||||
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementFluidRender;
|
||||
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementItemRender;
|
||||
import refinedstorage.apiimpl.autocrafting.craftingmonitor.CraftingMonitorElementText;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
|
||||
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementItemStack;
|
||||
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactory;
|
||||
import refinedstorage.apiimpl.solderer.*;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
|
||||
@@ -57,6 +59,9 @@ public class ProxyCommon {
|
||||
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementFluidRender.ID, buf -> new CraftingMonitorElementFluidRender(buf.readInt(), RSUtils.readFluidStack(buf).getRight(), buf.readInt()));
|
||||
API.instance().getCraftingMonitorElementRegistry().add(CraftingMonitorElementText.ID, buf -> new CraftingMonitorElementText(ByteBufUtils.readUTF8String(buf), buf.readInt()));
|
||||
|
||||
API.instance().getCraftingPreviewElementRegistry().add(CraftingPreviewElementItemStack.ID, CraftingPreviewElementItemStack::fromByteBuf);
|
||||
API.instance().getCraftingPreviewElementRegistry().add(CraftingPreviewElementFluidStack.ID, CraftingPreviewElementFluidStack::fromByteBuf);
|
||||
|
||||
int id = 0;
|
||||
|
||||
RS.INSTANCE.network.registerMessage(MessageTileDataParameter.class, MessageTileDataParameter.class, id++, Side.CLIENT);
|
||||
|
||||
Reference in New Issue
Block a user