diff --git a/src/main/java/vazkii/botania/api/mana/IManaSpreader.java b/src/main/java/vazkii/botania/api/mana/IManaSpreader.java index 61b9f8e32..8e727c7f6 100644 --- a/src/main/java/vazkii/botania/api/mana/IManaSpreader.java +++ b/src/main/java/vazkii/botania/api/mana/IManaSpreader.java @@ -10,6 +10,11 @@ */ package vazkii.botania.api.mana; +import org.apache.commons.lang3.tuple.Pair; + +import net.minecraft.util.math.BlockPos; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.common.entity.EntityManaBurst; /** * Any TileEntity that implements this is considered a Mana Spreader, @@ -26,5 +31,7 @@ public interface IManaSpreader extends IManaBlock, IPingable, IDirectioned { public int getLastBurstDeathTick(); public void setLastBurstDeathTick(int ticksExisted); + + public IManaBurst runBurstSimulation(); } diff --git a/src/main/java/vazkii/botania/common/block/tile/mana/TileSpreader.java b/src/main/java/vazkii/botania/common/block/tile/mana/TileSpreader.java index c996eaf06..f12e82f0f 100644 --- a/src/main/java/vazkii/botania/common/block/tile/mana/TileSpreader.java +++ b/src/main/java/vazkii/botania/common/block/tile/mana/TileSpreader.java @@ -484,6 +484,14 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector, else this.receiver = null; lastTentativeBurst = fakeBurst.propsList; } + + @Override + public IManaBurst runBurstSimulation() { + EntityManaBurst fakeBurst = getBurst(true); + fakeBurst.setScanBeam(); + fakeBurst.getCollidedTile(true); + return fakeBurst; + } public EntityManaBurst getBurst(boolean fake) { EntityManaBurst burst = new EntityManaBurst(this, fake); diff --git a/src/main/java/vazkii/botania/common/item/lens/ItemLens.java b/src/main/java/vazkii/botania/common/item/lens/ItemLens.java index a11903ef1..99cc4d539 100644 --- a/src/main/java/vazkii/botania/common/item/lens/ItemLens.java +++ b/src/main/java/vazkii/botania/common/item/lens/ItemLens.java @@ -45,7 +45,7 @@ import java.util.List; public class ItemLens extends ItemMod implements ILensControl, ICompositableLens, ITinyPlanetExcempt { - public static final int SUBTYPES = 23; + public static final int SUBTYPES = 24; public static final int NORMAL = 0, SPEED = 1, @@ -69,7 +69,8 @@ public class ItemLens extends ItemMod implements ILensControl, ICompositableLens REDIRECT = 19, FIREWORK = 20, FLARE = 21, - MESSENGER = 22; + MESSENGER = 22, + TRIPWIRE = 23; public static final int STORM = 5000; @@ -110,6 +111,7 @@ public class ItemLens extends ItemMod implements ILensControl, ICompositableLens setProps(FIREWORK, PROP_TOUCH); setProps(FLARE, PROP_CONTROL); setProps(MESSENGER, PROP_POWER); + setProps(TRIPWIRE, PROP_CONTROL); setLens(NORMAL, fallbackLens); setLens(SPEED, new LensSpeed()); @@ -134,6 +136,7 @@ public class ItemLens extends ItemMod implements ILensControl, ICompositableLens setLens(FIREWORK, new LensFirework()); setLens(FLARE, new LensFlare()); setLens(MESSENGER, new LensMessenger()); + setLens(TRIPWIRE, new LensTripwire()); } private static final String TAG_COLOR = "color"; diff --git a/src/main/java/vazkii/botania/common/item/lens/LensTripwire.java b/src/main/java/vazkii/botania/common/item/lens/LensTripwire.java new file mode 100644 index 000000000..de710bc68 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/lens/LensTripwire.java @@ -0,0 +1,55 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [02/10/2016, 18:27:42 (GMT)] + */ +package vazkii.botania.common.item.lens; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityThrowable; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.RayTraceResult; +import vazkii.botania.api.internal.IManaBurst; +import vazkii.botania.api.mana.BurstProperties; +import vazkii.botania.api.mana.IManaSpreader; +import vazkii.botania.common.core.helper.ItemNBTHelper; + +public class LensTripwire extends Lens { + + private static final String TAG_TRIPPED = "botania:triwireLensTripped"; + + @Override + public boolean allowBurstShooting(ItemStack stack, IManaSpreader spreader, boolean redstone) { + IManaBurst burst = spreader.runBurstSimulation(); + Entity e = (Entity) burst; + return e.getEntityData().getBoolean(TAG_TRIPPED); + } + + @Override + public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { + if(burst.isFake()) { + if(entity.worldObj.isRemote) + return; + + AxisAlignedBB axis = new AxisAlignedBB(entity.posX, entity.posY, entity.posZ, entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ).expand(0.25, 0.25, 0.25); + List entities = entity.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis); + if(!entities.isEmpty()) { + Entity e = (Entity) burst; + e.getEntityData().setBoolean(TAG_TRIPPED, true); + } + } + + } + +} diff --git a/src/main/java/vazkii/botania/common/lib/LibItemNames.java b/src/main/java/vazkii/botania/common/lib/LibItemNames.java index 0e7f5067e..1a4c926ea 100644 --- a/src/main/java/vazkii/botania/common/lib/LibItemNames.java +++ b/src/main/java/vazkii/botania/common/lib/LibItemNames.java @@ -184,7 +184,8 @@ public final class LibItemNames { "lensRedirect", "lensFirework", "lensFlare", - "lensMessenger" + "lensMessenger", + "lensTripwire" }; public static final String[] MANA_RESOURCE_NAMES = new String[] { diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index c05ad27e4..0c1217f62 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -1351,6 +1351,8 @@ item.botania:lensFlare.name=Mana Lens: Flare item.botania:lensFlare.short=Flare item.botania:lensMessenger.name=Mana Lens: Messenger item.botania:lensMessenger.short=Messenger +item.botania:lensTripwire.name=Mana Lens: Tripwire +item.botania:lensTripwire.short=Tripwire item.botania:rune0.name=Rune of Water item.botania:rune1.name=Rune of Fire item.botania:rune2.name=Rune of Earth diff --git a/src/main/resources/assets/botania/models/item/lensTripwire.json b/src/main/resources/assets/botania/models/item/lensTripwire.json new file mode 100644 index 000000000..65e88b7fd --- /dev/null +++ b/src/main/resources/assets/botania/models/item/lensTripwire.json @@ -0,0 +1,7 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "botania:items/lensInside", + "layer1": "botania:items/lensTripwire" + } +} \ No newline at end of file