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