Coding style / naming fixes
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
# Refined Storage Changelog
|
# Refined Storage Changelog
|
||||||
|
|
||||||
|
### 1.0.6
|
||||||
|
- Added crafting preview screen (way2muchnoise)
|
||||||
|
|
||||||
### 1.0.5
|
### 1.0.5
|
||||||
- Fixed crafting a complex item causes the process to flow off the Crafting Monitor's GUI (raoulvdberge)
|
- Fixed crafting a complex item causes the process to flow off the Crafting Monitor's GUI (raoulvdberge)
|
||||||
- Fixed shift clicking from Grid when player inventory is full throwing items in the world (raoulvdberge)
|
- Fixed shift clicking from Grid when player inventory is full throwing items in the world (raoulvdberge)
|
||||||
|
@@ -1,72 +0,0 @@
|
|||||||
package refinedstorage.apiimpl.autocrafting;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
|
||||||
import refinedstorage.api.network.NetworkUtils;
|
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public final class CraftingUtils {
|
|
||||||
public static Collection<AutoCraftInfoStack> getItems(INetworkMaster network, ItemStack stack, int quantity) {
|
|
||||||
AutoCraftInfoData data = new AutoCraftInfoData(network);
|
|
||||||
calcItems(network, stack, quantity, data);
|
|
||||||
return data.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void calcItems(INetworkMaster network, ItemStack stack, int quantity, AutoCraftInfoData data) {
|
|
||||||
quantity = -data.add(stack, quantity);
|
|
||||||
if (quantity > 0) {
|
|
||||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);
|
|
||||||
if (pattern != null) {
|
|
||||||
int quantityPerRequest = pattern.getQuantityPerRequest(stack);
|
|
||||||
while (quantity > 0) {
|
|
||||||
for (ItemStack ingredient : pattern.getInputs()) {
|
|
||||||
calcItems(network, ingredient, ingredient.stackSize, data);
|
|
||||||
}
|
|
||||||
data.get(stack).addExtras(quantityPerRequest);
|
|
||||||
quantity -= quantityPerRequest;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data.get(stack).setCantCraft(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class AutoCraftInfoData {
|
|
||||||
private HashMap<Integer, AutoCraftInfoStack> data;
|
|
||||||
private INetworkMaster network;
|
|
||||||
|
|
||||||
private AutoCraftInfoData(INetworkMaster network) {
|
|
||||||
this.data = new HashMap<>();
|
|
||||||
this.network = network;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return available stacks, if negative needs crafting
|
|
||||||
*/
|
|
||||||
private int add(ItemStack stack, int quantity) {
|
|
||||||
int hash = NetworkUtils.getItemStackHashCode(stack);
|
|
||||||
if (data.containsKey(hash)) {
|
|
||||||
AutoCraftInfoStack infoStack = data.get(hash);
|
|
||||||
infoStack.addNeeded(quantity);
|
|
||||||
return infoStack.getAvailable();
|
|
||||||
} else {
|
|
||||||
ItemStack networkStack = network.getItemStorage().get(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
|
|
||||||
AutoCraftInfoStack infoStack = new AutoCraftInfoStack(stack, quantity, networkStack == null ? 0 : networkStack.stackSize);
|
|
||||||
data.put(hash, infoStack);
|
|
||||||
return infoStack.getAvailable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private AutoCraftInfoStack get(ItemStack stack) {
|
|
||||||
return this.data.get(NetworkUtils.getItemStackHashCode(stack));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Collection<AutoCraftInfoStack> values() {
|
|
||||||
return this.data.values();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,70 @@
|
|||||||
|
package refinedstorage.apiimpl.autocrafting.preview;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
|
import refinedstorage.api.network.NetworkUtils;
|
||||||
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class CraftingPreviewData {
|
||||||
|
private HashMap<Integer, CraftingPreviewStack> data = new HashMap<>();
|
||||||
|
private INetworkMaster network;
|
||||||
|
|
||||||
|
public CraftingPreviewData(INetworkMaster network) {
|
||||||
|
this.network = network;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculate(ItemStack stack, int quantity) {
|
||||||
|
quantity = -add(stack, quantity);
|
||||||
|
if (quantity > 0) {
|
||||||
|
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);
|
||||||
|
|
||||||
|
if (pattern != null) {
|
||||||
|
int quantityPerRequest = pattern.getQuantityPerRequest(stack);
|
||||||
|
|
||||||
|
while (quantity > 0) {
|
||||||
|
for (ItemStack ingredient : pattern.getInputs()) {
|
||||||
|
calculate(ingredient, ingredient.stackSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
get(stack).addExtras(quantityPerRequest);
|
||||||
|
|
||||||
|
quantity -= quantityPerRequest;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
get(stack).setCantCraft(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int add(ItemStack stack, int quantity) {
|
||||||
|
int hash = NetworkUtils.getItemStackHashCode(stack);
|
||||||
|
|
||||||
|
if (data.containsKey(hash)) {
|
||||||
|
CraftingPreviewStack previewStack = data.get(hash);
|
||||||
|
|
||||||
|
previewStack.addNeeded(quantity);
|
||||||
|
|
||||||
|
return previewStack.getAvailable();
|
||||||
|
} else {
|
||||||
|
ItemStack networkStack = network.getItemStorage().get(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
|
||||||
|
|
||||||
|
CraftingPreviewStack previewStack = new CraftingPreviewStack(stack, quantity, networkStack == null ? 0 : networkStack.stackSize);
|
||||||
|
|
||||||
|
data.put(hash, previewStack);
|
||||||
|
|
||||||
|
return previewStack.getAvailable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftingPreviewStack get(ItemStack stack) {
|
||||||
|
return data.get(NetworkUtils.getItemStackHashCode(stack));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<CraftingPreviewStack> values() {
|
||||||
|
return this.data.values();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,17 +1,17 @@
|
|||||||
package refinedstorage.apiimpl.autocrafting;
|
package refinedstorage.apiimpl.autocrafting.preview;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class AutoCraftInfoStack {
|
public class CraftingPreviewStack {
|
||||||
private ItemStack stack;
|
private ItemStack stack;
|
||||||
private int needed;
|
private int needed;
|
||||||
private int stock;
|
private int stock;
|
||||||
private int extras;
|
private int extras;
|
||||||
private boolean cantCraft;
|
private boolean cantCraft;
|
||||||
|
|
||||||
public AutoCraftInfoStack(ItemStack stack, int needed, int stock) {
|
public CraftingPreviewStack(ItemStack stack, int needed, int stock) {
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
this.needed = needed;
|
this.needed = needed;
|
||||||
this.stock = stock;
|
this.stock = stock;
|
||||||
@@ -28,14 +28,17 @@ public class AutoCraftInfoStack {
|
|||||||
buf.writeBoolean(cantCraft);
|
buf.writeBoolean(cantCraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AutoCraftInfoStack fromByteBuf(ByteBuf buf) {
|
public static CraftingPreviewStack fromByteBuf(ByteBuf buf) {
|
||||||
Item item = Item.getItemById(buf.readInt());
|
Item item = Item.getItemById(buf.readInt());
|
||||||
int meta = buf.readInt();
|
int meta = buf.readInt();
|
||||||
int toCraft = buf.readInt();
|
int toCraft = buf.readInt();
|
||||||
int available = buf.readInt();
|
int available = buf.readInt();
|
||||||
AutoCraftInfoStack stack = new AutoCraftInfoStack(new ItemStack(item, 1, meta), toCraft, available);
|
|
||||||
|
CraftingPreviewStack stack = new CraftingPreviewStack(new ItemStack(item, 1, meta), toCraft, available);
|
||||||
|
|
||||||
stack.extras = buf.readInt();
|
stack.extras = buf.readInt();
|
||||||
stack.cantCraft = buf.readBoolean();
|
stack.cantCraft = buf.readBoolean();
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,11 +81,4 @@ public class AutoCraftInfoStack {
|
|||||||
public void setCantCraft(boolean cantCraft) {
|
public void setCantCraft(boolean cantCraft) {
|
||||||
this.cantCraft = cantCraft;
|
this.cantCraft = cantCraft;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return stack.toString() + ", needed=" + needed + ", stock=" + stock + ", extras=" + extras + ", canCraft=" + !cantCraft;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
29
src/main/java/refinedstorage/gui/GuiCraftingPreview.java
Normal file → Executable file
29
src/main/java/refinedstorage/gui/GuiCraftingPreview.java
Normal file → Executable file
@@ -1,6 +1,5 @@
|
|||||||
package refinedstorage.gui;
|
package refinedstorage.gui;
|
||||||
|
|
||||||
import com.google.common.primitives.Ints;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
@@ -12,8 +11,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.apiimpl.autocrafting.AutoCraftInfoStack;
|
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewStack;
|
||||||
import refinedstorage.network.MessageGridCraftingPreview;
|
|
||||||
import refinedstorage.network.MessageGridCraftingStart;
|
import refinedstorage.network.MessageGridCraftingStart;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -24,21 +22,23 @@ import java.util.List;
|
|||||||
public class GuiCraftingPreview extends GuiBase {
|
public class GuiCraftingPreview extends GuiBase {
|
||||||
private static final int VISIBLE_ROWS = 8;
|
private static final int VISIBLE_ROWS = 8;
|
||||||
|
|
||||||
private List<AutoCraftInfoStack> stacks;
|
private List<CraftingPreviewStack> stacks;
|
||||||
private GuiScreen parent;
|
private GuiScreen parent;
|
||||||
|
|
||||||
private int hash, quantity;
|
private int hash;
|
||||||
|
private int quantity;
|
||||||
|
|
||||||
private GuiButton startButton;
|
private GuiButton startButton;
|
||||||
private GuiButton cancelButton;
|
private GuiButton cancelButton;
|
||||||
|
|
||||||
public GuiCraftingPreview(GuiScreen parent, Collection<AutoCraftInfoStack> stacks, int hash, int quantity) {
|
public GuiCraftingPreview(GuiScreen parent, Collection<CraftingPreviewStack> stacks, int hash, int quantity) {
|
||||||
super(new Container() {
|
super(new Container() {
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteractWith(EntityPlayer playerIn) {
|
public boolean canInteractWith(EntityPlayer player) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}, 176, 181);
|
}, 176, 181);
|
||||||
|
|
||||||
this.stacks = new ArrayList<>(stacks);
|
this.stacks = new ArrayList<>(stacks);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ public class GuiCraftingPreview extends GuiBase {
|
|||||||
startButton = addButton(x + 100, y + 150, 50, 20, t("misc.refinedstorage:start"));
|
startButton = addButton(x + 100, y + 150, 50, 20, t("misc.refinedstorage:start"));
|
||||||
cancelButton = addButton(x + 20, y + 150, 50, 20, t("gui.cancel"));
|
cancelButton = addButton(x + 20, y + 150, 50, 20, t("gui.cancel"));
|
||||||
|
|
||||||
startButton.enabled = stacks.stream().filter(AutoCraftInfoStack::cantCraft).count() == 0;
|
startButton.enabled = stacks.stream().filter(CraftingPreviewStack::cantCraft).count() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,26 +74,27 @@ public class GuiCraftingPreview extends GuiBase {
|
|||||||
int slot = scrollbar.getOffset() * 2;
|
int slot = scrollbar.getOffset() * 2;
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
if (slot < stacks.size()) {
|
if (slot < stacks.size()) {
|
||||||
AutoCraftInfoStack stack = stacks.get(slot);
|
CraftingPreviewStack stack = stacks.get(slot);
|
||||||
|
|
||||||
if (stack.cantCraft()) {
|
if (stack.cantCraft()) {
|
||||||
drawTexture(x, y, 0, 185, 67, 29);
|
drawTexture(x, y, 0, 185, 67, 29);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i%2 == 1) {
|
if (i % 2 == 1) {
|
||||||
x -= 68;
|
x -= 68;
|
||||||
y += 30;
|
y += 30;
|
||||||
} else {
|
} else {
|
||||||
x += 68;
|
x += 68;
|
||||||
}
|
}
|
||||||
|
|
||||||
slot++;
|
slot++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY) {
|
||||||
drawString(7, 7, t("gui.refinedstorage:crafting_preview.title"));
|
drawString(7, 7, t("gui.refinedstorage:crafting_preview"));
|
||||||
|
|
||||||
int x = 22;
|
int x = 22;
|
||||||
int y = 22;
|
int y = 22;
|
||||||
@@ -106,7 +107,7 @@ public class GuiCraftingPreview extends GuiBase {
|
|||||||
|
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
if (slot < stacks.size()) {
|
if (slot < stacks.size()) {
|
||||||
AutoCraftInfoStack stack = stacks.get(slot);
|
CraftingPreviewStack stack = stacks.get(slot);
|
||||||
|
|
||||||
drawItem(x, y + 5, stack.getStack());
|
drawItem(x, y + 5, stack.getStack());
|
||||||
|
|
||||||
@@ -116,10 +117,10 @@ public class GuiCraftingPreview extends GuiBase {
|
|||||||
GlStateManager.scale(scale, scale, 1);
|
GlStateManager.scale(scale, scale, 1);
|
||||||
|
|
||||||
if (stack.needsCrafting()) {
|
if (stack.needsCrafting()) {
|
||||||
|
|
||||||
String format = stack.cantCraft() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft";
|
String format = stack.cantCraft() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft";
|
||||||
drawString(calculateOffsetOnScale(x + 20, scale), calculateOffsetOnScale(y + 8, scale), t(format, stack.getToCraft()));
|
drawString(calculateOffsetOnScale(x + 20, scale), calculateOffsetOnScale(y + 8, scale), t(format, stack.getToCraft()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.getStock() > 0) {
|
if (stack.getStock() > 0) {
|
||||||
drawString(calculateOffsetOnScale(x + 20, scale), calculateOffsetOnScale(y + 13, scale), t("gui.refinedstorage:crafting_preview.available", stack.getStock()));
|
drawString(calculateOffsetOnScale(x + 20, scale), calculateOffsetOnScale(y + 13, scale), t("gui.refinedstorage:crafting_preview.available", stack.getStock()));
|
||||||
}
|
}
|
||||||
@@ -140,6 +141,7 @@ public class GuiCraftingPreview extends GuiBase {
|
|||||||
|
|
||||||
slot++;
|
slot++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hoveringStack != null) {
|
if (hoveringStack != null) {
|
||||||
drawTooltip(mouseX, mouseY, hoveringStack.getTooltip(Minecraft.getMinecraft().thePlayer, false));
|
drawTooltip(mouseX, mouseY, hoveringStack.getTooltip(Minecraft.getMinecraft().thePlayer, false));
|
||||||
}
|
}
|
||||||
@@ -169,6 +171,7 @@ public class GuiCraftingPreview extends GuiBase {
|
|||||||
|
|
||||||
private void startRequest() {
|
private void startRequest() {
|
||||||
RefinedStorage.INSTANCE.network.sendToServer(new MessageGridCraftingStart(hash, quantity));
|
RefinedStorage.INSTANCE.network.sendToServer(new MessageGridCraftingStart(hash, quantity));
|
||||||
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,7 +2,6 @@ package refinedstorage.gui.grid;
|
|||||||
|
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
|
||||||
import net.minecraft.client.gui.GuiTextField;
|
import net.minecraft.client.gui.GuiTextField;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||||
@@ -19,16 +18,16 @@ public class GuiCraftingStart extends GuiBase {
|
|||||||
private static final int DEFAULT_AMOUNT = 1;
|
private static final int DEFAULT_AMOUNT = 1;
|
||||||
|
|
||||||
private GuiTextField amountField;
|
private GuiTextField amountField;
|
||||||
private GuiGrid gui;
|
private GuiGrid parent;
|
||||||
private ClientStackItem stack;
|
private ClientStackItem stack;
|
||||||
private GuiButton startButton;
|
private GuiButton startButton;
|
||||||
private GuiButton cancelButton;
|
private GuiButton cancelButton;
|
||||||
private GuiButton[] incrementButtons = new GuiButton[6];
|
private GuiButton[] incrementButtons = new GuiButton[6];
|
||||||
|
|
||||||
public GuiCraftingStart(GuiGrid gui, EntityPlayer player, ClientStackItem stack) {
|
public GuiCraftingStart(GuiGrid parent, EntityPlayer player, ClientStackItem stack) {
|
||||||
super(new ContainerCraftingSettings(player, stack.getStack()), 172, 99);
|
super(new ContainerCraftingSettings(player, stack.getStack()), 172, 99);
|
||||||
|
|
||||||
this.gui = gui;
|
this.parent = parent;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +129,10 @@ public class GuiCraftingStart extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void close() {
|
private void close() {
|
||||||
FMLClientHandler.instance().showGuiScreen(gui);
|
FMLClientHandler.instance().showGuiScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiGrid getGui() {
|
public GuiGrid getParent() {
|
||||||
return gui;
|
return parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
src/main/java/refinedstorage/network/MessageGridCraftingPreview.java
Normal file → Executable file
25
src/main/java/refinedstorage/network/MessageGridCraftingPreview.java
Normal file → Executable file
@@ -3,16 +3,14 @@ package refinedstorage.network;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
import refinedstorage.apiimpl.autocrafting.AutoCraftInfoStack;
|
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewData;
|
||||||
import refinedstorage.apiimpl.autocrafting.CraftingUtils;
|
|
||||||
import refinedstorage.container.ContainerGrid;
|
import refinedstorage.container.ContainerGrid;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class MessageGridCraftingPreview extends MessageHandlerPlayerToServer<MessageGridCraftingPreview> implements IMessage {
|
public class MessageGridCraftingPreview extends MessageHandlerPlayerToServer<MessageGridCraftingPreview> implements IMessage {
|
||||||
private int hash;
|
private int hash;
|
||||||
private int quantity;
|
private int quantity;
|
||||||
@@ -42,11 +40,20 @@ public class MessageGridCraftingPreview extends MessageHandlerPlayerToServer<Mes
|
|||||||
Container container = player.openContainer;
|
Container container = player.openContainer;
|
||||||
|
|
||||||
if (container instanceof ContainerGrid) {
|
if (container instanceof ContainerGrid) {
|
||||||
TileEntity entity = player.getEntityWorld().getTileEntity(((ContainerGrid) container).getGrid().getNetworkPosition());
|
TileEntity tile = player.getEntityWorld().getTileEntity(((ContainerGrid) container).getGrid().getNetworkPosition());
|
||||||
if (entity != null && entity instanceof INetworkMaster) {
|
|
||||||
INetworkMaster network = (INetworkMaster) entity;
|
if (tile != null && tile instanceof INetworkMaster) {
|
||||||
Collection<AutoCraftInfoStack> stacks = CraftingUtils.getItems(network, network.getItemStorage().get(message.hash), message.quantity);
|
INetworkMaster network = (INetworkMaster) tile;
|
||||||
RefinedStorage.INSTANCE.network.sendTo(new MessageGridCraftingPreviewResponse(stacks, message.hash, message.quantity), player);
|
|
||||||
|
ItemStack stack = network.getItemStorage().get(message.hash);
|
||||||
|
|
||||||
|
if (stack != null) {
|
||||||
|
CraftingPreviewData previewData = new CraftingPreviewData(network);
|
||||||
|
|
||||||
|
previewData.calculate(stack, message.quantity);
|
||||||
|
|
||||||
|
RefinedStorage.INSTANCE.network.sendTo(new MessageGridCraftingPreviewResponse(previewData.values(), message.hash, message.quantity), player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
src/main/java/refinedstorage/network/MessageGridCraftingPreviewResponse.java
Normal file → Executable file
25
src/main/java/refinedstorage/network/MessageGridCraftingPreviewResponse.java
Normal file → Executable file
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
|||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
import refinedstorage.apiimpl.autocrafting.AutoCraftInfoStack;
|
import refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewStack;
|
||||||
import refinedstorage.gui.GuiCraftingPreview;
|
import refinedstorage.gui.GuiCraftingPreview;
|
||||||
import refinedstorage.gui.grid.GuiCraftingStart;
|
import refinedstorage.gui.grid.GuiCraftingStart;
|
||||||
|
|
||||||
@@ -15,15 +15,14 @@ import java.util.Collection;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHandler<MessageGridCraftingPreviewResponse, IMessage> {
|
public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHandler<MessageGridCraftingPreviewResponse, IMessage> {
|
||||||
|
private Collection<CraftingPreviewStack> stacks;
|
||||||
private Collection<AutoCraftInfoStack> stacks;
|
private int hash;
|
||||||
private int hash, quantity;
|
private int quantity;
|
||||||
|
|
||||||
public MessageGridCraftingPreviewResponse() {
|
public MessageGridCraftingPreviewResponse() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageGridCraftingPreviewResponse(Collection<AutoCraftInfoStack> stacks, int hash, int quantity) {
|
public MessageGridCraftingPreviewResponse(Collection<CraftingPreviewStack> stacks, int hash, int quantity) {
|
||||||
this.stacks = stacks;
|
this.stacks = stacks;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
@@ -35,9 +34,11 @@ public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHan
|
|||||||
this.quantity = buf.readInt();
|
this.quantity = buf.readInt();
|
||||||
|
|
||||||
this.stacks = new LinkedList<>();
|
this.stacks = new LinkedList<>();
|
||||||
|
|
||||||
int size = buf.readInt();
|
int size = buf.readInt();
|
||||||
for (int i = 0 ; i < size; i++) {
|
|
||||||
this.stacks.add(AutoCraftInfoStack.fromByteBuf(buf));
|
for (int i = 0; i < size; i++) {
|
||||||
|
this.stacks.add(CraftingPreviewStack.fromByteBuf(buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +48,8 @@ public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHan
|
|||||||
buf.writeInt(this.quantity);
|
buf.writeInt(this.quantity);
|
||||||
|
|
||||||
buf.writeInt(stacks.size());
|
buf.writeInt(stacks.size());
|
||||||
for (AutoCraftInfoStack stack : stacks) {
|
|
||||||
|
for (CraftingPreviewStack stack : stacks) {
|
||||||
stack.writeToByteBuf(buf);
|
stack.writeToByteBuf(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,10 +57,13 @@ public class MessageGridCraftingPreviewResponse implements IMessage, IMessageHan
|
|||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageGridCraftingPreviewResponse message, MessageContext ctx) {
|
public IMessage onMessage(MessageGridCraftingPreviewResponse message, MessageContext ctx) {
|
||||||
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
||||||
|
|
||||||
if (screen instanceof GuiCraftingStart) {
|
if (screen instanceof GuiCraftingStart) {
|
||||||
screen = ((GuiCraftingStart) screen).getGui();
|
screen = ((GuiCraftingStart) screen).getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingPreview(screen, message.stacks, message.hash, message.quantity));
|
FMLCommonHandler.instance().showGuiScreen(new GuiCraftingPreview(screen, message.stacks, message.hash, message.quantity));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,8 +41,8 @@ gui.refinedstorage:network_transmitter.missing_upgrade=Insert upgrade
|
|||||||
gui.refinedstorage:fluid_interface=Fluid Interface
|
gui.refinedstorage:fluid_interface=Fluid Interface
|
||||||
gui.refinedstorage:fluid_interface.in=In
|
gui.refinedstorage:fluid_interface.in=In
|
||||||
gui.refinedstorage:fluid_interface.out=Out
|
gui.refinedstorage:fluid_interface.out=Out
|
||||||
gui.refinedstorage:crafting_preview.title=Crafting Preview
|
gui.refinedstorage:crafting_preview=Crafting Preview
|
||||||
gui.refinedstorage:crafting_preview.to_craft=To Craft: %d
|
gui.refinedstorage:crafting_preview.to_craft=To craft: %d
|
||||||
gui.refinedstorage:crafting_preview.available=Available: %d
|
gui.refinedstorage:crafting_preview.available=Available: %d
|
||||||
gui.refinedstorage:crafting_preview.missing=Missing: %d
|
gui.refinedstorage:crafting_preview.missing=Missing: %d
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user