Configurable Logistical Contollers

- Added Containers and GUIs for Logistical Controllers
This commit is contained in:
simibubi 2019-10-06 21:49:44 +02:00
parent 0f9cb916cd
commit 4e69d98ebc
35 changed files with 866 additions and 193 deletions

View file

@ -2,6 +2,8 @@ package com.simibubi.create;
import com.simibubi.create.modules.logistics.block.inventories.FlexcrateContainer;
import com.simibubi.create.modules.logistics.block.inventories.FlexcrateScreen;
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerContainer;
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerScreen;
import com.simibubi.create.modules.logistics.management.index.LogisticalIndexContainer;
import com.simibubi.create.modules.logistics.management.index.LogisticalIndexScreen;
import com.simibubi.create.modules.schematics.block.SchematicTableContainer;
@ -32,6 +34,7 @@ public enum AllContainers {
SCHEMATICANNON(SchematicannonContainer::new),
FLEXCRATE(FlexcrateContainer::new),
LOGISTICAL_INDEX(LogisticalIndexContainer::new),
LOGISTICAL_CONTROLLER(LogisticalInventoryControllerContainer::new),
;
@ -58,6 +61,7 @@ public enum AllContainers {
bind(SCHEMATICANNON, SchematicannonScreen::new);
bind(FLEXCRATE, FlexcrateScreen::new);
bind(LOGISTICAL_INDEX, LogisticalIndexScreen::new);
bind(LOGISTICAL_CONTROLLER, LogisticalInventoryControllerScreen::new);
}
@OnlyIn(Dist.CLIENT)

View file

@ -11,6 +11,7 @@ import com.simibubi.create.modules.contraptions.receivers.constructs.ConfigureCh
import com.simibubi.create.modules.curiosities.placementHandgun.BuilderGunBeamPacket;
import com.simibubi.create.modules.curiosities.symmetry.SymmetryEffectPacket;
import com.simibubi.create.modules.logistics.block.diodes.ConfigureFlexpeaterPacket;
import com.simibubi.create.modules.logistics.management.controller.LogisticalControllerConfigurationPacket;
import com.simibubi.create.modules.logistics.management.index.IndexContainerUpdatePacket;
import com.simibubi.create.modules.logistics.management.index.IndexOrderRequest;
import com.simibubi.create.modules.logistics.packet.ConfigureFlexcratePacket;
@ -35,6 +36,8 @@ public enum AllPackets {
CONFIGURE_CHASSIS(ConfigureChassisPacket.class, ConfigureChassisPacket::new),
CONFIGURE_MOTOR(ConfigureMotorPacket.class, ConfigureMotorPacket::new),
CONFIGURE_FLEXPEATER(ConfigureFlexpeaterPacket.class, ConfigureFlexpeaterPacket::new),
CONFIGURE_LOGISTICAL_CONTROLLER(LogisticalControllerConfigurationPacket.class,
LogisticalControllerConfigurationPacket::new),
PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new),
UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new),
INDEX_ORDER_REQUEST(IndexOrderRequest.class, IndexOrderRequest::new),

View file

