mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-22 15:39:22 +01:00
IT COMPILES!!
This commit is contained in:
parent
46320dd889
commit
0df6401c4e
50 changed files with 800 additions and 882 deletions
|
@ -8,8 +8,8 @@ import de.ellpeck.prettypipes.network.PipeNetwork;
|
|||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||
import de.ellpeck.prettypipes.pipe.PipeRenderer;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeRenderer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.MainPipeGui;
|
||||
|
@ -36,9 +36,9 @@ 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.pressurizer.PressurizerBlock;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerContainer;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerGui;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlock;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlock;
|
||||
|
@ -47,36 +47,26 @@ 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;
|
||||
import net.minecraft.client.gui.ScreenManager;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.RenderTypeLookup;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.inventory.container.MenuType;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.capabilities.CapabilityToken;
|
||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
@ -84,7 +74,6 @@ import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -94,7 +83,7 @@ import java.util.function.BiFunction;
|
|||
@Mod.EventBusSubscriber(bus = Bus.MOD)
|
||||
public final class Registry {
|
||||
|
||||
public static final CreativeModeTab GROUP = new CreativeModeTab(PrettyPipes.ID) {
|
||||
public static final CreativeModeTab TAB = new CreativeModeTab(PrettyPipes.ID) {
|
||||
@Override
|
||||
public ItemStack makeIcon() {
|
||||
return new ItemStack(wrenchItem);
|
||||
|
@ -110,21 +99,21 @@ public final class Registry {
|
|||
public static Item pipeFrameItem;
|
||||
|
||||
public static Block pipeBlock;
|
||||
public static BlockEntityType<PipeBlockEntity> pipeTileEntity;
|
||||
public static BlockEntityType<PipeBlockEntity> pipeBlockEntity;
|
||||
public static MenuType<MainPipeContainer> pipeContainer;
|
||||
|
||||
public static Block itemTerminalBlock;
|
||||
public static BlockEntityType<ItemTerminalBlockEntity> itemTerminalTileEntity;
|
||||
public static BlockEntityType<ItemTerminalBlockEntity> itemTerminalBlockEntity;
|
||||
public static MenuType<ItemTerminalContainer> itemTerminalContainer;
|
||||
|
||||
public static Block craftingTerminalBlock;
|
||||
public static BlockEntityType<CraftingTerminalBlockEntity> craftingTerminalTileEntity;
|
||||
public static BlockEntityType<CraftingTerminalBlockEntity> craftingTerminalBlockEntity;
|
||||
public static MenuType<CraftingTerminalContainer> craftingTerminalContainer;
|
||||
|
||||
public static EntityType<PipeFrameEntity> pipeFrameEntity;
|
||||
|
||||
public static Block pressurizerBlock;
|
||||
public static BlockEntityType<PressurizerBlockEntity> pressurizerTileEntity;
|
||||
public static BlockEntityType<PressurizerBlockEntity> pressurizerBlockEntity;
|
||||
public static MenuType<PressurizerContainer> pressurizerContainer;
|
||||
|
||||
public static MenuType<ExtractionModuleContainer> extractionModuleContainer;
|
||||
|
@ -147,10 +136,10 @@ public final class Registry {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event) {
|
||||
IForgeRegistry<Item> registry = event.getRegistry();
|
||||
var registry = event.getRegistry();
|
||||
registry.registerAll(
|
||||
wrenchItem = new WrenchItem().setRegistryName("wrench"),
|
||||
new Item(new Item.Properties().group(GROUP)).setRegistryName("blank_module"),
|
||||
new Item(new Item.Properties().tab(TAB)).setRegistryName("blank_module"),
|
||||
pipeFrameItem = new PipeFrameItem().setRegistryName("pipe_frame")
|
||||
);
|
||||
registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new));
|
||||
|
@ -168,23 +157,23 @@ public final class Registry {
|
|||
|
||||
ForgeRegistries.BLOCKS.getValues().stream()
|
||||
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
|
||||
.forEach(b -> registry.register(new BlockItem(b, new Item.Properties().group(GROUP)).setRegistryName(b.getRegistryName())));
|
||||
.forEach(b -> registry.register(new BlockItem(b, new Item.Properties().tab(TAB)).setRegistryName(b.getRegistryName())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerTiles(RegistryEvent.Register<TileEntityType<?>> event) {
|
||||
public static void registerBlockEntities(RegistryEvent.Register<BlockEntityType<?>> event) {
|
||||
event.getRegistry().registerAll(
|
||||
pipeTileEntity = (TileEntityType<PipeBlockEntity>) TileEntityType.Builder.create(PipeBlockEntity::new, pipeBlock).build(null).setRegistryName("pipe"),
|
||||
itemTerminalTileEntity = (TileEntityType<ItemTerminalBlockEntity>) TileEntityType.Builder.create(ItemTerminalBlockEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"),
|
||||
craftingTerminalTileEntity = (TileEntityType<CraftingTerminalBlockEntity>) TileEntityType.Builder.create(CraftingTerminalBlockEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal"),
|
||||
pressurizerTileEntity = (TileEntityType<PressurizerBlockEntity>) TileEntityType.Builder.create(PressurizerBlockEntity::new, pressurizerBlock).build(null).setRegistryName("pressurizer")
|
||||
pipeBlockEntity = (BlockEntityType<PipeBlockEntity>) BlockEntityType.Builder.of(PipeBlockEntity::new, pipeBlock).build(null).setRegistryName("pipe"),
|
||||
itemTerminalBlockEntity = (BlockEntityType<ItemTerminalBlockEntity>) BlockEntityType.Builder.of(ItemTerminalBlockEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"),
|
||||
craftingTerminalBlockEntity = (BlockEntityType<CraftingTerminalBlockEntity>) BlockEntityType.Builder.of(CraftingTerminalBlockEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal"),
|
||||
pressurizerBlockEntity = (BlockEntityType<PressurizerBlockEntity>) BlockEntityType.Builder.of(PressurizerBlockEntity::new, pressurizerBlock).build(null).setRegistryName("pressurizer")
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerEntities(RegistryEvent.Register<EntityType<?>> event) {
|
||||
event.getRegistry().registerAll(
|
||||
pipeFrameEntity = (EntityType<PipeFrameEntity>) EntityType.Builder.<PipeFrameEntity>create(PipeFrameEntity::new, EntityClassification.MISC).build("pipe_frame").setRegistryName("pipe_frame")
|
||||
pipeFrameEntity = (EntityType<PipeFrameEntity>) EntityType.Builder.<PipeFrameEntity>of(PipeFrameEntity::new, MobCategory.MISC).build("pipe_frame").setRegistryName("pipe_frame")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -207,32 +196,30 @@ public final class Registry {
|
|||
|
||||
private static <T extends AbstractPipeContainer<?>> MenuType<T> createPipeContainer(String name) {
|
||||
return (MenuType<T>) IForgeMenuType.create((windowId, inv, data) -> {
|
||||
PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, inv.player.world, data.readBlockPos());
|
||||
int moduleIndex = data.readInt();
|
||||
ItemStack moduleStack = tile.modules.getStackInSlot(moduleIndex);
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, inv.player.level, data.readBlockPos());
|
||||
var moduleIndex = data.readInt();
|
||||
var moduleStack = tile.modules.getStackInSlot(moduleIndex);
|
||||
return ((IModule) moduleStack.getItem()).getContainer(moduleStack, tile, windowId, inv, inv.player, moduleIndex);
|
||||
}).setRegistryName(name);
|
||||
}
|
||||
|
||||
private static Item[] createTieredModule(String name, BiFunction<String, ModuleTier, ModuleItem> item) {
|
||||
List<Item> items = new ArrayList<>();
|
||||
for (ModuleTier tier : ModuleTier.values())
|
||||
for (var tier : ModuleTier.values())
|
||||
items.add(item.apply(name, tier).setRegistryName(tier.name().toLowerCase(Locale.ROOT) + "_" + name));
|
||||
return items.toArray(new Item[0]);
|
||||
}
|
||||
|
||||
public static void setup(FMLCommonSetupEvent event) {
|
||||
registerCap(PipeNetwork.class);
|
||||
registerCap(IPipeConnectable.class);
|
||||
PacketHandler.setup();
|
||||
}
|
||||
|
||||
public static final class Client {
|
||||
|
||||
public static void setup(FMLClientSetupEvent event) {
|
||||
RenderTypeLookup.setRenderLayer(pipeBlock, RenderType.getCutout());
|
||||
ClientRegistry.bindTileEntityRenderer(pipeTileEntity, PipeRenderer::new);
|
||||
RenderingRegistry.registerEntityRenderingHandler(pipeFrameEntity, PipeFrameRenderer::new);
|
||||
ItemBlockRenderTypes.setRenderLayer(pipeBlock, RenderType.cutout());
|
||||
BlockEntityRenderers.register(pipeBlockEntity, PipeRenderer::new);
|
||||
EntityRenderers.register(pipeFrameEntity, PipeFrameRenderer::new);
|
||||
|
||||
MenuScreens.register(pipeContainer, MainPipeGui::new);
|
||||
MenuScreens.register(itemTerminalContainer, ItemTerminalGui::new);
|
||||
|
@ -247,19 +234,4 @@ public final class Registry {
|
|||
MenuScreens.register(filterModifierModuleContainer, FilterModifierModuleGui::new);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void registerCap(Class<T> capClass) {
|
||||
CapabilityManager.INSTANCE.register(capClass, new Capability.IStorage<T>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public INBT writeNBT(Capability<T> capability, T instance, Direction side) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<T> capability, T instance, Direction side, INBT nbt) {
|
||||
|
||||
}
|
||||
}, () -> null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public abstract class ModuleItem extends Item implements IModule {
|
|||
private final String name;
|
||||
|
||||
public ModuleItem(String name) {
|
||||
super(new Properties().tab(Registry.GROUP).stacksTo(16));
|
||||
super(new Properties().tab(Registry.TAB).stacksTo(16));
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.List;
|
|||
public class PipeFrameItem extends Item {
|
||||
|
||||
public PipeFrameItem() {
|
||||
super(new Properties().tab(Registry.GROUP));
|
||||
super(new Properties().tab(Registry.TAB));
|
||||
}
|
||||
|
||||
// HangingEntityItem copypasta mostly, since it hardcodes the entities bleh
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.util.List;
|
|||
public class WrenchItem extends Item {
|
||||
|
||||
public WrenchItem() {
|
||||
super(new Item.Properties().stacksTo(1).tab(Registry.GROUP));
|
||||
super(new Item.Properties().stacksTo(1).tab(Registry.TAB));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.misc;
|
|||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -12,7 +12,7 @@ import net.minecraftforge.fml.common.Mod;
|
|||
public final class Events {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onWorldCaps(AttachCapabilitiesEvent<World> event) {
|
||||
public static void onWorldCaps(AttachCapabilitiesEvent<Level> event) {
|
||||
event.addCapability(new ResourceLocation(PrettyPipes.ID, "network"), new PipeNetwork(event.getObject()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import de.ellpeck.prettypipes.packets.PacketButton;
|
|||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -16,7 +16,6 @@ import net.minecraft.world.inventory.Slot;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
|
@ -50,8 +49,8 @@ public class ItemFilter extends ItemStackHandler {
|
|||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public List<Widget> getButtons(Screen gui, int x, int y) {
|
||||
List<Widget> buttons = new ArrayList<>();
|
||||
public List<AbstractWidget> getButtons(Screen gui, int x, int y) {
|
||||
List<AbstractWidget> buttons = new ArrayList<>();
|
||||
if (this.canModifyWhitelist) {
|
||||
var whitelistText = (Supplier<TranslatableComponent>) () -> new TranslatableComponent("info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist"));
|
||||
buttons.add(new Button(x, y, 70, 20, whitelistText.get(), button -> {
|
||||
|
|
|
@ -1,26 +1,17 @@
|
|||
package de.ellpeck.prettypipes.misc;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.ItemRenderer;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ItemTerminalWidget extends Widget {
|
||||
public class ItemTerminalWidget extends AbstractWidget {
|
||||
|
||||
private final ItemTerminalGui screen;
|
||||
public final int gridX;
|
||||
|
@ -30,7 +21,7 @@ public class ItemTerminalWidget extends Widget {
|
|||
public boolean craftable;
|
||||
|
||||
public ItemTerminalWidget(int xIn, int yIn, int gridX, int gridY, ItemTerminalGui screen) {
|
||||
super(xIn, yIn, 16, 16, new StringTextComponent(""));
|
||||
super(xIn, yIn, 16, 16, new TextComponent(""));
|
||||
this.gridX = gridX;
|
||||
this.gridY = gridY;
|
||||
this.screen = screen;
|
||||
|
@ -44,25 +35,25 @@ public class ItemTerminalWidget extends Widget {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderButton(MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
Minecraft mc = this.screen.getMinecraft();
|
||||
ItemRenderer renderer = mc.getItemRenderer();
|
||||
public void renderButton(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
var mc = this.screen.getMinecraft();
|
||||
var renderer = mc.getItemRenderer();
|
||||
this.setBlitOffset(100);
|
||||
renderer.zLevel = 100;
|
||||
renderer.blitOffset = 100;
|
||||
if (this.selected)
|
||||
fill(matrix, this.x, this.y, this.x + 16, this.y + 16, -2130706433);
|
||||
RenderSystem.enableDepthTest();
|
||||
renderer.renderItemAndEffectIntoGUI(mc.player, this.stack, this.x, this.y);
|
||||
int amount = !this.craftable ? this.stack.getCount() : 0;
|
||||
String amountStrg = this.stack.getCount() >= 1000 ? amount / 1000 + "k" : String.valueOf(amount);
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.scalef(0.8F, 0.8F, 1);
|
||||
renderer.renderItemOverlayIntoGUI(mc.fontRenderer, this.stack, (int) (this.x / 0.8F) + 4, (int) (this.y / 0.8F) + 4, amountStrg);
|
||||
RenderSystem.popMatrix();
|
||||
renderer.zLevel = 0;
|
||||
renderer.renderGuiItem(this.stack, this.x, this.y);
|
||||
var amount = !this.craftable ? this.stack.getCount() : 0;
|
||||
var amountStrg = this.stack.getCount() >= 1000 ? amount / 1000 + "k" : String.valueOf(amount);
|
||||
matrix.pushPose();
|
||||
matrix.scale(0.8F, 0.8F, 1);
|
||||
renderer.renderGuiItemDecorations(mc.font, this.stack, (int) (this.x / 0.8F) + 4, (int) (this.y / 0.8F) + 4, amountStrg);
|
||||
matrix.popPose();
|
||||
renderer.blitOffset = 0;
|
||||
this.setBlitOffset(0);
|
||||
|
||||
if (this.isHovered()) {
|
||||
if (this.isHoveredOrFocused()) {
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.colorMask(true, true, true, false);
|
||||
this.fillGradient(matrix, this.x, this.y, this.x + 16, this.y + 16, -2130706433, -2130706433);
|
||||
|
@ -72,18 +63,21 @@ public class ItemTerminalWidget extends Widget {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderToolTip(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
if (this.visible && this.isHovered()) {
|
||||
GuiUtils.preItemToolTip(this.stack);
|
||||
List<ITextComponent> tooltip = this.screen.getTooltipFromItem(this.stack);
|
||||
public void renderToolTip(PoseStack matrix, int mouseX, int mouseY) {
|
||||
if (this.visible && this.isHoveredOrFocused()) {
|
||||
var tooltip = this.screen.getTooltipFromItem(this.stack);
|
||||
if (this.stack.getCount() >= 1000) {
|
||||
ITextComponent comp = tooltip.get(0);
|
||||
if (comp instanceof TextComponent) {
|
||||
tooltip.set(0, ((TextComponent) comp).append(new StringTextComponent(" (" + this.stack.getCount() + ')').mergeStyle(TextFormatting.BOLD)));
|
||||
var comp = tooltip.get(0);
|
||||
if (comp instanceof TextComponent text) {
|
||||
tooltip.set(0, text.append(new TextComponent(" (" + this.stack.getCount() + ')').withStyle(ChatFormatting.BOLD)));
|
||||
}
|
||||
}
|
||||
this.screen.func_243308_b(matrix, tooltip, mouseX, mouseY);
|
||||
GuiUtils.postItemToolTip();
|
||||
this.screen.renderTooltip(matrix, tooltip, Optional.empty(), mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNarration(NarrationElementOutput output) {
|
||||
// TODO narration
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PlayerPrefs {
|
||||
|
||||
|
@ -45,7 +47,7 @@ public class PlayerPrefs {
|
|||
}
|
||||
|
||||
private static File getFile() {
|
||||
File location = Minecraft.getInstance().gameDir;
|
||||
File location = Minecraft.getInstance().gameDirectory;
|
||||
return new File(location, PrettyPipes.ID + "prefs");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class NetworkItem {
|
|||
}
|
||||
|
||||
public ItemStack asStack() {
|
||||
ItemStack stack = this.item.stack.copy();
|
||||
ItemStack stack = this.item.stack().copy();
|
||||
stack.setCount(this.amount);
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.misc.ItemEquality;
|
|||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
@ -93,14 +94,14 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
|
|||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.put("pipe_pos", NBTUtil.writeBlockPos(this.pipePos));
|
||||
nbt.putInt("direction", this.direction.getIndex());
|
||||
nbt.put("pipe_pos", NbtUtils.writeBlockPos(this.pipePos));
|
||||
nbt.putInt("direction", this.direction.ordinal());
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.pipePos = NBTUtil.readBlockPos(nbt.getCompound("pipe_pos"));
|
||||
this.direction = Direction.byIndex(nbt.getInt("direction"));
|
||||
this.pipePos = NbtUtils.readBlockPos(nbt.getCompound("pipe_pos"));
|
||||
this.direction = Direction.values()[(nbt.getInt("direction"))];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package de.ellpeck.prettypipes.network;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -28,25 +27,23 @@ public class NetworkLock implements INBTSerializable<CompoundTag> {
|
|||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.putUniqueId("id", this.lockId);
|
||||
nbt.putUUID("id", this.lockId);
|
||||
nbt.put("location", this.location.serializeNBT());
|
||||
nbt.put("stack", this.stack.write(new CompoundTag()));
|
||||
nbt.put("stack", this.stack.save(new CompoundTag()));
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.lockId = nbt.getUniqueId("id");
|
||||
this.lockId = nbt.getUUID("id");
|
||||
this.location = new NetworkLocation(nbt.getCompound("location"));
|
||||
this.stack = ItemStack.read(nbt.getCompound("stack"));
|
||||
this.stack = ItemStack.of(nbt.getCompound("stack"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof NetworkLock) {
|
||||
NetworkLock that = (NetworkLock) o;
|
||||
if (o instanceof NetworkLock that)
|
||||
return this.lockId.equals(that.lockId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,33 +1,29 @@
|
|||
package de.ellpeck.prettypipes.network;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeItem;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import org.jgrapht.Graph;
|
||||
import org.jgrapht.GraphPath;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -88,9 +84,9 @@ public class PipeItem implements IPipeItem {
|
|||
|
||||
// initialize position if new
|
||||
if (this.x == 0 && this.y == 0 && this.z == 0) {
|
||||
this.x = MathHelper.lerp(0.5F, startInventory.getX(), this.currGoalPos.getX()) + 0.5F;
|
||||
this.y = MathHelper.lerp(0.5F, startInventory.getY(), this.currGoalPos.getY()) + 0.5F;
|
||||
this.z = MathHelper.lerp(0.5F, startInventory.getZ(), this.currGoalPos.getZ()) + 0.5F;
|
||||
this.x = Mth.lerp(0.5F, startInventory.getX(), this.currGoalPos.getX()) + 0.5F;
|
||||
this.y = Mth.lerp(0.5F, startInventory.getY(), this.currGoalPos.getY()) + 0.5F;
|
||||
this.z = Mth.lerp(0.5F, startInventory.getZ(), this.currGoalPos.getZ()) + 0.5F;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,25 +94,25 @@ public class PipeItem implements IPipeItem {
|
|||
public void updateInPipe(PipeBlockEntity currPipe) {
|
||||
// this prevents pipes being updated after one another
|
||||
// causing an item that just switched to tick twice
|
||||
long worldTick = currPipe.getWorld().getGameTime();
|
||||
var worldTick = currPipe.getLevel().getGameTime();
|
||||
if (this.lastWorldTick == worldTick)
|
||||
return;
|
||||
this.lastWorldTick = worldTick;
|
||||
|
||||
float motionLeft = this.speed;
|
||||
var motionLeft = this.speed;
|
||||
while (motionLeft > 0) {
|
||||
float currSpeed = Math.min(0.25F, motionLeft);
|
||||
var currSpeed = Math.min(0.25F, motionLeft);
|
||||
motionLeft -= currSpeed;
|
||||
|
||||
BlockPos myPos = new BlockPos(this.x, this.y, this.z);
|
||||
if (!myPos.equals(currPipe.getPos()) && (currPipe.getPos().equals(this.getDestPipe()) || !myPos.equals(this.startInventory))) {
|
||||
var myPos = new BlockPos(this.x, this.y, this.z);
|
||||
if (!myPos.equals(currPipe.getBlockPos()) && (currPipe.getBlockPos().equals(this.getDestPipe()) || !myPos.equals(this.startInventory))) {
|
||||
// we're done with the current pipe, so switch to the next one
|
||||
currPipe.getItems().remove(this);
|
||||
PipeBlockEntity next = this.getNextTile(currPipe, true);
|
||||
var next = this.getNextTile(currPipe, true);
|
||||
if (next == null) {
|
||||
if (!currPipe.getWorld().isRemote) {
|
||||
if (currPipe.getPos().equals(this.getDestPipe())) {
|
||||
// ..or store in our destination container if we reached our destination
|
||||
if (!currPipe.getLevel().isClientSide) {
|
||||
if (currPipe.getBlockPos().equals(this.getDestPipe())) {
|
||||
// ...or store in our destination container if we reached our destination
|
||||
this.stack = this.store(currPipe);
|
||||
if (!this.stack.isEmpty())
|
||||
this.onPathObstructed(currPipe, true);
|
||||
|
@ -130,29 +126,29 @@ public class PipeItem implements IPipeItem {
|
|||
currPipe = next;
|
||||
}
|
||||
} else {
|
||||
double dist = Vector3d.copy(this.currGoalPos).squareDistanceTo(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F);
|
||||
var dist = (this.currGoalPos).distSqr(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F, false);
|
||||
if (dist < currSpeed * currSpeed) {
|
||||
// we're past the start of the pipe, so move to the center of the next pipe
|
||||
BlockPos nextPos;
|
||||
PipeBlockEntity next = this.getNextTile(currPipe, false);
|
||||
var next = this.getNextTile(currPipe, false);
|
||||
if (next == null || next == currPipe) {
|
||||
if (currPipe.getPos().equals(this.getDestPipe())) {
|
||||
if (currPipe.getBlockPos().equals(this.getDestPipe())) {
|
||||
nextPos = this.destInventory;
|
||||
} else {
|
||||
currPipe.getItems().remove(this);
|
||||
if (!currPipe.getWorld().isRemote)
|
||||
if (!currPipe.getLevel().isClientSide)
|
||||
this.onPathObstructed(currPipe, false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
nextPos = next.getPos();
|
||||
nextPos = next.getBlockPos();
|
||||
}
|
||||
float tolerance = 0.001F;
|
||||
var tolerance = 0.001F;
|
||||
if (dist >= tolerance * tolerance) {
|
||||
// when going around corners, we want to move right up to the corner
|
||||
Vector3d motion = new Vector3d(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ);
|
||||
Vector3d diff = new Vector3d(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z);
|
||||
if (motion.crossProduct(diff).length() >= tolerance) {
|
||||
var motion = new Vec3(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ);
|
||||
var diff = new Vec3(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z);
|
||||
if (motion.cross(diff).length() >= tolerance) {
|
||||
currSpeed = (float) Math.sqrt(dist);
|
||||
} else {
|
||||
// we're not going around a corner, so continue
|
||||
|
@ -169,7 +165,7 @@ public class PipeItem implements IPipeItem {
|
|||
this.lastY = this.y;
|
||||
this.lastZ = this.z;
|
||||
|
||||
Vector3d dist = new Vector3d(this.currGoalPos.getX() + 0.5F - this.x, this.currGoalPos.getY() + 0.5F - this.y, this.currGoalPos.getZ() + 0.5F - this.z);
|
||||
var dist = new Vec3(this.currGoalPos.getX() + 0.5F - this.x, this.currGoalPos.getY() + 0.5F - this.y, this.currGoalPos.getZ() + 0.5F - this.z);
|
||||
dist = dist.normalize();
|
||||
this.x += dist.x * currSpeed;
|
||||
this.y += dist.y * currSpeed;
|
||||
|
@ -178,37 +174,37 @@ public class PipeItem implements IPipeItem {
|
|||
}
|
||||
|
||||
protected void onPathObstructed(PipeBlockEntity currPipe, boolean tryReturn) {
|
||||
if (currPipe.getWorld().isRemote)
|
||||
if (currPipe.getLevel().isClientSide)
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(currPipe.getWorld());
|
||||
var network = PipeNetwork.get(currPipe.getLevel());
|
||||
if (tryReturn) {
|
||||
// first time: we try to return to our input chest
|
||||
if (!this.retryOnObstruction && network.routeItemToLocation(currPipe.getPos(), this.destInventory, this.getStartPipe(), this.startInventory, this.stack, speed -> this)) {
|
||||
if (!this.retryOnObstruction && network.routeItemToLocation(currPipe.getBlockPos(), this.destInventory, this.getStartPipe(), this.startInventory, this.stack, speed -> this)) {
|
||||
this.retryOnObstruction = true;
|
||||
return;
|
||||
}
|
||||
// second time: we arrived at our input chest, it is full, so we try to find a different goal location
|
||||
ItemStack remain = network.routeItem(currPipe.getPos(), this.destInventory, this.stack, (stack, speed) -> this, false);
|
||||
var remain = network.routeItem(currPipe.getBlockPos(), this.destInventory, this.stack, (stack, speed) -> this, false);
|
||||
if (!remain.isEmpty())
|
||||
this.drop(currPipe.getWorld(), remain.copy());
|
||||
this.drop(currPipe.getLevel(), remain.copy());
|
||||
} else {
|
||||
// if all re-routing attempts fail, we drop
|
||||
this.drop(currPipe.getWorld(), this.stack);
|
||||
this.drop(currPipe.getLevel(), this.stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(World world, ItemStack stack) {
|
||||
ItemEntity item = new ItemEntity(world, this.x, this.y, this.z, stack.copy());
|
||||
item.world.addEntity(item);
|
||||
public void drop(Level world, ItemStack stack) {
|
||||
var item = new ItemEntity(world, this.x, this.y, this.z, stack.copy());
|
||||
item.level.addFreshEntity(item);
|
||||
}
|
||||
|
||||
protected ItemStack store(PipeBlockEntity currPipe) {
|
||||
Direction dir = Utility.getDirectionFromOffset(this.destInventory, this.getDestPipe());
|
||||
IPipeConnectable connectable = currPipe.getPipeConnectable(dir);
|
||||
var dir = Utility.getDirectionFromOffset(this.destInventory, this.getDestPipe());
|
||||
var connectable = currPipe.getPipeConnectable(dir);
|
||||
if (connectable != null)
|
||||
return connectable.insertItem(currPipe.getPos(), dir, this.stack, false);
|
||||
IItemHandler handler = currPipe.getItemHandler(dir);
|
||||
return connectable.insertItem(currPipe.getBlockPos(), dir, this.stack, false);
|
||||
var handler = currPipe.getItemHandler(dir);
|
||||
if (handler != null)
|
||||
return ItemHandlerHelper.insertItemStacked(handler, this.stack, false);
|
||||
return this.stack;
|
||||
|
@ -217,10 +213,10 @@ public class PipeItem implements IPipeItem {
|
|||
protected PipeBlockEntity getNextTile(PipeBlockEntity currPipe, boolean progress) {
|
||||
if (this.path.size() <= this.currentTile + 1)
|
||||
return null;
|
||||
BlockPos pos = this.path.get(this.currentTile + 1);
|
||||
var pos = this.path.get(this.currentTile + 1);
|
||||
if (progress)
|
||||
this.currentTile++;
|
||||
PipeNetwork network = PipeNetwork.get(currPipe.getWorld());
|
||||
var network = PipeNetwork.get(currPipe.getLevel());
|
||||
return network.getPipe(pos);
|
||||
}
|
||||
|
||||
|
@ -245,41 +241,41 @@ public class PipeItem implements IPipeItem {
|
|||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
var nbt = new CompoundTag();
|
||||
nbt.putString("type", this.type.toString());
|
||||
nbt.put("stack", this.stack.serializeNBT());
|
||||
nbt.putFloat("speed", this.speed);
|
||||
nbt.put("start_inv", NBTUtil.writeBlockPos(this.startInventory));
|
||||
nbt.put("dest_inv", NBTUtil.writeBlockPos(this.destInventory));
|
||||
nbt.put("curr_goal", NBTUtil.writeBlockPos(this.currGoalPos));
|
||||
nbt.put("start_inv", NbtUtils.writeBlockPos(this.startInventory));
|
||||
nbt.put("dest_inv", NbtUtils.writeBlockPos(this.destInventory));
|
||||
nbt.put("curr_goal", NbtUtils.writeBlockPos(this.currGoalPos));
|
||||
nbt.putBoolean("drop_on_obstruction", this.retryOnObstruction);
|
||||
nbt.putInt("tile", this.currentTile);
|
||||
nbt.putFloat("x", this.x);
|
||||
nbt.putFloat("y", this.y);
|
||||
nbt.putFloat("z", this.z);
|
||||
ListTag list = new ListTag();
|
||||
for (BlockPos pos : this.path)
|
||||
list.add(NBTUtil.writeBlockPos(pos));
|
||||
var list = new ListTag();
|
||||
for (var pos : this.path)
|
||||
list.add(NbtUtils.writeBlockPos(pos));
|
||||
nbt.put("path", list);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.stack = ItemStack.read(nbt.getCompound("stack"));
|
||||
this.stack = ItemStack.of(nbt.getCompound("stack"));
|
||||
this.speed = nbt.getFloat("speed");
|
||||
this.startInventory = NBTUtil.readBlockPos(nbt.getCompound("start_inv"));
|
||||
this.destInventory = NBTUtil.readBlockPos(nbt.getCompound("dest_inv"));
|
||||
this.currGoalPos = NBTUtil.readBlockPos(nbt.getCompound("curr_goal"));
|
||||
this.startInventory = NbtUtils.readBlockPos(nbt.getCompound("start_inv"));
|
||||
this.destInventory = NbtUtils.readBlockPos(nbt.getCompound("dest_inv"));
|
||||
this.currGoalPos = NbtUtils.readBlockPos(nbt.getCompound("curr_goal"));
|
||||
this.retryOnObstruction = nbt.getBoolean("drop_on_obstruction");
|
||||
this.currentTile = nbt.getInt("tile");
|
||||
this.x = nbt.getFloat("x");
|
||||
this.y = nbt.getFloat("y");
|
||||
this.z = nbt.getFloat("z");
|
||||
this.path.clear();
|
||||
ListTag list = nbt.getList("path", Constants.NBT.TAG_COMPOUND);
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
this.path.add(NBTUtil.readBlockPos(list.getCompound(i)));
|
||||
var list = nbt.getList("path", Tag.TAG_COMPOUND);
|
||||
for (var i = 0; i < list.size(); i++)
|
||||
this.path.add(NbtUtils.readBlockPos(list.getCompound(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -289,40 +285,40 @@ public class PipeItem implements IPipeItem {
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void render(PipeBlockEntity tile, MatrixStack matrixStack, Random random, float partialTicks, int light, int overlay, IRenderTypeBuffer buffer) {
|
||||
public void render(PipeBlockEntity tile, PoseStack matrixStack, Random random, float partialTicks, int light, int overlay, MultiBufferSource source) {
|
||||
matrixStack.translate(
|
||||
MathHelper.lerp(partialTicks, this.lastX, this.x),
|
||||
MathHelper.lerp(partialTicks, this.lastY, this.y),
|
||||
MathHelper.lerp(partialTicks, this.lastZ, this.z));
|
||||
Mth.lerp(partialTicks, this.lastX, this.x),
|
||||
Mth.lerp(partialTicks, this.lastY, this.y),
|
||||
Mth.lerp(partialTicks, this.lastZ, this.z));
|
||||
|
||||
if (this.stack.getItem() instanceof BlockItem) {
|
||||
float scale = 0.7F;
|
||||
var scale = 0.7F;
|
||||
matrixStack.scale(scale, scale, scale);
|
||||
matrixStack.translate(0, -0.2F, 0);
|
||||
} else {
|
||||
float scale = 0.45F;
|
||||
var scale = 0.45F;
|
||||
matrixStack.scale(scale, scale, scale);
|
||||
matrixStack.translate(0, -0.1F, 0);
|
||||
}
|
||||
|
||||
random.setSeed(Item.getIdFromItem(this.stack.getItem()) + this.stack.getDamage());
|
||||
int amount = this.getModelCount();
|
||||
random.setSeed(Item.getId(this.stack.getItem()) + this.stack.getDamageValue());
|
||||
var amount = this.getModelCount();
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
matrixStack.push();
|
||||
for (var i = 0; i < amount; i++) {
|
||||
matrixStack.pushPose();
|
||||
if (amount > 1) {
|
||||
matrixStack.translate(
|
||||
(random.nextFloat() * 2.0F - 1.0F) * 0.25F * 0.5F,
|
||||
(random.nextFloat() * 2.0F - 1.0F) * 0.25F * 0.5F,
|
||||
(random.nextFloat() * 2.0F - 1.0F) * 0.25F * 0.5F);
|
||||
}
|
||||
Minecraft.getInstance().getItemRenderer().renderItem(this.stack, ItemCameraTransforms.TransformType.GROUND, light, overlay, matrixStack, buffer);
|
||||
matrixStack.pop();
|
||||
Minecraft.getInstance().getItemRenderer().renderStatic(this.stack, ItemTransforms.TransformType.GROUND, light, overlay, matrixStack, source, 0);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getModelCount() {
|
||||
int i = 1;
|
||||
var i = 1;
|
||||
if (this.stack.getCount() > 48) {
|
||||
i = 5;
|
||||
} else if (this.stack.getCount() > 32) {
|
||||
|
@ -336,32 +332,32 @@ public class PipeItem implements IPipeItem {
|
|||
}
|
||||
|
||||
protected static List<BlockPos> compilePath(GraphPath<BlockPos, NetworkEdge> path) {
|
||||
Graph<BlockPos, NetworkEdge> graph = path.getGraph();
|
||||
var graph = path.getGraph();
|
||||
List<BlockPos> ret = new ArrayList<>();
|
||||
List<BlockPos> nodes = path.getVertexList();
|
||||
var nodes = path.getVertexList();
|
||||
if (nodes.size() == 1) {
|
||||
// add the single pipe twice if there's only one
|
||||
// this is a dirty hack but it works fine so eh
|
||||
for (int i = 0; i < 2; i++)
|
||||
// this is a dirty hack, but it works fine so eh
|
||||
for (var i = 0; i < 2; i++)
|
||||
ret.add(nodes.get(0));
|
||||
return ret;
|
||||
}
|
||||
for (int i = 0; i < nodes.size() - 1; i++) {
|
||||
BlockPos first = nodes.get(i);
|
||||
BlockPos second = nodes.get(i + 1);
|
||||
NetworkEdge edge = graph.getEdge(first, second);
|
||||
Consumer<Integer> add = j -> {
|
||||
BlockPos pos = edge.pipes.get(j);
|
||||
for (var i = 0; i < nodes.size() - 1; i++) {
|
||||
var first = nodes.get(i);
|
||||
var second = nodes.get(i + 1);
|
||||
var edge = graph.getEdge(first, second);
|
||||
var add = (Consumer<Integer>) j -> {
|
||||
var pos = edge.pipes.get(j);
|
||||
if (!ret.contains(pos))
|
||||
ret.add(pos);
|
||||
};
|
||||
// if the edge is the other way around, we need to loop through tiles
|
||||
// the other way also
|
||||
if (!graph.getEdgeSource(edge).equals(first)) {
|
||||
for (int j = edge.pipes.size() - 1; j >= 0; j--)
|
||||
for (var j = edge.pipes.size() - 1; j >= 0; j--)
|
||||
add.accept(j);
|
||||
} else {
|
||||
for (int j = 0; j < edge.pipes.size(); j++)
|
||||
for (var j = 0; j < edge.pipes.size(); j++)
|
||||
add.accept(j);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package de.ellpeck.prettypipes.packets;
|
|||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
|
@ -13,11 +12,6 @@ import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
|||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -25,12 +19,6 @@ import net.minecraft.world.MenuProvider;
|
|||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import org.apache.logging.log4j.util.TriConsumer;
|
||||
|
@ -55,7 +43,7 @@ public class PacketButton {
|
|||
}
|
||||
|
||||
public static PacketButton fromBytes(FriendlyByteBuf buf) {
|
||||
PacketButton packet = new PacketButton();
|
||||
var packet = new PacketButton();
|
||||
packet.pos = buf.readBlockPos();
|
||||
packet.result = ButtonResult.values()[buf.readByte()];
|
||||
packet.data = buf.readVarIntArray();
|
||||
|
@ -87,11 +75,11 @@ public class PacketButton {
|
|||
|
||||
public enum ButtonResult {
|
||||
PIPE_TAB((pos, data, player) -> {
|
||||
PipeBlockEntity tile = Utility.getBlockEntity(PipeBlockEntity.class, player.level, pos);
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, player.level, pos);
|
||||
if (data[0] < 0) {
|
||||
NetworkHooks.openGui((ServerPlayer) player, tile, pos);
|
||||
} else {
|
||||
ItemStack stack = tile.modules.getStackInSlot(data[0]);
|
||||
var stack = tile.modules.getStackInSlot(data[0]);
|
||||
NetworkHooks.openGui((ServerPlayer) player, new MenuProvider() {
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
|
@ -111,28 +99,28 @@ public class PacketButton {
|
|||
}
|
||||
}),
|
||||
FILTER_CHANGE((pos, data, player) -> {
|
||||
IFilteredContainer container = (IFilteredContainer) player.containerMenu;
|
||||
ItemFilter filter = container.getFilter();
|
||||
var container = (IFilteredContainer) player.containerMenu;
|
||||
var filter = container.getFilter();
|
||||
filter.onButtonPacket(data[0]);
|
||||
}),
|
||||
STACK_SIZE_MODULE_BUTTON((pos, data, player) -> {
|
||||
AbstractPipeContainer<?> container = (AbstractPipeContainer<?>) player.containerMenu;
|
||||
var container = (AbstractPipeContainer<?>) player.containerMenu;
|
||||
StackSizeModuleItem.setLimitToMaxStackSize(container.moduleStack, !StackSizeModuleItem.getLimitToMaxStackSize(container.moduleStack));
|
||||
}),
|
||||
STACK_SIZE_AMOUNT((pos, data, player) -> {
|
||||
AbstractPipeContainer<?> container = (AbstractPipeContainer<?>) player.containerMenu;
|
||||
var container = (AbstractPipeContainer<?>) player.containerMenu;
|
||||
StackSizeModuleItem.setMaxStackSize(container.moduleStack, data[0]);
|
||||
}),
|
||||
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
|
||||
CraftingTerminalBlockEntity tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos);
|
||||
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos);
|
||||
tile.requestCraftingItems(player, data[0]);
|
||||
}),
|
||||
CANCEL_CRAFTING((pos, data, player) -> {
|
||||
ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos);
|
||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos);
|
||||
tile.cancelCrafting();
|
||||
}),
|
||||
TAG_FILTER((pos, data, player) -> {
|
||||
FilterModifierModuleContainer container = (FilterModifierModuleContainer) player.containerMenu;
|
||||
var container = (FilterModifierModuleContainer) player.containerMenu;
|
||||
FilterModifierModuleItem.setFilterTag(container.moduleStack, container.getTags().get(data[0]));
|
||||
});
|
||||
|
||||
|
|
|
@ -3,13 +3,9 @@ package de.ellpeck.prettypipes.packets;
|
|||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.ellpeck.prettypipes.pipe;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.network.NetworkEdge;
|
||||
import de.ellpeck.prettypipes.network.PipeItem;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -41,15 +42,11 @@ public interface IPipeItem extends INBTSerializable<CompoundTag> {
|
|||
int getItemsOnTheWay(BlockPos goalInv);
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
void render(PipeBlockEntity tile, PoseStack matrixStack, Random random, float partialTicks, int light, int overlay);
|
||||
void render(PipeBlockEntity tile, PoseStack matrixStack, Random random, float partialTicks, int light, int overlay, MultiBufferSource source);
|
||||
|
||||
static IPipeItem load(CompoundTag nbt) {
|
||||
// TODO legacy compat, remove eventually
|
||||
if (!nbt.contains("type"))
|
||||
nbt.putString("type", PipeItem.TYPE.toString());
|
||||
|
||||
ResourceLocation type = new ResourceLocation(nbt.getString("type"));
|
||||
BiFunction<ResourceLocation, CompoundTag, IPipeItem> func = TYPES.get(type);
|
||||
var type = new ResourceLocation(nbt.getString("type"));
|
||||
var func = TYPES.get(type);
|
||||
return func != null ? func.apply(type, nbt) : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,7 +289,7 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new PipeBlockEntity(Registry.pipeTileEntity, pos, state);
|
||||
return new PipeBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,7 +30,6 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
@ -78,8 +77,8 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
private final LazyOptional<PipeBlockEntity> lazyThis = LazyOptional.of(() -> this);
|
||||
private final Lazy<Integer> workRandomizer = Lazy.of(() -> this.level.random.nextInt(200));
|
||||
|
||||
public PipeBlockEntity(BlockEntityType<?> type, BlockPos p_155229_, BlockState p_155230_) {
|
||||
super(type, p_155229_, p_155230_);
|
||||
public PipeBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Registry.pipeBlockEntity, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.ellpeck.prettypipes.pipe;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer;
|
||||
|
@ -13,6 +14,9 @@ public class PipeRenderer implements BlockEntityRenderer<PipeBlockEntity> {
|
|||
|
||||
private final Random random = new Random();
|
||||
|
||||
public PipeRenderer(BlockEntityRendererProvider.Context ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PipeBlockEntity tile, float partialTicks, PoseStack matrixStack, MultiBufferSource source, int light, int overlay) {
|
||||
if (!tile.getItems().isEmpty()) {
|
||||
|
@ -21,7 +25,7 @@ public class PipeRenderer implements BlockEntityRenderer<PipeBlockEntity> {
|
|||
matrixStack.translate(-tilePos.getX(), -tilePos.getY(), -tilePos.getZ());
|
||||
for (IPipeItem item : tile.getItems()) {
|
||||
matrixStack.pushPose();
|
||||
item.render(tile, matrixStack, this.random, partialTicks, light, overlay);
|
||||
item.render(tile, matrixStack, this.random, partialTicks, light, overlay, source);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
matrixStack.popPose();
|
||||
|
|
|
@ -14,7 +14,7 @@ public class RedstoneModuleItem extends ModuleItem {
|
|||
|
||||
@Override
|
||||
public boolean canPipeWork(ItemStack module, PipeBlockEntity tile) {
|
||||
return !tile.getWorld().isBlockPowered(tile.getPos());
|
||||
return !tile.getLevel().hasNeighborSignal(tile.getBlockPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,8 +3,8 @@ package de.ellpeck.prettypipes.pipe.modules;
|
|||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class SortingModuleItem extends ModuleItem {
|
|||
module.getOrCreateTag().putInt("last", next);
|
||||
return next % nodes.size();
|
||||
case RANDOM:
|
||||
return tile.getWorld().rand.nextInt(nodes.size());
|
||||
return tile.getLevel().random.nextInt(nodes.size());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package de.ellpeck.prettypipes.pipe.modules.craft;
|
|||
|
||||
import de.ellpeck.prettypipes.misc.FilterSlot;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModuleItem> {
|
||||
|
@ -13,7 +13,7 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
|||
public ItemStackHandler output;
|
||||
public boolean modified;
|
||||
|
||||
public CraftingModuleContainer(ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public CraftingModuleContainer(MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,11 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
|||
for (int i = 0; i < this.input.getSlots(); i++) {
|
||||
this.addSlot(new FilterSlot(this.input, i, (176 - this.module.inputSlots * 18) / 2 + 1 + i % 9 * 18, 17 + 32 + i / 9 * 18, false) {
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
super.onSlotChanged();
|
||||
public void setChanged() {
|
||||
super.setChanged();
|
||||
CraftingModuleContainer.this.modified = true;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -34,8 +35,8 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
|||
for (int i = 0; i < this.output.getSlots(); i++) {
|
||||
this.addSlot(new FilterSlot(this.output, i, (176 - this.module.outputSlots * 18) / 2 + 1 + i % 9 * 18, 85 + i / 9 * 18, false) {
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
super.onSlotChanged();
|
||||
public void setChanged() {
|
||||
super.setChanged();
|
||||
CraftingModuleContainer.this.modified = true;
|
||||
}
|
||||
});
|
||||
|
@ -43,8 +44,8 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
if (this.modified)
|
||||
this.module.save(this.input, this.output, this.moduleStack);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.craft;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class CraftingModuleGui extends AbstractPipeGui<CraftingModuleContainer> {
|
||||
public CraftingModuleGui(CraftingModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public CraftingModuleGui(CraftingModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(matrix, partialTicks, mouseX, mouseY);
|
||||
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
this.blit(matrix, this.guiLeft + 176 / 2 - 16 / 2, this.guiTop + 32 + 18 * 2, 176, 80, 16, 16);
|
||||
protected void renderBg(PoseStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
super.renderBg(matrix, partialTicks, mouseX, mouseY);
|
||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
this.blit(matrix, this.leftPos + 176 / 2 - 16 / 2, this.topPos + 32 + 18 * 2, 176, 80, 16, 16);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,19 +6,17 @@ import de.ellpeck.prettypipes.items.ModuleItem;
|
|||
import de.ellpeck.prettypipes.items.ModuleTier;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||
import de.ellpeck.prettypipes.network.NetworkLock;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
|
@ -51,8 +49,8 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new CraftingModuleContainer(Registry.craftingModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new CraftingModuleContainer(Registry.craftingModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,23 +67,23 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
public void tick(ItemStack module, PipeBlockEntity tile) {
|
||||
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
// process crafting ingredient requests
|
||||
if (!tile.craftIngredientRequests.isEmpty()) {
|
||||
network.startProfile("crafting_ingredients");
|
||||
NetworkLock request = tile.craftIngredientRequests.peek();
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
Pair<BlockPos, ItemStack> dest = tile.getAvailableDestination(request.stack, true, true);
|
||||
var request = tile.craftIngredientRequests.peek();
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var dest = tile.getAvailableDestination(request.stack, true, true);
|
||||
if (dest != null) {
|
||||
ItemStack requestRemain = network.requestExistingItem(request.location, tile.getPos(), dest.getLeft(), request, dest.getRight(), equalityTypes);
|
||||
var requestRemain = network.requestExistingItem(request.location, tile.getBlockPos(), dest.getLeft(), request, dest.getRight(), equalityTypes);
|
||||
network.resolveNetworkLock(request);
|
||||
tile.craftIngredientRequests.remove();
|
||||
|
||||
// if we couldn't fit all items into the destination, create another request for the rest
|
||||
ItemStack remain = request.stack.copy();
|
||||
var remain = request.stack.copy();
|
||||
remain.shrink(dest.getRight().getCount() - requestRemain.getCount());
|
||||
if (!remain.isEmpty()) {
|
||||
NetworkLock remainRequest = new NetworkLock(request.location, remain);
|
||||
var remainRequest = new NetworkLock(request.location, remain);
|
||||
tile.craftIngredientRequests.add(remainRequest);
|
||||
network.createNetworkLock(remainRequest);
|
||||
}
|
||||
|
@ -95,17 +93,17 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
// pull requested crafting results from the network once they are stored
|
||||
if (!tile.craftResultRequests.isEmpty()) {
|
||||
network.startProfile("crafting_results");
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(tile.getPos());
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
for (Pair<BlockPos, ItemStack> request : tile.craftResultRequests) {
|
||||
ItemStack remain = request.getRight().copy();
|
||||
PipeBlockEntity destPipe = network.getPipe(request.getLeft());
|
||||
var items = network.getOrderedNetworkItems(tile.getBlockPos());
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
for (var request : tile.craftResultRequests) {
|
||||
var remain = request.getRight().copy();
|
||||
var destPipe = network.getPipe(request.getLeft());
|
||||
if (destPipe != null) {
|
||||
Pair<BlockPos, ItemStack> dest = destPipe.getAvailableDestinationOrConnectable(remain, true, true);
|
||||
var dest = destPipe.getAvailableDestinationOrConnectable(remain, true, true);
|
||||
if (dest == null)
|
||||
continue;
|
||||
for (NetworkLocation item : items) {
|
||||
ItemStack requestRemain = network.requestExistingItem(item, request.getLeft(), dest.getLeft(), null, dest.getRight(), equalityTypes);
|
||||
for (var item : items) {
|
||||
var requestRemain = network.requestExistingItem(item, request.getLeft(), dest.getLeft(), null, dest.getRight(), equalityTypes);
|
||||
remain.shrink(dest.getRight().getCount() - requestRemain.getCount());
|
||||
if (remain.isEmpty())
|
||||
break;
|
||||
|
@ -127,9 +125,9 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
@Override
|
||||
public List<ItemStack> getAllCraftables(ItemStack module, PipeBlockEntity tile) {
|
||||
List<ItemStack> ret = new ArrayList<>();
|
||||
ItemStackHandler output = this.getOutput(module);
|
||||
for (int i = 0; i < output.getSlots(); i++) {
|
||||
ItemStack stack = output.getStackInSlot(i);
|
||||
var output = this.getOutput(module);
|
||||
for (var i = 0; i < output.getSlots(); i++) {
|
||||
var stack = output.getStackInSlot(i);
|
||||
if (!stack.isEmpty())
|
||||
ret.add(stack);
|
||||
}
|
||||
|
@ -138,18 +136,18 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
|
||||
@Override
|
||||
public int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(tile.getPos());
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
ItemStackHandler input = this.getInput(module);
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
var items = network.getOrderedNetworkItems(tile.getBlockPos());
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var input = this.getInput(module);
|
||||
|
||||
int craftable = 0;
|
||||
ItemStackHandler output = this.getOutput(module);
|
||||
for (int i = 0; i < output.getSlots(); i++) {
|
||||
ItemStack out = output.getStackInSlot(i);
|
||||
var craftable = 0;
|
||||
var output = this.getOutput(module);
|
||||
for (var i = 0; i < output.getSlots(); i++) {
|
||||
var out = output.getStackInSlot(i);
|
||||
if (!out.isEmpty() && ItemEquality.compareItems(out, stack, equalityTypes)) {
|
||||
// figure out how many crafting operations we can actually do with the input items we have in the network
|
||||
int availableCrafts = CraftingTerminalBlockEntity.getAvailableCrafts(tile, input.getSlots(), input::getStackInSlot, k -> true, s -> items, unavailableConsumer, addDependency(dependencyChain, module), equalityTypes);
|
||||
var availableCrafts = CraftingTerminalBlockEntity.getAvailableCrafts(tile, input.getSlots(), input::getStackInSlot, k -> true, s -> items, unavailableConsumer, addDependency(dependencyChain, module), equalityTypes);
|
||||
if (availableCrafts > 0)
|
||||
craftable += out.getCount() * availableCrafts;
|
||||
}
|
||||
|
@ -160,33 +158,33 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
@Override
|
||||
public ItemStack craft(ItemStack module, PipeBlockEntity tile, BlockPos destPipe, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
|
||||
// check if we can craft the required amount of items
|
||||
int craftableAmount = this.getCraftableAmount(module, tile, unavailableConsumer, stack, dependencyChain);
|
||||
var craftableAmount = this.getCraftableAmount(module, tile, unavailableConsumer, stack, dependencyChain);
|
||||
if (craftableAmount <= 0)
|
||||
return stack;
|
||||
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(tile.getPos());
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
var items = network.getOrderedNetworkItems(tile.getBlockPos());
|
||||
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
int resultAmount = this.getResultAmountPerCraft(module, stack, equalityTypes);
|
||||
int requiredCrafts = MathHelper.ceil(stack.getCount() / (float) resultAmount);
|
||||
int toCraft = Math.min(craftableAmount, requiredCrafts);
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var resultAmount = this.getResultAmountPerCraft(module, stack, equalityTypes);
|
||||
var requiredCrafts = Mth.ceil(stack.getCount() / (float) resultAmount);
|
||||
var toCraft = Math.min(craftableAmount, requiredCrafts);
|
||||
|
||||
ItemStackHandler input = this.getInput(module);
|
||||
for (int i = 0; i < input.getSlots(); i++) {
|
||||
ItemStack in = input.getStackInSlot(i);
|
||||
var input = this.getInput(module);
|
||||
for (var i = 0; i < input.getSlots(); i++) {
|
||||
var in = input.getStackInSlot(i);
|
||||
if (in.isEmpty())
|
||||
continue;
|
||||
ItemStack copy = in.copy();
|
||||
var copy = in.copy();
|
||||
copy.setCount(in.getCount() * toCraft);
|
||||
Pair<List<NetworkLock>, ItemStack> ret = ItemTerminalBlockEntity.requestItemLater(tile.getWorld(), tile.getPos(), items, unavailableConsumer, copy, addDependency(dependencyChain, module), equalityTypes);
|
||||
var ret = ItemTerminalBlockEntity.requestItemLater(tile.getLevel(), tile.getBlockPos(), items, unavailableConsumer, copy, addDependency(dependencyChain, module), equalityTypes);
|
||||
tile.craftIngredientRequests.addAll(ret.getLeft());
|
||||
}
|
||||
|
||||
ItemStack remain = stack.copy();
|
||||
var remain = stack.copy();
|
||||
remain.shrink(resultAmount * toCraft);
|
||||
|
||||
ItemStack result = stack.copy();
|
||||
var result = stack.copy();
|
||||
result.shrink(remain.getCount());
|
||||
tile.craftResultRequests.add(Pair.of(destPipe, result));
|
||||
|
||||
|
@ -194,21 +192,21 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
public ItemStackHandler getInput(ItemStack module) {
|
||||
ItemStackHandler handler = new ItemStackHandler(this.inputSlots);
|
||||
var handler = new ItemStackHandler(this.inputSlots);
|
||||
if (module.hasTag())
|
||||
handler.deserializeNBT(module.getTag().getCompound("input"));
|
||||
return handler;
|
||||
}
|
||||
|
||||
public ItemStackHandler getOutput(ItemStack module) {
|
||||
ItemStackHandler handler = new ItemStackHandler(this.outputSlots);
|
||||
var handler = new ItemStackHandler(this.outputSlots);
|
||||
if (module.hasTag())
|
||||
handler.deserializeNBT(module.getTag().getCompound("output"));
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void save(ItemStackHandler input, ItemStackHandler output, ItemStack module) {
|
||||
CompoundTag tag = module.getOrCreateTag();
|
||||
var tag = module.getOrCreateTag();
|
||||
if (input != null)
|
||||
tag.put("input", input.serializeNBT());
|
||||
if (output != null)
|
||||
|
@ -216,10 +214,10 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
private int getResultAmountPerCraft(ItemStack module, ItemStack stack, ItemEquality... equalityTypes) {
|
||||
ItemStackHandler output = this.getOutput(module);
|
||||
int resultAmount = 0;
|
||||
for (int i = 0; i < output.getSlots(); i++) {
|
||||
ItemStack out = output.getStackInSlot(i);
|
||||
var output = this.getOutput(module);
|
||||
var resultAmount = 0;
|
||||
for (var i = 0; i < output.getSlots(); i++) {
|
||||
var out = output.getStackInSlot(i);
|
||||
if (ItemEquality.compareItems(stack, out, equalityTypes))
|
||||
resultAmount += out.getCount();
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.extraction;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class ExtractionModuleGui extends AbstractPipeGui<ExtractionModuleContainer> {
|
||||
public ExtractionModuleGui(ExtractionModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public ExtractionModuleGui(ExtractionModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
for (Widget widget : this.container.filter.getButtons(this, this.guiLeft + 7, this.guiTop + 17 + 32 + 20))
|
||||
this.addButton(widget);
|
||||
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
|
||||
this.addRenderableWidget(widget);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,16 @@ package de.ellpeck.prettypipes.pipe.modules.filter;
|
|||
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
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 net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
|
||||
public class FilterIncreaseModuleContainer extends AbstractPipeContainer<FilterIncreaseModuleItem> implements ItemFilter.IFilteredContainer {
|
||||
|
||||
public ItemFilter filter;
|
||||
|
||||
public FilterIncreaseModuleContainer(ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public FilterIncreaseModuleContainer(MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@ public class FilterIncreaseModuleContainer extends AbstractPipeContainer<FilterI
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
this.filter.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.filter;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class FilterIncreaseModuleGui extends AbstractPipeGui<FilterIncreaseModuleContainer> {
|
||||
public FilterIncreaseModuleGui(FilterIncreaseModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public FilterIncreaseModuleGui(FilterIncreaseModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import de.ellpeck.prettypipes.items.ModuleItem;
|
|||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class FilterIncreaseModuleItem extends ModuleItem {
|
||||
|
@ -28,8 +28,8 @@ public class FilterIncreaseModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new FilterIncreaseModuleContainer(Registry.filterIncreaseModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new FilterIncreaseModuleContainer(Registry.filterIncreaseModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,10 +3,10 @@ package de.ellpeck.prettypipes.pipe.modules.insertion;
|
|||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
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 net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
|
|||
|
||||
public ItemFilter filter;
|
||||
|
||||
public FilterModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public FilterModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
this.filter.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.insertion;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class FilterModuleGui extends AbstractPipeGui<FilterModuleContainer> {
|
||||
public FilterModuleGui(FilterModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public FilterModuleGui(FilterModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
for (Widget widget : this.container.filter.getButtons(this, this.guiLeft + 7, this.guiTop + 17 + 32 + 18 * MathHelper.ceil(this.container.filter.getSlots() / 9F) + 2))
|
||||
this.addButton(widget);
|
||||
for (AbstractWidget widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 18 * Mth.ceil(this.menu.filter.getSlots() / 9F) + 2))
|
||||
this.addRenderableWidget(widget);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ import de.ellpeck.prettypipes.items.ModuleTier;
|
|||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class FilterModuleItem extends ModuleItem {
|
||||
|
@ -39,8 +39,8 @@ public class FilterModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,11 +2,11 @@ package de.ellpeck.prettypipes.pipe.modules.modifier;
|
|||
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashSet;
|
||||
|
@ -16,7 +16,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterModifierModuleItem> {
|
||||
|
||||
public FilterModifierModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public FilterModifierModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,59 +1,60 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.modifier;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.audio.SimpleSound;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModuleContainer> {
|
||||
|
||||
private int scrollOffset;
|
||||
private boolean isScrolling;
|
||||
private List<ResourceLocation> tags;
|
||||
private final List<Tag> tagButtons = new ArrayList<>();
|
||||
|
||||
public FilterModifierModuleGui(FilterModifierModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
public FilterModifierModuleGui(FilterModifierModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(matrix, partialTicks, mouseX, mouseY);
|
||||
this.blit(matrix, this.guiLeft + 7, this.guiTop + 32 + 15, 0, 196, 162, 60);
|
||||
protected void renderBg(PoseStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
super.renderBg(matrix, partialTicks, mouseX, mouseY);
|
||||
this.blit(matrix, this.leftPos + 7, this.topPos + 32 + 15, 0, 196, 162, 60);
|
||||
|
||||
for (Tag tag : this.tagButtons)
|
||||
for (var tag : this.tagButtons)
|
||||
tag.draw(matrix, mouseX, mouseY);
|
||||
|
||||
if (this.tags.size() >= 6) {
|
||||
float percentage = this.scrollOffset / (float) (this.tags.size() - 5);
|
||||
this.blit(matrix, this.guiLeft + 156, this.guiTop + 32 + 16 + (int) (percentage * (58 - 15)), 232, 241, 12, 15);
|
||||
var percentage = this.scrollOffset / (float) (this.tags.size() - 5);
|
||||
this.blit(matrix, this.leftPos + 156, this.topPos + 32 + 16 + (int) (percentage * (58 - 15)), 232, 241, 12, 15);
|
||||
} else {
|
||||
this.blit(matrix, this.guiLeft + 156, this.guiTop + 32 + 16, 244, 241, 12, 15);
|
||||
this.blit(matrix, this.leftPos + 156, this.topPos + 32 + 16, 244, 241, 12, 15);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
this.tags = this.container.getTags();
|
||||
this.tags = this.menu.getTags();
|
||||
this.updateWidgets();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
for (Tag tag : this.tagButtons) {
|
||||
for (var tag : this.tagButtons) {
|
||||
if (tag.onClicked(mouseX, mouseY, button))
|
||||
return true;
|
||||
}
|
||||
if (button == 0 && mouseX >= this.guiLeft + 156 && this.guiTop + mouseY >= 32 + 16 && mouseX < this.guiLeft + 156 + 12 && mouseY < this.guiTop + 32 + 16 + 58) {
|
||||
if (button == 0 && mouseX >= this.leftPos + 156 && this.topPos + mouseY >= 32 + 16 && mouseX < this.leftPos + 156 + 12 && mouseY < this.topPos + 32 + 16 + 58) {
|
||||
this.isScrolling = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -70,8 +71,8 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int i, double j, double k) {
|
||||
if (this.isScrolling) {
|
||||
float percentage = MathHelper.clamp(((float) mouseY - (this.guiTop + 32 + 18)) / (58 - 15), 0, 1);
|
||||
int offset = (int) (percentage * (float) (this.tags.size() - 5));
|
||||
var percentage = Mth.clamp(((float) mouseY - (this.topPos + 32 + 18)) / (58 - 15), 0, 1);
|
||||
var offset = (int) (percentage * (float) (this.tags.size() - 5));
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -84,7 +85,7 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double scroll) {
|
||||
if (this.tags.size() >= 6) {
|
||||
int offset = MathHelper.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.tags.size() - 5);
|
||||
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.tags.size() - 5);
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -95,10 +96,10 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
|
||||
private void updateWidgets() {
|
||||
this.tagButtons.clear();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (var i = 0; i < 5; i++) {
|
||||
if (i >= this.tags.size())
|
||||
break;
|
||||
this.tagButtons.add(new Tag(this.tags.get(this.scrollOffset + i), this.guiLeft + 10, this.guiTop + 32 + 17 + i * 12));
|
||||
this.tagButtons.add(new Tag(this.tags.get(this.scrollOffset + i), this.leftPos + 10, this.topPos + 32 + 17 + i * 12));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,15 +115,15 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
this.y = y;
|
||||
}
|
||||
|
||||
private void draw(MatrixStack matrix, double mouseX, double mouseY) {
|
||||
int color = 4210752;
|
||||
String text = this.tag.toString();
|
||||
private void draw(PoseStack matrix, double mouseX, double mouseY) {
|
||||
var color = 4210752;
|
||||
var text = this.tag.toString();
|
||||
if (mouseX >= this.x && mouseY >= this.y && mouseX < this.x + 140 && mouseY < this.y + 12)
|
||||
color = 0xFFFFFF;
|
||||
if (this.tag.equals(FilterModifierModuleItem.getFilterTag(FilterModifierModuleGui.this.container.moduleStack)))
|
||||
text = TextFormatting.BOLD + text;
|
||||
FilterModifierModuleGui.this.font.drawString(matrix, text, this.x, this.y, color);
|
||||
FilterModifierModuleGui.this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
if (this.tag.equals(FilterModifierModuleItem.getFilterTag(FilterModifierModuleGui.this.menu.moduleStack)))
|
||||
text = ChatFormatting.BOLD + text;
|
||||
FilterModifierModuleGui.this.font.draw(matrix, text, this.x, this.y, color);
|
||||
FilterModifierModuleGui.this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
}
|
||||
|
||||
private boolean onClicked(double mouseX, double mouseY, int button) {
|
||||
|
@ -130,8 +131,8 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
return false;
|
||||
if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 140 || mouseY >= this.y + 12)
|
||||
return false;
|
||||
PacketButton.sendAndExecute(FilterModifierModuleGui.this.container.tile.getPos(), PacketButton.ButtonResult.TAG_FILTER, FilterModifierModuleGui.this.tags.indexOf(this.tag));
|
||||
FilterModifierModuleGui.this.getMinecraft().getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1));
|
||||
PacketButton.sendAndExecute(FilterModifierModuleGui.this.menu.tile.getBlockPos(), PacketButton.ButtonResult.TAG_FILTER, FilterModifierModuleGui.this.tags.indexOf(this.tag));
|
||||
FilterModifierModuleGui.this.getMinecraft().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,10 @@ import de.ellpeck.prettypipes.misc.ItemEquality;
|
|||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import joptsimple.internal.Strings;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class FilterModifierModuleItem extends ModuleItem {
|
||||
|
||||
|
@ -39,13 +33,8 @@ public class FilterModifierModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new FilterModifierModuleContainer(Registry.filterModifierModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new FilterModifierModuleContainer(Registry.filterModifierModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
public ItemEquality getEqualityType(ItemStack stack) {
|
||||
|
|
|
@ -3,10 +3,10 @@ package de.ellpeck.prettypipes.pipe.modules.retrieval;
|
|||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
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 net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalMod
|
|||
|
||||
public ItemFilter filter;
|
||||
|
||||
public RetrievalModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public RetrievalModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalMod
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
this.filter.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.retrieval;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class RetrievalModuleGui extends AbstractPipeGui<RetrievalModuleContainer> {
|
||||
public RetrievalModuleGui(RetrievalModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public RetrievalModuleGui(RetrievalModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
for (Widget widget : this.container.filter.getButtons(this, this.guiLeft + 7, this.guiTop + 17 + 32 + 20))
|
||||
this.addButton(widget);
|
||||
for (AbstractWidget widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
|
||||
this.addRenderableWidget(widget);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,14 @@ import de.ellpeck.prettypipes.misc.ItemFilter;
|
|||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public class RetrievalModuleItem extends ModuleItem {
|
||||
|
||||
private final int maxExtraction;
|
||||
private final int speed;
|
||||
private final boolean preventOversending;
|
||||
|
@ -33,7 +34,7 @@ public class RetrievalModuleItem extends ModuleItem {
|
|||
public void tick(ItemStack module, PipeBlockEntity tile) {
|
||||
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
PipeNetwork network = PipeNetwork.get(tile.getLevel());
|
||||
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
// loop through filters to see which items to pull
|
||||
|
@ -49,8 +50,8 @@ public class RetrievalModuleItem extends ModuleItem {
|
|||
continue;
|
||||
ItemStack remain = dest.getRight().copy();
|
||||
// are we already waiting for crafting results? If so, don't request those again
|
||||
remain.shrink(network.getCurrentlyCraftingAmount(tile.getPos(), copy, equalityTypes));
|
||||
if (network.requestItem(tile.getPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
||||
remain.shrink(network.getCurrentlyCraftingAmount(tile.getBlockPos(), copy, equalityTypes));
|
||||
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -77,8 +78,8 @@ public class RetrievalModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new RetrievalModuleContainer(Registry.retrievalModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new RetrievalModuleContainer(Registry.retrievalModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.stacksize;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StackSizeModuleContainer extends AbstractPipeContainer<StackSizeModuleItem> {
|
||||
public StackSizeModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
|
||||
public StackSizeModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,57 +1,59 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.stacksize;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton.ButtonResult;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class StackSizeModuleGui extends AbstractPipeGui<StackSizeModuleContainer> {
|
||||
public StackSizeModuleGui(StackSizeModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public StackSizeModuleGui(StackSizeModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
TextFieldWidget textField = this.addButton(new TextFieldWidget(this.font, this.guiLeft + 7, this.guiTop + 17 + 32 + 10, 40, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".max_stack_size")) {
|
||||
EditBox textField = this.addRenderableWidget(new EditBox(this.font, this.leftPos + 7, this.topPos + 17 + 32 + 10, 40, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".max_stack_size")) {
|
||||
@Override
|
||||
public void writeText(String textToWrite) {
|
||||
public void insertText(String textToWrite) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for (char c : textToWrite.toCharArray()) {
|
||||
if (Character.isDigit(c))
|
||||
ret.append(c);
|
||||
}
|
||||
super.writeText(ret.toString());
|
||||
super.insertText(ret.toString());
|
||||
}
|
||||
|
||||
});
|
||||
textField.setText(String.valueOf(StackSizeModuleItem.getMaxStackSize(this.container.moduleStack)));
|
||||
textField.setMaxStringLength(4);
|
||||
textField.setValue(String.valueOf(StackSizeModuleItem.getMaxStackSize(this.menu.moduleStack)));
|
||||
textField.setMaxLength(4);
|
||||
textField.setResponder(s -> {
|
||||
if (s.isEmpty())
|
||||
return;
|
||||
int amount = Integer.parseInt(s);
|
||||
PacketButton.sendAndExecute(this.container.tile.getPos(), ButtonResult.STACK_SIZE_AMOUNT, amount);
|
||||
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_AMOUNT, amount);
|
||||
});
|
||||
Supplier<TranslationTextComponent> buttonText = () -> new TranslationTextComponent("info." + PrettyPipes.ID + ".limit_to_max_" + (StackSizeModuleItem.getLimitToMaxStackSize(this.container.moduleStack) ? "on" : "off"));
|
||||
this.addButton(new Button(this.guiLeft + 7, this.guiTop + 17 + 32 + 10 + 22, 120, 20, buttonText.get(), b -> {
|
||||
PacketButton.sendAndExecute(this.container.tile.getPos(), ButtonResult.STACK_SIZE_MODULE_BUTTON);
|
||||
Supplier<TranslatableComponent> buttonText = () -> new TranslatableComponent("info." + PrettyPipes.ID + ".limit_to_max_" + (StackSizeModuleItem.getLimitToMaxStackSize(this.menu.moduleStack) ? "on" : "off"));
|
||||
this.addRenderableWidget(new Button(this.leftPos + 7, this.topPos + 17 + 32 + 10 + 22, 120, 20, buttonText.get(), b -> {
|
||||
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_MODULE_BUTTON);
|
||||
b.setMessage(buttonText.get());
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(matrix, mouseX, mouseY);
|
||||
this.font.drawString(matrix, I18n.format("info." + PrettyPipes.ID + ".max_stack_size") + ":", 7, 17 + 32, 4210752);
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
super.renderLabels(matrix, mouseX, mouseY);
|
||||
this.font.draw(matrix, I18n.get("info." + PrettyPipes.ID + ".max_stack_size") + ":", 7, 17 + 32, 4210752);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import de.ellpeck.prettypipes.items.ModuleItem;
|
|||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class StackSizeModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new StackSizeModuleContainer(Registry.stackSizeModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new StackSizeModuleContainer(Registry.stackSizeModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +1,58 @@
|
|||
package de.ellpeck.prettypipes.pressurizer;
|
||||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ContainerBlock;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class PressurizerBlock extends ContainerBlock {
|
||||
public class PressurizerBlock extends BaseEntityBlock {
|
||||
|
||||
public PressurizerBlock() {
|
||||
super(Properties.create(Material.ROCK).hardnessAndResistance(3).sound(SoundType.STONE));
|
||||
super(BlockBehaviour.Properties.of(Material.STONE).strength(3).sound(SoundType.STONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) {
|
||||
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
||||
PressurizerBlockEntity tile = Utility.getBlockEntity(PressurizerBlockEntity.class, worldIn, pos);
|
||||
if (tile == null)
|
||||
return ActionResultType.PASS;
|
||||
if (!worldIn.isRemote)
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
|
||||
return ActionResultType.SUCCESS;
|
||||
return InteractionResult.PASS;
|
||||
if (!worldIn.isClientSide)
|
||||
NetworkHooks.openGui((ServerPlayer) player, tile, pos);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new PressurizerBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
||||
return new PressurizerBlockEntity();
|
||||
public RenderShape getRenderShape(BlockState state) {
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
@ -34,8 +33,8 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
|
|||
private final LazyOptional<IPipeConnectable> lazyThis = LazyOptional.of(() -> this);
|
||||
private int lastEnergy;
|
||||
|
||||
public PressurizerBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
public PressurizerBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Registry.pressurizerBlockEntity, pos, state);
|
||||
}
|
||||
|
||||
public boolean pressurizeItem(ItemStack stack, boolean simulate) {
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
package de.ellpeck.prettypipes.pressurizer;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class PressurizerGui extends AbstractContainerScreen<PressurizerContainer> {
|
||||
|
||||
public class PressurizerGui extends ContainerScreen<PressurizerContainer> {
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pressurizer.png");
|
||||
|
||||
public PressurizerGui(PressurizerContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
public PressurizerGui(PressurizerContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
this.xSize = 176;
|
||||
this.ySize = 137;
|
||||
this.imageWidth = 176;
|
||||
this.imageHeight = 137;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(matrix);
|
||||
super.render(matrix, mouseX, mouseY, partialTicks);
|
||||
this.func_230459_a_(matrix, mouseX, mouseY);
|
||||
if (mouseX >= this.guiLeft + 26 && mouseY >= this.guiTop + 22 && mouseX < this.guiLeft + 26 + 124 && mouseY < this.guiTop + 22 + 12)
|
||||
this.renderTooltip(matrix, new TranslationTextComponent("info." + PrettyPipes.ID + ".energy", this.container.tile.getEnergy(), this.container.tile.getMaxEnergy()), mouseX, mouseY);
|
||||
this.renderTooltip(matrix, mouseX, mouseY);
|
||||
if (mouseX >= this.leftPos + 26 && mouseY >= this.topPos + 22 && mouseX < this.leftPos + 26 + 124 && mouseY < this.topPos + 22 + 12)
|
||||
this.renderTooltip(matrix, new TranslatableComponent("info." + PrettyPipes.ID + ".energy", this.menu.tile.getEnergy(), this.menu.tile.getMaxEnergy()), mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
this.font.drawString(matrix, this.playerInventory.getDisplayName().getString(), 8, this.ySize - 96 + 2, 4210752);
|
||||
this.font.drawString(matrix, this.title.getString(), 8, 6, 4210752);
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
this.font.draw(matrix, this.playerInventoryTitle.getString(), 8, this.imageHeight - 96 + 2, 4210752);
|
||||
this.font.draw(matrix, this.title.getString(), 8, 6, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) {
|
||||
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
this.blit(matrixStack, this.guiLeft, this.guiTop, 0, 0, 176, 137);
|
||||
int energy = (int) (this.container.tile.getEnergyPercentage() * 124);
|
||||
this.blit(matrixStack, this.guiLeft + 26, this.guiTop + 22, 0, 137, energy, 12);
|
||||
protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y) {
|
||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
this.blit(matrixStack, this.leftPos, this.topPos, 0, 0, 176, 137);
|
||||
int energy = (int) (this.menu.tile.getEnergyPercentage() * 124);
|
||||
this.blit(matrixStack, this.leftPos + 26, this.topPos + 22, 0, 137, energy, 12);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package de.ellpeck.prettypipes.terminal;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class CraftingTerminalBlock extends ItemTerminalBlock {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
||||
return new CraftingTerminalBlockEntity();
|
||||
public @org.jetbrains.annotations.Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new CraftingTerminalBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,26 +7,24 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.misc.EquatableItemStack;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.network.NetworkItem;
|
||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
@ -42,18 +40,18 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
|||
public final ItemStackHandler craftItems = new ItemStackHandler(9) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
for (Player playerEntity : CraftingTerminalBlockEntity.this.getLookingPlayers())
|
||||
playerEntity.containerMenu.onCraftMatrixChanged(null);
|
||||
for (var playerEntity : CraftingTerminalBlockEntity.this.getLookingPlayers())
|
||||
playerEntity.containerMenu.slotsChanged(null);
|
||||
}
|
||||
};
|
||||
public final ItemStackHandler ghostItems = new ItemStackHandler(9);
|
||||
|
||||
public CraftingTerminalBlockEntity() {
|
||||
super(Registry.craftingTerminalTileEntity);
|
||||
public CraftingTerminalBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Registry.craftingTerminalBlockEntity, pos, state);
|
||||
}
|
||||
|
||||
public ItemStack getRequestedCraftItem(int slot) {
|
||||
ItemStack stack = this.craftItems.getStackInSlot(slot);
|
||||
var stack = this.craftItems.getStackInSlot(slot);
|
||||
if (!stack.isEmpty())
|
||||
return stack;
|
||||
return this.ghostItems.getStackInSlot(slot);
|
||||
|
@ -65,30 +63,30 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
|||
|
||||
public void setGhostItems(ListMultimap<Integer, ItemStack> stacks) {
|
||||
this.updateItems();
|
||||
for (int i = 0; i < this.ghostItems.getSlots(); i++) {
|
||||
List<ItemStack> items = stacks.get(i);
|
||||
for (var i = 0; i < this.ghostItems.getSlots(); i++) {
|
||||
var items = stacks.get(i);
|
||||
if (items.isEmpty()) {
|
||||
this.ghostItems.setStackInSlot(i, ItemStack.EMPTY);
|
||||
continue;
|
||||
}
|
||||
ItemStack toSet = items.get(0);
|
||||
var toSet = items.get(0);
|
||||
// if we have more than one item to choose from, we want to pick the one that we have most of in the system
|
||||
if (items.size() > 1) {
|
||||
int highestAmount = 0;
|
||||
for (ItemStack stack : items) {
|
||||
int amount = 0;
|
||||
var highestAmount = 0;
|
||||
for (var stack : items) {
|
||||
var amount = 0;
|
||||
// check existing items
|
||||
NetworkItem network = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT));
|
||||
var network = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT));
|
||||
if (network != null) {
|
||||
amount = network.getLocations().stream()
|
||||
.mapToInt(l -> l.getItemAmount(this.world, stack, ItemEquality.NBT))
|
||||
.mapToInt(l -> l.getItemAmount(this.level, stack, ItemEquality.NBT))
|
||||
.sum();
|
||||
}
|
||||
// check craftables
|
||||
if (amount <= 0 && highestAmount <= 0) {
|
||||
PipeBlockEntity pipe = this.getConnectedPipe();
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe != null)
|
||||
amount = PipeNetwork.get(this.world).getCraftableAmount(pipe.getPos(), null, stack, new Stack<>(), ItemEquality.NBT);
|
||||
amount = PipeNetwork.get(this.level).getCraftableAmount(pipe.getBlockPos(), null, stack, new Stack<>(), ItemEquality.NBT);
|
||||
}
|
||||
if (amount > highestAmount) {
|
||||
highestAmount = amount;
|
||||
|
@ -99,77 +97,77 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
|||
this.ghostItems.setStackInSlot(i, toSet.copy());
|
||||
}
|
||||
|
||||
if (!this.world.isRemote) {
|
||||
if (!this.level.isClientSide) {
|
||||
ListMultimap<Integer, ItemStack> clients = ArrayListMultimap.create();
|
||||
for (int i = 0; i < this.ghostItems.getSlots(); i++)
|
||||
for (var i = 0; i < this.ghostItems.getSlots(); i++)
|
||||
clients.put(i, this.ghostItems.getStackInSlot(i));
|
||||
PacketHandler.sendToAllLoaded(this.world, this.pos, new PacketGhostSlot(this.pos, clients));
|
||||
PacketHandler.sendToAllLoaded(this.level, this.getBlockPos(), new PacketGhostSlot(this.getBlockPos(), clients));
|
||||
}
|
||||
}
|
||||
|
||||
public void requestCraftingItems(PlayerEntity player, int maxAmount) {
|
||||
PipeBlockEntity pipe = this.getConnectedPipe();
|
||||
public void requestCraftingItems(Player player, int maxAmount) {
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
var network = PipeNetwork.get(this.level);
|
||||
network.startProfile("terminal_request_crafting");
|
||||
this.updateItems();
|
||||
// get the amount of crafts that we can do
|
||||
int lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
|
||||
NetworkItem item = this.networkItems.get(s);
|
||||
var lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
|
||||
var item = this.networkItems.get(s);
|
||||
return item != null ? item.getLocations() : Collections.emptyList();
|
||||
}, onItemUnavailable(player), new Stack<>(), ItemEquality.NBT);
|
||||
if (lowestAvailable > 0) {
|
||||
// if we're limiting the amount, pretend we only have that amount available
|
||||
if (maxAmount < lowestAvailable)
|
||||
lowestAvailable = maxAmount;
|
||||
for (int i = 0; i < this.craftItems.getSlots(); i++) {
|
||||
ItemStack requested = this.getRequestedCraftItem(i);
|
||||
for (var i = 0; i < this.craftItems.getSlots(); i++) {
|
||||
var requested = this.getRequestedCraftItem(i);
|
||||
if (requested.isEmpty())
|
||||
continue;
|
||||
requested = requested.copy();
|
||||
requested.setCount(lowestAvailable);
|
||||
this.requestItemImpl(requested, onItemUnavailable(player));
|
||||
}
|
||||
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
||||
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
|
||||
}
|
||||
network.endProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag write(CompoundTag compound) {
|
||||
public CompoundTag save(CompoundTag compound) {
|
||||
compound.put("craft_items", this.craftItems.serializeNBT());
|
||||
return super.write(compound);
|
||||
return super.save(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(BlockState state, CompoundTag compound) {
|
||||
public void load(CompoundTag compound) {
|
||||
this.craftItems.deserializeNBT(compound.getCompound("craft_items"));
|
||||
super.read(state, compound);
|
||||
super.load(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("container." + PrettyPipes.ID + ".crafting_terminal");
|
||||
public Component getDisplayName() {
|
||||
return new TranslatableComponent("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);
|
||||
public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
|
||||
return new CraftingTerminalContainer(Registry.craftingTerminalContainer, window, player, this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack remain, boolean simulate) {
|
||||
BlockPos pos = pipePos.offset(direction);
|
||||
CraftingTerminalBlockEntity tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, this.world, pos);
|
||||
var pos = pipePos.relative(direction);
|
||||
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, this.level, pos);
|
||||
if (tile != null) {
|
||||
remain = remain.copy();
|
||||
int lowestSlot = -1;
|
||||
var lowestSlot = -1;
|
||||
do {
|
||||
for (int i = 0; i < tile.craftItems.getSlots(); i++) {
|
||||
ItemStack stack = tile.getRequestedCraftItem(i);
|
||||
int count = tile.isGhostItem(i) ? 0 : stack.getCount();
|
||||
for (var i = 0; i < tile.craftItems.getSlots(); i++) {
|
||||
var stack = tile.getRequestedCraftItem(i);
|
||||
var count = tile.isGhostItem(i) ? 0 : stack.getCount();
|
||||
if (!ItemHandlerHelper.canItemStacksStack(stack, remain))
|
||||
continue;
|
||||
// ensure that a single non-stackable item can still enter a ghost slot
|
||||
|
@ -179,7 +177,7 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
|||
lowestSlot = i;
|
||||
}
|
||||
if (lowestSlot >= 0) {
|
||||
ItemStack copy = remain.copy();
|
||||
var copy = remain.copy();
|
||||
copy.setCount(1);
|
||||
// if there were remaining items inserting into the slot with lowest contents, we're overflowing
|
||||
if (tile.craftItems.insertItem(lowestSlot, copy, simulate).getCount() > 0)
|
||||
|
@ -196,32 +194,32 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
|||
}
|
||||
|
||||
public static int getAvailableCrafts(PipeBlockEntity tile, int slots, Function<Integer, ItemStack> inputFunction, Predicate<Integer> isGhost, Function<EquatableItemStack, Collection<NetworkLocation>> locationsFunction, Consumer<ItemStack> unavailableConsumer, Stack<ItemStack> dependencyChain, ItemEquality... equalityTypes) {
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
// the highest amount we can craft with the items we have
|
||||
int lowestAvailable = Integer.MAX_VALUE;
|
||||
var lowestAvailable = Integer.MAX_VALUE;
|
||||
// this is the amount of items required for each ingredient when crafting ONE
|
||||
Map<EquatableItemStack, MutableInt> requiredItems = new HashMap<>();
|
||||
for (int i = 0; i < slots; i++) {
|
||||
ItemStack requested = inputFunction.apply(i);
|
||||
for (var i = 0; i < slots; i++) {
|
||||
var requested = inputFunction.apply(i);
|
||||
if (requested.isEmpty())
|
||||
continue;
|
||||
MutableInt amount = requiredItems.computeIfAbsent(new EquatableItemStack(requested, equalityTypes), s -> new MutableInt());
|
||||
var amount = requiredItems.computeIfAbsent(new EquatableItemStack(requested, equalityTypes), s -> new MutableInt());
|
||||
amount.add(requested.getCount());
|
||||
// if no items fit into the crafting input, we still want to pretend they do for requesting
|
||||
int fit = Math.max(requested.getMaxStackSize() - (isGhost.test(i) ? 0 : requested.getCount()), 1);
|
||||
var fit = Math.max(requested.getMaxStackSize() - (isGhost.test(i) ? 0 : requested.getCount()), 1);
|
||||
if (lowestAvailable > fit)
|
||||
lowestAvailable = fit;
|
||||
}
|
||||
for (Map.Entry<EquatableItemStack, MutableInt> entry : requiredItems.entrySet()) {
|
||||
EquatableItemStack stack = entry.getKey();
|
||||
for (var entry : requiredItems.entrySet()) {
|
||||
var stack = entry.getKey();
|
||||
|
||||
// total amount of available items of this type
|
||||
int available = 0;
|
||||
for (NetworkLocation location : locationsFunction.apply(stack)) {
|
||||
int amount = location.getItemAmount(tile.getWorld(), stack.stack, equalityTypes);
|
||||
var available = 0;
|
||||
for (var location : locationsFunction.apply(stack)) {
|
||||
var amount = location.getItemAmount(tile.getLevel(), stack.stack(), equalityTypes);
|
||||
if (amount <= 0)
|
||||
continue;
|
||||
amount -= network.getLockedAmount(location.getPos(), stack.stack, null, equalityTypes);
|
||||
amount -= network.getLockedAmount(location.getPos(), stack.stack(), null, equalityTypes);
|
||||
available += amount;
|
||||
}
|
||||
// divide the total by the amount required to get the amount that
|
||||
|
@ -230,17 +228,17 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
|||
|
||||
// check how many craftable items we have and add those on if we need to
|
||||
if (available < lowestAvailable) {
|
||||
int craftable = network.getCraftableAmount(tile.getPos(), unavailableConsumer, stack.stack, dependencyChain, equalityTypes);
|
||||
var craftable = network.getCraftableAmount(tile.getBlockPos(), unavailableConsumer, stack.stack(), dependencyChain, equalityTypes);
|
||||
if (craftable > 0)
|
||||
available += craftable / entry.getValue().intValue();
|
||||
}
|
||||
|
||||
// clamp to lowest available
|
||||
// clamp to the lowest available
|
||||
if (available < lowestAvailable)
|
||||
lowestAvailable = available;
|
||||
|
||||
if (available <= 0 && unavailableConsumer != null)
|
||||
unavailableConsumer.accept(stack.stack);
|
||||
unavailableConsumer.accept(stack.stack());
|
||||
}
|
||||
return lowestAvailable;
|
||||
}
|
||||
|
|
|
@ -1,79 +1,78 @@
|
|||
package de.ellpeck.prettypipes.terminal;
|
||||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ContainerBlock;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemTerminalBlock extends ContainerBlock {
|
||||
public class ItemTerminalBlock extends BaseEntityBlock {
|
||||
|
||||
public ItemTerminalBlock() {
|
||||
super(Properties.create(Material.ROCK).hardnessAndResistance(3).sound(SoundType.STONE));
|
||||
super(Properties.of(Material.STONE).strength(3).sound(SoundType.STONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) {
|
||||
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
||||
ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
|
||||
if (tile == null)
|
||||
return ActionResultType.PASS;
|
||||
return InteractionResult.PASS;
|
||||
String reason = tile.getInvalidTerminalReason();
|
||||
if (reason != null) {
|
||||
if (!worldIn.isRemote)
|
||||
player.sendMessage(new TranslationTextComponent(reason).mergeStyle(TextFormatting.RED), UUID.randomUUID());
|
||||
return ActionResultType.SUCCESS;
|
||||
if (!worldIn.isClientSide)
|
||||
player.sendMessage(new TranslatableComponent(reason).withStyle(ChatFormatting.RED), UUID.randomUUID());
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
if (!worldIn.isRemote) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
|
||||
if (!worldIn.isClientSide) {
|
||||
NetworkHooks.openGui((ServerPlayer) player, tile, pos);
|
||||
tile.updateItems(player);
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.getBlock() != newState.getBlock()) {
|
||||
ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
|
||||
if (tile != null)
|
||||
Utility.dropInventory(tile, tile.items);
|
||||
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||
super.onRemove(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
||||
return new ItemTerminalBlockEntity();
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new ItemTerminalBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.MODEL;
|
||||
public RenderShape getRenderShape(BlockState state) {
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,30 +16,23 @@ import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
|||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
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.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
@ -51,7 +44,7 @@ import java.util.*;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnectable {
|
||||
public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnectable, MenuProvider {
|
||||
|
||||
public final ItemStackHandler items = new ItemStackHandler(12) {
|
||||
@Override
|
||||
|
@ -63,6 +56,14 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
private final Queue<NetworkLock> existingRequests = new LinkedList<>();
|
||||
private final LazyOptional<IPipeConnectable> lazyThis = LazyOptional.of(() -> this);
|
||||
|
||||
public ItemTerminalBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
public ItemTerminalBlockEntity(BlockPos pos, BlockState state) {
|
||||
this(Registry.itemTerminalBlockEntity, pos, state);
|
||||
}
|
||||
|
||||
// TODO tick
|
||||
/* @Override
|
||||
public void tick() {
|
||||
|
@ -105,15 +106,15 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
@Override
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
PipeNetwork network = PipeNetwork.get(this.level);
|
||||
for (NetworkLock lock : this.existingRequests)
|
||||
var network = PipeNetwork.get(this.level);
|
||||
for (var lock : this.existingRequests)
|
||||
network.resolveNetworkLock(lock);
|
||||
this.lazyThis.invalidate();
|
||||
}
|
||||
|
||||
public String getInvalidTerminalReason() {
|
||||
PipeNetwork network = PipeNetwork.get(this.level);
|
||||
long pipes = Arrays.stream(Direction.values())
|
||||
var network = PipeNetwork.get(this.level);
|
||||
var pipes = Arrays.stream(Direction.values())
|
||||
.map(d -> network.getPipe(this.worldPosition.relative(d)))
|
||||
.filter(Objects::nonNull).count();
|
||||
if (pipes <= 0)
|
||||
|
@ -124,9 +125,9 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
}
|
||||
|
||||
public PipeBlockEntity getConnectedPipe() {
|
||||
PipeNetwork network = PipeNetwork.get(this.level);
|
||||
for (Direction dir : Direction.values()) {
|
||||
PipeBlockEntity pipe = network.getPipe(this.worldPosition.relative(dir));
|
||||
var network = PipeNetwork.get(this.level);
|
||||
for (var dir : Direction.values()) {
|
||||
var pipe = network.getPipe(this.worldPosition.relative(dir));
|
||||
if (pipe != null)
|
||||
return pipe;
|
||||
}
|
||||
|
@ -134,15 +135,15 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
}
|
||||
|
||||
public void updateItems(Player... playersToSync) {
|
||||
PipeBlockEntity pipe = this.getConnectedPipe();
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return;
|
||||
this.networkItems = this.collectItems(ItemEquality.NBT);
|
||||
if (playersToSync.length > 0) {
|
||||
List<ItemStack> clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
||||
List<ItemStack> clientCraftables = PipeNetwork.get(this.level).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
List<ItemStack> currentlyCrafting = this.getCurrentlyCrafting().stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
||||
for (Player player : playersToSync) {
|
||||
var clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
||||
var clientCraftables = PipeNetwork.get(this.level).getAllCraftables(pipe.getBlockPos()).stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
var currentlyCrafting = this.getCurrentlyCrafting().stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
||||
for (var player : playersToSync) {
|
||||
if (!(player.containerMenu instanceof ItemTerminalContainer container))
|
||||
continue;
|
||||
if (container.tile != this)
|
||||
|
@ -153,12 +154,12 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
}
|
||||
|
||||
public void requestItem(Player player, ItemStack stack) {
|
||||
PipeNetwork network = PipeNetwork.get(this.level);
|
||||
var network = PipeNetwork.get(this.level);
|
||||
network.startProfile("terminal_request_item");
|
||||
this.updateItems();
|
||||
int requested = this.requestItemImpl(stack, onItemUnavailable(player));
|
||||
var requested = this.requestItemImpl(stack, onItemUnavailable(player));
|
||||
if (requested > 0) {
|
||||
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
||||
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
|
||||
} else {
|
||||
onItemUnavailable(player).accept(stack);
|
||||
}
|
||||
|
@ -166,32 +167,29 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
}
|
||||
|
||||
public int requestItemImpl(ItemStack stack, Consumer<ItemStack> unavailableConsumer) {
|
||||
NetworkItem item = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT));
|
||||
var item = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT));
|
||||
Collection<NetworkLocation> locations = item == null ? Collections.emptyList() : item.getLocations();
|
||||
Pair<List<NetworkLock>, ItemStack> ret = requestItemLater(this.level, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT);
|
||||
var ret = requestItemLater(this.level, this.getConnectedPipe().getBlockPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT);
|
||||
this.existingRequests.addAll(ret.getLeft());
|
||||
return stack.getCount() - ret.getRight().getCount();
|
||||
}
|
||||
|
||||
protected Player[] getLookingPlayers() {
|
||||
return this.level.getPlayers().stream()
|
||||
.filter(p -> p.openContainer instanceof ItemTerminalContainer)
|
||||
.filter(p -> ((ItemTerminalContainer) p.openContainer).tile == this)
|
||||
.toArray(PlayerEntity[]::new);
|
||||
return this.level.players().stream().filter(p -> p.containerMenu instanceof ItemTerminalContainer container && container.tile == this).toArray(Player[]::new);
|
||||
}
|
||||
|
||||
private Map<EquatableItemStack, NetworkItem> collectItems(ItemEquality... equalityTypes) {
|
||||
PipeNetwork network = PipeNetwork.get(this.level);
|
||||
var network = PipeNetwork.get(this.level);
|
||||
network.startProfile("terminal_collect_items");
|
||||
PipeBlockEntity pipe = this.getConnectedPipe();
|
||||
var pipe = this.getConnectedPipe();
|
||||
Map<EquatableItemStack, NetworkItem> items = new HashMap<>();
|
||||
for (NetworkLocation location : network.getOrderedNetworkItems(pipe.getPos())) {
|
||||
for (Map.Entry<Integer, ItemStack> entry : location.getItems(this.level).entrySet()) {
|
||||
for (var location : network.getOrderedNetworkItems(pipe.getBlockPos())) {
|
||||
for (var entry : location.getItems(this.level).entrySet()) {
|
||||
// make sure we can extract from this slot to display it
|
||||
if (!location.canExtract(this.level, entry.getKey()))
|
||||
continue;
|
||||
EquatableItemStack equatable = new EquatableItemStack(entry.getValue(), equalityTypes);
|
||||
NetworkItem item = items.computeIfAbsent(equatable, NetworkItem::new);
|
||||
var equatable = new EquatableItemStack(entry.getValue(), equalityTypes);
|
||||
var item = items.computeIfAbsent(equatable, NetworkItem::new);
|
||||
item.add(location, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -200,57 +198,57 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
}
|
||||
|
||||
private List<ItemStack> getCurrentlyCrafting() {
|
||||
PipeNetwork network = PipeNetwork.get(this.level);
|
||||
PipeBlockEntity pipe = this.getConnectedPipe();
|
||||
var network = PipeNetwork.get(this.level);
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return Collections.emptyList();
|
||||
List<Pair<BlockPos, ItemStack>> crafting = network.getCurrentlyCrafting(pipe.getPos());
|
||||
var crafting = network.getCurrentlyCrafting(pipe.getBlockPos());
|
||||
return crafting.stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void cancelCrafting() {
|
||||
PipeNetwork network = PipeNetwork.get(this.level);
|
||||
PipeBlockEntity pipe = this.getConnectedPipe();
|
||||
var network = PipeNetwork.get(this.level);
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return;
|
||||
for (Pair<BlockPos, ItemStack> craftable : network.getAllCraftables(pipe.getPos())) {
|
||||
PipeBlockEntity otherPipe = network.getPipe(craftable.getLeft());
|
||||
for (var craftable : network.getAllCraftables(pipe.getBlockPos())) {
|
||||
var otherPipe = network.getPipe(craftable.getLeft());
|
||||
if (otherPipe != null) {
|
||||
for (NetworkLock lock : otherPipe.craftIngredientRequests)
|
||||
for (var lock : otherPipe.craftIngredientRequests)
|
||||
network.resolveNetworkLock(lock);
|
||||
otherPipe.craftIngredientRequests.clear();
|
||||
otherPipe.craftResultRequests.clear();
|
||||
}
|
||||
}
|
||||
PlayerEntity[] lookingPlayers = this.getLookingPlayers();
|
||||
var lookingPlayers = this.getLookingPlayers();
|
||||
if (lookingPlayers.length > 0)
|
||||
this.updateItems(lookingPlayers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag write(CompoundTag compound) {
|
||||
public CompoundTag save(CompoundTag compound) {
|
||||
compound.put("items", this.items.serializeNBT());
|
||||
compound.put("requests", Utility.serializeAll(this.existingRequests));
|
||||
return super.write(compound);
|
||||
return super.save(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(BlockState state, CompoundTag compound) {
|
||||
public void load(CompoundTag compound) {
|
||||
this.items.deserializeNBT(compound.getCompound("items"));
|
||||
this.existingRequests.clear();
|
||||
this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", NBT.TAG_COMPOUND), NetworkLock::new));
|
||||
super.read(state, compound);
|
||||
this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), NetworkLock::new));
|
||||
super.load(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("container." + PrettyPipes.ID + ".item_terminal");
|
||||
public Component getDisplayName() {
|
||||
return new TranslatableComponent("container." + PrettyPipes.ID + ".item_terminal");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) {
|
||||
return new ItemTerminalContainer(Registry.itemTerminalContainer, window, player, this.pos);
|
||||
public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
|
||||
return new ItemTerminalContainer(Registry.itemTerminalContainer, window, player, this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -267,8 +265,8 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
|
||||
@Override
|
||||
public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack stack, boolean simulate) {
|
||||
BlockPos pos = pipePos.offset(direction);
|
||||
ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, world, pos);
|
||||
var pos = pipePos.relative(direction);
|
||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, this.level, pos);
|
||||
if (tile != null)
|
||||
return ItemHandlerHelper.insertItemStacked(tile.items, stack, simulate);
|
||||
return stack;
|
||||
|
@ -279,13 +277,13 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
return true;
|
||||
}
|
||||
|
||||
public static Pair<List<NetworkLock>, ItemStack> requestItemLater(World world, BlockPos destPipe, Collection<NetworkLocation> locations, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain, ItemEquality... equalityTypes) {
|
||||
public static Pair<List<NetworkLock>, ItemStack> requestItemLater(Level world, BlockPos destPipe, Collection<NetworkLocation> locations, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain, ItemEquality... equalityTypes) {
|
||||
List<NetworkLock> requests = new ArrayList<>();
|
||||
ItemStack remain = stack.copy();
|
||||
PipeNetwork network = PipeNetwork.get(world);
|
||||
var remain = stack.copy();
|
||||
var network = PipeNetwork.get(world);
|
||||
// check for existing items
|
||||
for (NetworkLocation location : locations) {
|
||||
int amount = location.getItemAmount(world, stack, equalityTypes);
|
||||
for (var location : locations) {
|
||||
var amount = location.getItemAmount(world, stack, equalityTypes);
|
||||
if (amount <= 0)
|
||||
continue;
|
||||
amount -= network.getLockedAmount(location.getPos(), stack, null, equalityTypes);
|
||||
|
@ -294,9 +292,9 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
amount = remain.getCount();
|
||||
remain.shrink(amount);
|
||||
while (amount > 0) {
|
||||
ItemStack copy = stack.copy();
|
||||
var copy = stack.copy();
|
||||
copy.setCount(Math.min(stack.getMaxStackSize(), amount));
|
||||
NetworkLock lock = new NetworkLock(location, copy);
|
||||
var lock = new NetworkLock(location, copy);
|
||||
network.createNetworkLock(lock);
|
||||
requests.add(lock);
|
||||
amount -= copy.getCount();
|
||||
|
|
|
@ -2,20 +2,15 @@ package de.ellpeck.prettypipes.terminal.containers;
|
|||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.CraftResultInventory;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.CraftingResultSlot;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.*;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.network.play.server.SSetSlotPacket;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -23,42 +18,42 @@ import java.util.Optional;
|
|||
|
||||
public class CraftingTerminalContainer extends ItemTerminalContainer {
|
||||
|
||||
public CraftingInventory craftInventory;
|
||||
public CraftResultInventory craftResult;
|
||||
private final PlayerEntity player;
|
||||
public CraftingContainer craftInventory;
|
||||
public ResultContainer craftResult;
|
||||
private final Player player;
|
||||
|
||||
public CraftingTerminalContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos) {
|
||||
public CraftingTerminalContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos) {
|
||||
super(type, id, player, pos);
|
||||
this.player = player;
|
||||
this.onCraftMatrixChanged(this.craftInventory);
|
||||
this.slotsChanged(this.craftInventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addOwnSlots(PlayerEntity player) {
|
||||
protected void addDataSlots(ContainerData data) {
|
||||
this.craftInventory = new WrappedCraftingInventory(this.getTile().craftItems, this, 3, 3);
|
||||
this.craftResult = new CraftResultInventory();
|
||||
this.addSlot(new CraftingResultSlot(player, this.craftInventory, this.craftResult, 0, 25, 77));
|
||||
this.craftResult = new ResultContainer();
|
||||
this.addSlot(new ResultSlot(this.player, this.craftInventory, this.craftResult, 0, 25, 77));
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
this.addSlot(new Slot(this.craftInventory, j + i * 3, 7 + j * 18, 18 + i * 18));
|
||||
super.addOwnSlots(player);
|
||||
super.addDataSlots(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftMatrixChanged(IInventory inventoryIn) {
|
||||
if (!this.player.world.isRemote) {
|
||||
public void slotsChanged(Container inventoryIn) {
|
||||
if (!this.player.level.isClientSide) {
|
||||
ItemStack ret = ItemStack.EMPTY;
|
||||
Optional<ICraftingRecipe> optional = this.player.world.getServer().getRecipeManager().getRecipe(IRecipeType.CRAFTING, this.craftInventory, this.player.world);
|
||||
Optional<CraftingRecipe> optional = this.player.level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory, this.player.level);
|
||||
if (optional.isPresent())
|
||||
ret = optional.get().getCraftingResult(this.craftInventory);
|
||||
this.craftResult.setInventorySlotContents(0, ret);
|
||||
((ServerPlayerEntity) this.player).connection.sendPacket(new SSetSlotPacket(this.windowId, 0, ret));
|
||||
ret = optional.get().assemble(this.craftInventory);
|
||||
this.craftResult.setItem(0, ret);
|
||||
((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, 0, ret));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::mergeItemStack, player, slotIndex, stack -> Pair.of(6 + 10, 12 + 10));
|
||||
public ItemStack quickMoveStack(Player player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::moveItemStackTo, player, slotIndex, stack -> Pair.of(6 + 10, 12 + 10));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,13 +62,13 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) {
|
||||
public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) {
|
||||
if (slotId > 0 && clickTypeIn == ClickType.PICKUP) {
|
||||
Slot slot = this.inventorySlots.get(slotId);
|
||||
if (slot.inventory == this.craftInventory && !slot.getHasStack())
|
||||
Slot slot = this.slots.get(slotId);
|
||||
if (slot.container == this.craftInventory && !slot.hasItem())
|
||||
this.getTile().ghostItems.setStackInSlot(slot.getSlotIndex(), ItemStack.EMPTY);
|
||||
}
|
||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
super.clicked(slotId, dragType, clickTypeIn, player);
|
||||
}
|
||||
|
||||
public CraftingTerminalBlockEntity getTile() {
|
||||
|
|
|
@ -1,46 +1,42 @@
|
|||
package de.ellpeck.prettypipes.terminal.containers;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class CraftingTerminalGui extends ItemTerminalGui {
|
||||
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png");
|
||||
private Button requestButton;
|
||||
|
||||
public CraftingTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
public CraftingTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
this.xSize = 256;
|
||||
this.imageWidth = 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
this.requestButton = this.addButton(new Button(this.guiLeft + 8, this.guiTop + 100, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||
int amount = requestModifier();
|
||||
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
|
||||
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + 8, this.topPos + 100, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||
var amount = requestModifier();
|
||||
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
|
||||
}));
|
||||
this.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
CraftingTerminalBlockEntity tile = this.getCraftingContainer().getTile();
|
||||
public void containerTick() {
|
||||
super.containerTick();
|
||||
var tile = this.getCraftingContainer().getTile();
|
||||
this.requestButton.active = false;
|
||||
for (int i = 0; i < tile.craftItems.getSlots(); i++) {
|
||||
ItemStack stack = tile.getRequestedCraftItem(i);
|
||||
for (var i = 0; i < tile.craftItems.getSlots(); i++) {
|
||||
var stack = tile.getRequestedCraftItem(i);
|
||||
if (!stack.isEmpty() && stack.getCount() < stack.getMaxStackSize()) {
|
||||
this.requestButton.active = true;
|
||||
break;
|
||||
|
@ -49,23 +45,23 @@ public class CraftingTerminalGui extends ItemTerminalGui {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(matrix, mouseX, mouseY);
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
super.renderLabels(matrix, mouseX, mouseY);
|
||||
|
||||
CraftingTerminalContainer container = this.getCraftingContainer();
|
||||
CraftingTerminalBlockEntity tile = container.getTile();
|
||||
for (int i = 0; i < tile.ghostItems.getSlots(); i++) {
|
||||
var container = this.getCraftingContainer();
|
||||
var tile = container.getTile();
|
||||
for (var i = 0; i < tile.ghostItems.getSlots(); i++) {
|
||||
if (!tile.craftItems.getStackInSlot(i).isEmpty())
|
||||
continue;
|
||||
ItemStack ghost = tile.ghostItems.getStackInSlot(i);
|
||||
var ghost = tile.ghostItems.getStackInSlot(i);
|
||||
if (ghost.isEmpty())
|
||||
continue;
|
||||
int finalI = i;
|
||||
Slot slot = container.inventorySlots.stream().filter(s -> s.inventory == container.craftInventory && s.getSlotIndex() == finalI).findFirst().orElse(null);
|
||||
var finalI = i;
|
||||
var slot = container.slots.stream().filter(s -> s.container == container.craftInventory && s.getSlotIndex() == finalI).findFirst().orElse(null);
|
||||
if (slot == null)
|
||||
continue;
|
||||
this.minecraft.getItemRenderer().renderItemIntoGUI(ghost, slot.xPos, slot.yPos);
|
||||
this.minecraft.getItemRenderer().renderItemOverlayIntoGUI(this.font, ghost, slot.xPos, slot.yPos, "0");
|
||||
this.minecraft.getItemRenderer().renderGuiItem(ghost, slot.x, slot.y);
|
||||
this.minecraft.getItemRenderer().renderGuiItemDecorations(this.font, ghost, slot.x, slot.y, "0");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,6 +76,6 @@ public class CraftingTerminalGui extends ItemTerminalGui {
|
|||
}
|
||||
|
||||
protected CraftingTerminalContainer getCraftingContainer() {
|
||||
return (CraftingTerminalContainer) this.container;
|
||||
return (CraftingTerminalContainer) this.menu;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.ellpeck.prettypipes.terminal.containers;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.misc.ItemTerminalWidget;
|
||||
import de.ellpeck.prettypipes.misc.PlayerPrefs;
|
||||
|
@ -10,23 +11,15 @@ import de.ellpeck.prettypipes.packets.PacketRequest;
|
|||
import joptsimple.internal.Strings;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -66,14 +59,14 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
protected void init() {
|
||||
super.init();
|
||||
|
||||
this.search = this.addWidget(new EditBox(this.font, this.leftPos + this.getXOffset() + 97, this.topPos + 6, 86, 8, new StringTextComponent("")));
|
||||
this.search = this.addRenderableWidget(new EditBox(this.font, this.leftPos + this.getXOffset() + 97, this.topPos + 6, 86, 8, new TextComponent("")));
|
||||
this.search.setBordered(false);
|
||||
this.lastSearchText = "";
|
||||
if (this.items != null)
|
||||
this.updateWidgets();
|
||||
|
||||
this.plusButton = this.addWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 + 12, this.topPos + 103, 12, 12, new StringTextComponent("+"), button -> {
|
||||
int modifier = requestModifier();
|
||||
this.plusButton = this.addRenderableWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 + 12, this.topPos + 103, 12, 12, new TextComponent("+"), button -> {
|
||||
var modifier = requestModifier();
|
||||
if (modifier > 1 && this.requestAmount == 1) {
|
||||
this.requestAmount = modifier;
|
||||
} else {
|
||||
|
@ -83,44 +76,44 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
if (this.requestAmount > 384)
|
||||
this.requestAmount = 384;
|
||||
}));
|
||||
this.minusButton = this.addWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 24, this.topPos + 103, 12, 12, new StringTextComponent("-"), button -> {
|
||||
this.minusButton = this.addRenderableWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 24, this.topPos + 103, 12, 12, new TextComponent("-"), button -> {
|
||||
this.requestAmount -= requestModifier();
|
||||
if (this.requestAmount < 1)
|
||||
this.requestAmount = 1;
|
||||
}));
|
||||
this.minusButton.active = false;
|
||||
this.requestButton = this.addWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 25, this.topPos + 115, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||
Optional<ItemTerminalWidget> widget = this.streamWidgets().filter(w -> w.selected).findFirst();
|
||||
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 25, this.topPos + 115, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||
var widget = this.streamWidgets().filter(w -> w.selected).findFirst();
|
||||
if (!widget.isPresent())
|
||||
return;
|
||||
ItemStack stack = widget.get().stack.copy();
|
||||
var stack = widget.get().stack.copy();
|
||||
stack.setCount(1);
|
||||
PacketHandler.sendToServer(new PacketRequest(this.menu.tile.getBlockPos(), stack, this.requestAmount));
|
||||
this.requestAmount = 1;
|
||||
}));
|
||||
this.requestButton.active = false;
|
||||
this.orderButton = this.addWidget(new Button(this.leftPos - 22, this.topPos, 20, 20, new TextComponent(""), button -> {
|
||||
this.orderButton = this.addRenderableWidget(new Button(this.leftPos - 22, this.topPos, 20, 20, new TextComponent(""), button -> {
|
||||
if (this.sortedItems == null)
|
||||
return;
|
||||
PlayerPrefs prefs = PlayerPrefs.get();
|
||||
var prefs = PlayerPrefs.get();
|
||||
prefs.terminalItemOrder = prefs.terminalItemOrder.next();
|
||||
prefs.save();
|
||||
this.updateWidgets();
|
||||
}));
|
||||
this.ascendingButton = this.addButton(new Button(this.leftPos - 22, this.topPos + 22, 20, 20, new StringTextComponent(""), button -> {
|
||||
this.ascendingButton = this.addRenderableWidget(new Button(this.leftPos - 22, this.topPos + 22, 20, 20, new TextComponent(""), button -> {
|
||||
if (this.sortedItems == null)
|
||||
return;
|
||||
PlayerPrefs prefs = PlayerPrefs.get();
|
||||
var prefs = PlayerPrefs.get();
|
||||
prefs.terminalAscending = !prefs.terminalAscending;
|
||||
prefs.save();
|
||||
this.updateWidgets();
|
||||
}));
|
||||
this.cancelCraftingButton = this.addButton(new Button(this.leftPos + this.xSize + 4, this.topPos + 4 + 64, 54, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".cancel_all"), b -> {
|
||||
this.cancelCraftingButton = this.addRenderableWidget(new Button(this.leftPos + this.imageWidth + 4, this.topPos + 4 + 64, 54, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".cancel_all"), b -> {
|
||||
}));
|
||||
this.cancelCraftingButton.visible = false;
|
||||
for (int y = 0; y < 4; y++) {
|
||||
for (int x = 0; x < 9; x++)
|
||||
this.addButton(new ItemTerminalWidget(this.leftPos + this.getXOffset() + 8 + x * 18, this.topPos + 18 + y * 18, x, y, this));
|
||||
for (var y = 0; y < 4; y++) {
|
||||
for (var x = 0; x < 9; x++)
|
||||
this.addRenderableWidget(new ItemTerminalWidget(this.leftPos + this.getXOffset() + 8 + x * 18, this.topPos + 18 + y * 18, x, y, this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,15 +122,15 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
public void containerTick() {
|
||||
super.containerTick();
|
||||
this.requestButton.active = this.streamWidgets().anyMatch(w -> w.selected);
|
||||
this.plusButton.active = this.requestAmount < 384;
|
||||
this.minusButton.active = this.requestAmount > 1;
|
||||
|
||||
this.search.tick();
|
||||
if (this.items != null) {
|
||||
String text = this.search.getText();
|
||||
var text = this.search.getValue();
|
||||
if (!this.lastSearchText.equals(text)) {
|
||||
this.lastSearchText = text;
|
||||
this.updateWidgets();
|
||||
|
@ -158,9 +151,9 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
// we have to do the click logic here because JEI is activated when letting go of the mouse button
|
||||
// and vanilla buttons are activated when the click starts, so we'll always invoke jei accidentally by default
|
||||
if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
|
||||
if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHoveredOrFocused()) {
|
||||
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
||||
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CANCEL_CRAFTING));
|
||||
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CANCEL_CRAFTING));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -169,7 +162,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
this.isScrolling = false;
|
||||
else if (button == 1 && mouseX >= this.search.x && mouseX <= this.search.x + this.search.getWidth() && mouseY >= this.search.y && mouseY <= this.search.y + 8) {
|
||||
//clear text from search field when letting go of right mouse button within search field
|
||||
this.search.setText("");
|
||||
this.search.setValue("");
|
||||
return true;
|
||||
}
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
|
@ -178,8 +171,8 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int i, double j, double k) {
|
||||
if (this.isScrolling) {
|
||||
float percentage = MathHelper.clamp(((float) mouseY - (this.topPos + 18) - 7.5F) / (70 - 15), 0, 1);
|
||||
int offset = (int) (percentage * (float) (this.sortedItems.size() / 9 - 3));
|
||||
var percentage = Mth.clamp(((float) mouseY - (this.topPos + 18) - 7.5F) / (70 - 15), 0, 1);
|
||||
var offset = (int) (percentage * (float) (this.sortedItems.size() / 9 - 3));
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -193,8 +186,8 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
public boolean keyPressed(int x, int y, int z) {
|
||||
// for some reason we have to do this to make the text field allow the inventory key to be typed
|
||||
if (this.search.isFocused()) {
|
||||
InputMappings.Input mouseKey = InputMappings.getInputByCode(x, y);
|
||||
if (this.minecraft.gameSettings.keyBindInventory.isActiveAndMatches(mouseKey))
|
||||
var mouseKey = InputConstants.getKey(x, y);
|
||||
if (this.minecraft.options.keyInventory.isActiveAndMatches(mouseKey))
|
||||
return false;
|
||||
}
|
||||
return super.keyPressed(x, y, z);
|
||||
|
@ -208,30 +201,30 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
}
|
||||
|
||||
public void updateWidgets() {
|
||||
PlayerPrefs prefs = PlayerPrefs.get();
|
||||
this.ascendingButton.setMessage(new StringTextComponent(prefs.terminalAscending ? "^" : "v"));
|
||||
this.orderButton.setMessage(new StringTextComponent(prefs.terminalItemOrder.name().substring(0, 1)));
|
||||
var prefs = PlayerPrefs.get();
|
||||
this.ascendingButton.setMessage(new TextComponent(prefs.terminalAscending ? "^" : "v"));
|
||||
this.orderButton.setMessage(new TextComponent(prefs.terminalItemOrder.name().substring(0, 1)));
|
||||
this.cancelCraftingButton.visible = this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty();
|
||||
|
||||
Comparator<ItemStack> comparator = prefs.terminalItemOrder.comparator;
|
||||
var comparator = prefs.terminalItemOrder.comparator;
|
||||
if (!prefs.terminalAscending)
|
||||
comparator = comparator.reversed();
|
||||
|
||||
// add all items to the sorted items list
|
||||
this.sortedItems.clear();
|
||||
for (ItemStack stack : this.items)
|
||||
for (var stack : this.items)
|
||||
this.sortedItems.add(Pair.of(stack, false));
|
||||
for (ItemStack stack : this.craftables)
|
||||
for (var stack : this.craftables)
|
||||
this.sortedItems.add(Pair.of(stack, true));
|
||||
|
||||
// compare by craftability first, and then by the player's chosen order
|
||||
Comparator<Pair<ItemStack, Boolean>> fullComparator = Comparator.comparing(Pair::getRight);
|
||||
this.sortedItems.sort(fullComparator.thenComparing(Pair::getLeft, comparator));
|
||||
|
||||
String searchText = this.search.getText();
|
||||
var searchText = this.search.getValue();
|
||||
if (!Strings.isNullOrEmpty(searchText)) {
|
||||
this.sortedItems.removeIf(s -> {
|
||||
String search = searchText;
|
||||
var search = searchText;
|
||||
String toCompare;
|
||||
if (search.startsWith("@")) {
|
||||
toCompare = s.getLeft().getItem().getCreatorModId(s.getLeft());
|
||||
|
@ -247,16 +240,16 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
if (this.sortedItems.size() < 9 * 4)
|
||||
this.scrollOffset = 0;
|
||||
|
||||
List<ItemTerminalWidget> widgets = this.streamWidgets().collect(Collectors.toList());
|
||||
for (int i = 0; i < widgets.size(); i++) {
|
||||
ItemTerminalWidget widget = widgets.get(i);
|
||||
int index = i + this.scrollOffset * 9;
|
||||
var widgets = this.streamWidgets().collect(Collectors.toList());
|
||||
for (var i = 0; i < widgets.size(); i++) {
|
||||
var widget = widgets.get(i);
|
||||
var index = i + this.scrollOffset * 9;
|
||||
if (index >= this.sortedItems.size()) {
|
||||
widget.stack = ItemStack.EMPTY;
|
||||
widget.craftable = false;
|
||||
widget.visible = false;
|
||||
} else {
|
||||
Pair<ItemStack, Boolean> stack = this.sortedItems.get(index);
|
||||
var stack = this.sortedItems.get(index);
|
||||
widget.stack = stack.getLeft();
|
||||
widget.craftable = stack.getRight();
|
||||
widget.visible = true;
|
||||
|
@ -265,51 +258,51 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(matrix);
|
||||
super.render(matrix, mouseX, mouseY, partialTicks);
|
||||
for (Widget widget : this.buttons) {
|
||||
if (widget instanceof ItemTerminalWidget)
|
||||
widget.renderToolTip(matrix, mouseX, mouseY);
|
||||
for (var widget : this.renderables) {
|
||||
if (widget instanceof ItemTerminalWidget terminal)
|
||||
terminal.renderToolTip(matrix, mouseX, mouseY);
|
||||
}
|
||||
if (this.sortedItems != null) {
|
||||
PlayerPrefs prefs = PlayerPrefs.get();
|
||||
if (this.orderButton.isHovered())
|
||||
this.renderTooltip(matrix, new TranslationTextComponent("info." + PrettyPipes.ID + ".order", I18n.format("info." + PrettyPipes.ID + ".order." + prefs.terminalItemOrder.name().toLowerCase(Locale.ROOT))), mouseX, mouseY);
|
||||
if (this.ascendingButton.isHovered())
|
||||
this.renderTooltip(matrix, new TranslationTextComponent("info." + PrettyPipes.ID + "." + (prefs.terminalAscending ? "ascending" : "descending")), mouseX, mouseY);
|
||||
var prefs = PlayerPrefs.get();
|
||||
if (this.orderButton.isHoveredOrFocused())
|
||||
this.renderTooltip(matrix, new TranslatableComponent("info." + PrettyPipes.ID + ".order", I18n.get("info." + PrettyPipes.ID + ".order." + prefs.terminalItemOrder.name().toLowerCase(Locale.ROOT))), mouseX, mouseY);
|
||||
if (this.ascendingButton.isHoveredOrFocused())
|
||||
this.renderTooltip(matrix, new TranslatableComponent("info." + PrettyPipes.ID + "." + (prefs.terminalAscending ? "ascending" : "descending")), mouseX, mouseY);
|
||||
}
|
||||
if (this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
|
||||
String[] tooltip = I18n.format("info." + PrettyPipes.ID + ".cancel_all.desc").split("\n");
|
||||
this.func_243308_b(matrix, Arrays.stream(tooltip).map(StringTextComponent::new).collect(Collectors.toList()), mouseX, mouseY);
|
||||
if (this.cancelCraftingButton.visible && this.cancelCraftingButton.isHoveredOrFocused()) {
|
||||
var tooltip = I18n.get("info." + PrettyPipes.ID + ".cancel_all.desc").split("\n");
|
||||
this.renderComponentTooltip(matrix, Arrays.stream(tooltip).map(TextComponent::new).collect(Collectors.toList()), mouseX, mouseY);
|
||||
}
|
||||
if (!this.hoveredCrafting.isEmpty())
|
||||
this.renderTooltip(matrix, this.hoveredCrafting, mouseX, mouseY);
|
||||
this.func_230459_a_(matrix, mouseX, mouseY);
|
||||
this.renderTooltip(matrix, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
this.font.drawString(matrix, this.playerInventory.getDisplayName().getString(), 8 + this.getXOffset(), this.ySize - 96 + 2, 4210752);
|
||||
this.font.drawString(matrix, this.title.getString(), 8, 6, 4210752);
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
this.font.draw(matrix, this.playerInventoryTitle.getString(), 8 + this.getXOffset(), this.imageHeight - 96 + 2, 4210752);
|
||||
this.font.draw(matrix, this.title.getString(), 8, 6, 4210752);
|
||||
|
||||
String amount = String.valueOf(this.requestAmount);
|
||||
this.font.drawString(matrix, amount, (176 + 15 - this.font.getStringWidth(amount)) / 2F - 7 + this.getXOffset(), 106, 4210752);
|
||||
var amount = String.valueOf(this.requestAmount);
|
||||
this.font.draw(matrix, amount, (176 + 15 - this.font.width(amount)) / 2F - 7 + this.getXOffset(), 106, 4210752);
|
||||
|
||||
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
||||
this.font.drawString(matrix, I18n.format("info." + PrettyPipes.ID + ".crafting"), this.xSize + 4, 4 + 6, 4210752);
|
||||
this.font.draw(matrix, I18n.get("info." + PrettyPipes.ID + ".crafting"), this.imageWidth + 4, 4 + 6, 4210752);
|
||||
if (this.currentlyCrafting.size() > 6)
|
||||
this.font.drawString(matrix, ". . .", this.xSize + 24, 4 + 51, 4210752);
|
||||
this.font.draw(matrix, ". . .", this.imageWidth + 24, 4 + 51, 4210752);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
this.getMinecraft().getTextureManager().bindTexture(this.getTexture());
|
||||
this.blit(matrix, this.leftPos, this.topPos, 0, 0, this.xSize, this.ySize);
|
||||
protected void renderBg(PoseStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
this.getMinecraft().getTextureManager().bindForSetup(this.getTexture());
|
||||
this.blit(matrix, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight);
|
||||
|
||||
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {
|
||||
float percentage = this.scrollOffset / (float) (this.sortedItems.size() / 9 - 3);
|
||||
var percentage = this.scrollOffset / (float) (this.sortedItems.size() / 9 - 3);
|
||||
this.blit(matrix, this.leftPos + this.getXOffset() + 172, this.topPos + 18 + (int) (percentage * (70 - 15)), 232, 241, 12, 15);
|
||||
} else {
|
||||
this.blit(matrix, this.leftPos + this.getXOffset() + 172, this.topPos + 18, 244, 241, 12, 15);
|
||||
|
@ -318,16 +311,16 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
// draw the items that are currently crafting
|
||||
this.hoveredCrafting = ItemStack.EMPTY;
|
||||
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
||||
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
this.blit(matrix, this.leftPos + this.xSize, this.topPos + 4, 191, 0, 65, 89);
|
||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
this.blit(matrix, this.leftPos + this.imageWidth, this.topPos + 4, 191, 0, 65, 89);
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
for (ItemStack stack : this.currentlyCrafting) {
|
||||
int itemX = this.leftPos + this.xSize + 4 + x * 18;
|
||||
int itemY = this.topPos + 4 + 16 + y * 18;
|
||||
this.itemRenderer.renderItemAndEffectIntoGUI(stack, itemX, itemY);
|
||||
this.itemRenderer.renderItemOverlayIntoGUI(this.font, stack, itemX, itemY, String.valueOf(stack.getCount()));
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
for (var stack : this.currentlyCrafting) {
|
||||
var itemX = this.leftPos + this.imageWidth + 4 + x * 18;
|
||||
var itemY = this.topPos + 4 + 16 + y * 18;
|
||||
this.itemRenderer.renderGuiItem(stack, itemX, itemY);
|
||||
this.itemRenderer.renderGuiItemDecorations(this.font, stack, itemX, itemY, String.valueOf(stack.getCount()));
|
||||
if (mouseX >= itemX && mouseY >= itemY && mouseX < itemX + 16 && mouseY < itemY + 18)
|
||||
this.hoveredCrafting = stack;
|
||||
x++;
|
||||
|
@ -348,7 +341,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double scroll) {
|
||||
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {
|
||||
int offset = MathHelper.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.sortedItems.size() / 9 - 3);
|
||||
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.sortedItems.size() / 9 - 3);
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -358,7 +351,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
}
|
||||
|
||||
public Stream<ItemTerminalWidget> streamWidgets() {
|
||||
return this.buttons.stream()
|
||||
return this.renderables.stream()
|
||||
.filter(w -> w instanceof ItemTerminalWidget)
|
||||
.map(w -> (ItemTerminalWidget) w);
|
||||
}
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
package de.ellpeck.prettypipes.terminal.containers;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.world.entity.player.StackedContents;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.item.crafting.RecipeItemHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class WrappedCraftingInventory extends CraftingInventory {
|
||||
public class WrappedCraftingInventory extends CraftingContainer {
|
||||
|
||||
private final ItemStackHandler items;
|
||||
private final Container eventHandler;
|
||||
private final AbstractContainerMenu eventHandler;
|
||||
|
||||
public WrappedCraftingInventory(ItemStackHandler items, Container eventHandlerIn, int width, int height) {
|
||||
public WrappedCraftingInventory(ItemStackHandler items, AbstractContainerMenu eventHandlerIn, int width, int height) {
|
||||
super(eventHandlerIn, width, height);
|
||||
this.eventHandler = eventHandlerIn;
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
public int getContainerSize() {
|
||||
return this.items.getSlots();
|
||||
}
|
||||
|
||||
|
@ -34,41 +32,41 @@ public class WrappedCraftingInventory extends CraftingInventory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index) {
|
||||
public ItemStack getItem(int index) {
|
||||
return this.items.getStackInSlot(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
public ItemStack removeItemNoUpdate(int index) {
|
||||
ItemStack before = this.items.getStackInSlot(index);
|
||||
this.items.setStackInSlot(index, ItemStack.EMPTY);
|
||||
return before;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count) {
|
||||
public ItemStack removeItem(int index, int count) {
|
||||
ItemStack slotStack = this.items.getStackInSlot(index);
|
||||
ItemStack ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
|
||||
if (!ret.isEmpty())
|
||||
this.eventHandler.onCraftMatrixChanged(this);
|
||||
this.eventHandler.slotsChanged(this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int index, ItemStack stack) {
|
||||
public void setItem(int index, ItemStack stack) {
|
||||
this.items.setStackInSlot(index, stack);
|
||||
this.eventHandler.onCraftMatrixChanged(this);
|
||||
this.eventHandler.slotsChanged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
public void clearContent() {
|
||||
for (int i = 0; i < this.items.getSlots(); i++)
|
||||
this.items.setStackInSlot(i, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillStackedContents(RecipeItemHelper helper) {
|
||||
public void fillStackedContents(StackedContents helper) {
|
||||
for (int i = 0; i < this.items.getSlots(); i++)
|
||||
helper.accountPlainStack(this.items.getStackInSlot(i));
|
||||
helper.accountStack(this.items.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue