42
42
43
43
import de .dustplanet .silkspawners .compat .api .NMSProvider ;
44
44
import net .minecraft .core .Registry ;
45
+ import net .minecraft .core .component .DataComponentMap ;
45
46
import net .minecraft .core .component .DataComponents ;
46
47
import net .minecraft .core .registries .BuiltInRegistries ;
47
48
import net .minecraft .nbt .CompoundTag ;
@@ -174,17 +175,21 @@ public void setSpawnersUnstackable() {
174
175
final ResourceLocation resourceLocation = new ResourceLocation (NAMESPACED_SPAWNER_ID );
175
176
final Registry <Item > itemRegistry = BuiltInRegistries .ITEM ;
176
177
final Item spawner = itemRegistry .get (resourceLocation );
178
+ final DataComponentMap currentComponents = spawner .components ();
179
+ final DataComponentMap updatedComponents = DataComponentMap .composite (currentComponents ,
180
+ DataComponentMap .builder ().set (DataComponents .MAX_STACK_SIZE , 1 ).build ());
177
181
try {
178
- final Field maxStackSize = Item .class .getDeclaredField ("maxStackSize" );
179
- maxStackSize .setAccessible (true );
180
- maxStackSize .set (spawner , 1 );
182
+
183
+ final Field components = Item .class .getDeclaredField ("components" );
184
+ components .setAccessible (true );
185
+ components .set (spawner , updatedComponents );
181
186
} catch (@ SuppressWarnings ("unused" ) NoSuchFieldException | SecurityException | IllegalArgumentException
182
187
| IllegalAccessException e ) {
183
188
try {
184
- // int maxStackSize -> d
185
- final Field maxStackSize = Item .class .getDeclaredField ("d " );
186
- maxStackSize .setAccessible (true );
187
- maxStackSize .set (spawner , 1 );
189
+ // DataComponentMap components -> c
190
+ final Field components = Item .class .getDeclaredField ("c " );
191
+ components .setAccessible (true );
192
+ components .set (spawner , updatedComponents );
188
193
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e1 ) {
189
194
e1 .printStackTrace ();
190
195
}
@@ -232,8 +237,8 @@ public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
232
237
itemStack = CraftItemStack .asNMSCopy (craftStack );
233
238
final CustomData blockData = itemStack .getOrDefault (DataComponents .BLOCK_ENTITY_DATA , CustomData .EMPTY );
234
239
final CustomData customData = itemStack .getOrDefault (DataComponents .CUSTOM_DATA , CustomData .EMPTY );
235
- CompoundTag tag = blockData .copyTag ();
236
- CompoundTag customTag = customData .copyTag ();
240
+ final CompoundTag tag = blockData .copyTag ();
241
+ final CompoundTag customTag = customData .copyTag ();
237
242
238
243
// Check for SilkSpawners key
239
244
if (!customTag .contains ("SilkSpawners" )) {
@@ -294,7 +299,7 @@ public String getVanillaNBTEntityID(final ItemStack item) {
294
299
final CraftItemStack craftStack = CraftItemStack .asCraftCopy (item );
295
300
itemStack = CraftItemStack .asNMSCopy (craftStack );
296
301
final CustomData blockEntityData = itemStack .getOrDefault (DataComponents .BLOCK_ENTITY_DATA , CustomData .EMPTY );
297
- CompoundTag tag = blockEntityData .copyTag ();
302
+ final CompoundTag tag = blockEntityData .copyTag ();
298
303
299
304
if (tag .contains ("EntityId" )) {
300
305
return tag .getString ("EntityId" );
@@ -313,7 +318,7 @@ public String getVanillaNBTEntityID(final ItemStack item) {
313
318
/**
314
319
* Return the spawner block the player is looking at, or null if isn't.
315
320
*
316
- * @param player the player
321
+ * @param player the player
317
322
* @param distance the reach distance
318
323
* @return the found block or null
319
324
*/
@@ -345,8 +350,8 @@ public ItemStack newEggItem(final String entityID, final int amount, final Strin
345
350
itemStack = CraftItemStack .asNMSCopy (craftStack );
346
351
final CustomData blockData = itemStack .getOrDefault (DataComponents .ENTITY_DATA , CustomData .EMPTY );
347
352
final CustomData customData = itemStack .getOrDefault (DataComponents .CUSTOM_DATA , CustomData .EMPTY );
348
- CompoundTag tag = blockData .copyTag ();
349
- CompoundTag customTag = customData .copyTag ();
353
+ final CompoundTag tag = blockData .copyTag ();
354
+ final CompoundTag customTag = customData .copyTag ();
350
355
351
356
if (!customTag .contains ("SilkSpawners" )) {
352
357
customTag .put ("SilkSpawners" , new CompoundTag ());
@@ -373,7 +378,7 @@ public String getVanillaEggNBTEntityID(final ItemStack item) {
373
378
final CraftItemStack craftStack = CraftItemStack .asCraftCopy (item );
374
379
itemStack = CraftItemStack .asNMSCopy (craftStack );
375
380
final CustomData blockEntityData = itemStack .getOrDefault (DataComponents .ENTITY_DATA , CustomData .EMPTY );
376
- CompoundTag tag = blockEntityData .copyTag ();
381
+ final CompoundTag tag = blockEntityData .copyTag ();
377
382
378
383
if (tag .contains ("id" )) {
379
384
return tag .getString ("id" ).replace ("minecraft:" , "" );
0 commit comments