@ -46,6 +46,13 @@ public enum ScreenResources {
INDEX_SEARCH("index.png", 0, 99, 28, 19),
INDEX_SEARCH_OVERLAY("widgets.png", 0, 81, 176, 20),
LOGISTICAL_CONTROLLER_TRIM("controller.png", 178, 6),
LOGISTICAL_CONTROLLER("controller.png", 0, 6, 185, 71),
ITEM_COUNT_SCROLLAREA("controller.png", 62, 83, 22, 10),
BIG_SLOT("controller.png", 0, 83, 26, 26),
SHIPPING_SLOT("controller.png", 26, 83, 18, 21),
RECEIVING_SLOT("controller.png", 44, 83, 18, 21),
SLOT_FRAME("index.png", 0, 118, 18, 18),
SLOT_INNER("index.png", 18, 118, 18, 18),
DISABLED_SLOT_FRAME("index.png", 0, 136, 18, 18),
@ -77,43 +84,50 @@ public enum ScreenResources {
BLUEPRINT_SLOT("widgets.png", 90, 0, 24, 24),
// Icons
ICON_NONE("icons.png", 16, 16, 16, 16),
ICON_ADD("icons.png", 16, 16),
ICON_TRASH("icons.png", 16, 0, 16, 16),
ICON_3x3("icons.png", 32, 0, 16, 16),
ICON_TARGET("icons.png", 48, 0, 16, 16),
ICON_CONFIRM("icons.png", 0, 16, 16, 16),
I_NONE(16, 16),
I_ADD(0, 0),
I_TRASH(16, 0),
I_3x3(32, 0),
I_TARGET(48, 0),
I_CONFIRM(0, 16),
ICON_OPEN_FOLDER("icons.png", 32, 16, 16, 16),
ICON_REFRESH("icons.png", 48, 16, 16, 16),
I_OPEN_FOLDER(32, 16),
I_REFRESH(48, 16),
ICON_DONT_REPLACE("icons.png", 0, 32, 16, 16),
ICON_REPLACE_SOLID("icons.png", 16, 32, 16, 16),
ICON_REPLACE_ANY("icons.png", 32, 32, 16, 16),
ICON_REPLACE_EMPTY("icons.png", 48, 32, 16, 16),
I_DONT_REPLACE(0, 32),
I_REPLACE_SOLID(16, 32),
I_REPLACE_ANY(32, 32),
I_REPLACE_EMPTY(48, 32),
ICON_TOOL_DEPLOY("icons.png", 0, 48, 16, 16),
ICON_SKIP_MISSING("icons.png", 16, 48, 16, 16),
ICON_SKIP_TILES("icons.png", 32, 48, 16, 16),
I_TOOL_DEPLOY(0, 48),
I_SKIP_MISSING(16, 48),
I_SKIP_TILES(32, 48),
ICON_TOOL_MOVE_XZ("icons.png", 0, 64, 16, 16),
ICON_TOOL_MOVE_Y("icons.png", 16, 64, 16, 16),
ICON_TOOL_ROTATE("icons.png", 32, 64, 16, 16),
ICON_TOOL_MIRROR("icons.png", 48, 64, 16, 16),
I_TOOL_MOVE_XZ(0, 64),
I_TOOL_MOVE_Y(16, 64),
I_TOOL_ROTATE(32, 64),
I_TOOL_MIRROR(48, 64),
ICON_PLAY("icons.png", 0, 80, 16, 16),
ICON_PAUSE("icons.png", 16, 80, 16, 16),
ICON_STOP("icons.png", 32, 80, 16, 16),
I_PLAY(0, 80),
I_PAUSE(16, 80),
I_STOP(32, 80),
ICON_PATTERN_SOLID("icons.png", 0, 96, 16, 16),
ICON_PATTERN_CHECKERED("icons.png", 16, 96, 16, 16),
ICON_PATTERN_CHECKERED_INVERSED("icons.png", 32, 96, 16, 16),
ICON_PATTERN_CHANCE_25("icons.png", 48, 96, 16, 16),
ICON_PATTERN_CHANCE_50("icons.png", 0, 112, 16, 16),
ICON_PATTERN_CHANCE_75("icons.png", 16, 112, 16, 16),
ICON_FOLLOW_DIAGONAL("icons.png", 32, 112, 16, 16),
ICON_FOLLOW_MATERIAL("icons.png", 48, 112, 16, 16),
I_PATTERN_SOLID(0, 96),
I_PATTERN_CHECKERED(16, 96),
I_PATTERN_CHECKERED_INVERSED(32, 96),
I_PATTERN_CHANCE_25(48, 96),
I_PATTERN_CHANCE_50(0, 112),
I_PATTERN_CHANCE_75(16, 112),
I_FOLLOW_DIAGONAL(32, 112),
I_FOLLOW_MATERIAL(48, 112),
I_PRIORITY_VERY_LOW(64, 0),
I_PRIORITY_LOW(80, 0),
I_PRIORITY_HIGH(96, 0),
I_PRIORITY_VERY_HIGH(112, 0),
I_ACTIVE(64, 16),
I_PASSIVE(80, 16),
;
public static final int FONT_COLOR = 0x575F7A;
@ -126,6 +140,10 @@ public enum ScreenResources {
this(location, 0, 0, width, height);
}
private ScreenResources(int startX, int startY) {
this("icons.png", startX, startY, 16, 16);
}
private ScreenResources(String location, int startX, int startY, int width, int height) {
this.location = new ResourceLocation(Create.ID, "textures/gui/" + location);
this.width = width;

View file

@ -0,0 +1,58 @@
package com.simibubi.create.foundation.block;
import com.simibubi.create.AllContainers;
import net.minecraft.client.Minecraft;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
public abstract class AbstractTileEntityContainer<T extends TileEntity> extends Container {
public T te;
public PlayerEntity player;
@SuppressWarnings("unchecked")
public AbstractTileEntityContainer(AllContainers containerType, int id, PlayerInventory inv,
PacketBuffer extraData) {
super(containerType.type, id);
ClientWorld world = Minecraft.getInstance().world;
this.te = (T) world.getTileEntity(extraData.readBlockPos());
this.te.handleUpdateTag(extraData.readCompoundTag());
this.player = inv.player;
init();
}
public AbstractTileEntityContainer(AllContainers containerType, int id, PlayerInventory inv, T te) {
super(containerType.type, id);
this.te = te;
this.player = inv.player;
init();
}
protected abstract void init();
protected void addPlayerSlots(int x, int y) {
for (int row = 0; row < 3; ++row)
for (int col = 0; col < 9; ++col)
this.addSlot(new Slot(player.inventory, col + row * 9 + 9, x + col * 18, y + row * 18));
for (int hotbarSlot = 0; hotbarSlot < 9; ++hotbarSlot)
this.addSlot(new Slot(player.inventory, hotbarSlot, x + hotbarSlot * 18, y + 3 * 18 + 4));
}
@Override
public boolean canInteractWith(PlayerEntity playerIn) {
return true;
}
@Override
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
return ItemStack.EMPTY;
}
}

View file

@ -0,0 +1,36 @@
package com.simibubi.create.foundation.block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
public interface IWithContainer<T extends TileEntity, C extends AbstractTileEntityContainer<T>> extends INamedContainerProvider {
public IContainerFactory<T, C> getContainerFactory();
@SuppressWarnings("unchecked")
@Override
default Container createMenu(int id, PlayerInventory inv, PlayerEntity player) {
return getContainerFactory().create(id, inv, ((T) this));
}
@Override
default ITextComponent getDisplayName() {
return new StringTextComponent(((TileEntity) this).getType().getRegistryName().toString());
}
public interface IContainerFactory<T extends TileEntity, C extends AbstractTileEntityContainer<? extends TileEntity>> {
public C create(int id, PlayerInventory inv, T te);
}
default void sendToContainer(PacketBuffer buffer) {
buffer.writeBlockPos(((TileEntity) this).getPos());
buffer.writeCompoundTag(((TileEntity) this).getUpdateTag());
}
}

View file

@ -0,0 +1,19 @@
package com.simibubi.create.foundation.block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraftforge.fml.network.NetworkHooks;
public interface IWithContainerTileEntity<T extends TileEntity & IWithContainer<T, ?>> extends IWithTileEntity<T> {
default void open(IWorld world, BlockPos pos, PlayerEntity player) {
T te = getTileEntity(world, pos);
if (te == null || world.isRemote())
return;
NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer);
}
}

View file

@ -3,14 +3,21 @@ package com.simibubi.create.foundation.gui;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -127,5 +134,86 @@ public abstract class AbstractSimiContainerScreen<T extends Container> extends C
}
}
}
protected void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition,
@Nullable String text, int textColor) {
if (!stack.isEmpty()) {
if (stack.getItem().showDurabilityBar(stack)) {
GlStateManager.disableLighting();
GlStateManager.disableDepthTest();
GlStateManager.disableTexture();
GlStateManager.disableAlphaTest();
GlStateManager.disableBlend();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
double health = stack.getItem().getDurabilityForDisplay(stack);
int i = Math.round(13.0F - (float) health * 13.0F);
int j = stack.getItem().getRGBDurabilityForDisplay(stack);
this.draw(bufferbuilder, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255);
this.draw(bufferbuilder, xPosition + 2, yPosition + 13, i, 1, j >> 16 & 255, j >> 8 & 255, j & 255,
255);
GlStateManager.enableBlend();
GlStateManager.enableAlphaTest();
GlStateManager.enableTexture();
GlStateManager.enableLighting();
GlStateManager.enableDepthTest();
}
if (stack.getCount() != 1 || text != null) {
String s = text == null ? String.valueOf(stack.getCount()) : text;
GlStateManager.disableLighting();
GlStateManager.disableDepthTest();
GlStateManager.disableBlend();
GlStateManager.pushMatrix();
int guiScaleFactor = (int) minecraft.mainWindow.getGuiScaleFactor();
GlStateManager.translated((float) (xPosition + 16.5f), (float) (yPosition + 16.5f), 0);
double scale = getItemCountTextScale();
GlStateManager.scaled(scale, scale, 0);
GlStateManager.translated(-fr.getStringWidth(s) - (guiScaleFactor > 1 ? 0 : -.5f),
-font.FONT_HEIGHT + (guiScaleFactor > 1 ? 1 : 1.75f), 0);
fr.drawStringWithShadow(s, 0, 0, textColor);
GlStateManager.popMatrix();
GlStateManager.enableBlend();
GlStateManager.enableLighting();
GlStateManager.enableDepthTest();
GlStateManager.enableBlend();
}
}
}
public double getItemCountTextScale() {
int guiScaleFactor = (int) minecraft.mainWindow.getGuiScaleFactor();
double scale = 1;
switch (guiScaleFactor) {
case 1:
scale = 2060 / 2048d;
break;
case 2:
scale = .5;
break;
case 3:
scale = .675;
break;
case 4:
scale = .75;
break;
default:
scale = ((float) guiScaleFactor - 1) / guiScaleFactor;
}
return scale;
}
private void draw(BufferBuilder renderer, int x, int y, int width, int height, int red, int green, int blue,
int alpha) {
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
renderer.pos((double) (x + 0), (double) (y + 0), 0.0D).color(red, green, blue, alpha).endVertex();
renderer.pos((double) (x + 0), (double) (y + height), 0.0D).color(red, green, blue, alpha).endVertex();
renderer.pos((double) (x + width), (double) (y + height), 0.0D).color(red, green, blue, alpha).endVertex();
renderer.pos((double) (x + width), (double) (y + 0), 0.0D).color(red, green, blue, alpha).endVertex();
Tessellator.getInstance().draw();
}
}

View file

