package me.km.items; import me.km.KajetansMod; import me.km.api.GlobalText; import me.km.effects.ActiveEffectBase; import me.km.effects.Effect; import me.km.effects.EffectCause; import me.km.effects.EffectUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; public class ItemWand extends ItemWeapon { private final int strength; public ItemWand(String name, String local, ToolMaterial material, int strength) { super(name, local, material, 0, -3); this.strength = strength; } @Override public ActionResult onItemRightClick(World w, EntityPlayer p, EnumHand hand) { if(w.isRemote || KajetansMod.singlePlayer) { return new ActionResult(EnumActionResult.SUCCESS, p.getHeldItem(hand)); } if(!KajetansMod.worldManager.getWorldPreferences(w).scrolls) { KajetansMod.effects.send(p, GlobalText.noScrolls()); return new ActionResult(EnumActionResult.FAIL, p.getHeldItem(hand)); } int wand = EffectUtils.getEffectLevel(p, Effect.USE_WAND); if(wand < 1) { KajetansMod.effects.send(p, "Du kannst keine Zauberstäbe benutzen."); return new ActionResult(EnumActionResult.FAIL, p.getHeldItem(hand)); } ItemStack stack = p.getHeldItem(hand); try { Class c = EffectUtils.getEffectClass(stack.getDisplayName().substring(2)); if(c == null) { throw new Exception(); } if(ActiveEffectBase.executeEffect(c, (EntityPlayerMP) p, strength, 0, EffectCause.WAND)) { if(!p.isCreative()) { stack.damageItem(1, p); } } } catch(Exception ex) { KajetansMod.effects.send(p, "Der Zauberstab ist korrupt."); return new ActionResult(EnumActionResult.FAIL, stack); } p.addStat(StatList.getObjectUseStats(this)); return new ActionResult(EnumActionResult.SUCCESS, stack); } }