New Lenses (part 3)

This commit is contained in:
Vasco Lavos committed 2015-11-15 22:01:09 +00:00
1 parent 5f8c650fa2
commit 3fa9ca216d
8 files changed
+166 -13

No files matched your search

@@ -0,0 +1,35 @@
/**
* 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, 21:00:32 (GMT)]
*/
package vazkii.botania.api.mana;
import net.minecraft.item.ItemStack;
/**
* An extension of ILens that allows for the lens item to control the
* spreader's behaviour.
*/
public interface ILensControl extends ILens {
public boolean isControlLens(ItemStack stack);
public boolean allowBurstShooting(ItemStack stack, IManaSpreader spreader, boolean redstone);
/**
* Used for the tick of a non-redstone spreader.
*/
public void onControlledSpreaderTick(ItemStack stack, IManaSpreader spreader, boolean redstone);
/**
* Used for when a redstone spreader gets a pulse.
*/
public void onControlledSpreaderPulse(ItemStack stack, IManaSpreader spreader, boolean redstone);
}
@@ -40,6 +40,7 @@ import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.mana.BurstProperties;
import vazkii.botania.api.mana.IKeyLocked;
import vazkii.botania.api.mana.ILens;
import vazkii.botania.api.mana.ILensControl;
import vazkii.botania.api.mana.ILensEffect;
import vazkii.botania.api.mana.IManaCollector;
import vazkii.botania.api.mana.IManaPool;
@@ -223,12 +224,24 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
boolean shouldShoot = !redstone;
if(isRedstone())
boolean isredstone = isRedstone();
if(isredstone)
shouldShoot = redstone && !redstoneLastTick;
if(shouldShoot && receiver != null && receiver instanceof IKeyLocked)
shouldShoot = ((IKeyLocked) receiver).getInputKey().equals(getOutputKey());
ItemStack lens = getStackInSlot(0);
ILensControl control = getLensController(lens);
if(control != null) {
if(isredstone) {
if(shouldShoot)
control.onControlledSpreaderPulse(lens, this, redstone);
} else control.onControlledSpreaderTick(lens, this, redstone);
shouldShoot &= control.allowBurstShooting(lens, this, redstone);
}
if(shouldShoot)
tryShootBurst();
@@ -435,6 +448,11 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
}
public void checkForReceiver() {
ItemStack stack = getStackInSlot(0);
ILensControl control = getLensController(stack);
if(control != null && !control.allowBurstShooting(stack, this, false))
return;
EntityManaBurst fakeBurst = getBurst(true);
fakeBurst.setScanBeam();
TileEntity receiver = fakeBurst.getCollidedTile(true);
@@ -486,6 +504,16 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
}
return null;
}
public ILensControl getLensController(ItemStack stack) {
if(stack != null && stack.getItem() instanceof ILensControl) {
ILensControl control = (ILensControl) stack.getItem();
if(control.isControlLens(stack))
return control;
}
return null;
}
public static MovingObjectPosition raytraceFromEntity(World world, Entity player, boolean par3, double range) {
float f = 1.0F;
@@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import vazkii.botania.api.mana.ILens;
import vazkii.botania.api.mana.ILensControl;
import vazkii.botania.common.item.ItemManaGun;
public class ManaGunLensRecipe implements IRecipe {
@@ -30,9 +31,12 @@ public class ManaGunLensRecipe implements IRecipe {
if(stack.getItem() instanceof ItemManaGun && ItemManaGun.getLens(stack) == null)
foundGun = true;
else if(stack.getItem() instanceof ILens)
foundLens = true;
else if(stack.getItem() instanceof ILens) {
if(!(stack.getItem() instanceof ILensControl) || !((ILensControl) stack.getItem()).isControlLens(stack))
foundLens = true;
else return false;
}
else return false; // Found an invalid item, breaking the recipe
}
}
@@ -29,6 +29,8 @@ import net.minecraftforge.oredict.RecipeSorter.Category;
import vazkii.botania.api.internal.IManaBurst;
import vazkii.botania.api.mana.BurstProperties;
import vazkii.botania.api.mana.ILens;
import vazkii.botania.api.mana.ILensControl;
import vazkii.botania.api.mana.IManaSpreader;
import vazkii.botania.api.mana.ITinyPlanetExcempt;
import vazkii.botania.client.core.helper.IconHelper;
import vazkii.botania.common.Botania;
@@ -39,7 +41,7 @@ import vazkii.botania.common.item.ItemMod;
import vazkii.botania.common.lib.LibItemNames;
import cpw.mods.fml.common.registry.GameRegistry;
public class ItemLens extends ItemMod implements ILens, ITinyPlanetExcempt {
public class ItemLens extends ItemMod implements ILensControl, ITinyPlanetExcempt {
public static final int SUBTYPES = 22;
@@ -331,4 +333,24 @@ public class ItemLens extends ItemMod implements ILens, ITinyPlanetExcempt {
public boolean shouldPull(ItemStack stack) {
return stack.getItemDamage() != STORM;
}
@Override
public boolean isControlLens(ItemStack stack) {
return (props[stack.getItemDamage()] & PROP_CONTROL) != 0;
}
@Override
public boolean allowBurstShooting(ItemStack stack, IManaSpreader spreader, boolean redstone) {
return lenses[stack.getItemDamage()].allowBurstShooting(stack, spreader, redstone);
}
@Override
public void onControlledSpreaderTick(ItemStack stack, IManaSpreader spreader, boolean redstone) {
lenses[stack.getItemDamage()].onControlledSpreaderTick(stack, spreader, redstone);
}
@Override
public void onControlledSpreaderPulse(ItemStack stack, IManaSpreader spreader, boolean redstone) {
lenses[stack.getItemDamage()].onControlledSpreaderPulse(stack, spreader, redstone);
}
}
@@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import vazkii.botania.api.internal.IManaBurst;
import vazkii.botania.api.mana.BurstProperties;
import vazkii.botania.api.mana.IManaSpreader;
public class Lens {
@@ -29,5 +30,18 @@ public class Lens {
public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) {
// NO-OP
}
public boolean allowBurstShooting(ItemStack stack, IManaSpreader spreader, boolean redstone) {
return true;
}
public void onControlledSpreaderTick(ItemStack stack, IManaSpreader spreader, boolean redstone) {
// NO-OP
}
public void onControlledSpreaderPulse(ItemStack stack, IManaSpreader spreader, boolean redstone) {
// NO-OP
}
}
@@ -24,7 +24,6 @@ import vazkii.botania.common.core.helper.ItemNBTHelper;
public class LensFirework extends Lens {
@Override
public boolean collideBurst(IManaBurst burst, EntityThrowable entity, MovingObjectPosition pos, boolean isManaBlock, boolean dead, ItemStack stack) {
if(!burst.isFake()) {
@@ -45,12 +44,12 @@ public class LensFirework extends Lens {
NBTTagCompound explosion = new NBTTagCompound();
explosion.setIntArray("Colors", new int[] { color });
int type = 0;
double rand = Math.random() * 100;
if(rand > 50) {
if(rand > 15)
int type = 1;
double rand = Math.random();
if(rand > 0.25) {
if(rand > 0.9)
type = 2;
else type = 1;
else type = 0;
}
explosion.setInteger("Type", type);
@@ -10,8 +10,60 @@
*/
package vazkii.botania.common.item.lens;
import java.awt.Color;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import vazkii.botania.api.mana.IManaSpreader;
import vazkii.botania.common.Botania;
public class LensFlare extends Lens {
// TODO
@Override
public boolean allowBurstShooting(ItemStack stack, IManaSpreader spreader, boolean redstone) {
return false;
}
@Override
public void onControlledSpreaderTick(ItemStack stack, IManaSpreader spreader, boolean redstone) {
if(!redstone)
emitParticles(stack, spreader, redstone);
}
@Override
public void onControlledSpreaderPulse(ItemStack stack, IManaSpreader spreader, boolean redstone) {
emitParticles(stack, spreader, redstone);
}
private void emitParticles(ItemStack stack, IManaSpreader spreader, boolean redstone) {
float rotationYaw = -(spreader.getRotationX() + 90F);
float rotationPitch = spreader.getRotationY();
// Lots of EntityThrowable copypasta
float f = 0.3F;
float mx = (float) (MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f / 2D);
float mz = (float) (-(MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f) / 2D);
float my = (float) (MathHelper.sin(rotationPitch / 180.0F * (float) Math.PI) * f / 2D);
int storedColor = ItemLens.getStoredColor(stack);
float r = 1, g = 1, b = 1;
TileEntity tile = (TileEntity) spreader;
if(storedColor == 16) {
Color c = Color.getHSBColor(tile.getWorldObj().getTotalWorldTime() * 2 % 360 / 360F, 1F, 1F);
r = (float) c.getRed() / 255F;
g = (float) c.getGreen() / 255F;
b = (float) c.getBlue() / 255F;
} else if(storedColor >= 0) {
float[] colortable = EntitySheep.fleeceColorTable[storedColor];
r = colortable[0];
g = colortable[1];
b = colortable[2];
}
Botania.proxy.wispFX(tile.getWorldObj(), tile.xCoord + 0.5, tile.yCoord + 0.5, tile.zCoord + 0.5, r, g, b, 0.4F, mx, my, mz);
}
}
@@ -34,7 +34,6 @@ public class LensRedirect extends Lens {
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);