Skip to content

Commit

Permalink
Update to store empty sets until some flag is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
ApexModder committed Sep 7, 2024
1 parent 9b12643 commit de4e095
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 32 deletions.
9 changes: 6 additions & 3 deletions patches/net/minecraft/world/effect/MobEffect.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
private int blendDurationTicks;
private Optional<SoundEvent> soundOnAdded = Optional.empty();
private FeatureFlagSet requiredFeatures = FeatureFlags.VANILLA_SET;
+ private it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+ private it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet();

protected MobEffect(MobEffectCategory p_19451_, int p_19452_) {
this.category = p_19451_;
Expand Down Expand Up @@ -47,19 +47,22 @@
public MobEffect requiredFeatures(FeatureFlag... p_338702_) {
this.requiredFeatures = FeatureFlags.REGISTRY.subset(p_338702_);
return this;
@@ -181,8 +_,34 @@
@@ -181,8 +_,37 @@
return this.requiredFeatures;
}

- static record AttributeTemplate(ResourceLocation id, double amount, AttributeModifier.Operation operation) {
+ public MobEffect requiredFlags(net.neoforged.neoforge.flag.Flag... requiredFlags) {
+ if(this.requiredFlags.isEmpty())
+ this.requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+
+ java.util.Collections.addAll(this.requiredFlags, requiredFlags);
+ return this;
+ }
+
+ @Override
+ public it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags() {
+ return it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(requiredFlags);
+ return requiredFlags.isEmpty() ? it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet() : it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(requiredFlags);
+ }
+
+ /**
Expand Down
9 changes: 6 additions & 3 deletions patches/net/minecraft/world/entity/EntityType.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
+ this.trackDeltasSupplier = trackDeltasSupplier;
+ this.trackingRangeSupplier = trackingRangeSupplier;
+ this.updateIntervalSupplier = updateIntervalSupplier;
+ this.requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(requiredFlags);
+ this.requiredFlags = requiredFlags.isEmpty() ? it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet() : it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(requiredFlags);
}

@Nullable
Expand Down Expand Up @@ -134,12 +134,12 @@
+ private java.util.function.Predicate<EntityType<?>> velocityUpdateSupplier = EntityType::defaultTrackDeltasSupplier;
+ private java.util.function.ToIntFunction<EntityType<?>> trackingRangeSupplier = EntityType::defaultTrackingRangeSupplier;
+ private java.util.function.ToIntFunction<EntityType<?>> updateIntervalSupplier = EntityType::defaultUpdateIntervalSupplier;
+ private final it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+ private it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet();
+
private Builder(EntityType.EntityFactory<T> p_20696_, MobCategory p_20697_) {
this.factory = p_20696_;
this.category = p_20697_;
@@ -1309,11 +_,35 @@
@@ -1309,11 +_,38 @@
return this;
}

Expand All @@ -153,6 +153,9 @@
}

+ public EntityType.Builder<T> requiredFlags(net.neoforged.neoforge.flag.Flag... requiredFlags) {
+ if(this.requiredFlags.isEmpty())
+ this.requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+
+ java.util.Collections.addAll(this.requiredFlags, requiredFlags);
+ return this;
+ }
Expand Down
12 changes: 6 additions & 6 deletions patches/net/minecraft/world/inventory/MenuType.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

private static <T extends AbstractContainerMenu> MenuType<T> register(String p_39989_, MenuType.MenuSupplier<T> p_39990_) {
return Registry.register(BuiltInRegistries.MENU, p_39989_, new MenuType<>(p_39990_, FeatureFlags.VANILLA_SET));
@@ -46,8 +_,13 @@
}

@@ -48,6 +_,13 @@
public MenuType(MenuType.MenuSupplier<T> p_267054_, FeatureFlagSet p_266909_) {
+ this(p_267054_, p_266909_, new net.neoforged.neoforge.flag.Flag[0]);
this.constructor = p_267054_;
this.requiredFeatures = p_266909_;
+ this.requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet();
+ }
+
+ public MenuType(MenuType.MenuSupplier<T> p_267054_, FeatureFlagSet p_266909_, net.neoforged.neoforge.flag.Flag[] requiredFlags) {
this.constructor = p_267054_;
this.requiredFeatures = p_266909_;
+ this.constructor = p_267054_;
+ this.requiredFeatures = p_266909_;
+ this.requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSet.of(requiredFlags);
}

Expand Down
9 changes: 6 additions & 3 deletions patches/net/minecraft/world/item/Item.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
this.craftingRemainingItem = p_41383_.craftingRemainingItem;
this.requiredFeatures = p_41383_.requiredFeatures;
- if (SharedConstants.IS_RUNNING_IN_IDE) {
+ this.requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(p_41383_.requiredFlags);
+ this.requiredFlags = p_41383_.requiredFlags.isEmpty() ? it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet() : it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(p_41383_.requiredFlags);
+ if (SharedConstants.IS_RUNNING_IN_IDE && false) {
String s = this.getClass().getSimpleName();
if (!s.endsWith("Item")) {
Expand Down Expand Up @@ -177,11 +177,11 @@
Item craftingRemainingItem;
FeatureFlagSet requiredFeatures = FeatureFlags.VANILLA_SET;
+ private boolean canRepair = true;
+ private final it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+ private it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet();

public Item.Properties food(FoodProperties p_41490_) {
return this.component(DataComponents.FOOD, p_41490_);
@@ -381,12 +_,27 @@
@@ -381,12 +_,30 @@
return this.component(DataComponents.JUKEBOX_PLAYABLE, new JukeboxPlayable(new EitherHolder<>(p_350862_), true));
}

Expand All @@ -200,6 +200,9 @@
}

+ public Item.Properties requiredFlags(net.neoforged.neoforge.flag.Flag... requiredFlags) {
+ if(this.requiredFlags.isEmpty())
+ this.requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+
+ java.util.Collections.addAll(this.requiredFlags, requiredFlags);
+ return this;
+ }
Expand Down
9 changes: 6 additions & 3 deletions patches/net/minecraft/world/item/alchemy/Potion.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
private final String name;
private final List<MobEffectInstance> effects;
private FeatureFlagSet requiredFeatures = FeatureFlags.VANILLA_SET;
+ private it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+ private it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet();

public Potion(MobEffectInstance... p_43487_) {
this(null, p_43487_);
Expand All @@ -19,20 +19,23 @@
public Potion requiredFeatures(FeatureFlag... p_338520_) {
this.requiredFeatures = FeatureFlags.REGISTRY.subset(p_338520_);
return this;
@@ -42,6 +_,16 @@
@@ -42,6 +_,19 @@
@Override
public FeatureFlagSet requiredFeatures() {
return this.requiredFeatures;
+ }
+
+ public Potion requiredFlags(net.neoforged.neoforge.flag.Flag... requiredFlags) {
+ if(this.requiredFlags.isEmpty())
+ this.requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+
+ java.util.Collections.addAll(this.requiredFlags, requiredFlags);
+ return this;
+ }
+
+ @Override
+ public it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags() {
+ return it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(requiredFlags);
+ return requiredFlags.isEmpty() ? it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet() : it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(requiredFlags);
}

public static String getName(Optional<Holder<Potion>> p_330503_, String p_43493_) {
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
@@ -98,6 +_,7 @@
protected final BlockBehaviour.Properties properties;
@Nullable
protected ResourceKey<LootTable> drops;
+ protected final it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags;

public BlockBehaviour(BlockBehaviour.Properties p_60452_) {
this.hasCollision = p_60452_.hasCollision;
@@ -110,7 +_,19 @@
this.jumpFactor = p_60452_.jumpFactor;
this.dynamicShape = p_60452_.dynamicShape;
this.requiredFeatures = p_60452_.requiredFeatures;
+ this.requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(p_60452_.requiredFlags);
+ p_60452_.requiredFlags = p_60452_.requiredFlags.isEmpty() ? it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet() : it.unimi.dsi.fastutil.objects.ReferenceSets.unmodifiable(p_60452_.requiredFlags);
this.properties = p_60452_;
+ final ResourceKey<LootTable> lootTableCache = p_60452_.drops;
+ if (lootTableCache != null) {
Expand Down Expand Up @@ -86,7 +78,7 @@
+
+ @Override
+ public final it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags() {
+ return requiredFlags;
+ return properties.requiredFlags;
+ }
+
+ // Neo: Holds the loot table for this block's drops. Used for getLootTable method.
Expand Down Expand Up @@ -169,14 +161,15 @@
FeatureFlagSet requiredFeatures = FeatureFlags.VANILLA_SET;
@Nullable
BlockBehaviour.OffsetFunction offsetFunction;
+ private final it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+ private it.unimi.dsi.fastutil.objects.ReferenceSet<net.neoforged.neoforge.flag.Flag> requiredFlags = it.unimi.dsi.fastutil.objects.ReferenceSets.emptySet();

private Properties() {
}
@@ -1020,6 +_,7 @@
@@ -1020,6 +_,8 @@
blockbehaviour$properties.offsetFunction = blockbehaviour$properties1.offsetFunction;
blockbehaviour$properties.spawnTerrainParticles = blockbehaviour$properties1.spawnTerrainParticles;
blockbehaviour$properties.requiredFeatures = blockbehaviour$properties1.requiredFeatures;
+ blockbehaviour$properties.requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+ blockbehaviour$properties.requiredFlags.addAll(blockbehaviour$properties1.requiredFlags);
blockbehaviour$properties.emissiveRendering = blockbehaviour$properties1.emissiveRendering;
blockbehaviour$properties.instrument = blockbehaviour$properties1.instrument;
Expand All @@ -198,7 +191,7 @@
}

public BlockBehaviour.Properties ignitedByLava() {
@@ -1215,8 +_,17 @@
@@ -1215,8 +_,20 @@
return this;
}

Expand All @@ -212,6 +205,9 @@
+ }
+
+ public BlockBehaviour.Properties requiredFlags(net.neoforged.neoforge.flag.Flag... requiredFlags) {
+ if(this.requiredFlags.isEmpty())
+ this.requiredFlags = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
+
+ java.util.Collections.addAll(this.requiredFlags, requiredFlags);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static <T extends AbstractContainerMenu> MenuType<T> create(IContainerFactory<T>
}

static <T extends AbstractContainerMenu> MenuType<T> create(IContainerFactory<T> factory) {
return create(factory, new Flag[0]);
return new MenuType<>(factory, FeatureFlags.DEFAULT_FLAGS);
}

T create(int windowId, Inventory playerInv, RegistryFriendlyByteBuf extraData);
Expand Down

0 comments on commit de4e095

Please sign in to comment.