Support for invs that have more or less than 9 slots in Crafter Manager
This commit is contained in:
@@ -37,6 +37,10 @@ public interface ICraftingPatternContainer {
|
|||||||
IItemHandlerModifiable getPatternInventory();
|
IItemHandlerModifiable getPatternInventory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The name of this container for categorizing in the Crafting Manager GUI.
|
||||||
|
* Can be a localized or unlocalized name.
|
||||||
|
* If it's unlocalized, it will automatically format the name.
|
||||||
|
*
|
||||||
* @return the name of this container
|
* @return the name of this container
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getName();
|
||||||
|
|||||||
@@ -302,15 +302,12 @@ public class CraftingManager implements ICraftingManager {
|
|||||||
|
|
||||||
patterns.addAll(container.getPatterns());
|
patterns.addAll(container.getPatterns());
|
||||||
|
|
||||||
// @todo: ???
|
// @todo: Crafter first!
|
||||||
if (container.getPatternInventory().getSlots() == 9 || true) {
|
if (!containerInventories.containsKey(container.getName())) {
|
||||||
// @todo: Crafter first!
|
containerInventories.put(container.getName(), new ArrayList<>());
|
||||||
if (!containerInventories.containsKey(container.getName())) {
|
|
||||||
containerInventories.put(container.getName(), new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
containerInventories.get(container.getName()).add(container.getPatternInventory());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
containerInventories.get(container.getName()).add(container.getPatternInventory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,10 @@ public class NetworkNodeCrafterManager extends NetworkNode {
|
|||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(EntityPlayerMP player) {
|
public void sendTo(EntityPlayerMP player) {
|
||||||
RS.INSTANCE.network.sendTo(new MessageCrafterManagerSlotSizes(network.getCraftingManager().getNamedContainers()), player);
|
if (network != null) {
|
||||||
|
RS.INSTANCE.network.sendTo(new MessageCrafterManagerSlotSizes(network.getCraftingManager().getNamedContainers()), player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class BlockCrafterManager extends BlockNode {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
if (!world.isRemote && tryOpenNetworkGui(RSGui.CRAFTER_MANAGER, player, world, pos, side, Permission.MODIFY, Permission.AUTOCRAFTING)) {
|
if (!world.isRemote && tryOpenNetworkGui(RSGui.CRAFTER_MANAGER, player, world, pos, side, Permission.MODIFY, Permission.AUTOCRAFTING)) {
|
||||||
((TileCrafterManager) world.getTileEntity(pos)).getNode().send((EntityPlayerMP) player);
|
((TileCrafterManager) world.getTileEntity(pos)).getNode().sendTo((EntityPlayerMP) player);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.container;
|
|||||||
import com.raoulvdberge.refinedstorage.gui.grid.IGridDisplay;
|
import com.raoulvdberge.refinedstorage.gui.grid.IGridDisplay;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileCrafterManager;
|
import com.raoulvdberge.refinedstorage.tile.TileCrafterManager;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
@@ -98,10 +99,12 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
if (!player.world.isRemote) {
|
if (!player.world.isRemote) {
|
||||||
addPlayerInventory(8, display.getYPlayerInventory());
|
addPlayerInventory(8, display.getYPlayerInventory());
|
||||||
|
|
||||||
for (Map.Entry<String, List<IItemHandlerModifiable>> entry : crafterManager.getNode().getNetwork().getCraftingManager().getNamedContainers().entrySet()) {
|
if (crafterManager.getNode().getNetwork() != null) {
|
||||||
for (IItemHandlerModifiable handler : entry.getValue()) {
|
for (Map.Entry<String, List<IItemHandlerModifiable>> entry : crafterManager.getNode().getNetwork().getCraftingManager().getNamedContainers().entrySet()) {
|
||||||
for (int i = 0; i < handler.getSlots(); ++i) {
|
for (IItemHandlerModifiable handler : entry.getValue()) {
|
||||||
addSlotToContainer(new SlotItemHandler(handler, i, 0, 0));
|
for (int i = 0; i < handler.getSlots(); ++i) {
|
||||||
|
addSlotToContainer(new SlotItemHandler(handler, i, 0, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,30 +128,36 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
addPlayerInventory(8, display.getYPlayerInventory());
|
addPlayerInventory(8, display.getYPlayerInventory());
|
||||||
|
|
||||||
int y = 19 + 18 - display.getCurrentOffset() * 18;
|
int y = 19 + 18 - display.getCurrentOffset() * 18;
|
||||||
|
int x = 8;
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> entry : containerData.entrySet()) {
|
for (Map.Entry<String, Integer> entry : containerData.entrySet()) {
|
||||||
boolean visible = entry.getKey().toLowerCase().contains(display.getSearchFieldText().toLowerCase());
|
// @todo: broken on servers prolly
|
||||||
|
boolean visible = I18n.format(entry.getKey()).toLowerCase().contains(display.getSearchFieldText().toLowerCase());
|
||||||
|
|
||||||
for (int i = 0; i < entry.getValue(); ++i) {
|
IItemHandlerModifiable dummy;
|
||||||
IItemHandlerModifiable dummy;
|
|
||||||
|
|
||||||
if (newContainerData == null) { // We're only resizing, get the previous inventory...
|
if (newContainerData == null) { // We're only resizing, get the previous inventory...
|
||||||
dummy = dummyInventories.get(entry.getKey() + "," + i);
|
dummy = dummyInventories.get(entry.getKey());
|
||||||
} else {
|
} else {
|
||||||
dummyInventories.put(entry.getKey() + "," + i, dummy = new ItemHandlerBase(9));
|
dummyInventories.put(entry.getKey(), dummy = new ItemHandlerBase(entry.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < 9; ++j) {
|
for (int slot = 0; slot < entry.getValue(); ++slot) {
|
||||||
addSlotToContainer(new SlotCrafterManager(dummy, j, 8 + j * 18, y, visible));
|
addSlotToContainer(new SlotCrafterManager(dummy, slot, x, y, visible));
|
||||||
}
|
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
y += 18;
|
x += 18;
|
||||||
|
|
||||||
|
if ((slot + 1) % 9 == 0) {
|
||||||
|
x = 8;
|
||||||
|
y += 18;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
y += 18;
|
x = 8;
|
||||||
|
y += 18 * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.raoulvdberge.refinedstorage.gui;
|
|||||||
import com.raoulvdberge.refinedstorage.container.ContainerCrafter;
|
import com.raoulvdberge.refinedstorage.container.ContainerCrafter;
|
||||||
import com.raoulvdberge.refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import com.raoulvdberge.refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileCrafter;
|
import com.raoulvdberge.refinedstorage.tile.TileCrafter;
|
||||||
import net.minecraft.client.resources.I18n;
|
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||||
|
|
||||||
public class GuiCrafter extends GuiBase {
|
public class GuiCrafter extends GuiBase {
|
||||||
public GuiCrafter(ContainerCrafter container) {
|
public GuiCrafter(ContainerCrafter container) {
|
||||||
@@ -28,7 +28,7 @@ public class GuiCrafter extends GuiBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY) {
|
||||||
drawString(7, 7, t(I18n.format(TileCrafter.NAME.getValue())));
|
drawString(7, 7, RenderUtils.shorten(t(TileCrafter.NAME.getValue()), 26));
|
||||||
drawString(7, 43, t("container.inventory"));
|
drawString(7, 43, t("container.inventory"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import com.raoulvdberge.refinedstorage.gui.sidebutton.SideButtonGridSize;
|
|||||||
import com.raoulvdberge.refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import com.raoulvdberge.refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileCrafterManager;
|
import com.raoulvdberge.refinedstorage.tile.TileCrafterManager;
|
||||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataManager;
|
import com.raoulvdberge.refinedstorage.tile.data.TileDataManager;
|
||||||
|
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||||
import net.minecraft.client.gui.GuiTextField;
|
import net.minecraft.client.gui.GuiTextField;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
|
import net.minecraft.inventory.Slot;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -76,9 +78,9 @@ public class GuiCrafterManager extends GuiBase implements IGridDisplay {
|
|||||||
int rows = 0;
|
int rows = 0;
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> containerData : container.getContainerData().entrySet()) {
|
for (Map.Entry<String, Integer> containerData : container.getContainerData().entrySet()) {
|
||||||
if (containerData.getKey().toLowerCase().contains(getSearchFieldText().toLowerCase())) {
|
if (t(containerData.getKey()).toLowerCase().contains(getSearchFieldText().toLowerCase())) {
|
||||||
rows++;
|
rows++;
|
||||||
rows += containerData.getValue();
|
rows += Math.ceil((double) Math.max(9, containerData.getValue()) / 9D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,15 +143,25 @@ public class GuiCrafterManager extends GuiBase implements IGridDisplay {
|
|||||||
|
|
||||||
int rows = getVisibleRows();
|
int rows = getVisibleRows();
|
||||||
|
|
||||||
for (int i = 0; i < rows; ++i) {
|
int yy = y;
|
||||||
y += 18;
|
|
||||||
|
|
||||||
drawTexture(x, y, 0, getHeader() + (i > 0 ? (i == rows - 1 ? 18 * 2 : 18) : 0), screenWidth, 18);
|
for (int i = 0; i < rows; ++i) {
|
||||||
|
yy += 18;
|
||||||
|
|
||||||
|
drawTexture(x, yy, 0, getHeader() + (i > 0 ? (i == rows - 1 ? 18 * 2 : 18) : 0), screenWidth, 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
y += 18;
|
yy += 18;
|
||||||
|
|
||||||
drawTexture(x, y, 0, getHeader() + (18 * 3), screenWidth, getFooter());
|
drawTexture(x, yy, 0, getHeader() + (18 * 3), screenWidth, getFooter());
|
||||||
|
|
||||||
|
if (container != null) {
|
||||||
|
for (Slot slot : container.inventorySlots) {
|
||||||
|
if (slot instanceof ContainerCrafterManager.SlotCrafterManager && slot.isEnabled()) {
|
||||||
|
drawTexture(x + slot.xPos - 1, y + slot.yPos - 1, 0, 193, 18, 18);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (searchField != null) {
|
if (searchField != null) {
|
||||||
searchField.drawTextBox();
|
searchField.drawTextBox();
|
||||||
@@ -185,12 +197,12 @@ public class GuiCrafterManager extends GuiBase implements IGridDisplay {
|
|||||||
drawString(7, 7, t("gui.refinedstorage:crafter_manager"));
|
drawString(7, 7, t("gui.refinedstorage:crafter_manager"));
|
||||||
drawString(7, getYPlayerInventory() - 12, t("container.inventory"));
|
drawString(7, getYPlayerInventory() - 12, t("container.inventory"));
|
||||||
|
|
||||||
if (container != null) {
|
if (container != null && container.getContainerData() != null) {
|
||||||
int x = 7;
|
int x = 7;
|
||||||
int y = 18 - getCurrentOffset() * 18;
|
int y = 18 - getCurrentOffset() * 18;
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> entry : container.getContainerData().entrySet()) {
|
for (Map.Entry<String, Integer> entry : container.getContainerData().entrySet()) {
|
||||||
if (entry.getKey().toLowerCase().contains(getSearchFieldText().toLowerCase())) {
|
if (t(entry.getKey()).toLowerCase().contains(getSearchFieldText().toLowerCase())) {
|
||||||
if (y >= getHeader() - 1 && y < getHeader() + getVisibleRows() * 18 - 1) {
|
if (y >= getHeader() - 1 && y < getHeader() + getVisibleRows() * 18 - 1) {
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
GlStateManager.color(1, 1, 1);
|
GlStateManager.color(1, 1, 1);
|
||||||
@@ -199,14 +211,12 @@ public class GuiCrafterManager extends GuiBase implements IGridDisplay {
|
|||||||
|
|
||||||
drawTexturedModalRect(x, y, 0, 174, 18 * 9, 18);
|
drawTexturedModalRect(x, y, 0, 174, 18 * 9, 18);
|
||||||
|
|
||||||
drawString(x + 4, y + 5, I18n.format(entry.getKey()));
|
drawString(x + 4, y + 6, RenderUtils.shorten(I18n.format(entry.getKey()), 25));
|
||||||
}
|
}
|
||||||
|
|
||||||
y += (entry.getValue() + 1) * 18;
|
y += (Math.ceil((double) Math.max(9, entry.getValue()) / 9D) + 1) * 18;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,12 @@ public class MessageCrafterManagerSlotSizes implements IMessage, IMessageHandler
|
|||||||
|
|
||||||
for (Map.Entry<String, List<IItemHandlerModifiable>> entry : containerData.entrySet()) {
|
for (Map.Entry<String, List<IItemHandlerModifiable>> entry : containerData.entrySet()) {
|
||||||
ByteBufUtils.writeUTF8String(buf, entry.getKey());
|
ByteBufUtils.writeUTF8String(buf, entry.getKey());
|
||||||
buf.writeInt(entry.getValue().size());
|
|
||||||
|
int slots = 0;
|
||||||
|
for (IItemHandlerModifiable handler : entry.getValue()) {
|
||||||
|
slots += handler.getSlots();
|
||||||
|
}
|
||||||
|
buf.writeInt(slots);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,13 @@ public final class RenderUtils {
|
|||||||
return start.addVector(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
|
return start.addVector(lookVec.x * reachDistance, lookVec.y * reachDistance, lookVec.z * reachDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String shorten(String text, int length) {
|
||||||
|
if (text.length() > length) {
|
||||||
|
text = text.substring(0, length) + "...";
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vec3d start, Vec3d end, Collection<AxisAlignedBB> boxes) {
|
public static AdvancedRayTraceResult collisionRayTrace(BlockPos pos, Vec3d start, Vec3d end, Collection<AxisAlignedBB> boxes) {
|
||||||
double minDistance = Double.POSITIVE_INFINITY;
|
double minDistance = Double.POSITIVE_INFINITY;
|
||||||
AdvancedRayTraceResult hit = null;
|
AdvancedRayTraceResult hit = null;
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Reference in New Issue
Block a user