Miscellaneous setup

This commit is contained in:
Electroblob
2018-01-30 16:02:13 +00:00
parent da6b007a3a
commit 2af7329478
59 changed files with 1833 additions and 13509 deletions
@@ -2,24 +2,23 @@ package electroblob.wizardry.item;
import java.util.List;
import electroblob.wizardry.WizardData;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.event.SpellCastEvent;
import electroblob.wizardry.event.SpellCastEvent.Source;
import electroblob.wizardry.packet.PacketCastSpell;
import electroblob.wizardry.packet.WizardryPacketHandler;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.registry.WizardryTabs;
import electroblob.wizardry.spell.Spell;
import electroblob.wizardry.util.SpellModifiers;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -36,7 +35,6 @@ public class ItemScroll extends Item {
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List<ItemStack> list){
// Isn't this sooooo much neater with the filter thing?
for(Spell spell : Spell.getSpells(Spell.nonContinuousSpells)){
list.add(new ItemStack(item, 1, spell.id()));
}
@@ -70,59 +68,42 @@ public class ItemScroll extends Item {
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
if(player.isPotionActive(WizardryPotions.arcane_jammer)) return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);;
Spell spell = Spell.get(stack.getItemDamage());
// If a spell is disabled in the config, it will not work.
if(!spell.isEnabled()){
if(!world.isRemote) player.addChatMessage(new TextComponentTranslation("spell.disabled", spell.getNameForTranslationFormatted()));
// 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(spell.chargeup > 0 && !entityplayer.isUsingItem()){
// Spells with a chargeup time are now handled separately.
entityplayer.setItemInUse(stack, this.getMaxItemUseDuration(stack));
return stack;
}
*/
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()){
// Sends a packet to all players in dimension to tell them to spawn particles.
IMessage msg = new PacketCastSpell.Message(player.getEntityId(), hand, spell.id(), new SpellModifiers());
IMessage msg = new PacketCastSpell.Message(player.getEntityId(), hand, spell.id(), modifiers);
WizardryPacketHandler.net.sendToDimension(msg, world.provider.getDimension());
}
if(!player.capabilities.isCreativeMode && !WizardData.get(player).hasSpellBeenDiscovered(spell) && Wizardry.settings.discoveryMode){
player.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1.25f, 1);
if(!player.worldObj.isRemote) player.addChatMessage(new TextComponentTranslation("spell.discover", spell.getNameForTranslationFormatted()));
}
WizardData.get(player).discoverSpell(spell);
// Scrolls are consumed upon successful use in survival mode
if(!player.capabilities.isCreativeMode) stack.stackSize--;
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
// Client-inconsistent spell casting. The code inside the else if statement only runs client-side.
// This else if check was bugging me for AGES! I can't believe I didn't compare to ItemWand before.
}else if(!spell.doesSpellRequirePacket()){
// This is all that needs to happen, because everything above works fine on just the server side.
if(spell.cast(world, player, hand, 0, new SpellModifiers())){
// Added in version 1.1.3 to fix the client-side spell discovery not updating for spells with the
// packet optimisation.
if(WizardData.get(player) != null){
WizardData.get(player).discoverSpell(spell);
}
new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
// Client-inconsistent spell casting. This code only runs client-side.
if(spell.cast(world, player, hand, 0, modifiers)){
// This is all that needs to happen, because everything above works fine on just the server side.
MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Post(player, spell, modifiers, Source.SCROLL));
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
}
}