diff --git a/patches/net/minecraft/world/entity/EntityType.java.patch b/patches/net/minecraft/world/entity/EntityType.java.patch index 8f8b38efa5..72c56c0522 100644 --- a/patches/net/minecraft/world/entity/EntityType.java.patch +++ b/patches/net/minecraft/world/entity/EntityType.java.patch @@ -1,21 +1,22 @@ --- a/net/minecraft/world/entity/EntityType.java +++ b/net/minecraft/world/entity/EntityType.java -@@ -1070,6 +_,10 @@ +@@ -1070,6 +_,11 @@ private final float spawnDimensionsScale; private final FeatureFlagSet requiredFeatures; + private final java.util.function.Predicate> trackDeltasSupplier; + private final java.util.function.ToIntFunction> trackingRangeSupplier; + private final java.util.function.ToIntFunction> updateIntervalSupplier; ++ private final boolean onlyOpCanSetNbt; + private static EntityType register(ResourceKey> p_368669_, EntityType.Builder p_368714_) { return Registry.register(BuiltInRegistries.ENTITY_TYPE, p_368669_, p_368714_.build(p_368669_)); } -@@ -1106,6 +_,28 @@ +@@ -1106,6 +_,29 @@ Optional> p_368696_, FeatureFlagSet p_273518_ ) { -+ this(p_273268_, p_272918_, p_273417_, p_273389_, p_273556_, p_272654_, p_273631_, p_272946_, p_338404_, p_272895_, p_273451_, p_368582_, p_368696_, p_273518_, EntityType::defaultTrackDeltasSupplier, EntityType::defaultTrackingRangeSupplier, EntityType::defaultUpdateIntervalSupplier); ++ this(p_273268_, p_272918_, p_273417_, p_273389_, p_273556_, p_272654_, p_273631_, p_272946_, p_338404_, p_272895_, p_273451_, p_368582_, p_368696_, p_273518_, EntityType::defaultTrackDeltasSupplier, EntityType::defaultTrackingRangeSupplier, EntityType::defaultUpdateIntervalSupplier, false); + } + + public EntityType( @@ -35,18 +36,20 @@ + FeatureFlagSet p_273518_, + final java.util.function.Predicate> trackDeltasSupplier, + final java.util.function.ToIntFunction> trackingRangeSupplier, -+ final java.util.function.ToIntFunction> updateIntervalSupplier ++ final java.util.function.ToIntFunction> updateIntervalSupplier, ++ boolean onlyOpCanSetNbt + ) { this.factory = p_273268_; this.category = p_272918_; this.canSpawnFarFromPlayer = p_272654_; -@@ -1120,6 +_,9 @@ +@@ -1120,6 +_,10 @@ this.descriptionId = p_368582_; this.lootTable = p_368696_; this.requiredFeatures = p_273518_; + this.trackDeltasSupplier = trackDeltasSupplier; + this.trackingRangeSupplier = trackingRangeSupplier; + this.updateIntervalSupplier = updateIntervalSupplier; ++ this.onlyOpCanSetNbt = onlyOpCanSetNbt; } @Nullable @@ -88,7 +91,11 @@ return this != PLAYER && this != LLAMA_SPIT && this != WITHER -@@ -1462,6 +_,8 @@ +@@ -1459,9 +_,12 @@ + } + + public boolean onlyOpCanSetNbt() { ++ if (onlyOpCanSetNbt) return true; return OP_ONLY_CUSTOM_DATA.contains(this); } @@ -97,18 +104,19 @@ public static class Builder { private final EntityType.EntityFactory factory; private final MobCategory category; -@@ -1481,6 +_,10 @@ +@@ -1481,6 +_,11 @@ ); private DependantName, String> descriptionId = p_367918_ -> Util.makeDescriptionId("entity", p_367918_.location()); + private java.util.function.Predicate> velocityUpdateSupplier = EntityType::defaultTrackDeltasSupplier; + private java.util.function.ToIntFunction> trackingRangeSupplier = EntityType::defaultTrackingRangeSupplier; + private java.util.function.ToIntFunction> updateIntervalSupplier = EntityType::defaultUpdateIntervalSupplier; ++ private boolean onlyOpCanSetNbt = false; + private Builder(EntityType.EntityFactory p_20696_, MobCategory p_20697_) { this.factory = p_20696_; this.category = p_20697_; -@@ -1593,6 +_,21 @@ +@@ -1593,6 +_,26 @@ return this; } @@ -126,19 +134,25 @@ + this.velocityUpdateSupplier = t->value; + return this; + } ++ ++ public EntityType.Builder setOnlyOpCanSetNbt(boolean onlyOpCanSetNbt) { ++ this.onlyOpCanSetNbt = onlyOpCanSetNbt; ++ return this; ++ } + public EntityType build(ResourceKey> p_368626_) { if (this.serialize) { Util.fetchChoiceType(References.ENTITY_TREE, p_368626_.location().toString()); -@@ -1612,7 +_,10 @@ +@@ -1612,7 +_,11 @@ this.updateInterval, this.descriptionId.get(p_368626_), this.lootTable.get(p_368626_), - this.requiredFeatures + this.requiredFeatures, -+ velocityUpdateSupplier, -+ trackingRangeSupplier, -+ updateIntervalSupplier ++ this.velocityUpdateSupplier, ++ this.trackingRangeSupplier, ++ this.updateIntervalSupplier, ++ this.onlyOpCanSetNbt ); } } diff --git a/patches/net/minecraft/world/level/block/entity/BlockEntityType.java.patch b/patches/net/minecraft/world/level/block/entity/BlockEntityType.java.patch index 87245aa63a..a9309b96e9 100644 --- a/patches/net/minecraft/world/level/block/entity/BlockEntityType.java.patch +++ b/patches/net/minecraft/world/level/block/entity/BlockEntityType.java.patch @@ -1,35 +1,63 @@ --- a/net/minecraft/world/level/block/entity/BlockEntityType.java +++ b/net/minecraft/world/level/block/entity/BlockEntityType.java -@@ -230,6 +_,7 @@ +@@ -230,8 +_,11 @@ public static final BlockEntityType VAULT = register("vault", VaultBlockEntity::new, Blocks.VAULT); private static final Set> OP_ONLY_CUSTOM_DATA = Set.of(COMMAND_BLOCK, LECTERN, SIGN, HANGING_SIGN, MOB_SPAWNER, TRIAL_SPAWNER); private final BlockEntityType.BlockEntitySupplier factory; + // Neo: This field will be modified by BlockEntityTypeAddBlocksEvent event. Please use the event to add to this field for vanilla or other mod's BlockEntityTypes. private final Set validBlocks; private final Holder.Reference> builtInRegistryHolder = BuiltInRegistries.BLOCK_ENTITY_TYPE.createIntrusiveHolder(this); ++ // Neo: Allow modded BE types to declare that they have NBT data only OPs can set ++ private final boolean onlyOpCanSetNbt; -@@ -254,9 +_,24 @@ - this.validBlocks = p_155260_; + @Nullable + public static ResourceLocation getKey(BlockEntityType p_58955_) { +@@ -250,8 +_,26 @@ } + public BlockEntityType(BlockEntityType.BlockEntitySupplier p_155259_, Set p_155260_) { ++ this(p_155259_, p_155260_, false); ++ } ++ ++ public BlockEntityType(BlockEntityType.BlockEntitySupplier p_155259_, Set p_155260_, boolean onlyOpCanSetNbt) { + this.factory = p_155259_; + this.validBlocks = p_155260_; ++ this.onlyOpCanSetNbt = onlyOpCanSetNbt; ++ } ++ + // Neo: Additional constructor for convenience. + public BlockEntityType(BlockEntityType.BlockEntitySupplier p_155259_, Block... p_155260_) { -+ this(p_155259_, Set.of(p_155260_)); ++ this(p_155259_, false, p_155260_); ++ } ++ ++ // Neo: Additional constructor for convenience. ++ public BlockEntityType(BlockEntityType.BlockEntitySupplier p_155259_, boolean onlyOpCanSetNbt, Block... p_155260_) { ++ this(p_155259_, Set.of(p_155260_), onlyOpCanSetNbt); + if (p_155260_.length == 0) { + throw new IllegalArgumentException("Block entity type instantiated without valid blocks. If this is intentional, pass Set.of() instead of an empty varag."); + } -+ } -+ + } + @Nullable - public T create(BlockPos p_155265_, BlockState p_155266_) { +@@ -259,6 +_,13 @@ return (T)this.factory.create(p_155265_, p_155266_); -+ } -+ + } + + /** + * Neo: Add getter for an immutable view of the set of valid blocks. + */ + public Set getValidBlocks() { + return java.util.Collections.unmodifiableSet(this.validBlocks); ++ } ++ + public boolean isValid(BlockState p_155263_) { + return this.validBlocks.contains(p_155263_.getBlock()); + } +@@ -275,6 +_,7 @@ + } + + public boolean onlyOpCanSetNbt() { ++ if (onlyOpCanSetNbt) return true; + return OP_ONLY_CUSTOM_DATA.contains(this); } - public boolean isValid(BlockState p_155263_) {