Initial 1.11.2 update

This commit is contained in:
Electroblob
2018-02-07 21:15:50 +00:00
parent 67f6be0671
commit 3df5597dcc
368 changed files with 17234 additions and 15082 deletions
@@ -9,11 +9,13 @@ import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
/** Allows wizardry to identify items that are conjured (and therefore need destroying if they leave the inventory)
* without explicitly referencing each, thereby allowing for better expandibility. */
/**
* Allows wizardry to identify items that are conjured (and therefore need destroying if they leave the inventory)
* without explicitly referencing each, thereby allowing for better expandibility.
*/
@Mod.EventBusSubscriber
public interface IConjuredItem {
/** The NBT tag key used to store the duration multiplier for conjured items. */
public static final String DURATION_MULTIPLIER_KEY = "durationMultiplier";
@@ -22,20 +24,24 @@ public interface IConjuredItem {
if(!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setFloat(DURATION_MULTIPLIER_KEY, multiplier);
}
/** Helper method for returning the max damage of a conjured item based on its NBT data. Centralises the code.
* Implementors will almost certainly want to call this from {@link Item#getMaxDamage(ItemStack stack)}. */
/**
* Helper method for returning the max damage of a conjured item based on its NBT data. Centralises the code.
* Implementors will almost certainly want to call this from {@link Item#getMaxDamage(ItemStack stack)}.
*/
public default int getMaxDamageFromNBT(ItemStack stack){
if(stack.hasTagCompound() && stack.getTagCompound().hasKey(DURATION_MULTIPLIER_KEY)){
return (int)(this.getBaseDuration() * stack.getTagCompound().getFloat(DURATION_MULTIPLIER_KEY));
}
return this.getBaseDuration();
}
/** Returns the base duration in ticks for this conjured item. Should be a constant (commonly 600).
* Implementors may want to call this when setting an item's max damage in its constructor. */
/**
* Returns the base duration in ticks for this conjured item. Should be a constant (commonly 600). Implementors may
* want to call this when setting an item's max damage in its constructor.
*/
public int getBaseDuration();
@SubscribeEvent
public static void onLivingDropsEvent(LivingDropsEvent event){
// Destroys conjured items if their caster dies.
@@ -45,7 +51,7 @@ public interface IConjuredItem {
}
}
}
@SubscribeEvent
public static void onItemTossEvent(ItemTossEvent event){
// Prevents conjured items being thrown by dragging and dropping outside the inventory.
@@ -9,51 +9,56 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemArcaneTome extends Item {
public ItemArcaneTome() {
public ItemArcaneTome(){
super();
this.setHasSubtypes(true);
this.setMaxStackSize(1);
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list){
for(int i=1; i<Tier.values().length; i++) {
list.add(new ItemStack(item, 1, i));
}
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> list){
for(int i = 1; i < Tier.values().length; i++){
list.add(new ItemStack(item, 1, i));
}
}
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return true;
}
@Override
public EnumRarity getRarity(ItemStack stack)
{
switch(this.getDamage(stack)){
case 1: return EnumRarity.UNCOMMON;
case 2: return EnumRarity.RARE;
case 3: return EnumRarity.EPIC;
}
return EnumRarity.COMMON;
}
@SideOnly(Side.CLIENT)
@Override
public EnumRarity getRarity(ItemStack stack){
switch(this.getDamage(stack)){
case 1:
return EnumRarity.UNCOMMON;
case 2:
return EnumRarity.RARE;
case 3:
return EnumRarity.EPIC;
}
return EnumRarity.COMMON;
}
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean showAdvanced){
Tier tier = Tier.values()[stack.getItemDamage()];
Tier tier2 = Tier.values()[stack.getItemDamage()-1];
Tier tier2 = Tier.values()[stack.getItemDamage() - 1];
tooltip.add(tier.getDisplayNameWithFormatting());
tooltip.add("\u00A77" + net.minecraft.client.resources.I18n.format("item.wizardry:arcane_tome.desc1", tier2.getDisplayNameWithFormatting()));
tooltip.add("\u00A77" + net.minecraft.client.resources.I18n.format("item.wizardry:arcane_tome.desc2", tier.getDisplayNameWithFormatting() + "\u00A77"));
tooltip.add("\u00A77" + net.minecraft.client.resources.I18n.format("item.wizardry:arcane_tome.desc1",
tier2.getDisplayNameWithFormatting()));
tooltip.add("\u00A77" + net.minecraft.client.resources.I18n.format("item.wizardry:arcane_tome.desc2",
tier.getDisplayNameWithFormatting() + "\u00A77"));
}
}
@@ -8,39 +8,41 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemArmourUpgrade extends Item {
public ItemArmourUpgrade() {
public ItemArmourUpgrade(){
super();
this.setMaxStackSize(1);
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC;
}
return EnumRarity.EPIC;
}
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced){
tooltip.add(net.minecraft.client.resources.I18n.format("item.wizardry:armour_upgrade.desc1", "\u00A77"));
tooltip.add(net.minecraft.client.resources.I18n.format("item.wizardry:armour_upgrade.desc2", "\u00A77", "\u00A7d"));
tooltip.add(
net.minecraft.client.resources.I18n.format("item.wizardry:armour_upgrade.desc2", "\u00A77", "\u00A7d"));
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> subItems){
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
}
}
@@ -1,7 +1,5 @@
package electroblob.wizardry.item;
import java.util.List;
import electroblob.wizardry.entity.projectile.EntityFirebomb;
import electroblob.wizardry.registry.WizardryTabs;
import net.minecraft.creativetab.CreativeTabs;
@@ -12,39 +10,42 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemFirebomb extends Item {
public ItemFirebomb(){
this.maxStackSize = 16;
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
public ItemFirebomb(){
this.maxStackSize = 16;
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
if(!player.capabilities.isCreativeMode){
--stack.stackSize;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
player.playSound(SoundEvents.ENTITY_SNOWBALL_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
ItemStack stack = player.getHeldItem(hand);
if(!world.isRemote){
EntityFirebomb firebomb = new EntityFirebomb(world, player);
// This is the standard set of parameters for this method, used by snowballs and ender pearls.
firebomb.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
world.spawnEntityInWorld(firebomb);
}
if(!player.capabilities.isCreativeMode){
stack.shrink(1);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item parItem, CreativeTabs parTab, List<ItemStack> parListSubItems){
parListSubItems.add(new ItemStack(this, 1));
}
player.playSound(SoundEvents.ENTITY_SNOWBALL_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if(!world.isRemote){
EntityFirebomb firebomb = new EntityFirebomb(world, player);
// This is the standard set of parameters for this method, used by snowballs and ender pearls.
firebomb.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
world.spawnEntity(firebomb);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item parItem, CreativeTabs parTab, NonNullList<ItemStack> parListSubItems){
parListSubItems.add(new ItemStack(this, 1));
}
}
@@ -1,7 +1,5 @@
package electroblob.wizardry.item;
import java.util.List;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import net.minecraft.creativetab.CreativeTabs;
@@ -11,13 +9,14 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemFlamingAxe extends ItemAxe implements IConjuredItem {
public ItemFlamingAxe(ToolMaterial material) {
public ItemFlamingAxe(ToolMaterial material){
super(material, 8, -3);
this.setMaxDamage(getBaseDuration());
this.setNoRepair();
@@ -28,65 +27,65 @@ public class ItemFlamingAxe extends ItemAxe implements IConjuredItem {
public int getBaseDuration(){
return 600;
}
@Override
public int getMaxDamage(ItemStack stack){
return this.getMaxDamageFromNBT(stack);
}
return this.getMaxDamageFromNBT(stack);
}
@Override
// This method allows the code for the item's timer to be greatly simplified by damaging it directly from
// onUpdate() and removing the workaround that involved WizardData and all sorts of crazy stuff.
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged){
if(oldStack != null || newStack != null){
if(!oldStack.isEmpty() || !newStack.isEmpty()){
// We only care about the situation where we specifically want the animation NOT to play.
if(oldStack.getItem() == newStack.getItem() && !slotChanged) return false;
}
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected){
int damage = stack.getItemDamage();
if(damage > stack.getMaxDamage()) entity.replaceItemInInventory(slot, null);
stack.setItemDamage(damage + 1);
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase wielder){
if(!MagicDamage.isEntityImmune(DamageType.FIRE, target)) target.setFire(8);
return false;
}
if(!MagicDamage.isEntityImmune(DamageType.FIRE, target)) target.setFire(8);
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return true;
}
@Override
public boolean getIsRepairable(ItemStack stack, ItemStack par2ItemStack){
return false;
}
return false;
}
@Override
public int getItemEnchantability(){
return 0;
}
return 0;
}
// Cannot be dropped
@Override
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player){
return false;
}
return false;
}
@Override
@SideOnly(Side.CLIENT)
@SideOnly(Side.CLIENT)
// Why does this method pass in an item as an argument? It is always the same item the method is invoked on.
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> items){
items.add(new ItemStack(this, 1));
}
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> items){
items.add(new ItemStack(this, 1));
}
}
@@ -1,7 +1,5 @@
package electroblob.wizardry.item;
import java.util.List;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
@@ -13,82 +11,83 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemFrostAxe extends ItemAxe implements IConjuredItem {
public ItemFrostAxe(ToolMaterial material) {
public ItemFrostAxe(ToolMaterial material){
super(material, 8, -3);
this.setMaxDamage(getBaseDuration());
this.setNoRepair();
this.setCreativeTab(null);
}
@Override
public int getBaseDuration(){
return 600;
}
@Override
public int getMaxDamage(ItemStack stack){
return this.getMaxDamageFromNBT(stack);
}
return this.getMaxDamageFromNBT(stack);
}
@Override
// This method allows the code for the item's timer to be greatly simplified by damaging it directly from
// onUpdate() and removing the workaround that involved WizardData and all sorts of crazy stuff.
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged){
if(oldStack != null || newStack != null){
if(!oldStack.isEmpty() || !newStack.isEmpty()){
// We only care about the situation where we specifically want the animation NOT to play.
if(oldStack.getItem() == newStack.getItem() && !slotChanged) return false;
}
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected){
int damage = stack.getItemDamage();
if(damage > stack.getMaxDamage()) entity.replaceItemInInventory(slot, null);
stack.setItemDamage(damage + 1);
}
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase wielder)
{
if(!MagicDamage.isEntityImmune(DamageType.FROST, target)) target.addPotionEffect(new PotionEffect(WizardryPotions.frost, 160, 1));
return false;
}
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase wielder){
if(!MagicDamage.isEntityImmune(DamageType.FROST, target))
target.addPotionEffect(new PotionEffect(WizardryPotions.frost, 160, 1));
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return true;
}
@Override
public boolean getIsRepairable(ItemStack stack, ItemStack par2ItemStack){
return false;
}
return false;
}
@Override
public int getItemEnchantability(){
return 0;
}
return 0;
}
// Cannot be dropped
@Override
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player){
return false;
}
return false;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item parItem, CreativeTabs parTab, List<ItemStack> parListSubItems){
parListSubItems.add(new ItemStack(this, 1));
}
@SideOnly(Side.CLIENT)
public void getSubItems(Item parItem, CreativeTabs parTab, NonNullList<ItemStack> parListSubItems){
parListSubItems.add(new ItemStack(this, 1));
}
}
@@ -16,6 +16,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
@@ -24,7 +25,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemIdentificationScroll extends Item {
public ItemIdentificationScroll() {
public ItemIdentificationScroll(){
super();
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
@@ -43,7 +44,9 @@ public class ItemIdentificationScroll extends Item {
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
ItemStack stack = player.getHeldItem(hand);
if(WizardData.get(player) != null){
@@ -56,14 +59,16 @@ public class ItemIdentificationScroll extends Item {
if((stack1.getItem() instanceof ItemSpellBook || stack1.getItem() instanceof ItemScroll)
&& !properties.hasSpellBeenDiscovered(spell)){
if(!MinecraftForge.EVENT_BUS.post(new DiscoverSpellEvent(player, spell, DiscoverSpellEvent.Source.IDENTIFICATION_SCROLL))){
if(!MinecraftForge.EVENT_BUS.post(new DiscoverSpellEvent(player, spell,
DiscoverSpellEvent.Source.IDENTIFICATION_SCROLL))){
// Identification scrolls give the chat readout in creative mode, otherwise it looks like
// nothing happens!
properties.discoverSpell(spell);
player.addStat(WizardryAchievements.identify_spell);
player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1.25f, 1);
if(!player.capabilities.isCreativeMode) stack.stackSize--;
if(!world.isRemote) player.addChatMessage(new TextComponentTranslation("spell.discover", spell.getNameForTranslationFormatted()));
if(!player.capabilities.isCreativeMode) stack.shrink(1);
if(!world.isRemote) player.sendMessage(new TextComponentTranslation("spell.discover",
spell.getNameForTranslationFormatted()));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
@@ -71,7 +76,8 @@ public class ItemIdentificationScroll extends Item {
}
}
// If it found nothing to identify, it says so!
if(!world.isRemote) player.addChatMessage(new TextComponentTranslation("item.wizardry:identification_scroll.nothing_to_identify"));
if(!world.isRemote) player.sendMessage(
new TextComponentTranslation("item.wizardry:identification_scroll.nothing_to_identify"));
}
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
@@ -79,7 +85,7 @@ public class ItemIdentificationScroll extends Item {
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item parItem, CreativeTabs parTab, List<ItemStack> parListSubItems){
public void getSubItems(Item parItem, CreativeTabs parTab, NonNullList<ItemStack> parListSubItems){
parListSubItems.add(new ItemStack(this, 1));
}
}
@@ -1,7 +1,5 @@
package electroblob.wizardry.item;
import java.util.List;
import electroblob.wizardry.entity.projectile.EntityPoisonBomb;
import electroblob.wizardry.registry.WizardryTabs;
import net.minecraft.creativetab.CreativeTabs;
@@ -12,40 +10,43 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemPoisonBomb extends Item {
public ItemPoisonBomb(){
this.maxStackSize = 16;
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
public ItemPoisonBomb(){
this.maxStackSize = 16;
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
if(!player.capabilities.isCreativeMode){
--stack.stackSize;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
player.playSound(SoundEvents.ENTITY_SNOWBALL_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
ItemStack stack = player.getHeldItem(hand);
if(!world.isRemote){
EntityPoisonBomb poisonbomb = new EntityPoisonBomb(world, player);
// This is the standard set of parameters for this method, used by snowballs and ender pearls.
poisonbomb.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
world.spawnEntityInWorld(poisonbomb);
}
if(!player.capabilities.isCreativeMode){
stack.shrink(1);
}
player.playSound(SoundEvents.ENTITY_SNOWBALL_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if(!world.isRemote){
EntityPoisonBomb poisonbomb = new EntityPoisonBomb(world, player);
// This is the standard set of parameters for this method, used by snowballs and ender pearls.
poisonbomb.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
world.spawnEntity(poisonbomb);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
}
@@ -1,7 +1,5 @@
package electroblob.wizardry.item;
import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.event.SpellCastEvent;
import electroblob.wizardry.event.SpellCastEvent.Source;
@@ -17,6 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
@@ -34,7 +33,7 @@ public class ItemScroll extends Item {
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List<ItemStack> list){
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, NonNullList<ItemStack> list){
for(Spell spell : Spell.getSpells(Spell.nonContinuousSpells)){
list.add(new ItemStack(item, 1, spell.id()));
}
@@ -50,39 +49,40 @@ public class ItemScroll extends Item {
// Item's version of this method is, quite frankly, an abomination. Why is a deprecated method being used as such
// an integral part of the code? And what's the point in getUnlocalisedNameInefficiently?
public String getItemStackDisplayName(ItemStack stack){
/* Ok, so this method can be called from either the client or the server side. Obviously, on the client the
* spell name is either translated or obfuscated, then it is put into the item name as part of that translation.
* On the server side, however, there's a problem: on the one hand, the spell name shouldn't be obfuscated in
* case the server wants to do something with it, and in that case returning world-specific gobbledegook is
* not particularly helpful. On the other hand, something might happen that causes this method to be called on
* the server side, but the result to then be sent to the client, which means broken discovery system.
* Simply put, I can't predict that, and it's not my job to cater for other people's incorrect usage of code,
* especially when that might compromise some perfectly reasonable use (think Bibliocraft's 'best guess' book
* detection). */
* case the server wants to do something with it, and in that case returning world-specific gobbledegook is not
* particularly helpful. On the other hand, something might happen that causes this method to be called on the
* server side, but the result to then be sent to the client, which means broken discovery system. Simply put, I
* can't predict that, and it's not my job to cater for other people's incorrect usage of code, especially when
* that might compromise some perfectly reasonable use (think Bibliocraft's 'best guess' book detection). */
// TODO: Backport this proxy-based fix.
return Wizardry.proxy.getScrollDisplayName(stack);
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
ItemStack stack = player.getHeldItem(hand);
Spell spell = Spell.get(stack.getItemDamage());
// By default, scrolls have no modifiers - but with the event system, they could be added.
SpellModifiers modifiers = new SpellModifiers();
// If anything stops the spell working at this point, nothing else happens.
if(MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Pre(player, spell, modifiers, Source.SCROLL))){
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
}
if(!spell.isContinuous){
if(!world.isRemote){
if(spell.cast(world, player, hand, 0, new SpellModifiers())){
MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Post(player, spell, modifiers, Source.SCROLL));
if(spell.doesSpellRequirePacket()){
@@ -92,12 +92,12 @@ public class ItemScroll extends Item {
}
// Scrolls are consumed upon successful use in survival mode
if(!player.capabilities.isCreativeMode) stack.stackSize--;
if(!player.capabilities.isCreativeMode) stack.shrink(1);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
// This else if check was bugging me for AGES! I can't believe I didn't compare to ItemWand before.
// This else if check was bugging me for AGES! I can't believe I didn't compare to ItemWand before.
}else if(!spell.doesSpellRequirePacket()){
// Client-inconsistent spell casting. This code only runs client-side.
if(spell.cast(world, player, hand, 0, modifiers)){
@@ -1,7 +1,5 @@
package electroblob.wizardry.item;
import java.util.List;
import electroblob.wizardry.entity.projectile.EntitySmokeBomb;
import electroblob.wizardry.registry.WizardryTabs;
import net.minecraft.creativetab.CreativeTabs;
@@ -12,39 +10,42 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemSmokeBomb extends Item {
public ItemSmokeBomb(){
this.maxStackSize = 16;
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
public ItemSmokeBomb(){
this.maxStackSize = 16;
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
if(!player.capabilities.isCreativeMode){
--stack.stackSize;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
player.playSound(SoundEvents.ENTITY_SNOWBALL_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
ItemStack stack = player.getHeldItem(hand);
if(!world.isRemote){
EntitySmokeBomb smokebomb = new EntitySmokeBomb(world, player);
// This is the standard set of parameters for this method, used by snowballs and ender pearls.
smokebomb.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
world.spawnEntityInWorld(smokebomb);
}
if(!player.capabilities.isCreativeMode){
stack.shrink(1);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
player.playSound(SoundEvents.ENTITY_SNOWBALL_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if(!world.isRemote){
EntitySmokeBomb smokebomb = new EntitySmokeBomb(world, player);
// This is the standard set of parameters for this method, used by snowballs and ender pearls.
smokebomb.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
world.spawnEntity(smokebomb);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
}
@@ -1,7 +1,5 @@
package electroblob.wizardry.item;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -11,100 +9,104 @@ import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemSpectralArmour extends ItemArmor implements IConjuredItem {
public ItemSpectralArmour(ArmorMaterial material, int renderIndex, EntityEquipmentSlot armourType) {
public ItemSpectralArmour(ArmorMaterial material, int renderIndex, EntityEquipmentSlot armourType){
super(material, renderIndex, armourType);
this.setCreativeTab(null);
this.setMaxDamage(getBaseDuration());
}
@Override
public int getBaseDuration(){
return 1200;
}
@Override
public int getMaxDamage(ItemStack stack){
return this.getMaxDamageFromNBT(stack);
}
return this.getMaxDamageFromNBT(stack);
}
// Overridden to stop the enchantment trick making the name turn blue.
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.COMMON;
}
return EnumRarity.COMMON;
}
@Override
// This method allows the code for the item's timer to be greatly simplified by damaging it directly from
// onUpdate() and removing the workaround that involved WizardData and all sorts of crazy stuff.
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged){
if(oldStack != null || newStack != null){
if(!oldStack.isEmpty() || !newStack.isEmpty()){
// We only care about the situation where we specifically want the animation NOT to play.
if(oldStack.getItem() == newStack.getItem() && !slotChanged) return false;
}
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
}
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack stack){
int damage = stack.getItemDamage();
if(damage > stack.getMaxDamage()) player.inventory.clearMatchingItems(this, -1, 1, null);
stack.setItemDamage(damage + 1);
}
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return true;
}
@Override
public boolean getIsRepairable(ItemStack stack, ItemStack par2ItemStack){
return false;
}
return false;
}
@Override
public int getItemEnchantability(){
return 0;
}
return 0;
}
// Cannot be dropped
@Override
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player){
return false;
}
return false;
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) {
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type){
if(slot == EntityEquipmentSlot.LEGS) return "wizardry:textures/armour/spectral_armour_legs.png";
return "wizardry:textures/armour/spectral_armour.png";
}
@Override
@SideOnly(Side.CLIENT)
public net.minecraft.client.model.ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, EntityEquipmentSlot armorSlot,
net.minecraft.client.model.ModelBiped _default) {
public net.minecraft.client.model.ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack,
EntityEquipmentSlot armorSlot, net.minecraft.client.model.ModelBiped _default){
net.minecraft.client.renderer.GlStateManager.enableBlend();
net.minecraft.client.renderer.GlStateManager.tryBlendFuncSeparate(net.minecraft.client.renderer.GlStateManager.SourceFactor.SRC_ALPHA, net.minecraft.client.renderer.GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
net.minecraft.client.renderer.GlStateManager.SourceFactor.ONE, net.minecraft.client.renderer.GlStateManager.DestFactor.ZERO);
net.minecraft.client.renderer.GlStateManager.tryBlendFuncSeparate(
net.minecraft.client.renderer.GlStateManager.SourceFactor.SRC_ALPHA,
net.minecraft.client.renderer.GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
net.minecraft.client.renderer.GlStateManager.SourceFactor.ONE,
net.minecraft.client.renderer.GlStateManager.DestFactor.ZERO);
return super.getArmorModel(entityLiving, itemStack, armorSlot, _default);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item parItem, CreativeTabs parTab, List<ItemStack> parListSubItems){
parListSubItems.add(new ItemStack(this, 1));
}
@SideOnly(Side.CLIENT)
public void getSubItems(Item parItem, CreativeTabs parTab, NonNullList<ItemStack> parListSubItems){
parListSubItems.add(new ItemStack(this, 1));
}
}
@@ -1,7 +1,5 @@
package electroblob.wizardry.item;
import java.util.List;
import javax.annotation.Nullable;
import electroblob.wizardry.Wizardry;
@@ -24,6 +22,7 @@ import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
@@ -37,65 +36,64 @@ public class ItemSpectralBow extends ItemBow implements IConjuredItem {
this.setMaxDamage(getBaseDuration());
this.setNoRepair();
this.setCreativeTab(null);
this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter()
{
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
{
if (entityIn == null)
{
return 0.0F;
}
else
{
ItemStack itemstack = entityIn.getActiveItemStack();
// Mojang, observe - hardcoding item references into their own classes is NOT good Java.
return itemstack != null && itemstack.getItem() == ItemSpectralBow.this ? (float)(stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20.0F : 0.0F;
}
}
});
this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter()
{
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
{
return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F;
}
});
this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter(){
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn){
if(entityIn == null){
return 0.0F;
}else{
ItemStack itemstack = entityIn.getActiveItemStack();
// Mojang, observe - hardcoding item references into their own classes is NOT good Java.
return itemstack.getItem() == ItemSpectralBow.this
? (float)(stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20.0F
: 0.0F;
}
}
});
this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter(){
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn){
return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F
: 0.0F;
}
});
}
@Override
@SideOnly(Side.CLIENT)
@SideOnly(Side.CLIENT)
// Why does this still exist? Item models deal with this now, right?
public boolean isFull3D(){
return true;
}
@Override
public int getBaseDuration(){
return 600;
}
@Override
public int getMaxDamage(ItemStack stack){
return this.getMaxDamageFromNBT(stack);
}
return this.getMaxDamageFromNBT(stack);
}
@Override
// This method allows the code for the item's timer to be greatly simplified by damaging it directly from
// onUpdate() and removing the workaround that involved WizardData and all sorts of crazy stuff.
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged){
if(oldStack != null && newStack != null){
// TODO: For some reason there used to be an && here instead of an ||, which makes me wonder if there's a weird
// fix I did that needs removing.
if(!oldStack.isEmpty() || !newStack.isEmpty()){
// We only care about the situation where we specifically want the animation NOT to play.
if(oldStack.getItem() == newStack.getItem() && !slotChanged
// This code should only run on the client side, so using Minecraft is ok.
&& !Minecraft.getMinecraft().thePlayer.isHandActive()) return false;
// This code should only run on the client side, so using Minecraft is ok.
&& !Minecraft.getMinecraft().player.isHandActive())
return false;
}
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected){
int damage = stack.getItemDamage();
@@ -105,23 +103,26 @@ public class ItemSpectralBow extends ItemBow implements IConjuredItem {
stack.setItemDamage(damage + 1);
}
}
// The following two methods re-route the displayed durability through the proxies in order to override the pausing
// of the item timer when the bow is being pulled.
@Override
public double getDurabilityForDisplay(ItemStack stack){
return Wizardry.proxy.getConjuredBowDurability(stack);
}
public double getDefaultDurabilityForDisplay(ItemStack stack){
return super.getDurabilityForDisplay(stack);
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(stack, world, player, hand, true);
ItemStack stack = player.getHeldItem(hand);
ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(stack, world, player, hand,
true);
if(ret != null) return ret;
@@ -132,7 +133,7 @@ public class ItemSpectralBow extends ItemBow implements IConjuredItem {
}
@Override
@SideOnly(Side.CLIENT)
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return true;
}
@@ -152,7 +153,7 @@ public class ItemSpectralBow extends ItemBow implements IConjuredItem {
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player){
return false;
}
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count){
// player.getItemInUseMaxCount() is named incorrectly; you only have to look at the method to see what it really
@@ -165,55 +166,54 @@ public class ItemSpectralBow extends ItemBow implements IConjuredItem {
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entity, int timeLeft){
// Decreases the timer by the amount it should have been decreased while the bow was in use.
if(!world.isRemote) stack.setItemDamage(stack.getItemDamage() + (this.getMaxItemUseDuration(stack) - timeLeft));
if (entity instanceof EntityPlayer){
if(entity instanceof EntityPlayer){
EntityPlayer entityplayer = (EntityPlayer)entity;
int i = this.getMaxItemUseDuration(stack) - timeLeft;
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, world, (EntityPlayer)entity, i, true);
if (i < 0) return;
if(i < 0) return;
float f = getArrowVelocity(i);
if ((double)f >= 0.1D){
if((double)f >= 0.1D){
if(!world.isRemote){
if (!world.isRemote){
ItemArrow itemarrow = (ItemArrow)Items.ARROW;
EntityArrow entityarrow = itemarrow.createArrow(world, new ItemStack(itemarrow), entityplayer);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F,
f * 3.0F, 1.0F);
if (f == 1.0F)
{
if(f == 1.0F){
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0)
{
if(j > 0){
entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0)
{
if(k > 0){
entityarrow.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
{
if(EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0){
entityarrow.setFire(100);
}
entityarrow.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
world.spawnEntityInWorld(entityarrow);
world.spawnEntity(entityarrow);
}
world.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
world.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ,
SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F,
1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
entityplayer.addStat(StatList.getObjectUseStats(this));
}
@@ -222,8 +222,8 @@ public class ItemSpectralBow extends ItemBow implements IConjuredItem {
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> subItems){
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
}
@@ -1,13 +1,12 @@
package electroblob.wizardry.item;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -20,63 +19,63 @@ public class ItemSpectralPickaxe extends ItemPickaxe implements IConjuredItem {
this.setNoRepair();
this.setCreativeTab(null);
}
@Override
public int getBaseDuration(){
return 600;
}
@Override
public int getMaxDamage(ItemStack stack){
return this.getMaxDamageFromNBT(stack);
}
return this.getMaxDamageFromNBT(stack);
}
@Override
// This method allows the code for the item's timer to be greatly simplified by damaging it directly from
// onUpdate() and removing the workaround that involved WizardData and all sorts of crazy stuff.
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged){
if(oldStack != null || newStack != null){
if(!oldStack.isEmpty() || !newStack.isEmpty()){
// We only care about the situation where we specifically want the animation NOT to play.
if(oldStack.getItem() == newStack.getItem() && !slotChanged) return false;
}
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected){
int damage = stack.getItemDamage();
if(damage > stack.getMaxDamage()) entity.replaceItemInInventory(slot, null);
stack.setItemDamage(damage + 1);
}
@Override
@SideOnly(Side.CLIENT)
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return true;
}
@Override
public boolean getIsRepairable(ItemStack stack, ItemStack par2ItemStack){
return false;
}
return false;
}
@Override
public int getItemEnchantability(){
return 0;
}
return 0;
}
// Cannot be dropped
@Override
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player){
return false;
}
return false;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
}
@@ -1,82 +1,81 @@
package electroblob.wizardry.item;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemSpectralSword extends ItemSword implements IConjuredItem {
public ItemSpectralSword(ToolMaterial material) {
public ItemSpectralSword(ToolMaterial material){
super(material);
this.setMaxDamage(getBaseDuration());
this.setNoRepair();
this.setCreativeTab(null);
}
@Override
public int getBaseDuration(){
return 600;
}
@Override
public int getMaxDamage(ItemStack stack){
return this.getMaxDamageFromNBT(stack);
}
return this.getMaxDamageFromNBT(stack);
}
@Override
// This method allows the code for the item's timer to be greatly simplified by damaging it directly from
// onUpdate() and removing the workaround that involved WizardData and all sorts of crazy stuff.
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged){
if(oldStack != null || newStack != null){
if(!oldStack.isEmpty() || !newStack.isEmpty()){
// We only care about the situation where we specifically want the animation NOT to play.
if(oldStack.getItem() == newStack.getItem() && !slotChanged) return false;
}
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected){
int damage = stack.getItemDamage();
if(damage > stack.getMaxDamage()) entity.replaceItemInInventory(slot, null);
stack.setItemDamage(damage + 1);
}
@Override
@SideOnly(Side.CLIENT)
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return true;
}
@Override
public boolean getIsRepairable(ItemStack stack, ItemStack par2ItemStack){
return false;
}
return false;
}
@Override
public int getItemEnchantability(){
return 0;
}
return 0;
}
// Cannot be dropped
@Override
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player){
return false;
}
return false;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
}
@@ -15,64 +15,63 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
public class ItemSpellBook extends Item {
public ItemSpellBook() {
public ItemSpellBook(){
super();
this.setHasSubtypes(true);
this.setMaxStackSize(1);
this.setCreativeTab(WizardryTabs.SPELLS);
}
@Override
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list){
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> list){
// In this particular case, getTotalSpellCount() is a more efficient way of doing this since the spell instance
// is not required, only the id.
for(int i = 0; i < Spell.getTotalSpellCount(); i++){
// i+1 is used so that the metadata ties up with the id() method. In other words, the none spell has id
// 0 and since this is not used as a spell book the metadata starts at 1.
list.add(new ItemStack(item, 1, i+1));
}
for(int i = 0; i < Spell.getTotalSpellCount(); i++){
// i+1 is used so that the metadata ties up with the id() method. In other words, the none spell has id
// 0 and since this is not used as a spell book the metadata starts at 1.
list.add(new ItemStack(item, 1, i + 1));
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
ItemStack stack = player.getHeldItem(hand);
player.openGui(Wizardry.instance, WizardryGuiHandler.SPELL_BOOK, world, 0, 0, 0);
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemstack, EntityPlayer player, List<String> tooltip, boolean advanced){
// Tooltip is left blank for wizards buying generic spell books.
if(itemstack.getItemDamage() != OreDictionary.WILDCARD_VALUE){
Spell spell = Spell.get(itemstack.getItemDamage());
boolean discovered = true;
if(Wizardry.settings.discoveryMode && !player.capabilities.isCreativeMode && WizardData.get(player) != null
&& !WizardData.get(player).hasSpellBeenDiscovered(spell)){
discovered = false;
}
// Element colour is not given for undiscovered spells
tooltip.add(discovered ? "\u00A77" + spell.getDisplayNameWithFormatting() : "#\u00A79" + SpellGlyphData.getGlyphName(spell, player.worldObj));
tooltip.add(discovered ? "\u00A77" + spell.getDisplayNameWithFormatting()
: "#\u00A79" + SpellGlyphData.getGlyphName(spell, player.world));
tooltip.add(spell.tier.getDisplayNameWithFormatting());
}
/* Removed to streamline the tooltip a bit. Information is now within the book.
if(spell.isContinuous){
tooltip.add("\u00A79Mana Cost: " + spell.cost + " per second");
}else{
tooltip.add("\u00A79Mana Cost: " + spell.cost);
}
*/
/* Removed to streamline the tooltip a bit. Information is now within the book. if(spell.isContinuous){
* tooltip.add("\u00A79Mana Cost: " + spell.cost + " per second"); }else{ tooltip.add("\u00A79Mana Cost: " +
* spell.cost); } */
}
@Override
@SideOnly(Side.CLIENT)
public net.minecraft.client.gui.FontRenderer getFontRenderer(ItemStack stack){
@@ -33,6 +33,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
@@ -41,7 +42,8 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/** This class is (literally) where the magic happens! All wand types are single instances of this class. There's a lot
/**
* This class is (literally) where the magic happens! All wand types are single instances of this class. There's a lot
* of quite hard-to-read code in here, but unfortunately there's not much I can do about that. For this reason, I have
* written the {@link WandHelper} class.<i> I strongly recommend you use it for interacting with wand items wherever
* possible.</i>
@@ -52,13 +54,15 @@ import net.minecraftforge.fml.relauncher.SideOnly;
* - onItemRightClick is where non-continuous spells are cast, and it sets the item in use for continuous spells<br>
* - onUsingTick does the casting for continuous spells<br>
* - onUpdate deals with the cooldowns for the spells
* @since Wizardry 1.0 */
*
* @since Wizardry 1.0
*/
public class ItemWand extends Item {
public Tier tier;
public Element element;
public ItemWand(Tier tier, Element element) {
public ItemWand(Tier tier, Element element){
super();
setMaxStackSize(1);
if(element == null || tier == Tier.BASIC){
@@ -83,7 +87,7 @@ public class ItemWand extends Item {
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item parItem, CreativeTabs parTab, List<ItemStack> parListSubItems){
public void getSubItems(Item parItem, CreativeTabs parTab, NonNullList<ItemStack> parListSubItems){
parListSubItems.add(new ItemStack(this, 1));
}
@@ -91,7 +95,8 @@ public class ItemWand extends Item {
@Override
public int getMaxDamage(ItemStack itemstack){
// + 0.5f corrects small float errors rounding down
return (int)(super.getMaxDamage(itemstack)*(1.0f + Constants.STORAGE_INCREASE_PER_LEVEL * WandHelper.getUpgradeLevel(itemstack, WizardryItems.storage_upgrade)) + 0.5f);
return (int)(super.getMaxDamage(itemstack) * (1.0f + Constants.STORAGE_INCREASE_PER_LEVEL
* WandHelper.getUpgradeLevel(itemstack, WizardryItems.storage_upgrade)) + 0.5f);
}
@Override
@@ -105,15 +110,18 @@ public class ItemWand extends Item {
WandHelper.decrementCooldowns(itemstack);
// Decrements wand damage (increases mana) every 1.5 seconds if it has a condenser upgrade
if(!world.isRemote && itemstack.isItemDamaged() && world.getWorldTime() % Constants.CONDENSER_TICK_INTERVAL == 0){
if(!world.isRemote && itemstack.isItemDamaged()
&& world.getWorldTime() % Constants.CONDENSER_TICK_INTERVAL == 0){
// If the upgrade level is 0, this does nothing anyway.
itemstack.setItemDamage(itemstack.getItemDamage() - WandHelper.getUpgradeLevel(itemstack, WizardryItems.condenser_upgrade));
itemstack.setItemDamage(
itemstack.getItemDamage() - WandHelper.getUpgradeLevel(itemstack, WizardryItems.condenser_upgrade));
}
if(entity instanceof EntityPlayer && this.element != null && this.element != Element.MAGIC){
// As it stands, this will trigger every tick. Not ideal, but I can't find a way to detect if a player
// has a certain achievement.
// EDIT: There is a way to check, using StatFileWriter#hasAchievementUnlocked, but this ends up calling the same
// EDIT: There is a way to check, using StatFileWriter#hasAchievementUnlocked, but this ends up calling the
// same
// thing as addStat anyway, meaning there's no point and it's probably not much of a problem anyway.
((EntityPlayer)entity).addStat(WizardryAchievements.elemental);
}
@@ -124,11 +132,12 @@ public class ItemWand extends Item {
// This method does some VERY strange things! Despite its name, it also seems to affect the updating of NBT...
if(oldStack != null || newStack != null){
if(!oldStack.isEmpty() || !newStack.isEmpty()){
// We only care about the situation where we specifically want the animation NOT to play.
if(oldStack.getItem() == newStack.getItem() && !slotChanged
&& oldStack.getItem() instanceof ItemWand && newStack.getItem() instanceof ItemWand
&& WandHelper.getCurrentSpell(oldStack) == WandHelper.getCurrentSpell(newStack)) return false;
if(oldStack.getItem() == newStack.getItem() && !slotChanged && oldStack.getItem() instanceof ItemWand
&& newStack.getItem() instanceof ItemWand
&& WandHelper.getCurrentSpell(oldStack) == WandHelper.getCurrentSpell(newStack))
return false;
}
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
@@ -149,7 +158,9 @@ public class ItemWand extends Item {
public void addInformation(ItemStack itemstack, EntityPlayer player, List<String> text, boolean advanced){
// +0.5f is necessary due to the error in the way floats are calculated.
if(element != null) text.add("\u00A78" + net.minecraft.client.resources.I18n.format("item.wizardry:wand.buff", (int)((tier.level+1)*Constants.DAMAGE_INCREASE_PER_TIER*100 + 0.5f) + "%", element.getDisplayName()));
if(element != null) text.add("\u00A78" + net.minecraft.client.resources.I18n.format("item.wizardry:wand.buff",
(int)((tier.level + 1) * Constants.DAMAGE_INCREASE_PER_TIER * 100 + 0.5f) + "%",
element.getDisplayName()));
Spell spell = WandHelper.getCurrentSpell(itemstack);
@@ -159,29 +170,34 @@ public class ItemWand extends Item {
discovered = false;
}
text.add("\u00A77" + net.minecraft.client.resources.I18n.format("item.wizardry:wand.spell", discovered ? "\u00A77" + spell.getDisplayNameWithFormatting() : "#\u00A79" + SpellGlyphData.getGlyphName(spell, player.worldObj)));
text.add("\u00A77" + net.minecraft.client.resources.I18n.format("item.wizardry:wand.spell",
discovered ? "\u00A77" + spell.getDisplayNameWithFormatting()
: "#\u00A79" + SpellGlyphData.getGlyphName(spell, player.world)));
text.add("\u00A79" + net.minecraft.client.resources.I18n.format("item.wizardry:wand.mana", (this.getMaxDamage(itemstack) - this.getDamage(itemstack)), this.getMaxDamage(itemstack)));
text.add("\u00A79" + net.minecraft.client.resources.I18n.format("item.wizardry:wand.mana",
(this.getMaxDamage(itemstack) - this.getDamage(itemstack)), this.getMaxDamage(itemstack)));
}
@Override
public String getItemStackDisplayName(ItemStack stack){
return (this.element == null ? "" : this.element.getFormattingCode()) + super.getItemStackDisplayName(stack);
}
// Continuous spells use the onUsingItemTick method instead of this one.
/* An important thing to note about this method: it is only called on the server and the client of the player
* holding the item (I call this client-inconsistency). This means if you spawn particles here they will not show up
* on other players' screens. Instead, this must be done via packets. */
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
ItemStack stack = player.getHeldItem(hand);
// Alternate right-click function; overrides spell casting.
if(this.selectMinionTarget(player, world)) return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
Spell spell = WandHelper.getCurrentSpell(stack);
SpellModifiers modifiers = this.calculateModifiers(stack, spell);
// If anything stops the spell working at this point, nothing else happens.
if(MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Pre(player, spell, modifiers, Source.WAND))){
return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
@@ -197,7 +213,7 @@ public class ItemWand extends Item {
// Conditions for the spell to be attempted. The tier check is a failsafe; it should never be false unless the
// NBT is modified directly.
if(!spell.isContinuous && spell.tier.level <= this.tier.level
// Checks that the wand has enough mana to cast the spell
// Checks that the wand has enough mana to cast the spell
&& spell.cost <= (stack.getMaxDamage() - stack.getItemDamage())
// Checks that the spell is not in cooldown or that the player is in creative mode
&& (WandHelper.getCurrentCooldown(stack) == 0 || player.capabilities.isCreativeMode)){
@@ -207,7 +223,7 @@ public class ItemWand extends Item {
if(!world.isRemote){
if(spell.cast(world, player, hand, 0, modifiers)){
MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Post(player, spell, modifiers, Source.WAND));
// = Packets =
@@ -225,11 +241,15 @@ public class ItemWand extends Item {
// Spells only have a cooldown in survival
if(!player.capabilities.isCreativeMode){
float cooldownMultiplier = 1.0f - WandHelper.getUpgradeLevel(stack, WizardryItems.cooldown_upgrade)*Constants.COOLDOWN_REDUCTION_PER_LEVEL;
float cooldownMultiplier = 1.0f
- WandHelper.getUpgradeLevel(stack, WizardryItems.cooldown_upgrade)
* Constants.COOLDOWN_REDUCTION_PER_LEVEL;
if(player.isPotionActive(WizardryPotions.font_of_mana)){
// Dividing by this rather than setting it takes upgrades and font of mana into account simultaneously
cooldownMultiplier /= 2 + player.getActivePotionEffect(WizardryPotions.font_of_mana).getAmplifier();
// Dividing by this rather than setting it takes upgrades and font of mana into account
// simultaneously
cooldownMultiplier /= 2
+ player.getActivePotionEffect(WizardryPotions.font_of_mana).getAmplifier();
}
WandHelper.setCurrentCooldown(stack, (int)(spell.cooldown * cooldownMultiplier));
@@ -239,7 +259,8 @@ public class ItemWand extends Item {
// The spell costs 20% less for every armour piece of the matching element.
int armourPieces = getMatchingArmourCount(player, spell);
stack.damageItem((int)(spell.cost * (1.0f - armourPieces*Constants.COST_REDUCTION_PER_ARMOUR)), player);
stack.damageItem((int)(spell.cost * (1.0f - armourPieces * Constants.COST_REDUCTION_PER_ARMOUR)),
player);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
@@ -264,20 +285,23 @@ public class ItemWand extends Item {
if(user instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)user;
Spell spell = WandHelper.getCurrentSpell(stack);
SpellModifiers modifiers = this.calculateModifiers(stack, spell);
int castingTick = stack.getMaxItemUseDuration() - count;
if(MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Tick(player, spell, modifiers, Source.WAND, castingTick))) return;
if(MinecraftForge.EVENT_BUS
.post(new SpellCastEvent.Tick(player, spell, modifiers, Source.WAND, castingTick)))
return;
// Continuous spells (these must check if they can be cast each tick since the mana changes)
if(spell.isContinuous && spell.tier.level <= this.tier.level
&& spell.cost/5 <= (stack.getMaxDamage() - stack.getItemDamage())){
&& spell.cost / 5 <= (stack.getMaxDamage() - stack.getItemDamage())){
if(spell.cast(player.worldObj, player, player.getActiveHand(), castingTick, modifiers)){
if(spell.cast(player.world, player, player.getActiveHand(), castingTick, modifiers)){
if(castingTick == 0) MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Post(player, spell, modifiers, Source.WAND));
if(castingTick == 0)
MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Post(player, spell, modifiers, Source.WAND));
// = Mana cost =
// Divides the mana cost over a second appropriately; since damage is an integer it cannot
@@ -285,7 +309,8 @@ public class ItemWand extends Item {
// Now does five times per second regardless of the spell cost, but each time it does 1/5 of the
// cost per second.
int tickNumber = (count % 20) + 1;
// Tests if the tick counter is a multiple of 4 plus 1, i.e. is true when tickNumber = 1, 5, 9, 13 or 17.
// Tests if the tick counter is a multiple of 4 plus 1, i.e. is true when tickNumber = 1, 5, 9, 13
// or 17.
// Made a slight adjustment since the counter starts on 1 and not 4.
if(tickNumber % 4 == 1){
@@ -293,20 +318,26 @@ public class ItemWand extends Item {
switch(armourPieces){
case 0: stack.damageItem(spell.cost/5, player);
break;
case 0:
stack.damageItem(spell.cost / 5, player);
break;
case 1: if(tickNumber != 17) stack.damageItem(spell.cost/5, player);
break;
case 1:
if(tickNumber != 17) stack.damageItem(spell.cost / 5, player);
break;
case 2: if(tickNumber != 9 && tickNumber != 17) stack.damageItem(spell.cost/5, player);
break;
case 2:
if(tickNumber != 9 && tickNumber != 17) stack.damageItem(spell.cost / 5, player);
break;
case 3: if(tickNumber != 5 && tickNumber != 13 && tickNumber != 17) stack.damageItem(spell.cost/5, player);
break;
case 3:
if(tickNumber != 5 && tickNumber != 13 && tickNumber != 17)
stack.damageItem(spell.cost / 5, player);
break;
case 4: if(tickNumber == 1) stack.damageItem(spell.cost/5, player);
break;
case 4:
if(tickNumber == 1) stack.damageItem(spell.cost / 5, player);
break;
}
}
@@ -316,13 +347,15 @@ public class ItemWand extends Item {
}
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity, EnumHand hand){
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity,
EnumHand hand){
if(player.isSneaking() && entity instanceof EntityPlayer && WizardData.get(player) != null){
// This is one of those "the method doing the work looks as if it's just returning a value" situations.
// ... I know, right?! I feel very programmer-y. But it's not too confusing here, and it looks neat.
String string = WizardData.get(player).toggleAlly((EntityPlayer)entity) ? "item.wizardry:wand.addally" : "item.wizardry:wand.removeally";
if(!player.worldObj.isRemote) player.addChatMessage(new TextComponentTranslation(string, entity.getName()));
String string = WizardData.get(player).toggleAlly((EntityPlayer)entity) ? "item.wizardry:wand.addally"
: "item.wizardry:wand.removeally";
if(!player.world.isRemote) player.sendMessage(new TextComponentTranslation(string, entity.getName()));
return true;
}
@@ -336,19 +369,24 @@ public class ItemWand extends Item {
// Now we only need to add multipliers if they are not 1.
int level = WandHelper.getUpgradeLevel(stack, WizardryItems.range_upgrade);
if(level > 0) modifiers.set(WizardryItems.range_upgrade, 1.0f + level * Constants.RANGE_INCREASE_PER_LEVEL, true);
if(level > 0)
modifiers.set(WizardryItems.range_upgrade, 1.0f + level * Constants.RANGE_INCREASE_PER_LEVEL, true);
level = WandHelper.getUpgradeLevel(stack, WizardryItems.duration_upgrade);
if(level > 0) modifiers.set(WizardryItems.duration_upgrade, 1.0f + level * Constants.DURATION_INCREASE_PER_LEVEL, false);
if(level > 0)
modifiers.set(WizardryItems.duration_upgrade, 1.0f + level * Constants.DURATION_INCREASE_PER_LEVEL, false);
level = WandHelper.getUpgradeLevel(stack, WizardryItems.blast_upgrade);
if(level > 0) modifiers.set(WizardryItems.blast_upgrade, 1.0f + level * Constants.BLAST_RADIUS_INCREASE_PER_LEVEL, true);
if(level > 0)
modifiers.set(WizardryItems.blast_upgrade, 1.0f + level * Constants.BLAST_RADIUS_INCREASE_PER_LEVEL, true);
// I would have liked to have made potion effects increase in strength according to the damage multiplier,
// but the amplifier level is too discrete to make this work. For example, wither 3 for 10 seconds will kill a
// normal mob on full 20 health, but wither 2 for the same duration only deals about 6 hearts of damage in total.
// normal mob on full 20 health, but wither 2 for the same duration only deals about 6 hearts of damage in
// total.
if(this.element == spell.element){
modifiers.set(SpellModifiers.DAMAGE, 1.0f + (this.tier.level + 1) * Constants.DAMAGE_INCREASE_PER_TIER, true);
modifiers.set(SpellModifiers.DAMAGE, 1.0f + (this.tier.level + 1) * Constants.DAMAGE_INCREASE_PER_TIER,
true);
}
return modifiers;
@@ -364,7 +402,8 @@ public class ItemWand extends Item {
ItemStack armour = player.getItemStackFromSlot(slot);
if(armour != null && armour.getItem() instanceof ItemWizardArmour
&& ((ItemWizardArmour)armour.getItem()).element == spell.element) armourPieces++;
&& ((ItemWizardArmour)armour.getItem()).element == spell.element)
armourPieces++;
}
return armourPieces;
@@ -5,6 +5,7 @@ import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.constants.Constants;
import electroblob.wizardry.constants.Element;
import electroblob.wizardry.registry.WizardryAchievements;
import electroblob.wizardry.registry.WizardryTabs;
import electroblob.wizardry.spell.Petrify;
import electroblob.wizardry.util.WizardryUtilities;
@@ -19,154 +20,161 @@ import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.ISpecialArmor;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@Mod.EventBusSubscriber
public class ItemWizardArmour extends ItemArmor implements ISpecialArmor {
public Element element;
public ItemWizardArmour(ArmorMaterial material, int renderIndex, EntityEquipmentSlot armourType, Element element) {
public ItemWizardArmour(ArmorMaterial material, int renderIndex, EntityEquipmentSlot armourType, Element element){
super(material, renderIndex, armourType);
this.element = element;
this.setCreativeTab(WizardryTabs.WIZARDRY);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced){
if(stack.hasTagCompound() && stack.getTagCompound().getBoolean("legendary")) tooltip.add("\u00A7d" + net.minecraft.client.resources.I18n.format("item.wizardry:wizard_armour.legendary"));
if(element != null) tooltip.add("\u00A78" + net.minecraft.client.resources.I18n.format("item.wizardry:wizard_armour.buff", (int)(Constants.COST_REDUCTION_PER_ARMOUR*100) + "%", element.getDisplayName()));
tooltip.add("\u00A79" + net.minecraft.client.resources.I18n.format("item.wizardry:wizard_armour.mana", (this.getMaxDamage(stack) - this.getDamage(stack)), this.getMaxDamage(stack)));
if(stack.hasTagCompound() && stack.getTagCompound().getBoolean("legendary")) tooltip
.add("\u00A7d" + net.minecraft.client.resources.I18n.format("item.wizardry:wizard_armour.legendary"));
if(element != null)
tooltip.add("\u00A78" + net.minecraft.client.resources.I18n.format("item.wizardry:wizard_armour.buff",
(int)(Constants.COST_REDUCTION_PER_ARMOUR * 100) + "%", element.getDisplayName()));
tooltip.add("\u00A79" + net.minecraft.client.resources.I18n.format("item.wizardry:wizard_armour.mana",
(this.getMaxDamage(stack) - this.getDamage(stack)), this.getMaxDamage(stack)));
}
@Override
public String getItemStackDisplayName(ItemStack stack){
return ((this.element == null ? "" : this.element.getFormattingCode()) + super.getItemStackDisplayName(stack));
}
return ((this.element == null ? "" : this.element.getFormattingCode()) + super.getItemStackDisplayName(stack));
}
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return stack.hasTagCompound() && stack.getTagCompound().getBoolean("legendary");
}
@Override
@SideOnly(Side.CLIENT)
public net.minecraft.client.model.ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack, EntityEquipmentSlot armourSlot, net.minecraft.client.model.ModelBiped _default){
public net.minecraft.client.model.ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemStack,
EntityEquipmentSlot armourSlot, net.minecraft.client.model.ModelBiped _default){
net.minecraft.client.model.ModelBiped model = Wizardry.proxy.getWizardArmourModel();
// Legs use modelBiped
if(armourSlot == EntityEquipmentSlot.LEGS) return null;
if(model != null){
model.bipedHead.showModel = armourSlot == EntityEquipmentSlot.HEAD;
model.bipedHeadwear.showModel = false;
model.bipedBody.showModel = armourSlot == EntityEquipmentSlot.CHEST || armourSlot == EntityEquipmentSlot.LEGS;
model.bipedBody.showModel = armourSlot == EntityEquipmentSlot.CHEST
|| armourSlot == EntityEquipmentSlot.LEGS;
model.bipedRightArm.showModel = armourSlot == EntityEquipmentSlot.CHEST;
model.bipedLeftArm.showModel = armourSlot == EntityEquipmentSlot.CHEST;
model.bipedRightLeg.showModel = armourSlot == EntityEquipmentSlot.LEGS || armourSlot == EntityEquipmentSlot.FEET;
model.bipedLeftLeg.showModel = armourSlot == EntityEquipmentSlot.LEGS || armourSlot == EntityEquipmentSlot.FEET;
model.bipedRightLeg.showModel = armourSlot == EntityEquipmentSlot.LEGS
|| armourSlot == EntityEquipmentSlot.FEET;
model.bipedLeftLeg.showModel = armourSlot == EntityEquipmentSlot.LEGS
|| armourSlot == EntityEquipmentSlot.FEET;
model.isSneak = entityLiving.isSneaking();
model.isRiding = entityLiving.isRiding();
model.isChild = entityLiving.isChild();
boolean leftHanded = entityLiving.getPrimaryHand() == EnumHandSide.LEFT;
ItemStack itemstackR = leftHanded ? entityLiving.getHeldItemOffhand() : entityLiving.getHeldItemMainhand();
ItemStack itemstackL = leftHanded ? entityLiving.getHeldItemMainhand() : entityLiving.getHeldItemOffhand();
if (itemstackR != null)
{
model.rightArmPose = net.minecraft.client.model.ModelBiped.ArmPose.ITEM;
if(itemstackR != null){
model.rightArmPose = net.minecraft.client.model.ModelBiped.ArmPose.ITEM;
if (entityLiving.getItemInUseCount() > 0)
{
EnumAction enumaction = itemstackR.getItemUseAction();
if(entityLiving.getItemInUseCount() > 0){
EnumAction enumaction = itemstackR.getItemUseAction();
if (enumaction == EnumAction.BLOCK)
{
model.rightArmPose = net.minecraft.client.model.ModelBiped.ArmPose.BLOCK;
}
else if (enumaction == EnumAction.BOW)
{
model.rightArmPose = net.minecraft.client.model.ModelBiped.ArmPose.BOW_AND_ARROW;
}
}
}
if(enumaction == EnumAction.BLOCK){
model.rightArmPose = net.minecraft.client.model.ModelBiped.ArmPose.BLOCK;
}else if(enumaction == EnumAction.BOW){
model.rightArmPose = net.minecraft.client.model.ModelBiped.ArmPose.BOW_AND_ARROW;
}
}
}
if (itemstackL != null)
{
model.leftArmPose = net.minecraft.client.model.ModelBiped.ArmPose.ITEM;
if(itemstackL != null){
model.leftArmPose = net.minecraft.client.model.ModelBiped.ArmPose.ITEM;
if (entityLiving.getItemInUseCount() > 0)
{
EnumAction enumaction1 = itemstackL.getItemUseAction();
if(entityLiving.getItemInUseCount() > 0){
EnumAction enumaction1 = itemstackL.getItemUseAction();
if (enumaction1 == EnumAction.BLOCK)
{
model.leftArmPose = net.minecraft.client.model.ModelBiped.ArmPose.BLOCK;
}
else if (enumaction1 == EnumAction.BOW)
{
model.leftArmPose = net.minecraft.client.model.ModelBiped.ArmPose.BOW_AND_ARROW;
}
}
}
if(enumaction1 == EnumAction.BLOCK){
model.leftArmPose = net.minecraft.client.model.ModelBiped.ArmPose.BLOCK;
}else if(enumaction1 == EnumAction.BOW){
model.leftArmPose = net.minecraft.client.model.ModelBiped.ArmPose.BOW_AND_ARROW;
}
}
}
}
return model;
}
return model;
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) {
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type){
// Returns a completely transparent texture if the player is invisible. This is such an annoyingly easy
// fix, considering how long I spent trying to do this before - a bit of lateral thinking was all it took.
// Do note however that a texture pack could override this.
if(entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isInvisible()
&& !entity.getEntityData().getBoolean(Petrify.NBT_KEY)) return "wizardry:textures/armour/invisible_armour.png";
if(slot == EntityEquipmentSlot.LEGS) return this.element == null ? "wizardry:textures/armour/wizard_armour_legs.png" :
"wizardry:textures/armour/wizard_armour_" + this.element.getUnlocalisedName() + "_legs.png";
return this.element == null ? "wizardry:textures/armour/wizard_armour.png" :
"wizardry:textures/armour/wizard_armour_" + this.element.getUnlocalisedName() + ".png";
&& !entity.getEntityData().getBoolean(Petrify.NBT_KEY))
return "wizardry:textures/armour/invisible_armour.png";
if(slot == EntityEquipmentSlot.LEGS)
return this.element == null ? "wizardry:textures/armour/wizard_armour_legs.png"
: "wizardry:textures/armour/wizard_armour_" + this.element.getUnlocalisedName() + "_legs.png";
return this.element == null ? "wizardry:textures/armour/wizard_armour.png"
: "wizardry:textures/armour/wizard_armour_" + this.element.getUnlocalisedName() + ".png";
}
@Override
public boolean getIsRepairable(ItemStack stack, ItemStack par2ItemStack)
{
return false;
}
@Override
public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slotIndex){
public boolean getIsRepairable(ItemStack stack, ItemStack par2ItemStack){
return false;
}
@Override
public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage,
int slotIndex){
EntityEquipmentSlot slot = getArmorSlotFromIndex(slotIndex);
if (!source.isUnblockable() && armor.getItemDamage() < armor.getMaxDamage()){
if(!source.isUnblockable() && armor.getItemDamage() < armor.getMaxDamage()){
if(armor.hasTagCompound() && armor.getTagCompound().getBoolean("legendary")){
// Legendary armour gives full 10 shields, like diamond.
return new ArmorProperties(0, ArmorMaterial.DIAMOND.getDamageReductionAmount(slot) / 25D, armor.getMaxDamage() + 1 - armor.getItemDamage());
return new ArmorProperties(0, ArmorMaterial.DIAMOND.getDamageReductionAmount(slot) / 25D,
armor.getMaxDamage() + 1 - armor.getItemDamage());
}else{
return new ArmorProperties(0, this.damageReduceAmount / 25D, armor.getMaxDamage() + 1 - armor.getItemDamage());
return new ArmorProperties(0, this.damageReduceAmount / 25D,
armor.getMaxDamage() + 1 - armor.getItemDamage());
}
}else{
return new ArmorProperties(0, 0, 0);
}
}else{
return new ArmorProperties(0, 0, 0);
}
}
@Override
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slotIndex) {
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slotIndex){
EntityEquipmentSlot slot = getArmorSlotFromIndex(slotIndex);
if(armor.getItemDamage() < armor.getMaxDamage()){
if(armor.hasTagCompound() && armor.getTagCompound().getBoolean("legendary")){
// Legendary armour gives full 10 shields, like diamond.
@@ -191,21 +199,23 @@ public class ItemWizardArmour extends ItemArmor implements ISpecialArmor {
}
}
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
/** Returns the EntityEquipmentSlot for which index() returns an integer equal to the passed in slotIndex and
* which is an armour slot (not a hand slot). This only exists because the 1.10.2 version of Forge still uses
* an integer slot index in ISpecialArmor instead of an EntityEquipmentSlot. */
// NOTE: Remove in 1.11.2
private EntityEquipmentSlot getArmorSlotFromIndex(int slotIndex) {
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> subItems){
subItems.add(new ItemStack(this, 1));
}
/**
* Returns the EntityEquipmentSlot for which index() returns an integer equal to the passed in slotIndex and which
* is an armour slot (not a hand slot). This only exists because the 1.10.2/1.11.2 versions of Forge still uses an
* integer slot index in ISpecialArmor instead of an EntityEquipmentSlot.
*/
// NOTE: Remove in 1.12.2
private EntityEquipmentSlot getArmorSlotFromIndex(int slotIndex){
// Had to pick something to begin with.
EntityEquipmentSlot slot = EntityEquipmentSlot.HEAD;
for(EntityEquipmentSlot s : WizardryUtilities.ARMOUR_SLOTS){
if(s.getIndex() == slotIndex){
slot = s;
@@ -214,4 +224,21 @@ public class ItemWizardArmour extends ItemArmor implements ISpecialArmor {
return slot;
}
@SubscribeEvent
public static void onLivingUpdateEvent(LivingUpdateEvent event){
if(event.getEntityLiving() instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)event.getEntityLiving();
for(ItemStack stack : player.getArmorInventoryList()){
if(stack == null || !(stack.getItem() instanceof ItemWizardArmour)){
return; // If any of the armour slots doesn't contain wizard armour, don't trigger the achievement.
}
}
// If it gets this far, then all slots must be wizard armour, so trigger the achievement.
player.addStat(WizardryAchievements.armour_set);
}
}
}
@@ -12,6 +12,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -20,8 +21,8 @@ public class ItemWizardHandbook extends Item {
// Yep, I hardcoded my own name into the mod. Don't want people changing it now, do I?
private static final String AUTHOR = "Electroblob";
public ItemWizardHandbook() {
public ItemWizardHandbook(){
super();
this.setMaxStackSize(1);
this.setCreativeTab(WizardryTabs.WIZARDRY);
@@ -29,18 +30,20 @@ public class ItemWizardHandbook extends Item {
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced){
tooltip.add("\u00A77" + net.minecraft.client.resources.I18n.format("item.wizardry:wizard_handbook.desc", AUTHOR));
tooltip.add(
"\u00A77" + net.minecraft.client.resources.I18n.format("item.wizardry:wizard_handbook.desc", AUTHOR));
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
ItemStack stack = player.getHeldItem(hand);
player.openGui(Wizardry.instance, WizardryGuiHandler.WIZARD_HANDBOOK, world, 0, 0, 0);
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> items){
items.add(new ItemStack(this, 1));
}
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, NonNullList<ItemStack> items){
items.add(new ItemStack(this, 1));
}
}