New Lenses (part 1)

This commit is contained in:
Vasco Lavos committed 2015-11-15 19:49:12 +00:00
1 parent f1193e8af6
commit 7c9084eab2
16 files changed
+211 -12

No files matched your search

@@ -0,0 +1,24 @@
/**
* This class was created by <Vazkii>. 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 @ [15/11/2015, 19:27:07 (GMT)]
*/
package vazkii.botania.api.mana;
/**
* Any TileEntity that implements this is defined as having a direction,
* and has two rotations (X and Y).
* An example of this is the Mana Spreader.
*/
public interface IDirectioned {
public float getRotationX();
public float getRotationY();
}
@@ -14,13 +14,8 @@ package vazkii.botania.api.mana;
/**
* Any TileEntity that implements this is considered a Mana Spreader,
* by which can fire mana bursts as a spreader.
*
*/
public interface IManaSpreader extends IManaBlock, IPingable {
public float getRotationX();
public float getRotationY();
public interface IManaSpreader extends IManaBlock, IPingable, IDirectioned {
public void setCanShoot(boolean canShoot);
@@ -0,0 +1,29 @@
/**
* This class was created by <Vazkii>. 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 @ [15/11/2015, 19:28:18 (GMT)]
*/
package vazkii.botania.api.mana;
/**
* This is an extension of IDirectioned for TileEntities
* that allow for their rotation to be public and modifiable outside.
* This is used in botania for the Redirective mana lens.
*/
public interface IRedirectable extends IDirectioned {
public void setRotationX(float rot);
public void setRotationY(float rot);
/**
* This should be called after rotation setting is done to allow
* for the block to re-calculate.
*/
public void commitRedirection();
}
@@ -1,4 +1,4 @@
@API(owner = "Botania", apiVersion = "67", provides = "BotaniaAPI")
@API(owner = "Botania", apiVersion = "68", provides = "BotaniaAPI")
package vazkii.botania.api;
import cpw.mods.fml.common.API;
@@ -28,7 +28,9 @@ import net.minecraft.stats.Achievement;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
@@ -120,6 +122,7 @@ public class BlockPool extends BlockModContainer implements IWandHUD, IWandable,
}
}
@Override
public void addCollisionBoxesToList(World p_149743_1_, int p_149743_2_, int p_149743_3_, int p_149743_4_, AxisAlignedBB p_149743_5_, List p_149743_6_, Entity p_149743_7_) {
float f = 1F / 16F;
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, f, 1.0F);
@@ -134,6 +137,11 @@ public class BlockPool extends BlockModContainer implements IWandHUD, IWandable,
super.addCollisionBoxesToList(p_149743_1_, p_149743_2_, p_149743_3_, p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_);
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
}
@Override
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
return side == ForgeDirection.DOWN;
}
@Override
public boolean isOpaqueCube() {
@@ -45,6 +45,7 @@ import vazkii.botania.api.mana.IManaCollector;
import vazkii.botania.api.mana.IManaPool;
import vazkii.botania.api.mana.IManaReceiver;
import vazkii.botania.api.mana.IManaSpreader;
import vazkii.botania.api.mana.IRedirectable;
import vazkii.botania.api.mana.IThrottledPacket;
import vazkii.botania.api.mana.ManaNetworkEvent;
import vazkii.botania.api.wand.IWandBindable;
@@ -59,7 +60,7 @@ import vazkii.botania.common.entity.EntityManaBurst;
import vazkii.botania.common.entity.EntityManaBurst.PositionProperties;
import vazkii.botania.common.lib.LibBlockNames;
public class TileSpreader extends TileSimpleInventory implements IManaCollector, IWandBindable, IKeyLocked, IThrottledPacket, IManaSpreader {
public class TileSpreader extends TileSimpleInventory implements IManaCollector, IWandBindable, IKeyLocked, IThrottledPacket, IManaSpreader, IRedirectable {
private static final int MAX_MANA = 1000;
private static final int ULTRA_MAX_MANA = 6400;
@@ -670,6 +671,21 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
return rotationY;
}
@Override
public void setRotationX(float rot) {
rotationX = rot;
}
@Override
public void setRotationY(float rot) {
rotationY = rot;
}
@Override
public void commitRedirection() {
checkForReceiver();
}
@Override
public void setCanShoot(boolean canShoot) {
canShootBurst = canShoot;
@@ -717,4 +733,5 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
public UUID getIdentifierUnsafe() {
return identity;
}
}
@@ -41,7 +41,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
public class ItemLens extends ItemMod implements ILens, ITinyPlanetExcempt {
public static final int SUBTYPES = 19;
public static final int SUBTYPES = 22;
public static final int NORMAL = 0,
SPEED = 1,
@@ -61,7 +61,10 @@ public class ItemLens extends ItemMod implements ILens, ITinyPlanetExcempt {
FIRE = 15,
PISTON = 16,
LIGHT = 17,
WARP = 18;
WARP = 18,
REDIRECT = 19,
FIREWORK = 20,
FLARE = 21;
public static final int STORM = 5000;
@@ -70,7 +73,8 @@ public class ItemLens extends ItemMod implements ILens, ITinyPlanetExcempt {
PROP_ORIENTATION = 1 << 1,
PROP_TOUCH = 1 << 2,
PROP_INTERACTION = 1 << 3,
PROP_DAMAGE = 1 << 4;
PROP_DAMAGE = 1 << 4,
PROP_CONTROL = 1 << 5;
private static final int[] props = new int[SUBTYPES];
private static final Lens[] lenses = new Lens[SUBTYPES];
@@ -97,6 +101,9 @@ public class ItemLens extends ItemMod implements ILens, ITinyPlanetExcempt {
setProps(PISTON, PROP_TOUCH | PROP_INTERACTION);
setProps(LIGHT, PROP_TOUCH | PROP_INTERACTION);
setProps(WARP, PROP_NONE);
setProps(REDIRECT, PROP_TOUCH | PROP_INTERACTION);
setProps(FIREWORK, PROP_TOUCH);
setProps(FLARE, PROP_CONTROL);
setLens(NORMAL, fallbackLens);
setLens(SPEED, new LensSpeed());
@@ -117,6 +124,9 @@ public class ItemLens extends ItemMod implements ILens, ITinyPlanetExcempt {
setLens(PISTON, new LensPiston());
setLens(LIGHT, new LensLight());
setLens(WARP, new LensWarp());
setLens(REDIRECT, new LensRedirect());
setLens(FIREWORK, new LensFirework());
setLens(FLARE, new LensFlare());
}
private static final String TAG_COLOR = "color";
@@ -0,0 +1,17 @@
/**
* This class was created by <Vazkii>. 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 @ [15/11/2015, 19:12:41 (GMT)]
*/
package vazkii.botania.common.item.lens;
public class LensFirework extends Lens {
// TODO
}
@@ -0,0 +1,17 @@
/**
* This class was created by <Vazkii>. 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 @ [15/11/2015, 19:13:10 (GMT)]
*/
package vazkii.botania.common.item.lens;
public class LensFlare extends Lens {
// TODO
}
@@ -0,0 +1,79 @@
/**
* This class was created by <Vazkii>. 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 @ [15/11/2015, 19:13:03 (GMT)]
*/
package vazkii.botania.common.item.lens;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MovingObjectPosition;
import vazkii.botania.api.internal.IManaBurst;
import vazkii.botania.api.mana.IDirectioned;
import vazkii.botania.api.mana.IManaSpreader;
import vazkii.botania.api.mana.IRedirectable;
import vazkii.botania.api.mana.IThrottledPacket;
import vazkii.botania.common.block.tile.mana.TileSpreader;
import vazkii.botania.common.core.helper.Vector3;
public class LensRedirect extends Lens {
@Override
public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) {
ChunkCoordinates coords = burst.getBurstSourceChunkCoordinates();
if(!entity.worldObj.isRemote && pos.entityHit == null && (pos.blockX != coords.posX || pos.blockY != coords.posY || pos.blockZ != coords.posZ)) {
TileEntity tile = entity.worldObj.getTileEntity(pos.blockX, pos.blockY, pos.blockZ);
if(tile != null && tile instanceof IRedirectable) {
if(!burst.isFake()) {
IRedirectable redir = (IRedirectable) tile;
System.out.println(redir);
Vector3 tileVec = Vector3.fromTileEntityCenter(tile);
Vector3 sourceVec = new Vector3(coords.posX + 0.5, coords.posY + 0.5, coords.posZ + 0.5);
AxisAlignedBB axis = entity.worldObj.getBlock(coords.posX, coords.posY, coords.posZ).getCollisionBoundingBoxFromPool(entity.worldObj, coords.posX, coords.posY, coords.posZ);
if(axis == null)
axis = AxisAlignedBB.getBoundingBox(coords.posX, coords.posY, coords.posZ, coords.posX + 1, coords.posY + 1, coords.posZ + 1);
if(!sourceVec.isInside(axis))
sourceVec = new Vector3(axis.minX + (axis.maxX - axis.minX) / 2, axis.minY + (axis.maxY - axis.minY) / 2, axis.minZ + (axis.maxZ - axis.minZ) / 2);
Vector3 diffVec = sourceVec.copy().sub(tileVec);
Vector3 diffVec2D = new Vector3(diffVec.x, diffVec.z, 0);
Vector3 rotVec = new Vector3(0, 1, 0);
double angle = rotVec.angle(diffVec2D) / Math.PI * 180.0;
if(sourceVec.x < tileVec.x)
angle = -angle;
redir.setRotationX((float) angle + 90F);
rotVec = new Vector3(diffVec.x, 0, diffVec.z);
angle = diffVec.angle(rotVec) * 180F / Math.PI;
if(sourceVec.y < tileVec.y)
angle = -angle;
redir.setRotationY((float) angle);
redir.commitRedirection();
if(redir instanceof IThrottledPacket)
((IThrottledPacket) redir).markDispatchable();
}
}
}
if(!isManaBlock) {
dead = false;
burst.setMinManaLoss(Math.max(0, burst.getMinManaLoss() - 4));
}
return dead;
}
}
@@ -179,7 +179,10 @@ public final class LibItemNames {
"lensFire",
"lensPiston",
"lensLight",
"lensWarp"
"lensWarp",
"lensRedirect",
"lensFirework",
"lensFlare"
};
public static final String[] MANA_RESOURCE_NAMES = new String[] {