Add ability to restore ruined spell books with the imbuement altar

For now this ignores dust elements but may change this in future
This commit is contained in:
Electroblob77
2020-09-14 15:37:05 +01:00
parent ac7e2fda94
commit ea4e07b2c9
7 changed files with 83 additions and 0 deletions
@@ -139,6 +139,7 @@ public class BlockImbuementAltar extends Block implements ITileEntityProvider {
ItemStack stack = toInsert.copy();
stack.setCount(1);
((TileEntityImbuementAltar)tileEntity).setStack(stack);
((TileEntityImbuementAltar)tileEntity).setLastUser(player);
if(!player.isCreative()) toInsert.shrink(1);
}else{
@@ -150,6 +151,7 @@ public class BlockImbuementAltar extends Block implements ITileEntityProvider {
}
((TileEntityImbuementAltar)tileEntity).setStack(ItemStack.EMPTY);
((TileEntityImbuementAltar)tileEntity).setLastUser(null);
if(currentStack.getItem() instanceof ItemWizardArmour && ((ItemWizardArmour)currentStack.getItem()).element != null){
// Not perfect since we don't know if the player actually imbued the armour, but it's good enough for now
@@ -28,6 +28,8 @@ public final class WizardryLoot {
//public static final String FROM_SPAWNER_NBT_FLAG = "fromSpawner";
public static final ResourceLocation RUINED_SPELL_BOOK_LOOT_TABLE = new ResourceLocation(Wizardry.MODID, "gameplay/imbuement_altar/ruined_spell_book");
private WizardryLoot(){} // No instances!
/** Called from the preInit method in the main mod class to register the custom dungeon loot. */
@@ -69,6 +71,7 @@ public final class WizardryLoot {
LootTableList.register(new ResourceLocation(Wizardry.MODID, "entities/mob_additions"));
LootTableList.register(new ResourceLocation(Wizardry.MODID, "gameplay/fishing/junk_additions"));
LootTableList.register(new ResourceLocation(Wizardry.MODID, "gameplay/fishing/treasure_additions"));
LootTableList.register(RUINED_SPELL_BOOK_LOOT_TABLE);
}
@@ -6,10 +6,12 @@ import electroblob.wizardry.item.IManaStoringItem;
import electroblob.wizardry.item.ItemWizardArmour;
import electroblob.wizardry.registry.WizardryBlocks;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.registry.WizardryLoot;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.GeometryUtils;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -20,9 +22,14 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.WorldServer;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootTable;
import org.apache.commons.lang3.ArrayUtils;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
public class TileEntityImbuementAltar extends TileEntity implements ITickable {
@@ -31,6 +38,7 @@ public class TileEntityImbuementAltar extends TileEntity implements ITickable {
private ItemStack stack;
private int imbuementTimer;
private Element displayElement;
private EntityPlayer lastUser;
public TileEntityImbuementAltar(){
stack = ItemStack.EMPTY;
@@ -41,6 +49,10 @@ public class TileEntityImbuementAltar extends TileEntity implements ITickable {
checkRecipe();
}
public void setLastUser(EntityPlayer player){
this.lastUser = player;
}
public void checkRecipe(){
if(getResult().isEmpty()){
@@ -144,6 +156,26 @@ public class TileEntityImbuementAltar extends TileEntity implements ITickable {
}
}
if(stack.getItem() == WizardryItems.ruined_spell_book){
if(!ArrayUtils.contains(getReceptacleElements(), null)){ // All receptacles filled (any element)
if(imbuementTimer >= IMBUEMENT_DURATION - 1 && world instanceof WorldServer){
LootTable table = this.world.getLootTableManager().getLootTableFromLocation(WizardryLoot.RUINED_SPELL_BOOK_LOOT_TABLE);
LootContext context = new LootContext.Builder((WorldServer)world).withPlayer(lastUser)
.withLuck(lastUser == null ? 0 : lastUser.getLuck()).build();
List<ItemStack> stacks = table.generateLootForPools(world.rand, context);
return stacks.isEmpty() ? ItemStack.EMPTY : stacks.get(0);
}
displayElement = Element.MAGIC;
return new ItemStack(WizardryItems.spell_book); // No point generating loot every tick just to check the recipe
}
}
displayElement = null;
return ItemStack.EMPTY;
}
@@ -187,6 +219,7 @@ public class TileEntityImbuementAltar extends TileEntity implements ITickable {
stack.writeToNBT(itemTag);
nbt.setTag("item", itemTag);
nbt.setInteger("imbuementTimer", imbuementTimer);
if(lastUser != null) nbt.setUniqueId("lastUser", lastUser.getUniqueID());
return nbt;
}
@@ -196,6 +229,7 @@ public class TileEntityImbuementAltar extends TileEntity implements ITickable {
NBTTagCompound itemTag = nbt.getCompoundTag("item");
this.stack = new ItemStack(itemTag);
this.imbuementTimer = nbt.getInteger("imbuementTimer");
this.lastUser = world.getPlayerEntityByUUID(nbt.getUniqueId("lastUser"));
}
@Override
@@ -0,0 +1,19 @@
{
"display": {
"title": {
"translate": "advancement.ebwizardry:restore_ruined_book"
},
"description": {
"translate": "advancement.ebwizardry:restore_ruined_book.desc"
},
"icon": {
"item": "ebwizardry:ruined_spell_book"
}
},
"parent": "ebwizardry:restore_imbuement_altar",
"criteria": {
"criteria_0": {
"trigger": "ebwizardry:restore_ruined_book"
}
}
}
@@ -693,6 +693,8 @@ advancement.ebwizardry\:restore_imbuement_altar=Good As New
advancement.ebwizardry\:restore_imbuement_altar.desc=Restore an imbuement altar to its former glory
advancement.ebwizardry\:create_elemental_armour=Changing Clothes
advancement.ebwizardry\:create_elemental_armour.desc=Imbue a piece of wizard armour with spectral dust of one of the arcane elements
advancement.ebwizardry\:restore_ruined_book=Arcane Archaeologist
advancement.ebwizardry\:restore_ruined_book.desc=Restore a ruined spell book at an imbuement altar
advancement.ebwizardry\:craft_lectern=Arcane Encyclopaedia
advancement.ebwizardry\:craft_lectern.desc=Craft a lectern to keep track of your spell library
@@ -693,6 +693,8 @@ advancement.ebwizardry\:restore_imbuement_altar=Good As New
advancement.ebwizardry\:restore_imbuement_altar.desc=Restore an imbuement altar to its former glory
advancement.ebwizardry\:create_elemental_armour=Changing Clothes
advancement.ebwizardry\:create_elemental_armour.desc=Imbue a piece of wizard armor with spectral dust of one of the arcane elements
advancement.ebwizardry\:restore_ruined_book=Arcane Archaeologist
advancement.ebwizardry\:restore_ruined_book.desc=Restore a ruined spell book at an imbuement altar
advancement.ebwizardry\:craft_lectern=Arcane Encyclopedia
advancement.ebwizardry\:craft_lectern.desc=Craft a lectern to keep track of your spell library
@@ -0,0 +1,21 @@
{
"pools": [
{
"name": "spell_book",
"rolls": 1,
"entries": [
{
"type": "item",
"name": "ebwizardry:spell_book",
"weight": 1,
"functions": [
{
"function": "ebwizardry:random_spell",
"undiscovered_bias": 0.3
}
]
}
]
}
]
}