Skip to content

Commit

Permalink
Adding NBT data for bosses and drops
Browse files Browse the repository at this point in the history
This gives awesome flexability when it comes to the monsters created by the  mod.

Also updating example fights to show how to drop a totem of summoning as a reward.
  • Loading branch information
Brian-Wuest committed Jun 28, 2020
1 parent ad9eace commit f02900f
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 139 deletions.
17 changes: 13 additions & 4 deletions sample_fights/creeper.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"maxHealth": 40,
"attackDamage": 10.5,
"alwaysShowDisplayName": true,
"additionalDrops": [
{
"additionalDrops": [{
"item": "minecraft:diamond",
"minDrops": 1,
"maxDrops": 4,
Expand All @@ -19,13 +18,23 @@
"item": "minecraft:gold_chestplate",
"minDrops": 1,
"maxDrops": 1,
"dropChance": 715
"dropChance": 71
},
{
"item": "minecraft:diamond_sword",
"minDrops": 1,
"maxDrops": 1,
"dropChance": 75
},
{
"item": "from_the_depths:item_totem_of_summoning",
"minDrops": 1,
"maxDrops": 1,
"dropChance": 100,
"_comment": "Provide a drop for the next monster in a sequence of bosses. This is especially helpful to get players to build up to a mega boss!",
"nbt": {
"spawn_info": "Custom_Skeleton"
}
}
]
},
Expand All @@ -48,4 +57,4 @@
"count": 1
}
}
}
}
31 changes: 31 additions & 0 deletions sample_fights/slime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"key": "Custom_slime",
"bossInfo": {
"domain": "minecraft",
"name": "slime",
"displayName": "Custom Slime Rawr!",
"maxHealth": 40,
"attackDamage": 10.5,
"alwaysShowDisplayName": true,
"nbt": {"Size": -1 },
"additionalDrops": [{
"item": "minecraft:diamond",
"minDrops": 1,
"maxDrops": 4,
"dropChance": 70
},
{
"item": "minecraft:gold_chestplate",
"minDrops": 1,
"maxDrops": 1,
"dropChance": 715
},
{
"item": "minecraft:diamond_sword",
"minDrops": 1,
"maxDrops": 1,
"dropChance": 75
}
]
}
}
25 changes: 10 additions & 15 deletions src/main/java/com/wuest/from_the_depths/EntityInfo/BaseMonster.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public abstract class BaseMonster {
public ArrayList<DropInfo> additionalDrops;
public String commandToRunAtSpawn;
public JsonObject nbt;
protected NBTTagCompound convertedNBT;

public BaseMonster() {
this.maxHealth = -1;
Expand Down Expand Up @@ -95,31 +94,33 @@ public Entity createEntityForWorld(World world, BlockPos pos, ICommandSender com
NBTTagCompound entityCompoundTag = entityLiving.getEntityData();
entityCompoundTag.setTag("from_the_depths", trackingTag);

// Serialize the entity NBT data so it can be updated.
NBTTagCompound serializedEntity = entityLiving.serializeNBT();

entityLiving.forceSpawn = true;
entityLiving.rotationYawHead = entityLiving.rotationYaw;
entityLiving.renderYawOffset = entityLiving.rotationYaw;
entityLiving.setPositionAndUpdate(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
entityLiving.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(spawnPos)),
(IEntityLivingData) null);

// Serialize the entity NBT data so it can be updated.
NBTTagCompound serializedEntity = entityLiving.serializeNBT();

// This has to be after the "onInitialSpawn" call since some monsters will set properties to random values which need to be set specifically.
if (this.nbt != null) {
NBTTagCompound compound = null;
try {
this.convertedNBT = JsonToNBT.getTagFromJson(this.nbt.toString());
compound = JsonToNBT.getTagFromJson(this.nbt.toString());
}
catch (NBTException exception) {
FromTheDepths.logger.error(exception);
}

for (String tagKey : this.convertedNBT.getKeySet()) {
serializedEntity.setTag(tagKey, this.convertedNBT.getTag(tagKey));
}
if (compound != null && !compound.hasNoTags()) {
for (String tagKey : compound.getKeySet()) {
serializedEntity.setTag(tagKey, compound.getTag(tagKey));
}

entityLiving.readEntityFromNBT(serializedEntity);
entityLiving = (EntityLiving)EntityList.createEntityFromNBT(serializedEntity,world);
}
}

world.spawnEntity(entityLiving);
Expand Down Expand Up @@ -272,12 +273,6 @@ public void loadFromNBT(NBTTagCompound tag) {
this.commandToRunAtSpawn = tag.getString("commandToRunAtSpawn");

if (tag.hasKey("nbt")) {
try {
this.convertedNBT = JsonToNBT.getTagFromJson(tag.getString("nbt"));
} catch (NBTException exception) {
FromTheDepths.logger.error(exception);
}

JsonParser parser = new JsonParser();
this.nbt = (JsonObject)parser.parse(tag.getString("nbt"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ public BossAddInfo clone() {
newInstance.numberLeftToSpawn = this.numberLeftToSpawn;
newInstance.timeUntilNextSpawn = this.timeUntilNextSpawn;
newInstance.commandToRunAtSpawn = this.commandToRunAtSpawn;

newInstance.nbt = this.nbt;

if (this.nextWaveOfAdds != null) {
newInstance.nextWaveOfAdds = this.nextWaveOfAdds.clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public BossInfo clone() {
newInstance.timeToWaitBeforeSpawn = this.timeToWaitBeforeSpawn;
newInstance.commandToRunAtSpawn = this.commandToRunAtSpawn;
newInstance.nbt = this.nbt;
newInstance.convertedNBT = this.convertedNBT;

for (DropInfo info : this.additionalDrops) {
newInstance.additionalDrops.add(info.clone());
Expand Down
Loading

0 comments on commit f02900f

Please sign in to comment.