@ -5,6 +5,7 @@ import java.util.function.Supplier;
import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.foundation.utility.ColorHelper;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
@ -15,6 +16,7 @@ import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public class ScreenElementRenderer {
@ -34,6 +36,10 @@ public class ScreenElementRenderer {
}
public static void renderBlock(Supplier<BlockState> transformsAndState) {
renderBlock(transformsAndState, -1);
}
public static void renderBlock(Supplier<BlockState> transformsAndState, int color) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
@ -50,7 +56,18 @@ public class ScreenElementRenderer {
GlStateManager.scaled(50, -50, 50);
Minecraft mc = Minecraft.getInstance();
mc.getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
mc.getBlockRendererDispatcher().renderBlockBrightness(toRender, 1);
if (color == -1) {
mc.getBlockRendererDispatcher().renderBlockBrightness(toRender, 1);
} else {
GlStateManager.disableLighting();
GlStateManager.rotated(90, 0, 1, 0);
Vec3d rgb = ColorHelper.getRGB(color);
mc.getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(
mc.getBlockRendererDispatcher().getModelForState(toRender), 1, (float) rgb.x, (float) rgb.y,
(float) rgb.z);
GlStateManager.enableLighting();
}
if (!toRender.getFluidState().isEmpty()) {
RenderHelper.disableStandardItemLighting();
@ -58,7 +75,8 @@ public class ScreenElementRenderer {
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.setTranslation(0, -300, 0);
bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
mc.getBlockRendererDispatcher().renderFluid(new BlockPos(0, 300, 0), mc.world, bufferbuilder, toRender.getFluidState());
mc.getBlockRendererDispatcher().renderFluid(new BlockPos(0, 300, 0), mc.world, bufferbuilder,
toRender.getFluidState());
Tessellator.getInstance().draw();
bufferbuilder.setTranslation(0, 0, 0);
}

View file

@ -144,7 +144,7 @@ public class CountedItemsList {
return getItemSet(stack);
}
public class ItemStackEntry implements Comparable<ItemStackEntry> {
public static class ItemStackEntry implements Comparable<ItemStackEntry> {
public ItemStack stack;
public int amount;

View file

@ -2,6 +2,8 @@ package com.simibubi.create.foundation.utility;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.util.math.Vec3d;
public class ColorHelper {
public static int rainbowColor(int timeStep) {
@ -34,24 +36,29 @@ public class ColorHelper {
int g2 = (color2 >> 8) & 0xFF;
int b2 = color2 & 0xFF;
int color = ((int) (r1 + (r2 - r1) * w) << 16)
+ ((int) (g1 + (g2 - g1) * w) << 8)
+ (int) (b1 + (b2 - b1) * w);
int color = ((int) (r1 + (r2 - r1) * w) << 16) + ((int) (g1 + (g2 - g1) * w) << 8) + (int) (b1 + (b2 - b1) * w);
return color;
}
public static void glColor(int color) {
color = mixColors(color, 0xFFFFFF, .5f);
int r = (color >> 16);
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
GlStateManager.color4f(r / 256f, g / 256f, b / 256f, 1);
}
public static void glResetColor() {
GlStateManager.color4f(1, 1, 1, 1);
}
public static Vec3d getRGB(int color) {
int r = (color >> 16);
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
return new Vec3d(r, g, b).scale(1 / 256d);
}
}

View file

@ -73,19 +73,19 @@ public class BuilderGunScreen extends AbstractSimiScreen {
widgets.clear();
replaceModeIndicator = new Indicator(i + 51, j + 36, "");
replaceModeButton = new IconButton(i + 51, j + 41, ScreenResources.ICON_REPLACE_SOLID);
replaceModeButton = new IconButton(i + 51, j + 41, ScreenResources.I_REPLACE_SOLID);
if (nbt.contains("Replace") && nbt.getBoolean("Replace"))
replaceModeIndicator.state = State.ON;
replaceModeButton.setToolTip(Lang.translate("gui.blockzapper.replaceMode"));
spreadDiagonallyIndicator = new Indicator(i + 74, j + 36, "");
spreadDiagonallyButton = new IconButton(i + 74, j + 41, ScreenResources.ICON_FOLLOW_DIAGONAL);
spreadDiagonallyButton = new IconButton(i + 74, j + 41, ScreenResources.I_FOLLOW_DIAGONAL);
if (nbt.contains("SearchDiagonal") && nbt.getBoolean("SearchDiagonal"))
spreadDiagonallyIndicator.state = State.ON;
spreadDiagonallyButton.setToolTip(Lang.translate("gui.blockzapper.searchDiagonal"));
spreadMaterialIndicator = new Indicator(i + 92, j + 36, "");
spreadMaterialButton = new IconButton(i + 92, j + 41, ScreenResources.ICON_FOLLOW_MATERIAL);
spreadMaterialButton = new IconButton(i + 92, j + 41, ScreenResources.I_FOLLOW_MATERIAL);
if (nbt.contains("SearchFuzzy") && nbt.getBoolean("SearchFuzzy"))
spreadMaterialIndicator.state = State.ON;
spreadMaterialButton.setToolTip(Lang.translate("gui.blockzapper.searchFuzzy"));

View file

@ -4,12 +4,12 @@ import com.simibubi.create.ScreenResources;
public enum PlacementPatterns {
Solid(ScreenResources.ICON_PATTERN_SOLID),
Checkered(ScreenResources.ICON_PATTERN_CHECKERED),
InverseCheckered(ScreenResources.ICON_PATTERN_CHECKERED_INVERSED),
Chance25(ScreenResources.ICON_PATTERN_CHANCE_25),
Chance50(ScreenResources.ICON_PATTERN_CHANCE_50),
Chance75(ScreenResources.ICON_PATTERN_CHANCE_75);
Solid(ScreenResources.I_PATTERN_SOLID),
Checkered(ScreenResources.I_PATTERN_CHECKERED),
InverseCheckered(ScreenResources.I_PATTERN_CHECKERED_INVERSED),
Chance25(ScreenResources.I_PATTERN_CHANCE_25),
Chance50(ScreenResources.I_PATTERN_CHANCE_50),
Chance75(ScreenResources.I_PATTERN_CHANCE_75);
public String translationKey;
public ScreenResources icon;

View file

@ -1,13 +1,16 @@
package com.simibubi.create.modules.logistics.management;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.PriorityQueue;
import java.util.function.Predicate;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerTileEntity;
import com.simibubi.create.modules.logistics.management.base.LogisticalTask;
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.DepositTask;
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.SupplyTask;
import com.simibubi.create.modules.logistics.management.controller.StorageTileEntity;
import com.simibubi.create.modules.logistics.management.controller.TransactionsTileEntity;
import com.simibubi.create.modules.logistics.management.index.LogisticalIndexTileEntity;
@ -41,11 +44,15 @@ public class LogisticalNetwork {
if (receivers.contains(te))
return;
receivers.add(te);
indexers.forEach(LogisticalIndexTileEntity::syncReceivers);
reAdvertiseReceivers();
}
participants++;
}
public void reAdvertiseReceivers() {
indexers.forEach(LogisticalIndexTileEntity::syncReceivers);
}
public void removeController(LogisticalControllerTileEntity te) {
if (te instanceof TransactionsTileEntity)
if (!taskQueues.remove((TransactionsTileEntity) te))
@ -59,7 +66,7 @@ public class LogisticalNetwork {
if (te.isReceiver()) {
if (!receivers.remove(te))
return;
indexers.forEach(LogisticalIndexTileEntity::syncReceivers);
reAdvertiseReceivers();
}
participants--;
}
@ -76,4 +83,50 @@ public class LogisticalNetwork {
receivers.forEach(LogisticalControllerTileEntity::notifyTaskUpdate);
}
public String getNextAvailableAddress(LogisticalControllerTileEntity te) {
Predicate<String> isTaken = s -> false;
String prefix = "";
if (te instanceof TransactionsTileEntity) {
prefix = "Task Manager ";
isTaken = s -> isNameTaken(taskQueues, s);
}
else if (te instanceof LogisticalIndexTileEntity) {
prefix = "Index ";
isTaken = s -> isNameTaken(indexers, s);
}
else if (te instanceof StorageTileEntity) {
prefix = "Storage ";
isTaken = s -> isNameTaken(suppliers, s);
}
else if (te.isSupplier()) {
prefix = "Supply ";
isTaken = s -> isNameTaken(suppliers, s);
}
else if (te.isReceiver()) {
prefix = "Request ";
isTaken = s -> isNameTaken(receivers, s);
}
int i = 0;
String name;
do {
name = prefix + (i == 0 ? "" : i);
i++;
} while (isTaken.test(name));
return name;
}
private static <T extends LogisticalControllerTileEntity> boolean isNameTaken(Collection<T> list, String name) {
for (T controller : list)
if (controller.address.equals(name))
return true;
return false;
}
}

View file

@ -25,26 +25,30 @@ public class LogisticalNetworkHandler {
public LogisticalNetwork handleAdded(LogisticalControllerTileEntity te) {
LogisticalNetwork networkByID = getNetworkByID(te.getWorld(), te.getNetworkId());
if (te.address == null || te.address.isEmpty()) {
te.address = networkByID.getNextAvailableAddress(te);
te.sendData();
}
networkByID.addController(te);
return networkByID;
}
public void handleRemoved(LogisticalControllerTileEntity te) {
getNetworkByID(te.getWorld(), te.getNetworkId()).removeController(te);
removeIfEmpty(te.getWorld(), te.getNetworkId());
}
public LogisticalNetwork getNetworkByID(IWorld world, UUID id) {
Map<UUID, LogisticalNetwork> worldNets = networks.get(world);
if (!worldNets.containsKey(id))
worldNets.put(id, new LogisticalNetwork());
return worldNets.get(id);
}
private void removeIfEmpty(IWorld world, UUID id) {
Map<UUID, LogisticalNetwork> worldNets = networks.get(world);
if (worldNets.get(id).isEmpty())
worldNets.remove(id);
}
}

View file

@ -9,6 +9,7 @@ import java.util.stream.Collectors;
import com.google.common.base.Predicates;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.foundation.block.SyncedTileEntity;
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;

View file

@ -11,11 +11,14 @@ import java.util.List;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.Create;
import com.simibubi.create.foundation.block.IWithContainer;
import com.simibubi.create.foundation.block.IWithTileEntity;
import com.simibubi.create.foundation.block.IWithoutBlockItem;
import com.simibubi.create.foundation.block.RenderUtilityBlock;
import com.simibubi.create.modules.logistics.management.base.LogisticalCasingBlock.Part;
import com.simibubi.create.modules.logistics.management.controller.CalculationTileEntity;
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity;
import com.simibubi.create.modules.logistics.management.controller.RequestTileEntity;
import com.simibubi.create.modules.logistics.management.controller.StorageTileEntity;
import com.simibubi.create.modules.logistics.management.controller.SupplyTileEntity;
@ -27,10 +30,10 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.DirectionalBlock;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.IProperty;
import net.minecraft.state.StateContainer.Builder;
@ -46,6 +49,7 @@ import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;
public class LogisticalControllerBlock extends DirectionalBlock
implements IWithoutBlockItem, IWithTileEntity<LogisticalControllerTileEntity> {
@ -127,21 +131,35 @@ public class LogisticalControllerBlock extends DirectionalBlock
return isCasing;
}
@Override
public String getTranslationKey() {
return "block." + Create.ID + ".logistical_controller";
}
public static String getControllerTypeTranslationKey(BlockState state) {
return "item." + Create.ID + ".logistical_controller_" + state.get(TYPE).name().toLowerCase();
}
@Override
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (player.isSneaking() || !player.isAllowEdit())
return false;
ItemStack held = player.getHeldItem(handIn);
if (held.getItem() != Items.NAME_TAG)
return false;
if (!held.hasDisplayName())
if (!state.hasTileEntity())
return false;
withTileEntityDo(worldIn, pos, te -> {
te.setName(held.getDisplayName().getUnformattedComponentText());
});
TileEntity te = worldIn.getTileEntity(pos);
if (!(te instanceof LogisticalInventoryControllerTileEntity))
return false;
if (state.get(TYPE) == Type.CALCULATION)
return false;
if (AllItems.LOGISTICAL_DIAL.typeOf(player.getHeldItem(handIn)))
return false;
if (worldIn.isRemote)
return true;
IWithContainer<?, ?> cte = (IWithContainer<?, ?>) te;
NetworkHooks.openGui((ServerPlayerEntity) player, cte, cte::sendToContainer);
return true;
}

View file

@ -1,6 +1,7 @@
package com.simibubi.create.modules.logistics.management.base;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.Create;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock.Type;
import net.minecraft.item.BlockItem;
@ -23,6 +24,11 @@ public class LogisticalControllerItem extends BlockItem {
items.add(new ItemStack(this));
}
}
@Override
public String getTranslationKey(ItemStack stack) {
return "item." + Create.ID + "." + getRegistryName().getPath();
}
public Type getType() {
return type;

View file

@ -18,10 +18,11 @@ public abstract class LogisticalControllerTileEntity extends SyncedTileEntity
implements Comparable<LogisticalControllerTileEntity>, ITickableTileEntity {
public static final int COOLDOWN = 20;
public Priority priority = Priority.LOW;
public String address = "";
protected Priority priority = Priority.LOW;
protected LogisticalNetwork network;
protected String name = "";
protected UUID networkId;
protected boolean initialize;
protected boolean checkTasks;
@ -39,7 +40,7 @@ public abstract class LogisticalControllerTileEntity extends SyncedTileEntity
initialize();
return;
}
if (taskCooldown > 0)
taskCooldown--;
}
@ -55,20 +56,12 @@ public abstract class LogisticalControllerTileEntity extends SyncedTileEntity
handleRemoved();
super.remove();
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public boolean hasFastRenderer() {
return true;
}
public void notifyTaskUpdate() {
checkTasks = true;
}
@ -77,7 +70,8 @@ public abstract class LogisticalControllerTileEntity extends SyncedTileEntity
public CompoundNBT write(CompoundNBT compound) {
if (networkId != null)
compound.putUniqueId("NetworkID", networkId);
compound.putString("Address", name);
compound.putString("Address", address);
compound.putInt("Priority", priority.ordinal());
return super.write(compound);
}
@ -89,7 +83,8 @@ public abstract class LogisticalControllerTileEntity extends SyncedTileEntity
public void read(CompoundNBT compound) {
if (compound.contains("NetworkIDLeast"))
networkId = compound.getUniqueId("NetworkID");
name = compound.getString("Address");
address = compound.getString("Address");
priority = Priority.values()[compound.getInt("Priority")];
super.read(compound);
}
@ -149,8 +144,12 @@ public abstract class LogisticalControllerTileEntity extends SyncedTileEntity
return network;
}
public Priority getPriority() {
return priority;
}
public static enum Priority {
LOWEST, LOW, MEDIUM, HIGH, HIGHEST;
HIGHEST, HIGH, LOWEST, LOW;
}
}

View file

@ -1,7 +1,6 @@
package com.simibubi.create.modules.logistics.management.controller;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.modules.logistics.management.base.LogisticalInventoryControllerTileEntity;
public class CalculationTileEntity extends LogisticalInventoryControllerTileEntity {

View file

@ -0,0 +1,62 @@
package com.simibubi.create.modules.logistics.management.controller;
import com.simibubi.create.foundation.packet.TileEntityConfigurationPacket;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerTileEntity.Priority;
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity.ShippingInventory;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
public class LogisticalControllerConfigurationPacket
extends TileEntityConfigurationPacket<LogisticalInventoryControllerTileEntity> {
String address;
int filterAmount;
Priority priority;
boolean active;
public LogisticalControllerConfigurationPacket(BlockPos pos, String address, int filterAmount,
Priority priority, boolean active) {
super(pos);
this.address = address;
this.filterAmount = filterAmount;
this.priority = priority;
this.active = active;
}
public LogisticalControllerConfigurationPacket(PacketBuffer buffer) {
super(buffer);
}
@Override
protected void writeSettings(PacketBuffer buffer) {
buffer.writeString(address, 2048);
buffer.writeInt(filterAmount);
buffer.writeInt(priority.ordinal());
buffer.writeBoolean(active);
}
@Override
protected void readSettings(PacketBuffer buffer) {
address = buffer.readString(2048);
filterAmount = buffer.readInt();
priority = Priority.values()[buffer.readInt()];
active = buffer.readBoolean();
}
@Override
protected void applySettings(LogisticalInventoryControllerTileEntity te) {
if (!address.isEmpty()) {
te.address = address;
if (te.getNetwork() != null)
te.getNetwork().reAdvertiseReceivers();
}
te.priority = priority;
te.isActive = active;
te.shippingInventory.ifPresent(inv -> {
ShippingInventory sInv = (ShippingInventory) inv;
sInv.filterAmount = filterAmount;
});
}
}

View file

@ -0,0 +1,55 @@
package com.simibubi.create.modules.logistics.management.controller;
import com.simibubi.create.AllContainers;
import com.simibubi.create.foundation.block.AbstractTileEntityContainer;
import com.simibubi.create.foundation.type.CombinedCountedItemsList;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.items.SlotItemHandler;
public class LogisticalInventoryControllerContainer
extends AbstractTileEntityContainer<LogisticalInventoryControllerTileEntity> {
public CombinedCountedItemsList<String> allItems = new CombinedCountedItemsList<>();
public LogisticalInventoryControllerContainer(int id, PlayerInventory inv, PacketBuffer extraData) {
super(AllContainers.LOGISTICAL_CONTROLLER, id, inv, extraData);
}
public LogisticalInventoryControllerContainer(int id, PlayerInventory inv,
LogisticalInventoryControllerTileEntity te) {
super(AllContainers.LOGISTICAL_CONTROLLER, id, inv, te);
}
public void init() {
addSlot(new SlotItemHandler(te.getInventory(), 0, 135, 32));
addSlot(new SlotItemHandler(te.getInventory(), 1, 135 + 18, 32));
addSlot(new SlotItemHandler(te.getInventory(), 2, 84, 29));
addPlayerSlots(48, 118);
detectAndSendChanges();
}
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) {
if (slotId != 2)
return super.slotClick(slotId, dragType, clickTypeIn, player);
ItemStack item = player.inventory.getItemStack();
ItemStack copy = item.copy();
if (copy.isEmpty()) {
te.getInventory().extractItem(2, 1, false);
return ItemStack.EMPTY;
}
copy.setCount(1);
te.getInventory().extractItem(2, 1, false);
te.getInventory().insertItem(2, copy, false);
return item;
}
}

View file

@ -0,0 +1,252 @@
package com.simibubi.create.modules.logistics.management.controller;
import static com.simibubi.create.ScreenResources.I_PRIORITY_HIGH;
import static com.simibubi.create.ScreenResources.I_PRIORITY_LOW;
import static com.simibubi.create.ScreenResources.I_PRIORITY_VERY_HIGH;
import static com.simibubi.create.ScreenResources.I_PRIORITY_VERY_LOW;
import static com.simibubi.create.ScreenResources.LOGISTICAL_CONTROLLER;
import static com.simibubi.create.ScreenResources.LOGISTICAL_CONTROLLER_TRIM;
import static com.simibubi.create.ScreenResources.PLAYER_INVENTORY;
import static com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock.TYPE;
import static net.minecraft.state.properties.BlockStateProperties.FACING;
import java.util.Arrays;
import java.util.List;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.GlStateManager;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems;
import com.simibubi.create.AllPackets;
import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen;
import com.simibubi.create.foundation.gui.ScreenElementRenderer;
import com.simibubi.create.foundation.gui.widgets.IconButton;
import com.simibubi.create.foundation.gui.widgets.Indicator;
import com.simibubi.create.foundation.gui.widgets.Indicator.State;
import com.simibubi.create.foundation.gui.widgets.ScrollInput;
import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock.Type;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerTileEntity.Priority;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.InputMappings;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
public class LogisticalInventoryControllerScreen
extends AbstractSimiContainerScreen<LogisticalInventoryControllerContainer> {
private BlockState controllerState;
private BlockState controllerLightState;
private ItemStack nameTagItem;
private ItemStack boxItem;
private Type controllerType;
private ScrollInput priorityInput;
private TextFieldWidget addressInput;
private IconButton passiveModeButton;
private IconButton activeModeButton;
private Indicator passiveModeIndicator;
private Indicator activeModeIndicator;
private IconButton confirmButton;
private ScrollInput filterAmountInput;
private final List<ScreenResources> priorityIcons = Arrays.asList(I_PRIORITY_VERY_HIGH, I_PRIORITY_HIGH,
I_PRIORITY_LOW, I_PRIORITY_VERY_LOW);
private final List<String> priorityOptions = Lang.translatedOptions("logistics.priority", "highest", "high", "low",
"lowest");
private String priority = Lang.translate("logistics.priority");
private String requestedItemCount = Lang.translate("gui.requester.requestedItemCount");
private String activeMode = Lang.translate("gui.logistical_controller.active_mode");
private String passiveMode = Lang.translate("gui.logistical_controller.passive_mode");
private String storagePassiveModeOnly = Lang.translate("gui.storage.passiveModeOnly");
private String title;
public LogisticalInventoryControllerScreen(LogisticalInventoryControllerContainer container, PlayerInventory inv,
ITextComponent title) {
super(container, inv, title);
this.title = I18n
.format(LogisticalControllerBlock.getControllerTypeTranslationKey(container.te.getBlockState()));
controllerState = container.te.getBlockState().with(BlockStateProperties.FACING, Direction.SOUTH);
controllerType = controllerState.get(LogisticalControllerBlock.TYPE);
controllerLightState = AllBlocks.LOGISTICAL_CONTROLLER_INDICATOR.get().getDefaultState()
.with(FACING, controllerState.get(FACING)).with(TYPE, controllerState.get(TYPE));
nameTagItem = new ItemStack(Items.NAME_TAG);
boxItem = AllItems.CARDBOARD_BOX_1410.asStack();
}
@Override
protected void init() {
setWindowSize(256, 200);
super.init();
widgets.clear();
int x = guiLeft;
int y = guiTop;
addressInput = new TextFieldWidget(font, x + 29, y + 62, 116, 8, "");
addressInput.setTextColor(0xFFFFFF);
addressInput.setDisabledTextColour(-1);
addressInput.setText(container.te.address);
addressInput.setEnableBackgroundDrawing(false);
addressInput.setMaxStringLength(256);
addressInput.func_212954_a(this::onAddressInputChanged);
addressInput.setFocused2(false);
priorityInput = new SelectionScrollInput(x + 49, y + 31, 18, 18).forOptions(priorityOptions).titled(priority)
.setState(container.te.getPriority().ordinal());
filterAmountInput = new ScrollInput(x + 85, y + 46, 15, 8).withRange(1, 1025).withShiftStep(64)
.titled(requestedItemCount).setState(container.te.getInventory().filterAmount);
passiveModeButton = new IconButton(x + 8, y + 31, ScreenResources.I_PASSIVE);
passiveModeButton.setToolTip(passiveMode);
if (controllerType == Type.STORAGE)
passiveModeButton.getToolTip().add(TextFormatting.GOLD + storagePassiveModeOnly);
passiveModeIndicator = new Indicator(x + 8, y + 26, "");
activeModeButton = new IconButton(x + 26, y + 31, ScreenResources.I_ACTIVE);
activeModeButton.setToolTip(activeMode);
activeModeIndicator = new Indicator(x + 26, y + 26, "");
setPassiveMode(!container.te.isActive);
confirmButton = new IconButton(x + 152, y + 57, ScreenResources.I_CONFIRM);
widgets.addAll(Arrays.asList(priorityInput, addressInput, passiveModeButton, passiveModeIndicator,
activeModeButton, activeModeIndicator, confirmButton));
if (controllerType == Type.REQUEST)
widgets.add(filterAmountInput);
}
@Override
protected void renderWindow(int mouseX, int mouseY, float partialTicks) {
int x = guiLeft;
int y = guiTop;
LOGISTICAL_CONTROLLER_TRIM.draw(this, x, y);
LOGISTICAL_CONTROLLER_TRIM.draw(this, x, y + 6 + LOGISTICAL_CONTROLLER.height);
ColorHelper.glColor(container.te.getColor());
LOGISTICAL_CONTROLLER.draw(this, x, y + 6);
ColorHelper.glResetColor();
ScreenResources.BIG_SLOT.draw(this, x + 79, y + 24);
ScreenResources.SHIPPING_SLOT.draw(this, x + 134, y + 28);
ScreenResources.RECEIVING_SLOT.draw(this, x + 134 + 18, y + 28);
PLAYER_INVENTORY.draw(this, x + (getXSize() - PLAYER_INVENTORY.width) / 2, y + 100);
ScreenResources priorityIcon = priorityIcons.get(priorityInput.getState());
ColorHelper.glColor(0);
priorityIcon.draw(this, x + 51, y + 33);
ColorHelper.glResetColor();
priorityIcon.draw(this, x + 50, y + 32);
if (controllerType == Type.REQUEST) {
ScreenResources.ITEM_COUNT_SCROLLAREA.draw(this, x + 81, y + 45);
GlStateManager.pushMatrix();
double scale = getItemCountTextScale();
String text = "" + filterAmountInput.getState();
GlStateManager.translated(x + 91.5, y + 53, 0);
GlStateManager.scaled(scale, scale, 0);
int guiScaleFactor = (int) minecraft.mainWindow.getGuiScaleFactor();
GlStateManager.translated((-font.getStringWidth(text)) / 2,
-font.FONT_HEIGHT + (guiScaleFactor > 1 ? 1 : 1.75f), 0);
font.drawStringWithShadow(text, 0, 0, 0xFFFFFF);
GlStateManager.popMatrix();
}
font.drawString(playerInventory.getDisplayName().getFormattedText(), x + 48, y + 106, 0x666666);
font.drawStringWithShadow(title, x + (LOGISTICAL_CONTROLLER.width - font.getStringWidth(title)) / 2, y + 9,
ColorHelper.mixColors(0xFFFFFF, container.te.getColor(), .25f));
ScreenElementRenderer.renderBlock(() -> {
transformRenderedBlocks();
return controllerState;
});
ScreenElementRenderer.renderBlock(() -> {
transformRenderedBlocks();
return controllerLightState;
}, container.te.getColor());
ColorHelper.glResetColor();
RenderHelper.enableGUIStandardItemLighting();
itemRenderer.renderItemIntoGUI(nameTagItem, x + 7, y + 57);
itemRenderer.renderItemIntoGUI(boxItem, x + 116, y + 32);
}
public void onAddressInputChanged(String s) {
confirmButton.active = !s.isEmpty();
}
@Override
public boolean keyPressed(int code, int p_keyPressed_2_, int p_keyPressed_3_) {
InputMappings.Input mouseKey = InputMappings.getInputByCode(code, p_keyPressed_2_);
boolean closingScreen = this.minecraft.gameSettings.keyBindInventory.isActiveAndMatches(mouseKey);
boolean enter = code == GLFW.GLFW_KEY_ENTER;
if (closingScreen && addressInput.isFocused())
return true;
if (enter && addressInput.isFocused())
addressInput.changeFocus(false);
return super.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_);
}
@Override
public boolean mouseClicked(double x, double y, int button) {
if (confirmButton.active && confirmButton.isHovered())
minecraft.displayGuiScreen(null);
if (activeModeButton.active && activeModeButton.isHovered())
setPassiveMode(false);
if (passiveModeButton.active && passiveModeButton.isHovered())
setPassiveMode(true);
return super.mouseClicked(x, y, button);
}
public void setPassiveMode(boolean passive) {
if (controllerType == Type.STORAGE) {
activeModeButton.active = passiveModeButton.active = false;
activeModeIndicator.state = State.OFF;
passiveModeIndicator.state = State.ON;
return;
}
activeModeButton.active = passive;
passiveModeButton.active = !passive;
activeModeIndicator.state = passive ? State.OFF : State.ON;
passiveModeIndicator.state = !passive ? State.OFF : State.ON;
}
@Override
public void removed() {
boolean active = !activeModeButton.active;
Priority priorityOut = Priority.values()[priorityInput.getState()];
String text = addressInput.getText();
AllPackets.channel.sendToServer(new LogisticalControllerConfigurationPacket(container.te.getPos(), text,
filterAmountInput.getState(), priorityOut, active));
super.removed();
}
private void transformRenderedBlocks() {
GlStateManager.translated(guiLeft + 205, guiTop + 70, 0);
GlStateManager.rotatef(50, -.5f, 1, -.2f);
GlStateManager.rotatef(190, 0, 1, 0);
GlStateManager.scaled(1.25, 1.25, 1.25);
}
}

View file

@ -1,4 +1,4 @@
package com.simibubi.create.modules.logistics.management.base;
package com.simibubi.create.modules.logistics.management.controller;
import static net.minecraft.state.properties.BlockStateProperties.FACING;
@ -12,11 +12,16 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
import com.simibubi.create.foundation.block.IWithContainer;
import com.simibubi.create.foundation.type.CombinedCountedItemsList;
import com.simibubi.create.foundation.type.CountedItemsList;
import com.simibubi.create.foundation.type.CountedItemsList.ItemStackEntry;
import com.simibubi.create.foundation.utility.ItemHelper;
import com.simibubi.create.modules.logistics.item.CardboardBoxItem;
import com.simibubi.create.modules.logistics.management.base.LogisticalCasingTileEntity;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerTileEntity;
import com.simibubi.create.modules.logistics.management.base.LogisticalTask;
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.DepositTask;
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.SupplyTask;
@ -24,6 +29,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
@ -34,7 +40,8 @@ import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
public abstract class LogisticalInventoryControllerTileEntity extends LogisticalControllerTileEntity {
public abstract class LogisticalInventoryControllerTileEntity extends LogisticalControllerTileEntity
implements IWithContainer<LogisticalInventoryControllerTileEntity, LogisticalInventoryControllerContainer> {
protected Map<BlockPos, ConnectedInventory> observedInventories = new HashMap<>();
protected Map<IItemHandler, ConnectedInventory> inventoryByHandler = new HashMap<>();
@ -44,6 +51,8 @@ public abstract class LogisticalInventoryControllerTileEntity extends Logistical
protected LazyOptional<IItemHandler> shippingInventory;
protected boolean tryInsertBox;
public boolean isActive;
public LogisticalInventoryControllerTileEntity(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
this.shippingInventory = LazyOptional.of(this::createInventory);
@ -56,6 +65,7 @@ public abstract class LogisticalInventoryControllerTileEntity extends Logistical
ShippingInventory inv = (ShippingInventory) shippingInventory.orElse(null);
inv.deserializeNBT(compound.getCompound("ShippingInventory"));
}
isActive = compound.getBoolean("Active");
}
public void inventoryChanged(BlockPos pos) {
@ -96,7 +106,7 @@ public abstract class LogisticalInventoryControllerTileEntity extends Logistical
protected void notifyIndexers(CountedItemsList updates) {
if (network == null)
return;
network.indexers.forEach(indexer -> indexer.handleUpdatedController(getName(), updates));
network.indexers.forEach(indexer -> indexer.handleUpdatedController(address, updates));
}
@Override
@ -275,6 +285,7 @@ public abstract class LogisticalInventoryControllerTileEntity extends Logistical
@Override
public CompoundNBT write(CompoundNBT compound) {
shippingInventory.ifPresent(inv -> compound.put("ShippingInventory", ((ShippingInventory) inv).serializeNBT()));
compound.putBoolean("Active", isActive);
return super.write(compound);
}
@ -324,25 +335,40 @@ public abstract class LogisticalInventoryControllerTileEntity extends Logistical
}
}
@Override
public IContainerFactory<LogisticalInventoryControllerTileEntity, LogisticalInventoryControllerContainer> getContainerFactory() {
return LogisticalInventoryControllerContainer::new;
}
@Override
public void sendToContainer(PacketBuffer buffer) {
IWithContainer.super.sendToContainer(buffer);
}
protected abstract ShippingInventory createInventory();
public class ShippingInventory extends ItemStackHandler {
static final int SHIPPING = 0;
static final int RECEIVING = 1;
static final int FILTER = 2;
int filterAmount = 0;
boolean ships;
boolean receives;
public ShippingInventory(boolean ships, boolean receives) {
super(2);
super(3);
this.ships = ships;
this.receives = receives;
}
@Override
public boolean isItemValid(int slot, ItemStack stack) {
if (slot == FILTER)
return true;
if (slot == RECEIVING && receives)
return stack.getItem() instanceof CardboardBoxItem && CardboardBoxItem.matchAddress(stack, name);
return stack.getItem() instanceof CardboardBoxItem && CardboardBoxItem.matchAddress(stack, address);
return false;
}
@ -357,6 +383,15 @@ public abstract class LogisticalInventoryControllerTileEntity extends Logistical
return super.extractItem(slot, amount, simulate);
}
@Override
public void setStackInSlot(int slot, ItemStack stack) {
if (slot == FILTER) {
stack = stack.copy();
stack.setCount(1);
}
super.setStackInSlot(slot, stack);
}
public void createPackage(List<ItemStack> contents, String address) {
ItemStack box = CardboardBoxItem.containing(contents);
CardboardBoxItem.addAddress(box, address);
@ -388,6 +423,7 @@ public abstract class LogisticalInventoryControllerTileEntity extends Logistical
CompoundNBT tag = super.serializeNBT();
tag.putBoolean("Ships", ships);
tag.putBoolean("Receives", receives);
tag.putInt("FilterAmount", filterAmount);
return tag;
}
@ -395,6 +431,7 @@ public abstract class LogisticalInventoryControllerTileEntity extends Logistical
public void deserializeNBT(CompoundNBT nbt) {
ships = nbt.getBoolean("Ships");
receives = nbt.getBoolean("Receives");
filterAmount = nbt.getInt("FilterAmount");
super.deserializeNBT(nbt);
}
}

View file

@ -1,7 +1,6 @@
package com.simibubi.create.modules.logistics.management.controller;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.modules.logistics.management.base.LogisticalInventoryControllerTileEntity;
public class RequestTileEntity extends LogisticalInventoryControllerTileEntity {

View file

@ -1,7 +1,6 @@
package com.simibubi.create.modules.logistics.management.controller;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.modules.logistics.management.base.LogisticalInventoryControllerTileEntity;
public class StorageTileEntity extends LogisticalInventoryControllerTileEntity {

View file

@ -1,7 +1,6 @@
package com.simibubi.create.modules.logistics.management.controller;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.modules.logistics.management.base.LogisticalInventoryControllerTileEntity;
public class SupplyTileEntity extends LogisticalInventoryControllerTileEntity {

View file

@ -2,7 +2,6 @@ package com.simibubi.create.modules.logistics.management.index;
import static com.simibubi.create.ScreenResources.DISABLED_SLOT_FRAME;
import static com.simibubi.create.ScreenResources.DISABLED_SLOT_INNER;
import static com.simibubi.create.ScreenResources.ICON_CONFIRM;
import static com.simibubi.create.ScreenResources.INDEX_BOTTOM;
import static com.simibubi.create.ScreenResources.INDEX_BOTTOM_TRIM;
import static com.simibubi.create.ScreenResources.INDEX_MIDDLE;
@ -15,6 +14,7 @@ import static com.simibubi.create.ScreenResources.INDEX_TAB;
import static com.simibubi.create.ScreenResources.INDEX_TAB_ACTIVE;
import static com.simibubi.create.ScreenResources.INDEX_TOP;
import static com.simibubi.create.ScreenResources.INDEX_TOP_TRIM;
import static com.simibubi.create.ScreenResources.I_CONFIRM;
import static com.simibubi.create.ScreenResources.SLOT_FRAME;
import static com.simibubi.create.ScreenResources.SLOT_INNER;
@ -24,8 +24,6 @@ import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.GlStateManager;
@ -44,12 +42,8 @@ import com.simibubi.create.foundation.utility.Lang;
import net.minecraft.block.Blocks;
import net.minecraft.client.GameSettings;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.util.InputMappings;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
@ -118,14 +112,14 @@ public class LogisticalIndexScreen extends AbstractSimiContainerScreen<Logistica
receiverTextField.setEnableBackgroundDrawing(false);
receiverTextField.setMaxStringLength(256);
receiverTextField.func_212954_a(this::onReceiverTextChanged);
if (initialTargetAddress != null)
if (initialTargetAddress != null)
receiverTextField.setText(initialTargetAddress);
receiverTextField.setFocused2(false);
receiverScrollInput = new SelectionScrollInput(guiLeft + 24, guiTop + 235, 126, 18).forOptions(receivers)
.titled(receiverScrollInputTitle).calling(this::onReceiverScrollInputChanged);
orderButton = new IconButton(guiLeft + 152, guiTop + 235, ICON_CONFIRM);
orderButton = new IconButton(guiLeft + 152, guiTop + 235, I_CONFIRM);
orderButton.active = false;
orderButton.setToolTip(orderButtonTooltip);
@ -161,6 +155,7 @@ public class LogisticalIndexScreen extends AbstractSimiContainerScreen<Logistica
if (container.te.update) {
buildDisplayedItems();
((SelectionScrollInput) receiverScrollInput).forOptions(container.te.availableReceivers);
container.te.update = false;
}
@ -515,7 +510,7 @@ public class LogisticalIndexScreen extends AbstractSimiContainerScreen<Logistica
int color = 0xFFFFFF;
if (orderedFully) {
color = ColorHelper.mixColors(container.te.getColor(), 0, 0.5f);
text = "0";
text = "\\u2714";
}
this.renderItemOverlayIntoGUI(font, stack, slotX, slotY, text, color);
@ -566,80 +561,4 @@ public class LogisticalIndexScreen extends AbstractSimiContainerScreen<Logistica
resetColor();
}
public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition,
@Nullable String text, int textColor) {
if (!stack.isEmpty()) {
if (stack.getItem().showDurabilityBar(stack)) {
GlStateManager.disableLighting();
GlStateManager.disableDepthTest();
GlStateManager.disableTexture();
GlStateManager.disableAlphaTest();
GlStateManager.disableBlend();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
double health = stack.getItem().getDurabilityForDisplay(stack);
int i = Math.round(13.0F - (float) health * 13.0F);
int j = stack.getItem().getRGBDurabilityForDisplay(stack);
this.draw(bufferbuilder, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255);
this.draw(bufferbuilder, xPosition + 2, yPosition + 13, i, 1, j >> 16 & 255, j >> 8 & 255, j & 255,
255);
GlStateManager.enableBlend();
GlStateManager.enableAlphaTest();
GlStateManager.enableTexture();
GlStateManager.enableLighting();
GlStateManager.enableDepthTest();
}
if (stack.getCount() != 1 || text != null) {
String s = text == null ? String.valueOf(stack.getCount()) : text;
GlStateManager.disableLighting();
GlStateManager.disableDepthTest();
GlStateManager.disableBlend();
GlStateManager.pushMatrix();
int guiScaleFactor = (int) minecraft.mainWindow.getGuiScaleFactor();
GlStateManager.translated((float) (xPosition + 16.5f), (float) (yPosition + 16.5f), 0);
double scale = 1;
switch (guiScaleFactor) {
case 1:
scale = 2060 / 2048d;
break;
case 2:
scale = .5;
break;
case 3:
scale = .675;
break;
case 4:
scale = .75;
break;
default:
scale = ((float) guiScaleFactor - 1) / guiScaleFactor;
}
GlStateManager.scaled(scale, scale, 0);
GlStateManager.translated(-fr.getStringWidth(s) - (guiScaleFactor > 1 ? 0 : -.5f),
-font.FONT_HEIGHT + (guiScaleFactor > 1 ? 1 : 1.75f), 0);
fr.drawStringWithShadow(s, 0, 0, textColor);
GlStateManager.popMatrix();
GlStateManager.enableBlend();
GlStateManager.enableLighting();
GlStateManager.enableDepthTest();
GlStateManager.enableBlend();
}
}
}
private void draw(BufferBuilder renderer, int x, int y, int width, int height, int red, int green, int blue,
int alpha) {
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
renderer.pos((double) (x + 0), (double) (y + 0), 0.0D).color(red, green, blue, alpha).endVertex();
renderer.pos((double) (x + 0), (double) (y + height), 0.0D).color(red, green, blue, alpha).endVertex();
renderer.pos((double) (x + width), (double) (y + height), 0.0D).color(red, green, blue, alpha).endVertex();
renderer.pos((double) (x + width), (double) (y + 0), 0.0D).color(red, green, blue, alpha).endVertex();
Tessellator.getInstance().draw();
}
}

View file

@ -16,7 +16,7 @@ import com.simibubi.create.foundation.type.CountedItemsList;
import com.simibubi.create.foundation.type.CountedItemsList.ItemStackEntry;
import com.simibubi.create.modules.logistics.management.LogisticalNetwork;
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerTileEntity;
import com.simibubi.create.modules.logistics.management.base.LogisticalInventoryControllerTileEntity;
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity;
import com.simibubi.create.modules.logistics.management.index.IndexContainerUpdatePacket.Type;
import net.minecraft.entity.player.PlayerEntity;
@ -91,7 +91,7 @@ public class LogisticalIndexTileEntity extends LogisticalControllerTileEntity im
return;
availableReceivers.clear();
for (LogisticalControllerTileEntity logisticalControllerTileEntity : network.receivers)
availableReceivers.add(logisticalControllerTileEntity.getName());
availableReceivers.add(logisticalControllerTileEntity.address);
sendData();
}
@ -165,7 +165,7 @@ public class LogisticalIndexTileEntity extends LogisticalControllerTileEntity im
if (!(te instanceof LogisticalInventoryControllerTileEntity))
continue;
CountedItemsList allItems = ((LogisticalInventoryControllerTileEntity) te).getAllItems();
controllers.put(te.getName(), allItems);
controllers.put(te.address, allItems);
}
}

