123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package me.km.items;
- import java.util.List;
- import me.km.KajetansMod;
- import me.km.api.GlobalText;
- import me.km.api.Utils;
- import me.km.effects.Effect;
- import me.km.effects.EffectCause;
- import net.minecraft.client.util.ITooltipFlag;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.EntityPlayerMP;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- 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;
- import net.minecraftforge.common.capabilities.ICapabilityProvider;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class ItemScroll extends ItemBase
- {
- public ItemScroll(String name, String local)
- {
- super(name, local);
- }
- @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.scrolls.send(p, GlobalText.noScrolls());
- return new ActionResult(EnumActionResult.FAIL, p.getHeldItem(hand));
- }
-
- ItemStack stack = p.getHeldItem(hand);
- NBTTagCompound com = getTagCompound(stack);
- int id = com.getInteger("effect_id");
- if(id == -1)
- {
- KajetansMod.scrolls.send(p, "Die Schriftrolle hat keinen Effekt.");
- return new ActionResult(EnumActionResult.FAIL, stack);
- }
- Effect eff = Effect.getEffect(id);
- if(eff == null)
- {
- KajetansMod.scrolls.send(p, "Die Schriftrolle ist korrupt.");
- return new ActionResult(EnumActionResult.FAIL, stack);
- }
- if(eff.getEffectInstance().run((EntityPlayerMP) p, com.getInteger("effect_level"), 0, 20, EffectCause.SCROLL))
- {
- if(!p.isCreative())
- {
- stack.shrink(1);
- }
- p.addStat(StatList.getObjectUseStats(this));
- return new ActionResult(EnumActionResult.SUCCESS, stack);
- }
- return new ActionResult(EnumActionResult.FAIL, stack);
- }
- @SideOnly(Side.CLIENT)
- @Override
- public void addInformation(ItemStack stack, World w, List<String> lore, ITooltipFlag flag)
- {
- NBTTagCompound com = getTagCompound(stack);
- String s = com.getString("effect_name");
- if(!s.isEmpty())
- {
- lore.set(0, s + " " + Utils.intToRoman(com.getInteger("effect_level")));
- }
- }
-
- @Override
- public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt)
- {
- getTagCompound(stack);
- return null;
- }
-
- private NBTTagCompound getTagCompound(ItemStack stack)
- {
- NBTTagCompound com = stack.getTagCompound();
- if(com == null)
- {
- com = new NBTTagCompound();
- com.setInteger("effect_id", -1);
- com.setInteger("effect_level", 1);
- com.setString("effect_name", "");
- stack.setTagCompound(com);
- }
- else
- {
- if(!com.hasKey("effect_id"))
- {
- com.setInteger("effect_id", -1);
- }
- if(!com.hasKey("effect_level"))
- {
- com.setInteger("effect_level", 1);
- }
- if(!com.hasKey("effect_name"))
- {
- com.setString("effect_name", "");
- }
- }
- return com;
- }
-
- public void setEffect(ItemStack stack, int id, int level, String name)
- {
- NBTTagCompound com = getTagCompound(stack);
- com.setInteger("effect_id", id);
- level = Math.max(1, Math.min(20, level));
- com.setInteger("effect_level", level);
- com.setString("effect_name", name);
- }
- }
|