mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-29 18:28:34 +01:00
Added enabling/disabling the magnet ring
This commit is contained in:
parent
03a0588faf
commit
65e443e13b
4 changed files with 43 additions and 22 deletions
|
@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.items;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||||
|
@ -45,12 +46,12 @@ public class ItemBattery extends ItemEnergy{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasEffect(ItemStack stack){
|
public boolean hasEffect(ItemStack stack){
|
||||||
return this.isDischargeMode(stack);
|
return ItemUtil.isEnabled(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected){
|
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected){
|
||||||
if(!world.isRemote && entity instanceof EntityPlayer && this.isDischargeMode(stack)){
|
if(!world.isRemote && entity instanceof EntityPlayer && ItemUtil.isEnabled(stack)){
|
||||||
EntityPlayer player = (EntityPlayer)entity;
|
EntityPlayer player = (EntityPlayer)entity;
|
||||||
for(int i = 0; i < player.inventory.getSizeInventory(); i++){
|
for(int i = 0; i < player.inventory.getSizeInventory(); i++){
|
||||||
ItemStack slot = player.inventory.getStackInSlot(i);
|
ItemStack slot = player.inventory.getStackInSlot(i);
|
||||||
|
@ -81,32 +82,17 @@ public class ItemBattery extends ItemEnergy{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand){
|
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand){
|
||||||
ItemStack stack = player.getHeldItem(hand);
|
|
||||||
if(!worldIn.isRemote && player.isSneaking()){
|
if(!worldIn.isRemote && player.isSneaking()){
|
||||||
boolean isDischarge = this.isDischargeMode(stack);
|
ItemUtil.changeEnabled(player, hand);
|
||||||
this.setDischargeMode(stack, !isDischarge);
|
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
|
||||||
|
|
||||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
|
|
||||||
}
|
}
|
||||||
return super.onItemRightClick(worldIn, player, hand);
|
return super.onItemRightClick(worldIn, player, hand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDischargeMode(ItemStack stack){
|
|
||||||
return stack.hasTagCompound() && stack.getTagCompound().getBoolean("DischargeMode");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setDischargeMode(ItemStack stack, boolean mode){
|
|
||||||
if(!stack.hasTagCompound()){
|
|
||||||
stack.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.getTagCompound().setBoolean("DischargeMode", mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
|
||||||
super.addInformation(stack, player, list, bool);
|
super.addInformation(stack, player, list, bool);
|
||||||
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".battery."+(this.isDischargeMode(stack) ? "discharge" : "noDischarge")));
|
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".battery."+(ItemUtil.isEnabled(stack) ? "discharge" : "noDischarge")));
|
||||||
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".battery.changeMode"));
|
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".battery.changeMode"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,16 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.items;
|
package de.ellpeck.actuallyadditions.mod.items;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.EnumRarity;
|
import net.minecraft.item.EnumRarity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.EnumActionResult;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
@ -28,9 +32,14 @@ public class ItemMagnetRing extends ItemEnergy{
|
||||||
super(200000, 1000, name);
|
super(200000, 1000, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasEffect(ItemStack stack){
|
||||||
|
return !ItemUtil.isEnabled(stack);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
|
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
|
||||||
if(entity instanceof EntityPlayer && !world.isRemote){
|
if(entity instanceof EntityPlayer && !world.isRemote && !ItemUtil.isEnabled(stack)){
|
||||||
EntityPlayer player = (EntityPlayer)entity;
|
EntityPlayer player = (EntityPlayer)entity;
|
||||||
|
|
||||||
if(!entity.isSneaking()){
|
if(!entity.isSneaking()){
|
||||||
|
@ -56,6 +65,14 @@ public class ItemMagnetRing extends ItemEnergy{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand){
|
||||||
|
if(!worldIn.isRemote && player.isSneaking()){
|
||||||
|
ItemUtil.changeEnabled(player, hand);
|
||||||
|
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
|
||||||
|
}
|
||||||
|
return super.onItemRightClick(worldIn, player, hand);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumRarity getRarity(ItemStack stack){
|
public EnumRarity getRarity(ItemStack stack){
|
||||||
|
|
|
@ -15,9 +15,12 @@ import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
|
||||||
import de.ellpeck.actuallyadditions.mod.creative.CreativeTab;
|
import de.ellpeck.actuallyadditions.mod.creative.CreativeTab;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.enchantment.Enchantment;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
|
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
|
@ -167,4 +170,19 @@ public final class ItemUtil{
|
||||||
public static boolean canBeStacked(ItemStack stack1, ItemStack stack2){
|
public static boolean canBeStacked(ItemStack stack1, ItemStack stack2){
|
||||||
return ItemStack.areItemsEqual(stack1, stack2) && ItemStack.areItemStackTagsEqual(stack1, stack2);
|
return ItemStack.areItemsEqual(stack1, stack2) && ItemStack.areItemStackTagsEqual(stack1, stack2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isEnabled(ItemStack stack){
|
||||||
|
return stack.hasTagCompound() && stack.getTagCompound().getBoolean("IsEnabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void changeEnabled(EntityPlayer player, EnumHand hand){
|
||||||
|
ItemStack stack = player.getHeldItem(hand);
|
||||||
|
|
||||||
|
if(!stack.hasTagCompound()){
|
||||||
|
stack.setTagCompound(new NBTTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isEnabled = isEnabled(stack);
|
||||||
|
stack.getTagCompound().setBoolean("IsEnabled", !isEnabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -911,7 +911,7 @@ booklet.actuallyadditions.chapter.staff.name=Staff
|
||||||
booklet.actuallyadditions.chapter.staff.text.1=The <item>Teleport Staff<r>, when charged in an Energizer, can be <imp>right-clicked<r> to <imp>teleport you to where you're looking<r>. When you are looking at a block, it will teleport you there, however, when you aren't looking at a block, you can only be looking upwards up to <imp>5 degrees<r>, otherwise the teleport will fail.
|
booklet.actuallyadditions.chapter.staff.text.1=The <item>Teleport Staff<r>, when charged in an Energizer, can be <imp>right-clicked<r> to <imp>teleport you to where you're looking<r>. When you are looking at a block, it will teleport you there, however, when you aren't looking at a block, you can only be looking upwards up to <imp>5 degrees<r>, otherwise the teleport will fail.
|
||||||
|
|
||||||
booklet.actuallyadditions.chapter.magnetRing.name=Ring Of Magnetism
|
booklet.actuallyadditions.chapter.magnetRing.name=Ring Of Magnetism
|
||||||
booklet.actuallyadditions.chapter.magnetRing.text.1=The <item>Ring Of Magnetism<r>, when it is charged in an Energizer and inside your inventory, uses <imp>CF<r> to suck up items that are farther away than you can pick up by yourself.
|
booklet.actuallyadditions.chapter.magnetRing.text.1=The <item>Ring Of Magnetism<r>, when it has been charged charged in an Energizer and is inside your inventory, uses <imp>CF<r> to suck up items that are farther away than you can pick up by yourself. <n>You can enable and disable it by <imp>sneak-right-clicking<r> with it in hand.
|
||||||
|
|
||||||
booklet.actuallyadditions.chapter.growthRing.name=Ring Of Growth
|
booklet.actuallyadditions.chapter.growthRing.name=Ring Of Growth
|
||||||
booklet.actuallyadditions.chapter.growthRing.text.1=The <item>Ring Of Growth<r>, when it is charged in an Energizer and in your hand, uses <imp>CF<r> to make plants around you grow much faster.
|
booklet.actuallyadditions.chapter.growthRing.text.1=The <item>Ring Of Growth<r>, when it is charged in an Energizer and in your hand, uses <imp>CF<r> to make plants around you grow much faster.
|
||||||
|
|
Loading…
Reference in a new issue