|
25 | 25 |
|
26 | 26 | package de.derfrzocker.custom.ore.generator.impl.v1_14_R1.customdata;
|
27 | 27 |
|
28 |
| -import com.github.codedoctorde.itemmods.ItemMods; |
29 |
| -import com.github.codedoctorde.itemmods.config.ArmorStandBlockConfig; |
30 |
| -import com.github.codedoctorde.itemmods.config.BlockConfig; |
31 |
| -import com.mojang.brigadier.exceptions.CommandSyntaxException; |
32 | 28 | import de.derfrzocker.custom.ore.generator.api.OreConfig;
|
33 | 29 | import de.derfrzocker.custom.ore.generator.api.customdata.CustomData;
|
34 | 30 | import de.derfrzocker.custom.ore.generator.api.customdata.CustomDataApplier;
|
| 31 | +import dev.linwood.itemmods.ItemMods; |
| 32 | +import dev.linwood.itemmods.pack.PackObject; |
| 33 | +import dev.linwood.itemmods.pack.asset.BlockAsset; |
| 34 | +import dev.linwood.itemmods.pack.asset.raw.ModelAsset; |
35 | 35 | import net.minecraft.server.v1_14_R1.BlockPosition;
|
36 | 36 | import net.minecraft.server.v1_14_R1.EntityArmorStand;
|
| 37 | +import net.minecraft.server.v1_14_R1.EntityTypes; |
37 | 38 | import net.minecraft.server.v1_14_R1.EnumItemSlot;
|
38 | 39 | import net.minecraft.server.v1_14_R1.GeneratorAccess;
|
39 |
| -import net.minecraft.server.v1_14_R1.MojangsonParser; |
| 40 | +import net.minecraft.server.v1_14_R1.IRegistry; |
| 41 | +import net.minecraft.server.v1_14_R1.Item; |
| 42 | +import net.minecraft.server.v1_14_R1.ItemStack; |
| 43 | +import net.minecraft.server.v1_14_R1.MinecraftKey; |
| 44 | +import net.minecraft.server.v1_14_R1.MobSpawnerAbstract; |
| 45 | +import net.minecraft.server.v1_14_R1.MobSpawnerData; |
40 | 46 | import net.minecraft.server.v1_14_R1.NBTTagCompound;
|
41 | 47 | import net.minecraft.server.v1_14_R1.TileEntity;
|
| 48 | +import net.minecraft.server.v1_14_R1.TileEntityMobSpawner; |
42 | 49 | import org.apache.commons.lang.Validate;
|
43 | 50 | import org.bukkit.NamespacedKey;
|
44 |
| -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; |
45 | 51 | import org.bukkit.craftbukkit.v1_14_R1.persistence.CraftPersistentDataContainer;
|
46 | 52 | import org.bukkit.craftbukkit.v1_14_R1.persistence.CraftPersistentDataTypeRegistry;
|
47 |
| -import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage; |
48 | 53 | import org.bukkit.persistence.PersistentDataType;
|
49 | 54 | import org.jetbrains.annotations.NotNull;
|
50 | 55 |
|
@@ -74,70 +79,43 @@ public void apply(@NotNull final OreConfig oreConfig, @NotNull final Object loca
|
74 | 79 | return; //TODO maybe throw exception?
|
75 | 80 |
|
76 | 81 | final String name = (String) objectOptional.get();
|
77 |
| - final Optional<BlockConfig> blockConfigOptional = ItemMods.getPlugin().getCustomBlockManager().getBlocks().stream().filter(blockConfig -> blockConfig.getName().equals(name)).findAny(); |
| 82 | + PackObject packObject = new PackObject(name); |
| 83 | + BlockAsset blockAsset = packObject.getBlock(); |
78 | 84 |
|
79 |
| - if (!blockConfigOptional.isPresent()) |
| 85 | + if (blockAsset == null) { |
80 | 86 | return; //TODO maybe throw exception?
|
| 87 | + } |
| 88 | + |
| 89 | + ModelAsset modelAsset = packObject.getModel(); |
81 | 90 |
|
82 |
| - final BlockConfig blockConfig = blockConfigOptional.get(); |
83 |
| - final ArmorStandBlockConfig armorStandBlockConfig = blockConfig.getArmorStand(); |
84 |
| - |
85 |
| - if (armorStandBlockConfig != null) { |
86 |
| - final EntityArmorStand entityArmorStand = new EntityArmorStand(generatorAccess.getMinecraftWorld(), blockPosition.getX() + 0.5, blockPosition.getY(), blockPosition.getZ() + 0.5); |
87 |
| - |
88 |
| - entityArmorStand.setSmall(armorStandBlockConfig.isSmall()); |
89 |
| - entityArmorStand.setMarker(armorStandBlockConfig.isMarker()); |
90 |
| - entityArmorStand.setInvulnerable(armorStandBlockConfig.isInvulnerable()); |
91 |
| - entityArmorStand.setCustomNameVisible(armorStandBlockConfig.isCustomNameVisible()); |
92 |
| - entityArmorStand.setCustomName(CraftChatMessage.fromStringOrNull(armorStandBlockConfig.getCustomName())); |
93 |
| - entityArmorStand.setInvisible(armorStandBlockConfig.isInvisible()); |
94 |
| - entityArmorStand.getScoreboardTags().add(blockConfig.getTag()); |
95 |
| - entityArmorStand.setNoGravity(true); |
96 |
| - entityArmorStand.setSilent(true); |
97 |
| - entityArmorStand.setBasePlate(armorStandBlockConfig.isBasePlate()); |
98 |
| - entityArmorStand.setSlot(EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(armorStandBlockConfig.getHelmet())); |
99 |
| - entityArmorStand.setSlot(EnumItemSlot.CHEST, CraftItemStack.asNMSCopy(armorStandBlockConfig.getChestplate())); |
100 |
| - entityArmorStand.setSlot(EnumItemSlot.LEGS, CraftItemStack.asNMSCopy(armorStandBlockConfig.getLeggings())); |
101 |
| - entityArmorStand.setSlot(EnumItemSlot.FEET, CraftItemStack.asNMSCopy(armorStandBlockConfig.getBoots())); |
102 |
| - entityArmorStand.setSlot(EnumItemSlot.MAINHAND, CraftItemStack.asNMSCopy(armorStandBlockConfig.getMainHand())); |
103 |
| - entityArmorStand.setSlot(EnumItemSlot.OFFHAND, CraftItemStack.asNMSCopy(armorStandBlockConfig.getOffHand())); |
104 |
| - |
105 |
| - // Fixing ArmorStand rotating issue, I have now idea why the yaw and/or pitch is another value than 0. |
106 |
| - // That needs a more detailed investigation, which of the above methods changes the yaw and/or pitch, |
107 |
| - // but for now it works. |
108 |
| - entityArmorStand.yaw = 0; |
109 |
| - entityArmorStand.pitch = 0; |
110 |
| - |
111 |
| - entityArmorStand.getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(ItemMods.getPlugin(), "type"), PersistentDataType.STRING, blockConfig.getTag()); |
112 |
| - |
113 |
| - generatorAccess.addEntity(entityArmorStand); |
| 91 | + if (modelAsset == null) { |
| 92 | + return; //TODO maybe throw exception? |
114 | 93 | }
|
115 | 94 |
|
116 | 95 | final TileEntity tileEntity = generatorAccess.getTileEntity(blockPosition);
|
117 | 96 |
|
118 | 97 | if (tileEntity != null) {
|
119 |
| - if (blockConfig.getData() != null) { |
120 |
| - final NBTTagCompound nbtTagCompound = new NBTTagCompound(); |
121 |
| - tileEntity.save(nbtTagCompound); |
122 |
| - |
123 |
| - try { |
124 |
| - final NBTTagCompound nbtTagCompound1 = MojangsonParser.parse(blockConfig.getData()); |
125 |
| - |
126 |
| - nbtTagCompound.a(nbtTagCompound1); |
127 |
| - } catch (final CommandSyntaxException e) { |
128 |
| - throw new RuntimeException("Error while parsing String to NBTTagCompound", e); |
129 |
| - } |
130 |
| - |
131 |
| - tileEntity.load(nbtTagCompound); |
| 98 | + TileEntityMobSpawner spawnerBlock = (TileEntityMobSpawner) tileEntity; |
| 99 | + MobSpawnerAbstract spawner = spawnerBlock.getSpawner(); |
| 100 | + spawner.requiredPlayerRange = 0; |
| 101 | + spawner.spawnCount = 0; |
| 102 | + |
| 103 | + EntityArmorStand armorStand = new EntityArmorStand(EntityTypes.ARMOR_STAND, null); |
| 104 | + Item item = IRegistry.ITEM.get(new MinecraftKey(modelAsset.getFallbackTexture().getKey().toString())); |
| 105 | + ItemStack itemStack = new ItemStack(item); |
| 106 | + NBTTagCompound compoundTag = itemStack.getOrCreateTag(); |
| 107 | + compoundTag.setInt("CustomModelData", packObject.getCustomModel()); |
| 108 | + armorStand.setSilent(true); |
| 109 | + armorStand.setSlot(EnumItemSlot.MAINHAND, itemStack); |
| 110 | + |
| 111 | + NBTTagCompound saved = new NBTTagCompound(); |
| 112 | + armorStand.save(saved); |
| 113 | + spawner.spawnData = new MobSpawnerData(1, saved); |
| 114 | + if (tileEntity.persistentDataContainer == null) { |
| 115 | + tileEntity.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); |
132 | 116 | }
|
133 | 117 |
|
134 |
| - if (blockConfig.getTag() != null) { |
135 |
| - if (tileEntity.persistentDataContainer == null) { |
136 |
| - tileEntity.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); |
137 |
| - } |
138 |
| - |
139 |
| - tileEntity.persistentDataContainer.set(new NamespacedKey(ItemMods.getPlugin(), "type"), PersistentDataType.STRING, blockConfig.getTag()); |
140 |
| - } |
| 118 | + tileEntity.persistentDataContainer.set(new NamespacedKey(ItemMods.getPlugin(), "custom_block_type"), PersistentDataType.STRING, packObject.toString()); |
141 | 119 |
|
142 | 120 | generatorAccess.w(blockPosition).removeTileEntity(blockPosition);
|
143 | 121 | generatorAccess.w(blockPosition).setTileEntity(blockPosition, tileEntity);
|
|
0 commit comments