46
46
import net .minecraft .world .level .dimension .DimensionType ;
47
47
import net .minecraft .world .level .storage .LevelData ;
48
48
import net .minecraft .world .level .storage .WritableLevelData ;
49
+ import net .minecraft .world .phys .AABB ;
49
50
import org .checkerframework .checker .nullness .qual .NonNull ;
50
51
import org .checkerframework .checker .nullness .qual .Nullable ;
51
52
import org .spongepowered .api .ResourceKey ;
59
60
import org .spongepowered .asm .mixin .Mixin ;
60
61
import org .spongepowered .asm .mixin .Mutable ;
61
62
import org .spongepowered .asm .mixin .Shadow ;
63
+ import org .spongepowered .asm .mixin .injection .At ;
64
+ import org .spongepowered .asm .mixin .injection .Coerce ;
65
+ import org .spongepowered .asm .mixin .injection .Inject ;
66
+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
62
67
import org .spongepowered .common .SpongeCommon ;
63
68
import org .spongepowered .common .accessor .world .entity .MobAccessor ;
64
69
import org .spongepowered .common .accessor .world .entity .item .FallingBlockEntityAccessor ;
70
+ import org .spongepowered .common .bridge .data .VanishableBridge ;
65
71
import org .spongepowered .common .bridge .world .level .LevelBridge ;
66
72
import org .spongepowered .common .data .persistence .NBTTranslator ;
67
73
import org .spongepowered .common .entity .projectile .UnknownProjectileSource ;
75
81
@ Mixin (net .minecraft .world .level .Level .class )
76
82
public abstract class LevelMixin implements LevelBridge , LevelAccessor {
77
83
78
- // @formatter: off
84
+ //@formatter: off
79
85
@ Mutable @ Shadow @ Final private net .minecraft .resources .ResourceKey <DimensionType > dimensionTypeId ;
80
86
@ Mutable @ Shadow @ Final private Holder <DimensionType > dimensionTypeRegistration ;
81
87
@ Shadow protected float oRainLevel ;
@@ -96,9 +102,7 @@ public abstract class LevelMixin implements LevelBridge, LevelAccessor {
96
102
@ Shadow public abstract net .minecraft .world .level .block .entity .@ Nullable BlockEntity shadow$getBlockEntity (BlockPos p_175625_1_ );
97
103
@ Shadow public abstract WorldBorder shadow$getWorldBorder ();
98
104
//@Shadow protected abstract void shadow$postGameEventInRadius(@javax.annotation.Nullable net.minecraft.world.entity.Entity $$0, GameEvent $$1, BlockPos $$2, int $$3);
99
- // @formatter on
100
-
101
-
105
+ //@formatter on
102
106
103
107
104
108
@ Override
@@ -115,13 +119,14 @@ public abstract class LevelMixin implements LevelBridge, LevelAccessor {
115
119
}
116
120
117
121
@ SuppressWarnings ("unchecked" )
122
+ @ Override
118
123
public <E extends org .spongepowered .api .entity .Entity > E bridge$createEntity (
119
- final DataContainer dataContainer ,
120
- final @ Nullable Vector3d position ,
121
- final @ Nullable Predicate <Vector3d > positionCheck ) throws IllegalArgumentException , IllegalStateException {
124
+ final DataContainer dataContainer ,
125
+ final @ Nullable Vector3d position ,
126
+ final @ Nullable Predicate <Vector3d > positionCheck ) throws IllegalArgumentException , IllegalStateException {
122
127
123
128
final EntityType <@ NonNull ?> type = dataContainer .getRegistryValue (Constants .Entity .TYPE , RegistryTypes .ENTITY_TYPE )
124
- .orElseThrow (() -> new IllegalArgumentException ("DataContainer does not contain a valid entity type." ));
129
+ .orElseThrow (() -> new IllegalArgumentException ("DataContainer does not contain a valid entity type." ));
125
130
final Vector3d proposedPosition ;
126
131
if (position == null ) {
127
132
proposedPosition = DataUtil .getPosition3d (dataContainer , Constants .Sponge .SNAPSHOT_WORLD_POSITION );
@@ -131,9 +136,9 @@ public abstract class LevelMixin implements LevelBridge, LevelAccessor {
131
136
132
137
if (positionCheck != null && !positionCheck .test (proposedPosition )) {
133
138
throw new IllegalArgumentException (String .format ("Position (%.2f, %.2f, %.2f) is not a valid position in this context." ,
134
- proposedPosition .x (),
135
- proposedPosition .y (),
136
- proposedPosition .z ()));
139
+ proposedPosition .x (),
140
+ proposedPosition .y (),
141
+ proposedPosition .z ()));
137
142
}
138
143
139
144
final @ Nullable Vector3d rotation ;
@@ -152,15 +157,15 @@ public abstract class LevelMixin implements LevelBridge, LevelAccessor {
152
157
153
158
final Entity createdEntity = this .bridge$createEntity (type , position , false );
154
159
dataContainer .getView (Constants .Sponge .UNSAFE_NBT )
155
- .map (NBTTranslator .INSTANCE ::translate )
156
- .ifPresent (x -> {
157
- final net .minecraft .world .entity .Entity e = ((net .minecraft .world .entity .Entity ) createdEntity );
158
- // mimicing Entity#restoreFrom
159
- x .remove ("Dimension" );
160
- e .load (x );
161
- // position needs a reset
162
- e .moveTo (proposedPosition .x (), proposedPosition .y (), proposedPosition .z ());
163
- });
160
+ .map (NBTTranslator .INSTANCE ::translate )
161
+ .ifPresent (x -> {
162
+ final net .minecraft .world .entity .Entity e = ((net .minecraft .world .entity .Entity ) createdEntity );
163
+ // mimicing Entity#restoreFrom
164
+ x .remove ("Dimension" );
165
+ e .load (x );
166
+ // position needs a reset
167
+ e .moveTo (proposedPosition .x (), proposedPosition .y (), proposedPosition .z ());
168
+ });
164
169
if (rotation != null ) {
165
170
createdEntity .setRotation (rotation );
166
171
}
@@ -227,7 +232,7 @@ public abstract class LevelMixin implements LevelBridge, LevelAccessor {
227
232
if (naturally && entity instanceof Mob ) {
228
233
// Adding the default equipment
229
234
final DifficultyInstance difficulty = this .shadow$getCurrentDifficultyAt (new BlockPos ((int ) x , (int ) y , (int ) z ));
230
- ((MobAccessor )entity ).invoker$populateDefaultEquipmentSlots (this .random , difficulty );
235
+ ((MobAccessor ) entity ).invoker$populateDefaultEquipmentSlots (this .random , difficulty );
231
236
}
232
237
233
238
if (entity instanceof Painting ) {
@@ -238,4 +243,29 @@ public abstract class LevelMixin implements LevelBridge, LevelAccessor {
238
243
239
244
return (E ) entity ;
240
245
}
246
+
247
+ @ Inject (method = {
248
+ "getEntities(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;" ,
249
+ "getEntities(Lnet/minecraft/world/level/entity/EntityTypeTest;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;" ,
250
+ }, at = @ At ("RETURN" ))
251
+ private void impl$IgnoreTargetingOfVanishedEntities (
252
+ final @ Coerce Object entityIn , final AABB aabb ,
253
+ final Predicate <?> filter , final CallbackInfoReturnable <List <net .minecraft .world .entity .Entity >> cir
254
+ ) {
255
+ if (this .bridge$isFake ()) {
256
+ return ;
257
+ }
258
+ final List <net .minecraft .world .entity .Entity > entities = cir .getReturnValue ();
259
+ if (entities == null || entities .isEmpty ()) {
260
+ return ;
261
+ }
262
+ entities .removeIf (entity -> {
263
+ if (entity instanceof VanishableBridge vb ) {
264
+ final var state = vb .bridge$vanishState ();
265
+ return state .invisible () && state .untargetable ();
266
+ }
267
+ return false ;
268
+ });
269
+ }
270
+
241
271
}
0 commit comments