mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-26 00:39:22 +01:00
a lot of 1.20.4 work
This commit is contained in:
parent
e6ad1b9bc6
commit
75cd73470f
23 changed files with 169 additions and 186 deletions
|
@ -51,7 +51,9 @@ import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
|
|||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
@ -63,16 +65,13 @@ import net.minecraft.world.item.Item;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
import net.neoforged.neoforge.common.capabilities.CapabilityToken;
|
||||
import net.neoforged.neoforge.capabilities.BlockCapability;
|
||||
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.neoforged.neoforge.registries.ForgeRegistries;
|
||||
import net.neoforged.neoforge.registries.RegisterEvent;
|
||||
import net.neoforged.neoforge.common.capabilities.CapabilityManager;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
|
@ -81,10 +80,10 @@ import java.util.function.BiFunction;
|
|||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class Registry {
|
||||
|
||||
public static Capability<PipeNetwork> pipeNetworkCapability = CapabilityManager.get(new CapabilityToken<>() {
|
||||
});
|
||||
public static Capability<IPipeConnectable> pipeConnectableCapability = CapabilityManager.get(new CapabilityToken<>() {
|
||||
});
|
||||
// TODO use saved data for pipe networks
|
||||
/*public static BlockCapability<PipeNetwork, Void> pipeNetworkCapability = CapabilityManager.get(new CapabilityToken<>() {
|
||||
});*/
|
||||
public static BlockCapability<IPipeConnectable, Direction> pipeConnectableCapability = BlockCapability.createSided(new ResourceLocation(PrettyPipes.ID, "pipe_connectable"), IPipeConnectable.class);
|
||||
|
||||
public static Item wrenchItem;
|
||||
public static Item pipeFrameItem;
|
||||
|
@ -117,14 +116,14 @@ public final class Registry {
|
|||
|
||||
@SubscribeEvent
|
||||
public static void register(RegisterEvent event) {
|
||||
event.register(ForgeRegistries.Keys.BLOCKS, h -> {
|
||||
event.register(Registries.BLOCK, h -> {
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "pipe"), Registry.pipeBlock = new PipeBlock());
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalBlock = new ItemTerminalBlock());
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalBlock = new CraftingTerminalBlock());
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "pressurizer"), Registry.pressurizerBlock = new PressurizerBlock());
|
||||
});
|
||||
|
||||
event.register(ForgeRegistries.Keys.ITEMS, h -> {
|
||||
event.register(Registries.ITEM, h -> {
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "wrench"), Registry.wrenchItem = new WrenchItem());
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "blank_module"), new Item(new Item.Properties()));
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameItem = new PipeFrameItem());
|
||||
|
@ -149,22 +148,22 @@ public final class Registry {
|
|||
h.register(new ResourceLocation(PrettyPipes.ID, name), new SortingModuleItem(name, type));
|
||||
}
|
||||
|
||||
ForgeRegistries.BLOCKS.getEntries().stream()
|
||||
BuiltInRegistries.BLOCK.entrySet().stream()
|
||||
.filter(b -> b.getKey().location().getNamespace().equals(PrettyPipes.ID))
|
||||
.forEach(b -> h.register(b.getKey().location(), new BlockItem(b.getValue(), new Item.Properties())));
|
||||
});
|
||||
|
||||
event.register(ForgeRegistries.Keys.BLOCK_ENTITY_TYPES, h -> {
|
||||
event.register(Registries.BLOCK_ENTITY_TYPE, h -> {
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "pipe"), Registry.pipeBlockEntity = BlockEntityType.Builder.of(PipeBlockEntity::new, Registry.pipeBlock).build(null));
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalBlockEntity = BlockEntityType.Builder.of(ItemTerminalBlockEntity::new, Registry.itemTerminalBlock).build(null));
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalBlockEntity = BlockEntityType.Builder.of(CraftingTerminalBlockEntity::new, Registry.craftingTerminalBlock).build(null));
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "pressurizer"), Registry.pressurizerBlockEntity = BlockEntityType.Builder.of(PressurizerBlockEntity::new, Registry.pressurizerBlock).build(null));
|
||||
});
|
||||
|
||||
event.register(ForgeRegistries.Keys.ENTITY_TYPES, h ->
|
||||
event.register(Registries.ENTITY_TYPE, h ->
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameEntity = EntityType.Builder.<PipeFrameEntity>of(PipeFrameEntity::new, MobCategory.MISC).build("pipe_frame")));
|
||||
|
||||
event.register(ForgeRegistries.Keys.MENU_TYPES, h -> {
|
||||
event.register(Registries.MENU, h -> {
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "pipe"), Registry.pipeContainer = IMenuTypeExtension.create((windowId, inv, data) -> new MainPipeContainer(Registry.pipeContainer, windowId, inv.player, data.readBlockPos())));
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalContainer = IMenuTypeExtension.create((windowId, inv, data) -> new ItemTerminalContainer(Registry.itemTerminalContainer, windowId, inv.player, data.readBlockPos())));
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalContainer = IMenuTypeExtension.create((windowId, inv, data) -> new CraftingTerminalContainer(Registry.craftingTerminalContainer, windowId, inv.player, data.readBlockPos())));
|
||||
|
@ -183,14 +182,14 @@ public final class Registry {
|
|||
h.register(new ResourceLocation(PrettyPipes.ID, "tab"), CreativeModeTab.builder()
|
||||
.title(Component.translatable("item_group." + PrettyPipes.ID + ".tab"))
|
||||
.icon(() -> new ItemStack(Registry.wrenchItem))
|
||||
.displayItems((params, output) -> ForgeRegistries.ITEMS.getEntries().stream()
|
||||
.displayItems((params, output) -> BuiltInRegistries.ITEM.entrySet().stream()
|
||||
.filter(b -> b.getKey().location().getNamespace().equals(PrettyPipes.ID))
|
||||
.sorted(Comparator.comparing(b -> b.getValue().getClass().getSimpleName()))
|
||||
.forEach(b -> output.accept(b.getValue()))).build()
|
||||
);
|
||||
});
|
||||
|
||||
event.register(ForgeRegistries.Keys.RECIPE_SERIALIZERS, h -> {
|
||||
event.register(Registries.RECIPE_SERIALIZER, h -> {
|
||||
h.register(new ResourceLocation(PrettyPipes.ID, "module_clearing"), ModuleClearingRecipe.SERIALIZER);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -16,12 +16,13 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CraftingModuleTransferHandler implements IRecipeTransferHandler<CraftingModuleContainer, CraftingRecipe> {
|
||||
public class CraftingModuleTransferHandler implements IRecipeTransferHandler<CraftingModuleContainer, RecipeHolder<CraftingRecipe>> {
|
||||
|
||||
@Override
|
||||
public Class<CraftingModuleContainer> getContainerClass() {
|
||||
|
@ -34,12 +35,12 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
|
|||
}
|
||||
|
||||
@Override
|
||||
public RecipeType<CraftingRecipe> getRecipeType() {
|
||||
public RecipeType<RecipeHolder<CraftingRecipe>> getRecipeType() {
|
||||
return RecipeTypes.CRAFTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable IRecipeTransferError transferRecipe(CraftingModuleContainer container, CraftingRecipe recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||
public @Nullable IRecipeTransferError transferRecipe(CraftingModuleContainer container, RecipeHolder<CraftingRecipe> recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||
if (!doTransfer)
|
||||
return null;
|
||||
var inputs = new ArrayList<ItemStack>();
|
||||
|
@ -65,4 +66,5 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
|
|||
PacketHandler.sendToServer(new PacketCraftingModuleTransfer(inputs, outputs));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -21,7 +22,7 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<CraftingTerminalContainer, CraftingRecipe> {
|
||||
public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<CraftingTerminalContainer, RecipeHolder<CraftingRecipe>> {
|
||||
|
||||
@Override
|
||||
public Class<CraftingTerminalContainer> getContainerClass() {
|
||||
|
@ -34,12 +35,12 @@ public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<C
|
|||
}
|
||||
|
||||
@Override
|
||||
public RecipeType<CraftingRecipe> getRecipeType() {
|
||||
public RecipeType<RecipeHolder<CraftingRecipe>> getRecipeType() {
|
||||
return RecipeTypes.CRAFTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable IRecipeTransferError transferRecipe(CraftingTerminalContainer container, CraftingRecipe recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||
public @Nullable IRecipeTransferError transferRecipe(CraftingTerminalContainer container, RecipeHolder<CraftingRecipe> recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) {
|
||||
if (!doTransfer)
|
||||
return null;
|
||||
List<PacketGhostSlot.Entry> stacks = new ArrayList<>();
|
||||
|
@ -49,4 +50,5 @@ public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<C
|
|||
PacketHandler.sendToServer(new PacketGhostSlot(container.getTile().getBlockPos(), stacks));
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@ import net.minecraft.world.item.ItemStack;
|
|||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.neoforged.neoforge.entity.IEntityAdditionalSpawnData;
|
||||
import net.neoforged.neoforge.entity.IEntityWithComplexSpawn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PipeFrameEntity extends ItemFrame implements IEntityAdditionalSpawnData {
|
||||
public class PipeFrameEntity extends ItemFrame implements IEntityWithComplexSpawn {
|
||||
|
||||
private static final EntityDataAccessor<Integer> AMOUNT = SynchedEntityData.defineId(PipeFrameEntity.class, EntityDataSerializers.INT);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import de.ellpeck.prettypipes.Utility;
|
|||
import de.ellpeck.prettypipes.entities.PipeFrameEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
@ -15,7 +16,6 @@ import net.minecraft.world.item.ItemStack;
|
|||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.neoforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
@ -66,6 +66,6 @@ public class PipeFrameItem extends Item {
|
|||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
super.appendHoverText(stack, worldIn, tooltip, flagIn);
|
||||
Utility.addTooltip(ForgeRegistries.ITEMS.getKey(this).getPath(), tooltip);
|
||||
Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), tooltip);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.Utility;
|
|||
import de.ellpeck.prettypipes.pipe.ConnectionType;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
|
@ -19,7 +20,6 @@ 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 net.neoforged.neoforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -108,7 +108,7 @@ public class WrenchItem extends Item {
|
|||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
Utility.addTooltip(ForgeRegistries.ITEMS.getKey(this).getPath(), tooltip);
|
||||
Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), tooltip);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -125,4 +125,5 @@ public class WrenchItem extends Item {
|
|||
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
|
||||
return enchantment == Enchantments.SILK_TOUCH;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package de.ellpeck.prettypipes.misc;
|
||||
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartingEvent;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.event.AttachCapabilitiesEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -20,8 +22,13 @@ import java.nio.file.Paths;
|
|||
public final class Events {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onWorldCaps(AttachCapabilitiesEvent<Level> event) {
|
||||
event.addCapability(new ResourceLocation(PrettyPipes.ID, "network"), new PipeNetwork(event.getObject()));
|
||||
public static void onWorldCaps(RegisterCapabilitiesEvent event) {
|
||||
event.registerBlockEntity(Registry.pipeConnectableCapability, Registry.pipeBlockEntity, (e, d) -> e);
|
||||
event.registerBlockEntity(Registry.pipeConnectableCapability, Registry.pressurizerBlockEntity, (e, d) -> e);
|
||||
event.registerBlockEntity(Registry.pipeConnectableCapability, Registry.itemTerminalBlockEntity, (e, d) -> e);
|
||||
event.registerBlockEntity(Registry.pipeConnectableCapability, Registry.craftingTerminalBlockEntity, (e, d) -> e);
|
||||
|
||||
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, Registry.pressurizerBlockEntity, (e, d) -> e.storage);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -53,4 +60,5 @@ public final class Events {
|
|||
return 0;
|
||||
})));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.function.Supplier;
|
|||
public class ItemEquality {
|
||||
|
||||
public static final ItemEquality DAMAGE = new ItemEquality((stack, filter) -> stack.getDamageValue() == filter.getDamageValue(), false, Type.DAMAGE);
|
||||
public static final ItemEquality NBT = new ItemEquality(ItemStack::areShareTagsEqual, false, Type.NBT);
|
||||
public static final ItemEquality NBT = new ItemEquality((stack, filter) -> Objects.equals(stack.getTag(), filter.getTag()) && stack.areAttachmentsCompatible(filter), false, Type.NBT);
|
||||
public static final ItemEquality MOD = new ItemEquality((stack, filter) -> stack.getItem().getCreatorModId(stack).equals(filter.getItem().getCreatorModId(filter)), true, Type.MOD);
|
||||
|
||||
public final Type type;
|
||||
|
@ -56,4 +56,5 @@ public class ItemEquality {
|
|||
return this.defaultInstance.get();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ public class ModuleClearingRecipe extends CustomRecipe {
|
|||
|
||||
public static final RecipeSerializer<ModuleClearingRecipe> SERIALIZER = new SimpleCraftingRecipeSerializer<>(ModuleClearingRecipe::new);
|
||||
|
||||
public ModuleClearingRecipe(ResourceLocation res, CraftingBookCategory cat) {
|
||||
super(res, cat);
|
||||
public ModuleClearingRecipe(CraftingBookCategory cat) {
|
||||
super(cat);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -243,7 +243,7 @@ public class PipeItem implements IPipeItem {
|
|||
public CompoundTag serializeNBT() {
|
||||
var nbt = new CompoundTag();
|
||||
nbt.putString("type", this.type.toString());
|
||||
nbt.put("stack", this.stack.serializeNBT());
|
||||
nbt.put("stack", this.stack.save(new CompoundTag()));
|
||||
nbt.putFloat("speed", this.speed);
|
||||
nbt.put("start_inv", NbtUtils.writeBlockPos(this.startInventory));
|
||||
nbt.put("dest_inv", NbtUtils.writeBlockPos(this.destInventory));
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.google.common.collect.ArrayListMultimap;
|
|||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.Streams;
|
||||
import de.ellpeck.prettypipes.PrettyPipes;
|
||||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||
|
@ -18,12 +17,11 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
import net.neoforged.neoforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.jgrapht.ListenableGraph;
|
||||
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
|
||||
|
@ -34,8 +32,6 @@ import org.jgrapht.graph.DefaultListenableGraph;
|
|||
import org.jgrapht.graph.SimpleWeightedGraph;
|
||||
import org.jgrapht.traverse.BreadthFirstIterator;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
|
@ -43,33 +39,66 @@ import java.util.function.Function;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphListener<BlockPos, NetworkEdge> {
|
||||
public class PipeNetwork extends SavedData implements GraphListener<BlockPos, NetworkEdge> {
|
||||
|
||||
private static final Factory<PipeNetwork> FACTORY = new Factory<>(PipeNetwork::new, PipeNetwork::new);
|
||||
private static PipeNetwork clientNetwork;
|
||||
|
||||
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, PipeBlockEntity> tileCache = new HashMap<>();
|
||||
private final ListMultimap<BlockPos, IPipeItem> pipeItems = ArrayListMultimap.create();
|
||||
private final ListMultimap<BlockPos, NetworkLock> networkLocks = ArrayListMultimap.create();
|
||||
private final Level world;
|
||||
private final LazyOptional<PipeNetwork> lazyThis = LazyOptional.of(() -> this);
|
||||
private Level level;
|
||||
|
||||
public PipeNetwork(Level world) {
|
||||
this.world = world;
|
||||
public PipeNetwork() {
|
||||
this.graph = new DefaultListenableGraph<>(new SimpleWeightedGraph<>(NetworkEdge.class));
|
||||
this.graph.addGraphListener(this);
|
||||
this.dijkstra = new DijkstraShortestPath<>(this.graph);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||
return cap == Registry.pipeNetworkCapability ? this.lazyThis.cast() : LazyOptional.empty();
|
||||
public PipeNetwork(CompoundTag nbt) {
|
||||
this();
|
||||
this.load(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
var nbt = new CompoundTag();
|
||||
public void edgeAdded(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
|
||||
this.clearDestinationCache(e.getEdge().pipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edgeRemoved(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
|
||||
this.clearDestinationCache(e.getEdge().pipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void vertexAdded(GraphVertexChangeEvent<BlockPos> e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void vertexRemoved(GraphVertexChangeEvent<BlockPos> e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PipeNetwork{" +
|
||||
"\ngraph=" + this.graph +
|
||||
",\nnodeToConnectedNodes=" + this.nodeToConnectedNodes +
|
||||
",\ntileCache=" + this.tileCache.keySet() +
|
||||
",\npipeItems=" + this.pipeItems +
|
||||
",\nnetworkLocks=" + this.networkLocks + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag save(CompoundTag nbt) {
|
||||
var nodes = new ListTag();
|
||||
for (var node : this.graph.vertexSet())
|
||||
nodes.add(NbtUtils.writeBlockPos(node));
|
||||
|
@ -83,8 +112,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag nbt) {
|
||||
public void load(CompoundTag nbt) {
|
||||
this.graph.removeAllVertices(new ArrayList<>(this.graph.vertexSet()));
|
||||
this.pipeItems.clear();
|
||||
this.networkLocks.clear();
|
||||
|
@ -124,7 +152,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
return;
|
||||
for (var edge : neighbors) {
|
||||
var end = edge.getEndPipe();
|
||||
this.refreshNode(end, this.world.getBlockState(end));
|
||||
this.refreshNode(end, this.level.getBlockState(end));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +163,7 @@ 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.isLoaded(startPipePos))
|
||||
if (!this.level.isLoaded(startPipePos))
|
||||
return stack;
|
||||
var startPipe = this.getPipe(startPipePos);
|
||||
if (startPipe == null)
|
||||
|
@ -144,7 +172,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
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))
|
||||
if (!this.level.isLoaded(pipePos))
|
||||
continue;
|
||||
var pipe = this.getPipe(pipePos);
|
||||
var dest = pipe.getAvailableDestination(Direction.values(), stack, false, preventOversending);
|
||||
|
@ -165,7 +193,7 @@ 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.isLoaded(startPipePos) || !this.world.isLoaded(destPipePos))
|
||||
if (!this.level.isLoaded(startPipePos) || !this.level.isLoaded(destPipePos))
|
||||
return false;
|
||||
var startPipe = this.getPipe(startPipePos);
|
||||
if (startPipe == null)
|
||||
|
@ -178,7 +206,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
var item = itemSupplier.apply(startPipe.getItemSpeed(stack));
|
||||
item.setDestination(startInventory, destInventory, path);
|
||||
startPipe.addNewItem(item);
|
||||
PacketHandler.sendToAllLoaded(this.world, startPipePos, new PacketItemEnterPipe(startPipePos, item));
|
||||
PacketHandler.sendToAllLoaded(this.level, startPipePos, new PacketItemEnterPipe(startPipePos, item));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -216,7 +244,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
if (location.getPos().equals(destInventory))
|
||||
return stack;
|
||||
// make sure we don't pull any locked items
|
||||
var amount = location.getItemAmount(this.world, stack, equalityTypes);
|
||||
var amount = location.getItemAmount(this.level, stack, equalityTypes);
|
||||
if (amount <= 0)
|
||||
return stack;
|
||||
amount -= this.getLockedAmount(location.getPos(), stack, ignoredLock, equalityTypes);
|
||||
|
@ -227,9 +255,9 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
if (remain.getCount() < amount)
|
||||
amount = remain.getCount();
|
||||
remain.shrink(amount);
|
||||
for (int slot : location.getStackSlots(this.world, stack, equalityTypes)) {
|
||||
for (int slot : location.getStackSlots(this.level, stack, equalityTypes)) {
|
||||
// try to extract from that location's inventory and send the item
|
||||
var handler = location.getItemHandler(this.world);
|
||||
var handler = location.getItemHandler(this.level);
|
||||
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);
|
||||
|
@ -244,7 +272,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public PipeBlockEntity getPipe(BlockPos pos) {
|
||||
var tile = this.tileCache.get(pos);
|
||||
if (tile == null || tile.isRemoved()) {
|
||||
tile = Utility.getBlockEntity(PipeBlockEntity.class, this.world, pos);
|
||||
tile = Utility.getBlockEntity(PipeBlockEntity.class, this.level, pos);
|
||||
if (tile != null)
|
||||
this.tileCache.put(pos, tile);
|
||||
}
|
||||
|
@ -291,7 +319,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
this.startProfile("get_all_craftables");
|
||||
List<Pair<BlockPos, ItemStack>> craftables = new ArrayList<>();
|
||||
for (var dest : this.getOrderedNetworkNodes(node)) {
|
||||
if (!this.world.isLoaded(dest))
|
||||
if (!this.level.isLoaded(dest))
|
||||
continue;
|
||||
var pipe = this.getPipe(dest);
|
||||
for (var stack : pipe.getAllCraftables())
|
||||
|
@ -306,7 +334,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
for (var pair : this.getAllCraftables(node)) {
|
||||
if (!ItemEquality.compareItems(pair.getRight(), stack, equalityTypes))
|
||||
continue;
|
||||
if (!this.world.isLoaded(pair.getLeft()))
|
||||
if (!this.level.isLoaded(pair.getLeft()))
|
||||
continue;
|
||||
var pipe = this.getPipe(pair.getLeft());
|
||||
if (pipe != null)
|
||||
|
@ -321,7 +349,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
this.startProfile("get_network_items");
|
||||
List<NetworkLocation> info = new ArrayList<>();
|
||||
for (var dest : this.getOrderedNetworkNodes(node)) {
|
||||
if (!this.world.isLoaded(dest))
|
||||
if (!this.level.isLoaded(dest))
|
||||
continue;
|
||||
var pipe = this.getPipe(dest);
|
||||
for (var dir : Direction.values()) {
|
||||
|
@ -329,10 +357,10 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
if (handler == null || !pipe.canNetworkSee(dir, handler))
|
||||
continue;
|
||||
// check if this handler already exists (double-connected pipes, double chests etc.)
|
||||
if (info.stream().anyMatch(l -> handler.equals(l.getItemHandler(this.world))))
|
||||
if (info.stream().anyMatch(l -> handler.equals(l.getItemHandler(this.level))))
|
||||
continue;
|
||||
var location = new NetworkLocation(dest, dir);
|
||||
if (!location.isEmpty(this.world))
|
||||
if (!location.isEmpty(this.level))
|
||||
info.add(location);
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +403,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
public BlockPos getNodeFromPipe(BlockPos pos) {
|
||||
if (this.isNode(pos))
|
||||
return pos;
|
||||
var state = this.world.getBlockState(pos);
|
||||
var state = this.level.getBlockState(pos);
|
||||
if (!(state.getBlock() instanceof PipeBlock))
|
||||
return null;
|
||||
for (var dir : Direction.values()) {
|
||||
|
@ -411,7 +439,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
if (!ignoreCurrBlocked && !state.getValue(PipeBlock.DIRECTIONS.get(dir)).isConnected())
|
||||
return null;
|
||||
var currPos = pos.relative(dir);
|
||||
var currState = this.world.getBlockState(currPos);
|
||||
var currState = this.level.getBlockState(currPos);
|
||||
if (!(currState.getBlock() instanceof PipeBlock))
|
||||
return null;
|
||||
this.startProfile("create_edge");
|
||||
|
@ -432,7 +460,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
if (!currState.getValue(PipeBlock.DIRECTIONS.get(nextDir)).isConnected())
|
||||
continue;
|
||||
var offset = currPos.relative(nextDir);
|
||||
var offState = this.world.getBlockState(offset);
|
||||
var offState = this.level.getBlockState(offset);
|
||||
if (!(offState.getBlock() instanceof PipeBlock))
|
||||
continue;
|
||||
if (edge.pipes.contains(offset))
|
||||
|
@ -496,44 +524,27 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
|
|||
.mapToInt(i -> i.getItemsOnTheWay(goalInv)).sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edgeAdded(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
|
||||
this.clearDestinationCache(e.getEdge().pipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edgeRemoved(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
|
||||
this.clearDestinationCache(e.getEdge().pipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void vertexAdded(GraphVertexChangeEvent<BlockPos> e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void vertexRemoved(GraphVertexChangeEvent<BlockPos> e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PipeNetwork{" +
|
||||
"\ngraph=" + this.graph +
|
||||
",\nnodeToConnectedNodes=" + this.nodeToConnectedNodes +
|
||||
",\ntileCache=" + this.tileCache.keySet() +
|
||||
",\npipeItems=" + this.pipeItems +
|
||||
",\nnetworkLocks=" + this.networkLocks + '}';
|
||||
}
|
||||
|
||||
public void startProfile(String name) {
|
||||
this.world.getProfiler().push(() -> PrettyPipes.ID + ":pipe_network_" + name);
|
||||
this.level.getProfiler().push(() -> PrettyPipes.ID + ":pipe_network_" + name);
|
||||
}
|
||||
|
||||
public void endProfile() {
|
||||
this.world.getProfiler().pop();
|
||||
this.level.getProfiler().pop();
|
||||
}
|
||||
|
||||
public static PipeNetwork get(Level world) {
|
||||
return world.getCapability(Registry.pipeNetworkCapability).orElse(null);
|
||||
public static PipeNetwork get(Level level) {
|
||||
if (level instanceof ServerLevel server) {
|
||||
var ret = server.getDataStorage().computeIfAbsent(PipeNetwork.FACTORY, "pipe_network");
|
||||
if (ret.level == null)
|
||||
ret.level = level;
|
||||
return ret;
|
||||
} else {
|
||||
if (PipeNetwork.clientNetwork == null || PipeNetwork.clientNetwork.level != level) {
|
||||
PipeNetwork.clientNetwork = new PipeNetwork();
|
||||
PipeNetwork.clientNetwork.level = level;
|
||||
}
|
||||
return PipeNetwork.clientNetwork;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ import net.minecraft.world.MenuProvider;
|
|||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.neoforged.neoforge.network.NetworkEvent;
|
||||
import net.neoforged.neoforge.network.NetworkHooks;
|
||||
import org.apache.logging.log4j.util.TriConsumer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
|
|
@ -34,9 +34,8 @@ 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.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||
import net.neoforged.neoforge.network.NetworkHooks;
|
||||
import org.apache.commons.lang3.mutable.MutableObject;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
|
@ -204,10 +203,10 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
var opposite = direction.getOpposite();
|
||||
var tile = world.getBlockEntity(offset);
|
||||
if (tile != null) {
|
||||
var connectable = tile.getCapability(Registry.pipeConnectableCapability, opposite).orElse(null);
|
||||
var connectable = world.getCapability(Registry.pipeConnectableCapability, pos, state, tile, opposite);
|
||||
if (connectable != null)
|
||||
return connectable.getConnectionType(pos, direction);
|
||||
var handler = tile.getCapability(Capabilities.ITEM_HANDLER, opposite).orElse(null);
|
||||
var handler = world.getCapability(Capabilities.ItemHandler.BLOCK, pos, state, tile, opposite);
|
||||
if (handler != null)
|
||||
return ConnectionType.CONNECTED;
|
||||
}
|
||||
|
@ -225,7 +224,7 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
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;
|
||||
var mapColor = state.getMapColor(world,pos);
|
||||
var mapColor = state.getMapColor(world, pos);
|
||||
if (mapColor == MapColor.STONE || mapColor == MapColor.METAL)
|
||||
return Block.canSupportCenter(world, pos, direction.getOpposite());
|
||||
return false;
|
||||
|
@ -271,9 +270,9 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void playerWillDestroy(Level worldIn, BlockPos pos, BlockState state, Player player) {
|
||||
public BlockState playerWillDestroy(Level worldIn, BlockPos pos, BlockState state, Player player) {
|
||||
PipeBlock.dropItems(worldIn, pos, player);
|
||||
super.playerWillDestroy(worldIn, pos, state, player);
|
||||
return super.playerWillDestroy(worldIn, pos, state, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -316,4 +315,5 @@ public class PipeBlock extends BaseEntityBlock {
|
|||
tile.removeCover(player, InteractionHand.MAIN_HAND);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,12 +36,11 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
import net.minecraft.world.phys.AABB;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.capabilities.BlockCapability;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.common.util.Lazy;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import net.neoforged.neoforge.common.capabilities.Capability;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -80,7 +79,6 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
protected List<IPipeItem> items;
|
||||
private int lastItemAmount;
|
||||
private int priority;
|
||||
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) {
|
||||
|
@ -108,7 +106,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
for (var triple : this.craftResultRequests) {
|
||||
var nbt = new CompoundTag();
|
||||
nbt.putLong("dest_pipe", triple.getLeft().asLong());
|
||||
nbt.put("item", triple.getRight().serializeNBT());
|
||||
nbt.put("item", triple.getRight().save(new CompoundTag()));
|
||||
results.add(nbt);
|
||||
}
|
||||
compound.put("craft_results", results);
|
||||
|
@ -315,26 +313,26 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
}
|
||||
|
||||
public IItemHandler getItemHandler(Direction dir) {
|
||||
var handler = this.getNeighborCap(dir, Capabilities.ITEM_HANDLER);
|
||||
var handler = this.getNeighborCap(dir, Capabilities.ItemHandler.BLOCK);
|
||||
if (handler != null)
|
||||
return handler;
|
||||
return Utility.getBlockItemHandler(this.level, this.worldPosition.relative(dir), dir.getOpposite());
|
||||
}
|
||||
|
||||
public <T> T getNeighborCap(Direction dir, Capability<T> cap) {
|
||||
public <T, C> T getNeighborCap(Direction dir, BlockCapability<T, Direction> cap) {
|
||||
if (!this.isConnected(dir))
|
||||
return null;
|
||||
var pos = this.worldPosition.relative(dir);
|
||||
var tile = this.level.getBlockEntity(pos);
|
||||
if (tile != null)
|
||||
return tile.getCapability(cap, dir.getOpposite()).orElse(null);
|
||||
return this.level.getCapability(cap, tile.getBlockPos(), tile.getBlockState(), tile, dir.getOpposite());
|
||||
return null;
|
||||
}
|
||||
|
||||
public IPipeConnectable getPipeConnectable(Direction dir) {
|
||||
var tile = this.level.getBlockEntity(this.worldPosition.relative(dir));
|
||||
if (tile != null)
|
||||
return tile.getCapability(Registry.pipeConnectableCapability, dir.getOpposite()).orElse(null);
|
||||
return this.level.getCapability(Registry.pipeConnectableCapability, tile.getBlockPos(), tile.getBlockState(), tile, dir.getOpposite());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -400,7 +398,6 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
var network = PipeNetwork.get(this.level);
|
||||
for (var lock : this.craftIngredientRequests)
|
||||
network.resolveNetworkLock(lock);
|
||||
this.lazyThis.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -414,19 +411,13 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
|||
return new MainPipeContainer(Registry.pipeContainer, window, player, PipeBlockEntity.this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO render bounding box?
|
||||
/* @Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public AABB getRenderBoundingBox() {
|
||||
// our render bounding box should always be the full block in case we're covered
|
||||
return new AABB(this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
|
||||
if (cap == Registry.pipeConnectableCapability)
|
||||
return this.lazyThis.cast();
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
|
||||
|
|
|
@ -54,10 +54,10 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
|||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(graphics);
|
||||
this.renderBackground(graphics, mouseX, mouseY, partialTicks);
|
||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||
for (var widget : this.renderables) {
|
||||
// TDOO render widget tooltips?
|
||||
// TODO render widget tooltips?
|
||||
/* if (widget instanceof AbstractWidget abstractWidget) {
|
||||
if (abstractWidget.isHoveredOrFocused())
|
||||
abstractWidget.renderToolTip(matrix, mouseX, mouseY);
|
||||
|
@ -156,5 +156,7 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
|||
AbstractPipeGui.this.getMinecraft().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -85,9 +85,9 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double scroll) {
|
||||
public boolean mouseScrolled(double x, double y, double scrollX, double scrollY) {
|
||||
if (this.tags.size() >= 6) {
|
||||
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.tags.size() - 5);
|
||||
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scrollY), 0, this.tags.size() - 5);
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -138,5 +138,7 @@ public class FilterModifierModuleGui extends AbstractPipeGui<FilterModifierModul
|
|||
FilterModifierModuleGui.this.getMinecraft().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.ellpeck.prettypipes.pressurizer;
|
|||
import de.ellpeck.prettypipes.Registry;
|
||||
import de.ellpeck.prettypipes.Utility;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -21,8 +22,6 @@ 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.phys.BlockHitResult;
|
||||
import net.neoforged.neoforge.registries.ForgeRegistries;
|
||||
import net.neoforged.neoforge.network.NetworkHooks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
@ -56,7 +55,7 @@ public class PressurizerBlock extends BaseEntityBlock {
|
|||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
Utility.addTooltip(ForgeRegistries.BLOCKS.getKey(this).getPath(), tooltip);
|
||||
Utility.addTooltip(BuiltInRegistries.BLOCK.getKey(this).getPath(), tooltip);
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
|
@ -77,4 +76,5 @@ public class PressurizerBlock extends BaseEntityBlock {
|
|||
return 0;
|
||||
return (int) (pipe.getEnergy() / (float) pipe.getMaxEnergy() * 15);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,19 +20,13 @@ 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.neoforged.neoforge.common.capabilities.Capability;
|
||||
import net.neoforged.neoforge.common.capabilities.Capabilities;
|
||||
import net.neoforged.neoforge.energy.EnergyStorage;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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);
|
||||
public final ModifiableEnergyStorage storage = new ModifiableEnergyStorage(64000, 512, 0);
|
||||
private int lastEnergy;
|
||||
|
||||
public PressurizerBlockEntity(BlockPos pos, BlockState state) {
|
||||
|
@ -94,24 +88,6 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
|
|||
return new PressurizerContainer(Registry.pressurizerContainer, window, player, this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
|
||||
if (cap == Capabilities.ENERGY) {
|
||||
return this.lazyStorage.cast();
|
||||
} else if (cap == Registry.pipeConnectableCapability) {
|
||||
return this.lazyThis.cast();
|
||||
} else {
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
this.lazyStorage.invalidate();
|
||||
this.lazyThis.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
|
||||
return ConnectionType.CONNECTED;
|
||||
|
@ -141,7 +117,7 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
|
|||
}
|
||||
}
|
||||
|
||||
private static class ModifiableEnergyStorage extends EnergyStorage {
|
||||
public static class ModifiableEnergyStorage extends EnergyStorage {
|
||||
|
||||
public ModifiableEnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
||||
super(capacity, maxReceive, maxExtract);
|
||||
|
@ -157,5 +133,7 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
|
|||
this.energy -= energyExtracted;
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class PressurizerGui extends AbstractContainerScreen<PressurizerContainer
|
|||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(graphics);
|
||||
this.renderBackground(graphics, mouseX, mouseY, partialTicks);
|
||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||
this.renderTooltip(graphics, mouseX, mouseY);
|
||||
if (mouseX >= this.leftPos + 26 && mouseY >= this.topPos + 22 && mouseX < this.leftPos + 26 + 124 && mouseY < this.topPos + 22 + 12)
|
||||
|
@ -38,4 +38,5 @@ public class PressurizerGui extends AbstractContainerScreen<PressurizerContainer
|
|||
var energy = (int) (this.menu.tile.getEnergyPercentage() * 124);
|
||||
graphics.blit(PressurizerGui.TEXTURE, this.leftPos + 26, this.topPos + 22, 0, 137, energy, 12);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.Registry;
|
|||
import de.ellpeck.prettypipes.Utility;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -21,8 +22,6 @@ 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.phys.BlockHitResult;
|
||||
import net.neoforged.neoforge.network.NetworkHooks;
|
||||
import net.neoforged.neoforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
@ -74,7 +73,7 @@ public class ItemTerminalBlock extends BaseEntityBlock {
|
|||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
Utility.addTooltip(ForgeRegistries.BLOCKS.getKey(this).getPath(), tooltip);
|
||||
Utility.addTooltip(BuiltInRegistries.BLOCK.getKey(this).getPath(), tooltip);
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
|
|
|
@ -31,8 +31,6 @@ 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.neoforged.neoforge.common.capabilities.Capability;
|
||||
import net.neoforged.neoforge.common.util.LazyOptional;
|
||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
@ -53,7 +51,6 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
};
|
||||
protected Map<EquatableItemStack, NetworkItem> networkItems;
|
||||
private final Queue<NetworkLock> existingRequests = new LinkedList<>();
|
||||
private final LazyOptional<IPipeConnectable> lazyThis = LazyOptional.of(() -> this);
|
||||
|
||||
public ItemTerminalBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
|
@ -106,7 +103,6 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
var network = PipeNetwork.get(this.level);
|
||||
for (var lock : this.existingRequests)
|
||||
network.resolveNetworkLock(lock);
|
||||
this.lazyThis.invalidate();
|
||||
}
|
||||
|
||||
public String getInvalidTerminalReason() {
|
||||
|
@ -257,13 +253,6 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
|||
return new ItemTerminalContainer(Registry.itemTerminalContainer, window, player, this.worldPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
|
||||
if (cap == Registry.pipeConnectableCapability)
|
||||
return this.lazyThis.cast();
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
|
||||
return ConnectionType.CONNECTED;
|
||||
|
|
|
@ -50,7 +50,7 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
|||
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().assemble(this.craftInventory, this.player.level().registryAccess());
|
||||
ret = optional.get().value().assemble(this.craftInventory, this.player.level().registryAccess());
|
||||
this.craftResult.setItem(0, ret);
|
||||
((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, 0, ret));
|
||||
}
|
||||
|
@ -79,4 +79,5 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
|||
public CraftingTerminalBlockEntity getTile() {
|
||||
return (CraftingTerminalBlockEntity) this.tile;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -130,7 +130,6 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
this.plusButton.active = this.requestAmount < 384;
|
||||
this.minusButton.active = this.requestAmount > 1;
|
||||
|
||||
this.search.tick();
|
||||
if (this.items != null) {
|
||||
var text = this.search.getValue();
|
||||
if (!this.lastSearchText.equals(text)) {
|
||||
|
@ -265,10 +264,9 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(graphics);
|
||||
this.renderBackground(graphics, mouseX, mouseY, partialTicks);
|
||||
super.render(graphics, mouseX, mouseY, partialTicks);
|
||||
for (var widget : this.renderables) {
|
||||
if (widget instanceof ItemTerminalWidget terminal)
|
||||
|
@ -290,7 +288,6 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
this.renderTooltip(graphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
|
||||
graphics.drawString(this.font, this.playerInventoryTitle.getString(), 8 + this.getXOffset(), this.imageHeight - 96 + 2, 4210752, false);
|
||||
|
@ -347,9 +344,9 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double x, double y, double scroll) {
|
||||
public boolean mouseScrolled(double x, double y, double scrollX, double scrollY) {
|
||||
if (this.sortedItems != null && this.sortedItems.size() >= 9 * 4) {
|
||||
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scroll), 0, this.sortedItems.size() / 9 - 3);
|
||||
var offset = Mth.clamp(this.scrollOffset - (int) Math.signum(scrollY), 0, this.sortedItems.size() / 9 - 3);
|
||||
if (offset != this.scrollOffset) {
|
||||
this.scrollOffset = offset;
|
||||
this.updateWidgets();
|
||||
|
@ -379,4 +376,5 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue