Reimplement fix for #68 from #110, using IManaStoringItem and multiple mana flask sizes

This commit is contained in:
Electroblob77
2019-09-04 11:47:23 +01:00
parent 1ba723ade1
commit 3a788c867c
2 changed files with 187 additions and 76 deletions
@@ -3,9 +3,7 @@ package electroblob.wizardry.registry;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.item.IManaStoringItem;
import electroblob.wizardry.item.ItemManaFlask;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.inventory.ContainerWorkbench;
import net.minecraft.inventory.IInventory;
import electroblob.wizardry.misc.RecipeRechargeWithFlask;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
@@ -14,9 +12,6 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import net.minecraftforge.registries.IForgeRegistry;
import java.util.LinkedList;
@@ -54,84 +49,77 @@ public final class WizardryRecipes {
// Mana flask recipes
ItemStack smallFlaskStack = new ItemStack(WizardryItems.small_mana_flask);
ItemStack mediumFlaskStack = new ItemStack(WizardryItems.medium_mana_flask);
ItemStack largeFlaskStack = new ItemStack(WizardryItems.large_mana_flask);
ItemStack chargeable;
Item chargeable;
while(!chargingRecipeQueue.isEmpty()){
// Use remove() and not poll() because the queue shouldn't be empty in here
chargeable = new ItemStack(chargingRecipeQueue.remove(), 1, OreDictionary.WILDCARD_VALUE);
chargeable = chargingRecipeQueue.remove();
registry.register(new ShapelessOreRecipe(null, chargeable, chargeable, smallFlaskStack){
@Override public boolean isDynamic(){ return true; } // Stops it appearing in the recipe book
}.setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/small_flask_" + chargeable.getItem().getRegistryName().getPath())));
registry.register(new RecipeRechargeWithFlask(chargeable, (ItemManaFlask)WizardryItems.small_mana_flask)
.setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/small_flask_" + chargeable.getRegistryName().getPath())));
registry.register(new ShapelessOreRecipe(null, chargeable, chargeable, mediumFlaskStack){
@Override public boolean isDynamic(){ return true; }
}.setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/medium_flask_" + chargeable.getItem().getRegistryName().getPath())));
registry.register(new RecipeRechargeWithFlask(chargeable, (ItemManaFlask)WizardryItems.medium_mana_flask)
.setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/medium_flask_" + chargeable.getRegistryName().getPath())));
registry.register(new ShapelessOreRecipe(null, chargeable, chargeable, largeFlaskStack){
@Override public boolean isDynamic(){ return true; }
}.setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/large_flask_" + chargeable.getItem().getRegistryName().getPath())));
registry.register(new RecipeRechargeWithFlask(chargeable, (ItemManaFlask)WizardryItems.large_mana_flask)
.setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/large_flask_" + chargeable.getRegistryName().getPath())));
}
}
@SubscribeEvent
public static void onPlayerTickEvent(TickEvent.PlayerTickEvent event){
if(event.phase == TickEvent.Phase.START){
if(event.player.openContainer instanceof ContainerWorkbench){
IInventory craftMatrix = ((ContainerWorkbench)event.player.openContainer).craftMatrix;
ItemStack output = ((ContainerWorkbench)event.player.openContainer).craftResult.getStackInSlot(0);
processManaFlaskCrafting(craftMatrix, output);
}else if(event.player.openContainer instanceof ContainerPlayer){
IInventory craftMatrix = ((ContainerPlayer)event.player.openContainer).craftMatrix;
ItemStack output = ((ContainerPlayer)event.player.openContainer).craftResult.getStackInSlot(0);
// Unfortunately I have no choice but to call this method every tick when the player isn't using another
// inventory, since the only thing tracking whether the player is looking at their inventory is the GUI
// itself, which is client-side only.
processManaFlaskCrafting(craftMatrix, output);
}
}
}
private static void processManaFlaskCrafting(IInventory craftMatrix, ItemStack output){
// Charges wand using mana flask
ItemManaFlask flask = null;
ItemStack input = ItemStack.EMPTY;
for(int i = 0; i < craftMatrix.getSizeInventory(); i++){
ItemStack stack = craftMatrix.getStackInSlot(i);
if(stack.getItem() instanceof ItemManaFlask){
flask = (ItemManaFlask)stack.getItem();
}
if(stack.getItem() instanceof IManaStoringItem){
input = stack;
}
}
if(flask == null) return;
if(output.getItem() instanceof IManaStoringItem && !input.isEmpty()){
output.setTagCompound((input.getTagCompound()));
int currentMana = ((IManaStoringItem)input.getItem()).getMana(input);
((IManaStoringItem)output.getItem()).setMana(output, Math.min(currentMana + flask.size.capacity,
((IManaStoringItem)input.getItem()).getManaCapacity(input)));
}
}
// @SubscribeEvent
// public static void onPlayerTickEvent(TickEvent.PlayerTickEvent event){
//
// if(event.phase == TickEvent.Phase.START){
//
// if(event.player.openContainer instanceof ContainerWorkbench){
//
// IInventory craftMatrix = ((ContainerWorkbench)event.player.openContainer).craftMatrix;
// ItemStack output = ((ContainerWorkbench)event.player.openContainer).craftResult.getStackInSlot(0);
// processManaFlaskCrafting(craftMatrix, output);
//
// }else if(event.player.openContainer instanceof ContainerPlayer){
//
// IInventory craftMatrix = ((ContainerPlayer)event.player.openContainer).craftMatrix;
// ItemStack output = ((ContainerPlayer)event.player.openContainer).craftResult.getStackInSlot(0);
// // Unfortunately I have no choice but to call this method every tick when the player isn't using another
// // inventory, since the only thing tracking whether the player is looking at their inventory is the GUI
// // itself, which is client-side only.
// processManaFlaskCrafting(craftMatrix, output);
// }
// }
// }
//
// private static void processManaFlaskCrafting(IInventory craftMatrix, ItemStack output){
//
// // Charges wand using mana flask
//
// ItemManaFlask flask = null;
// ItemStack input = ItemStack.EMPTY;
//
// for(int i = 0; i < craftMatrix.getSizeInventory(); i++){
//
// ItemStack stack = craftMatrix.getStackInSlot(i);
//
// if(stack.getItem() instanceof ItemManaFlask){
// flask = (ItemManaFlask)stack.getItem();
// }
//
// if(stack.getItem() instanceof IManaStoringItem){
// input = stack;
// }
// }
//
// if(flask == null) return;
//
// if(output.getItem() instanceof IManaStoringItem && !input.isEmpty()){
//
// output.setTagCompound((input.getTagCompound()));
//
// int currentMana = ((IManaStoringItem)input.getItem()).getMana(input);
//
// ((IManaStoringItem)output.getItem()).setMana(output, Math.min(currentMana + flask.size.capacity,
// ((IManaStoringItem)input.getItem()).getManaCapacity(input)));
// }
// }
}