Merge pull request #110 from Corail31/1.12.2

Fixes #68 #108
This commit is contained in:
Electroblob
2019-01-15 23:25:16 +00:00
committed by GitHub
7 changed files with 65 additions and 102 deletions
@@ -8,7 +8,6 @@ import electroblob.wizardry.entity.living.ISummonedCreature;
import electroblob.wizardry.event.DiscoverSpellEvent;
import electroblob.wizardry.event.SpellCastEvent;
import electroblob.wizardry.item.ItemWand;
import electroblob.wizardry.item.ItemWizardArmour;
import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.registry.WizardryAdvancementTriggers;
import electroblob.wizardry.registry.WizardryEnchantments;
@@ -33,9 +32,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.inventory.ContainerWorkbench;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.PotionEffect;
@@ -289,24 +285,6 @@ public final class WizardryEventHandler {
EntityPlayer player = (EntityPlayer)event.getEntityLiving();
if(player.world.isRemote) hackilyFixContinuousSpellCasting(player);
// Mana flask crafting
if(player.openContainer instanceof ContainerWorkbench){
IInventory craftMatrix = ((ContainerWorkbench)player.openContainer).craftMatrix;
ItemStack output = ((ContainerWorkbench)player.openContainer).craftResult.getStackInSlot(0);
processManaFlaskCrafting(craftMatrix, output);
}else if(player.openContainer instanceof ContainerPlayer){
IInventory craftMatrix = ((ContainerPlayer)player.openContainer).craftMatrix;
ItemStack output = ((ContainerPlayer)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);
}
}
if(event.getEntityLiving().world.isRemote){
@@ -401,50 +379,4 @@ public final class WizardryEventHandler {
}
}
}
private static void processManaFlaskCrafting(IInventory craftMatrix, ItemStack output){
// Charges wand using mana flask. It is here rather than in the crafting handler so the result displays
// the proper damage before it is actually crafted.
boolean flag = false;
ItemStack wand = ItemStack.EMPTY;
ItemStack armour = ItemStack.EMPTY;
for(int i = 0; i < craftMatrix.getSizeInventory(); i++){
ItemStack itemstack = craftMatrix.getStackInSlot(i);
if(itemstack.getItem() == WizardryItems.mana_flask){
flag = true;
}
if(itemstack.getItem() instanceof ItemWand){
wand = itemstack;
}
if(itemstack.getItem() instanceof ItemWizardArmour){
armour = itemstack;
}
}
if(output.getItem() instanceof ItemWand && flag && !wand.isEmpty()){
output.setTagCompound((wand.getTagCompound()));
if(wand.getItemDamage() - Constants.MANA_PER_FLASK < 0){
output.setItemDamage(0);
}else{
output.setItemDamage(wand.getItemDamage() - Constants.MANA_PER_FLASK);
}
}
if(output.getItem() instanceof ItemWizardArmour && flag && !armour.isEmpty()){
output.setTagCompound((armour.getTagCompound()));
if(armour.getItemDamage() - Constants.MANA_PER_FLASK < 0){
output.setItemDamage(0);
}else{
output.setItemDamage(wand.getItemDamage() - Constants.MANA_PER_FLASK);
}
}
}
}
@@ -24,8 +24,9 @@ public class BlockVanishingCobweb extends BlockContainer {
super(material);
}
@Override
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer(){
public BlockRenderLayer getRenderLayer(){
return BlockRenderLayer.CUTOUT;
}
@@ -0,0 +1,54 @@
package electroblob.wizardry.recipe;
import electroblob.wizardry.constants.Constants;
import electroblob.wizardry.item.ItemWand;
import electroblob.wizardry.item.ItemWizardArmour;
import electroblob.wizardry.registry.WizardryItems;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapelessOreRecipe;
public class RecipeRechargeWithFlask extends ShapelessOreRecipe {
public RecipeRechargeWithFlask() {
super(null, ItemStack.EMPTY, ItemStack.EMPTY, WizardryItems.mana_flask);
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
ItemStack result = lookupForIngredients(inv, true);
if (!result.isEmpty()) {
result.setItemDamage(Math.max(output.getItemDamage() - Constants.MANA_PER_FLASK, 0));
}
return result;
}
@Override
public boolean matches(InventoryCrafting inv, World world) {
return !lookupForIngredients(inv, false).isEmpty();
}
/* lookup for the needed ingredients && return the rechargeable itemstack */
private ItemStack lookupForIngredients(InventoryCrafting inv, boolean copy) {
ItemStack flask = ItemStack.EMPTY;
ItemStack rechargeable = ItemStack.EMPTY;
for (int i = 0; (flask.isEmpty() || rechargeable.isEmpty()) && i < inv.getSizeInventory(); i++) {
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty()) {
if (flask.isEmpty() && itemstack.getItem() == WizardryItems.mana_flask) {
flask = itemstack;
} else if (rechargeable.isEmpty() && (itemstack.getItem() instanceof ItemWand || itemstack.getItem() instanceof ItemWizardArmour) && itemstack.getItemDamage() > 0) {
rechargeable = copy ? itemstack.copy() : itemstack;
} else {
return ItemStack.EMPTY;
}
}
}
return flask.isEmpty() || rechargeable.isEmpty() ? ItemStack.EMPTY : rechargeable;
}
@Override
public boolean isDynamic() {
return true;
}
}
@@ -0,0 +1,3 @@
@javax.annotation.ParametersAreNonnullByDefault
@mcp.MethodsReturnNonnullByDefault
package electroblob.wizardry.recipe;
@@ -60,11 +60,11 @@ public final class WizardryBlocks {
/**
* Sets both the registry and unlocalised names of the given block, then registers it with the given registry. Use
* this instead of {@link Block#setRegistryName(String)} and {@link Block#setUnlocalizedName(String)} during
* this instead of {@link Block#setRegistryName(String)} and {@link Block#setTranslationKey(String)} during
* construction, for convenience and consistency.
*
* @param registry The registry to register the given block to.
* @param item The block to register.
* @param block The block to register.
* @param name The name of the block, without the mod ID or the .name stuff. The registry name will be
* {@code ebwizardry:[name]}. The unlocalised name will be {@code tile.ebwizardry:[name].name}.
*/
@@ -261,7 +261,7 @@ public final class WizardryItems {
/**
* Sets both the registry and unlocalised names of the given item, then registers it with the given registry. Use
* this instead of {@link Item#setRegistryName(String)} and {@link Item#setUnlocalizedName(String)} during
* this instead of {@link Item#setRegistryName(String)} and {@link Item#setTranslationKey(String)} during
* construction, for convenience and consistency.
*
* @param registry The registry to register the given item to.
@@ -5,8 +5,6 @@ import java.util.List;
import com.google.common.collect.Lists;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.constants.Element;
import electroblob.wizardry.constants.Tier;
import electroblob.wizardry.entity.EntityArc;
import electroblob.wizardry.entity.EntityMeteor;
import electroblob.wizardry.entity.EntityShield;
@@ -64,16 +62,15 @@ import electroblob.wizardry.entity.projectile.EntitySparkBomb;
import electroblob.wizardry.entity.projectile.EntityThunderbolt;
import electroblob.wizardry.loot.RandomSpell;
import electroblob.wizardry.loot.WizardSpell;
import electroblob.wizardry.recipe.RecipeRechargeWithFlask;
import electroblob.wizardry.tileentity.TileEntityArcaneWorkbench;
import electroblob.wizardry.tileentity.TileEntityMagicLight;
import electroblob.wizardry.tileentity.TileEntityPlayerSave;
import electroblob.wizardry.tileentity.TileEntityStatue;
import electroblob.wizardry.tileentity.TileEntityTimer;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Biomes;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
@@ -87,8 +84,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import net.minecraftforge.registries.IForgeRegistry;
/**
@@ -251,31 +246,9 @@ public final class WizardryRegistry {
FurnaceRecipes.instance().addSmeltingRecipeForBlock(WizardryBlocks.crystal_ore, new ItemStack(WizardryItems.magic_crystal), 0.5f);
// Mana flask recipes
ItemStack manaFlaskStack = new ItemStack(WizardryItems.mana_flask);
ItemStack miscWandStack;
// Mana flask recipe
registry.register(new RecipeRechargeWithFlask().setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/eb_rechargeable_with_flask")));
for(Element element : Element.values()){
for(Tier tier : Tier.values()){
miscWandStack = new ItemStack(WizardryUtilities.getWand(tier, element), 1, OreDictionary.WILDCARD_VALUE);
registry.register(new ShapelessOreRecipe(null, miscWandStack, miscWandStack, manaFlaskStack){
@Override public boolean isDynamic(){ return true; } // Stops it appearing in the recipe book
}.setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/flask_wand_" + element.getUnlocalisedName() + "_" + tier.getUnlocalisedName())));
}
}
ItemStack miscArmourStack;
for(Element element : Element.values()){
for(EntityEquipmentSlot slot : WizardryUtilities.ARMOUR_SLOTS){
miscArmourStack = new ItemStack(WizardryUtilities.getArmour(element, slot), 1, OreDictionary.WILDCARD_VALUE);
registry.register(new ShapelessOreRecipe(null, miscArmourStack, miscArmourStack, manaFlaskStack){
@Override public boolean isDynamic(){ return true; } // Stops it appearing in the recipe book
}.setRegistryName(new ResourceLocation(Wizardry.MODID, "recipes/flask_armour_" + element.getUnlocalisedName() + "_" + slot.getName())));
}
}
}
}