1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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<ItemStack> 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<? extends ActiveEffectBase> 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);
- }
- }
|