Merge branch 'mc1.20.1/feature-dev' into mc1.21.1/dev

# Conflicts:
#	src/main/java/com/simibubi/create/AllRegistries.java
#	src/main/java/com/simibubi/create/content/kinetics/belt/transport/TransportedItemStack.java
#	src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessing.java
#	src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessingType.java
#	src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessingTypeRegistry.java
#	src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmInteractionPoint.java
#	src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmInteractionPointType.java
#	src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelBlockEntity.java
#	src/main/java/com/simibubi/create/content/logistics/filter/AttributeFilterScreen.java
#	src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/AllItemAttributeTypes.java
#	src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/ItemAttribute.java
#	src/main/java/com/simibubi/create/content/logistics/packagerLink/LogisticallyLinkedBehaviour.java
This commit is contained in:
IThundxr 2025-02-17 10:59:32 -05:00
commit a9b40126a4
Failed to generate hash of commit
28 changed files with 121 additions and 64 deletions

View file

@ -9,6 +9,7 @@ import com.simibubi.create.content.logistics.packagePort.PackagePortTargetType;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.registries.NewRegistryEvent;
@ -16,24 +17,25 @@ import net.neoforged.neoforge.registries.RegistryBuilder;
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
public class AllRegistries {
public static final Registry<ArmInteractionPointType> ARM_INTERACTION_POINT_TYPES = create(Keys.ARM_INTERACTION_POINT_TYPES);
public static final Registry<FanProcessingType> FAN_PROCESSING_TYPES = create(Keys.FAN_PROCESSING_TYPES);
public static final Registry<ItemAttributeType> ITEM_ATTRIBUTE_TYPES = create(AllRegistries.Keys.ITEM_ATTRIBUTE_TYPES);
public static final Registry<PackagePortTargetType> PACKAGE_PORT_TARGETS = create(Keys.PACKAGE_PORT_TARGETS);
public static final Registry<MountedItemStorageType<?>> MOUNTED_ITEM_STORAGE_TYPES = create(Keys.MOUNTED_ITEM_STORAGE_TYPES);
public static final Registry<MountedFluidStorageType<?>> MOUNTED_FLUID_STORAGE_TYPES = create(Keys.MOUNTED_FLUID_STORAGE_TYPES);
public static final Registry<ArmInteractionPointType> ARM_INTERACTION_POINT_TYPE = create(Keys.ARM_INTERACTION_POINT_TYPE);
public static final Registry<FanProcessingType> FAN_PROCESSING_TYPE = create(Keys.FAN_PROCESSING_TYPE);
public static final Registry<ItemAttributeType> ITEM_ATTRIBUTE_TYPE = create(AllRegistries.Keys.ITEM_ATTRIBUTE_TYPE);
public static final Registry<PackagePortTargetType> PACKAGE_PORT_TARGET = create(Keys.PACKAGE_PORT_TARGET);
public static final Registry<MountedItemStorageType<?>> MOUNTED_ITEM_STORAGE_TYPE = create(Keys.MOUNTED_ITEM_STORAGE_TYPE);
public static final Registry<MountedFluidStorageType<?>> MOUNTED_FLUID_STORAGE_TYPE = create(Keys.MOUNTED_FLUID_STORAGE_TYPE);
private static <T> Registry<T> create(ResourceKey<Registry<T>> key) {
return new RegistryBuilder<>(key).sync(true).create();
}
// Make these non-plural
public static final class Keys {
public static final ResourceKey<Registry<ArmInteractionPointType>> ARM_INTERACTION_POINT_TYPES = key("arm_interaction_point_types");
public static final ResourceKey<Registry<FanProcessingType>> FAN_PROCESSING_TYPES = key("fan_processing_types");
public static final ResourceKey<Registry<ItemAttributeType>> ITEM_ATTRIBUTE_TYPES = key("item_attribute_types");
public static final ResourceKey<Registry<PackagePortTargetType>> PACKAGE_PORT_TARGETS = key("package_port_targets");
public static final ResourceKey<Registry<MountedItemStorageType<?>>> MOUNTED_ITEM_STORAGE_TYPES = key("mounted_item_storage_type");
public static final ResourceKey<Registry<MountedFluidStorageType<?>>> MOUNTED_FLUID_STORAGE_TYPES = key("mounted_fluid_storage_type");
public static final ResourceKey<Registry<ArmInteractionPointType>> ARM_INTERACTION_POINT_TYPE = key("arm_interaction_point_type");
public static final ResourceKey<Registry<FanProcessingType>> FAN_PROCESSING_TYPE = key("fan_processing_type");
public static final ResourceKey<Registry<ItemAttributeType>> ITEM_ATTRIBUTE_TYPE = key("item_attribute_type");
public static final ResourceKey<Registry<PackagePortTargetType>> PACKAGE_PORT_TARGET = key("package_port_target");
public static final ResourceKey<Registry<MountedItemStorageType<?>>> MOUNTED_ITEM_STORAGE_TYPE = key("mounted_item_storage_type");
public static final ResourceKey<Registry<MountedFluidStorageType<?>>> MOUNTED_FLUID_STORAGE_TYPE = key("mounted_fluid_storage_type");
private static <T> ResourceKey<Registry<T>> key(String name) {
return ResourceKey.createRegistryKey(Create.asResource(name));
@ -42,11 +44,11 @@ public class AllRegistries {
@SubscribeEvent
public static void registerRegistries(NewRegistryEvent event) {
event.register(AllRegistries.ARM_INTERACTION_POINT_TYPES);
event.register(AllRegistries.FAN_PROCESSING_TYPES);
event.register(AllRegistries.ITEM_ATTRIBUTE_TYPES);
event.register(AllRegistries.PACKAGE_PORT_TARGETS);
event.register(AllRegistries.MOUNTED_ITEM_STORAGE_TYPES);
event.register(AllRegistries.MOUNTED_FLUID_STORAGE_TYPES);
event.register(AllRegistries.ARM_INTERACTION_POINT_TYPE);
event.register(AllRegistries.FAN_PROCESSING_TYPE);
event.register(AllRegistries.ITEM_ATTRIBUTE_TYPE);
event.register(AllRegistries.PACKAGE_PORT_TARGET);
event.register(AllRegistries.MOUNTED_ITEM_STORAGE_TYPE);
event.register(AllRegistries.MOUNTED_FLUID_STORAGE_TYPE);
}
}

View file

@ -28,7 +28,7 @@ public class MountedStorageTypeRegistry {
* that will register the given MountedItemStorageType to a block when ready.
*/
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> mountedItemStorage(RegistryEntry<? extends MountedItemStorageType<?>, ?> type) {
return builder -> builder.onRegisterAfter(Keys.MOUNTED_ITEM_STORAGE_TYPES, block -> ITEM_LOOKUP.register(block, type.get()));
return builder -> builder.onRegisterAfter(Keys.MOUNTED_ITEM_STORAGE_TYPE, block -> ITEM_LOOKUP.register(block, type.get()));
}
/**
@ -36,6 +36,6 @@ public class MountedStorageTypeRegistry {
* that will register the given MountedFluidStorageType to a block when ready.
*/
public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> mountedFluidStorage(RegistryEntry<? extends MountedFluidStorageType<?>, ?> type) {
return builder -> builder.onRegisterAfter(Keys.MOUNTED_FLUID_STORAGE_TYPES, block -> FLUID_LOOKUP.register(block, type.get()));
return builder -> builder.onRegisterAfter(Keys.MOUNTED_FLUID_STORAGE_TYPE, block -> FLUID_LOOKUP.register(block, type.get()));
}
}

View file

@ -13,7 +13,7 @@ import net.minecraft.world.level.block.state.BlockState;
public abstract class MountedFluidStorageType<T extends MountedFluidStorage> {
public static final Codec<MountedFluidStorageType<?>> CODEC = Codec.lazyInitialized(
AllRegistries.MOUNTED_FLUID_STORAGE_TYPES::byNameCodec
AllRegistries.MOUNTED_FLUID_STORAGE_TYPE::byNameCodec
);
public final MapCodec<? extends T> codec;

View file

@ -15,7 +15,7 @@ public class MountedFluidStorageTypeBuilder<T extends MountedFluidStorageType<?>
private final T type;
public MountedFluidStorageTypeBuilder(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, T type) {
super(owner, parent, name, callback, AllRegistries.Keys.MOUNTED_FLUID_STORAGE_TYPES);
super(owner, parent, name, callback, AllRegistries.Keys.MOUNTED_FLUID_STORAGE_TYPE);
this.type = type;
}

View file

@ -13,7 +13,7 @@ import net.minecraft.world.level.block.state.BlockState;
public abstract class MountedItemStorageType<T extends MountedItemStorage> {
public static final Codec<MountedItemStorageType<?>> CODEC = Codec.lazyInitialized(
AllRegistries.MOUNTED_ITEM_STORAGE_TYPES::byNameCodec
AllRegistries.MOUNTED_ITEM_STORAGE_TYPE::byNameCodec
);
public final MapCodec<? extends T> codec;

View file

@ -15,7 +15,7 @@ public class MountedItemStorageTypeBuilder<T extends MountedItemStorageType<?>,
private final T type;
public MountedItemStorageTypeBuilder(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, T type) {
super(owner, parent, name, callback, AllRegistries.Keys.MOUNTED_ITEM_STORAGE_TYPES);
super(owner, parent, name, callback, AllRegistries.Keys.MOUNTED_ITEM_STORAGE_TYPE);
this.type = type;
}

View file

@ -686,6 +686,9 @@ public abstract class Contraption {
controllerPos = toLocalPos(NBTHelper.readBlockPos(nbt, "Controller"));
nbt.put("Controller", NbtUtils.writeBlockPos(controllerPos));
if (updateTags.containsKey(localPos))
updateTags.get(localPos).put("Controller", NbtUtils.writeBlockPos(controllerPos));
if (multiBlockBE.isController() && multiBlockBE.getHeight() <= 1 && multiBlockBE.getWidth() <= 1) {
nbt.put("LastKnownPos", NbtUtils.writeBlockPos(BlockPos.ZERO.below(Integer.MAX_VALUE - 1)));
return;

View file

@ -83,7 +83,7 @@ public class TransportedItemStack implements Comparable<TransportedItemStack> {
nbt.putInt("InDirection", insertedFrom.get3DDataValue());
if (processedBy != null && processedBy != AllFanProcessingTypes.NONE) {
ResourceLocation key = AllRegistries.FAN_PROCESSING_TYPES.getKey(processedBy);
ResourceLocation key = AllRegistries.FAN_PROCESSING_TYPE.getKey(processedBy);
if (key == null)
throw new IllegalArgumentException("Could not get id for FanProcessingType " + processedBy + "!");

View file

@ -60,7 +60,7 @@ import net.minecraft.world.phys.Vec3;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredRegister;
public class AllFanProcessingTypes {
private static final DeferredRegister<FanProcessingType> REGISTER = DeferredRegister.create(AllRegistries.Keys.FAN_PROCESSING_TYPES, Create.ID);
private static final DeferredRegister<FanProcessingType> REGISTER = DeferredRegister.create(AllRegistries.Keys.FAN_PROCESSING_TYPE, Create.ID);
public static final NoneType NONE = register("none", new NoneType());
public static final BlastingType BLASTING = register("blasting", new BlastingType());

View file

@ -95,7 +95,7 @@ public class FanProcessing {
CompoundTag processing = createData.getCompound("Processing");
if (!processing.contains("Type") || AllFanProcessingTypes.parseLegacy(processing.getString("Type")) != type) {
ResourceLocation key = AllRegistries.FAN_PROCESSING_TYPES.getKey(type);
ResourceLocation key = AllRegistries.FAN_PROCESSING_TYPE.getKey(type);
if (key == null)
throw new IllegalArgumentException("Could not get id for FanProcessingType " + type + "!");

View file

@ -36,7 +36,7 @@ public interface FanProcessingType {
if (id == null) {
return AllFanProcessingTypes.NONE;
}
FanProcessingType type = AllRegistries.FAN_PROCESSING_TYPES.get(id);
FanProcessingType type = AllRegistries.FAN_PROCESSING_TYPE.get(id);
if (type == null) {
return AllFanProcessingTypes.NONE;
}

View file

@ -4,12 +4,12 @@ import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import org.jetbrains.annotations.UnmodifiableView;
import com.simibubi.create.AllRegistries;
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
import org.jetbrains.annotations.UnmodifiableView;
public class FanProcessingTypeRegistry {
private static List<FanProcessingType> sortedTypes = null;
@UnmodifiableView
@ -20,9 +20,8 @@ public class FanProcessingTypeRegistry {
if (sortedTypes == null) {
sortedTypes = new ReferenceArrayList<>();
for (Entry<?, FanProcessingType> type : AllRegistries.FAN_PROCESSING_TYPES.entrySet())
for (Entry<?, FanProcessingType> type : AllRegistries.FAN_PROCESSING_TYPE.entrySet())
sortedTypes.add(type.getValue());
sortedTypes.sort((t1, t2) -> t2.getPriority() - t1.getPriority());
sortedTypesView = Collections.unmodifiableList(sortedTypes);

View file

@ -66,7 +66,7 @@ import net.neoforged.neoforge.items.wrapper.SidedInvWrapper;
import net.neoforged.neoforge.registries.DeferredRegister;
public class AllArmInteractionPointTypes {
private static final DeferredRegister<ArmInteractionPointType> REGISTER = DeferredRegister.create(AllRegistries.Keys.ARM_INTERACTION_POINT_TYPES, Create.ID);
private static final DeferredRegister<ArmInteractionPointType> REGISTER = DeferredRegister.create(AllRegistries.Keys.ARM_INTERACTION_POINT_TYPE, Create.ID);
static {
register("basin", new BasinType());

View file

@ -5,8 +5,8 @@ import javax.annotation.Nullable;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.content.contraptions.StructureTransform;
import net.createmod.catnip.nbt.NBTHelper;
import net.createmod.catnip.math.VecHelper;
import net.createmod.catnip.nbt.NBTHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
@ -18,6 +18,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.capabilities.BlockCapabilityCache;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler;
@ -90,7 +91,8 @@ public class ArmInteractionPoint {
return type.canCreatePoint(level, pos, cachedState);
}
public void keepAlive() {}
public void keepAlive() {
}
@Nullable
protected IItemHandler getHandler() {
@ -142,7 +144,7 @@ public class ArmInteractionPoint {
}
public final CompoundTag serialize(BlockPos anchor) {
ResourceLocation key = AllRegistries.ARM_INTERACTION_POINT_TYPES.getKey(type);
ResourceLocation key = AllRegistries.ARM_INTERACTION_POINT_TYPE.getKey(type);
if (key == null)
throw new IllegalArgumentException("Could not get id for ArmInteractionPointType " + type + "!");
@ -158,7 +160,7 @@ public class ArmInteractionPoint {
ResourceLocation id = ResourceLocation.tryParse(nbt.getString("Type"));
if (id == null)
return null;
ArmInteractionPointType type = AllRegistries.ARM_INTERACTION_POINT_TYPES.get(id);
ArmInteractionPointType type = AllRegistries.ARM_INTERACTION_POINT_TYPE.get(id);
if (type == null)
return null;
BlockPos pos = NBTHelper.readBlockPos(nbt, "Pos").offset(anchor);

View file

@ -7,6 +7,8 @@ import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.jetbrains.annotations.UnmodifiableView;
import com.simibubi.create.AllRegistries;
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
@ -14,8 +16,6 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.UnmodifiableView;
public abstract class ArmInteractionPointType {
private static List<ArmInteractionPointType> sortedTypes = null;
@UnmodifiableView
@ -30,9 +30,8 @@ public abstract class ArmInteractionPointType {
if (sortedTypes == null) {
sortedTypes = new ReferenceArrayList<>();
for (Entry<?, ArmInteractionPointType> type : AllRegistries.ARM_INTERACTION_POINT_TYPES.entrySet())
for (Entry<?, ArmInteractionPointType> type : AllRegistries.ARM_INTERACTION_POINT_TYPE.entrySet())
sortedTypes.add(type.getValue());
sortedTypes.sort((t1, t2) -> t2.getPriority() - t1.getPriority());
sortedTypesView = Collections.unmodifiableList(sortedTypes);

View file

@ -19,12 +19,12 @@ import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Direction.AxisDirection;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderLookup.Provider;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
@ -201,6 +201,12 @@ public class WaterWheelBlockEntity extends GeneratingKineticBlockEntity {
redraw();
}
@Override
public void writeSafe(CompoundTag tag, Provider registries) {
super.writeSafe(tag, registries);
tag.put("Material", NbtUtils.writeBlockState(material));
}
@Override
public void write(CompoundTag compound, HolderLookup.Provider registries, boolean clientPacket) {
super.write(compound, registries, clientPacket);

View file

@ -27,8 +27,12 @@ public class AddressEditBox extends EditBox {
private String prevValue = "=)";
public AddressEditBox(Screen screen, Font pFont, int pX, int pY, int pWidth, int pHeight, boolean anchorToBottom) {
this(screen, pFont, pX, pY, pWidth, pHeight, anchorToBottom, null);
}
public AddressEditBox(Screen screen, Font pFont, int pX, int pY, int pWidth, int pHeight, boolean anchorToBottom, String localAddress) {
super(pFont, pX, pY, pWidth, pHeight, Component.empty());
destinationSuggestions = AddressEditBoxHelper.createSuggestions(screen, this, anchorToBottom);
destinationSuggestions = AddressEditBoxHelper.createSuggestions(screen, this, anchorToBottom, localAddress);
destinationSuggestions.setAllowSuggestions(true);
destinationSuggestions.updateCommandInfo();
mainResponder = t -> {

View file

@ -38,7 +38,7 @@ public class AddressEditBoxHelper {
NEARBY_CLIPBOARDS.put(blockPos, new WeakReference<>(blockEntity));
}
public static DestinationSuggestions createSuggestions(Screen screen, EditBox pInput, boolean anchorToBottom) {
public static DestinationSuggestions createSuggestions(Screen screen, EditBox pInput, boolean anchorToBottom, String localAddress) {
Minecraft mc = Minecraft.getInstance();
Player player = mc.player;
List<IntAttached<String>> options = new ArrayList<>();
@ -50,6 +50,11 @@ public class AddressEditBoxHelper {
if (player == null)
return destinationSuggestions;
if (localAddress != null) {
options.add(IntAttached.with(-1, localAddress));
alreadyAdded.add(localAddress);
}
for (int i = 0; i < Inventory.INVENTORY_SIZE; i++)
appendAddresses(options, alreadyAdded, player.getInventory()
.getItem(i));

View file

@ -27,6 +27,7 @@ import com.simibubi.create.content.logistics.BigItemStack;
import com.simibubi.create.content.logistics.factoryBoard.FactoryPanelBlock.PanelSlot;
import com.simibubi.create.content.logistics.filter.FilterItem;
import com.simibubi.create.content.logistics.filter.FilterItemStack;
import com.simibubi.create.content.logistics.packagePort.frogport.FrogportBlockEntity;
import com.simibubi.create.content.logistics.packager.InventorySummary;
import com.simibubi.create.content.logistics.packager.PackagerBlockEntity;
import com.simibubi.create.content.logistics.packager.PackagingRequest;
@ -787,6 +788,7 @@ public class FactoryPanelBehaviour extends FilteringBehaviour implements MenuPro
CompoundTag panelTag = new CompoundTag();
super.write(panelTag, registries, clientPacket);
panelTag.putInt("Timer", timer);
panelTag.putInt("LastLevel", lastReportedLevelInStorage);
panelTag.putInt("LastPromised", lastReportedPromises);
panelTag.putInt("LastUnloadedLinks", lastReportedUnloadedLinks);
@ -821,6 +823,7 @@ public class FactoryPanelBehaviour extends FilteringBehaviour implements MenuPro
filter = FilterItemStack.of(registries, panelTag.getCompound("Filter"));
count = panelTag.getInt("FilterAmount");
upTo = panelTag.getBoolean("UpTo");
timer = panelTag.getInt("Timer");
lastReportedLevelInStorage = panelTag.getInt("LastLevel");
lastReportedPromises = panelTag.getInt("LastPromised");
lastReportedUnloadedLinks = panelTag.getInt("LastUnloadedLinks");
@ -1060,4 +1063,14 @@ public class FactoryPanelBehaviour extends FilteringBehaviour implements MenuPro
.getName();
}
public String getFrogAddress() {
PackagerBlockEntity packager = panelBE().getRestockedPackager();
if (packager == null)
return null;
if (packager.getLevel().getBlockEntity(packager.getBlockPos().above()) instanceof FrogportBlockEntity fpbe)
if (fpbe.addressFilter != null && !fpbe.addressFilter.isBlank())
return fpbe.addressFilter + "";
return null;
}
}

View file

@ -153,8 +153,8 @@ public class FactoryPanelScreen extends AbstractSimiScreen {
int y = guiTop;
if (addressBox == null) {
addressBox =
new AddressEditBox(this, new NoShadowFontWrapper(font), x + 36, y + windowHeight - 51, 108, 10, false);
String frogAddress = behaviour.getFrogAddress();
addressBox = new AddressEditBox(this, new NoShadowFontWrapper(font), x + 36, y + windowHeight - 51, 108, 10, false, frogAddress);
addressBox.setValue(behaviour.recipeAddress);
addressBox.setTextColor(0x555555);
}

View file

@ -151,7 +151,7 @@ public class AttributeFilterScreen extends AbstractFilterScreen<AttributeFilterM
.color(ScrollInput.HEADER_RGB.getRGB())
.component());
attributesOfItem.clear();
for (Map.Entry<ResourceKey<ItemAttributeType>, ItemAttributeType> entrySet : AllRegistries.ITEM_ATTRIBUTE_TYPES.entrySet())
for (Map.Entry<ResourceKey<ItemAttributeType>, ItemAttributeType> entrySet : AllRegistries.ITEM_ATTRIBUTE_TYPE.entrySet())
attributesOfItem.addAll(entrySet.getValue().getAllAttributes(stack, minecraft.level));
List<Component> options = attributesOfItem.stream()
.map(a -> a.format(false))

View file

@ -41,7 +41,7 @@ import net.neoforged.neoforge.registries.DeferredRegister;
// TODO - Documentation
public class AllItemAttributeTypes {
private static final DeferredRegister<ItemAttributeType> REGISTER = DeferredRegister.create(AllRegistries.ITEM_ATTRIBUTE_TYPES, Create.ID);
private static final DeferredRegister<ItemAttributeType> REGISTER = DeferredRegister.create(AllRegistries.ITEM_ATTRIBUTE_TYPE, Create.ID);
public static final ItemAttributeType
PLACEABLE = singleton("placeable", s -> s.getItem() instanceof BlockItem),

View file

@ -25,8 +25,8 @@ import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
public interface ItemAttribute {
Codec<ItemAttribute> CODEC = AllRegistries.ITEM_ATTRIBUTE_TYPES.byNameCodec().dispatch(ItemAttribute::getType, ItemAttributeType::codec);
StreamCodec<RegistryFriendlyByteBuf, ItemAttribute> STREAM_CODEC = ByteBufCodecs.registry(Keys.ITEM_ATTRIBUTE_TYPES).dispatch(ItemAttribute::getType, ItemAttributeType::streamCodec);
Codec<ItemAttribute> CODEC = AllRegistries.ITEM_ATTRIBUTE_TYPE.byNameCodec().dispatch(ItemAttribute::getType, ItemAttributeType::codec);
StreamCodec<RegistryFriendlyByteBuf, ItemAttribute> STREAM_CODEC = ByteBufCodecs.registry(Keys.ITEM_ATTRIBUTE_TYPE).dispatch(ItemAttribute::getType, ItemAttributeType::streamCodec);
static CompoundTag saveStatic(ItemAttribute attribute, HolderLookup.Provider registries) {
CompoundTag nbt = new CompoundTag();
@ -41,7 +41,7 @@ public interface ItemAttribute {
static List<ItemAttribute> getAllAttributes(ItemStack stack, Level level) {
List<ItemAttribute> attributes = new ArrayList<>();
for (ItemAttributeType type : AllRegistries.ITEM_ATTRIBUTE_TYPES) {
for (ItemAttributeType type : AllRegistries.ITEM_ATTRIBUTE_TYPE) {
attributes.addAll(type.getAllAttributes(stack, level));
}
return attributes;

View file

@ -9,6 +9,8 @@ import org.jetbrains.annotations.NotNull;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
@ -62,5 +64,10 @@ public final class SingletonItemAttribute implements ItemAttribute {
public MapCodec<? extends ItemAttribute> codec() {
return Codec.unit(attribute).fieldOf("value");
}
@Override
public StreamCodec<? super RegistryFriendlyByteBuf, ? extends ItemAttribute> streamCodec() {
return StreamCodec.unit(attribute);
}
}
}

View file

@ -1,10 +1,10 @@
package com.simibubi.create.content.logistics.packagePort;
import org.jetbrains.annotations.ApiStatus.Internal;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.Create;
import com.simibubi.create.content.logistics.packagePort.PackagePortTarget.ChainConveyorFrogportTarget;
import com.simibubi.create.content.logistics.packagePort.PackagePortTarget.TrainStationFrogportTarget;
import net.minecraft.core.Holder;
@ -12,10 +12,8 @@ import net.minecraft.core.Holder;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.jetbrains.annotations.ApiStatus.Internal;
public class AllPackagePortTargetTypes {
private static final DeferredRegister<PackagePortTargetType> REGISTER = DeferredRegister.create(AllRegistries.PACKAGE_PORT_TARGETS, Create.ID);
private static final DeferredRegister<PackagePortTargetType> REGISTER = DeferredRegister.create(AllRegistries.PACKAGE_PORT_TARGET, Create.ID);
public static final Holder<PackagePortTargetType> CHAIN_CONVEYOR = REGISTER.register("chain_conveyor", ChainConveyorFrogportTarget.Type::new);
public static final Holder<PackagePortTargetType> TRAIN_STATION = REGISTER.register("train_station", TrainStationFrogportTarget.Type::new);

View file

@ -31,8 +31,8 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.Vec3;
public abstract class PackagePortTarget {
public static final Codec<PackagePortTarget> CODEC = AllRegistries.PACKAGE_PORT_TARGETS.byNameCodec().dispatch(PackagePortTarget::getType, PackagePortTargetType::codec);
public static final StreamCodec<? super RegistryFriendlyByteBuf, PackagePortTarget> STREAM_CODEC = ByteBufCodecs.registry(Keys.PACKAGE_PORT_TARGETS).dispatch(PackagePortTarget::getType, PackagePortTargetType::streamCodec);
public static final Codec<PackagePortTarget> CODEC = AllRegistries.PACKAGE_PORT_TARGET.byNameCodec().dispatch(PackagePortTarget::getType, PackagePortTargetType::codec);
public static final StreamCodec<? super RegistryFriendlyByteBuf, PackagePortTarget> STREAM_CODEC = ByteBufCodecs.registry(Keys.PACKAGE_PORT_TARGET).dispatch(PackagePortTarget::getType, PackagePortTargetType::streamCodec);
public BlockPos relativePos;

View file

@ -267,7 +267,7 @@ public class PackagerBlockEntity extends SmartBlockEntity {
BlockState blockState = getBlockState();
if (!blockState.hasProperty(PackagerBlock.LINKED))
return;
boolean shouldBeLinked = shouldBeLinked();
boolean shouldBeLinked = getLinkPos() != null;
boolean isLinked = blockState.getValue(PackagerBlock.LINKED);
if (shouldBeLinked == isLinked)
return;
@ -279,16 +279,16 @@ public class PackagerBlockEntity extends SmartBlockEntity {
.orElse(false);
}
private boolean shouldBeLinked() {
private BlockPos getLinkPos() {
for (Direction d : Iterate.directions) {
BlockState adjacentState = level.getBlockState(worldPosition.relative(d));
if (!AllBlocks.STOCK_LINK.has(adjacentState))
continue;
if (PackagerLinkBlock.getConnectedDirection(adjacentState) != d)
continue;
return true;
return worldPosition.relative(d);
}
return false;
return null;
}
public void flashLink() {
@ -551,6 +551,11 @@ public class PackagerBlockEntity extends SmartBlockEntity {
if (!requestQueue && !signBasedAddress.isBlank())
PackageItem.addAddress(createdBox, signBasedAddress);
BlockPos linkPos = getLinkPos();
if (extractedPackageItem.isEmpty() && linkPos != null
&& level.getBlockEntity(linkPos) instanceof PackagerLinkBlockEntity plbe)
plbe.behaviour.deductFromAccurateSummary(extractedItems);
if (!heldBox.isEmpty() || animationTicks != 0) {
queuedExitingPackages.add(createdBox);
return;

View file

@ -11,6 +11,8 @@ import java.util.stream.Stream;
import javax.annotation.Nullable;
import net.neoforged.neoforge.items.ItemStackHandler;
import org.apache.commons.lang3.mutable.MutableBoolean;
import com.google.common.cache.Cache;
@ -187,6 +189,18 @@ public class LogisticallyLinkedBehaviour extends BlockEntityBehaviour {
return InventorySummary.EMPTY;
}
public void deductFromAccurateSummary(ItemStackHandler packageContents) {
InventorySummary summary = LogisticsManager.ACCURATE_SUMMARIES.getIfPresent(freqId);
if (summary == null)
return;
for (int i = 0; i < packageContents.getSlots(); i++) {
ItemStack orderedStack = packageContents.getStackInSlot(i);
if (orderedStack.isEmpty())
continue;
summary.add(orderedStack, -Math.min(summary.getCountOf(orderedStack), orderedStack.getCount()));
}
}
//
public boolean mayInteract(Player player) {