View file

@ -72,9 +72,9 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
widgets.add(schematicsLabel);
}
confirmButton = new IconButton(mainLeft + 69, mainTop + 55, ScreenResources.ICON_CONFIRM);
folderButton = new IconButton(mainLeft + 204, mainTop + 6, ScreenResources.ICON_OPEN_FOLDER);
refreshButton = new IconButton(mainLeft + 204, mainTop + 26, ScreenResources.ICON_REFRESH);
confirmButton = new IconButton(mainLeft + 69, mainTop + 55, ScreenResources.I_CONFIRM);
folderButton = new IconButton(mainLeft + 204, mainTop + 6, ScreenResources.I_OPEN_FOLDER);
refreshButton = new IconButton(mainLeft + 204, mainTop + 26, ScreenResources.I_REFRESH);
widgets.add(confirmButton);
widgets.add(folderButton);
widgets.add(refreshButton);

View file

@ -72,11 +72,11 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
widgets.clear();
// Play Pause Stop
playButton = new IconButton(x + 70, y + 55, ScreenResources.ICON_PLAY);
playButton = new IconButton(x + 70, y + 55, ScreenResources.I_PLAY);
playIndicator = new Indicator(x + 70, y + 50, "");
pauseButton = new IconButton(x + 88, y + 55, ScreenResources.ICON_PAUSE);
pauseButton = new IconButton(x + 88, y + 55, ScreenResources.I_PAUSE);
pauseIndicator = new Indicator(x + 88, y + 50, "");
resetButton = new IconButton(x + 106, y + 55, ScreenResources.ICON_STOP);
resetButton = new IconButton(x + 106, y + 55, ScreenResources.I_STOP);
resetIndicator = new Indicator(x + 106, y + 50, "");
resetIndicator.state = State.RED;
Collections.addAll(widgets, playButton, playIndicator, pauseButton, pauseIndicator, resetButton,
@ -85,9 +85,9 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
// Replace settings
replaceLevelButtons = new Vector<>(4);
replaceLevelIndicators = new Vector<>(4);
List<ScreenResources> icons = ImmutableList.of(ScreenResources.ICON_DONT_REPLACE,
ScreenResources.ICON_REPLACE_SOLID, ScreenResources.ICON_REPLACE_ANY,
ScreenResources.ICON_REPLACE_EMPTY);
List<ScreenResources> icons = ImmutableList.of(ScreenResources.I_DONT_REPLACE,
ScreenResources.I_REPLACE_SOLID, ScreenResources.I_REPLACE_ANY,
ScreenResources.I_REPLACE_EMPTY);
List<String> toolTips = ImmutableList.of(Lang.translate("gui.schematicannon.option.dontReplaceSolid"),
Lang.translate("gui.schematicannon.option.replaceWithSolid"),
Lang.translate("gui.schematicannon.option.replaceWithAny"),
@ -102,12 +102,12 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
widgets.addAll(replaceLevelIndicators);
// Other Settings
skipMissingButton = new IconButton(x + 106, y + 101, ScreenResources.ICON_SKIP_MISSING);
skipMissingButton = new IconButton(x + 106, y + 101, ScreenResources.I_SKIP_MISSING);
skipMissingButton.setToolTip(Lang.translate("gui.schematicannon.option.skipMissing"));
skipMissingIndicator = new Indicator(x + 106, y + 96, "");
Collections.addAll(widgets, skipMissingButton, skipMissingIndicator);
skipTilesButton = new IconButton(x + 124, y + 101, ScreenResources.ICON_SKIP_TILES);
skipTilesButton = new IconButton(x + 124, y + 101, ScreenResources.I_SKIP_TILES);
skipTilesButton.setToolTip(Lang.translate("gui.schematicannon.option.skipTileEntities"));
skipTilesIndicator = new Indicator(x + 124, y + 96, "");
Collections.addAll(widgets, skipTilesButton, skipTilesIndicator);

View file

@ -9,12 +9,12 @@ import com.simibubi.create.foundation.utility.Lang;
public enum Tools {
Deploy(new DeployTool(), ScreenResources.ICON_TOOL_DEPLOY),
Move(new MoveTool(), ScreenResources.ICON_TOOL_MOVE_XZ),
MoveY(new MoveVerticalTool(), ScreenResources.ICON_TOOL_MOVE_Y),
Rotate(new RotateTool(), ScreenResources.ICON_TOOL_ROTATE),
Print(new PlaceTool(), ScreenResources.ICON_CONFIRM),
Flip(new FlipTool(), ScreenResources.ICON_TOOL_MIRROR);
Deploy(new DeployTool(), ScreenResources.I_TOOL_DEPLOY),
Move(new MoveTool(), ScreenResources.I_TOOL_MOVE_XZ),
MoveY(new MoveVerticalTool(), ScreenResources.I_TOOL_MOVE_Y),
Rotate(new RotateTool(), ScreenResources.I_TOOL_ROTATE),
Print(new PlaceTool(), ScreenResources.I_CONFIRM),
Flip(new FlipTool(), ScreenResources.I_TOOL_MIRROR);
private ISchematicTool tool;
private ScreenResources icon;

View file

@ -24,6 +24,13 @@
"item.create.flour": "Wheat Flour",
"item.create.dough": "Dough",
"item.create.logistical_controller_supply": "Item Supply",
"item.create.logistical_controller_request": "Item Request",
"item.create.logistical_controller_storage": "Item Storage",
"item.create.logistical_controller_calculation": "Ingredient Calculator",
"item.create.logistical_controller_transactions": "Task Manager",
"item.create.logistical_dial": "Logistical Dial",
"item.create.blazing_pickaxe": "Blazing Pickaxe",
"item.create.blazing_shovel": "Blazing Shovel",
"item.create.blazing_axe": "Blazing Axe",
@ -75,6 +82,9 @@
"block.create.pulse_repeater": "Pulse Repeater",
"block.create.flexpeater": "FlexPeater",
"block.create.entity_detector": "Belt Observer",
"block.create.logistical_casing": "Logistical Casing",
"block.create.logistical_controller": "Logistical Controller",
"block.create.logistical_index": "Logistical Index",
"block.create.tiled_glass": "Tiled Glass",
"block.create.tiled_glass_pane": "Tiled Glass Pane",
@ -344,6 +354,16 @@
"create.gui.index.targetAddressSelect": "Destination Address",
"create.gui.index.confirmOrder": "Confirm Order",
"create.logistics.priority": "Priority",
"create.logistics.priority.lowest": "Lowest",
"create.logistics.priority.low": "Low",
"create.logistics.priority.high": "High",
"create.logistics.priority.highest": "Highest",
"create.gui.logistical_controller.active_mode": "Active Mode",
"create.gui.logistical_controller.passive_mode": "Passive Mode",
"create.gui.requester.requestedItemCount": "Requested Amount",
"create.gui.storage.passiveModeOnly": "Item Storage is Passive only",
"create.tooltip.holdKey": "Hold [%1$s]",
"create.tooltip.holdKeyOrKey": "Hold [%1$s] or [%2$s]",
"create.tooltip.keyShift": "Shift",

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB