From 4476b3c7c2599b3477acaafcb5fc3c7bf5f04ada Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 25 Jul 2015 12:11:31 +0200 Subject: [PATCH] Added Ring of Suction --- .../ellpeck/actuallyadditions/PLANNED.txt | 1 - .../actuallyadditions/items/InitItems.java | 4 + .../items/ItemGrowthRing.java | 3 +- .../items/ItemMagnetRing.java | 77 +++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/items/ItemMagnetRing.java diff --git a/src/main/java/ellpeck/actuallyadditions/PLANNED.txt b/src/main/java/ellpeck/actuallyadditions/PLANNED.txt index d9018e278..a50dc0a6f 100644 --- a/src/main/java/ellpeck/actuallyadditions/PLANNED.txt +++ b/src/main/java/ellpeck/actuallyadditions/PLANNED.txt @@ -70,7 +70,6 @@ -Depending on the fluids, it generates more power -More Effect Rings - -Ring of Growth: Lets Plants grow, more Reach with Tier 2 -Ring of Thorns: Hurts Attackers when they hit you with a Projectile -Ring of Water Walking -Ring of Aquadive: Fast underwater movement diff --git a/src/main/java/ellpeck/actuallyadditions/items/InitItems.java b/src/main/java/ellpeck/actuallyadditions/items/InitItems.java index 0374f62f4..3520a14a4 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/InitItems.java +++ b/src/main/java/ellpeck/actuallyadditions/items/InitItems.java @@ -109,6 +109,7 @@ public class InitItems{ public static Item itemWingsOfTheBats; public static Item itemGrowthRing; + public static Item itemMagnetRing; public static void init(){ ModUtil.LOGGER.info("Initializing Items..."); @@ -116,6 +117,9 @@ public class InitItems{ itemGrowthRing = new ItemGrowthRing(); ItemUtil.register(itemGrowthRing); + itemMagnetRing = new ItemMagnetRing(); + ItemUtil.register(itemMagnetRing); + itemHelmEmerald = new ItemArmorAA("itemHelmEmerald", InitArmorMaterials.armorMaterialEmerald, 0, "gemEmerald", "armorEmerald"); itemChestEmerald = new ItemArmorAA("itemChestEmerald", InitArmorMaterials.armorMaterialEmerald, 1, "gemEmerald", "armorEmerald"); itemPantsEmerald = new ItemArmorAA("itemPantsEmerald", InitArmorMaterials.armorMaterialEmerald, 2, "gemEmerald", "armorEmerald"); diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemGrowthRing.java b/src/main/java/ellpeck/actuallyadditions/items/ItemGrowthRing.java index 1d9691403..bd19d0cd1 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemGrowthRing.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemGrowthRing.java @@ -24,7 +24,7 @@ import java.util.Random; public class ItemGrowthRing extends ItemEnergy implements INameableItem{ private static final int RANGE = 5; - private static final int ENERGY_USED_PER_TICK = 800; + private static final int ENERGY_USED_PER_TICK = 500; //The waiting time per growth cycle private static final int WAIT_TIME = 30; //The amount of Growth Ticks given to random plants around @@ -37,6 +37,7 @@ public class ItemGrowthRing extends ItemEnergy implements INameableItem{ @Override public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){ if(!(entity instanceof EntityPlayer) || world.isRemote) return; + EntityPlayer player = (EntityPlayer)entity; ItemStack equipped = player.getCurrentEquippedItem(); diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemMagnetRing.java b/src/main/java/ellpeck/actuallyadditions/items/ItemMagnetRing.java new file mode 100644 index 000000000..774bb42e7 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemMagnetRing.java @@ -0,0 +1,77 @@ +package ellpeck.actuallyadditions.items; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.util.INameableItem; +import ellpeck.actuallyadditions.util.ModUtil; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +import java.util.ArrayList; + +public class ItemMagnetRing extends ItemEnergy implements INameableItem{ + + private static final int RANGE = 8; + private static final int ENERGY_USED_PER_TICK = 3; + + public ItemMagnetRing(){ + super(3000000, 5000, 1); + } + + @SuppressWarnings("unchecked") + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){ + if(this.getEnergyStored(stack) >= ENERGY_USED_PER_TICK){ + //Get all the Items in the area + ArrayList items = (ArrayList)world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(entity.posX-RANGE, entity.posY-RANGE, entity.posZ-RANGE, entity.posX+RANGE, entity.posY+RANGE, entity.posZ+RANGE)); + if(!items.isEmpty()){ + for(EntityItem item : items){ + //If the Item is near enough to get picked up + //(So it doesn't bounce around until it notices itself..) + if(Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ).distanceTo(Vec3.createVectorHelper(item.posX, item.posY, item.posZ)) <= 1.5){ + item.onCollideWithPlayer((EntityPlayer)entity); + } + else{ + double speed = 0.02; + //Move the Item closer to the Player + item.motionX += (entity.posX+0.5-item.posX)*speed; + item.motionY += (entity.posY+1.0-item.posY)*speed; + item.motionZ += (entity.posZ+0.5-item.posZ)*speed; + } + } + } + + //Use Energy per tick + this.extractEnergy(stack, ENERGY_USED_PER_TICK, false); + } + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + return EnumRarity.epic; + } + + @Override + public IIcon getIcon(ItemStack stack, int pass){ + return this.itemIcon; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconReg){ + this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getName()); + } + + @Override + public String getName(){ + return "itemSuctionRing"; + } +}