mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-24 20:48:34 +01:00
Compare commits
5 commits
b991f8575f
...
ae5128971c
Author | SHA1 | Date | |
---|---|---|---|
ae5128971c | |||
1d9c22cb0a | |||
0df6401c4e | |||
46320dd889 | |||
077b09c37d |
76 changed files with 1977 additions and 2095 deletions
|
@ -95,7 +95,7 @@ repositories {
|
|||
|
||||
configurations {
|
||||
embed
|
||||
compile.extendsFrom(embed)
|
||||
implementation.extendsFrom(embed)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
|
@ -8,8 +8,8 @@ import de.ellpeck.prettypipes.network.PipeNetwork;
|
|||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeRenderer;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.MainPipeGui;
|
||||
|
@ -36,39 +36,37 @@ import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleContainer;
|
|||
import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleGui;
|
||||
import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleItem;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerBlock;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerContainer;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerGui;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlock;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlock;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
||||
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalGui;
|
||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer;
|
||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.gui.ScreenManager;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.RenderTypeLookup;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.extensions.IForgeContainerType;
|
||||
import net.minecraftforge.common.capabilities.CapabilityToken;
|
||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
@ -76,7 +74,6 @@ import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -86,46 +83,46 @@ import java.util.function.BiFunction;
|
|||
@Mod.EventBusSubscriber(bus = Bus.MOD)
|
||||
public final class Registry {
|
||||
|
||||
public static final ItemGroup GROUP = new ItemGroup(PrettyPipes.ID) {
|
||||
public static final CreativeModeTab TAB = new CreativeModeTab(PrettyPipes.ID) {
|
||||
@Override
|
||||
public ItemStack createIcon() {
|
||||
public ItemStack makeIcon() {
|
||||
return new ItemStack(wrenchItem);
|
||||
}
|
||||
};
|
||||
|
||||
@CapabilityInject(PipeNetwork.class)
|
||||
public static Capability<PipeNetwork> pipeNetworkCapability;
|
||||
@CapabilityInject(IPipeConnectable.class)
|
||||
public static Capability<IPipeConnectable> pipeConnectableCapability;
|
||||
public static Capability<PipeNetwork> pipeNetworkCapability = CapabilityManager.get(new CapabilityToken<>() {
|
||||
});
|
||||
public static Capability<IPipeConnectable> pipeConnectableCapability = CapabilityManager.get(new CapabilityToken<>() {
|
||||
});
|
||||
|
||||
public static Item wrenchItem;
|
||||
public static Item pipeFrameItem;
|
||||
|
||||
public static Block pipeBlock;
|
||||
public static TileEntityType<PipeTileEntity> pipeTileEntity;
|
||||
public static ContainerType<MainPipeContainer> pipeContainer;
|
||||
public static BlockEntityType<PipeBlockEntity> pipeBlockEntity;
|
||||
public static MenuType<MainPipeContainer> pipeContainer;
|
||||
|
||||
public static Block itemTerminalBlock;
|
||||
public static TileEntityType<ItemTerminalTileEntity> itemTerminalTileEntity;
|
||||
public static ContainerType<ItemTerminalContainer> itemTerminalContainer;
|
||||
public static BlockEntityType<ItemTerminalBlockEntity> itemTerminalBlockEntity;
|
||||
public static MenuType<ItemTerminalContainer> itemTerminalContainer;
|
||||
|
||||
public static Block craftingTerminalBlock;
|
||||
public static TileEntityType<CraftingTerminalTileEntity> craftingTerminalTileEntity;
|
||||
public static ContainerType<CraftingTerminalContainer> craftingTerminalContainer;
|
||||
public static BlockEntityType<CraftingTerminalBlockEntity> craftingTerminalBlockEntity;
|
||||
public static MenuType<CraftingTerminalContainer> craftingTerminalContainer;
|
||||
|
||||
public static EntityType<PipeFrameEntity> pipeFrameEntity;
|
||||
|
||||
public static Block pressurizerBlock;
|
||||
public static TileEntityType<PressurizerBlockEntity> pressurizerTileEntity;
|
||||
public static ContainerType<PressurizerContainer> pressurizerContainer;
|
||||
public static BlockEntityType<PressurizerBlockEntity> pressurizerBlockEntity;
|
||||
public static MenuType<PressurizerContainer> pressurizerContainer;
|
||||
|
||||
public static ContainerType<ExtractionModuleContainer> extractionModuleContainer;
|
||||
public static ContainerType<FilterModuleContainer> filterModuleContainer;
|
||||
public static ContainerType<RetrievalModuleContainer> retrievalModuleContainer;
|
||||
public static ContainerType<StackSizeModuleContainer> stackSizeModuleContainer;
|
||||
public static ContainerType<FilterIncreaseModuleContainer> filterIncreaseModuleContainer;
|
||||
public static ContainerType<CraftingModuleContainer> craftingModuleContainer;
|
||||
public static ContainerType<FilterModifierModuleContainer> filterModifierModuleContainer;
|
||||
public static MenuType<ExtractionModuleContainer> extractionModuleContainer;
|
||||
public static MenuType<FilterModuleContainer> filterModuleContainer;
|
||||
public static MenuType<RetrievalModuleContainer> retrievalModuleContainer;
|
||||
public static MenuType<StackSizeModuleContainer> stackSizeModuleContainer;
|
||||
public static MenuType<FilterIncreaseModuleContainer> filterIncreaseModuleContainer;
|
||||
public static MenuType<CraftingModuleContainer> craftingModuleContainer;
|
||||
public static MenuType<FilterModifierModuleContainer> filterModifierModuleContainer;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
||||
|
@ -139,10 +136,10 @@ public final class Registry {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event) {
|
||||
IForgeRegistry<Item> registry = event.getRegistry();
|
||||
var registry = event.getRegistry();
|
||||
registry.registerAll(
|
||||
wrenchItem = new WrenchItem().setRegistryName("wrench"),
|
||||
new Item(new Item.Properties().group(GROUP)).setRegistryName("blank_module"),
|
||||
new Item(new Item.Properties().tab(TAB)).setRegistryName("blank_module"),
|
||||
pipeFrameItem = new PipeFrameItem().setRegistryName("pipe_frame")
|
||||
);
|
||||
registry.registerAll(createTieredModule("extraction_module", ExtractionModuleItem::new));
|
||||
|
@ -160,33 +157,33 @@ public final class Registry {
|
|||
|
||||
ForgeRegistries.BLOCKS.getValues().stream()
|
||||
.filter(b -> b.getRegistryName().getNamespace().equals(PrettyPipes.ID))
|
||||
.forEach(b -> registry.register(new BlockItem(b, new Item.Properties().group(GROUP)).setRegistryName(b.getRegistryName())));
|
||||
.forEach(b -> registry.register(new BlockItem(b, new Item.Properties().tab(TAB)).setRegistryName(b.getRegistryName())));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerTiles(RegistryEvent.Register<TileEntityType<?>> event) {
|
||||
public static void registerBlockEntities(RegistryEvent.Register<BlockEntityType<?>> event) {
|
||||
event.getRegistry().registerAll(
|
||||
pipeTileEntity = (TileEntityType<PipeTileEntity>) TileEntityType.Builder.create(PipeTileEntity::new, pipeBlock).build(null).setRegistryName("pipe"),
|
||||
itemTerminalTileEntity = (TileEntityType<ItemTerminalTileEntity>) TileEntityType.Builder.create(ItemTerminalTileEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"),
|
||||
craftingTerminalTileEntity = (TileEntityType<CraftingTerminalTileEntity>) TileEntityType.Builder.create(CraftingTerminalTileEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal"),
|
||||
pressurizerTileEntity = (TileEntityType<PressurizerBlockEntity>) TileEntityType.Builder.create(PressurizerBlockEntity::new, pressurizerBlock).build(null).setRegistryName("pressurizer")
|
||||
pipeBlockEntity = (BlockEntityType<PipeBlockEntity>) BlockEntityType.Builder.of(PipeBlockEntity::new, pipeBlock).build(null).setRegistryName("pipe"),
|
||||
itemTerminalBlockEntity = (BlockEntityType<ItemTerminalBlockEntity>) BlockEntityType.Builder.of(ItemTerminalBlockEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"),
|
||||
craftingTerminalBlockEntity = (BlockEntityType<CraftingTerminalBlockEntity>) BlockEntityType.Builder.of(CraftingTerminalBlockEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal"),
|
||||
pressurizerBlockEntity = (BlockEntityType<PressurizerBlockEntity>) BlockEntityType.Builder.of(PressurizerBlockEntity::new, pressurizerBlock).build(null).setRegistryName("pressurizer")
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerEntities(RegistryEvent.Register<EntityType<?>> event) {
|
||||
event.getRegistry().registerAll(
|
||||
pipeFrameEntity = (EntityType<PipeFrameEntity>) EntityType.Builder.<PipeFrameEntity>create(PipeFrameEntity::new, EntityClassification.MISC).build("pipe_frame").setRegistryName("pipe_frame")
|
||||
pipeFrameEntity = (EntityType<PipeFrameEntity>) EntityType.Builder.<PipeFrameEntity>of(PipeFrameEntity::new, MobCategory.MISC).build("pipe_frame").setRegistryName("pipe_frame")
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerContainers(RegistryEvent.Register<ContainerType<?>> event) {
|
||||
public static void registerContainers(RegistryEvent.Register<MenuType<?>> event) {
|
||||
event.getRegistry().registerAll(
|
||||
pipeContainer = (ContainerType<MainPipeContainer>) IForgeContainerType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"),
|
||||
itemTerminalContainer = (ContainerType<ItemTerminalContainer>) IForgeContainerType.create((windowId, inv, data) -> new ItemTerminalContainer(itemTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("item_terminal"),
|
||||
craftingTerminalContainer = (ContainerType<CraftingTerminalContainer>) IForgeContainerType.create((windowId, inv, data) -> new CraftingTerminalContainer(craftingTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("crafting_terminal"),
|
||||
pressurizerContainer = (ContainerType<PressurizerContainer>) IForgeContainerType.create((windowId, inv, data) -> new PressurizerContainer(pressurizerContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pressurizer"),
|
||||
pipeContainer = (MenuType<MainPipeContainer>) IForgeMenuType.create((windowId, inv, data) -> new MainPipeContainer(pipeContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pipe"),
|
||||
itemTerminalContainer = (MenuType<ItemTerminalContainer>) IForgeMenuType.create((windowId, inv, data) -> new ItemTerminalContainer(itemTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("item_terminal"),
|
||||
craftingTerminalContainer = (MenuType<CraftingTerminalContainer>) IForgeMenuType.create((windowId, inv, data) -> new CraftingTerminalContainer(craftingTerminalContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("crafting_terminal"),
|
||||
pressurizerContainer = (MenuType<PressurizerContainer>) IForgeMenuType.create((windowId, inv, data) -> new PressurizerContainer(pressurizerContainer, windowId, inv.player, data.readBlockPos())).setRegistryName("pressurizer"),
|
||||
extractionModuleContainer = createPipeContainer("extraction_module"),
|
||||
filterModuleContainer = createPipeContainer("filter_module"),
|
||||
retrievalModuleContainer = createPipeContainer("retrieval_module"),
|
||||
|
@ -197,60 +194,44 @@ public final class Registry {
|
|||
);
|
||||
}
|
||||
|
||||
private static <T extends AbstractPipeContainer<?>> ContainerType<T> createPipeContainer(String name) {
|
||||
return (ContainerType<T>) IForgeContainerType.create((windowId, inv, data) -> {
|
||||
PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, inv.player.world, data.readBlockPos());
|
||||
int moduleIndex = data.readInt();
|
||||
ItemStack moduleStack = tile.modules.getStackInSlot(moduleIndex);
|
||||
private static <T extends AbstractPipeContainer<?>> MenuType<T> createPipeContainer(String name) {
|
||||
return (MenuType<T>) IForgeMenuType.create((windowId, inv, data) -> {
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, inv.player.level, data.readBlockPos());
|
||||
var moduleIndex = data.readInt();
|
||||
var moduleStack = tile.modules.getStackInSlot(moduleIndex);
|
||||
return ((IModule) moduleStack.getItem()).getContainer(moduleStack, tile, windowId, inv, inv.player, moduleIndex);
|
||||
}).setRegistryName(name);
|
||||
}
|
||||
|
||||
private static Item[] createTieredModule(String name, BiFunction<String, ModuleTier, ModuleItem> item) {
|
||||
List<Item> items = new ArrayList<>();
|
||||
for (ModuleTier tier : ModuleTier.values())
|
||||
for (var tier : ModuleTier.values())
|
||||
items.add(item.apply(name, tier).setRegistryName(tier.name().toLowerCase(Locale.ROOT) + "_" + name));
|
||||
return items.toArray(new Item[0]);
|
||||
}
|
||||
|
||||
public static void setup(FMLCommonSetupEvent event) {
|
||||
registerCap(PipeNetwork.class);
|
||||
registerCap(IPipeConnectable.class);
|
||||
PacketHandler.setup();
|
||||
}
|
||||
|
||||
public static final class Client {
|
||||
|
||||
public static void setup(FMLClientSetupEvent event) {
|
||||
RenderTypeLookup.setRenderLayer(pipeBlock, RenderType.getCutout());
|
||||
ClientRegistry.bindTileEntityRenderer(pipeTileEntity, PipeRenderer::new);
|
||||
RenderingRegistry.registerEntityRenderingHandler(pipeFrameEntity, PipeFrameRenderer::new);
|
||||
ItemBlockRenderTypes.setRenderLayer(pipeBlock, RenderType.cutout());
|
||||
BlockEntityRenderers.register(pipeBlockEntity, PipeRenderer::new);
|
||||
EntityRenderers.register(pipeFrameEntity, PipeFrameRenderer::new);
|
||||
|
||||
ScreenManager.registerFactory(pipeContainer, MainPipeGui::new);
|
||||
ScreenManager.registerFactory(itemTerminalContainer, ItemTerminalGui::new);
|
||||
ScreenManager.registerFactory(pressurizerContainer, PressurizerGui::new);
|
||||
ScreenManager.registerFactory(craftingTerminalContainer, CraftingTerminalGui::new);
|
||||
ScreenManager.registerFactory(extractionModuleContainer, ExtractionModuleGui::new);
|
||||
ScreenManager.registerFactory(filterModuleContainer, FilterModuleGui::new);
|
||||
ScreenManager.registerFactory(retrievalModuleContainer, RetrievalModuleGui::new);
|
||||
ScreenManager.registerFactory(stackSizeModuleContainer, StackSizeModuleGui::new);
|
||||
ScreenManager.registerFactory(filterIncreaseModuleContainer, FilterIncreaseModuleGui::new);
|
||||
ScreenManager.registerFactory(craftingModuleContainer, CraftingModuleGui::new);
|
||||
ScreenManager.registerFactory(filterModifierModuleContainer, FilterModifierModuleGui::new);
|
||||
MenuScreens.register(pipeContainer, MainPipeGui::new);
|
||||
MenuScreens.register(itemTerminalContainer, ItemTerminalGui::new);
|
||||
MenuScreens.register(pressurizerContainer, PressurizerGui::new);
|
||||
MenuScreens.register(craftingTerminalContainer, CraftingTerminalGui::new);
|
||||
MenuScreens.register(extractionModuleContainer, ExtractionModuleGui::new);
|
||||
MenuScreens.register(filterModuleContainer, FilterModuleGui::new);
|
||||
MenuScreens.register(retrievalModuleContainer, RetrievalModuleGui::new);
|
||||
MenuScreens.register(stackSizeModuleContainer, StackSizeModuleGui::new);
|
||||
MenuScreens.register(filterIncreaseModuleContainer, FilterIncreaseModuleGui::new);
|
||||
MenuScreens.register(craftingModuleContainer, CraftingModuleGui::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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,25 +5,20 @@ import net.minecraft.client.gui.screens.Screen;
|
|||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.WorldlyContainer;
|
||||
import net.minecraft.world.WorldlyContainerHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
|
@ -36,7 +31,7 @@ import java.util.function.Function;
|
|||
|
||||
public final class Utility {
|
||||
|
||||
public static <T extends BlockEntity> T getBlockEntity(Class<T> type, LevelAccessor world, BlockPos pos) {
|
||||
public static <T extends BlockEntity> T getBlockEntity(Class<T> type, BlockGetter world, BlockPos pos) {
|
||||
var tile = world.getBlockEntity(pos);
|
||||
return type.isInstance(tile) ? (T) tile : null;
|
||||
}
|
||||
|
@ -55,7 +50,7 @@ public final class Utility {
|
|||
return Direction.fromNormal(diff.getX(), diff.getY(), diff.getZ());
|
||||
}
|
||||
|
||||
public static void addTooltip(String name, List<MutableComponent> tooltip) {
|
||||
public static void addTooltip(String name, List<Component> tooltip) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
var content = I18n.get("info." + PrettyPipes.ID + "." + name).split("\n");
|
||||
for (var s : content)
|
||||
|
|
|
@ -1,42 +1,29 @@
|
|||
package de.ellpeck.prettypipes.entities;
|
||||
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.FilledMapItem;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.network.IPacket;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.datasync.DataParameter;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
import net.minecraft.network.datasync.EntityDataManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.GameRules;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.storage.MapData;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
||||
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class PipeFrameEntity extends ItemFrame implements IEntityAdditionalSpawnData {
|
||||
|
||||
|
@ -65,15 +52,15 @@ public class PipeFrameEntity extends ItemFrame implements IEntityAdditionalSpawn
|
|||
return;
|
||||
if (this.tickCount % 40 != 0)
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(this.level);
|
||||
BlockPos attached = getAttachedPipe(this.level, this.pos, this.direction);
|
||||
var network = PipeNetwork.get(this.level);
|
||||
var attached = getAttachedPipe(this.level, this.pos, this.direction);
|
||||
if (attached != null) {
|
||||
BlockPos node = network.getNodeFromPipe(attached);
|
||||
var node = network.getNodeFromPipe(attached);
|
||||
if (node != null) {
|
||||
ItemStack stack = this.getItem();
|
||||
var stack = this.getItem();
|
||||
if (!stack.isEmpty()) {
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(node);
|
||||
int amount = items.stream().mapToInt(i -> i.getItemAmount(this.level, stack)).sum();
|
||||
var items = network.getOrderedNetworkItems(node);
|
||||
var amount = items.stream().mapToInt(i -> i.getItemAmount(this.level, stack)).sum();
|
||||
this.entityData.set(AMOUNT, amount);
|
||||
return;
|
||||
}
|
||||
|
@ -83,103 +70,97 @@ public class PipeFrameEntity extends ItemFrame implements IEntityAdditionalSpawn
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onValidSurface() {
|
||||
return super.onValidSurface() && canPlace(this.world, this.hangingPosition, this.facingDirection);
|
||||
public boolean survives() {
|
||||
return super.survives() && canPlace(this.level, this.pos, this.direction);
|
||||
}
|
||||
|
||||
private static BlockPos getAttachedPipe(Level world, BlockPos pos, Direction direction) {
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
BlockPos offset = pos.relative(direction.getOpposite(), i);
|
||||
BlockState state = world.getBlockState(offset);
|
||||
for (var i = 1; i <= 2; i++) {
|
||||
var offset = pos.relative(direction.getOpposite(), i);
|
||||
var state = world.getBlockState(offset);
|
||||
if (state.getBlock() instanceof PipeBlock)
|
||||
return offset;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean canPlace(World world, BlockPos pos, Direction direction) {
|
||||
public static boolean canPlace(Level world, BlockPos pos, Direction direction) {
|
||||
return getAttachedPipe(world, pos, direction) != null;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return this.dataManager.get(AMOUNT);
|
||||
return this.entityData.get(AMOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attackEntityFrom(DamageSource source, float amount) {
|
||||
public boolean hurt(DamageSource source, float amount) {
|
||||
if (this.isInvulnerableTo(source)) {
|
||||
return false;
|
||||
} else if (!source.isExplosion() && !this.getDisplayedItem().isEmpty()) {
|
||||
if (!this.world.isRemote) {
|
||||
this.dropItemOrSelf(source.getTrueSource(), false);
|
||||
this.playSound(SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM, 1.0F, 1.0F);
|
||||
} else if (!source.isExplosion() && !this.getItem().isEmpty()) {
|
||||
if (!this.level.isClientSide) {
|
||||
this.dropItemOrSelf(source.getDirectEntity(), false);
|
||||
this.playSound(SoundEvents.ITEM_FRAME_REMOVE_ITEM, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return super.attackEntityFrom(source, amount);
|
||||
return super.hurt(source, amount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroken(@Nullable Entity brokenEntity) {
|
||||
this.playSound(SoundEvents.ENTITY_ITEM_FRAME_BREAK, 1.0F, 1.0F);
|
||||
public void dropItem(@Nullable Entity brokenEntity) {
|
||||
this.playSound(SoundEvents.ITEM_FRAME_BREAK, 1.0F, 1.0F);
|
||||
this.dropItemOrSelf(brokenEntity, true);
|
||||
}
|
||||
|
||||
private void dropItemOrSelf(@Nullable Entity entityIn, boolean b) {
|
||||
if (!this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
|
||||
if (!this.level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
|
||||
if (entityIn == null)
|
||||
this.getDisplayedItem().setAttachedEntity(null);
|
||||
this.getItem().setEntityRepresentation(null);
|
||||
} else {
|
||||
ItemStack itemstack = this.getDisplayedItem();
|
||||
this.setDisplayedItem(ItemStack.EMPTY);
|
||||
if (entityIn instanceof PlayerEntity) {
|
||||
PlayerEntity playerentity = (PlayerEntity) entityIn;
|
||||
if (playerentity.abilities.isCreativeMode) {
|
||||
itemstack.setAttachedEntity(null);
|
||||
var itemstack = this.getItem();
|
||||
this.setItem(ItemStack.EMPTY);
|
||||
if (entityIn instanceof Player playerentity) {
|
||||
if (playerentity.isCreative()) {
|
||||
itemstack.setEntityRepresentation(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (b)
|
||||
this.entityDropItem(Registry.pipeFrameItem);
|
||||
this.spawnAtLocation(Registry.pipeFrameItem);
|
||||
|
||||
if (!itemstack.isEmpty()) {
|
||||
itemstack = itemstack.copy();
|
||||
itemstack.setAttachedEntity(null);
|
||||
this.entityDropItem(itemstack);
|
||||
itemstack.setEntityRepresentation(null);
|
||||
this.spawnAtLocation(itemstack);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType processInitialInteract(PlayerEntity player, Hand hand) {
|
||||
if (this.getDisplayedItem().isEmpty())
|
||||
return super.processInitialInteract(player, hand);
|
||||
return ActionResultType.FAIL;
|
||||
public InteractionResult interact(Player player, InteractionHand hand) {
|
||||
if (this.getItem().isEmpty())
|
||||
return super.interact(player, hand);
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickedResult(RayTraceResult target) {
|
||||
public ItemStack getPickedResult(HitResult target) {
|
||||
return new ItemStack(Registry.pipeFrameItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPacket<?> createSpawnPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
public void writeSpawnData(FriendlyByteBuf buffer) {
|
||||
buffer.writeBlockPos(this.pos);
|
||||
buffer.writeInt(this.direction.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(PacketBuffer buffer) {
|
||||
buffer.writeBlockPos(this.hangingPosition);
|
||||
buffer.writeInt(this.facingDirection.getIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(PacketBuffer additionalData) {
|
||||
this.hangingPosition = additionalData.readBlockPos();
|
||||
this.updateFacingWithBoundingBox(Direction.values()[additionalData.readInt()]);
|
||||
public void readSpawnData(FriendlyByteBuf additionalData) {
|
||||
this.pos = additionalData.readBlockPos();
|
||||
this.direction = Direction.values()[additionalData.readInt()];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,42 +1,37 @@
|
|||
package de.ellpeck.prettypipes.entities;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.ItemFrameRenderer;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
|
||||
public class PipeFrameRenderer extends ItemFrameRenderer {
|
||||
public PipeFrameRenderer(EntityRendererManager renderManagerIn) {
|
||||
super(renderManagerIn, Minecraft.getInstance().getItemRenderer());
|
||||
public class PipeFrameRenderer extends ItemFrameRenderer<PipeFrameEntity> {
|
||||
|
||||
public PipeFrameRenderer(EntityRendererProvider.Context renderManagerIn) {
|
||||
super(renderManagerIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(ItemFrameEntity entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
|
||||
public void render(PipeFrameEntity entityIn, float entityYaw, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn) {
|
||||
super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
|
||||
matrixStackIn.push();
|
||||
Direction direction = entityIn.getHorizontalFacing();
|
||||
Vector3d vec3d = this.getRenderOffset(entityIn, partialTicks);
|
||||
matrixStackIn.translate(-vec3d.getX(), -vec3d.getY(), -vec3d.getZ());
|
||||
matrixStackIn.translate(direction.getXOffset() * 0.46875, direction.getYOffset() * 0.46875, direction.getZOffset() * 0.46875);
|
||||
matrixStackIn.rotate(Vector3f.XP.rotationDegrees(entityIn.rotationPitch));
|
||||
matrixStackIn.rotate(Vector3f.YP.rotationDegrees(180.0F - entityIn.rotationYaw));
|
||||
matrixStackIn.pushPose();
|
||||
var direction = entityIn.getDirection();
|
||||
var vec3d = this.getRenderOffset(entityIn, partialTicks);
|
||||
matrixStackIn.translate(-vec3d.x, -vec3d.y, -vec3d.z);
|
||||
matrixStackIn.translate(direction.getStepX() * 0.46875, direction.getStepY() * 0.46875, direction.getStepZ() * 0.46875);
|
||||
matrixStackIn.mulPose(Vector3f.XP.rotationDegrees(entityIn.getXRot()));
|
||||
matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(180.0F - entityIn.getYRot()));
|
||||
|
||||
FontRenderer font = this.getFontRendererFromRenderManager();
|
||||
int amount = ((PipeFrameEntity) entityIn).getAmount();
|
||||
String ammountStrg = amount < 0 ? "?" : String.valueOf(amount);
|
||||
float x = 0.5F - font.getStringWidth(ammountStrg) / 2F;
|
||||
Matrix4f matrix4f = matrixStackIn.getLast().getMatrix();
|
||||
var font = this.getFont();
|
||||
var amount = entityIn.getAmount();
|
||||
var ammountStrg = amount < 0 ? "?" : String.valueOf(amount);
|
||||
var x = 0.5F - font.width(ammountStrg) / 2F;
|
||||
var matrix4f = matrixStackIn.last().pose();
|
||||
matrixStackIn.translate(0, 0.285F, 0.415F);
|
||||
matrixStackIn.scale(-0.02F, -0.02F, 0.02F);
|
||||
font.renderString(ammountStrg, x, 0, 0xFFFFFF, true, matrix4f, bufferIn, false, 0, packedLightIn);
|
||||
font.drawInBatch(ammountStrg, x, 0, 0xFFFFFF, true, matrix4f, bufferIn, false, 0, packedLightIn);
|
||||
|
||||
matrixStackIn.pop();
|
||||
matrixStackIn.popPose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package de.ellpeck.prettypipes.items;
|
||||
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,33 +15,33 @@ import java.util.function.Consumer;
|
|||
|
||||
public interface IModule {
|
||||
|
||||
void tick(ItemStack module, PipeTileEntity tile);
|
||||
void tick(ItemStack module, PipeBlockEntity tile);
|
||||
|
||||
boolean canNetworkSee(ItemStack module, PipeTileEntity tile);
|
||||
boolean canNetworkSee(ItemStack module, PipeBlockEntity tile);
|
||||
|
||||
boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack);
|
||||
boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack);
|
||||
|
||||
int getMaxInsertionAmount(ItemStack module, PipeTileEntity tile, ItemStack stack, IItemHandler destination);
|
||||
int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination);
|
||||
|
||||
int getPriority(ItemStack module, PipeTileEntity tile);
|
||||
int getPriority(ItemStack module, PipeBlockEntity tile);
|
||||
|
||||
boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other);
|
||||
boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other);
|
||||
|
||||
boolean hasContainer(ItemStack module, PipeTileEntity tile);
|
||||
boolean hasContainer(ItemStack module, PipeBlockEntity tile);
|
||||
|
||||
AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex);
|
||||
AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex);
|
||||
|
||||
float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile);
|
||||
float getItemSpeedIncrease(ItemStack module, PipeBlockEntity tile);
|
||||
|
||||
boolean canPipeWork(ItemStack module, PipeTileEntity tile);
|
||||
boolean canPipeWork(ItemStack module, PipeBlockEntity tile);
|
||||
|
||||
List<ItemStack> getAllCraftables(ItemStack module, PipeTileEntity tile);
|
||||
List<ItemStack> getAllCraftables(ItemStack module, PipeBlockEntity tile);
|
||||
|
||||
int getCraftableAmount(ItemStack module, PipeTileEntity tile, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain);
|
||||
int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain);
|
||||
|
||||
ItemStack craft(ItemStack module, PipeTileEntity tile, BlockPos destPipe, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain);
|
||||
ItemStack craft(ItemStack module, PipeBlockEntity tile, BlockPos destPipe, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain);
|
||||
|
||||
Integer getCustomNextNode(ItemStack module, PipeTileEntity tile, List<BlockPos> nodes, int index);
|
||||
Integer getCustomNextNode(ItemStack module, PipeBlockEntity tile, List<BlockPos> nodes, int index);
|
||||
|
||||
ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile);
|
||||
ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile);
|
||||
}
|
||||
|
|
|
@ -3,16 +3,16 @@ package de.ellpeck.prettypipes.items;
|
|||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
@ -28,79 +28,79 @@ public abstract class ModuleItem extends Item implements IModule {
|
|||
private final String name;
|
||||
|
||||
public ModuleItem(String name) {
|
||||
super(new Properties().group(Registry.GROUP).maxStackSize(16));
|
||||
super(new Properties().tab(Registry.TAB).stacksTo(16));
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
super.appendHoverText(stack, worldIn, tooltip, flagIn);
|
||||
Utility.addTooltip(this.name, tooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ItemStack module, PipeTileEntity tile) {
|
||||
public void tick(ItemStack module, PipeBlockEntity tile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNetworkSee(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) {
|
||||
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInsertionAmount(ItemStack module, PipeTileEntity tile, ItemStack stack, IItemHandler destination) {
|
||||
public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority(ItemStack module, PipeTileEntity tile) {
|
||||
public int getPriority(ItemStack module, PipeBlockEntity tile) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity 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 null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile) {
|
||||
public float getItemSpeedIncrease(ItemStack module, PipeBlockEntity tile) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPipeWork(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean canPipeWork(ItemStack module, PipeBlockEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getAllCraftables(ItemStack module, PipeTileEntity tile) {
|
||||
public List<ItemStack> getAllCraftables(ItemStack module, PipeBlockEntity tile) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCraftableAmount(ItemStack module, PipeTileEntity tile, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
|
||||
public int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(ItemStack module, PipeTileEntity 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) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCustomNextNode(ItemStack module, PipeTileEntity tile, List<BlockPos> nodes, int index) {
|
||||
public Integer getCustomNextNode(ItemStack module, PipeBlockEntity tile, List<BlockPos> nodes, int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) {
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,71 +3,68 @@ package de.ellpeck.prettypipes.items;
|
|||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.entities.PipeFrameEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.item.HangingEntity;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.entity.item.PaintingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.decoration.HangingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class PipeFrameItem extends Item {
|
||||
|
||||
public PipeFrameItem() {
|
||||
super(new Properties().group(Registry.GROUP));
|
||||
super(new Properties().tab(Registry.TAB));
|
||||
}
|
||||
|
||||
// HangingEntityItem copypasta mostly, since it hardcodes the entities bleh
|
||||
@Override
|
||||
public ActionResultType onItemUse(ItemUseContext context) {
|
||||
BlockPos blockpos = context.getPos();
|
||||
Direction direction = context.getFace();
|
||||
BlockPos blockpos1 = blockpos.offset(direction);
|
||||
PlayerEntity playerentity = context.getPlayer();
|
||||
ItemStack itemstack = context.getItem();
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
var blockpos = context.getClickedPos();
|
||||
var direction = context.getClickedFace();
|
||||
var blockpos1 = blockpos.relative(direction);
|
||||
var playerentity = context.getPlayer();
|
||||
var itemstack = context.getItemInHand();
|
||||
if (playerentity != null && !this.canPlace(playerentity, direction, itemstack, blockpos1)) {
|
||||
return ActionResultType.FAIL;
|
||||
return InteractionResult.FAIL;
|
||||
} else {
|
||||
World world = context.getWorld();
|
||||
var world = context.getLevel();
|
||||
HangingEntity hangingentity = new PipeFrameEntity(Registry.pipeFrameEntity, world, blockpos1, direction);
|
||||
|
||||
CompoundTag CompoundTag = itemstack.getTag();
|
||||
if (CompoundTag != null) {
|
||||
EntityType.applyItemNBT(world, playerentity, hangingentity, CompoundTag);
|
||||
var compoundTag = itemstack.getTag();
|
||||
if (compoundTag != null) {
|
||||
EntityType.updateCustomEntityTag(world, playerentity, hangingentity, compoundTag);
|
||||
}
|
||||
|
||||
if (hangingentity.onValidSurface()) {
|
||||
if (!world.isRemote) {
|
||||
hangingentity.playPlaceSound();
|
||||
world.addEntity(hangingentity);
|
||||
if (hangingentity.survives()) {
|
||||
if (!world.isClientSide) {
|
||||
hangingentity.playPlacementSound();
|
||||
world.addFreshEntity(hangingentity);
|
||||
}
|
||||
|
||||
itemstack.shrink(1);
|
||||
return ActionResultType.SUCCESS;
|
||||
return InteractionResult.SUCCESS;
|
||||
} else {
|
||||
return ActionResultType.CONSUME;
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canPlace(PlayerEntity playerIn, Direction directionIn, ItemStack itemStackIn, BlockPos posIn) {
|
||||
return !directionIn.getAxis().isVertical() && playerIn.canPlayerEdit(posIn, directionIn, itemStackIn) && PipeFrameEntity.canPlace(playerIn.world, posIn, directionIn);
|
||||
protected boolean canPlace(Player playerIn, Direction directionIn, ItemStack itemStackIn, BlockPos posIn) {
|
||||
return !directionIn.getAxis().isVertical() && playerIn.mayUseItemAt(posIn, directionIn, itemStackIn) && PipeFrameEntity.canPlace(playerIn.level, posIn, directionIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
super.appendHoverText(stack, worldIn, tooltip, flagIn);
|
||||
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,48 +4,45 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.pipe.ConnectionType;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WrenchItem extends Item {
|
||||
|
||||
public WrenchItem() {
|
||||
super(new Item.Properties().maxStackSize(1).group(Registry.GROUP));
|
||||
super(new Item.Properties().stacksTo(1).tab(Registry.TAB));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUse(ItemUseContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getPos();
|
||||
PlayerEntity player = context.getPlayer();
|
||||
BlockState state = world.getBlockState(pos);
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
var world = context.getLevel();
|
||||
var pos = context.getClickedPos();
|
||||
var player = context.getPlayer();
|
||||
var state = world.getBlockState(pos);
|
||||
if (!(state.getBlock() instanceof PipeBlock))
|
||||
return ActionResultType.PASS;
|
||||
PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, world, pos);
|
||||
return InteractionResult.PASS;
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, world, pos);
|
||||
if (tile == null)
|
||||
return ActionResultType.FAIL;
|
||||
return InteractionResult.FAIL;
|
||||
|
||||
if (player.isSneaking()) {
|
||||
if (!world.isRemote) {
|
||||
if (player.isCrouching()) {
|
||||
if (!world.isClientSide) {
|
||||
if (tile.cover != null) {
|
||||
// remove the cover
|
||||
tile.removeCover(player, context.getHand());
|
||||
|
@ -53,64 +50,64 @@ public class WrenchItem extends Item {
|
|||
} else {
|
||||
// remove the pipe
|
||||
PipeBlock.dropItems(world, pos, player);
|
||||
Block.spawnDrops(state, world, pos, tile, null, ItemStack.EMPTY);
|
||||
Block.dropResources(state, world, pos, tile, null, ItemStack.EMPTY);
|
||||
world.removeBlock(pos, false);
|
||||
}
|
||||
world.playSound(null, pos, SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM, SoundCategory.PLAYERS, 1, 1);
|
||||
world.playSound(null, pos, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.PLAYERS, 1, 1);
|
||||
}
|
||||
return ActionResultType.func_233537_a_(world.isRemote);
|
||||
return InteractionResult.sidedSuccess(world.isClientSide);
|
||||
}
|
||||
|
||||
// placing covers
|
||||
if (tile.cover == null) {
|
||||
ItemStack offhand = player.getHeldItemOffhand();
|
||||
var offhand = player.getOffhandItem();
|
||||
if (offhand.getItem() instanceof BlockItem) {
|
||||
if (!world.isRemote) {
|
||||
BlockItemUseContext blockContext = new BlockItemUseContext(context);
|
||||
Block block = ((BlockItem) offhand.getItem()).getBlock();
|
||||
BlockState cover = block.getStateForPlacement(blockContext);
|
||||
if (cover != null && !block.hasTileEntity(cover)) {
|
||||
if (!world.isClientSide) {
|
||||
var blockContext = new BlockPlaceContext(context);
|
||||
var block = ((BlockItem) offhand.getItem()).getBlock();
|
||||
var cover = block.getStateForPlacement(blockContext);
|
||||
if (cover != null && !(block instanceof EntityBlock)) {
|
||||
tile.cover = cover;
|
||||
Utility.sendBlockEntityToClients(tile);
|
||||
offhand.shrink(1);
|
||||
world.playSound(null, pos, SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, SoundCategory.PLAYERS, 1, 1);
|
||||
world.playSound(null, pos, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.PLAYERS, 1, 1);
|
||||
}
|
||||
}
|
||||
return ActionResultType.func_233537_a_(world.isRemote);
|
||||
return InteractionResult.sidedSuccess(world.isClientSide);
|
||||
}
|
||||
}
|
||||
|
||||
// disabling directions
|
||||
for (Map.Entry<Direction, VoxelShape> entry : PipeBlock.DIR_SHAPES.entrySet()) {
|
||||
AxisAlignedBB box = entry.getValue().getBoundingBox().offset(pos).grow(0.001F);
|
||||
if (!box.contains(context.getHitVec()))
|
||||
for (var entry : PipeBlock.DIR_SHAPES.entrySet()) {
|
||||
var box = entry.getValue().bounds().move(pos).inflate(0.001F);
|
||||
if (!box.contains(context.getClickLocation()))
|
||||
continue;
|
||||
EnumProperty<ConnectionType> prop = PipeBlock.DIRECTIONS.get(entry.getKey());
|
||||
ConnectionType curr = state.get(prop);
|
||||
var prop = PipeBlock.DIRECTIONS.get(entry.getKey());
|
||||
var curr = state.getValue(prop);
|
||||
if (curr == ConnectionType.DISCONNECTED)
|
||||
continue;
|
||||
|
||||
if (!world.isRemote) {
|
||||
ConnectionType newType = curr == ConnectionType.BLOCKED ? ConnectionType.CONNECTED : ConnectionType.BLOCKED;
|
||||
BlockPos otherPos = pos.offset(entry.getKey());
|
||||
BlockState otherState = world.getBlockState(otherPos);
|
||||
if (!world.isClientSide) {
|
||||
var newType = curr == ConnectionType.BLOCKED ? ConnectionType.CONNECTED : ConnectionType.BLOCKED;
|
||||
var otherPos = pos.relative(entry.getKey());
|
||||
var otherState = world.getBlockState(otherPos);
|
||||
if (otherState.getBlock() instanceof PipeBlock) {
|
||||
otherState = otherState.with(PipeBlock.DIRECTIONS.get(entry.getKey().getOpposite()), newType);
|
||||
world.setBlockState(otherPos, otherState);
|
||||
otherState = otherState.setValue(PipeBlock.DIRECTIONS.get(entry.getKey().getOpposite()), newType);
|
||||
world.setBlockAndUpdate(otherPos, otherState);
|
||||
PipeBlock.onStateChanged(world, otherPos, otherState);
|
||||
}
|
||||
BlockState newState = state.with(prop, newType);
|
||||
world.setBlockState(pos, newState);
|
||||
var newState = state.setValue(prop, newType);
|
||||
world.setBlockAndUpdate(pos, newState);
|
||||
PipeBlock.onStateChanged(world, pos, newState);
|
||||
world.playSound(null, pos, SoundEvents.ENTITY_ITEM_FRAME_ROTATE_ITEM, SoundCategory.PLAYERS, 1, 1);
|
||||
world.playSound(null, pos, SoundEvents.ITEM_FRAME_ROTATE_ITEM, SoundSource.PLAYERS, 1, 1);
|
||||
}
|
||||
return ActionResultType.func_233537_a_(world.isRemote);
|
||||
return InteractionResult.sidedSuccess(world.isClientSide);
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
public void appendHoverText(ItemStack stack, Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,21 +5,11 @@ import net.minecraft.world.item.ItemStack;
|
|||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EquatableItemStack {
|
||||
|
||||
public final ItemStack stack;
|
||||
public final ItemEquality[] equalityTypes;
|
||||
|
||||
public EquatableItemStack(ItemStack stack, ItemEquality... equalityTypes) {
|
||||
this.stack = stack;
|
||||
this.equalityTypes = equalityTypes;
|
||||
}
|
||||
public record EquatableItemStack(ItemStack stack, ItemEquality... equalityTypes) {
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof EquatableItemStack) {
|
||||
EquatableItemStack other = (EquatableItemStack) o;
|
||||
if (o instanceof EquatableItemStack other)
|
||||
return Arrays.equals(this.equalityTypes, other.equalityTypes) && ItemEquality.compareItems(this.stack, other.stack, this.equalityTypes);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.misc;
|
|||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -12,7 +12,7 @@ import net.minecraftforge.fml.common.Mod;
|
|||
public final class Events {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onWorldCaps(AttachCapabilitiesEvent<World> event) {
|
||||
public static void onWorldCaps(AttachCapabilitiesEvent<Level> event) {
|
||||
event.addCapability(new ResourceLocation(PrettyPipes.ID, "network"), new PipeNetwork(event.getObject()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package de.ellpeck.prettypipes.misc;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FilterSlot extends SlotItemHandler {
|
||||
|
||||
|
@ -16,9 +16,9 @@ public class FilterSlot extends SlotItemHandler {
|
|||
this.onlyOneItem = onlyOneItem;
|
||||
}
|
||||
|
||||
public static boolean checkFilter(Container container, int slotId, PlayerEntity player) {
|
||||
if (slotId >= 0 && slotId < container.inventorySlots.size()) {
|
||||
Slot slot = container.getSlot(slotId);
|
||||
public static boolean checkFilter(AbstractContainerMenu container, int slotId, Player player) {
|
||||
if (slotId >= 0 && slotId < container.slots.size()) {
|
||||
var slot = container.getSlot(slotId);
|
||||
if (slot instanceof FilterSlot) {
|
||||
((FilterSlot) slot).slotClick(player);
|
||||
return true;
|
||||
|
@ -27,32 +27,33 @@ public class FilterSlot extends SlotItemHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void slotClick(PlayerEntity player) {
|
||||
ItemStack heldStack = player.inventory.getItemStack();
|
||||
ItemStack stackInSlot = this.getStack();
|
||||
private void slotClick(Player player) {
|
||||
var heldStack = player.inventoryMenu.getCarried();
|
||||
var stackInSlot = this.getItem();
|
||||
|
||||
if (!stackInSlot.isEmpty() && heldStack.isEmpty()) {
|
||||
this.putStack(ItemStack.EMPTY);
|
||||
this.safeInsert(ItemStack.EMPTY);
|
||||
} else if (!heldStack.isEmpty()) {
|
||||
ItemStack s = heldStack.copy();
|
||||
var s = heldStack.copy();
|
||||
if (this.onlyOneItem)
|
||||
s.setCount(1);
|
||||
this.putStack(s);
|
||||
this.safeInsert(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
public boolean mayPlace(@NotNull ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack) {
|
||||
super.putStack(stack.copy());
|
||||
public ItemStack safeInsert(ItemStack stack) {
|
||||
return super.safeInsert(stack.copy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(PlayerEntity playerIn) {
|
||||
public boolean mayPickup(Player playerIn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,18 +3,19 @@ package de.ellpeck.prettypipes.misc;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
|
@ -25,14 +26,14 @@ import java.util.function.Supplier;
|
|||
public class ItemFilter extends ItemStackHandler {
|
||||
|
||||
private final ItemStack stack;
|
||||
private final PipeTileEntity pipe;
|
||||
private final PipeBlockEntity pipe;
|
||||
public boolean isWhitelist;
|
||||
|
||||
public boolean canPopulateFromInventories;
|
||||
public boolean canModifyWhitelist = true;
|
||||
private boolean modified;
|
||||
|
||||
public ItemFilter(int size, ItemStack stack, PipeTileEntity pipe) {
|
||||
public ItemFilter(int size, ItemStack stack, PipeBlockEntity pipe) {
|
||||
super(size);
|
||||
this.stack = stack;
|
||||
this.pipe = pipe;
|
||||
|
@ -42,23 +43,23 @@ public class ItemFilter extends ItemStackHandler {
|
|||
|
||||
public List<Slot> getSlots(int x, int y) {
|
||||
List<Slot> slots = new ArrayList<>();
|
||||
for (int i = 0; i < this.getSlots(); i++)
|
||||
for (var i = 0; i < this.getSlots(); i++)
|
||||
slots.add(new FilterSlot(this, i, x + i % 9 * 18, y + i / 9 * 18, true));
|
||||
return slots;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public List<Widget> getButtons(Screen gui, int x, int y) {
|
||||
List<Widget> buttons = new ArrayList<>();
|
||||
public List<AbstractWidget> getButtons(Screen gui, int x, int y) {
|
||||
List<AbstractWidget> buttons = new ArrayList<>();
|
||||
if (this.canModifyWhitelist) {
|
||||
Supplier<TranslatableComponent> whitelistText = () -> 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 -> {
|
||||
PacketButton.sendAndExecute(this.pipe.getPos(), PacketButton.ButtonResult.FILTER_CHANGE, 0);
|
||||
PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, 0);
|
||||
button.setMessage(whitelistText.get());
|
||||
}));
|
||||
}
|
||||
if (this.canPopulateFromInventories) {
|
||||
buttons.add(new Button(x + 72, y, 70, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".populate"), button -> PacketButton.sendAndExecute(this.pipe.getPos(), PacketButton.ButtonResult.FILTER_CHANGE, 1)) {
|
||||
buttons.add(new Button(x + 72, y, 70, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".populate"), button -> PacketButton.sendAndExecute(this.pipe.getBlockPos(), PacketButton.ButtonResult.FILTER_CHANGE, 1)) {
|
||||
@Override
|
||||
public void renderToolTip(PoseStack matrix, int x, int y) {
|
||||
gui.renderTooltip(matrix, new TranslatableComponent("info." + PrettyPipes.ID + ".populate.description").withStyle(ChatFormatting.GRAY), x, y);
|
||||
|
@ -75,19 +76,19 @@ public class ItemFilter extends ItemStackHandler {
|
|||
this.save();
|
||||
} else if (id == 1 && this.canPopulateFromInventories) {
|
||||
// populate filter from inventories
|
||||
List<ItemFilter> filters = this.pipe.getFilters();
|
||||
for (Direction direction : Direction.values()) {
|
||||
IItemHandler handler = this.pipe.getItemHandler(direction);
|
||||
var filters = this.pipe.getFilters();
|
||||
for (var direction : Direction.values()) {
|
||||
var handler = this.pipe.getItemHandler(direction);
|
||||
if (handler == null)
|
||||
continue;
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
ItemStack stack = handler.getStackInSlot(i);
|
||||
for (var i = 0; i < handler.getSlots(); i++) {
|
||||
var stack = handler.getStackInSlot(i);
|
||||
if (stack.isEmpty() || this.isFiltered(stack))
|
||||
continue;
|
||||
ItemStack copy = stack.copy();
|
||||
var copy = stack.copy();
|
||||
copy.setCount(1);
|
||||
// try inserting into ourselves and any filter increase modifiers
|
||||
for (ItemFilter filter : filters) {
|
||||
for (var filter : filters) {
|
||||
if (ItemHandlerHelper.insertItem(filter, copy, false).isEmpty()) {
|
||||
filter.save();
|
||||
break;
|
||||
|
@ -103,11 +104,11 @@ public class ItemFilter extends ItemStackHandler {
|
|||
}
|
||||
|
||||
private boolean isFiltered(ItemStack stack) {
|
||||
ItemEquality[] types = getEqualityTypes(this.pipe);
|
||||
var types = getEqualityTypes(this.pipe);
|
||||
// also check if any filter increase modules have the item we need
|
||||
for (ItemStackHandler handler : this.pipe.getFilters()) {
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
ItemStack filter = handler.getStackInSlot(i);
|
||||
for (var i = 0; i < handler.getSlots(); i++) {
|
||||
var filter = handler.getStackInSlot(i);
|
||||
if (filter.isEmpty())
|
||||
continue;
|
||||
if (ItemEquality.compareItems(stack, filter, types))
|
||||
|
@ -126,7 +127,7 @@ public class ItemFilter extends ItemStackHandler {
|
|||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = super.serializeNBT();
|
||||
var nbt = super.serializeNBT();
|
||||
if (this.canModifyWhitelist)
|
||||
nbt.putBoolean("whitelist", this.isWhitelist);
|
||||
return nbt;
|
||||
|
@ -144,7 +145,7 @@ public class ItemFilter extends ItemStackHandler {
|
|||
this.modified = true;
|
||||
}
|
||||
|
||||
public static ItemEquality[] getEqualityTypes(PipeTileEntity pipe) {
|
||||
public static ItemEquality[] getEqualityTypes(PipeBlockEntity pipe) {
|
||||
return pipe.streamModules()
|
||||
.filter(m -> m.getRight() instanceof FilterModifierModuleItem)
|
||||
.map(m -> ((FilterModifierModuleItem) m.getRight()).getEqualityType(m.getLeft()))
|
||||
|
@ -152,6 +153,7 @@ public class ItemFilter extends ItemStackHandler {
|
|||
}
|
||||
|
||||
public interface IFilteredContainer {
|
||||
|
||||
ItemFilter getFilter();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,17 @@
|
|||
package de.ellpeck.prettypipes.misc;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ItemTerminalWidget extends Widget {
|
||||
public class ItemTerminalWidget extends AbstractWidget {
|
||||
|
||||
private final ItemTerminalGui screen;
|
||||
public final int gridX;
|
||||
|
@ -30,7 +21,7 @@ public class ItemTerminalWidget extends Widget {
|
|||
public boolean craftable;
|
||||
|
||||
public ItemTerminalWidget(int xIn, int yIn, int gridX, int gridY, ItemTerminalGui screen) {
|
||||
super(xIn, yIn, 16, 16, new StringTextComponent(""));
|
||||
super(xIn, yIn, 16, 16, new TextComponent(""));
|
||||
this.gridX = gridX;
|
||||
this.gridY = gridY;
|
||||
this.screen = screen;
|
||||
|
@ -44,25 +35,25 @@ public class ItemTerminalWidget extends Widget {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderButton(MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
Minecraft mc = this.screen.getMinecraft();
|
||||
ItemRenderer renderer = mc.getItemRenderer();
|
||||
public void renderButton(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
var mc = this.screen.getMinecraft();
|
||||
var renderer = mc.getItemRenderer();
|
||||
this.setBlitOffset(100);
|
||||
renderer.zLevel = 100;
|
||||
renderer.blitOffset = 100;
|
||||
if (this.selected)
|
||||
fill(matrix, this.x, this.y, this.x + 16, this.y + 16, -2130706433);
|
||||
RenderSystem.enableDepthTest();
|
||||
renderer.renderItemAndEffectIntoGUI(mc.player, this.stack, this.x, this.y);
|
||||
int amount = !this.craftable ? this.stack.getCount() : 0;
|
||||
String amountStrg = this.stack.getCount() >= 1000 ? amount / 1000 + "k" : String.valueOf(amount);
|
||||
RenderSystem.pushMatrix();
|
||||
RenderSystem.scalef(0.8F, 0.8F, 1);
|
||||
renderer.renderItemOverlayIntoGUI(mc.fontRenderer, this.stack, (int) (this.x / 0.8F) + 4, (int) (this.y / 0.8F) + 4, amountStrg);
|
||||
RenderSystem.popMatrix();
|
||||
renderer.zLevel = 0;
|
||||
renderer.renderGuiItem(this.stack, this.x, this.y);
|
||||
var amount = !this.craftable ? this.stack.getCount() : 0;
|
||||
var amountStrg = this.stack.getCount() >= 1000 ? amount / 1000 + "k" : String.valueOf(amount);
|
||||
matrix.pushPose();
|
||||
matrix.scale(0.8F, 0.8F, 1);
|
||||
renderer.renderGuiItemDecorations(mc.font, this.stack, (int) (this.x / 0.8F) + 4, (int) (this.y / 0.8F) + 4, amountStrg);
|
||||
matrix.popPose();
|
||||
renderer.blitOffset = 0;
|
||||
this.setBlitOffset(0);
|
||||
|
||||
if (this.isHovered()) {
|
||||
if (this.isHoveredOrFocused()) {
|
||||
RenderSystem.disableDepthTest();
|
||||
RenderSystem.colorMask(true, true, true, false);
|
||||
this.fillGradient(matrix, this.x, this.y, this.x + 16, this.y + 16, -2130706433, -2130706433);
|
||||
|
@ -72,18 +63,21 @@ public class ItemTerminalWidget extends Widget {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderToolTip(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
if (this.visible && this.isHovered()) {
|
||||
GuiUtils.preItemToolTip(this.stack);
|
||||
List<ITextComponent> tooltip = this.screen.getTooltipFromItem(this.stack);
|
||||
public void renderToolTip(PoseStack matrix, int mouseX, int mouseY) {
|
||||
if (this.visible && this.isHoveredOrFocused()) {
|
||||
var tooltip = this.screen.getTooltipFromItem(this.stack);
|
||||
if (this.stack.getCount() >= 1000) {
|
||||
ITextComponent comp = tooltip.get(0);
|
||||
if (comp instanceof TextComponent) {
|
||||
tooltip.set(0, ((TextComponent) comp).append(new StringTextComponent(" (" + this.stack.getCount() + ')').mergeStyle(TextFormatting.BOLD)));
|
||||
var comp = tooltip.get(0);
|
||||
if (comp instanceof TextComponent text) {
|
||||
tooltip.set(0, text.append(new TextComponent(" (" + this.stack.getCount() + ')').withStyle(ChatFormatting.BOLD)));
|
||||
}
|
||||
}
|
||||
this.screen.func_243308_b(matrix, tooltip, mouseX, mouseY);
|
||||
GuiUtils.postItemToolTip();
|
||||
this.screen.renderTooltip(matrix, tooltip, Optional.empty(), mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNarration(NarrationElementOutput output) {
|
||||
this.defaultButtonNarrationText(output);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PlayerPrefs {
|
||||
|
||||
|
@ -18,10 +20,10 @@ public class PlayerPrefs {
|
|||
public boolean syncJei = true;
|
||||
|
||||
public void save() {
|
||||
File file = getFile();
|
||||
var file = getFile();
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
try (var writer = new FileWriter(file)) {
|
||||
GSON.toJson(this, writer);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -30,9 +32,9 @@ public class PlayerPrefs {
|
|||
|
||||
public static PlayerPrefs get() {
|
||||
if (instance == null) {
|
||||
File file = getFile();
|
||||
var file = getFile();
|
||||
if (file.exists()) {
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
try (var reader = new FileReader(file)) {
|
||||
instance = GSON.fromJson(reader, PlayerPrefs.class);
|
||||
return instance;
|
||||
} catch (IOException e) {
|
||||
|
@ -45,7 +47,7 @@ public class PlayerPrefs {
|
|||
}
|
||||
|
||||
private static File getFile() {
|
||||
File location = Minecraft.getInstance().gameDir;
|
||||
var location = Minecraft.getInstance().gameDirectory;
|
||||
return new File(location, PrettyPipes.ID + "prefs");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
|
|||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
ListTag list = new ListTag();
|
||||
for (BlockPos pos : this.pipes)
|
||||
var nbt = new CompoundTag();
|
||||
var list = new ListTag();
|
||||
for (var pos : this.pipes)
|
||||
list.add(NbtUtils.writeBlockPos(pos));
|
||||
nbt.put("pipes", list);
|
||||
return nbt;
|
||||
|
@ -43,8 +43,8 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
|
|||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.pipes.clear();
|
||||
ListTag list = nbt.getList("pipes", Tag.TAG_COMPOUND);
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
var list = nbt.getList("pipes", Tag.TAG_COMPOUND);
|
||||
for (var i = 0; i < list.size(); i++)
|
||||
this.pipes.add(NbtUtils.readBlockPos(list.getCompound(i)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class NetworkItem {
|
|||
}
|
||||
|
||||
public ItemStack asStack() {
|
||||
ItemStack stack = this.item.stack.copy();
|
||||
var stack = this.item.stack().copy();
|
||||
stack.setCount(this.amount);
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package de.ellpeck.prettypipes.network;
|
||||
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
|
|||
this.deserializeNBT(nbt);
|
||||
}
|
||||
|
||||
public List<Integer> getStackSlots(World world, ItemStack stack, ItemEquality... equalityTypes) {
|
||||
public List<Integer> getStackSlots(Level world, ItemStack stack, ItemEquality... equalityTypes) {
|
||||
if (this.isEmpty(world))
|
||||
return Collections.emptyList();
|
||||
return this.getItems(world).entrySet().stream()
|
||||
|
@ -41,7 +41,7 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
|
|||
.map(Map.Entry::getKey).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public int getItemAmount(World world, ItemStack stack, ItemEquality... equalityTypes) {
|
||||
public int getItemAmount(Level world, ItemStack stack, ItemEquality... equalityTypes) {
|
||||
if (this.isEmpty(world))
|
||||
return 0;
|
||||
return this.getItems(world).entrySet().stream()
|
||||
|
@ -49,12 +49,12 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
|
|||
.mapToInt(kv -> kv.getValue().getCount()).sum();
|
||||
}
|
||||
|
||||
public Map<Integer, ItemStack> getItems(World world) {
|
||||
public Map<Integer, ItemStack> getItems(Level world) {
|
||||
if (this.itemCache == null) {
|
||||
IItemHandler handler = this.getItemHandler(world);
|
||||
var handler = this.getItemHandler(world);
|
||||
if (handler != null) {
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
ItemStack stack = handler.getStackInSlot(i);
|
||||
for (var i = 0; i < handler.getSlots(); i++) {
|
||||
var stack = handler.getStackInSlot(i);
|
||||
// check if the slot is accessible to us
|
||||
if (stack.isEmpty())
|
||||
continue;
|
||||
|
@ -68,40 +68,40 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
|
|||
return this.itemCache;
|
||||
}
|
||||
|
||||
public boolean canExtract(World world, int slot) {
|
||||
IItemHandler handler = this.getItemHandler(world);
|
||||
public boolean canExtract(Level world, int slot) {
|
||||
var handler = this.getItemHandler(world);
|
||||
return handler != null && !handler.extractItem(slot, 1, true).isEmpty();
|
||||
}
|
||||
|
||||
public IItemHandler getItemHandler(World world) {
|
||||
public IItemHandler getItemHandler(Level world) {
|
||||
if (this.handlerCache == null) {
|
||||
PipeNetwork network = PipeNetwork.get(world);
|
||||
PipeTileEntity pipe = network.getPipe(this.pipePos);
|
||||
var network = PipeNetwork.get(world);
|
||||
var pipe = network.getPipe(this.pipePos);
|
||||
this.handlerCache = pipe.getItemHandler(this.direction);
|
||||
}
|
||||
return this.handlerCache;
|
||||
}
|
||||
|
||||
public boolean isEmpty(World world) {
|
||||
Map<Integer, ItemStack> items = this.getItems(world);
|
||||
public boolean isEmpty(Level world) {
|
||||
var items = this.getItems(world);
|
||||
return items == null || items.isEmpty();
|
||||
}
|
||||
|
||||
public BlockPos getPos() {
|
||||
return this.pipePos.offset(this.direction);
|
||||
return this.pipePos.relative(this.direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.put("pipe_pos", NBTUtil.writeBlockPos(this.pipePos));
|
||||
nbt.putInt("direction", this.direction.getIndex());
|
||||
var nbt = new CompoundTag();
|
||||
nbt.put("pipe_pos", NbtUtils.writeBlockPos(this.pipePos));
|
||||
nbt.putInt("direction", this.direction.ordinal());
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.pipePos = NBTUtil.readBlockPos(nbt.getCompound("pipe_pos"));
|
||||
this.direction = Direction.byIndex(nbt.getInt("direction"));
|
||||
this.pipePos = NbtUtils.readBlockPos(nbt.getCompound("pipe_pos"));
|
||||
this.direction = Direction.values()[(nbt.getInt("direction"))];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package de.ellpeck.prettypipes.network;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -27,26 +26,24 @@ public class NetworkLock implements INBTSerializable<CompoundTag> {
|
|||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.putUniqueId("id", this.lockId);
|
||||
var nbt = new CompoundTag();
|
||||
nbt.putUUID("id", this.lockId);
|
||||
nbt.put("location", this.location.serializeNBT());
|
||||
nbt.put("stack", this.stack.write(new CompoundTag()));
|
||||
nbt.put("stack", this.stack.save(new CompoundTag()));
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.lockId = nbt.getUniqueId("id");
|
||||
this.lockId = nbt.getUUID("id");
|
||||
this.location = new NetworkLocation(nbt.getCompound("location"));
|
||||
this.stack = ItemStack.read(nbt.getCompound("stack"));
|
||||
this.stack = ItemStack.of(nbt.getCompound("stack"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof NetworkLock) {
|
||||
NetworkLock that = (NetworkLock) o;
|
||||
if (o instanceof NetworkLock that)
|
||||
return this.lockId.equals(that.lockId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,33 +1,29 @@
|
|||
package de.ellpeck.prettypipes.network;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeItem;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import org.jgrapht.Graph;
|
||||
import org.jgrapht.GraphPath;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -88,35 +84,35 @@ public class PipeItem implements IPipeItem {
|
|||
|
||||
// initialize position if new
|
||||
if (this.x == 0 && this.y == 0 && this.z == 0) {
|
||||
this.x = MathHelper.lerp(0.5F, startInventory.getX(), this.currGoalPos.getX()) + 0.5F;
|
||||
this.y = MathHelper.lerp(0.5F, startInventory.getY(), this.currGoalPos.getY()) + 0.5F;
|
||||
this.z = MathHelper.lerp(0.5F, startInventory.getZ(), this.currGoalPos.getZ()) + 0.5F;
|
||||
this.x = Mth.lerp(0.5F, startInventory.getX(), this.currGoalPos.getX()) + 0.5F;
|
||||
this.y = Mth.lerp(0.5F, startInventory.getY(), this.currGoalPos.getY()) + 0.5F;
|
||||
this.z = Mth.lerp(0.5F, startInventory.getZ(), this.currGoalPos.getZ()) + 0.5F;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateInPipe(PipeTileEntity currPipe) {
|
||||
public void updateInPipe(PipeBlockEntity currPipe) {
|
||||
// this prevents pipes being updated after one another
|
||||
// causing an item that just switched to tick twice
|
||||
long worldTick = currPipe.getWorld().getGameTime();
|
||||
var worldTick = currPipe.getLevel().getGameTime();
|
||||
if (this.lastWorldTick == worldTick)
|
||||
return;
|
||||
this.lastWorldTick = worldTick;
|
||||
|
||||
float motionLeft = this.speed;
|
||||
var motionLeft = this.speed;
|
||||
while (motionLeft > 0) {
|
||||
float currSpeed = Math.min(0.25F, motionLeft);
|
||||
var currSpeed = Math.min(0.25F, motionLeft);
|
||||
motionLeft -= currSpeed;
|
||||
|
||||
BlockPos myPos = new BlockPos(this.x, this.y, this.z);
|
||||
if (!myPos.equals(currPipe.getPos()) && (currPipe.getPos().equals(this.getDestPipe()) || !myPos.equals(this.startInventory))) {
|
||||
var myPos = new BlockPos(this.x, this.y, this.z);
|
||||
if (!myPos.equals(currPipe.getBlockPos()) && (currPipe.getBlockPos().equals(this.getDestPipe()) || !myPos.equals(this.startInventory))) {
|
||||
// we're done with the current pipe, so switch to the next one
|
||||
currPipe.getItems().remove(this);
|
||||
PipeTileEntity next = this.getNextTile(currPipe, true);
|
||||
var next = this.getNextTile(currPipe, true);
|
||||
if (next == null) {
|
||||
if (!currPipe.getWorld().isRemote) {
|
||||
if (currPipe.getPos().equals(this.getDestPipe())) {
|
||||
// ..or store in our destination container if we reached our destination
|
||||
if (!currPipe.getLevel().isClientSide) {
|
||||
if (currPipe.getBlockPos().equals(this.getDestPipe())) {
|
||||
// ...or store in our destination container if we reached our destination
|
||||
this.stack = this.store(currPipe);
|
||||
if (!this.stack.isEmpty())
|
||||
this.onPathObstructed(currPipe, true);
|
||||
|
@ -130,29 +126,29 @@ public class PipeItem implements IPipeItem {
|
|||
currPipe = next;
|
||||
}
|
||||
} else {
|
||||
double dist = Vector3d.copy(this.currGoalPos).squareDistanceTo(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F);
|
||||
var dist = (this.currGoalPos).distSqr(this.x - 0.5F, this.y - 0.5F, this.z - 0.5F, false);
|
||||
if (dist < currSpeed * currSpeed) {
|
||||
// we're past the start of the pipe, so move to the center of the next pipe
|
||||
BlockPos nextPos;
|
||||
PipeTileEntity next = this.getNextTile(currPipe, false);
|
||||
var next = this.getNextTile(currPipe, false);
|
||||
if (next == null || next == currPipe) {
|
||||
if (currPipe.getPos().equals(this.getDestPipe())) {
|
||||
if (currPipe.getBlockPos().equals(this.getDestPipe())) {
|
||||
nextPos = this.destInventory;
|
||||
} else {
|
||||
currPipe.getItems().remove(this);
|
||||
if (!currPipe.getWorld().isRemote)
|
||||
if (!currPipe.getLevel().isClientSide)
|
||||
this.onPathObstructed(currPipe, false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
nextPos = next.getPos();
|
||||
nextPos = next.getBlockPos();
|
||||
}
|
||||
float tolerance = 0.001F;
|
||||
var tolerance = 0.001F;
|
||||
if (dist >= tolerance * tolerance) {
|
||||
// when going around corners, we want to move right up to the corner
|
||||
Vector3d motion = new Vector3d(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ);
|
||||
Vector3d diff = new Vector3d(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z);
|
||||
if (motion.crossProduct(diff).length() >= tolerance) {
|
||||
var motion = new Vec3(this.x - this.lastX, this.y - this.lastY, this.z - this.lastZ);
|
||||
var diff = new Vec3(nextPos.getX() + 0.5F - this.x, nextPos.getY() + 0.5F - this.y, nextPos.getZ() + 0.5F - this.z);
|
||||
if (motion.cross(diff).length() >= tolerance) {
|
||||
currSpeed = (float) Math.sqrt(dist);
|
||||
} else {
|
||||
// we're not going around a corner, so continue
|
||||
|
@ -169,7 +165,7 @@ public class PipeItem implements IPipeItem {
|
|||
this.lastY = this.y;
|
||||
this.lastZ = this.z;
|
||||
|
||||
Vector3d dist = new Vector3d(this.currGoalPos.getX() + 0.5F - this.x, this.currGoalPos.getY() + 0.5F - this.y, this.currGoalPos.getZ() + 0.5F - this.z);
|
||||
var dist = new Vec3(this.currGoalPos.getX() + 0.5F - this.x, this.currGoalPos.getY() + 0.5F - this.y, this.currGoalPos.getZ() + 0.5F - this.z);
|
||||
dist = dist.normalize();
|
||||
this.x += dist.x * currSpeed;
|
||||
this.y += dist.y * currSpeed;
|
||||
|
@ -177,50 +173,50 @@ public class PipeItem implements IPipeItem {
|
|||
}
|
||||
}
|
||||
|
||||
protected void onPathObstructed(PipeTileEntity currPipe, boolean tryReturn) {
|
||||
if (currPipe.getWorld().isRemote)
|
||||
protected void onPathObstructed(PipeBlockEntity currPipe, boolean tryReturn) {
|
||||
if (currPipe.getLevel().isClientSide)
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(currPipe.getWorld());
|
||||
var network = PipeNetwork.get(currPipe.getLevel());
|
||||
if (tryReturn) {
|
||||
// first time: we try to return to our input chest
|
||||
if (!this.retryOnObstruction && network.routeItemToLocation(currPipe.getPos(), this.destInventory, this.getStartPipe(), this.startInventory, this.stack, speed -> this)) {
|
||||
if (!this.retryOnObstruction && network.routeItemToLocation(currPipe.getBlockPos(), this.destInventory, this.getStartPipe(), this.startInventory, this.stack, speed -> this)) {
|
||||
this.retryOnObstruction = true;
|
||||
return;
|
||||
}
|
||||
// second time: we arrived at our input chest, it is full, so we try to find a different goal location
|
||||
ItemStack remain = network.routeItem(currPipe.getPos(), this.destInventory, this.stack, (stack, speed) -> this, false);
|
||||
var remain = network.routeItem(currPipe.getBlockPos(), this.destInventory, this.stack, (stack, speed) -> this, false);
|
||||
if (!remain.isEmpty())
|
||||
this.drop(currPipe.getWorld(), remain.copy());
|
||||
this.drop(currPipe.getLevel(), remain.copy());
|
||||
} else {
|
||||
// if all re-routing attempts fail, we drop
|
||||
this.drop(currPipe.getWorld(), this.stack);
|
||||
this.drop(currPipe.getLevel(), this.stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(World world, ItemStack stack) {
|
||||
ItemEntity item = new ItemEntity(world, this.x, this.y, this.z, stack.copy());
|
||||
item.world.addEntity(item);
|
||||
public void drop(Level world, ItemStack stack) {
|
||||
var item = new ItemEntity(world, this.x, this.y, this.z, stack.copy());
|
||||
item.level.addFreshEntity(item);
|
||||
}
|
||||
|
||||
protected ItemStack store(PipeTileEntity currPipe) {
|
||||
Direction dir = Utility.getDirectionFromOffset(this.destInventory, this.getDestPipe());
|
||||
IPipeConnectable connectable = currPipe.getPipeConnectable(dir);
|
||||
protected ItemStack store(PipeBlockEntity currPipe) {
|
||||
var dir = Utility.getDirectionFromOffset(this.destInventory, this.getDestPipe());
|
||||
var connectable = currPipe.getPipeConnectable(dir);
|
||||
if (connectable != null)
|
||||
return connectable.insertItem(currPipe.getPos(), dir, this.stack, false);
|
||||
IItemHandler handler = currPipe.getItemHandler(dir);
|
||||
return connectable.insertItem(currPipe.getBlockPos(), dir, this.stack, false);
|
||||
var handler = currPipe.getItemHandler(dir);
|
||||
if (handler != null)
|
||||
return ItemHandlerHelper.insertItemStacked(handler, this.stack, false);
|
||||
return this.stack;
|
||||
}
|
||||
|
||||
protected PipeTileEntity getNextTile(PipeTileEntity currPipe, boolean progress) {
|
||||
protected PipeBlockEntity getNextTile(PipeBlockEntity currPipe, boolean progress) {
|
||||
if (this.path.size() <= this.currentTile + 1)
|
||||
return null;
|
||||
BlockPos pos = this.path.get(this.currentTile + 1);
|
||||
var pos = this.path.get(this.currentTile + 1);
|
||||
if (progress)
|
||||
this.currentTile++;
|
||||
PipeNetwork network = PipeNetwork.get(currPipe.getWorld());
|
||||
var network = PipeNetwork.get(currPipe.getLevel());
|
||||
return network.getPipe(pos);
|
||||
}
|
||||
|
||||
|
@ -245,41 +241,41 @@ public class PipeItem implements IPipeItem {
|
|||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
var nbt = new CompoundTag();
|
||||
nbt.putString("type", this.type.toString());
|
||||
nbt.put("stack", this.stack.serializeNBT());
|
||||
nbt.putFloat("speed", this.speed);
|
||||
nbt.put("start_inv", NBTUtil.writeBlockPos(this.startInventory));
|
||||
nbt.put("dest_inv", NBTUtil.writeBlockPos(this.destInventory));
|
||||
nbt.put("curr_goal", NBTUtil.writeBlockPos(this.currGoalPos));
|
||||
nbt.put("start_inv", NbtUtils.writeBlockPos(this.startInventory));
|
||||
nbt.put("dest_inv", NbtUtils.writeBlockPos(this.destInventory));
|
||||
nbt.put("curr_goal", NbtUtils.writeBlockPos(this.currGoalPos));
|
||||
nbt.putBoolean("drop_on_obstruction", this.retryOnObstruction);
|
||||
nbt.putInt("tile", this.currentTile);
|
||||
nbt.putFloat("x", this.x);
|
||||
nbt.putFloat("y", this.y);
|
||||
nbt.putFloat("z", this.z);
|
||||
ListTag list = new ListTag();
|
||||
for (BlockPos pos : this.path)
|
||||
list.add(NBTUtil.writeBlockPos(pos));
|
||||
var list = new ListTag();
|
||||
for (var pos : this.path)
|
||||
list.add(NbtUtils.writeBlockPos(pos));
|
||||
nbt.put("path", list);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
this.stack = ItemStack.read(nbt.getCompound("stack"));
|
||||
this.stack = ItemStack.of(nbt.getCompound("stack"));
|
||||
this.speed = nbt.getFloat("speed");
|
||||
this.startInventory = NBTUtil.readBlockPos(nbt.getCompound("start_inv"));
|
||||
this.destInventory = NBTUtil.readBlockPos(nbt.getCompound("dest_inv"));
|
||||
this.currGoalPos = NBTUtil.readBlockPos(nbt.getCompound("curr_goal"));
|
||||
this.startInventory = NbtUtils.readBlockPos(nbt.getCompound("start_inv"));
|
||||
this.destInventory = NbtUtils.readBlockPos(nbt.getCompound("dest_inv"));
|
||||
this.currGoalPos = NbtUtils.readBlockPos(nbt.getCompound("curr_goal"));
|
||||
this.retryOnObstruction = nbt.getBoolean("drop_on_obstruction");
|
||||
this.currentTile = nbt.getInt("tile");
|
||||
this.x = nbt.getFloat("x");
|
||||
this.y = nbt.getFloat("y");
|
||||
this.z = nbt.getFloat("z");
|
||||
this.path.clear();
|
||||
ListTag list = nbt.getList("path", Constants.NBT.TAG_COMPOUND);
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
this.path.add(NBTUtil.readBlockPos(list.getCompound(i)));
|
||||
var list = nbt.getList("path", Tag.TAG_COMPOUND);
|
||||
for (var i = 0; i < list.size(); i++)
|
||||
this.path.add(NbtUtils.readBlockPos(list.getCompound(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -289,40 +285,40 @@ public class PipeItem implements IPipeItem {
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void render(PipeTileEntity tile, MatrixStack matrixStack, Random random, float partialTicks, int light, int overlay, IRenderTypeBuffer buffer) {
|
||||
public void render(PipeBlockEntity tile, PoseStack matrixStack, Random random, float partialTicks, int light, int overlay, MultiBufferSource source) {
|
||||
matrixStack.translate(
|
||||
MathHelper.lerp(partialTicks, this.lastX, this.x),
|
||||
MathHelper.lerp(partialTicks, this.lastY, this.y),
|
||||
MathHelper.lerp(partialTicks, this.lastZ, this.z));
|
||||
Mth.lerp(partialTicks, this.lastX, this.x),
|
||||
Mth.lerp(partialTicks, this.lastY, this.y),
|
||||
Mth.lerp(partialTicks, this.lastZ, this.z));
|
||||
|
||||
if (this.stack.getItem() instanceof BlockItem) {
|
||||
float scale = 0.7F;
|
||||
var scale = 0.7F;
|
||||
matrixStack.scale(scale, scale, scale);
|
||||
matrixStack.translate(0, -0.2F, 0);
|
||||
} else {
|
||||
float scale = 0.45F;
|
||||
var scale = 0.45F;
|
||||
matrixStack.scale(scale, scale, scale);
|
||||
matrixStack.translate(0, -0.1F, 0);
|
||||
}
|
||||
|
||||
random.setSeed(Item.getIdFromItem(this.stack.getItem()) + this.stack.getDamage());
|
||||
int amount = this.getModelCount();
|
||||
random.setSeed(Item.getId(this.stack.getItem()) + this.stack.getDamageValue());
|
||||
var amount = this.getModelCount();
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
matrixStack.push();
|
||||
for (var i = 0; i < amount; i++) {
|
||||
matrixStack.pushPose();
|
||||
if (amount > 1) {
|
||||
matrixStack.translate(
|
||||
(random.nextFloat() * 2.0F - 1.0F) * 0.25F * 0.5F,
|
||||
(random.nextFloat() * 2.0F - 1.0F) * 0.25F * 0.5F,
|
||||
(random.nextFloat() * 2.0F - 1.0F) * 0.25F * 0.5F);
|
||||
}
|
||||
Minecraft.getInstance().getItemRenderer().renderItem(this.stack, ItemCameraTransforms.TransformType.GROUND, light, overlay, matrixStack, buffer);
|
||||
matrixStack.pop();
|
||||
Minecraft.getInstance().getItemRenderer().renderStatic(this.stack, ItemTransforms.TransformType.GROUND, light, overlay, matrixStack, source, 0);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getModelCount() {
|
||||
int i = 1;
|
||||
var i = 1;
|
||||
if (this.stack.getCount() > 48) {
|
||||
i = 5;
|
||||
} else if (this.stack.getCount() > 32) {
|
||||
|
@ -336,32 +332,32 @@ public class PipeItem implements IPipeItem {
|
|||
}
|
||||
|
||||
protected static List<BlockPos> compilePath(GraphPath<BlockPos, NetworkEdge> path) {
|
||||
Graph<BlockPos, NetworkEdge> graph = path.getGraph();
|
||||
var graph = path.getGraph();
|
||||
List<BlockPos> ret = new ArrayList<>();
|
||||
List<BlockPos> nodes = path.getVertexList();
|
||||
var nodes = path.getVertexList();
|
||||
if (nodes.size() == 1) {
|
||||
// add the single pipe twice if there's only one
|
||||
// this is a dirty hack but it works fine so eh
|
||||
for (int i = 0; i < 2; i++)
|
||||
// this is a dirty hack, but it works fine so eh
|
||||
for (var i = 0; i < 2; i++)
|
||||
ret.add(nodes.get(0));
|
||||
return ret;
|
||||
}
|
||||
for (int i = 0; i < nodes.size() - 1; i++) {
|
||||
BlockPos first = nodes.get(i);
|
||||
BlockPos second = nodes.get(i + 1);
|
||||
NetworkEdge edge = graph.getEdge(first, second);
|
||||
Consumer<Integer> add = j -> {
|
||||
BlockPos pos = edge.pipes.get(j);
|
||||
for (var i = 0; i < nodes.size() - 1; i++) {
|
||||
var first = nodes.get(i);
|
||||
var second = nodes.get(i + 1);
|
||||
var edge = graph.getEdge(first, second);
|
||||
var add = (Consumer<Integer>) j -> {
|
||||
var pos = edge.pipes.get(j);
|
||||
if (!ret.contains(pos))
|
||||
ret.add(pos);
|
||||
};
|
||||
// if the edge is the other way around, we need to loop through tiles
|
||||
// the other way also
|
||||
if (!graph.getEdgeSource(edge).equals(first)) {
|
||||
for (int j = edge.pipes.size() - 1; j >= 0; j--)
|
||||
for (var j = edge.pipes.size() - 1; j >= 0; j--)
|
||||
add.accept(j);
|
||||
} else {
|
||||
for (int j = 0; j < edge.pipes.size(); j++)
|
||||
for (var j = 0; j < edge.pipes.size(); j++)
|
||||
add.accept(j);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,29 +11,21 @@ import de.ellpeck.prettypipes.packets.PacketHandler;
|
|||
import de.ellpeck.prettypipes.packets.PacketItemEnterPipe;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeItem;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.jgrapht.GraphPath;
|
||||
import org.jgrapht.ListenableGraph;
|
||||
import org.jgrapht.alg.interfaces.ShortestPathAlgorithm;
|
||||
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
|
||||
import org.jgrapht.event.GraphEdgeChangeEvent;
|
||||
import org.jgrapht.event.GraphListener;
|
||||
|
@ -56,7 +48,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public final ListenableGraph<BlockPos, NetworkEdge> graph;
|
||||
private final DijkstraShortestPath<BlockPos, NetworkEdge> dijkstra;
|
||||
private final Map<BlockPos, List<BlockPos>> nodeToConnectedNodes = new HashMap<>();
|
||||
private final Map<BlockPos, PipeTileEntity> tileCache = new HashMap<>();
|
||||
private final Map<BlockPos, PipeBlockEntity> tileCache = new HashMap<>();
|
||||
private final ListMultimap<BlockPos, IPipeItem> pipeItems = ArrayListMultimap.create();
|
||||
private final ListMultimap<BlockPos, NetworkLock> networkLocks = ArrayListMultimap.create();
|
||||
private final Level world;
|
||||
|
@ -77,13 +69,13 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
ListTag nodes = new ListTag();
|
||||
for (BlockPos node : this.graph.vertexSet())
|
||||
var nbt = new CompoundTag();
|
||||
var nodes = new ListTag();
|
||||
for (var node : this.graph.vertexSet())
|
||||
nodes.add(NbtUtils.writeBlockPos(node));
|
||||
nbt.put("nodes", nodes);
|
||||
ListTag edges = new ListTag();
|
||||
for (NetworkEdge edge : this.graph.edgeSet())
|
||||
var edges = new ListTag();
|
||||
for (var edge : this.graph.edgeSet())
|
||||
edges.add(edge.serializeNBT());
|
||||
nbt.put("edges", edges);
|
||||
nbt.put("items", Utility.serializeAll(this.pipeItems.values()));
|
||||
|
@ -97,15 +89,15 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
this.pipeItems.clear();
|
||||
this.networkLocks.clear();
|
||||
|
||||
ListTag nodes = nbt.getList("nodes", Tag.TAG_COMPOUND);
|
||||
for (int i = 0; i < nodes.size(); i++)
|
||||
this.graph.addVertex(NBTUtil.readBlockPos(nodes.getCompound(i)));
|
||||
ListTag edges = nbt.getList("edges", Tag.TAG_COMPOUND);
|
||||
for (int i = 0; i < edges.size(); i++)
|
||||
var nodes = nbt.getList("nodes", Tag.TAG_COMPOUND);
|
||||
for (var i = 0; i < nodes.size(); i++)
|
||||
this.graph.addVertex(NbtUtils.readBlockPos(nodes.getCompound(i)));
|
||||
var edges = nbt.getList("edges", Tag.TAG_COMPOUND);
|
||||
for (var i = 0; i < edges.size(); i++)
|
||||
this.addEdge(new NetworkEdge(edges.getCompound(i)));
|
||||
for (IPipeItem item : Utility.deserializeAll(nbt.getList("items", NBT.TAG_COMPOUND), IPipeItem::load))
|
||||
for (var item : Utility.deserializeAll(nbt.getList("items", Tag.TAG_COMPOUND), IPipeItem::load))
|
||||
this.pipeItems.put(item.getCurrentPipe(), item);
|
||||
for (NetworkLock lock : Utility.deserializeAll(nbt.getList("locks", NBT.TAG_COMPOUND), NetworkLock::new))
|
||||
for (var lock : Utility.deserializeAll(nbt.getList("locks", Tag.TAG_COMPOUND), NetworkLock::new))
|
||||
this.createNetworkLock(lock);
|
||||
}
|
||||
|
||||
|
@ -126,12 +118,12 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
}
|
||||
|
||||
public void onPipeChanged(BlockPos pos, BlockState state) {
|
||||
List<NetworkEdge> neighbors = this.createAllEdges(pos, state, true);
|
||||
var neighbors = this.createAllEdges(pos, state, true);
|
||||
// if we only have one neighbor, then there can't be any new connections
|
||||
if (neighbors.size() <= 1 && !this.isNode(pos))
|
||||
return;
|
||||
for (NetworkEdge edge : neighbors) {
|
||||
BlockPos end = edge.getEndPipe();
|
||||
for (var edge : neighbors) {
|
||||
var end = edge.getEndPipe();
|
||||
this.refreshNode(end, this.world.getBlockState(end));
|
||||
}
|
||||
}
|
||||
|
@ -143,24 +135,24 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public ItemStack routeItem(BlockPos startPipePos, BlockPos startInventory, ItemStack stack, BiFunction<ItemStack, Float, IPipeItem> itemSupplier, boolean preventOversending) {
|
||||
if (!this.isNode(startPipePos))
|
||||
return stack;
|
||||
if (!this.world.isBlockLoaded(startPipePos))
|
||||
if (!this.world.isLoaded(startPipePos))
|
||||
return stack;
|
||||
PipeTileEntity startPipe = this.getPipe(startPipePos);
|
||||
var startPipe = this.getPipe(startPipePos);
|
||||
if (startPipe == null)
|
||||
return stack;
|
||||
this.startProfile("find_destination");
|
||||
List<BlockPos> nodes = this.getOrderedNetworkNodes(startPipePos);
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
BlockPos pipePos = nodes.get(startPipe.getNextNode(nodes, i));
|
||||
if (!this.world.isBlockLoaded(pipePos))
|
||||
var nodes = this.getOrderedNetworkNodes(startPipePos);
|
||||
for (var i = 0; i < nodes.size(); i++) {
|
||||
var pipePos = nodes.get(startPipe.getNextNode(nodes, i));
|
||||
if (!this.world.isLoaded(pipePos))
|
||||
continue;
|
||||
PipeTileEntity pipe = this.getPipe(pipePos);
|
||||
Pair<BlockPos, ItemStack> dest = pipe.getAvailableDestination(stack, false, preventOversending);
|
||||
var pipe = this.getPipe(pipePos);
|
||||
var dest = pipe.getAvailableDestination(stack, false, preventOversending);
|
||||
if (dest == null || dest.getLeft().equals(startInventory))
|
||||
continue;
|
||||
Function<Float, IPipeItem> sup = speed -> itemSupplier.apply(dest.getRight(), speed);
|
||||
if (this.routeItemToLocation(startPipePos, startInventory, pipe.getPos(), dest.getLeft(), dest.getRight(), sup)) {
|
||||
ItemStack remain = stack.copy();
|
||||
var sup = (Function<Float, IPipeItem>) speed -> itemSupplier.apply(dest.getRight(), speed);
|
||||
if (this.routeItemToLocation(startPipePos, startInventory, pipe.getBlockPos(), dest.getLeft(), dest.getRight(), sup)) {
|
||||
var remain = stack.copy();
|
||||
remain.shrink(dest.getRight().getCount());
|
||||
this.endProfile();
|
||||
return remain;
|
||||
|
@ -173,17 +165,17 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public boolean routeItemToLocation(BlockPos startPipePos, BlockPos startInventory, BlockPos destPipePos, BlockPos destInventory, ItemStack stack, Function<Float, IPipeItem> itemSupplier) {
|
||||
if (!this.isNode(startPipePos) || !this.isNode(destPipePos))
|
||||
return false;
|
||||
if (!this.world.isBlockLoaded(startPipePos) || !this.world.isBlockLoaded(destPipePos))
|
||||
if (!this.world.isLoaded(startPipePos) || !this.world.isLoaded(destPipePos))
|
||||
return false;
|
||||
PipeTileEntity startPipe = this.getPipe(startPipePos);
|
||||
var startPipe = this.getPipe(startPipePos);
|
||||
if (startPipe == null)
|
||||
return false;
|
||||
this.startProfile("get_path");
|
||||
GraphPath<BlockPos, NetworkEdge> path = this.dijkstra.getPath(startPipePos, destPipePos);
|
||||
var path = this.dijkstra.getPath(startPipePos, destPipePos);
|
||||
this.endProfile();
|
||||
if (path == null)
|
||||
return false;
|
||||
IPipeItem item = itemSupplier.apply(startPipe.getItemSpeed(stack));
|
||||
var item = itemSupplier.apply(startPipe.getItemSpeed(stack));
|
||||
item.setDestination(startInventory, destInventory, path);
|
||||
startPipe.addNewItem(item);
|
||||
PacketHandler.sendToAllLoaded(this.world, startPipePos, new PacketItemEnterPipe(startPipePos, item));
|
||||
|
@ -191,9 +183,9 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
}
|
||||
|
||||
public ItemStack requestItem(BlockPos destPipe, BlockPos destInventory, ItemStack stack, ItemEquality... equalityTypes) {
|
||||
ItemStack remain = stack.copy();
|
||||
var remain = stack.copy();
|
||||
// check existing items
|
||||
for (NetworkLocation location : this.getOrderedNetworkItems(destPipe)) {
|
||||
for (var location : this.getOrderedNetworkItems(destPipe)) {
|
||||
remain = this.requestExistingItem(location, destPipe, destInventory, null, remain, equalityTypes);
|
||||
if (remain.isEmpty())
|
||||
return remain;
|
||||
|
@ -203,10 +195,10 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
}
|
||||
|
||||
public ItemStack requestCraftedItem(BlockPos destPipe, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain, ItemEquality... equalityTypes) {
|
||||
for (Pair<BlockPos, ItemStack> craftable : this.getAllCraftables(destPipe)) {
|
||||
for (var craftable : this.getAllCraftables(destPipe)) {
|
||||
if (!ItemEquality.compareItems(stack, craftable.getRight(), equalityTypes))
|
||||
continue;
|
||||
PipeTileEntity pipe = this.getPipe(craftable.getLeft());
|
||||
var pipe = this.getPipe(craftable.getLeft());
|
||||
if (pipe == null)
|
||||
continue;
|
||||
stack = pipe.craft(destPipe, unavailableConsumer, stack, dependencyChain);
|
||||
|
@ -224,21 +216,21 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
if (location.getPos().equals(destInventory))
|
||||
return stack;
|
||||
// make sure we don't pull any locked items
|
||||
int amount = location.getItemAmount(this.world, stack, equalityTypes);
|
||||
var amount = location.getItemAmount(this.world, stack, equalityTypes);
|
||||
if (amount <= 0)
|
||||
return stack;
|
||||
amount -= this.getLockedAmount(location.getPos(), stack, ignoredLock, equalityTypes);
|
||||
if (amount <= 0)
|
||||
return stack;
|
||||
ItemStack remain = stack.copy();
|
||||
var remain = stack.copy();
|
||||
// make sure we only extract less than or equal to the requested amount
|
||||
if (remain.getCount() < amount)
|
||||
amount = remain.getCount();
|
||||
remain.shrink(amount);
|
||||
for (int slot : location.getStackSlots(this.world, stack, equalityTypes)) {
|
||||
// try to extract from that location's inventory and send the item
|
||||
IItemHandler handler = location.getItemHandler(this.world);
|
||||
ItemStack extracted = handler.extractItem(slot, amount, true);
|
||||
var handler = location.getItemHandler(this.world);
|
||||
var extracted = handler.extractItem(slot, amount, true);
|
||||
if (this.routeItemToLocation(location.pipePos, location.getPos(), destPipe, destInventory, extracted, speed -> itemSupplier.apply(extracted, speed))) {
|
||||
handler.extractItem(slot, extracted.getCount(), false);
|
||||
amount -= extracted.getCount();
|
||||
|
@ -249,10 +241,10 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
return remain;
|
||||
}
|
||||
|
||||
public PipeTileEntity getPipe(BlockPos pos) {
|
||||
PipeTileEntity tile = this.tileCache.get(pos);
|
||||
public PipeBlockEntity getPipe(BlockPos pos) {
|
||||
var tile = this.tileCache.get(pos);
|
||||
if (tile == null || tile.isRemoved()) {
|
||||
tile = Utility.getBlockEntity(PipeTileEntity.class, this.world, pos);
|
||||
tile = Utility.getBlockEntity(PipeBlockEntity.class, this.world, pos);
|
||||
this.tileCache.put(pos, tile);
|
||||
}
|
||||
return tile;
|
||||
|
@ -265,14 +257,14 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public List<Pair<BlockPos, ItemStack>> getCurrentlyCrafting(BlockPos node, ItemEquality... equalityTypes) {
|
||||
this.startProfile("get_currently_crafting");
|
||||
List<Pair<BlockPos, ItemStack>> items = new ArrayList<>();
|
||||
Iterator<PipeTileEntity> craftingPipes = this.getAllCraftables(node).stream().map(c -> this.getPipe(c.getLeft())).distinct().iterator();
|
||||
var craftingPipes = this.getAllCraftables(node).stream().map(c -> this.getPipe(c.getLeft())).distinct().iterator();
|
||||
while (craftingPipes.hasNext()) {
|
||||
PipeTileEntity pipe = craftingPipes.next();
|
||||
for (Pair<BlockPos, ItemStack> request : pipe.craftResultRequests) {
|
||||
BlockPos dest = request.getLeft();
|
||||
ItemStack stack = request.getRight();
|
||||
var pipe = craftingPipes.next();
|
||||
for (var request : pipe.craftResultRequests) {
|
||||
var dest = request.getLeft();
|
||||
var stack = request.getRight();
|
||||
// add up all the items that should go to the same location
|
||||
Optional<Pair<BlockPos, ItemStack>> existing = items.stream()
|
||||
var existing = items.stream()
|
||||
.filter(s -> s.getLeft().equals(dest) && ItemEquality.compareItems(s.getRight(), stack, equalityTypes))
|
||||
.findFirst();
|
||||
if (existing.isPresent()) {
|
||||
|
@ -297,25 +289,25 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
return Collections.emptyList();
|
||||
this.startProfile("get_all_craftables");
|
||||
List<Pair<BlockPos, ItemStack>> craftables = new ArrayList<>();
|
||||
for (BlockPos dest : this.getOrderedNetworkNodes(node)) {
|
||||
if (!this.world.isBlockLoaded(dest))
|
||||
for (var dest : this.getOrderedNetworkNodes(node)) {
|
||||
if (!this.world.isLoaded(dest))
|
||||
continue;
|
||||
PipeTileEntity pipe = this.getPipe(dest);
|
||||
for (ItemStack stack : pipe.getAllCraftables())
|
||||
craftables.add(Pair.of(pipe.getPos(), stack));
|
||||
var pipe = this.getPipe(dest);
|
||||
for (var stack : pipe.getAllCraftables())
|
||||
craftables.add(Pair.of(pipe.getBlockPos(), stack));
|
||||
}
|
||||
this.endProfile();
|
||||
return craftables;
|
||||
}
|
||||
|
||||
public int getCraftableAmount(BlockPos node, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain, ItemEquality... equalityTypes) {
|
||||
int total = 0;
|
||||
for (Pair<BlockPos, ItemStack> pair : this.getAllCraftables(node)) {
|
||||
var total = 0;
|
||||
for (var pair : this.getAllCraftables(node)) {
|
||||
if (!ItemEquality.compareItems(pair.getRight(), stack, equalityTypes))
|
||||
continue;
|
||||
if (!this.world.isBlockLoaded(pair.getLeft()))
|
||||
if (!this.world.isLoaded(pair.getLeft()))
|
||||
continue;
|
||||
PipeTileEntity pipe = this.getPipe(pair.getLeft());
|
||||
var pipe = this.getPipe(pair.getLeft());
|
||||
if (pipe != null)
|
||||
total += pipe.getCraftableAmount(unavailableConsumer, stack, dependencyChain);
|
||||
}
|
||||
|
@ -327,20 +319,20 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
return Collections.emptyList();
|
||||
this.startProfile("get_network_items");
|
||||
List<NetworkLocation> info = new ArrayList<>();
|
||||
for (BlockPos dest : this.getOrderedNetworkNodes(node)) {
|
||||
if (!this.world.isBlockLoaded(dest))
|
||||
for (var dest : this.getOrderedNetworkNodes(node)) {
|
||||
if (!this.world.isLoaded(dest))
|
||||
continue;
|
||||
PipeTileEntity pipe = this.getPipe(dest);
|
||||
var pipe = this.getPipe(dest);
|
||||
if (!pipe.canNetworkSee())
|
||||
continue;
|
||||
for (Direction dir : Direction.values()) {
|
||||
IItemHandler handler = pipe.getItemHandler(dir);
|
||||
for (var dir : Direction.values()) {
|
||||
var handler = pipe.getItemHandler(dir);
|
||||
if (handler == null)
|
||||
continue;
|
||||
// check if this handler already exists (double-connected pipes, double chests etc.)
|
||||
if (info.stream().anyMatch(l -> handler.equals(l.getItemHandler(this.world))))
|
||||
continue;
|
||||
NetworkLocation location = new NetworkLocation(dest, dir);
|
||||
var location = new NetworkLocation(dest, dir);
|
||||
if (!location.isEmpty(this.world))
|
||||
info.add(location);
|
||||
}
|
||||
|
@ -370,7 +362,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
private void refreshNode(BlockPos pos, BlockState state) {
|
||||
this.startProfile("refresh_node");
|
||||
this.graph.removeAllEdges(new ArrayList<>(this.graph.edgesOf(pos)));
|
||||
for (NetworkEdge edge : this.createAllEdges(pos, state, false))
|
||||
for (var edge : this.createAllEdges(pos, state, false))
|
||||
this.addEdge(edge);
|
||||
this.endProfile();
|
||||
}
|
||||
|
@ -384,11 +376,11 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public BlockPos getNodeFromPipe(BlockPos pos) {
|
||||
if (this.isNode(pos))
|
||||
return pos;
|
||||
BlockState state = this.world.getBlockState(pos);
|
||||
var state = this.world.getBlockState(pos);
|
||||
if (!(state.getBlock() instanceof PipeBlock))
|
||||
return null;
|
||||
for (Direction dir : Direction.values()) {
|
||||
NetworkEdge edge = this.createEdge(pos, state, dir, false);
|
||||
for (var dir : Direction.values()) {
|
||||
var edge = this.createEdge(pos, state, dir, false);
|
||||
if (edge != null)
|
||||
return edge.getEndPipe();
|
||||
}
|
||||
|
@ -398,8 +390,8 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
private List<NetworkEdge> createAllEdges(BlockPos pos, BlockState state, boolean ignoreCurrBlocked) {
|
||||
this.startProfile("create_all_edges");
|
||||
List<NetworkEdge> edges = new ArrayList<>();
|
||||
for (Direction dir : Direction.values()) {
|
||||
NetworkEdge edge = this.createEdge(pos, state, dir, ignoreCurrBlocked);
|
||||
for (var dir : Direction.values()) {
|
||||
var edge = this.createEdge(pos, state, dir, ignoreCurrBlocked);
|
||||
if (edge != null)
|
||||
edges.add(edge);
|
||||
}
|
||||
|
@ -408,14 +400,14 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
}
|
||||
|
||||
private NetworkEdge createEdge(BlockPos pos, BlockState state, Direction dir, boolean ignoreCurrBlocked) {
|
||||
if (!ignoreCurrBlocked && !state.get(PipeBlock.DIRECTIONS.get(dir)).isConnected())
|
||||
if (!ignoreCurrBlocked && !state.getValue(PipeBlock.DIRECTIONS.get(dir)).isConnected())
|
||||
return null;
|
||||
BlockPos currPos = pos.offset(dir);
|
||||
BlockState currState = this.world.getBlockState(currPos);
|
||||
var currPos = pos.relative(dir);
|
||||
var currState = this.world.getBlockState(currPos);
|
||||
if (!(currState.getBlock() instanceof PipeBlock))
|
||||
return null;
|
||||
this.startProfile("create_edge");
|
||||
NetworkEdge edge = new NetworkEdge();
|
||||
var edge = new NetworkEdge();
|
||||
edge.pipes.add(pos);
|
||||
edge.pipes.add(currPos);
|
||||
|
||||
|
@ -427,12 +419,12 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
return edge;
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
for (Direction nextDir : Direction.values()) {
|
||||
if (!currState.get(PipeBlock.DIRECTIONS.get(nextDir)).isConnected())
|
||||
var found = false;
|
||||
for (var nextDir : Direction.values()) {
|
||||
if (!currState.getValue(PipeBlock.DIRECTIONS.get(nextDir)).isConnected())
|
||||
continue;
|
||||
BlockPos offset = currPos.offset(nextDir);
|
||||
BlockState offState = this.world.getBlockState(offset);
|
||||
var offset = currPos.relative(nextDir);
|
||||
var offState = this.world.getBlockState(offset);
|
||||
if (!(offState.getBlock() instanceof PipeBlock))
|
||||
continue;
|
||||
if (edge.pipes.contains(offset))
|
||||
|
@ -453,10 +445,10 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public List<BlockPos> getOrderedNetworkNodes(BlockPos node) {
|
||||
if (!this.isNode(node))
|
||||
return Collections.emptyList();
|
||||
List<BlockPos> ret = this.nodeToConnectedNodes.get(node);
|
||||
var ret = this.nodeToConnectedNodes.get(node);
|
||||
if (ret == null) {
|
||||
this.startProfile("compile_connected_nodes");
|
||||
ShortestPathAlgorithm.SingleSourcePaths<BlockPos, NetworkEdge> paths = this.dijkstra.getPaths(node);
|
||||
var paths = this.dijkstra.getPaths(node);
|
||||
// sort destinations first by their priority (eg trash pipes should be last)
|
||||
// and then by their distance from the specified node
|
||||
ret = Streams.stream(new BreadthFirstIterator<>(this.graph, node))
|
||||
|
@ -472,7 +464,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public void clearDestinationCache(BlockPos... nodes) {
|
||||
this.startProfile("clear_node_cache");
|
||||
// remove caches for the nodes
|
||||
for (BlockPos node : nodes)
|
||||
for (var node : nodes)
|
||||
this.nodeToConnectedNodes.keySet().remove(node);
|
||||
// remove caches that contain the nodes as a destination
|
||||
this.nodeToConnectedNodes.values().removeIf(cached -> Arrays.stream(nodes).anyMatch(cached::contains));
|
||||
|
@ -485,7 +477,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
|
||||
public Stream<IPipeItem> getPipeItemsOnTheWay(BlockPos goalInv) {
|
||||
this.startProfile("get_pipe_items_on_the_way");
|
||||
Stream<IPipeItem> ret = this.pipeItems.values().stream().filter(i -> i.getDestInventory().equals(goalInv));
|
||||
var ret = this.pipeItems.values().stream().filter(i -> i.getDestInventory().equals(goalInv));
|
||||
this.endProfile();
|
||||
return ret;
|
||||
}
|
||||
|
@ -515,11 +507,11 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
}
|
||||
|
||||
public void startProfile(String name) {
|
||||
this.world.getProfiler().startSection(() -> PrettyPipes.ID + ":pipe_network_" + name);
|
||||
this.world.getProfiler().push(() -> PrettyPipes.ID + ":pipe_network_" + name);
|
||||
}
|
||||
|
||||
public void endProfile() {
|
||||
this.world.getProfiler().endSection();
|
||||
this.world.getProfiler().pop();
|
||||
}
|
||||
|
||||
public static PipeNetwork get(Level world) {
|
||||
|
|
|
@ -2,27 +2,25 @@ package de.ellpeck.prettypipes.packets;
|
|||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleContainer;
|
||||
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem;
|
||||
import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleItem;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.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.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import org.apache.logging.log4j.util.TriConsumer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -44,15 +42,15 @@ public class PacketButton {
|
|||
|
||||
}
|
||||
|
||||
public static PacketButton fromBytes(PacketBuffer buf) {
|
||||
PacketButton packet = new PacketButton();
|
||||
public static PacketButton fromBytes(FriendlyByteBuf buf) {
|
||||
var packet = new PacketButton();
|
||||
packet.pos = buf.readBlockPos();
|
||||
packet.result = ButtonResult.values()[buf.readByte()];
|
||||
packet.data = buf.readVarIntArray();
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static void toBytes(PacketButton packet, PacketBuffer buf) {
|
||||
public static void toBytes(PacketButton packet, FriendlyByteBuf buf) {
|
||||
buf.writeBlockPos(packet.pos);
|
||||
buf.writeByte(packet.result.ordinal());
|
||||
buf.writeVarIntArray(packet.data);
|
||||
|
@ -63,7 +61,7 @@ public class PacketButton {
|
|||
ctx.get().enqueueWork(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
Player player = ctx.get().getSender();
|
||||
message.result.action.accept(message.pos, message.data, player);
|
||||
}
|
||||
});
|
||||
|
@ -77,22 +75,23 @@ public class PacketButton {
|
|||
|
||||
public enum ButtonResult {
|
||||
PIPE_TAB((pos, data, player) -> {
|
||||
PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, player.world, pos);
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, player.level, pos);
|
||||
if (data[0] < 0) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
|
||||
NetworkHooks.openGui((ServerPlayer) player, tile, pos);
|
||||
} else {
|
||||
ItemStack stack = tile.modules.getStackInSlot(data[0]);
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, new INamedContainerProvider() {
|
||||
var stack = tile.modules.getStackInSlot(data[0]);
|
||||
NetworkHooks.openGui((ServerPlayer) player, new MenuProvider() {
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
public Component getDisplayName() {
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int windowId, PlayerInventory inv, PlayerEntity player) {
|
||||
public AbstractContainerMenu createMenu(int windowId, Inventory inv, Player player) {
|
||||
return ((IModule) stack.getItem()).getContainer(stack, tile, windowId, inv, player, data[0]);
|
||||
}
|
||||
|
||||
}, buf -> {
|
||||
buf.writeBlockPos(pos);
|
||||
buf.writeInt(data[0]);
|
||||
|
@ -100,34 +99,34 @@ public class PacketButton {
|
|||
}
|
||||
}),
|
||||
FILTER_CHANGE((pos, data, player) -> {
|
||||
IFilteredContainer container = (IFilteredContainer) player.openContainer;
|
||||
ItemFilter filter = container.getFilter();
|
||||
var container = (IFilteredContainer) player.containerMenu;
|
||||
var filter = container.getFilter();
|
||||
filter.onButtonPacket(data[0]);
|
||||
}),
|
||||
STACK_SIZE_MODULE_BUTTON((pos, data, player) -> {
|
||||
AbstractPipeContainer<?> container = (AbstractPipeContainer<?>) player.openContainer;
|
||||
var container = (AbstractPipeContainer<?>) player.containerMenu;
|
||||
StackSizeModuleItem.setLimitToMaxStackSize(container.moduleStack, !StackSizeModuleItem.getLimitToMaxStackSize(container.moduleStack));
|
||||
}),
|
||||
STACK_SIZE_AMOUNT((pos, data, player) -> {
|
||||
AbstractPipeContainer<?> container = (AbstractPipeContainer<?>) player.openContainer;
|
||||
var container = (AbstractPipeContainer<?>) player.containerMenu;
|
||||
StackSizeModuleItem.setMaxStackSize(container.moduleStack, data[0]);
|
||||
}),
|
||||
CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
|
||||
CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, player.world, pos);
|
||||
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level, pos);
|
||||
tile.requestCraftingItems(player, data[0]);
|
||||
}),
|
||||
CANCEL_CRAFTING((pos, data, player) -> {
|
||||
ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, pos);
|
||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos);
|
||||
tile.cancelCrafting();
|
||||
}),
|
||||
TAG_FILTER((pos, data, player) -> {
|
||||
FilterModifierModuleContainer container = (FilterModifierModuleContainer) player.openContainer;
|
||||
var container = (FilterModifierModuleContainer) player.containerMenu;
|
||||
FilterModifierModuleItem.setFilterTag(container.moduleStack, container.getTags().get(data[0]));
|
||||
});
|
||||
|
||||
public final TriConsumer<BlockPos, int[], PlayerEntity> action;
|
||||
public final TriConsumer<BlockPos, int[], Player> action;
|
||||
|
||||
ButtonResult(TriConsumer<BlockPos, int[], PlayerEntity> action) {
|
||||
ButtonResult(TriConsumer<BlockPos, int[], Player> action) {
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package de.ellpeck.prettypipes.packets;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -26,24 +26,24 @@ public class PacketCraftingModuleTransfer {
|
|||
|
||||
}
|
||||
|
||||
public static PacketCraftingModuleTransfer fromBytes(PacketBuffer buf) {
|
||||
PacketCraftingModuleTransfer packet = new PacketCraftingModuleTransfer();
|
||||
public static PacketCraftingModuleTransfer fromBytes(FriendlyByteBuf buf) {
|
||||
var packet = new PacketCraftingModuleTransfer();
|
||||
packet.inputs = new ArrayList<>();
|
||||
for (int i = buf.readInt(); i > 0; i--)
|
||||
packet.inputs.add(buf.readItemStack());
|
||||
for (var i = buf.readInt(); i > 0; i--)
|
||||
packet.inputs.add(buf.readItem());
|
||||
packet.outputs = new ArrayList<>();
|
||||
for (int i = buf.readInt(); i > 0; i--)
|
||||
packet.outputs.add(buf.readItemStack());
|
||||
for (var i = buf.readInt(); i > 0; i--)
|
||||
packet.outputs.add(buf.readItem());
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static void toBytes(PacketCraftingModuleTransfer packet, PacketBuffer buf) {
|
||||
public static void toBytes(PacketCraftingModuleTransfer packet, FriendlyByteBuf buf) {
|
||||
buf.writeInt(packet.inputs.size());
|
||||
for (ItemStack stack : packet.inputs)
|
||||
buf.writeItemStack(stack);
|
||||
for (var stack : packet.inputs)
|
||||
buf.writeItem(stack);
|
||||
buf.writeInt(packet.outputs.size());
|
||||
for (ItemStack stack : packet.outputs)
|
||||
buf.writeItemStack(stack);
|
||||
for (var stack : packet.outputs)
|
||||
buf.writeItem(stack);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Convert2Lambda")
|
||||
|
@ -51,13 +51,12 @@ public class PacketCraftingModuleTransfer {
|
|||
ctx.get().enqueueWork(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
if (player.openContainer instanceof CraftingModuleContainer) {
|
||||
CraftingModuleContainer container = (CraftingModuleContainer) player.openContainer;
|
||||
Player player = ctx.get().getSender();
|
||||
if (player.containerMenu instanceof CraftingModuleContainer container) {
|
||||
copy(container.input, message.inputs);
|
||||
copy(container.output, message.outputs);
|
||||
container.modified = true;
|
||||
container.detectAndSendChanges();
|
||||
container.broadcastChanges();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -65,9 +64,9 @@ public class PacketCraftingModuleTransfer {
|
|||
}
|
||||
|
||||
private static void copy(ItemStackHandler container, List<ItemStack> contents) {
|
||||
for (int i = 0; i < container.getSlots(); i++)
|
||||
for (var i = 0; i < container.getSlots(); i++)
|
||||
container.setStackInSlot(i, ItemStack.EMPTY);
|
||||
for (ItemStack stack : contents)
|
||||
for (var stack : contents)
|
||||
ItemHandlerHelper.insertItem(container, stack, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ package de.ellpeck.prettypipes.packets;
|
|||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
@ -29,35 +29,35 @@ public class PacketGhostSlot {
|
|||
|
||||
}
|
||||
|
||||
public static PacketGhostSlot fromBytes(PacketBuffer buf) {
|
||||
PacketGhostSlot packet = new PacketGhostSlot();
|
||||
public static PacketGhostSlot fromBytes(FriendlyByteBuf buf) {
|
||||
var packet = new PacketGhostSlot();
|
||||
packet.pos = buf.readBlockPos();
|
||||
packet.stacks = ArrayListMultimap.create();
|
||||
for (int i = buf.readInt(); i > 0; i--)
|
||||
packet.stacks.put(buf.readInt(), buf.readItemStack());
|
||||
for (var i = buf.readInt(); i > 0; i--)
|
||||
packet.stacks.put(buf.readInt(), buf.readItem());
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static void toBytes(PacketGhostSlot packet, PacketBuffer buf) {
|
||||
public static void toBytes(PacketGhostSlot packet, FriendlyByteBuf buf) {
|
||||
buf.writeBlockPos(packet.pos);
|
||||
buf.writeInt(packet.stacks.size());
|
||||
for (Map.Entry<Integer, ItemStack> entry : packet.stacks.entries()) {
|
||||
for (var entry : packet.stacks.entries()) {
|
||||
buf.writeInt(entry.getKey());
|
||||
buf.writeItemStack(entry.getValue());
|
||||
buf.writeItem(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("Convert2Lambda")
|
||||
public static void onMessage(PacketGhostSlot message, Supplier<NetworkEvent.Context> ctx) {
|
||||
Consumer<PlayerEntity> doIt = p -> {
|
||||
CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, p.world, message.pos);
|
||||
var doIt = (Consumer<Player>) p -> {
|
||||
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, p.level, message.pos);
|
||||
if (tile != null)
|
||||
tile.setGhostItems(message.stacks);
|
||||
};
|
||||
|
||||
// this whole thing is a dirty hack for allowing the same packet to be used
|
||||
// both client -> server and server -> client without any classloading issues
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
Player player = ctx.get().getSender();
|
||||
// are we on the client?
|
||||
if (player == null) {
|
||||
ctx.get().enqueueWork(new Runnable() {
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package de.ellpeck.prettypipes.packets;
|
||||
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.simple.SimpleChannel;
|
||||
|
||||
public final class PacketHandler {
|
||||
|
||||
|
@ -26,12 +25,12 @@ public final class PacketHandler {
|
|||
network.registerMessage(5, PacketCraftingModuleTransfer.class, PacketCraftingModuleTransfer::toBytes, PacketCraftingModuleTransfer::fromBytes, PacketCraftingModuleTransfer::onMessage);
|
||||
}
|
||||
|
||||
public static void sendToAllLoaded(World world, BlockPos pos, Object message) {
|
||||
public static void sendToAllLoaded(Level world, BlockPos pos, Object message) {
|
||||
network.send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunkAt(pos)), message);
|
||||
}
|
||||
|
||||
public static void sendTo(PlayerEntity player, Object message) {
|
||||
network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), message);
|
||||
public static void sendTo(Player player, Object message) {
|
||||
network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), message);
|
||||
}
|
||||
|
||||
public static void sendToServer(Object message) {
|
||||
|
|
|
@ -2,12 +2,12 @@ package de.ellpeck.prettypipes.packets;
|
|||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeItem;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -25,16 +25,16 @@ public class PacketItemEnterPipe {
|
|||
|
||||
}
|
||||
|
||||
public static PacketItemEnterPipe fromBytes(PacketBuffer buf) {
|
||||
PacketItemEnterPipe client = new PacketItemEnterPipe();
|
||||
public static PacketItemEnterPipe fromBytes(FriendlyByteBuf buf) {
|
||||
var client = new PacketItemEnterPipe();
|
||||
client.tilePos = buf.readBlockPos();
|
||||
client.item = buf.readCompoundTag();
|
||||
client.item = buf.readNbt();
|
||||
return client;
|
||||
}
|
||||
|
||||
public static void toBytes(PacketItemEnterPipe packet, PacketBuffer buf) {
|
||||
public static void toBytes(PacketItemEnterPipe packet, FriendlyByteBuf buf) {
|
||||
buf.writeBlockPos(packet.tilePos);
|
||||
buf.writeCompoundTag(packet.item);
|
||||
buf.writeNbt(packet.item);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Convert2Lambda")
|
||||
|
@ -42,11 +42,11 @@ public class PacketItemEnterPipe {
|
|||
ctx.get().enqueueWork(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.world == null)
|
||||
var mc = Minecraft.getInstance();
|
||||
if (mc.level == null)
|
||||
return;
|
||||
IPipeItem item = IPipeItem.load(message.item);
|
||||
PipeTileEntity pipe = Utility.getBlockEntity(PipeTileEntity.class, mc.world, message.tilePos);
|
||||
var item = IPipeItem.load(message.item);
|
||||
var pipe = Utility.getBlockEntity(PipeBlockEntity.class, mc.level, message.tilePos);
|
||||
if (pipe != null)
|
||||
pipe.getItems().add(item);
|
||||
}
|
||||
|
|
|
@ -2,13 +2,9 @@ package de.ellpeck.prettypipes.packets;
|
|||
|
||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -30,37 +26,37 @@ public class PacketNetworkItems {
|
|||
|
||||
}
|
||||
|
||||
public static PacketNetworkItems fromBytes(PacketBuffer buf) {
|
||||
PacketNetworkItems client = new PacketNetworkItems();
|
||||
public static PacketNetworkItems fromBytes(FriendlyByteBuf buf) {
|
||||
var client = new PacketNetworkItems();
|
||||
client.items = new ArrayList<>();
|
||||
for (int i = buf.readVarInt(); i > 0; i--) {
|
||||
ItemStack stack = buf.readItemStack();
|
||||
for (var i = buf.readVarInt(); i > 0; i--) {
|
||||
var stack = buf.readItem();
|
||||
stack.setCount(buf.readVarInt());
|
||||
client.items.add(stack);
|
||||
}
|
||||
client.craftables = new ArrayList<>();
|
||||
for (int i = buf.readVarInt(); i > 0; i--)
|
||||
client.craftables.add(buf.readItemStack());
|
||||
for (var i = buf.readVarInt(); i > 0; i--)
|
||||
client.craftables.add(buf.readItem());
|
||||
client.currentlyCrafting = new ArrayList<>();
|
||||
for (int i = buf.readVarInt(); i > 0; i--)
|
||||
client.currentlyCrafting.add(buf.readItemStack());
|
||||
for (var i = buf.readVarInt(); i > 0; i--)
|
||||
client.currentlyCrafting.add(buf.readItem());
|
||||
return client;
|
||||
}
|
||||
|
||||
public static void toBytes(PacketNetworkItems packet, PacketBuffer buf) {
|
||||
public static void toBytes(PacketNetworkItems packet, FriendlyByteBuf buf) {
|
||||
buf.writeVarInt(packet.items.size());
|
||||
for (ItemStack stack : packet.items) {
|
||||
ItemStack copy = stack.copy();
|
||||
for (var stack : packet.items) {
|
||||
var copy = stack.copy();
|
||||
copy.setCount(1);
|
||||
buf.writeItemStack(copy);
|
||||
buf.writeItem(copy);
|
||||
buf.writeVarInt(stack.getCount());
|
||||
}
|
||||
buf.writeVarInt(packet.craftables.size());
|
||||
for (ItemStack stack : packet.craftables)
|
||||
buf.writeItemStack(stack);
|
||||
for (var stack : packet.craftables)
|
||||
buf.writeItem(stack);
|
||||
buf.writeVarInt(packet.currentlyCrafting.size());
|
||||
for (ItemStack stack : packet.currentlyCrafting)
|
||||
buf.writeItemStack(stack);
|
||||
for (var stack : packet.currentlyCrafting)
|
||||
buf.writeItem(stack);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Convert2Lambda")
|
||||
|
@ -68,9 +64,9 @@ public class PacketNetworkItems {
|
|||
ctx.get().enqueueWork(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.currentScreen instanceof ItemTerminalGui)
|
||||
((ItemTerminalGui) mc.currentScreen).updateItemList(message.items, message.craftables, message.currentlyCrafting);
|
||||
var mc = Minecraft.getInstance();
|
||||
if (mc.screen instanceof ItemTerminalGui terminal)
|
||||
terminal.updateItemList(message.items, message.craftables, message.currentlyCrafting);
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package de.ellpeck.prettypipes.packets;
|
||||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -26,17 +26,17 @@ public class PacketRequest {
|
|||
|
||||
}
|
||||
|
||||
public static PacketRequest fromBytes(PacketBuffer buf) {
|
||||
PacketRequest packet = new PacketRequest();
|
||||
public static PacketRequest fromBytes(FriendlyByteBuf buf) {
|
||||
var packet = new PacketRequest();
|
||||
packet.pos = buf.readBlockPos();
|
||||
packet.stack = buf.readItemStack();
|
||||
packet.stack = buf.readItem();
|
||||
packet.amount = buf.readVarInt();
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static void toBytes(PacketRequest packet, PacketBuffer buf) {
|
||||
public static void toBytes(PacketRequest packet, FriendlyByteBuf buf) {
|
||||
buf.writeBlockPos(packet.pos);
|
||||
buf.writeItemStack(packet.stack);
|
||||
buf.writeItem(packet.stack);
|
||||
buf.writeVarInt(packet.amount);
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,8 @@ public class PacketRequest {
|
|||
ctx.get().enqueueWork(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, message.pos);
|
||||
Player player = ctx.get().getSender();
|
||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, message.pos);
|
||||
message.stack.setCount(message.amount);
|
||||
tile.requestItem(player, message.stack);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package de.ellpeck.prettypipes.pipe;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface IPipeConnectable {
|
||||
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
package de.ellpeck.prettypipes.pipe;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.network.NetworkEdge;
|
||||
import de.ellpeck.prettypipes.network.PipeItem;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
@ -31,9 +29,9 @@ public interface IPipeItem extends INBTSerializable<CompoundTag> {
|
|||
|
||||
void setDestination(BlockPos startInventory, BlockPos destInventory, GraphPath<BlockPos, NetworkEdge> path);
|
||||
|
||||
void updateInPipe(PipeTileEntity currPipe);
|
||||
void updateInPipe(PipeBlockEntity currPipe);
|
||||
|
||||
void drop(World world, ItemStack stack);
|
||||
void drop(Level world, ItemStack stack);
|
||||
|
||||
BlockPos getDestPipe();
|
||||
|
||||
|
@ -44,15 +42,11 @@ public interface IPipeItem extends INBTSerializable<CompoundTag> {
|
|||
int getItemsOnTheWay(BlockPos goalInv);
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
void render(PipeTileEntity tile, MatrixStack matrixStack, Random random, float partialTicks, int light, int overlay, IRenderTypeBuffer buffer);
|
||||
void render(PipeBlockEntity tile, PoseStack matrixStack, Random random, float partialTicks, int light, int overlay, MultiBufferSource source);
|
||||
|
||||
static IPipeItem load(CompoundTag nbt) {
|
||||
// TODO legacy compat, remove eventually
|
||||
if (!nbt.contains("type"))
|
||||
nbt.putString("type", PipeItem.TYPE.toString());
|
||||
|
||||
ResourceLocation type = new ResourceLocation(nbt.getString("type"));
|
||||
BiFunction<ResourceLocation, CompoundTag, IPipeItem> func = TYPES.get(type);
|
||||
var type = new ResourceLocation(nbt.getString("type"));
|
||||
var func = TYPES.get(type);
|
||||
return func != null ? func.apply(type, nbt) : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,51 +5,36 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.shapes.IBooleanFunction;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.BooleanOp;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import org.apache.commons.lang3.mutable.MutableObject;
|
||||
|
@ -76,31 +61,31 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
.build();
|
||||
|
||||
static {
|
||||
for (Direction dir : Direction.values())
|
||||
for (var dir : Direction.values())
|
||||
DIRECTIONS.put(dir, EnumProperty.create(dir.getName(), ConnectionType.class));
|
||||
}
|
||||
|
||||
public PipeBlock() {
|
||||
super(Block.Properties.of(Material.STONE).strength(2).sound(SoundType.STONE).noOcclusion());
|
||||
|
||||
BlockState state = this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, false);
|
||||
for (EnumProperty<ConnectionType> prop : DIRECTIONS.values())
|
||||
var state = this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, false);
|
||||
for (var prop : DIRECTIONS.values())
|
||||
state = state.setValue(prop, ConnectionType.DISCONNECTED);
|
||||
this.registerDefaultState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
||||
PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos);
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos);
|
||||
if (tile == null)
|
||||
return InteractionResult.PASS;
|
||||
if (!tile.canHaveModules())
|
||||
return InteractionResult.PASS;
|
||||
ItemStack stack = player.getItemInHand(handIn);
|
||||
var stack = player.getItemInHand(handIn);
|
||||
if (stack.getItem() instanceof IModule) {
|
||||
ItemStack copy = stack.copy();
|
||||
var copy = stack.copy();
|
||||
copy.setCount(1);
|
||||
ItemStack remain = ItemHandlerHelper.insertItem(tile.modules, copy, false);
|
||||
var remain = ItemHandlerHelper.insertItem(tile.modules, copy, false);
|
||||
if (remain.isEmpty()) {
|
||||
stack.shrink(1);
|
||||
return InteractionResult.SUCCESS;
|
||||
|
@ -114,62 +99,62 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(DIRECTIONS.values().toArray(new EnumProperty[0]));
|
||||
builder.add(BlockStateProperties.WATERLOGGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockState state) {
|
||||
return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
|
||||
return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
|
||||
BlockState newState = this.createState(worldIn, pos, state);
|
||||
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
|
||||
var newState = this.createState(worldIn, pos, state);
|
||||
if (newState != state) {
|
||||
worldIn.setBlockState(pos, newState);
|
||||
worldIn.setBlockAndUpdate(pos, newState);
|
||||
onStateChanged(worldIn, pos, newState);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
return this.createState(context.getWorld(), context.getPos(), this.getDefaultState());
|
||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
return this.createState(context.getLevel(), context.getClickedPos(), this.defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
|
||||
if (stateIn.get(BlockStateProperties.WATERLOGGED))
|
||||
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
|
||||
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
|
||||
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) {
|
||||
if (stateIn.getValue(BlockStateProperties.WATERLOGGED))
|
||||
worldIn.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(worldIn));
|
||||
return super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
|
||||
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
|
||||
onStateChanged(worldIn, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
||||
return this.cacheAndGetShape(state, worldIn, pos, s -> s.getShape(worldIn, pos, context), SHAPE_CACHE, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
public VoxelShape getCollisionShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
||||
return this.cacheAndGetShape(state, worldIn, pos, s -> s.getCollisionShape(worldIn, pos, context), COLL_SHAPE_CACHE, s -> {
|
||||
// make the shape a bit higher so we can jump up onto a higher block
|
||||
MutableObject<VoxelShape> newShape = new MutableObject<>(VoxelShapes.empty());
|
||||
s.forEachBox((x1, y1, z1, x2, y2, z2) -> newShape.setValue(VoxelShapes.combine(VoxelShapes.create(x1, y1, z1, x2, y2 + 3 / 16F, z2), newShape.getValue(), IBooleanFunction.OR)));
|
||||
return newShape.getValue().simplify();
|
||||
var newShape = new MutableObject<VoxelShape>(Shapes.empty());
|
||||
s.forAllBoxes((x1, y1, z1, x2, y2, z2) -> newShape.setValue(Shapes.join(Shapes.create(x1, y1, z1, x2, y2 + 3 / 16F, z2), newShape.getValue(), BooleanOp.OR)));
|
||||
return newShape.getValue().optimize();
|
||||
});
|
||||
}
|
||||
|
||||
private VoxelShape cacheAndGetShape(BlockState state, IBlockReader worldIn, BlockPos pos, Function<BlockState, VoxelShape> coverShapeSelector, Map<Pair<BlockState, BlockState>, VoxelShape> cache, Function<VoxelShape, VoxelShape> shapeModifier) {
|
||||
private VoxelShape cacheAndGetShape(BlockState state, BlockGetter worldIn, BlockPos pos, Function<BlockState, VoxelShape> coverShapeSelector, Map<Pair<BlockState, BlockState>, VoxelShape> cache, Function<VoxelShape, VoxelShape> shapeModifier) {
|
||||
VoxelShape coverShape = null;
|
||||
BlockState cover = null;
|
||||
PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos);
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos);
|
||||
if (tile != null && tile.cover != null) {
|
||||
cover = tile.cover;
|
||||
// try catch since the block might expect to find itself at the position
|
||||
|
@ -178,88 +163,88 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
Pair<BlockState, BlockState> key = Pair.of(state, cover);
|
||||
VoxelShape shape = cache.get(key);
|
||||
var key = Pair.of(state, cover);
|
||||
var shape = cache.get(key);
|
||||
if (shape == null) {
|
||||
shape = CENTER_SHAPE;
|
||||
for (Map.Entry<Direction, EnumProperty<ConnectionType>> entry : DIRECTIONS.entrySet()) {
|
||||
if (state.get(entry.getValue()).isConnected())
|
||||
shape = VoxelShapes.or(shape, DIR_SHAPES.get(entry.getKey()));
|
||||
for (var entry : DIRECTIONS.entrySet()) {
|
||||
if (state.getValue(entry.getValue()).isConnected())
|
||||
shape = Shapes.or(shape, DIR_SHAPES.get(entry.getKey()));
|
||||
}
|
||||
if (shapeModifier != null)
|
||||
shape = shapeModifier.apply(shape);
|
||||
if (coverShape != null)
|
||||
shape = VoxelShapes.or(shape, coverShape);
|
||||
shape = Shapes.or(shape, coverShape);
|
||||
cache.put(key, shape);
|
||||
}
|
||||
return shape;
|
||||
}
|
||||
|
||||
private BlockState createState(World world, BlockPos pos, BlockState curr) {
|
||||
BlockState state = this.getDefaultState();
|
||||
FluidState fluid = world.getFluidState(pos);
|
||||
if (fluid.isTagged(FluidTags.WATER) && fluid.getLevel() == 8)
|
||||
state = state.with(BlockStateProperties.WATERLOGGED, true);
|
||||
private BlockState createState(Level world, BlockPos pos, BlockState curr) {
|
||||
var state = this.defaultBlockState();
|
||||
var fluid = world.getFluidState(pos);
|
||||
if (fluid.is(FluidTags.WATER) && fluid.getAmount() == 8)
|
||||
state = state.setValue(BlockStateProperties.WATERLOGGED, true);
|
||||
|
||||
for (Direction dir : Direction.values()) {
|
||||
EnumProperty<ConnectionType> prop = DIRECTIONS.get(dir);
|
||||
ConnectionType type = this.getConnectionType(world, pos, dir, state);
|
||||
for (var dir : Direction.values()) {
|
||||
var prop = DIRECTIONS.get(dir);
|
||||
var type = this.getConnectionType(world, pos, dir, state);
|
||||
// don't reconnect on blocked faces
|
||||
if (type.isConnected() && curr.get(prop) == ConnectionType.BLOCKED)
|
||||
if (type.isConnected() && curr.getValue(prop) == ConnectionType.BLOCKED)
|
||||
type = ConnectionType.BLOCKED;
|
||||
state = state.with(prop, type);
|
||||
state = state.setValue(prop, type);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
protected ConnectionType getConnectionType(World world, BlockPos pos, Direction direction, BlockState state) {
|
||||
BlockPos offset = pos.offset(direction);
|
||||
if (!world.isBlockLoaded(offset))
|
||||
protected ConnectionType getConnectionType(Level world, BlockPos pos, Direction direction, BlockState state) {
|
||||
var offset = pos.relative(direction);
|
||||
if (!world.isLoaded(offset))
|
||||
return ConnectionType.DISCONNECTED;
|
||||
Direction opposite = direction.getOpposite();
|
||||
TileEntity tile = world.getTileEntity(offset);
|
||||
var opposite = direction.getOpposite();
|
||||
var tile = world.getBlockEntity(offset);
|
||||
if (tile != null) {
|
||||
IPipeConnectable connectable = tile.getCapability(Registry.pipeConnectableCapability, opposite).orElse(null);
|
||||
var connectable = tile.getCapability(Registry.pipeConnectableCapability, opposite).orElse(null);
|
||||
if (connectable != null)
|
||||
return connectable.getConnectionType(pos, direction);
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, opposite).orElse(null);
|
||||
var handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, opposite).orElse(null);
|
||||
if (handler != null)
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
IItemHandler blockHandler = Utility.getBlockItemHandler(world, offset, opposite);
|
||||
var blockHandler = Utility.getBlockItemHandler(world, offset, opposite);
|
||||
if (blockHandler != null)
|
||||
return ConnectionType.CONNECTED;
|
||||
BlockState offState = world.getBlockState(offset);
|
||||
var offState = world.getBlockState(offset);
|
||||
if (hasLegsTo(world, offState, offset, direction)) {
|
||||
if (DIRECTIONS.values().stream().noneMatch(d -> state.get(d) == ConnectionType.LEGS))
|
||||
if (DIRECTIONS.values().stream().noneMatch(d -> state.getValue(d) == ConnectionType.LEGS))
|
||||
return ConnectionType.LEGS;
|
||||
}
|
||||
return ConnectionType.DISCONNECTED;
|
||||
}
|
||||
|
||||
protected static boolean hasLegsTo(World world, BlockState state, BlockPos pos, Direction direction) {
|
||||
protected static boolean hasLegsTo(Level world, BlockState state, BlockPos pos, Direction direction) {
|
||||
if (state.getBlock() instanceof WallBlock || state.getBlock() instanceof FenceBlock)
|
||||
return direction == Direction.DOWN;
|
||||
if (state.getMaterial() == Material.ROCK || state.getMaterial() == Material.IRON)
|
||||
return hasEnoughSolidSide(world, pos, direction.getOpposite());
|
||||
if (state.getMaterial() == Material.STONE || state.getMaterial() == Material.METAL)
|
||||
return canSupportCenter(world, pos, direction.getOpposite());
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void onStateChanged(World world, BlockPos pos, BlockState newState) {
|
||||
public static void onStateChanged(Level world, BlockPos pos, BlockState newState) {
|
||||
// wait a few ticks before checking if we have to drop our modules, so that things like iron -> gold chest work
|
||||
PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, world, pos);
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, world, pos);
|
||||
if (tile != null)
|
||||
tile.moduleDropCheck = 5;
|
||||
|
||||
PipeNetwork network = PipeNetwork.get(world);
|
||||
int connections = 0;
|
||||
boolean force = false;
|
||||
for (Direction dir : Direction.values()) {
|
||||
ConnectionType value = newState.get(DIRECTIONS.get(dir));
|
||||
var network = PipeNetwork.get(world);
|
||||
var connections = 0;
|
||||
var force = false;
|
||||
for (var dir : Direction.values()) {
|
||||
var value = newState.getValue(DIRECTIONS.get(dir));
|
||||
if (!value.isConnected())
|
||||
continue;
|
||||
connections++;
|
||||
BlockState otherState = world.getBlockState(pos.offset(dir));
|
||||
var otherState = world.getBlockState(pos.relative(dir));
|
||||
// force a node if we're connecting to a different block (inventory etc.)
|
||||
if (otherState.getBlock() != newState.getBlock()) {
|
||||
force = true;
|
||||
|
@ -275,53 +260,59 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
}
|
||||
|
||||
@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()) {
|
||||
PipeNetwork network = PipeNetwork.get(worldIn);
|
||||
var network = PipeNetwork.get(worldIn);
|
||||
network.removeNode(pos);
|
||||
network.onPipeChanged(pos, state);
|
||||
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||
super.onRemove(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
public void playerWillDestroy(Level worldIn, BlockPos pos, BlockState state, Player player) {
|
||||
dropItems(worldIn, pos, player);
|
||||
super.onBlockHarvested(worldIn, pos, state, player);
|
||||
super.playerWillDestroy(worldIn, pos, state, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride(BlockState state) {
|
||||
public boolean hasAnalogOutputSignal(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
|
||||
PipeTileEntity pipe = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos);
|
||||
public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) {
|
||||
var pipe = Utility.getBlockEntity(PipeBlockEntity.class, world, pos);
|
||||
if (pipe == null)
|
||||
return 0;
|
||||
return Math.min(15, pipe.getItems().size());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
||||
return new PipeTileEntity();
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new PipeBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.MODEL;
|
||||
public RenderShape getRenderShape(BlockState state) {
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
|
||||
public static void dropItems(World worldIn, BlockPos pos, PlayerEntity player) {
|
||||
PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos);
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
||||
return createTickerHelper(type, Registry.pipeBlockEntity, PipeBlockEntity::tick);
|
||||
}
|
||||
|
||||
public static void dropItems(Level worldIn, BlockPos pos, Player player) {
|
||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, worldIn, pos);
|
||||
if (tile != null) {
|
||||
Utility.dropInventory(tile, tile.modules);
|
||||
for (IPipeItem item : tile.getItems())
|
||||
for (var item : tile.getItems())
|
||||
item.drop(worldIn, item.getContent());
|
||||
if (tile.cover != null)
|
||||
tile.removeCover(player, Hand.MAIN_HAND);
|
||||
tile.removeCover(player, InteractionHand.MAIN_HAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,38 +10,32 @@ import de.ellpeck.prettypipes.network.NetworkLock;
|
|||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer;
|
||||
import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
|
||||
import net.minecraft.profiler.IProfiler;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.common.util.Lazy;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
|
@ -57,7 +51,7 @@ import java.util.function.Consumer;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PipeTileEntity extends BlockEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable {
|
||||
public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeConnectable {
|
||||
|
||||
public final ItemStackHandler modules = new ItemStackHandler(3) {
|
||||
@Override
|
||||
|
@ -65,7 +59,7 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
var item = stack.getItem();
|
||||
if (!(item instanceof IModule module))
|
||||
return false;
|
||||
return PipeTileEntity.this.streamModules().allMatch(m -> module.isCompatible(stack, PipeTileEntity.this, m.getRight()) && m.getRight().isCompatible(m.getLeft(), PipeTileEntity.this, module));
|
||||
return PipeBlockEntity.this.streamModules().allMatch(m -> module.isCompatible(stack, PipeBlockEntity.this, m.getRight()) && m.getRight().isCompatible(m.getLeft(), PipeBlockEntity.this, module));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,9 +75,13 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
protected List<IPipeItem> items;
|
||||
private int lastItemAmount;
|
||||
private int priority;
|
||||
private final LazyOptional<PipeTileEntity> lazyThis = LazyOptional.of(() -> this);
|
||||
private final LazyOptional<PipeBlockEntity> lazyThis = LazyOptional.of(() -> this);
|
||||
private final Lazy<Integer> workRandomizer = Lazy.of(() -> this.level.random.nextInt(200));
|
||||
|
||||
public PipeBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Registry.pipeBlockEntity, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnloaded() {
|
||||
PipeNetwork.get(this.level).uncachePipe(this.worldPosition);
|
||||
|
@ -96,9 +94,9 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
compound.put("requests", Utility.serializeAll(this.craftIngredientRequests));
|
||||
if (this.cover != null)
|
||||
compound.put("cover", NbtUtils.writeBlockState(this.cover));
|
||||
ListTag results = new ListTag();
|
||||
for (Pair<BlockPos, ItemStack> triple : this.craftResultRequests) {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
var results = new ListTag();
|
||||
for (var triple : this.craftResultRequests) {
|
||||
var nbt = new CompoundTag();
|
||||
nbt.putLong("dest_pipe", triple.getLeft().asLong());
|
||||
nbt.put("item", triple.getRight().serializeNBT());
|
||||
results.add(nbt);
|
||||
|
@ -113,11 +111,11 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
this.moduleDropCheck = compound.getInt("module_drop_check");
|
||||
this.cover = compound.contains("cover") ? NbtUtils.readBlockState(compound.getCompound("cover")) : null;
|
||||
this.craftIngredientRequests.clear();
|
||||
this.craftIngredientRequests.addAll(Utility.deserializeAll(compound.getList("requests", NBT.TAG_COMPOUND), NetworkLock::new));
|
||||
this.craftIngredientRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), NetworkLock::new));
|
||||
this.craftResultRequests.clear();
|
||||
ListTag results = compound.getList("craft_results", NBT.TAG_COMPOUND);
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
CompoundTag nbt = results.getCompound(i);
|
||||
var results = compound.getList("craft_results", Tag.TAG_COMPOUND);
|
||||
for (var i = 0; i < results.size(); i++) {
|
||||
var nbt = results.getCompound(i);
|
||||
this.craftResultRequests.add(Pair.of(
|
||||
BlockPos.of(nbt.getLong("dest_pipe")),
|
||||
ItemStack.of(nbt.getCompound("item"))));
|
||||
|
@ -128,72 +126,27 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
@Override
|
||||
public CompoundTag getUpdateTag() {
|
||||
// sync pipe items on load
|
||||
CompoundTag nbt = this.write(new CompoundTag());
|
||||
var nbt = this.save(new CompoundTag());
|
||||
nbt.put("items", Utility.serializeAll(this.getItems()));
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(BlockState state, CompoundTag nbt) {
|
||||
this.read(state, nbt);
|
||||
List<IPipeItem> items = this.getItems();
|
||||
public void handleUpdateTag(CompoundTag nbt) {
|
||||
this.load(nbt);
|
||||
var items = this.getItems();
|
||||
items.clear();
|
||||
items.addAll(Utility.deserializeAll(nbt.getList("items", NBT.TAG_COMPOUND), IPipeItem::load));
|
||||
items.addAll(Utility.deserializeAll(nbt.getList("items", Tag.TAG_COMPOUND), IPipeItem::load));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
|
||||
this.read(this.getBlockState(), pkt.getNbtCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
// invalidate our pressurizer reference if it was removed
|
||||
if (this.pressurizer != null && this.pressurizer.isRemoved())
|
||||
this.pressurizer = null;
|
||||
|
||||
if (!this.world.isAreaLoaded(this.pos, 1))
|
||||
return;
|
||||
IProfiler profiler = this.world.getProfiler();
|
||||
|
||||
if (!this.world.isRemote) {
|
||||
// drop modules here to give a bit of time for blocks to update (iron -> gold chest etc.)
|
||||
if (this.moduleDropCheck > 0) {
|
||||
this.moduleDropCheck--;
|
||||
if (this.moduleDropCheck <= 0 && !this.canHaveModules())
|
||||
Utility.dropInventory(this, this.modules);
|
||||
}
|
||||
|
||||
profiler.startSection("ticking_modules");
|
||||
int prio = 0;
|
||||
Iterator<Pair<ItemStack, IModule>> modules = this.streamModules().iterator();
|
||||
while (modules.hasNext()) {
|
||||
Pair<ItemStack, IModule> module = modules.next();
|
||||
module.getRight().tick(module.getLeft(), this);
|
||||
prio += module.getRight().getPriority(module.getLeft(), this);
|
||||
}
|
||||
if (prio != this.priority) {
|
||||
this.priority = prio;
|
||||
// clear the cache so that it's reevaluated based on priority
|
||||
PipeNetwork.get(this.world).clearDestinationCache(this.pos);
|
||||
}
|
||||
profiler.endSection();
|
||||
}
|
||||
|
||||
profiler.startSection("ticking_items");
|
||||
List<IPipeItem> items = this.getItems();
|
||||
for (int i = items.size() - 1; i >= 0; i--)
|
||||
items.get(i).updateInPipe(this);
|
||||
if (items.size() != this.lastItemAmount) {
|
||||
this.lastItemAmount = items.size();
|
||||
this.world.updateComparatorOutputLevel(this.pos, this.getBlockState().getBlock());
|
||||
}
|
||||
profiler.endSection();
|
||||
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
|
||||
this.load(pkt.getTag());
|
||||
}
|
||||
|
||||
public List<IPipeItem> getItems() {
|
||||
if (this.items == null)
|
||||
this.items = PipeNetwork.get(this.world).getItemsInPipe(this.pos);
|
||||
this.items = PipeNetwork.get(this.level).getItemsInPipe(this.worldPosition);
|
||||
return this.items;
|
||||
}
|
||||
|
||||
|
@ -206,23 +159,23 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
}
|
||||
|
||||
public boolean isConnected(Direction dir) {
|
||||
return this.getBlockState().get(PipeBlock.DIRECTIONS.get(dir)).isConnected();
|
||||
return this.getBlockState().getValue(PipeBlock.DIRECTIONS.get(dir)).isConnected();
|
||||
}
|
||||
|
||||
public Pair<BlockPos, ItemStack> getAvailableDestinationOrConnectable(ItemStack stack, boolean force, boolean preventOversending) {
|
||||
Pair<BlockPos, ItemStack> dest = this.getAvailableDestination(stack, force, preventOversending);
|
||||
var dest = this.getAvailableDestination(stack, force, preventOversending);
|
||||
if (dest != null)
|
||||
return dest;
|
||||
// if there's no available destination, try inserting into terminals etc.
|
||||
for (Direction dir : Direction.values()) {
|
||||
IPipeConnectable connectable = this.getPipeConnectable(dir);
|
||||
for (var dir : Direction.values()) {
|
||||
var connectable = this.getPipeConnectable(dir);
|
||||
if (connectable == null)
|
||||
continue;
|
||||
ItemStack connectableRemain = connectable.insertItem(this.getPos(), dir, stack, true);
|
||||
var connectableRemain = connectable.insertItem(this.worldPosition, dir, stack, true);
|
||||
if (connectableRemain.getCount() != stack.getCount()) {
|
||||
ItemStack inserted = stack.copy();
|
||||
var inserted = stack.copy();
|
||||
inserted.shrink(connectableRemain.getCount());
|
||||
return Pair.of(this.getPos().offset(dir), inserted);
|
||||
return Pair.of(this.worldPosition.relative(dir), inserted);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -233,47 +186,47 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
return null;
|
||||
if (!force && this.streamModules().anyMatch(m -> !m.getRight().canAcceptItem(m.getLeft(), this, stack)))
|
||||
return null;
|
||||
for (Direction dir : Direction.values()) {
|
||||
IItemHandler handler = this.getItemHandler(dir);
|
||||
for (var dir : Direction.values()) {
|
||||
var handler = this.getItemHandler(dir);
|
||||
if (handler == null)
|
||||
continue;
|
||||
ItemStack remain = ItemHandlerHelper.insertItem(handler, stack, true);
|
||||
var remain = ItemHandlerHelper.insertItem(handler, stack, true);
|
||||
// did we insert anything?
|
||||
if (remain.getCount() == stack.getCount())
|
||||
continue;
|
||||
ItemStack toInsert = stack.copy();
|
||||
var toInsert = stack.copy();
|
||||
toInsert.shrink(remain.getCount());
|
||||
// limit to the max amount that modules allow us to insert
|
||||
int maxAmount = this.streamModules().mapToInt(m -> m.getRight().getMaxInsertionAmount(m.getLeft(), this, stack, handler)).min().orElse(Integer.MAX_VALUE);
|
||||
var maxAmount = this.streamModules().mapToInt(m -> m.getRight().getMaxInsertionAmount(m.getLeft(), this, stack, handler)).min().orElse(Integer.MAX_VALUE);
|
||||
if (maxAmount < toInsert.getCount())
|
||||
toInsert.setCount(maxAmount);
|
||||
BlockPos offset = this.pos.offset(dir);
|
||||
var offset = this.worldPosition.relative(dir);
|
||||
if (preventOversending || maxAmount < Integer.MAX_VALUE) {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
var network = PipeNetwork.get(this.level);
|
||||
// these are the items that are currently in the pipes, going to this inventory
|
||||
int onTheWay = network.getItemsOnTheWay(offset, null);
|
||||
var onTheWay = network.getItemsOnTheWay(offset, null);
|
||||
if (onTheWay > 0) {
|
||||
if (maxAmount < Integer.MAX_VALUE) {
|
||||
// these are the items on the way, limited to items of the same type as stack
|
||||
int onTheWaySame = network.getItemsOnTheWay(offset, stack);
|
||||
var onTheWaySame = network.getItemsOnTheWay(offset, stack);
|
||||
// check if any modules are limiting us
|
||||
if (toInsert.getCount() + onTheWaySame > maxAmount)
|
||||
toInsert.setCount(maxAmount - onTheWaySame);
|
||||
}
|
||||
// totalSpace will be the amount of items that fit into the attached container
|
||||
int totalSpace = 0;
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
ItemStack copy = stack.copy();
|
||||
int maxStackSize = copy.getMaxStackSize();
|
||||
var totalSpace = 0;
|
||||
for (var i = 0; i < handler.getSlots(); i++) {
|
||||
var copy = stack.copy();
|
||||
var maxStackSize = copy.getMaxStackSize();
|
||||
// if the container can store more than 64 items in this slot, then it's likely
|
||||
// a barrel or similar, meaning that the slot limit matters more than the max stack size
|
||||
int limit = handler.getSlotLimit(i);
|
||||
var limit = handler.getSlotLimit(i);
|
||||
if (limit > 64)
|
||||
maxStackSize = limit;
|
||||
copy.setCount(maxStackSize);
|
||||
// this is an inaccurate check since it ignores the fact that some slots might
|
||||
// have space for items of other types, but it'll be good enough for us
|
||||
ItemStack left = handler.insertItem(i, copy, true);
|
||||
var left = handler.insertItem(i, copy, true);
|
||||
totalSpace += maxStackSize - left.getCount();
|
||||
}
|
||||
// if the items on the way plus the items we're trying to move are too much, reduce
|
||||
|
@ -293,8 +246,8 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
}
|
||||
|
||||
public float getItemSpeed(ItemStack stack) {
|
||||
float moduleSpeed = (float) this.streamModules().mapToDouble(m -> m.getRight().getItemSpeedIncrease(m.getLeft(), this)).sum();
|
||||
float pressureSpeed = this.pressurizer != null && this.pressurizer.pressurizeItem(stack, true) ? 0.45F : 0;
|
||||
var moduleSpeed = (float) this.streamModules().mapToDouble(m -> m.getRight().getItemSpeedIncrease(m.getLeft(), this)).sum();
|
||||
var pressureSpeed = this.pressurizer != null && this.pressurizer.pressurizeItem(stack, true) ? 0.45F : 0;
|
||||
return 0.05F + moduleSpeed + pressureSpeed;
|
||||
}
|
||||
|
||||
|
@ -309,13 +262,13 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
}
|
||||
|
||||
public int getCraftableAmount(Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
|
||||
int total = 0;
|
||||
Iterator<Pair<ItemStack, IModule>> modules = this.streamModules().iterator();
|
||||
var total = 0;
|
||||
var modules = this.streamModules().iterator();
|
||||
while (modules.hasNext()) {
|
||||
Pair<ItemStack, IModule> module = modules.next();
|
||||
var module = modules.next();
|
||||
// make sure we don't factor in recursive dependencies like ingot -> block -> ingot etc.
|
||||
if (dependencyChain.stream().noneMatch(d -> ItemEquality.compareItems(module.getLeft(), d, ItemEquality.NBT))) {
|
||||
int amount = module.getRight().getCraftableAmount(module.getLeft(), this, unavailableConsumer, stack, dependencyChain);
|
||||
var amount = module.getRight().getCraftableAmount(module.getLeft(), this, unavailableConsumer, stack, dependencyChain);
|
||||
if (amount > 0)
|
||||
total += amount;
|
||||
}
|
||||
|
@ -324,9 +277,9 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
}
|
||||
|
||||
public ItemStack craft(BlockPos destPipe, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
|
||||
Iterator<Pair<ItemStack, IModule>> modules = this.streamModules().iterator();
|
||||
var modules = this.streamModules().iterator();
|
||||
while (modules.hasNext()) {
|
||||
Pair<ItemStack, IModule> module = modules.next();
|
||||
var module = modules.next();
|
||||
stack = module.getRight().craft(module.getLeft(), this, destPipe, unavailableConsumer, stack, dependencyChain);
|
||||
if (stack.isEmpty())
|
||||
break;
|
||||
|
@ -335,24 +288,24 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
}
|
||||
|
||||
public IItemHandler getItemHandler(Direction dir) {
|
||||
IItemHandler handler = this.getNeighborCap(dir, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
||||
var handler = this.getNeighborCap(dir, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
||||
if (handler != null)
|
||||
return handler;
|
||||
return Utility.getBlockItemHandler(this.world, this.pos.offset(dir), dir.getOpposite());
|
||||
return Utility.getBlockItemHandler(this.level, this.worldPosition.relative(dir), dir.getOpposite());
|
||||
}
|
||||
|
||||
public <T> T getNeighborCap(Direction dir, Capability<T> cap) {
|
||||
if (!this.isConnected(dir))
|
||||
return null;
|
||||
BlockPos pos = this.pos.offset(dir);
|
||||
TileEntity tile = this.world.getTileEntity(pos);
|
||||
var pos = this.worldPosition.relative(dir);
|
||||
var tile = this.level.getBlockEntity(pos);
|
||||
if (tile != null)
|
||||
return tile.getCapability(cap, dir.getOpposite()).orElse(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
public IPipeConnectable getPipeConnectable(Direction dir) {
|
||||
TileEntity tile = this.world.getTileEntity(this.pos.offset(dir));
|
||||
var tile = this.level.getBlockEntity(this.worldPosition.relative(dir));
|
||||
if (tile != null)
|
||||
return tile.getCapability(Registry.pipeConnectableCapability, dir.getOpposite()).orElse(null);
|
||||
return null;
|
||||
|
@ -363,11 +316,11 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
}
|
||||
|
||||
public boolean canHaveModules() {
|
||||
for (Direction dir : Direction.values()) {
|
||||
for (var dir : Direction.values()) {
|
||||
if (this.isConnectedInventory(dir))
|
||||
return true;
|
||||
IPipeConnectable connectable = this.getPipeConnectable(dir);
|
||||
if (connectable != null && connectable.allowsModules(this.pos, dir))
|
||||
var connectable = this.getPipeConnectable(dir);
|
||||
if (connectable != null && connectable.allowsModules(this.worldPosition, dir))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -379,8 +332,8 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
|
||||
public Stream<Pair<ItemStack, IModule>> streamModules() {
|
||||
Stream.Builder<Pair<ItemStack, IModule>> builder = Stream.builder();
|
||||
for (int i = 0; i < this.modules.getSlots(); i++) {
|
||||
ItemStack stack = this.modules.getStackInSlot(i);
|
||||
for (var i = 0; i < this.modules.getSlots(); i++) {
|
||||
var stack = this.modules.getStackInSlot(i);
|
||||
if (stack.isEmpty())
|
||||
continue;
|
||||
builder.accept(Pair.of(stack, (IModule) stack.getItem()));
|
||||
|
@ -388,17 +341,17 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
public void removeCover(PlayerEntity player, Hand hand) {
|
||||
if (this.world.isRemote)
|
||||
public void removeCover(Player player, InteractionHand hand) {
|
||||
if (this.level.isClientSide)
|
||||
return;
|
||||
List<ItemStack> drops = Block.getDrops(this.cover, (ServerWorld) this.world, this.pos, null, player, player.getHeldItem(hand));
|
||||
for (ItemStack drop : drops)
|
||||
Block.spawnAsEntity(this.world, this.pos, drop);
|
||||
var drops = Block.getDrops(this.cover, (ServerLevel) this.level, this.worldPosition, null, player, player.getItemInHand(hand));
|
||||
for (var drop : drops)
|
||||
Containers.dropItemStack(this.level, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), drop);
|
||||
this.cover = null;
|
||||
}
|
||||
|
||||
public boolean shouldWorkNow(int speed) {
|
||||
return (this.world.getGameTime() + this.workRandomizer.get()) % speed == 0;
|
||||
return (this.level.getGameTime() + this.workRandomizer.get()) % speed == 0;
|
||||
}
|
||||
|
||||
public int getNextNode(List<BlockPos> nodes, int index) {
|
||||
|
@ -414,31 +367,31 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
this.getItems().clear();
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
for (NetworkLock lock : this.craftIngredientRequests)
|
||||
var network = PipeNetwork.get(this.level);
|
||||
for (var lock : this.craftIngredientRequests)
|
||||
network.resolveNetworkLock(lock);
|
||||
this.lazyThis.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("container." + PrettyPipes.ID + ".pipe");
|
||||
public Component getDisplayName() {
|
||||
return new TranslatableComponent("container." + PrettyPipes.ID + ".pipe");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) {
|
||||
return new MainPipeContainer(Registry.pipeContainer, window, player, PipeTileEntity.this.pos);
|
||||
public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
|
||||
return new MainPipeContainer(Registry.pipeContainer, window, player, PipeBlockEntity.this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
public AABB getRenderBoundingBox() {
|
||||
// our render bounding box should always be the full block in case we're covered
|
||||
return new AxisAlignedBB(this.pos);
|
||||
return new AABB(this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -450,9 +403,54 @@ public class PipeTileEntity extends BlockEntity implements INamedContainerProvid
|
|||
|
||||
@Override
|
||||
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
|
||||
BlockState state = this.world.getBlockState(pipePos.offset(direction));
|
||||
if (state.get(PipeBlock.DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED)
|
||||
var state = this.level.getBlockState(pipePos.relative(direction));
|
||||
if (state.getValue(PipeBlock.DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED)
|
||||
return ConnectionType.BLOCKED;
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
|
||||
public static void tick(Level level, BlockPos pos, BlockState state, PipeBlockEntity pipe) {
|
||||
// invalidate our pressurizer reference if it was removed
|
||||
if (pipe.pressurizer != null && pipe.pressurizer.isRemoved())
|
||||
pipe.pressurizer = null;
|
||||
|
||||
if (!pipe.level.isAreaLoaded(pipe.worldPosition, 1))
|
||||
return;
|
||||
var profiler = pipe.level.getProfiler();
|
||||
|
||||
if (!pipe.level.isClientSide) {
|
||||
// drop modules here to give a bit of time for blocks to update (iron -> gold chest etc.)
|
||||
if (pipe.moduleDropCheck > 0) {
|
||||
pipe.moduleDropCheck--;
|
||||
if (pipe.moduleDropCheck <= 0 && !pipe.canHaveModules())
|
||||
Utility.dropInventory(pipe, pipe.modules);
|
||||
}
|
||||
|
||||
profiler.push("ticking_modules");
|
||||
var prio = 0;
|
||||
var modules = pipe.streamModules().iterator();
|
||||
while (modules.hasNext()) {
|
||||
var module = modules.next();
|
||||
module.getRight().tick(module.getLeft(), pipe);
|
||||
prio += module.getRight().getPriority(module.getLeft(), pipe);
|
||||
}
|
||||
if (prio != pipe.priority) {
|
||||
pipe.priority = prio;
|
||||
// clear the cache so that it's reevaluated based on priority
|
||||
PipeNetwork.get(pipe.level).clearDestinationCache(pipe.worldPosition);
|
||||
}
|
||||
profiler.pop();
|
||||
}
|
||||
|
||||
profiler.push("ticking_items");
|
||||
var items = pipe.getItems();
|
||||
for (var i = items.size() - 1; i >= 0; i--)
|
||||
items.get(i).updateInPipe(pipe);
|
||||
if (items.size() != pipe.lastItemAmount) {
|
||||
pipe.lastItemAmount = items.size();
|
||||
pipe.level.updateNeighbourForOutputSignal(pipe.worldPosition, pipe.getBlockState().getBlock());
|
||||
}
|
||||
profiler.pop();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,54 +1,51 @@
|
|||
package de.ellpeck.prettypipes.pipe;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockModelRenderer;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.RenderTypeLookup;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class PipeRenderer extends TileEntityRenderer<PipeTileEntity> {
|
||||
public class PipeRenderer implements BlockEntityRenderer<PipeBlockEntity> {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
public PipeRenderer(TileEntityRendererDispatcher disp) {
|
||||
super(disp);
|
||||
public PipeRenderer(BlockEntityRendererProvider.Context ctx) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PipeTileEntity tile, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int light, int overlay) {
|
||||
public void render(PipeBlockEntity tile, float partialTicks, PoseStack matrixStack, MultiBufferSource source, int light, int overlay) {
|
||||
if (!tile.getItems().isEmpty()) {
|
||||
matrixStack.push();
|
||||
BlockPos tilePos = tile.getPos();
|
||||
matrixStack.pushPose();
|
||||
var tilePos = tile.getBlockPos();
|
||||
matrixStack.translate(-tilePos.getX(), -tilePos.getY(), -tilePos.getZ());
|
||||
for (IPipeItem item : tile.getItems()) {
|
||||
matrixStack.push();
|
||||
item.render(tile, matrixStack, this.random, partialTicks, light, overlay, buffer);
|
||||
matrixStack.pop();
|
||||
for (var item : tile.getItems()) {
|
||||
matrixStack.pushPose();
|
||||
item.render(tile, matrixStack, this.random, partialTicks, light, overlay, source);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
matrixStack.pop();
|
||||
matrixStack.popPose();
|
||||
}
|
||||
if (tile.cover != null) {
|
||||
matrixStack.push();
|
||||
BlockModelRenderer.enableCache();
|
||||
for (RenderType layer : RenderType.getBlockRenderTypes()) {
|
||||
if (!RenderTypeLookup.canRenderInLayer(tile.cover, layer))
|
||||
matrixStack.pushPose();
|
||||
ForgeBlockModelRenderer.enableCaching();
|
||||
var renderer = Minecraft.getInstance().getBlockRenderer();
|
||||
for (var layer : RenderType.chunkBufferLayers()) {
|
||||
if (!ItemBlockRenderTypes.canRenderInLayer(tile.cover, layer))
|
||||
continue;
|
||||
ForgeHooksClient.setRenderLayer(layer);
|
||||
Minecraft.getInstance().getBlockRendererDispatcher().renderBlock(tile.cover, matrixStack, buffer, light, overlay, EmptyModelData.INSTANCE);
|
||||
ForgeHooksClient.setRenderType(layer);
|
||||
renderer.getModelRenderer().tesselateBlock(tile.getLevel(), renderer.getBlockModel(tile.cover), tile.cover, tile.getBlockPos(), matrixStack, source.getBuffer(layer), true, new Random(), tile.cover.getSeed(tile.getBlockPos()), overlay);
|
||||
}
|
||||
ForgeHooksClient.setRenderLayer(null);
|
||||
BlockModelRenderer.disableCache();
|
||||
matrixStack.pop();
|
||||
ForgeHooksClient.setRenderType(null);
|
||||
ForgeBlockModelRenderer.clearCache();
|
||||
matrixStack.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,28 +3,28 @@ package de.ellpeck.prettypipes.pipe.containers;
|
|||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.misc.FilterSlot;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class AbstractPipeContainer<T extends IModule> extends Container {
|
||||
public abstract class AbstractPipeContainer<T extends IModule> extends AbstractContainerMenu {
|
||||
|
||||
public final PipeTileEntity tile;
|
||||
public final PipeBlockEntity tile;
|
||||
public final T module;
|
||||
public final int moduleIndex;
|
||||
public final ItemStack moduleStack;
|
||||
|
||||
public AbstractPipeContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public AbstractPipeContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id);
|
||||
this.tile = Utility.getBlockEntity(PipeTileEntity.class, player.world, pos);
|
||||
this.tile = Utility.getBlockEntity(PipeBlockEntity.class, player.level, pos);
|
||||
this.moduleStack = moduleIndex < 0 ? null : this.tile.modules.getStackInSlot(moduleIndex);
|
||||
this.module = moduleIndex < 0 ? null : (T) this.moduleStack.getItem();
|
||||
this.moduleIndex = moduleIndex;
|
||||
|
@ -32,23 +32,18 @@ public abstract class AbstractPipeContainer<T extends IModule> extends Container
|
|||
// needs to be done here so transferStackInSlot works correctly, bleh
|
||||
this.addSlots();
|
||||
|
||||
for (int l = 0; l < 3; ++l)
|
||||
for (int j1 = 0; j1 < 9; ++j1)
|
||||
this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + j1 * 18, 89 + l * 18 + 32));
|
||||
for (int i1 = 0; i1 < 9; ++i1)
|
||||
this.addSlot(new Slot(player.inventory, i1, 8 + i1 * 18, 147 + 32));
|
||||
for (var l = 0; l < 3; ++l)
|
||||
for (var j1 = 0; j1 < 9; ++j1)
|
||||
this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + j1 * 18, 89 + l * 18 + 32));
|
||||
for (var i1 = 0; i1 < 9; ++i1)
|
||||
this.addSlot(new Slot(player.getInventory(), i1, 8 + i1 * 18, 147 + 32));
|
||||
}
|
||||
|
||||
protected abstract void addSlots();
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(PlayerEntity playerIn) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::mergeItemStack, player, slotIndex, stack -> {
|
||||
public ItemStack quickMoveStack(Player player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::moveItemStackTo, player, slotIndex, stack -> {
|
||||
if (stack.getItem() instanceof IModule)
|
||||
return Pair.of(0, 3);
|
||||
return null;
|
||||
|
@ -56,9 +51,14 @@ public abstract class AbstractPipeContainer<T extends IModule> extends Container
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) {
|
||||
public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) {
|
||||
if (FilterSlot.checkFilter(this, slotId, player))
|
||||
return ItemStack.EMPTY;
|
||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
return;
|
||||
super.clicked(slotId, dragType, clickTypeIn, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
package de.ellpeck.prettypipes.pipe.containers;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import net.minecraft.client.audio.SimpleSound;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extends ContainerScreen<T> {
|
||||
public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extends AbstractContainerScreen<T> {
|
||||
|
||||
protected static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pipe.png");
|
||||
private final List<Tab> tabs = new ArrayList<>();
|
||||
private final ItemStack[] lastItems = new ItemStack[this.container.tile.modules.getSlots()];
|
||||
private final ItemStack[] lastItems = new ItemStack[this.menu.tile.modules.getSlots()];
|
||||
|
||||
public AbstractPipeGui(T screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
public AbstractPipeGui(T screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
this.xSize = 176;
|
||||
this.ySize = 171 + 32;
|
||||
this.imageWidth = 176;
|
||||
this.imageHeight = 171 + 32;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,12 +38,12 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
|||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
public void containerTick() {
|
||||
super.containerTick();
|
||||
|
||||
boolean changed = false;
|
||||
for (int i = 0; i < this.container.tile.modules.getSlots(); i++) {
|
||||
ItemStack stack = this.container.tile.modules.getStackInSlot(i);
|
||||
var changed = false;
|
||||
for (var i = 0; i < this.menu.tile.modules.getSlots(); i++) {
|
||||
var stack = this.menu.tile.modules.getStackInSlot(i);
|
||||
if (stack != this.lastItems[i]) {
|
||||
this.lastItems[i] = stack;
|
||||
changed = true;
|
||||
|
@ -54,43 +54,44 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(matrix);
|
||||
super.render(matrix, mouseX, mouseY, partialTicks);
|
||||
for (Widget widget : this.buttons) {
|
||||
if (widget.isHovered())
|
||||
widget.renderToolTip(matrix, mouseX, mouseY);
|
||||
for (var widget : this.renderables) {
|
||||
if (widget instanceof AbstractWidget abstractWidget) {
|
||||
if (abstractWidget.isHoveredOrFocused())
|
||||
abstractWidget.renderToolTip(matrix, mouseX, mouseY);
|
||||
}
|
||||
this.func_230459_a_(matrix, mouseX, mouseY);
|
||||
}
|
||||
this.renderTooltip(matrix, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
this.font.drawString(matrix, this.playerInventory.getDisplayName().getString(), 8, this.ySize - 96 + 2, 4210752);
|
||||
this.font.drawString(matrix, this.title.getString(), 8, 6 + 32, 4210752);
|
||||
for (Tab tab : this.tabs)
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
this.font.draw(matrix, this.playerInventoryTitle.getString(), 8, this.imageHeight - 96 + 2, 4210752);
|
||||
this.font.draw(matrix, this.title.getString(), 8, 6 + 32, 4210752);
|
||||
for (var tab : this.tabs)
|
||||
tab.drawForeground(matrix, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
this.blit(matrix, this.guiLeft, this.guiTop + 32, 0, 0, 176, 171);
|
||||
protected void renderBg(PoseStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
this.blit(matrix, this.leftPos, this.topPos + 32, 0, 0, 176, 171);
|
||||
|
||||
for (Tab tab : this.tabs)
|
||||
for (var tab : this.tabs)
|
||||
tab.draw(matrix);
|
||||
|
||||
// draw the slots since we're using a blank ui
|
||||
for (Slot slot : this.container.inventorySlots) {
|
||||
if (slot.inventory == this.playerInventory)
|
||||
continue;
|
||||
this.blit(matrix, this.guiLeft + slot.xPos - 1, this.guiTop + slot.yPos - 1, 176, 62, 18, 18);
|
||||
for (var slot : this.menu.slots) {
|
||||
if (slot instanceof SlotItemHandler)
|
||||
this.blit(matrix, this.leftPos + slot.x - 1, this.topPos + slot.y - 1, 176, 62, 18, 18);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double x, double y, int button) {
|
||||
for (Tab tab : this.tabs) {
|
||||
for (var tab : this.tabs) {
|
||||
if (tab.onClicked(x, y, button))
|
||||
return true;
|
||||
}
|
||||
|
@ -100,17 +101,18 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
|||
private void initTabs() {
|
||||
this.tabs.clear();
|
||||
this.tabs.add(new Tab(new ItemStack(Registry.pipeBlock), 0, -1));
|
||||
for (int i = 0; i < this.container.tile.modules.getSlots(); i++) {
|
||||
ItemStack stack = this.container.tile.modules.getStackInSlot(i);
|
||||
for (var i = 0; i < this.menu.tile.modules.getSlots(); i++) {
|
||||
var stack = this.menu.tile.modules.getStackInSlot(i);
|
||||
if (stack.isEmpty())
|
||||
continue;
|
||||
IModule module = (IModule) stack.getItem();
|
||||
if (module.hasContainer(stack, this.container.tile))
|
||||
var module = (IModule) stack.getItem();
|
||||
if (module.hasContainer(stack, this.menu.tile))
|
||||
this.tabs.add(new Tab(stack, this.tabs.size(), i));
|
||||
}
|
||||
}
|
||||
|
||||
private class Tab {
|
||||
|
||||
private final ItemStack moduleStack;
|
||||
private final int index;
|
||||
private final int x;
|
||||
|
@ -119,16 +121,16 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
|||
public Tab(ItemStack moduleStack, int tabIndex, int index) {
|
||||
this.moduleStack = moduleStack;
|
||||
this.index = index;
|
||||
this.x = AbstractPipeGui.this.guiLeft + 5 + tabIndex * 28;
|
||||
this.y = AbstractPipeGui.this.guiTop;
|
||||
this.x = AbstractPipeGui.this.leftPos + 5 + tabIndex * 28;
|
||||
this.y = AbstractPipeGui.this.topPos;
|
||||
}
|
||||
|
||||
private void draw(MatrixStack matrix) {
|
||||
int y = 2;
|
||||
int v = 0;
|
||||
int height = 30;
|
||||
int itemOffset = 9;
|
||||
if (this.index == AbstractPipeGui.this.container.moduleIndex) {
|
||||
private void draw(PoseStack matrix) {
|
||||
var y = 2;
|
||||
var v = 0;
|
||||
var height = 30;
|
||||
var itemOffset = 9;
|
||||
if (this.index == AbstractPipeGui.this.menu.moduleIndex) {
|
||||
y = 0;
|
||||
v = 30;
|
||||
height = 32;
|
||||
|
@ -136,25 +138,25 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
|||
}
|
||||
AbstractPipeGui.this.blit(matrix, this.x, this.y + y, 176, v, 28, height);
|
||||
|
||||
AbstractPipeGui.this.itemRenderer.renderItemIntoGUI(this.moduleStack, this.x + 6, this.y + itemOffset);
|
||||
AbstractPipeGui.this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
AbstractPipeGui.this.itemRenderer.renderGuiItem(this.moduleStack, this.x + 6, this.y + itemOffset);
|
||||
AbstractPipeGui.this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
}
|
||||
|
||||
private void drawForeground(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
private void drawForeground(PoseStack matrix, int mouseX, int mouseY) {
|
||||
if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 28 || mouseY >= this.y + 32)
|
||||
return;
|
||||
AbstractPipeGui.this.renderTooltip(matrix, this.moduleStack.getDisplayName(), mouseX - AbstractPipeGui.this.guiLeft, mouseY - AbstractPipeGui.this.guiTop);
|
||||
AbstractPipeGui.this.renderTooltip(matrix, this.moduleStack.getDisplayName(), mouseX - AbstractPipeGui.this.leftPos, mouseY - AbstractPipeGui.this.topPos);
|
||||
}
|
||||
|
||||
private boolean onClicked(double mouseX, double mouseY, int button) {
|
||||
if (this.index == AbstractPipeGui.this.container.moduleIndex)
|
||||
if (this.index == AbstractPipeGui.this.menu.moduleIndex)
|
||||
return false;
|
||||
if (button != 0)
|
||||
return false;
|
||||
if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 28 || mouseY >= this.y + 32)
|
||||
return false;
|
||||
PacketHandler.sendToServer(new PacketButton(AbstractPipeGui.this.container.tile.getPos(), PacketButton.ButtonResult.PIPE_TAB, this.index));
|
||||
AbstractPipeGui.this.getMinecraft().getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1));
|
||||
PacketHandler.sendToServer(new PacketButton(AbstractPipeGui.this.menu.tile.getBlockPos(), PacketButton.ButtonResult.PIPE_TAB, this.index));
|
||||
AbstractPipeGui.this.getMinecraft().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package de.ellpeck.prettypipes.pipe.containers;
|
||||
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MainPipeContainer extends AbstractPipeContainer<IModule> {
|
||||
public MainPipeContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos) {
|
||||
|
||||
public MainPipeContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos) {
|
||||
super(type, id, player, pos, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (var i = 0; i < 3; i++)
|
||||
this.addSlot(new SlotItemHandler(this.tile.modules, i, 62 + i * 18, 17 + 32));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package de.ellpeck.prettypipes.pipe.containers;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class MainPipeGui extends AbstractPipeGui<MainPipeContainer> {
|
||||
public MainPipeGui(MainPipeContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public MainPipeGui(MainPipeContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules;
|
|||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.items.ModuleTier;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class HighPriorityModuleItem extends ModuleItem {
|
||||
|
@ -15,17 +15,17 @@ public class HighPriorityModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getPriority(ItemStack module, PipeTileEntity tile) {
|
||||
public int getPriority(ItemStack module, PipeBlockEntity tile) {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return !(other instanceof HighPriorityModuleItem) && !(other instanceof LowPriorityModuleItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules;
|
|||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.items.ModuleTier;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class LowPriorityModuleItem extends ModuleItem {
|
||||
|
@ -15,17 +15,17 @@ public class LowPriorityModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getPriority(ItemStack module, PipeTileEntity tile) {
|
||||
public int getPriority(ItemStack module, PipeBlockEntity tile) {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return !(other instanceof LowPriorityModuleItem) && !(other instanceof HighPriorityModuleItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package de.ellpeck.prettypipes.pipe.modules;
|
|||
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class RedstoneModuleItem extends ModuleItem {
|
||||
|
@ -13,17 +13,17 @@ public class RedstoneModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canPipeWork(ItemStack module, PipeTileEntity tile) {
|
||||
return !tile.getWorld().isBlockPowered(tile.getPos());
|
||||
public boolean canPipeWork(ItemStack module, PipeBlockEntity tile) {
|
||||
return !tile.getLevel().hasNeighborSignal(tile.getBlockPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return other != this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package de.ellpeck.prettypipes.pipe.modules;
|
|||
|
||||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,25 +19,25 @@ public class SortingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return !(other instanceof SortingModuleItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCustomNextNode(ItemStack module, PipeTileEntity tile, List<BlockPos> nodes, int index) {
|
||||
public Integer getCustomNextNode(ItemStack module, PipeBlockEntity tile, List<BlockPos> nodes, int index) {
|
||||
switch (this.type) {
|
||||
case ROUND_ROBIN:
|
||||
// store an ever-increasing index and choose destinations based on that
|
||||
int next = module.hasTag() ? module.getTag().getInt("last") + 1 : 0;
|
||||
var next = module.hasTag() ? module.getTag().getInt("last") + 1 : 0;
|
||||
module.getOrCreateTag().putInt("last", next);
|
||||
return next % nodes.size();
|
||||
case RANDOM:
|
||||
return tile.getWorld().rand.nextInt(nodes.size());
|
||||
return tile.getLevel().random.nextInt(nodes.size());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules;
|
|||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.items.ModuleTier;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class SpeedModuleItem extends ModuleItem {
|
||||
|
@ -15,17 +15,17 @@ public class SpeedModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return !(other instanceof SpeedModuleItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getItemSpeedIncrease(ItemStack module, PipeTileEntity tile) {
|
||||
public float getItemSpeedIncrease(ItemStack module, PipeBlockEntity tile) {
|
||||
return this.speedIncrease;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package de.ellpeck.prettypipes.pipe.modules.craft;
|
|||
|
||||
import de.ellpeck.prettypipes.misc.FilterSlot;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModuleItem> {
|
||||
|
@ -13,29 +13,30 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
|||
public ItemStackHandler output;
|
||||
public boolean modified;
|
||||
|
||||
public CraftingModuleContainer(ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public CraftingModuleContainer(MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
this.input = this.module.getInput(this.moduleStack);
|
||||
for (int i = 0; i < this.input.getSlots(); i++) {
|
||||
for (var i = 0; i < this.input.getSlots(); i++) {
|
||||
this.addSlot(new FilterSlot(this.input, i, (176 - this.module.inputSlots * 18) / 2 + 1 + i % 9 * 18, 17 + 32 + i / 9 * 18, false) {
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
super.onSlotChanged();
|
||||
public void setChanged() {
|
||||
super.setChanged();
|
||||
CraftingModuleContainer.this.modified = true;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
this.output = this.module.getOutput(this.moduleStack);
|
||||
for (int i = 0; i < this.output.getSlots(); i++) {
|
||||
for (var i = 0; i < this.output.getSlots(); i++) {
|
||||
this.addSlot(new FilterSlot(this.output, i, (176 - this.module.outputSlots * 18) / 2 + 1 + i % 9 * 18, 85 + i / 9 * 18, false) {
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
super.onSlotChanged();
|
||||
public void setChanged() {
|
||||
super.setChanged();
|
||||
CraftingModuleContainer.this.modified = true;
|
||||
}
|
||||
});
|
||||
|
@ -43,8 +44,8 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
if (this.modified)
|
||||
this.module.save(this.input, this.output, this.moduleStack);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.craft;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class CraftingModuleGui extends AbstractPipeGui<CraftingModuleContainer> {
|
||||
public CraftingModuleGui(CraftingModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public CraftingModuleGui(CraftingModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(matrix, partialTicks, mouseX, mouseY);
|
||||
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
this.blit(matrix, this.guiLeft + 176 / 2 - 16 / 2, this.guiTop + 32 + 18 * 2, 176, 80, 16, 16);
|
||||
protected void renderBg(PoseStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
super.renderBg(matrix, partialTicks, mouseX, mouseY);
|
||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
this.blit(matrix, this.leftPos + 176 / 2 - 16 / 2, this.topPos + 32 + 18 * 2, 176, 80, 16, 16);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,19 +6,17 @@ import de.ellpeck.prettypipes.items.ModuleItem;
|
|||
import de.ellpeck.prettypipes.items.ModuleTier;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||
import de.ellpeck.prettypipes.network.NetworkLock;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
|
@ -41,51 +39,51 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new CraftingModuleContainer(Registry.craftingModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new CraftingModuleContainer(Registry.craftingModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNetworkSee(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) {
|
||||
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(ItemStack module, PipeTileEntity tile) {
|
||||
public void tick(ItemStack module, PipeBlockEntity tile) {
|
||||
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
// process crafting ingredient requests
|
||||
if (!tile.craftIngredientRequests.isEmpty()) {
|
||||
network.startProfile("crafting_ingredients");
|
||||
NetworkLock request = tile.craftIngredientRequests.peek();
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
Pair<BlockPos, ItemStack> dest = tile.getAvailableDestination(request.stack, true, true);
|
||||
var request = tile.craftIngredientRequests.peek();
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var dest = tile.getAvailableDestination(request.stack, true, true);
|
||||
if (dest != null) {
|
||||
ItemStack requestRemain = network.requestExistingItem(request.location, tile.getPos(), dest.getLeft(), request, dest.getRight(), equalityTypes);
|
||||
var requestRemain = network.requestExistingItem(request.location, tile.getBlockPos(), dest.getLeft(), request, dest.getRight(), equalityTypes);
|
||||
network.resolveNetworkLock(request);
|
||||
tile.craftIngredientRequests.remove();
|
||||
|
||||
// if we couldn't fit all items into the destination, create another request for the rest
|
||||
ItemStack remain = request.stack.copy();
|
||||
var remain = request.stack.copy();
|
||||
remain.shrink(dest.getRight().getCount() - requestRemain.getCount());
|
||||
if (!remain.isEmpty()) {
|
||||
NetworkLock remainRequest = new NetworkLock(request.location, remain);
|
||||
var remainRequest = new NetworkLock(request.location, remain);
|
||||
tile.craftIngredientRequests.add(remainRequest);
|
||||
network.createNetworkLock(remainRequest);
|
||||
}
|
||||
|
@ -95,17 +93,17 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
// pull requested crafting results from the network once they are stored
|
||||
if (!tile.craftResultRequests.isEmpty()) {
|
||||
network.startProfile("crafting_results");
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(tile.getPos());
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
for (Pair<BlockPos, ItemStack> request : tile.craftResultRequests) {
|
||||
ItemStack remain = request.getRight().copy();
|
||||
PipeTileEntity destPipe = network.getPipe(request.getLeft());
|
||||
var items = network.getOrderedNetworkItems(tile.getBlockPos());
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
for (var request : tile.craftResultRequests) {
|
||||
var remain = request.getRight().copy();
|
||||
var destPipe = network.getPipe(request.getLeft());
|
||||
if (destPipe != null) {
|
||||
Pair<BlockPos, ItemStack> dest = destPipe.getAvailableDestinationOrConnectable(remain, true, true);
|
||||
var dest = destPipe.getAvailableDestinationOrConnectable(remain, true, true);
|
||||
if (dest == null)
|
||||
continue;
|
||||
for (NetworkLocation item : items) {
|
||||
ItemStack requestRemain = network.requestExistingItem(item, request.getLeft(), dest.getLeft(), null, dest.getRight(), equalityTypes);
|
||||
for (var item : items) {
|
||||
var requestRemain = network.requestExistingItem(item, request.getLeft(), dest.getLeft(), null, dest.getRight(), equalityTypes);
|
||||
remain.shrink(dest.getRight().getCount() - requestRemain.getCount());
|
||||
if (remain.isEmpty())
|
||||
break;
|
||||
|
@ -125,11 +123,11 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getAllCraftables(ItemStack module, PipeTileEntity tile) {
|
||||
public List<ItemStack> getAllCraftables(ItemStack module, PipeBlockEntity tile) {
|
||||
List<ItemStack> ret = new ArrayList<>();
|
||||
ItemStackHandler output = this.getOutput(module);
|
||||
for (int i = 0; i < output.getSlots(); i++) {
|
||||
ItemStack stack = output.getStackInSlot(i);
|
||||
var output = this.getOutput(module);
|
||||
for (var i = 0; i < output.getSlots(); i++) {
|
||||
var stack = output.getStackInSlot(i);
|
||||
if (!stack.isEmpty())
|
||||
ret.add(stack);
|
||||
}
|
||||
|
@ -137,19 +135,19 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getCraftableAmount(ItemStack module, PipeTileEntity tile, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(tile.getPos());
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
ItemStackHandler input = this.getInput(module);
|
||||
public int getCraftableAmount(ItemStack module, PipeBlockEntity tile, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain) {
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
var items = network.getOrderedNetworkItems(tile.getBlockPos());
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var input = this.getInput(module);
|
||||
|
||||
int craftable = 0;
|
||||
ItemStackHandler output = this.getOutput(module);
|
||||
for (int i = 0; i < output.getSlots(); i++) {
|
||||
ItemStack out = output.getStackInSlot(i);
|
||||
var craftable = 0;
|
||||
var output = this.getOutput(module);
|
||||
for (var i = 0; i < output.getSlots(); i++) {
|
||||
var out = output.getStackInSlot(i);
|
||||
if (!out.isEmpty() && ItemEquality.compareItems(out, stack, equalityTypes)) {
|
||||
// figure out how many crafting operations we can actually do with the input items we have in the network
|
||||
int availableCrafts = CraftingTerminalTileEntity.getAvailableCrafts(tile, input.getSlots(), input::getStackInSlot, k -> true, s -> items, unavailableConsumer, addDependency(dependencyChain, module), equalityTypes);
|
||||
var availableCrafts = CraftingTerminalBlockEntity.getAvailableCrafts(tile, input.getSlots(), input::getStackInSlot, k -> true, s -> items, unavailableConsumer, addDependency(dependencyChain, module), equalityTypes);
|
||||
if (availableCrafts > 0)
|
||||
craftable += out.getCount() * availableCrafts;
|
||||
}
|
||||
|
@ -158,35 +156,35 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(ItemStack module, PipeTileEntity 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
|
||||
int craftableAmount = this.getCraftableAmount(module, tile, unavailableConsumer, stack, dependencyChain);
|
||||
var craftableAmount = this.getCraftableAmount(module, tile, unavailableConsumer, stack, dependencyChain);
|
||||
if (craftableAmount <= 0)
|
||||
return stack;
|
||||
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
List<NetworkLocation> items = network.getOrderedNetworkItems(tile.getPos());
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
var items = network.getOrderedNetworkItems(tile.getBlockPos());
|
||||
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
int resultAmount = this.getResultAmountPerCraft(module, stack, equalityTypes);
|
||||
int requiredCrafts = MathHelper.ceil(stack.getCount() / (float) resultAmount);
|
||||
int toCraft = Math.min(craftableAmount, requiredCrafts);
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var resultAmount = this.getResultAmountPerCraft(module, stack, equalityTypes);
|
||||
var requiredCrafts = Mth.ceil(stack.getCount() / (float) resultAmount);
|
||||
var toCraft = Math.min(craftableAmount, requiredCrafts);
|
||||
|
||||
ItemStackHandler input = this.getInput(module);
|
||||
for (int i = 0; i < input.getSlots(); i++) {
|
||||
ItemStack in = input.getStackInSlot(i);
|
||||
var input = this.getInput(module);
|
||||
for (var i = 0; i < input.getSlots(); i++) {
|
||||
var in = input.getStackInSlot(i);
|
||||
if (in.isEmpty())
|
||||
continue;
|
||||
ItemStack copy = in.copy();
|
||||
var copy = in.copy();
|
||||
copy.setCount(in.getCount() * toCraft);
|
||||
Pair<List<NetworkLock>, ItemStack> ret = ItemTerminalTileEntity.requestItemLater(tile.getWorld(), tile.getPos(), items, unavailableConsumer, copy, addDependency(dependencyChain, module), equalityTypes);
|
||||
var ret = ItemTerminalBlockEntity.requestItemLater(tile.getLevel(), tile.getBlockPos(), items, unavailableConsumer, copy, addDependency(dependencyChain, module), equalityTypes);
|
||||
tile.craftIngredientRequests.addAll(ret.getLeft());
|
||||
}
|
||||
|
||||
ItemStack remain = stack.copy();
|
||||
var remain = stack.copy();
|
||||
remain.shrink(resultAmount * toCraft);
|
||||
|
||||
ItemStack result = stack.copy();
|
||||
var result = stack.copy();
|
||||
result.shrink(remain.getCount());
|
||||
tile.craftResultRequests.add(Pair.of(destPipe, result));
|
||||
|
||||
|
@ -194,21 +192,21 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
public ItemStackHandler getInput(ItemStack module) {
|
||||
ItemStackHandler handler = new ItemStackHandler(this.inputSlots);
|
||||
var handler = new ItemStackHandler(this.inputSlots);
|
||||
if (module.hasTag())
|
||||
handler.deserializeNBT(module.getTag().getCompound("input"));
|
||||
return handler;
|
||||
}
|
||||
|
||||
public ItemStackHandler getOutput(ItemStack module) {
|
||||
ItemStackHandler handler = new ItemStackHandler(this.outputSlots);
|
||||
var handler = new ItemStackHandler(this.outputSlots);
|
||||
if (module.hasTag())
|
||||
handler.deserializeNBT(module.getTag().getCompound("output"));
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void save(ItemStackHandler input, ItemStackHandler output, ItemStack module) {
|
||||
CompoundTag tag = module.getOrCreateTag();
|
||||
var tag = module.getOrCreateTag();
|
||||
if (input != null)
|
||||
tag.put("input", input.serializeNBT());
|
||||
if (output != null)
|
||||
|
@ -216,10 +214,10 @@ public class CraftingModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
private int getResultAmountPerCraft(ItemStack module, ItemStack stack, ItemEquality... equalityTypes) {
|
||||
ItemStackHandler output = this.getOutput(module);
|
||||
int resultAmount = 0;
|
||||
for (int i = 0; i < output.getSlots(); i++) {
|
||||
ItemStack out = output.getStackInSlot(i);
|
||||
var output = this.getOutput(module);
|
||||
var resultAmount = 0;
|
||||
for (var i = 0; i < output.getSlots(); i++) {
|
||||
var out = output.getStackInSlot(i);
|
||||
if (ItemEquality.compareItems(stack, out, equalityTypes))
|
||||
resultAmount += out.getCount();
|
||||
}
|
||||
|
|
|
@ -3,10 +3,9 @@ package de.ellpeck.prettypipes.pipe.modules.extraction;
|
|||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -14,20 +13,20 @@ public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionM
|
|||
|
||||
public ItemFilter filter;
|
||||
|
||||
public ExtractionModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public ExtractionModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
||||
for (Slot slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
|
||||
for (var slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
|
||||
this.addSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
this.filter.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.extraction;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class ExtractionModuleGui extends AbstractPipeGui<ExtractionModuleContainer> {
|
||||
public ExtractionModuleGui(ExtractionModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public ExtractionModuleGui(ExtractionModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
for (Widget widget : this.container.filter.getButtons(this, this.guiLeft + 7, this.guiTop + 17 + 32 + 20))
|
||||
this.addButton(widget);
|
||||
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
|
||||
this.addRenderableWidget(widget);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,12 @@ import de.ellpeck.prettypipes.items.ModuleItem;
|
|||
import de.ellpeck.prettypipes.items.ModuleTier;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class ExtractionModuleItem extends ModuleItem {
|
||||
|
||||
|
@ -30,23 +29,23 @@ public class ExtractionModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void tick(ItemStack module, PipeTileEntity tile) {
|
||||
public void tick(ItemStack module, PipeBlockEntity tile) {
|
||||
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
|
||||
return;
|
||||
ItemFilter filter = this.getItemFilter(module, tile);
|
||||
var filter = this.getItemFilter(module, tile);
|
||||
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
for (Direction dir : Direction.values()) {
|
||||
IItemHandler handler = tile.getItemHandler(dir);
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
for (var dir : Direction.values()) {
|
||||
var handler = tile.getItemHandler(dir);
|
||||
if (handler == null)
|
||||
continue;
|
||||
for (int j = 0; j < handler.getSlots(); j++) {
|
||||
ItemStack stack = handler.extractItem(j, this.maxExtraction, true);
|
||||
for (var j = 0; j < handler.getSlots(); j++) {
|
||||
var stack = handler.extractItem(j, this.maxExtraction, true);
|
||||
if (stack.isEmpty())
|
||||
continue;
|
||||
if (!filter.isAllowed(stack))
|
||||
continue;
|
||||
ItemStack remain = network.routeItem(tile.getPos(), tile.getPos().offset(dir), stack, this.preventOversending);
|
||||
var remain = network.routeItem(tile.getBlockPos(), tile.getBlockPos().relative(dir), stack, this.preventOversending);
|
||||
if (remain.getCount() != stack.getCount()) {
|
||||
handler.extractItem(j, stack.getCount() - remain.getCount(), false);
|
||||
return;
|
||||
|
@ -56,32 +55,32 @@ public class ExtractionModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canNetworkSee(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) {
|
||||
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return !(other instanceof ExtractionModuleItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new ExtractionModuleContainer(Registry.extractionModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new ExtractionModuleContainer(Registry.extractionModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) {
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
||||
return new ItemFilter(this.filterSlots, module, tile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,29 +2,29 @@ package de.ellpeck.prettypipes.pipe.modules.filter;
|
|||
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
|
||||
public class FilterIncreaseModuleContainer extends AbstractPipeContainer<FilterIncreaseModuleItem> implements ItemFilter.IFilteredContainer {
|
||||
|
||||
public ItemFilter filter;
|
||||
|
||||
public FilterIncreaseModuleContainer(ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public FilterIncreaseModuleContainer(MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
||||
for (Slot slot : this.filter.getSlots(8, 49))
|
||||
for (var slot : this.filter.getSlots(8, 49))
|
||||
this.addSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
this.filter.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.filter;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class FilterIncreaseModuleGui extends AbstractPipeGui<FilterIncreaseModuleContainer> {
|
||||
public FilterIncreaseModuleGui(FilterIncreaseModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public FilterIncreaseModuleGui(FilterIncreaseModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class FilterIncreaseModuleItem extends ModuleItem {
|
||||
|
@ -18,23 +18,23 @@ public class FilterIncreaseModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new FilterIncreaseModuleContainer(Registry.filterIncreaseModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new FilterIncreaseModuleContainer(Registry.filterIncreaseModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) {
|
||||
ItemFilter filter = new ItemFilter(18, module, tile);
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
||||
var filter = new ItemFilter(18, module, tile);
|
||||
filter.canModifyWhitelist = false;
|
||||
return filter;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ package de.ellpeck.prettypipes.pipe.modules.insertion;
|
|||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -14,20 +14,20 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
|
|||
|
||||
public ItemFilter filter;
|
||||
|
||||
public FilterModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public FilterModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
||||
for (Slot slot : this.filter.getSlots((176 - Math.min(this.module.filterSlots, 9) * 18) / 2 + 1, 17 + 32))
|
||||
for (var slot : this.filter.getSlots((176 - Math.min(this.module.filterSlots, 9) * 18) / 2 + 1, 17 + 32))
|
||||
this.addSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
this.filter.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.insertion;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class FilterModuleGui extends AbstractPipeGui<FilterModuleContainer> {
|
||||
public FilterModuleGui(FilterModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public FilterModuleGui(FilterModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
for (Widget widget : this.container.filter.getButtons(this, this.guiLeft + 7, this.guiTop + 17 + 32 + 18 * MathHelper.ceil(this.container.filter.getSlots() / 9F) + 2))
|
||||
this.addButton(widget);
|
||||
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 18 * Mth.ceil(this.menu.filter.getSlots() / 9F) + 2))
|
||||
this.addRenderableWidget(widget);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ import de.ellpeck.prettypipes.items.IModule;
|
|||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.items.ModuleTier;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class FilterModuleItem extends ModuleItem {
|
||||
|
@ -23,29 +23,29 @@ public class FilterModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) {
|
||||
ItemFilter filter = this.getItemFilter(module, tile);
|
||||
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
|
||||
var filter = this.getItemFilter(module, tile);
|
||||
return filter.isAllowed(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return !(other instanceof FilterModuleItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new FilterModuleContainer(Registry.filterModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) {
|
||||
ItemFilter filter = new ItemFilter(this.filterSlots, module, tile);
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
||||
var filter = new ItemFilter(this.filterSlots, module, tile);
|
||||
filter.canPopulateFromInventories = this.canPopulateFromInventories;
|
||||
return filter;
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ package de.ellpeck.prettypipes.pipe.modules.modifier;
|
|||
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashSet;
|
||||
|
@ -16,15 +16,15 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterModifierModuleItem> {
|
||||
|
||||
public FilterModifierModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public FilterModifierModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
public List<ResourceLocation> getTags() {
|
||||
Set<ResourceLocation> unsortedTags = new HashSet<>();
|
||||
for (ItemFilter filter : this.tile.getFilters()) {
|
||||
for (int i = 0; i < filter.getSlots(); i++) {
|
||||
ItemStack stack = filter.getStackInSlot(i);
|
||||
for (var filter : this.tile.getFilters()) {
|
||||
for (var i = 0; i < filter.getSlots(); i++) {
|
||||
var stack = filter.getStackInSlot(i);
|
||||
unsortedTags.addAll(stack.getItem().getTags());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,59 +1,60 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.modifier;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.audio.SimpleSound;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModuleContainer> {
|
||||
|
||||
private int scrollOffset;
|
||||
private boolean isScrolling;
|
||||
private List<ResourceLocation> tags;
|
||||
private final List<Tag> tagButtons = new ArrayList<>();
|
||||
|
||||
public FilterModifierModuleGui(FilterModifierModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
public FilterModifierModuleGui(FilterModifierModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(matrix, partialTicks, mouseX, mouseY);
|
||||
this.blit(matrix, this.guiLeft + 7, this.guiTop + 32 + 15, 0, 196, 162, 60);
|
||||
protected void renderBg(PoseStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
super.renderBg(matrix, partialTicks, mouseX, mouseY);
|
||||
this.blit(matrix, this.leftPos + 7, this.topPos + 32 + 15, 0, 196, 162, 60);
|
||||
|
||||
for (Tag tag : this.tagButtons)
|
||||
for (var tag : this.tagButtons)
|
||||
tag.draw(matrix, mouseX, mouseY);
|
||||
|
||||
if (this.tags.size() >= 6) {
|
||||
float percentage = this.scrollOffset / (float) (this.tags.size() - 5);
|
||||
this.blit(matrix, this.guiLeft + 156, this.guiTop + 32 + 16 + (int) (percentage * (58 - 15)), 232, 241, 12, 15);
|
||||
var percentage = this.scrollOffset / (float) (this.tags.size() - 5);
|
||||
this.blit(matrix, this.leftPos + 156, this.topPos + 32 + 16 + (int) (percentage * (58 - 15)), 232, 241, 12, 15);
|
||||
} else {
|
||||
this.blit(matrix, this.guiLeft + 156, this.guiTop + 32 + 16, 244, 241, 12, 15);
|
||||
this.blit(matrix, this.leftPos + 156, this.topPos + 32 + 16, 244, 241, 12, 15);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
this.tags = this.container.getTags();
|
||||
this.tags = this.menu.getTags();
|
||||
this.updateWidgets();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
for (Tag tag : this.tagButtons) {
|
||||
for (var tag : this.tagButtons) {
|
||||
if (tag.onClicked(mouseX, mouseY, button))
|
||||
return true;
|
||||
}
|
||||
if (button == 0 && mouseX >= this.guiLeft + 156 && this.guiTop + mouseY >= 32 + 16 && mouseX < this.guiLeft + 156 + 12 && mouseY < this.guiTop + 32 + 16 + 58) {
|
||||
if (button == 0 && mouseX >= this.leftPos + 156 && this.topPos + mouseY >= 32 + 16 && mouseX < this.leftPos + 156 + 12 && mouseY < this.topPos + 32 + 16 + 58) {
|
||||
this.isScrolling = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -70,8 +71,8 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int i, double j, double k) {
|
||||
if (this.isScrolling) {
|
||||
float percentage = MathHelper.clamp(((float) mouseY - (this.guiTop + 32 + 18)) / (58 - 15), 0, 1);
|
||||
int offset = (int) (percentage * (float) (this.tags.size() - 5));
|
||||
var percentage = Mth.clamp(((float) mouseY - (this.topPos + 32 + 18)) / (58 - 15), 0, 1);
|
||||
var offset = (int) (percentage * (float) (this.tags.size() - 5));
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -84,7 +85,7 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double scroll) {
|
||||
if (this.tags.size() >= 6) {
|
||||
int offset = MathHelper.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.tags.size() - 5);
|
||||
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.tags.size() - 5);
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -95,10 +96,10 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
|
||||
private void updateWidgets() {
|
||||
this.tagButtons.clear();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (var i = 0; i < 5; i++) {
|
||||
if (i >= this.tags.size())
|
||||
break;
|
||||
this.tagButtons.add(new Tag(this.tags.get(this.scrollOffset + i), this.guiLeft + 10, this.guiTop + 32 + 17 + i * 12));
|
||||
this.tagButtons.add(new Tag(this.tags.get(this.scrollOffset + i), this.leftPos + 10, this.topPos + 32 + 17 + i * 12));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,15 +115,15 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
this.y = y;
|
||||
}
|
||||
|
||||
private void draw(MatrixStack matrix, double mouseX, double mouseY) {
|
||||
int color = 4210752;
|
||||
String text = this.tag.toString();
|
||||
private void draw(PoseStack matrix, double mouseX, double mouseY) {
|
||||
var color = 4210752;
|
||||
var text = this.tag.toString();
|
||||
if (mouseX >= this.x && mouseY >= this.y && mouseX < this.x + 140 && mouseY < this.y + 12)
|
||||
color = 0xFFFFFF;
|
||||
if (this.tag.equals(FilterModifierModuleItem.getFilterTag(FilterModifierModuleGui.this.container.moduleStack)))
|
||||
text = TextFormatting.BOLD + text;
|
||||
FilterModifierModuleGui.this.font.drawString(matrix, text, this.x, this.y, color);
|
||||
FilterModifierModuleGui.this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
if (this.tag.equals(FilterModifierModuleItem.getFilterTag(FilterModifierModuleGui.this.menu.moduleStack)))
|
||||
text = ChatFormatting.BOLD + text;
|
||||
FilterModifierModuleGui.this.font.draw(matrix, text, this.x, this.y, color);
|
||||
FilterModifierModuleGui.this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
}
|
||||
|
||||
private boolean onClicked(double mouseX, double mouseY, int button) {
|
||||
|
@ -130,8 +131,8 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
return false;
|
||||
if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 140 || mouseY >= this.y + 12)
|
||||
return false;
|
||||
PacketButton.sendAndExecute(FilterModifierModuleGui.this.container.tile.getPos(), PacketButton.ButtonResult.TAG_FILTER, FilterModifierModuleGui.this.tags.indexOf(this.tag));
|
||||
FilterModifierModuleGui.this.getMinecraft().getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1));
|
||||
PacketButton.sendAndExecute(FilterModifierModuleGui.this.menu.tile.getBlockPos(), PacketButton.ButtonResult.TAG_FILTER, FilterModifierModuleGui.this.tags.indexOf(this.tag));
|
||||
FilterModifierModuleGui.this.getMinecraft().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,13 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import joptsimple.internal.Strings;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class FilterModifierModuleItem extends ModuleItem {
|
||||
|
||||
|
@ -29,23 +23,18 @@ public class FilterModifierModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return other != this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return this.type == ItemEquality.Type.TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new FilterModifierModuleContainer(Registry.filterModifierModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new FilterModifierModuleContainer(Registry.filterModifierModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
public ItemEquality getEqualityType(ItemStack stack) {
|
||||
|
@ -59,7 +48,7 @@ public class FilterModifierModuleItem extends ModuleItem {
|
|||
public static ResourceLocation getFilterTag(ItemStack stack) {
|
||||
if (!stack.hasTag())
|
||||
return null;
|
||||
String tag = stack.getTag().getString("filter_tag");
|
||||
var tag = stack.getTag().getString("filter_tag");
|
||||
if (Strings.isNullOrEmpty(tag))
|
||||
return null;
|
||||
return new ResourceLocation(tag);
|
||||
|
|
|
@ -3,10 +3,10 @@ package de.ellpeck.prettypipes.pipe.modules.retrieval;
|
|||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -14,20 +14,20 @@ public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalMod
|
|||
|
||||
public ItemFilter filter;
|
||||
|
||||
public RetrievalModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
public RetrievalModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSlots() {
|
||||
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
||||
for (Slot slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
|
||||
for (var slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
|
||||
this.addSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
public void removed(Player playerIn) {
|
||||
super.removed(playerIn);
|
||||
this.filter.save();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.retrieval;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class RetrievalModuleGui extends AbstractPipeGui<RetrievalModuleContainer> {
|
||||
public RetrievalModuleGui(RetrievalModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public RetrievalModuleGui(RetrievalModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
for (Widget widget : this.container.filter.getButtons(this, this.guiLeft + 7, this.guiTop + 17 + 32 + 20))
|
||||
this.addButton(widget);
|
||||
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
|
||||
this.addRenderableWidget(widget);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,15 +7,16 @@ import de.ellpeck.prettypipes.items.ModuleTier;
|
|||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public class RetrievalModuleItem extends ModuleItem {
|
||||
|
||||
private final int maxExtraction;
|
||||
private final int speed;
|
||||
private final boolean preventOversending;
|
||||
|
@ -30,60 +31,60 @@ public class RetrievalModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void tick(ItemStack module, PipeTileEntity tile) {
|
||||
public void tick(ItemStack module, PipeBlockEntity tile) {
|
||||
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(tile.getWorld());
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
|
||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||
// loop through filters to see which items to pull
|
||||
for (ItemFilter subFilter : tile.getFilters()) {
|
||||
for (int f = 0; f < subFilter.getSlots(); f++) {
|
||||
ItemStack filtered = subFilter.getStackInSlot(f);
|
||||
for (var subFilter : tile.getFilters()) {
|
||||
for (var f = 0; f < subFilter.getSlots(); f++) {
|
||||
var filtered = subFilter.getStackInSlot(f);
|
||||
if (filtered.isEmpty())
|
||||
continue;
|
||||
ItemStack copy = filtered.copy();
|
||||
var copy = filtered.copy();
|
||||
copy.setCount(this.maxExtraction);
|
||||
Pair<BlockPos, ItemStack> dest = tile.getAvailableDestination(copy, true, this.preventOversending);
|
||||
var dest = tile.getAvailableDestination(copy, true, this.preventOversending);
|
||||
if (dest == null)
|
||||
continue;
|
||||
ItemStack remain = dest.getRight().copy();
|
||||
var remain = dest.getRight().copy();
|
||||
// are we already waiting for crafting results? If so, don't request those again
|
||||
remain.shrink(network.getCurrentlyCraftingAmount(tile.getPos(), copy, equalityTypes));
|
||||
if (network.requestItem(tile.getPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
||||
remain.shrink(network.getCurrentlyCraftingAmount(tile.getBlockPos(), copy, equalityTypes));
|
||||
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canNetworkSee(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean canNetworkSee(ItemStack module, PipeBlockEntity tile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAcceptItem(ItemStack module, PipeTileEntity tile, ItemStack stack) {
|
||||
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return !(other instanceof RetrievalModuleItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new RetrievalModuleContainer(Registry.retrievalModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new RetrievalModuleContainer(Registry.retrievalModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeTileEntity tile) {
|
||||
ItemFilter filter = new ItemFilter(this.filterSlots, module, tile);
|
||||
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
||||
var filter = new ItemFilter(this.filterSlots, module, tile);
|
||||
filter.canModifyWhitelist = false;
|
||||
filter.isWhitelist = true;
|
||||
return filter;
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.stacksize;
|
||||
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StackSizeModuleContainer extends AbstractPipeContainer<StackSizeModuleItem> {
|
||||
public StackSizeModuleContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
|
||||
|
||||
public StackSizeModuleContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos, int moduleIndex) {
|
||||
super(type, id, player, pos, moduleIndex);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,57 +1,59 @@
|
|||
package de.ellpeck.prettypipes.pipe.modules.stacksize;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton.ButtonResult;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class StackSizeModuleGui extends AbstractPipeGui<StackSizeModuleContainer> {
|
||||
public StackSizeModuleGui(StackSizeModuleContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
|
||||
public StackSizeModuleGui(StackSizeModuleContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
TextFieldWidget textField = this.addButton(new TextFieldWidget(this.font, this.guiLeft + 7, this.guiTop + 17 + 32 + 10, 40, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".max_stack_size")) {
|
||||
var textField = this.addRenderableWidget(new EditBox(this.font, this.leftPos + 7, this.topPos + 17 + 32 + 10, 40, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".max_stack_size")) {
|
||||
@Override
|
||||
public void writeText(String textToWrite) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for (char c : textToWrite.toCharArray()) {
|
||||
public void insertText(String textToWrite) {
|
||||
var ret = new StringBuilder();
|
||||
for (var c : textToWrite.toCharArray()) {
|
||||
if (Character.isDigit(c))
|
||||
ret.append(c);
|
||||
}
|
||||
super.writeText(ret.toString());
|
||||
super.insertText(ret.toString());
|
||||
}
|
||||
|
||||
});
|
||||
textField.setText(String.valueOf(StackSizeModuleItem.getMaxStackSize(this.container.moduleStack)));
|
||||
textField.setMaxStringLength(4);
|
||||
textField.setValue(String.valueOf(StackSizeModuleItem.getMaxStackSize(this.menu.moduleStack)));
|
||||
textField.setMaxLength(4);
|
||||
textField.setResponder(s -> {
|
||||
if (s.isEmpty())
|
||||
return;
|
||||
int amount = Integer.parseInt(s);
|
||||
PacketButton.sendAndExecute(this.container.tile.getPos(), ButtonResult.STACK_SIZE_AMOUNT, amount);
|
||||
var amount = Integer.parseInt(s);
|
||||
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_AMOUNT, amount);
|
||||
});
|
||||
Supplier<TranslationTextComponent> buttonText = () -> new TranslationTextComponent("info." + PrettyPipes.ID + ".limit_to_max_" + (StackSizeModuleItem.getLimitToMaxStackSize(this.container.moduleStack) ? "on" : "off"));
|
||||
this.addButton(new Button(this.guiLeft + 7, this.guiTop + 17 + 32 + 10 + 22, 120, 20, buttonText.get(), b -> {
|
||||
PacketButton.sendAndExecute(this.container.tile.getPos(), ButtonResult.STACK_SIZE_MODULE_BUTTON);
|
||||
var buttonText = (Supplier<TranslatableComponent>) () -> new TranslatableComponent("info." + PrettyPipes.ID + ".limit_to_max_" + (StackSizeModuleItem.getLimitToMaxStackSize(this.menu.moduleStack) ? "on" : "off"));
|
||||
this.addRenderableWidget(new Button(this.leftPos + 7, this.topPos + 17 + 32 + 10 + 22, 120, 20, buttonText.get(), b -> {
|
||||
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_MODULE_BUTTON);
|
||||
b.setMessage(buttonText.get());
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(matrix, mouseX, mouseY);
|
||||
this.font.drawString(matrix, I18n.format("info." + PrettyPipes.ID + ".max_stack_size") + ":", 7, 17 + 32, 4210752);
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
super.renderLabels(matrix, mouseX, mouseY);
|
||||
this.font.draw(matrix, I18n.get("info." + PrettyPipes.ID + ".max_stack_size") + ":", 7, 17 + 32, 4210752);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.items.IModule;
|
||||
import de.ellpeck.prettypipes.items.ModuleItem;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class StackSizeModuleItem extends ModuleItem {
|
|||
|
||||
public static int getMaxStackSize(ItemStack module) {
|
||||
if (module.hasTag()) {
|
||||
int amount = module.getTag().getInt("max_stack_size");
|
||||
var amount = module.getTag().getInt("max_stack_size");
|
||||
if (amount > 0)
|
||||
return amount;
|
||||
}
|
||||
|
@ -42,13 +42,13 @@ public class StackSizeModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInsertionAmount(ItemStack module, PipeTileEntity tile, ItemStack stack, IItemHandler destination) {
|
||||
int max = getMaxStackSize(module);
|
||||
public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) {
|
||||
var max = getMaxStackSize(module);
|
||||
if (getLimitToMaxStackSize(module))
|
||||
max = Math.min(max, stack.getMaxStackSize());
|
||||
int amount = 0;
|
||||
for (int i = 0; i < destination.getSlots(); i++) {
|
||||
ItemStack stored = destination.getStackInSlot(i);
|
||||
var amount = 0;
|
||||
for (var i = 0; i < destination.getSlots(); i++) {
|
||||
var stored = destination.getStackInSlot(i);
|
||||
if (stored.isEmpty())
|
||||
continue;
|
||||
if (!ItemEquality.compareItems(stored, stack))
|
||||
|
@ -61,17 +61,17 @@ public class StackSizeModuleItem extends ModuleItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatible(ItemStack module, PipeTileEntity tile, IModule other) {
|
||||
public boolean isCompatible(ItemStack module, PipeBlockEntity tile, IModule other) {
|
||||
return !(other instanceof StackSizeModuleItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasContainer(ItemStack module, PipeTileEntity tile) {
|
||||
public boolean hasContainer(ItemStack module, PipeBlockEntity tile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeTileEntity tile, int windowId, PlayerInventory inv, PlayerEntity player, int moduleIndex) {
|
||||
return new StackSizeModuleContainer(Registry.stackSizeModuleContainer, windowId, player, tile.getPos(), moduleIndex);
|
||||
public AbstractPipeContainer<?> getContainer(ItemStack module, PipeBlockEntity tile, int windowId, Inventory inv, Player player, int moduleIndex) {
|
||||
return new StackSizeModuleContainer(Registry.stackSizeModuleContainer, windowId, player, tile.getBlockPos(), moduleIndex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +1,68 @@
|
|||
package de.ellpeck.prettypipes.pressurizer;
|
||||
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ContainerBlock;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class PressurizerBlock extends ContainerBlock {
|
||||
public class PressurizerBlock extends BaseEntityBlock {
|
||||
|
||||
public PressurizerBlock() {
|
||||
super(Properties.create(Material.ROCK).hardnessAndResistance(3).sound(SoundType.STONE));
|
||||
super(BlockBehaviour.Properties.of(Material.STONE).strength(3).sound(SoundType.STONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) {
|
||||
PressurizerBlockEntity tile = Utility.getBlockEntity(PressurizerBlockEntity.class, worldIn, pos);
|
||||
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
||||
var tile = Utility.getBlockEntity(PressurizerBlockEntity.class, worldIn, pos);
|
||||
if (tile == null)
|
||||
return ActionResultType.PASS;
|
||||
if (!worldIn.isRemote)
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
|
||||
return ActionResultType.SUCCESS;
|
||||
return InteractionResult.PASS;
|
||||
if (!worldIn.isClientSide)
|
||||
NetworkHooks.openGui((ServerPlayer) player, tile, pos);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new PressurizerBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
||||
return new PressurizerBlockEntity();
|
||||
public RenderShape getRenderShape(BlockState state) {
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
||||
return level.isClientSide ? null : createTickerHelper(type, Registry.pressurizerBlockEntity, PressurizerBlockEntity::tick);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,25 +6,21 @@ import de.ellpeck.prettypipes.Utility;
|
|||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.pipe.ConnectionType;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
|
||||
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.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
|
@ -33,19 +29,19 @@ import net.minecraftforge.energy.IEnergyStorage;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PressurizerBlockEntity extends BlockEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable {
|
||||
public class PressurizerBlockEntity extends BlockEntity implements MenuProvider, IPipeConnectable {
|
||||
|
||||
private final ModifiableEnergyStorage storage = new ModifiableEnergyStorage(64000, 512, 0);
|
||||
private final LazyOptional<IEnergyStorage> lazyStorage = LazyOptional.of(() -> this.storage);
|
||||
private final LazyOptional<IPipeConnectable> lazyThis = LazyOptional.of(() -> this);
|
||||
private int lastEnergy;
|
||||
|
||||
public PressurizerBlockEntity() {
|
||||
super(Registry.pressurizerTileEntity);
|
||||
public PressurizerBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Registry.pressurizerBlockEntity, pos, state);
|
||||
}
|
||||
|
||||
public boolean pressurizeItem(ItemStack stack, boolean simulate) {
|
||||
int amount = 100 * stack.getCount();
|
||||
var amount = 100 * stack.getCount();
|
||||
return this.storage.extractInternal(amount, simulate) >= amount;
|
||||
}
|
||||
|
||||
|
@ -62,41 +58,41 @@ public class PressurizerBlockEntity extends BlockEntity implements INamedContain
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag write(CompoundTag compound) {
|
||||
public CompoundTag save(CompoundTag compound) {
|
||||
compound.putInt("energy", this.getEnergy());
|
||||
return super.write(compound);
|
||||
return super.save(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(BlockState state, CompoundTag nbt) {
|
||||
public void load(CompoundTag nbt) {
|
||||
this.storage.setEnergyStored(nbt.getInt("energy"));
|
||||
super.read(state, nbt);
|
||||
super.load(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getUpdateTag() {
|
||||
return this.write(new CompoundTag());
|
||||
return this.save(new CompoundTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(BlockState state, CompoundTag tag) {
|
||||
this.read(state, tag);
|
||||
public void handleUpdateTag(CompoundTag tag) {
|
||||
this.load(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
|
||||
this.read(this.getBlockState(), pkt.getNbtCompound());
|
||||
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
|
||||
this.load(pkt.getTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("container." + PrettyPipes.ID + ".pressurizer");
|
||||
public Component getDisplayName() {
|
||||
return new TranslatableComponent("container." + PrettyPipes.ID + ".pressurizer");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) {
|
||||
return new PressurizerContainer(Registry.pressurizerContainer, window, player, this.pos);
|
||||
public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
|
||||
return new PressurizerContainer(Registry.pressurizerContainer, window, player, this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,43 +107,40 @@ public class PressurizerBlockEntity extends BlockEntity implements INamedContain
|
|||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
this.lazyStorage.invalidate();
|
||||
this.lazyThis.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (this.world.isRemote)
|
||||
return;
|
||||
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
|
||||
public static void tick(Level level, BlockPos pos, BlockState state, PressurizerBlockEntity pressurizer) {
|
||||
// notify pipes in network about us
|
||||
if (this.world.getGameTime() % 10 == 0) {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
for (Direction dir : Direction.values()) {
|
||||
BlockPos offset = this.pos.offset(dir);
|
||||
for (BlockPos node : network.getOrderedNetworkNodes(offset)) {
|
||||
if (!this.world.isBlockLoaded(node))
|
||||
if (pressurizer.level.getGameTime() % 10 == 0) {
|
||||
var network = PipeNetwork.get(pressurizer.level);
|
||||
for (var dir : Direction.values()) {
|
||||
var offset = pressurizer.worldPosition.relative(dir);
|
||||
for (var node : network.getOrderedNetworkNodes(offset)) {
|
||||
if (!pressurizer.level.isLoaded(node))
|
||||
continue;
|
||||
PipeTileEntity pipe = network.getPipe(node);
|
||||
var pipe = network.getPipe(node);
|
||||
if (pipe != null)
|
||||
pipe.pressurizer = this;
|
||||
pipe.pressurizer = pressurizer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// send energy update
|
||||
if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getGameTime() % 10 == 0) {
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
Utility.sendBlockEntityToClients(this);
|
||||
if (pressurizer.lastEnergy != pressurizer.storage.getEnergyStored() && pressurizer.level.getGameTime() % 10 == 0) {
|
||||
pressurizer.lastEnergy = pressurizer.storage.getEnergyStored();
|
||||
Utility.sendBlockEntityToClients(pressurizer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
|
||||
private static class ModifiableEnergyStorage extends EnergyStorage {
|
||||
|
||||
public ModifiableEnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
||||
|
@ -159,7 +152,7 @@ public class PressurizerBlockEntity extends BlockEntity implements INamedContain
|
|||
}
|
||||
|
||||
private int extractInternal(int maxExtract, boolean simulate) {
|
||||
int energyExtracted = Math.min(this.energy, maxExtract);
|
||||
var energyExtracted = Math.min(this.energy, maxExtract);
|
||||
if (!simulate)
|
||||
this.energy -= energyExtracted;
|
||||
return energyExtracted;
|
||||
|
|
|
@ -2,40 +2,36 @@ package de.ellpeck.prettypipes.pressurizer;
|
|||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PressurizerContainer extends AbstractContainerMenu {
|
||||
|
||||
public final PressurizerBlockEntity tile;
|
||||
|
||||
public PressurizerContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos) {
|
||||
super(type, id);
|
||||
this.tile = Utility.getBlockEntity(PressurizerBlockEntity.class, player.level, pos);
|
||||
|
||||
for (int l = 0; l < 3; ++l)
|
||||
for (int j1 = 0; j1 < 9; ++j1)
|
||||
for (var l = 0; l < 3; ++l)
|
||||
for (var j1 = 0; j1 < 9; ++j1)
|
||||
this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + j1 * 18, 55 + l * 18));
|
||||
for (int i1 = 0; i1 < 9; ++i1)
|
||||
for (var i1 = 0; i1 < 9; ++i1)
|
||||
this.addSlot(new Slot(player.getInventory(), i1, 8 + i1 * 18, 113));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::mergeItemStack, player, slotIndex, stack -> null);
|
||||
public ItemStack quickMoveStack(Player player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::moveItemStackTo, player, slotIndex, stack -> null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(PlayerEntity playerIn) {
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
package de.ellpeck.prettypipes.pressurizer;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class PressurizerGui extends AbstractContainerScreen<PressurizerContainer> {
|
||||
|
||||
public class PressurizerGui extends ContainerScreen<PressurizerContainer> {
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pressurizer.png");
|
||||
|
||||
public PressurizerGui(PressurizerContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
public PressurizerGui(PressurizerContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
this.xSize = 176;
|
||||
this.ySize = 137;
|
||||
this.imageWidth = 176;
|
||||
this.imageHeight = 137;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(matrix);
|
||||
super.render(matrix, mouseX, mouseY, partialTicks);
|
||||
this.func_230459_a_(matrix, mouseX, mouseY);
|
||||
if (mouseX >= this.guiLeft + 26 && mouseY >= this.guiTop + 22 && mouseX < this.guiLeft + 26 + 124 && mouseY < this.guiTop + 22 + 12)
|
||||
this.renderTooltip(matrix, new TranslationTextComponent("info." + PrettyPipes.ID + ".energy", this.container.tile.getEnergy(), this.container.tile.getMaxEnergy()), mouseX, mouseY);
|
||||
this.renderTooltip(matrix, mouseX, mouseY);
|
||||
if (mouseX >= this.leftPos + 26 && mouseY >= this.topPos + 22 && mouseX < this.leftPos + 26 + 124 && mouseY < this.topPos + 22 + 12)
|
||||
this.renderTooltip(matrix, new TranslatableComponent("info." + PrettyPipes.ID + ".energy", this.menu.tile.getEnergy(), this.menu.tile.getMaxEnergy()), mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
this.font.drawString(matrix, this.playerInventory.getDisplayName().getString(), 8, this.ySize - 96 + 2, 4210752);
|
||||
this.font.drawString(matrix, this.title.getString(), 8, 6, 4210752);
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
this.font.draw(matrix, this.playerInventoryTitle.getString(), 8, this.imageHeight - 96 + 2, 4210752);
|
||||
this.font.draw(matrix, this.title.getString(), 8, 6, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) {
|
||||
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
this.blit(matrixStack, this.guiLeft, this.guiTop, 0, 0, 176, 137);
|
||||
int energy = (int) (this.container.tile.getEnergyPercentage() * 124);
|
||||
this.blit(matrixStack, this.guiLeft + 26, this.guiTop + 22, 0, 137, energy, 12);
|
||||
protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y) {
|
||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
this.blit(matrixStack, this.leftPos, this.topPos, 0, 0, 176, 137);
|
||||
var energy = (int) (this.menu.tile.getEnergyPercentage() * 124);
|
||||
this.blit(matrixStack, this.leftPos + 26, this.topPos + 22, 0, 137, energy, 12);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
package de.ellpeck.prettypipes.terminal;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class CraftingTerminalBlock extends ItemTerminalBlock {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
||||
return new CraftingTerminalTileEntity();
|
||||
public @org.jetbrains.annotations.Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new CraftingTerminalBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
||||
return createTickerHelper(type, Registry.craftingTerminalBlockEntity, ItemTerminalBlockEntity::tick);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,25 +7,24 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.misc.EquatableItemStack;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.network.NetworkItem;
|
||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
@ -36,23 +35,23 @@ import java.util.function.Consumer;
|
|||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
||||
public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
||||
|
||||
public final ItemStackHandler craftItems = new ItemStackHandler(9) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
for (PlayerEntity playerEntity : CraftingTerminalTileEntity.this.getLookingPlayers())
|
||||
playerEntity.openContainer.onCraftMatrixChanged(null);
|
||||
for (var playerEntity : CraftingTerminalBlockEntity.this.getLookingPlayers())
|
||||
playerEntity.containerMenu.slotsChanged(null);
|
||||
}
|
||||
};
|
||||
public final ItemStackHandler ghostItems = new ItemStackHandler(9);
|
||||
|
||||
public CraftingTerminalTileEntity() {
|
||||
super(Registry.craftingTerminalTileEntity);
|
||||
public CraftingTerminalBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(Registry.craftingTerminalBlockEntity, pos, state);
|
||||
}
|
||||
|
||||
public ItemStack getRequestedCraftItem(int slot) {
|
||||
ItemStack stack = this.craftItems.getStackInSlot(slot);
|
||||
var stack = this.craftItems.getStackInSlot(slot);
|
||||
if (!stack.isEmpty())
|
||||
return stack;
|
||||
return this.ghostItems.getStackInSlot(slot);
|
||||
|
@ -64,30 +63,30 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
|||
|
||||
public void setGhostItems(ListMultimap<Integer, ItemStack> stacks) {
|
||||
this.updateItems();
|
||||
for (int i = 0; i < this.ghostItems.getSlots(); i++) {
|
||||
List<ItemStack> items = stacks.get(i);
|
||||
for (var i = 0; i < this.ghostItems.getSlots(); i++) {
|
||||
var items = stacks.get(i);
|
||||
if (items.isEmpty()) {
|
||||
this.ghostItems.setStackInSlot(i, ItemStack.EMPTY);
|
||||
continue;
|
||||
}
|
||||
ItemStack toSet = items.get(0);
|
||||
var toSet = items.get(0);
|
||||
// if we have more than one item to choose from, we want to pick the one that we have most of in the system
|
||||
if (items.size() > 1) {
|
||||
int highestAmount = 0;
|
||||
for (ItemStack stack : items) {
|
||||
int amount = 0;
|
||||
var highestAmount = 0;
|
||||
for (var stack : items) {
|
||||
var amount = 0;
|
||||
// check existing items
|
||||
NetworkItem network = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT));
|
||||
var network = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT));
|
||||
if (network != null) {
|
||||
amount = network.getLocations().stream()
|
||||
.mapToInt(l -> l.getItemAmount(this.world, stack, ItemEquality.NBT))
|
||||
.mapToInt(l -> l.getItemAmount(this.level, stack, ItemEquality.NBT))
|
||||
.sum();
|
||||
}
|
||||
// check craftables
|
||||
if (amount <= 0 && highestAmount <= 0) {
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe != null)
|
||||
amount = PipeNetwork.get(this.world).getCraftableAmount(pipe.getPos(), null, stack, new Stack<>(), ItemEquality.NBT);
|
||||
amount = PipeNetwork.get(this.level).getCraftableAmount(pipe.getBlockPos(), null, stack, new Stack<>(), ItemEquality.NBT);
|
||||
}
|
||||
if (amount > highestAmount) {
|
||||
highestAmount = amount;
|
||||
|
@ -98,77 +97,77 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
|||
this.ghostItems.setStackInSlot(i, toSet.copy());
|
||||
}
|
||||
|
||||
if (!this.world.isRemote) {
|
||||
if (!this.level.isClientSide) {
|
||||
ListMultimap<Integer, ItemStack> clients = ArrayListMultimap.create();
|
||||
for (int i = 0; i < this.ghostItems.getSlots(); i++)
|
||||
for (var i = 0; i < this.ghostItems.getSlots(); i++)
|
||||
clients.put(i, this.ghostItems.getStackInSlot(i));
|
||||
PacketHandler.sendToAllLoaded(this.world, this.pos, new PacketGhostSlot(this.pos, clients));
|
||||
PacketHandler.sendToAllLoaded(this.level, this.getBlockPos(), new PacketGhostSlot(this.getBlockPos(), clients));
|
||||
}
|
||||
}
|
||||
|
||||
public void requestCraftingItems(PlayerEntity player, int maxAmount) {
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
public void requestCraftingItems(Player player, int maxAmount) {
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
var network = PipeNetwork.get(this.level);
|
||||
network.startProfile("terminal_request_crafting");
|
||||
this.updateItems();
|
||||
// get the amount of crafts that we can do
|
||||
int lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
|
||||
NetworkItem item = this.networkItems.get(s);
|
||||
var lowestAvailable = getAvailableCrafts(pipe, this.craftItems.getSlots(), i -> ItemHandlerHelper.copyStackWithSize(this.getRequestedCraftItem(i), 1), this::isGhostItem, s -> {
|
||||
var item = this.networkItems.get(s);
|
||||
return item != null ? item.getLocations() : Collections.emptyList();
|
||||
}, onItemUnavailable(player), new Stack<>(), ItemEquality.NBT);
|
||||
if (lowestAvailable > 0) {
|
||||
// if we're limiting the amount, pretend we only have that amount available
|
||||
if (maxAmount < lowestAvailable)
|
||||
lowestAvailable = maxAmount;
|
||||
for (int i = 0; i < this.craftItems.getSlots(); i++) {
|
||||
ItemStack requested = this.getRequestedCraftItem(i);
|
||||
for (var i = 0; i < this.craftItems.getSlots(); i++) {
|
||||
var requested = this.getRequestedCraftItem(i);
|
||||
if (requested.isEmpty())
|
||||
continue;
|
||||
requested = requested.copy();
|
||||
requested.setCount(lowestAvailable);
|
||||
this.requestItemImpl(requested, onItemUnavailable(player));
|
||||
}
|
||||
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
||||
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending_ingredients", lowestAvailable).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
|
||||
}
|
||||
network.endProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag write(CompoundTag compound) {
|
||||
public CompoundTag save(CompoundTag compound) {
|
||||
compound.put("craft_items", this.craftItems.serializeNBT());
|
||||
return super.write(compound);
|
||||
return super.save(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(BlockState state, CompoundTag compound) {
|
||||
public void load(CompoundTag compound) {
|
||||
this.craftItems.deserializeNBT(compound.getCompound("craft_items"));
|
||||
super.read(state, compound);
|
||||
super.load(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("container." + PrettyPipes.ID + ".crafting_terminal");
|
||||
public Component getDisplayName() {
|
||||
return new TranslatableComponent("container." + PrettyPipes.ID + ".crafting_terminal");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) {
|
||||
return new CraftingTerminalContainer(Registry.craftingTerminalContainer, window, player, this.pos);
|
||||
public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
|
||||
return new CraftingTerminalContainer(Registry.craftingTerminalContainer, window, player, this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack remain, boolean simulate) {
|
||||
BlockPos pos = pipePos.offset(direction);
|
||||
CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, this.world, pos);
|
||||
var pos = pipePos.relative(direction);
|
||||
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, this.level, pos);
|
||||
if (tile != null) {
|
||||
remain = remain.copy();
|
||||
int lowestSlot = -1;
|
||||
var lowestSlot = -1;
|
||||
do {
|
||||
for (int i = 0; i < tile.craftItems.getSlots(); i++) {
|
||||
ItemStack stack = tile.getRequestedCraftItem(i);
|
||||
int count = tile.isGhostItem(i) ? 0 : stack.getCount();
|
||||
for (var i = 0; i < tile.craftItems.getSlots(); i++) {
|
||||
var stack = tile.getRequestedCraftItem(i);
|
||||
var count = tile.isGhostItem(i) ? 0 : stack.getCount();
|
||||
if (!ItemHandlerHelper.canItemStacksStack(stack, remain))
|
||||
continue;
|
||||
// ensure that a single non-stackable item can still enter a ghost slot
|
||||
|
@ -178,7 +177,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
|||
lowestSlot = i;
|
||||
}
|
||||
if (lowestSlot >= 0) {
|
||||
ItemStack copy = remain.copy();
|
||||
var copy = remain.copy();
|
||||
copy.setCount(1);
|
||||
// if there were remaining items inserting into the slot with lowest contents, we're overflowing
|
||||
if (tile.craftItems.insertItem(lowestSlot, copy, simulate).getCount() > 0)
|
||||
|
@ -194,33 +193,33 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
|||
return remain;
|
||||
}
|
||||
|
||||
public static int getAvailableCrafts(PipeTileEntity 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());
|
||||
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) {
|
||||
var network = PipeNetwork.get(tile.getLevel());
|
||||
// the highest amount we can craft with the items we have
|
||||
int lowestAvailable = Integer.MAX_VALUE;
|
||||
var lowestAvailable = Integer.MAX_VALUE;
|
||||
// this is the amount of items required for each ingredient when crafting ONE
|
||||
Map<EquatableItemStack, MutableInt> requiredItems = new HashMap<>();
|
||||
for (int i = 0; i < slots; i++) {
|
||||
ItemStack requested = inputFunction.apply(i);
|
||||
for (var i = 0; i < slots; i++) {
|
||||
var requested = inputFunction.apply(i);
|
||||
if (requested.isEmpty())
|
||||
continue;
|
||||
MutableInt amount = requiredItems.computeIfAbsent(new EquatableItemStack(requested, equalityTypes), s -> new MutableInt());
|
||||
var amount = requiredItems.computeIfAbsent(new EquatableItemStack(requested, equalityTypes), s -> new MutableInt());
|
||||
amount.add(requested.getCount());
|
||||
// if no items fit into the crafting input, we still want to pretend they do for requesting
|
||||
int fit = Math.max(requested.getMaxStackSize() - (isGhost.test(i) ? 0 : requested.getCount()), 1);
|
||||
var fit = Math.max(requested.getMaxStackSize() - (isGhost.test(i) ? 0 : requested.getCount()), 1);
|
||||
if (lowestAvailable > fit)
|
||||
lowestAvailable = fit;
|
||||
}
|
||||
for (Map.Entry<EquatableItemStack, MutableInt> entry : requiredItems.entrySet()) {
|
||||
EquatableItemStack stack = entry.getKey();
|
||||
for (var entry : requiredItems.entrySet()) {
|
||||
var stack = entry.getKey();
|
||||
|
||||
// total amount of available items of this type
|
||||
int available = 0;
|
||||
for (NetworkLocation location : locationsFunction.apply(stack)) {
|
||||
int amount = location.getItemAmount(tile.getWorld(), stack.stack, equalityTypes);
|
||||
var available = 0;
|
||||
for (var location : locationsFunction.apply(stack)) {
|
||||
var amount = location.getItemAmount(tile.getLevel(), stack.stack(), equalityTypes);
|
||||
if (amount <= 0)
|
||||
continue;
|
||||
amount -= network.getLockedAmount(location.getPos(), stack.stack, null, equalityTypes);
|
||||
amount -= network.getLockedAmount(location.getPos(), stack.stack(), null, equalityTypes);
|
||||
available += amount;
|
||||
}
|
||||
// divide the total by the amount required to get the amount that
|
||||
|
@ -229,17 +228,17 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
|
|||
|
||||
// check how many craftable items we have and add those on if we need to
|
||||
if (available < lowestAvailable) {
|
||||
int craftable = network.getCraftableAmount(tile.getPos(), unavailableConsumer, stack.stack, dependencyChain, equalityTypes);
|
||||
var craftable = network.getCraftableAmount(tile.getBlockPos(), unavailableConsumer, stack.stack(), dependencyChain, equalityTypes);
|
||||
if (craftable > 0)
|
||||
available += craftable / entry.getValue().intValue();
|
||||
}
|
||||
|
||||
// clamp to lowest available
|
||||
// clamp to the lowest available
|
||||
if (available < lowestAvailable)
|
||||
lowestAvailable = available;
|
||||
|
||||
if (available <= 0 && unavailableConsumer != null)
|
||||
unavailableConsumer.accept(stack.stack);
|
||||
unavailableConsumer.accept(stack.stack());
|
||||
}
|
||||
return lowestAvailable;
|
||||
}
|
|
@ -1,79 +1,88 @@
|
|||
package de.ellpeck.prettypipes.terminal;
|
||||
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ContainerBlock;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemTerminalBlock extends ContainerBlock {
|
||||
public class ItemTerminalBlock extends BaseEntityBlock {
|
||||
|
||||
public ItemTerminalBlock() {
|
||||
super(Properties.create(Material.ROCK).hardnessAndResistance(3).sound(SoundType.STONE));
|
||||
super(Properties.of(Material.STONE).strength(3).sound(SoundType.STONE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) {
|
||||
ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, worldIn, pos);
|
||||
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
|
||||
if (tile == null)
|
||||
return ActionResultType.PASS;
|
||||
String reason = tile.getInvalidTerminalReason();
|
||||
return InteractionResult.PASS;
|
||||
var reason = tile.getInvalidTerminalReason();
|
||||
if (reason != null) {
|
||||
if (!worldIn.isRemote)
|
||||
player.sendMessage(new TranslationTextComponent(reason).mergeStyle(TextFormatting.RED), UUID.randomUUID());
|
||||
return ActionResultType.SUCCESS;
|
||||
if (!worldIn.isClientSide)
|
||||
player.sendMessage(new TranslatableComponent(reason).withStyle(ChatFormatting.RED), UUID.randomUUID());
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
if (!worldIn.isRemote) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
|
||||
if (!worldIn.isClientSide) {
|
||||
NetworkHooks.openGui((ServerPlayer) player, tile, pos);
|
||||
tile.updateItems(player);
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.getBlock() != newState.getBlock()) {
|
||||
ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, worldIn, pos);
|
||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
|
||||
if (tile != null)
|
||||
Utility.dropInventory(tile, tile.items);
|
||||
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||
super.onRemove(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
||||
return new ItemTerminalTileEntity();
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new ItemTerminalBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.MODEL;
|
||||
public RenderShape getRenderShape(BlockState state) {
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
Utility.addTooltip(this.getRegistryName().getPath(), tooltip);
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
||||
return createTickerHelper(type, Registry.itemTerminalBlockEntity, ItemTerminalBlockEntity::tick);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,27 +13,26 @@ import de.ellpeck.prettypipes.packets.PacketHandler;
|
|||
import de.ellpeck.prettypipes.packets.PacketNetworkItems;
|
||||
import de.ellpeck.prettypipes.pipe.ConnectionType;
|
||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.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.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
@ -45,7 +44,7 @@ import java.util.*;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemTerminalTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable {
|
||||
public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnectable, MenuProvider {
|
||||
|
||||
public final ItemStackHandler items = new ItemStackHandler(12) {
|
||||
@Override
|
||||
|
@ -57,65 +56,64 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
private final Queue<NetworkLock> existingRequests = new LinkedList<>();
|
||||
private final LazyOptional<IPipeConnectable> lazyThis = LazyOptional.of(() -> this);
|
||||
|
||||
protected ItemTerminalTileEntity(TileEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
public ItemTerminalBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
public ItemTerminalTileEntity() {
|
||||
this(Registry.itemTerminalTileEntity);
|
||||
public ItemTerminalBlockEntity(BlockPos pos, BlockState state) {
|
||||
this(Registry.itemTerminalBlockEntity, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (this.world.isRemote)
|
||||
public static void tick(Level level, BlockPos pos, BlockState state, ItemTerminalBlockEntity terminal) {
|
||||
if (terminal.level.isClientSide)
|
||||
return;
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
var network = PipeNetwork.get(terminal.level);
|
||||
var pipe = terminal.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return;
|
||||
|
||||
boolean update = false;
|
||||
int interval = pipe.pressurizer != null ? 2 : 10;
|
||||
if (this.world.getGameTime() % interval == 0) {
|
||||
for (int i = 6; i < 12; i++) {
|
||||
ItemStack extracted = this.items.extractItem(i, Integer.MAX_VALUE, true);
|
||||
var update = false;
|
||||
var interval = pipe.pressurizer != null ? 2 : 10;
|
||||
if (terminal.level.getGameTime() % interval == 0) {
|
||||
for (var i = 6; i < 12; i++) {
|
||||
var extracted = terminal.items.extractItem(i, Integer.MAX_VALUE, true);
|
||||
if (extracted.isEmpty())
|
||||
continue;
|
||||
ItemStack remain = network.routeItem(pipe.getPos(), this.pos, extracted, true);
|
||||
var remain = network.routeItem(pipe.getBlockPos(), terminal.getBlockPos(), extracted, true);
|
||||
if (remain.getCount() == extracted.getCount())
|
||||
continue;
|
||||
this.items.extractItem(i, extracted.getCount() - remain.getCount(), false);
|
||||
terminal.items.extractItem(i, extracted.getCount() - remain.getCount(), false);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this.existingRequests.isEmpty()) {
|
||||
NetworkLock request = this.existingRequests.remove();
|
||||
if (!terminal.existingRequests.isEmpty()) {
|
||||
var request = terminal.existingRequests.remove();
|
||||
network.resolveNetworkLock(request);
|
||||
network.requestExistingItem(request.location, pipe.getPos(), this.pos, request, request.stack, ItemEquality.NBT);
|
||||
network.requestExistingItem(request.location, pipe.getBlockPos(), terminal.getBlockPos(), request, request.stack, ItemEquality.NBT);
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.world.getGameTime() % 100 == 0 || update) {
|
||||
PlayerEntity[] lookingPlayers = this.getLookingPlayers();
|
||||
if (terminal.level.getGameTime() % 100 == 0 || update) {
|
||||
var lookingPlayers = terminal.getLookingPlayers();
|
||||
if (lookingPlayers.length > 0)
|
||||
this.updateItems(lookingPlayers);
|
||||
terminal.updateItems(lookingPlayers);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
for (NetworkLock lock : this.existingRequests)
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
var network = PipeNetwork.get(this.level);
|
||||
for (var lock : this.existingRequests)
|
||||
network.resolveNetworkLock(lock);
|
||||
this.lazyThis.invalidate();
|
||||
}
|
||||
|
||||
public String getInvalidTerminalReason() {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
long pipes = Arrays.stream(Direction.values())
|
||||
.map(d -> network.getPipe(this.pos.offset(d)))
|
||||
var network = PipeNetwork.get(this.level);
|
||||
var pipes = Arrays.stream(Direction.values())
|
||||
.map(d -> network.getPipe(this.worldPosition.relative(d)))
|
||||
.filter(Objects::nonNull).count();
|
||||
if (pipes <= 0)
|
||||
return "info." + PrettyPipes.ID + ".no_pipe_connected";
|
||||
|
@ -124,43 +122,42 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
return null;
|
||||
}
|
||||
|
||||
public PipeTileEntity getConnectedPipe() {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
for (Direction dir : Direction.values()) {
|
||||
PipeTileEntity pipe = network.getPipe(this.pos.offset(dir));
|
||||
public PipeBlockEntity getConnectedPipe() {
|
||||
var network = PipeNetwork.get(this.level);
|
||||
for (var dir : Direction.values()) {
|
||||
var pipe = network.getPipe(this.worldPosition.relative(dir));
|
||||
if (pipe != null)
|
||||
return pipe;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateItems(PlayerEntity... playersToSync) {
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
public void updateItems(Player... playersToSync) {
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return;
|
||||
this.networkItems = this.collectItems(ItemEquality.NBT);
|
||||
if (playersToSync.length > 0) {
|
||||
List<ItemStack> clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
||||
List<ItemStack> clientCraftables = PipeNetwork.get(this.world).getAllCraftables(pipe.getPos()).stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
List<ItemStack> currentlyCrafting = this.getCurrentlyCrafting().stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
||||
for (PlayerEntity player : playersToSync) {
|
||||
if (!(player.openContainer instanceof ItemTerminalContainer))
|
||||
var clientItems = this.networkItems.values().stream().map(NetworkItem::asStack).collect(Collectors.toList());
|
||||
var clientCraftables = PipeNetwork.get(this.level).getAllCraftables(pipe.getBlockPos()).stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
var currentlyCrafting = this.getCurrentlyCrafting().stream().sorted(Comparator.comparingInt(ItemStack::getCount).reversed()).collect(Collectors.toList());
|
||||
for (var player : playersToSync) {
|
||||
if (!(player.containerMenu instanceof ItemTerminalContainer container))
|
||||
continue;
|
||||
ItemTerminalTileEntity tile = ((ItemTerminalContainer) player.openContainer).tile;
|
||||
if (tile != this)
|
||||
if (container.tile != this)
|
||||
continue;
|
||||
PacketHandler.sendTo(player, new PacketNetworkItems(clientItems, clientCraftables, currentlyCrafting));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void requestItem(PlayerEntity player, ItemStack stack) {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
public void requestItem(Player player, ItemStack stack) {
|
||||
var network = PipeNetwork.get(this.level);
|
||||
network.startProfile("terminal_request_item");
|
||||
this.updateItems();
|
||||
int requested = this.requestItemImpl(stack, onItemUnavailable(player));
|
||||
var requested = this.requestItemImpl(stack, onItemUnavailable(player));
|
||||
if (requested > 0) {
|
||||
player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.GREEN)), UUID.randomUUID());
|
||||
player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".sending", requested, stack.getDisplayName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GREEN)), UUID.randomUUID());
|
||||
} else {
|
||||
onItemUnavailable(player).accept(stack);
|
||||
}
|
||||
|
@ -168,32 +165,29 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
}
|
||||
|
||||
public int requestItemImpl(ItemStack stack, Consumer<ItemStack> unavailableConsumer) {
|
||||
NetworkItem item = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT));
|
||||
var item = this.networkItems.get(new EquatableItemStack(stack, ItemEquality.NBT));
|
||||
Collection<NetworkLocation> locations = item == null ? Collections.emptyList() : item.getLocations();
|
||||
Pair<List<NetworkLock>, ItemStack> ret = requestItemLater(this.world, this.getConnectedPipe().getPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT);
|
||||
var ret = requestItemLater(this.level, this.getConnectedPipe().getBlockPos(), locations, unavailableConsumer, stack, new Stack<>(), ItemEquality.NBT);
|
||||
this.existingRequests.addAll(ret.getLeft());
|
||||
return stack.getCount() - ret.getRight().getCount();
|
||||
}
|
||||
|
||||
protected PlayerEntity[] getLookingPlayers() {
|
||||
return this.world.getPlayers().stream()
|
||||
.filter(p -> p.openContainer instanceof ItemTerminalContainer)
|
||||
.filter(p -> ((ItemTerminalContainer) p.openContainer).tile == this)
|
||||
.toArray(PlayerEntity[]::new);
|
||||
protected Player[] getLookingPlayers() {
|
||||
return this.level.players().stream().filter(p -> p.containerMenu instanceof ItemTerminalContainer container && container.tile == this).toArray(Player[]::new);
|
||||
}
|
||||
|
||||
private Map<EquatableItemStack, NetworkItem> collectItems(ItemEquality... equalityTypes) {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
var network = PipeNetwork.get(this.level);
|
||||
network.startProfile("terminal_collect_items");
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
var pipe = this.getConnectedPipe();
|
||||
Map<EquatableItemStack, NetworkItem> items = new HashMap<>();
|
||||
for (NetworkLocation location : network.getOrderedNetworkItems(pipe.getPos())) {
|
||||
for (Map.Entry<Integer, ItemStack> entry : location.getItems(this.world).entrySet()) {
|
||||
for (var location : network.getOrderedNetworkItems(pipe.getBlockPos())) {
|
||||
for (var entry : location.getItems(this.level).entrySet()) {
|
||||
// make sure we can extract from this slot to display it
|
||||
if (!location.canExtract(this.world, entry.getKey()))
|
||||
if (!location.canExtract(this.level, entry.getKey()))
|
||||
continue;
|
||||
EquatableItemStack equatable = new EquatableItemStack(entry.getValue(), equalityTypes);
|
||||
NetworkItem item = items.computeIfAbsent(equatable, NetworkItem::new);
|
||||
var equatable = new EquatableItemStack(entry.getValue(), equalityTypes);
|
||||
var item = items.computeIfAbsent(equatable, NetworkItem::new);
|
||||
item.add(location, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -202,57 +196,57 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
}
|
||||
|
||||
private List<ItemStack> getCurrentlyCrafting() {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
var network = PipeNetwork.get(this.level);
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return Collections.emptyList();
|
||||
List<Pair<BlockPos, ItemStack>> crafting = network.getCurrentlyCrafting(pipe.getPos());
|
||||
var crafting = network.getCurrentlyCrafting(pipe.getBlockPos());
|
||||
return crafting.stream().map(Pair::getRight).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void cancelCrafting() {
|
||||
PipeNetwork network = PipeNetwork.get(this.world);
|
||||
PipeTileEntity pipe = this.getConnectedPipe();
|
||||
var network = PipeNetwork.get(this.level);
|
||||
var pipe = this.getConnectedPipe();
|
||||
if (pipe == null)
|
||||
return;
|
||||
for (Pair<BlockPos, ItemStack> craftable : network.getAllCraftables(pipe.getPos())) {
|
||||
PipeTileEntity otherPipe = network.getPipe(craftable.getLeft());
|
||||
for (var craftable : network.getAllCraftables(pipe.getBlockPos())) {
|
||||
var otherPipe = network.getPipe(craftable.getLeft());
|
||||
if (otherPipe != null) {
|
||||
for (NetworkLock lock : otherPipe.craftIngredientRequests)
|
||||
for (var lock : otherPipe.craftIngredientRequests)
|
||||
network.resolveNetworkLock(lock);
|
||||
otherPipe.craftIngredientRequests.clear();
|
||||
otherPipe.craftResultRequests.clear();
|
||||
}
|
||||
}
|
||||
PlayerEntity[] lookingPlayers = this.getLookingPlayers();
|
||||
var lookingPlayers = this.getLookingPlayers();
|
||||
if (lookingPlayers.length > 0)
|
||||
this.updateItems(lookingPlayers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag write(CompoundTag compound) {
|
||||
public CompoundTag save(CompoundTag compound) {
|
||||
compound.put("items", this.items.serializeNBT());
|
||||
compound.put("requests", Utility.serializeAll(this.existingRequests));
|
||||
return super.write(compound);
|
||||
return super.save(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(BlockState state, CompoundTag compound) {
|
||||
public void load(CompoundTag compound) {
|
||||
this.items.deserializeNBT(compound.getCompound("items"));
|
||||
this.existingRequests.clear();
|
||||
this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", NBT.TAG_COMPOUND), NetworkLock::new));
|
||||
super.read(state, compound);
|
||||
this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), NetworkLock::new));
|
||||
super.load(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("container." + PrettyPipes.ID + ".item_terminal");
|
||||
public Component getDisplayName() {
|
||||
return new TranslatableComponent("container." + PrettyPipes.ID + ".item_terminal");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) {
|
||||
return new ItemTerminalContainer(Registry.itemTerminalContainer, window, player, this.pos);
|
||||
public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
|
||||
return new ItemTerminalContainer(Registry.itemTerminalContainer, window, player, this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -269,8 +263,8 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
|
||||
@Override
|
||||
public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack stack, boolean simulate) {
|
||||
BlockPos pos = pipePos.offset(direction);
|
||||
ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, world, pos);
|
||||
var pos = pipePos.relative(direction);
|
||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, this.level, pos);
|
||||
if (tile != null)
|
||||
return ItemHandlerHelper.insertItemStacked(tile.items, stack, simulate);
|
||||
return stack;
|
||||
|
@ -281,13 +275,13 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
return true;
|
||||
}
|
||||
|
||||
public static Pair<List<NetworkLock>, ItemStack> requestItemLater(World world, BlockPos destPipe, Collection<NetworkLocation> locations, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain, ItemEquality... equalityTypes) {
|
||||
public static Pair<List<NetworkLock>, ItemStack> requestItemLater(Level world, BlockPos destPipe, Collection<NetworkLocation> locations, Consumer<ItemStack> unavailableConsumer, ItemStack stack, Stack<ItemStack> dependencyChain, ItemEquality... equalityTypes) {
|
||||
List<NetworkLock> requests = new ArrayList<>();
|
||||
ItemStack remain = stack.copy();
|
||||
PipeNetwork network = PipeNetwork.get(world);
|
||||
var remain = stack.copy();
|
||||
var network = PipeNetwork.get(world);
|
||||
// check for existing items
|
||||
for (NetworkLocation location : locations) {
|
||||
int amount = location.getItemAmount(world, stack, equalityTypes);
|
||||
for (var location : locations) {
|
||||
var amount = location.getItemAmount(world, stack, equalityTypes);
|
||||
if (amount <= 0)
|
||||
continue;
|
||||
amount -= network.getLockedAmount(location.getPos(), stack, null, equalityTypes);
|
||||
|
@ -296,9 +290,9 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
amount = remain.getCount();
|
||||
remain.shrink(amount);
|
||||
while (amount > 0) {
|
||||
ItemStack copy = stack.copy();
|
||||
var copy = stack.copy();
|
||||
copy.setCount(Math.min(stack.getMaxStackSize(), amount));
|
||||
NetworkLock lock = new NetworkLock(location, copy);
|
||||
var lock = new NetworkLock(location, copy);
|
||||
network.createNetworkLock(lock);
|
||||
requests.add(lock);
|
||||
amount -= copy.getCount();
|
||||
|
@ -313,7 +307,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
|
|||
return Pair.of(requests, remain);
|
||||
}
|
||||
|
||||
public static Consumer<ItemStack> onItemUnavailable(PlayerEntity player) {
|
||||
return s -> player.sendMessage(new TranslationTextComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.setFormatting(TextFormatting.RED)), UUID.randomUUID());
|
||||
public static Consumer<ItemStack> onItemUnavailable(Player player) {
|
||||
return s -> player.sendMessage(new TranslatableComponent("info." + PrettyPipes.ID + ".not_found", s.getDisplayName()).setStyle(Style.EMPTY.applyFormat(ChatFormatting.RED)), UUID.randomUUID());
|
||||
}
|
||||
}
|
|
@ -1,64 +1,57 @@
|
|||
package de.ellpeck.prettypipes.terminal.containers;
|
||||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.CraftResultInventory;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.CraftingResultSlot;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.*;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.network.play.server.SSetSlotPacket;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CraftingTerminalContainer extends ItemTerminalContainer {
|
||||
|
||||
public CraftingInventory craftInventory;
|
||||
public CraftResultInventory craftResult;
|
||||
private final PlayerEntity player;
|
||||
public CraftingContainer craftInventory;
|
||||
public ResultContainer craftResult;
|
||||
private final Player player;
|
||||
|
||||
public CraftingTerminalContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos) {
|
||||
public CraftingTerminalContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos) {
|
||||
super(type, id, player, pos);
|
||||
this.player = player;
|
||||
this.onCraftMatrixChanged(this.craftInventory);
|
||||
this.slotsChanged(this.craftInventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addOwnSlots(PlayerEntity player) {
|
||||
protected void addDataSlots(ContainerData data) {
|
||||
this.craftInventory = new WrappedCraftingInventory(this.getTile().craftItems, this, 3, 3);
|
||||
this.craftResult = new CraftResultInventory();
|
||||
this.addSlot(new CraftingResultSlot(player, this.craftInventory, this.craftResult, 0, 25, 77));
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
this.craftResult = new ResultContainer();
|
||||
this.addSlot(new ResultSlot(this.player, this.craftInventory, this.craftResult, 0, 25, 77));
|
||||
for (var i = 0; i < 3; i++)
|
||||
for (var j = 0; j < 3; j++)
|
||||
this.addSlot(new Slot(this.craftInventory, j + i * 3, 7 + j * 18, 18 + i * 18));
|
||||
super.addOwnSlots(player);
|
||||
super.addDataSlots(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftMatrixChanged(IInventory inventoryIn) {
|
||||
if (!this.player.world.isRemote) {
|
||||
ItemStack ret = ItemStack.EMPTY;
|
||||
Optional<ICraftingRecipe> optional = this.player.world.getServer().getRecipeManager().getRecipe(IRecipeType.CRAFTING, this.craftInventory, this.player.world);
|
||||
public void slotsChanged(Container inventoryIn) {
|
||||
if (!this.player.level.isClientSide) {
|
||||
var ret = ItemStack.EMPTY;
|
||||
var optional = this.player.level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory, this.player.level);
|
||||
if (optional.isPresent())
|
||||
ret = optional.get().getCraftingResult(this.craftInventory);
|
||||
this.craftResult.setInventorySlotContents(0, ret);
|
||||
((ServerPlayerEntity) this.player).connection.sendPacket(new SSetSlotPacket(this.windowId, 0, ret));
|
||||
ret = optional.get().assemble(this.craftInventory);
|
||||
this.craftResult.setItem(0, ret);
|
||||
((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, 0, ret));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::mergeItemStack, player, slotIndex, stack -> Pair.of(6 + 10, 12 + 10));
|
||||
public ItemStack quickMoveStack(Player player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::moveItemStackTo, player, slotIndex, stack -> Pair.of(6 + 10, 12 + 10));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,16 +60,16 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) {
|
||||
public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) {
|
||||
if (slotId > 0 && clickTypeIn == ClickType.PICKUP) {
|
||||
Slot slot = this.inventorySlots.get(slotId);
|
||||
if (slot.inventory == this.craftInventory && !slot.getHasStack())
|
||||
var slot = this.slots.get(slotId);
|
||||
if (slot.container == this.craftInventory && !slot.hasItem())
|
||||
this.getTile().ghostItems.setStackInSlot(slot.getSlotIndex(), ItemStack.EMPTY);
|
||||
}
|
||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
super.clicked(slotId, dragType, clickTypeIn, player);
|
||||
}
|
||||
|
||||
public CraftingTerminalTileEntity getTile() {
|
||||
return (CraftingTerminalTileEntity) this.tile;
|
||||
public CraftingTerminalBlockEntity getTile() {
|
||||
return (CraftingTerminalBlockEntity) this.tile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +1,42 @@
|
|||
package de.ellpeck.prettypipes.terminal.containers;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.packets.PacketRequest;
|
||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class CraftingTerminalGui extends ItemTerminalGui {
|
||||
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png");
|
||||
private Button requestButton;
|
||||
|
||||
public CraftingTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
public CraftingTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
this.xSize = 256;
|
||||
this.imageWidth = 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
this.requestButton = this.addButton(new Button(this.guiLeft + 8, this.guiTop + 100, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||
int amount = requestModifier();
|
||||
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
|
||||
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + 8, this.topPos + 100, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||
var amount = requestModifier();
|
||||
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount));
|
||||
}));
|
||||
this.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
CraftingTerminalTileEntity tile = this.getCraftingContainer().getTile();
|
||||
public void containerTick() {
|
||||
super.containerTick();
|
||||
var tile = this.getCraftingContainer().getTile();
|
||||
this.requestButton.active = false;
|
||||
for (int i = 0; i < tile.craftItems.getSlots(); i++) {
|
||||
ItemStack stack = tile.getRequestedCraftItem(i);
|
||||
for (var i = 0; i < tile.craftItems.getSlots(); i++) {
|
||||
var stack = tile.getRequestedCraftItem(i);
|
||||
if (!stack.isEmpty() && stack.getCount() < stack.getMaxStackSize()) {
|
||||
this.requestButton.active = true;
|
||||
break;
|
||||
|
@ -52,23 +45,23 @@ public class CraftingTerminalGui extends ItemTerminalGui {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(matrix, mouseX, mouseY);
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
super.renderLabels(matrix, mouseX, mouseY);
|
||||
|
||||
CraftingTerminalContainer container = this.getCraftingContainer();
|
||||
CraftingTerminalTileEntity tile = container.getTile();
|
||||
for (int i = 0; i < tile.ghostItems.getSlots(); i++) {
|
||||
var container = this.getCraftingContainer();
|
||||
var tile = container.getTile();
|
||||
for (var i = 0; i < tile.ghostItems.getSlots(); i++) {
|
||||
if (!tile.craftItems.getStackInSlot(i).isEmpty())
|
||||
continue;
|
||||
ItemStack ghost = tile.ghostItems.getStackInSlot(i);
|
||||
var ghost = tile.ghostItems.getStackInSlot(i);
|
||||
if (ghost.isEmpty())
|
||||
continue;
|
||||
int finalI = i;
|
||||
Slot slot = container.inventorySlots.stream().filter(s -> s.inventory == container.craftInventory && s.getSlotIndex() == finalI).findFirst().orElse(null);
|
||||
var finalI = i;
|
||||
var slot = container.slots.stream().filter(s -> s.container == container.craftInventory && s.getSlotIndex() == finalI).findFirst().orElse(null);
|
||||
if (slot == null)
|
||||
continue;
|
||||
this.minecraft.getItemRenderer().renderItemIntoGUI(ghost, slot.xPos, slot.yPos);
|
||||
this.minecraft.getItemRenderer().renderItemOverlayIntoGUI(this.font, ghost, slot.xPos, slot.yPos, "0");
|
||||
this.minecraft.getItemRenderer().renderGuiItem(ghost, slot.x, slot.y);
|
||||
this.minecraft.getItemRenderer().renderGuiItemDecorations(this.font, ghost, slot.x, slot.y, "0");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,6 +76,6 @@ public class CraftingTerminalGui extends ItemTerminalGui {
|
|||
}
|
||||
|
||||
protected CraftingTerminalContainer getCraftingContainer() {
|
||||
return (CraftingTerminalContainer) this.container;
|
||||
return (CraftingTerminalContainer) this.menu;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,44 +1,41 @@
|
|||
package de.ellpeck.prettypipes.terminal.containers;
|
||||
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemTerminalContainer extends Container {
|
||||
public class ItemTerminalContainer extends AbstractContainerMenu {
|
||||
|
||||
public final ItemTerminalTileEntity tile;
|
||||
public final ItemTerminalBlockEntity tile;
|
||||
|
||||
public ItemTerminalContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos) {
|
||||
public ItemTerminalContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos) {
|
||||
super(type, id);
|
||||
this.tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, pos);
|
||||
this.tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, pos);
|
||||
|
||||
this.addOwnSlots(player);
|
||||
|
||||
int off = this.getSlotXOffset();
|
||||
for (int l = 0; l < 3; ++l)
|
||||
for (int j1 = 0; j1 < 9; ++j1)
|
||||
this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + off + j1 * 18, 154 + l * 18));
|
||||
for (int i1 = 0; i1 < 9; ++i1)
|
||||
this.addSlot(new Slot(player.inventory, i1, 8 + off + i1 * 18, 212));
|
||||
var off = this.getSlotXOffset();
|
||||
for (var l = 0; l < 3; ++l)
|
||||
for (var j1 = 0; j1 < 9; ++j1)
|
||||
this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + off + j1 * 18, 154 + l * 18));
|
||||
for (var i1 = 0; i1 < 9; ++i1)
|
||||
this.addSlot(new Slot(player.getInventory(), i1, 8 + off + i1 * 18, 212));
|
||||
}
|
||||
|
||||
protected void addOwnSlots(PlayerEntity player) {
|
||||
int off = this.getSlotXOffset();
|
||||
for (int i = 0; i < 6; i++)
|
||||
protected void addOwnSlots(Player player) {
|
||||
var off = this.getSlotXOffset();
|
||||
for (var i = 0; i < 6; i++)
|
||||
this.addSlot(new SlotItemHandler(this.tile.items, i, 8 + off + i % 3 * 18, 102 + i / 3 * 18));
|
||||
for (int i = 0; i < 6; i++)
|
||||
for (var i = 0; i < 6; i++)
|
||||
this.addSlot(new SlotItemHandler(this.tile.items, i + 6, 116 + off + i % 3 * 18, 102 + i / 3 * 18));
|
||||
}
|
||||
|
||||
|
@ -47,12 +44,12 @@ public class ItemTerminalContainer extends Container {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::mergeItemStack, player, slotIndex, stack -> Pair.of(6, 12));
|
||||
public ItemStack quickMoveStack(Player player, int slotIndex) {
|
||||
return Utility.transferStackInSlot(this, this::moveItemStackTo, player, slotIndex, stack -> Pair.of(6, 12));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(PlayerEntity playerIn) {
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.ellpeck.prettypipes.terminal.containers;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.misc.ItemTerminalWidget;
|
||||
import de.ellpeck.prettypipes.misc.PlayerPrefs;
|
||||
|
@ -8,31 +9,29 @@ import de.ellpeck.prettypipes.packets.PacketButton;
|
|||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
import de.ellpeck.prettypipes.packets.PacketRequest;
|
||||
import joptsimple.internal.Strings;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
||||
public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContainer> {
|
||||
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/item_terminal.png");
|
||||
|
||||
public List<ItemStack> currentlyCrafting;
|
||||
public TextFieldWidget search;
|
||||
public EditBox search;
|
||||
|
||||
// craftables have the second parameter set to true
|
||||
private final List<Pair<ItemStack, Boolean>> sortedItems = new ArrayList<>();
|
||||
|
@ -50,24 +49,24 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
private ItemStack hoveredCrafting;
|
||||
private boolean isScrolling;
|
||||
|
||||
public ItemTerminalGui(ItemTerminalContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
|
||||
public ItemTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) {
|
||||
super(screenContainer, inv, titleIn);
|
||||
this.xSize = 176 + 15;
|
||||
this.ySize = 236;
|
||||
this.imageWidth = 176 + 15;
|
||||
this.imageHeight = 236;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
this.search = this.addButton(new TextFieldWidget(this.font, this.guiLeft + this.getXOffset() + 97, this.guiTop + 6, 86, 8, new StringTextComponent("")));
|
||||
this.search.setEnableBackgroundDrawing(false);
|
||||
this.search = this.addRenderableWidget(new EditBox(this.font, this.leftPos + this.getXOffset() + 97, this.topPos + 6, 86, 8, new TextComponent("")));
|
||||
this.search.setBordered(false);
|
||||
this.lastSearchText = "";
|
||||
if (this.items != null)
|
||||
this.updateWidgets();
|
||||
|
||||
this.plusButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 + 12, this.guiTop + 103, 12, 12, new StringTextComponent("+"), button -> {
|
||||
int modifier = requestModifier();
|
||||
this.plusButton = this.addRenderableWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 + 12, this.topPos + 103, 12, 12, new TextComponent("+"), button -> {
|
||||
var modifier = requestModifier();
|
||||
if (modifier > 1 && this.requestAmount == 1) {
|
||||
this.requestAmount = modifier;
|
||||
} else {
|
||||
|
@ -77,44 +76,44 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
if (this.requestAmount > 384)
|
||||
this.requestAmount = 384;
|
||||
}));
|
||||
this.minusButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 - 24, this.guiTop + 103, 12, 12, new StringTextComponent("-"), button -> {
|
||||
this.minusButton = this.addRenderableWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 24, this.topPos + 103, 12, 12, new TextComponent("-"), button -> {
|
||||
this.requestAmount -= requestModifier();
|
||||
if (this.requestAmount < 1)
|
||||
this.requestAmount = 1;
|
||||
}));
|
||||
this.minusButton.active = false;
|
||||
this.requestButton = this.addButton(new Button(this.guiLeft + this.getXOffset() + 95 - 7 - 25, this.guiTop + 115, 50, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||
Optional<ItemTerminalWidget> widget = this.streamWidgets().filter(w -> w.selected).findFirst();
|
||||
this.requestButton = this.addRenderableWidget(new Button(this.leftPos + this.getXOffset() + 95 - 7 - 25, this.topPos + 115, 50, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".request"), button -> {
|
||||
var widget = this.streamWidgets().filter(w -> w.selected).findFirst();
|
||||
if (!widget.isPresent())
|
||||
return;
|
||||
ItemStack stack = widget.get().stack.copy();
|
||||
var stack = widget.get().stack.copy();
|
||||
stack.setCount(1);
|
||||
PacketHandler.sendToServer(new PacketRequest(this.container.tile.getPos(), stack, this.requestAmount));
|
||||
PacketHandler.sendToServer(new PacketRequest(this.menu.tile.getBlockPos(), stack, this.requestAmount));
|
||||
this.requestAmount = 1;
|
||||
}));
|
||||
this.requestButton.active = false;
|
||||
this.orderButton = this.addButton(new Button(this.guiLeft - 22, this.guiTop, 20, 20, new StringTextComponent(""), button -> {
|
||||
this.orderButton = this.addRenderableWidget(new Button(this.leftPos - 22, this.topPos, 20, 20, new TextComponent(""), button -> {
|
||||
if (this.sortedItems == null)
|
||||
return;
|
||||
PlayerPrefs prefs = PlayerPrefs.get();
|
||||
var prefs = PlayerPrefs.get();
|
||||
prefs.terminalItemOrder = prefs.terminalItemOrder.next();
|
||||
prefs.save();
|
||||
this.updateWidgets();
|
||||
}));
|
||||
this.ascendingButton = this.addButton(new Button(this.guiLeft - 22, this.guiTop + 22, 20, 20, new StringTextComponent(""), button -> {
|
||||
this.ascendingButton = this.addRenderableWidget(new Button(this.leftPos - 22, this.topPos + 22, 20, 20, new TextComponent(""), button -> {
|
||||
if (this.sortedItems == null)
|
||||
return;
|
||||
PlayerPrefs prefs = PlayerPrefs.get();
|
||||
var prefs = PlayerPrefs.get();
|
||||
prefs.terminalAscending = !prefs.terminalAscending;
|
||||
prefs.save();
|
||||
this.updateWidgets();
|
||||
}));
|
||||
this.cancelCraftingButton = this.addButton(new Button(this.guiLeft + this.xSize + 4, this.guiTop + 4 + 64, 54, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".cancel_all"), b -> {
|
||||
this.cancelCraftingButton = this.addRenderableWidget(new Button(this.leftPos + this.imageWidth + 4, this.topPos + 4 + 64, 54, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".cancel_all"), b -> {
|
||||
}));
|
||||
this.cancelCraftingButton.visible = false;
|
||||
for (int y = 0; y < 4; y++) {
|
||||
for (int x = 0; x < 9; x++)
|
||||
this.addButton(new ItemTerminalWidget(this.guiLeft + this.getXOffset() + 8 + x * 18, this.guiTop + 18 + y * 18, x, y, this));
|
||||
for (var y = 0; y < 4; y++) {
|
||||
for (var x = 0; x < 9; x++)
|
||||
this.addRenderableWidget(new ItemTerminalWidget(this.leftPos + this.getXOffset() + 8 + x * 18, this.topPos + 18 + y * 18, x, y, this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,15 +122,15 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
public void containerTick() {
|
||||
super.containerTick();
|
||||
this.requestButton.active = this.streamWidgets().anyMatch(w -> w.selected);
|
||||
this.plusButton.active = this.requestAmount < 384;
|
||||
this.minusButton.active = this.requestAmount > 1;
|
||||
|
||||
this.search.tick();
|
||||
if (this.items != null) {
|
||||
String text = this.search.getText();
|
||||
var text = this.search.getValue();
|
||||
if (!this.lastSearchText.equals(text)) {
|
||||
this.lastSearchText = text;
|
||||
this.updateWidgets();
|
||||
|
@ -141,7 +140,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (button == 0 && mouseX >= this.guiLeft + this.getXOffset() + 172 && this.guiTop + mouseY >= 18 && mouseX < this.guiLeft + this.getXOffset() + 172 + 12 && mouseY < this.guiTop + 18 + 70) {
|
||||
if (button == 0 && mouseX >= this.leftPos + this.getXOffset() + 172 && this.topPos + mouseY >= 18 && mouseX < this.leftPos + this.getXOffset() + 172 + 12 && mouseY < this.topPos + 18 + 70) {
|
||||
this.isScrolling = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -152,9 +151,9 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
// we have to do the click logic here because JEI is activated when letting go of the mouse button
|
||||
// and vanilla buttons are activated when the click starts, so we'll always invoke jei accidentally by default
|
||||
if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
|
||||
if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHoveredOrFocused()) {
|
||||
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
||||
PacketHandler.sendToServer(new PacketButton(this.container.tile.getPos(), PacketButton.ButtonResult.CANCEL_CRAFTING));
|
||||
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CANCEL_CRAFTING));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -163,7 +162,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
this.isScrolling = false;
|
||||
else if (button == 1 && mouseX >= this.search.x && mouseX <= this.search.x + this.search.getWidth() && mouseY >= this.search.y && mouseY <= this.search.y + 8) {
|
||||
//clear text from search field when letting go of right mouse button within search field
|
||||
this.search.setText("");
|
||||
this.search.setValue("");
|
||||
return true;
|
||||
}
|
||||
return super.mouseReleased(mouseX, mouseY, button);
|
||||
|
@ -172,8 +171,8 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int i, double j, double k) {
|
||||
if (this.isScrolling) {
|
||||
float percentage = MathHelper.clamp(((float) mouseY - (this.guiTop + 18) - 7.5F) / (70 - 15), 0, 1);
|
||||
int offset = (int) (percentage * (float) (this.sortedItems.size() / 9 - 3));
|
||||
var percentage = Mth.clamp(((float) mouseY - (this.topPos + 18) - 7.5F) / (70 - 15), 0, 1);
|
||||
var offset = (int) (percentage * (float) (this.sortedItems.size() / 9 - 3));
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -187,8 +186,8 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
public boolean keyPressed(int x, int y, int z) {
|
||||
// for some reason we have to do this to make the text field allow the inventory key to be typed
|
||||
if (this.search.isFocused()) {
|
||||
InputMappings.Input mouseKey = InputMappings.getInputByCode(x, y);
|
||||
if (this.minecraft.gameSettings.keyBindInventory.isActiveAndMatches(mouseKey))
|
||||
var mouseKey = InputConstants.getKey(x, y);
|
||||
if (this.minecraft.options.keyInventory.isActiveAndMatches(mouseKey))
|
||||
return false;
|
||||
}
|
||||
return super.keyPressed(x, y, z);
|
||||
|
@ -202,30 +201,30 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
}
|
||||
|
||||
public void updateWidgets() {
|
||||
PlayerPrefs prefs = PlayerPrefs.get();
|
||||
this.ascendingButton.setMessage(new StringTextComponent(prefs.terminalAscending ? "^" : "v"));
|
||||
this.orderButton.setMessage(new StringTextComponent(prefs.terminalItemOrder.name().substring(0, 1)));
|
||||
var prefs = PlayerPrefs.get();
|
||||
this.ascendingButton.setMessage(new TextComponent(prefs.terminalAscending ? "^" : "v"));
|
||||
this.orderButton.setMessage(new TextComponent(prefs.terminalItemOrder.name().substring(0, 1)));
|
||||
this.cancelCraftingButton.visible = this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty();
|
||||
|
||||
Comparator<ItemStack> comparator = prefs.terminalItemOrder.comparator;
|
||||
var comparator = prefs.terminalItemOrder.comparator;
|
||||
if (!prefs.terminalAscending)
|
||||
comparator = comparator.reversed();
|
||||
|
||||
// add all items to the sorted items list
|
||||
this.sortedItems.clear();
|
||||
for (ItemStack stack : this.items)
|
||||
for (var stack : this.items)
|
||||
this.sortedItems.add(Pair.of(stack, false));
|
||||
for (ItemStack stack : this.craftables)
|
||||
for (var stack : this.craftables)
|
||||
this.sortedItems.add(Pair.of(stack, true));
|
||||
|
||||
// compare by craftability first, and then by the player's chosen order
|
||||
Comparator<Pair<ItemStack, Boolean>> fullComparator = Comparator.comparing(Pair::getRight);
|
||||
this.sortedItems.sort(fullComparator.thenComparing(Pair::getLeft, comparator));
|
||||
|
||||
String searchText = this.search.getText();
|
||||
var searchText = this.search.getValue();
|
||||
if (!Strings.isNullOrEmpty(searchText)) {
|
||||
this.sortedItems.removeIf(s -> {
|
||||
String search = searchText;
|
||||
var search = searchText;
|
||||
String toCompare;
|
||||
if (search.startsWith("@")) {
|
||||
toCompare = s.getLeft().getItem().getCreatorModId(s.getLeft());
|
||||
|
@ -241,16 +240,16 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
if (this.sortedItems.size() < 9 * 4)
|
||||
this.scrollOffset = 0;
|
||||
|
||||
List<ItemTerminalWidget> widgets = this.streamWidgets().collect(Collectors.toList());
|
||||
for (int i = 0; i < widgets.size(); i++) {
|
||||
ItemTerminalWidget widget = widgets.get(i);
|
||||
int index = i + this.scrollOffset * 9;
|
||||
var widgets = this.streamWidgets().collect(Collectors.toList());
|
||||
for (var i = 0; i < widgets.size(); i++) {
|
||||
var widget = widgets.get(i);
|
||||
var index = i + this.scrollOffset * 9;
|
||||
if (index >= this.sortedItems.size()) {
|
||||
widget.stack = ItemStack.EMPTY;
|
||||
widget.craftable = false;
|
||||
widget.visible = false;
|
||||
} else {
|
||||
Pair<ItemStack, Boolean> stack = this.sortedItems.get(index);
|
||||
var stack = this.sortedItems.get(index);
|
||||
widget.stack = stack.getLeft();
|
||||
widget.craftable = stack.getRight();
|
||||
widget.visible = true;
|
||||
|
@ -259,69 +258,69 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(matrix);
|
||||
super.render(matrix, mouseX, mouseY, partialTicks);
|
||||
for (Widget widget : this.buttons) {
|
||||
if (widget instanceof ItemTerminalWidget)
|
||||
widget.renderToolTip(matrix, mouseX, mouseY);
|
||||
for (var widget : this.renderables) {
|
||||
if (widget instanceof ItemTerminalWidget terminal)
|
||||
terminal.renderToolTip(matrix, mouseX, mouseY);
|
||||
}
|
||||
if (this.sortedItems != null) {
|
||||
PlayerPrefs prefs = PlayerPrefs.get();
|
||||
if (this.orderButton.isHovered())
|
||||
this.renderTooltip(matrix, new TranslationTextComponent("info." + PrettyPipes.ID + ".order", I18n.format("info." + PrettyPipes.ID + ".order." + prefs.terminalItemOrder.name().toLowerCase(Locale.ROOT))), mouseX, mouseY);
|
||||
if (this.ascendingButton.isHovered())
|
||||
this.renderTooltip(matrix, new TranslationTextComponent("info." + PrettyPipes.ID + "." + (prefs.terminalAscending ? "ascending" : "descending")), mouseX, mouseY);
|
||||
var prefs = PlayerPrefs.get();
|
||||
if (this.orderButton.isHoveredOrFocused())
|
||||
this.renderTooltip(matrix, new TranslatableComponent("info." + PrettyPipes.ID + ".order", I18n.get("info." + PrettyPipes.ID + ".order." + prefs.terminalItemOrder.name().toLowerCase(Locale.ROOT))), mouseX, mouseY);
|
||||
if (this.ascendingButton.isHoveredOrFocused())
|
||||
this.renderTooltip(matrix, new TranslatableComponent("info." + PrettyPipes.ID + "." + (prefs.terminalAscending ? "ascending" : "descending")), mouseX, mouseY);
|
||||
}
|
||||
if (this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
|
||||
String[] tooltip = I18n.format("info." + PrettyPipes.ID + ".cancel_all.desc").split("\n");
|
||||
this.func_243308_b(matrix, Arrays.stream(tooltip).map(StringTextComponent::new).collect(Collectors.toList()), mouseX, mouseY);
|
||||
if (this.cancelCraftingButton.visible && this.cancelCraftingButton.isHoveredOrFocused()) {
|
||||
var tooltip = I18n.get("info." + PrettyPipes.ID + ".cancel_all.desc").split("\n");
|
||||
this.renderComponentTooltip(matrix, Arrays.stream(tooltip).map(TextComponent::new).collect(Collectors.toList()), mouseX, mouseY);
|
||||
}
|
||||
if (!this.hoveredCrafting.isEmpty())
|
||||
this.renderTooltip(matrix, this.hoveredCrafting, mouseX, mouseY);
|
||||
this.func_230459_a_(matrix, mouseX, mouseY);
|
||||
this.renderTooltip(matrix, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrix, int mouseX, int mouseY) {
|
||||
this.font.drawString(matrix, this.playerInventory.getDisplayName().getString(), 8 + this.getXOffset(), this.ySize - 96 + 2, 4210752);
|
||||
this.font.drawString(matrix, this.title.getString(), 8, 6, 4210752);
|
||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||
this.font.draw(matrix, this.playerInventoryTitle.getString(), 8 + this.getXOffset(), this.imageHeight - 96 + 2, 4210752);
|
||||
this.font.draw(matrix, this.title.getString(), 8, 6, 4210752);
|
||||
|
||||
String amount = String.valueOf(this.requestAmount);
|
||||
this.font.drawString(matrix, amount, (176 + 15 - this.font.getStringWidth(amount)) / 2F - 7 + this.getXOffset(), 106, 4210752);
|
||||
var amount = String.valueOf(this.requestAmount);
|
||||
this.font.draw(matrix, amount, (176 + 15 - this.font.width(amount)) / 2F - 7 + this.getXOffset(), 106, 4210752);
|
||||
|
||||
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
||||
this.font.drawString(matrix, I18n.format("info." + PrettyPipes.ID + ".crafting"), this.xSize + 4, 4 + 6, 4210752);
|
||||
this.font.draw(matrix, I18n.get("info." + PrettyPipes.ID + ".crafting"), this.imageWidth + 4, 4 + 6, 4210752);
|
||||
if (this.currentlyCrafting.size() > 6)
|
||||
this.font.drawString(matrix, ". . .", this.xSize + 24, 4 + 51, 4210752);
|
||||
this.font.draw(matrix, ". . .", this.imageWidth + 24, 4 + 51, 4210752);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
this.getMinecraft().getTextureManager().bindTexture(this.getTexture());
|
||||
this.blit(matrix, this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||
protected void renderBg(PoseStack matrix, float partialTicks, int mouseX, int mouseY) {
|
||||
this.getMinecraft().getTextureManager().bindForSetup(this.getTexture());
|
||||
this.blit(matrix, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight);
|
||||
|
||||
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {
|
||||
float percentage = this.scrollOffset / (float) (this.sortedItems.size() / 9 - 3);
|
||||
this.blit(matrix, this.guiLeft + this.getXOffset() + 172, this.guiTop + 18 + (int) (percentage * (70 - 15)), 232, 241, 12, 15);
|
||||
var percentage = this.scrollOffset / (float) (this.sortedItems.size() / 9 - 3);
|
||||
this.blit(matrix, this.leftPos + this.getXOffset() + 172, this.topPos + 18 + (int) (percentage * (70 - 15)), 232, 241, 12, 15);
|
||||
} else {
|
||||
this.blit(matrix, this.guiLeft + this.getXOffset() + 172, this.guiTop + 18, 244, 241, 12, 15);
|
||||
this.blit(matrix, this.leftPos + this.getXOffset() + 172, this.topPos + 18, 244, 241, 12, 15);
|
||||
}
|
||||
|
||||
// draw the items that are currently crafting
|
||||
this.hoveredCrafting = ItemStack.EMPTY;
|
||||
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
|
||||
this.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||
this.blit(matrix, this.guiLeft + this.xSize, this.guiTop + 4, 191, 0, 65, 89);
|
||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||
this.blit(matrix, this.leftPos + this.imageWidth, this.topPos + 4, 191, 0, 65, 89);
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
for (ItemStack stack : this.currentlyCrafting) {
|
||||
int itemX = this.guiLeft + this.xSize + 4 + x * 18;
|
||||
int itemY = this.guiTop + 4 + 16 + y * 18;
|
||||
this.itemRenderer.renderItemAndEffectIntoGUI(stack, itemX, itemY);
|
||||
this.itemRenderer.renderItemOverlayIntoGUI(this.font, stack, itemX, itemY, String.valueOf(stack.getCount()));
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
for (var stack : this.currentlyCrafting) {
|
||||
var itemX = this.leftPos + this.imageWidth + 4 + x * 18;
|
||||
var itemY = this.topPos + 4 + 16 + y * 18;
|
||||
this.itemRenderer.renderGuiItem(stack, itemX, itemY);
|
||||
this.itemRenderer.renderGuiItemDecorations(this.font, stack, itemX, itemY, String.valueOf(stack.getCount()));
|
||||
if (mouseX >= itemX && mouseY >= itemY && mouseX < itemX + 16 && mouseY < itemY + 18)
|
||||
this.hoveredCrafting = stack;
|
||||
x++;
|
||||
|
@ -342,7 +341,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double scroll) {
|
||||
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {
|
||||
int offset = MathHelper.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.sortedItems.size() / 9 - 3);
|
||||
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.sortedItems.size() / 9 - 3);
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -352,7 +351,7 @@ public class ItemTerminalGui extends ContainerScreen<ItemTerminalContainer> {
|
|||
}
|
||||
|
||||
public Stream<ItemTerminalWidget> streamWidgets() {
|
||||
return this.buttons.stream()
|
||||
return this.renderables.stream()
|
||||
.filter(w -> w instanceof ItemTerminalWidget)
|
||||
.map(w -> (ItemTerminalWidget) w);
|
||||
}
|
||||
|
|
|
@ -1,32 +1,30 @@
|
|||
package de.ellpeck.prettypipes.terminal.containers;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.world.entity.player.StackedContents;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.item.crafting.RecipeItemHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class WrappedCraftingInventory extends CraftingInventory {
|
||||
public class WrappedCraftingInventory extends CraftingContainer {
|
||||
|
||||
private final ItemStackHandler items;
|
||||
private final Container eventHandler;
|
||||
private final AbstractContainerMenu eventHandler;
|
||||
|
||||
public WrappedCraftingInventory(ItemStackHandler items, Container eventHandlerIn, int width, int height) {
|
||||
public WrappedCraftingInventory(ItemStackHandler items, AbstractContainerMenu eventHandlerIn, int width, int height) {
|
||||
super(eventHandlerIn, width, height);
|
||||
this.eventHandler = eventHandlerIn;
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
public int getContainerSize() {
|
||||
return this.items.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
for (int i = 0; i < this.items.getSlots(); i++) {
|
||||
for (var i = 0; i < this.items.getSlots(); i++) {
|
||||
if (!this.items.getStackInSlot(i).isEmpty())
|
||||
return false;
|
||||
}
|
||||
|
@ -34,41 +32,41 @@ public class WrappedCraftingInventory extends CraftingInventory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index) {
|
||||
public ItemStack getItem(int index) {
|
||||
return this.items.getStackInSlot(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
ItemStack before = this.items.getStackInSlot(index);
|
||||
public ItemStack removeItemNoUpdate(int index) {
|
||||
var before = this.items.getStackInSlot(index);
|
||||
this.items.setStackInSlot(index, ItemStack.EMPTY);
|
||||
return before;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count) {
|
||||
ItemStack slotStack = this.items.getStackInSlot(index);
|
||||
ItemStack ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
|
||||
public ItemStack removeItem(int index, int count) {
|
||||
var slotStack = this.items.getStackInSlot(index);
|
||||
var ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
|
||||
if (!ret.isEmpty())
|
||||
this.eventHandler.onCraftMatrixChanged(this);
|
||||
this.eventHandler.slotsChanged(this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int index, ItemStack stack) {
|
||||
public void setItem(int index, ItemStack stack) {
|
||||
this.items.setStackInSlot(index, stack);
|
||||
this.eventHandler.onCraftMatrixChanged(this);
|
||||
this.eventHandler.slotsChanged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (int i = 0; i < this.items.getSlots(); i++)
|
||||
public void clearContent() {
|
||||
for (var i = 0; i < this.items.getSlots(); i++)
|
||||
this.items.setStackInSlot(i, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillStackedContents(RecipeItemHelper helper) {
|
||||
for (int i = 0; i < this.items.getSlots(); i++)
|
||||
helper.accountPlainStack(this.items.getStackInSlot(i));
|
||||
public void fillStackedContents(StackedContents helper) {
|
||||
for (var i = 0; i < this.items.getSlots(); i++)
|
||||
helper.accountStack(this.items.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue