crafting terminal base

This commit is contained in:
Ellpeck 2020-05-08 22:58:16 +02:00
parent 0bb8fbaf5c
commit 67e7da2b73
10 changed files with 139 additions and 17 deletions

View file

@ -24,8 +24,12 @@ import de.ellpeck.prettypipes.pipe.modules.retrieval.RetrievalModuleItem;
import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleContainer;
import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleGui;
import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleItem;
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlock;
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
import de.ellpeck.prettypipes.terminal.ItemTerminalBlock;
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalGui;
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer;
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
import net.minecraft.block.Block;
@ -88,6 +92,10 @@ public final class Registry {
public static TileEntityType<ItemTerminalTileEntity> itemTerminalTileEntity;
public static ContainerType<ItemTerminalContainer> itemTerminalContainer;
public static Block craftingTerminalBlock;
public static TileEntityType<CraftingTerminalTileEntity> craftingTerminalTileEntity;
public static ContainerType<CraftingTerminalContainer> craftingTerminalContainer;
public static EntityType<PipeFrameEntity> pipeFrameEntity;
public static ContainerType<ExtractionModuleContainer> extractionModuleContainer;
@ -99,7 +107,8 @@ public final class Registry {
public static void registerBlocks(RegistryEvent.Register<Block> event) {
event.getRegistry().registerAll(
pipeBlock = new PipeBlock().setRegistryName("pipe"),
itemTerminalBlock = new ItemTerminalBlock().setRegistryName("item_terminal")
itemTerminalBlock = new ItemTerminalBlock().setRegistryName("item_terminal"),
craftingTerminalBlock = new CraftingTerminalBlock().setRegistryName("crafting_terminal")
);
}
@ -129,7 +138,8 @@ public final class Registry {
public static void registerTiles(RegistryEvent.Register<TileEntityType<?>> event) {
event.getRegistry().registerAll(
pipeTileEntity = (TileEntityType<PipeTileEntity>) TileEntityType.Builder.create(PipeTileEntity::new, pipeBlock).build(null).setRegistryName("pipe"),
itemTerminalTileEntity = (TileEntityType<ItemTerminalTileEntity>) TileEntityType.Builder.create(ItemTerminalTileEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal")
itemTerminalTileEntity = (TileEntityType<ItemTerminalTileEntity>) TileEntityType.Builder.create(ItemTerminalTileEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"),
craftingTerminalTileEntity = (TileEntityType<CraftingTerminalTileEntity>) TileEntityType.Builder.create(CraftingTerminalTileEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal")
);
}
@ -145,6 +155,7 @@ public final class Registry {
event.getRegistry().registerAll(
pipeContainer = (ContainerType<MainPipeContainer>) IForgeContainerType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"),
itemTerminalContainer = (ContainerType<ItemTerminalContainer>) IForgeContainerType.create((windowId, inv, data) -> new ItemTerminalContainer(itemTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("item_terminal"),
craftingTerminalContainer = (ContainerType<CraftingTerminalContainer>) IForgeContainerType.create((windowId, inv, data) -> new CraftingTerminalContainer(craftingTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("crafting_terminal"),
extractionModuleContainer = createPipeContainer("extraction_module"),
filterModuleContainer = createPipeContainer("filter_module"),
retrievalModuleContainer = createPipeContainer("retrieval_module"),
@ -192,6 +203,7 @@ public final class Registry {
ScreenManager.registerFactory(pipeContainer, MainPipeGui::new);
ScreenManager.registerFactory(itemTerminalContainer, ItemTerminalGui::new);
ScreenManager.registerFactory(craftingTerminalContainer, CraftingTerminalGui::new);
ScreenManager.registerFactory(extractionModuleContainer, ExtractionModuleGui::new);
ScreenManager.registerFactory(filterModuleContainer, FilterModuleGui::new);
ScreenManager.registerFactory(retrievalModuleContainer, RetrievalModuleGui::new);

View file

@ -0,0 +1,17 @@
package de.ellpeck.prettypipes.terminal;
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
import net.minecraft.block.ContainerBlock;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockReader;
import javax.annotation.Nullable;
public class CraftingTerminalBlock extends ItemTerminalBlock {
@Nullable
@Override
public TileEntity createNewTileEntity(IBlockReader worldIn) {
return new CraftingTerminalTileEntity();
}
}

View file

@ -0,0 +1,31 @@
package de.ellpeck.prettypipes.terminal;
import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import javax.annotation.Nullable;
public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
public CraftingTerminalTileEntity() {
super(Registry.craftingTerminalTileEntity);
}
@Override
public ITextComponent getDisplayName() {
return new TranslationTextComponent("container." + PrettyPipes.ID + ".crafting_terminal");
}
@Nullable
@Override
public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) {
return new CraftingTerminalContainer(Registry.craftingTerminalContainer, window, player, this.pos);
}
}

View file

@ -52,8 +52,12 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
public Map<EquatableItemStack, NetworkItem> networkItems;
private final Queue<Triple<NetworkLocation, Integer, Integer>> pendingRequests = new ArrayDeque<>();
protected ItemTerminalTileEntity(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
public ItemTerminalTileEntity() {
super(Registry.itemTerminalTileEntity);
this(Registry.itemTerminalTileEntity);
}
@Override

View file

@ -0,0 +1,19 @@
package de.ellpeck.prettypipes.terminal.containers;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.util.math.BlockPos;
import javax.annotation.Nullable;
public class CraftingTerminalContainer extends ItemTerminalContainer {
public CraftingTerminalContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos) {
super(type, id, player, pos);
}
@Override
protected int getSlotXOffset() {
return 65;
}
}

View file

@ -0,0 +1,26 @@
package de.ellpeck.prettypipes.terminal.containers;
import de.ellpeck.prettypipes.PrettyPipes;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
public class CraftingTerminalGui extends ItemTerminalGui {
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png");
public CraftingTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
super(screenContainer, inv, titleIn);
this.xSize = 256;
}
@Override
protected ResourceLocation getTexture() {
return TEXTURE;
}
@Override
protected int getXOffset() {
return 65;
}
}

View file

@ -31,16 +31,21 @@ public class ItemTerminalContainer extends Container {
super(type, id);
this.tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos);
int off = this.getSlotXOffset();
for (int i = 0; i < 6; i++)
this.addSlot(new SlotItemHandler(this.tile.items, i, 8 + i % 3 * 18, 102 + i / 3 * 18));
this.addSlot(new SlotItemHandler(this.tile.items, i, 8 + off + i % 3 * 18, 102 + i / 3 * 18));
for (int i = 0; i < 6; i++)
this.addSlot(new SlotItemHandler(this.tile.items, i + 6, 116 + i % 3 * 18, 102 + i / 3 * 18));
this.addSlot(new SlotItemHandler(this.tile.items, i + 6, 116 + off + i % 3 * 18, 102 + i / 3 * 18));
for (int l = 0; l < 3; ++l)
for (int j1 = 0; j1 < 9; ++j1)
this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + j1 * 18, 154 + l * 18));
this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + off + j1 * 18, 154 + l * 18));
for (int i1 = 0; i1 < 9; ++i1)
this.addSlot(new Slot(player.inventory, i1, 8 + i1 * 18, 212));
this.addSlot(new Slot(player.inventory, i1, 8 + off + i1 * 18, 212));
}
protected int getSlotXOffset() {
return 0;
}
@Override

View file

@ -47,7 +47,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
@Override
protected void init() {
super.init();
this.plusButton = this.addButton(new Button(this.guiLeft + this.xSize / 2 - 7 + 12, this.guiTop + 103, 12, 12, "+", button -> {
this.plusButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 + 12, this.guiTop + 103, 12, 12, "+", button -> {
int modifier = requestModifier();
if (modifier > 1 && this.requestAmount == 1) {
this.requestAmount = modifier;
@ -57,13 +57,13 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
if (this.requestAmount > 384)
this.requestAmount = 384;
}));
this.minusButton = this.addButton(new Button(this.guiLeft + this.xSize / 2 - 7 - 24, this.guiTop + 103, 12, 12, "-", button -> {
this.minusButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 - 24, this.guiTop + 103, 12, 12, "-", button -> {
this.requestAmount -= requestModifier();
if (this.requestAmount < 1)
this.requestAmount = 1;
}));
this.minusButton.active = false;
this.requestButton = this.addButton(new Button(this.guiLeft + this.xSize / 2 - 7 - 25, this.guiTop + 115, 50, 20, I18n.format("info." + PrettyPipes.ID + ".request"), button -> {
this.requestButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 - 25, this.guiTop + 115, 50, 20, I18n.format("info." + PrettyPipes.ID + ".request"), button -> {
Optional<ItemTerminalWidget> widget = this.streamWidgets().filter(w -> w.selected).findFirst();
if (!widget.isPresent())
return;
@ -91,13 +91,17 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
}));
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 9; x++)
this.addButton(new ItemTerminalWidget(this.guiLeft + 8 + x * 18, this.guiTop + 18 + y * 18, x, y, this));
this.addButton(new ItemTerminalWidget(this.guiLeft + this.getXOffset() + 8 + x * 18, this.guiTop + 18 + y * 18, x, y, this));
}
this.search = this.addButton(new TextFieldWidget(this.font, this.guiLeft + 97, this.guiTop + 6, 86, 8, ""));
this.search = this.addButton(new TextFieldWidget(this.font, this.guiLeft + this.getXOffset() + 97, this.guiTop + 6, 86, 8, ""));
this.search.setEnableBackgroundDrawing(false);
this.lastSearchText = "";
}
protected int getXOffset() {
return 0;
}
@Override
public void tick() {
super.tick();
@ -194,26 +198,30 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8, this.ySize - 96 + 2, 4210752);
this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8 + this.getXOffset(), this.ySize - 96 + 2, 4210752);
this.font.drawString(this.title.getFormattedText(), 8, 6, 4210752);
String amount = String.valueOf(this.requestAmount);
this.font.drawString(amount, (this.xSize - this.font.getStringWidth(amount)) / 2F - 7, 106, 4210752);
this.font.drawString(amount, (176 + 15 - this.font.getStringWidth(amount)) / 2F - 7 + this.getXOffset(), 106, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
this.getMinecraft().getTextureManager().bindTexture(this.getTexture());
this.blit(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {
float percentage = this.scrollOffset / (float) (this.sortedItems.size() / 9 - 3);
this.blit(this.guiLeft + 172, this.guiTop + 18 + (int) (percentage * (70 - 15)), 244, 0, 12, 15);
this.blit(this.guiLeft + this.getXOffset() + 172, this.guiTop + 18 + (int) (percentage * (70 - 15)), 232, 241, 12, 15);
} else {
this.blit(this.guiLeft + 172, this.guiTop + 18, 244, 15, 12, 15);
this.blit(this.guiLeft + this.getXOffset() + 172, this.guiTop + 18, 244, 241, 12, 15);
}
}
protected ResourceLocation getTexture() {
return TEXTURE;
}
@Override
public boolean mouseScrolled(double x, double y, double scroll) {
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB