[SPIGOT-7201] Spawner ItemMeta not working as expected Created: 10/Dec/22 Updated: 25/Dec/24 Resolved: 10/Dec/22 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Jonathan Boisclair | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | 1.19.3, Spawner, bug, spigot | ||
Environment: |
Linux Mint 20.3, Java 17 OpenJDK |
Version: | 3617-Spigot-d90018e-4fa7e1c (MC: 1.19.3) |
Plugin: | ObsidianMaterial |
Guidelines Read: | Yes |
Description |
Both .getSpawnedType() and .setSpawnedType() throws exceptions
Java code throwing the exception: @Override public ItemStack toItem() { ItemStack itemStack = new ItemStack(Material.SPAWNER); ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta == null) return itemStack; if (!(itemMeta instanceof BlockStateMeta)) return itemStack; BlockStateMeta blockStateMeta = (BlockStateMeta) itemMeta; CreatureSpawner creatureSpawner = (CreatureSpawner) blockStateMeta.getBlockState(); try { creatureSpawner.setSpawnedType(entity); } catch (Throwable t) { t.printStackTrace(); } blockStateMeta.setDisplayName(creatureSpawner.getSpawnedType()+" Spawner"); blockStateMeta.setBlockState(creatureSpawner); itemStack.setItemMeta(itemMeta); return itemStack; } Stack trace for it: java.lang.NullPointerException: Cannot invoke "net.minecraft.world.level.MobSpawnerData.a()" because "net.minecraft.world.level.block.entity.TileEntityMobSpawner.d().f" is null |
Comments |
Comment by FreeSoccerHDX [ 10/Dec/22 ] |
Its not working because you create a new ItemStack, get the ItemMeta of it ... but there is no MobSpawner as reference set... it probably just creates a dummy with no information and thats why |