Functional Power System!

This commit is contained in:
Vasco Lavos committed 2014-01-26 21:28:00 +00:00
1 parent 0a23199bab
commit d16cbbea73
4 files changed
+197 -23

No files matched your search

@@ -20,5 +20,10 @@ package vazkii.botania.api.mana;
* - On the first tick of onUpdate(), call </i>ManaNetworkEvent.addCollector(this);<i>
*/
public interface IManaCollector extends IManaReceiver {
/**
* Called every tick on the client case the player is holding a Wand of the Forest.
*/
public void onClientDisplayTick();
}
@@ -132,7 +132,7 @@ public class TilePool extends TileSimpleInventory implements IManaPool {
@Override
public int getCurrentMana() {
return MAX_MANA;
return mana;
}
@Override
@@ -19,6 +19,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
@@ -29,6 +30,7 @@ import org.lwjgl.opengl.GL11;
import vazkii.botania.api.internal.ManaNetworkEvent;
import vazkii.botania.api.mana.IManaCollector;
import vazkii.botania.api.mana.IManaReceiver;
import vazkii.botania.client.core.helper.Vector3;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.entity.EntityManaBurst;
@@ -47,6 +49,8 @@ public class TileSpreader extends TileMod implements IManaCollector {
int knownMana = -1;
public float rotationX, rotationY;
boolean added = false;
IManaReceiver receiver = null;
@Override
public boolean isFull() {
@@ -76,6 +80,7 @@ public class TileSpreader extends TileMod implements IManaCollector {
ManaNetworkEvent.addCollector(this);
added = true;
}
tryShootBurst();
}
@Override
@@ -97,7 +102,7 @@ public class TileSpreader extends TileMod implements IManaCollector {
@Override
public boolean canRecieveManaFromBursts() {
return true;
return !isFull();
}
@Override
@@ -114,8 +119,6 @@ public class TileSpreader extends TileMod implements IManaCollector {
PacketDispatcher.sendPacketToPlayer(new Packet132TileEntityData(xCoord, yCoord, zCoord, -999, nbttagcompound), (Player) player);
}
worldObj.playSoundAtEntity(player, "random.orb", 1F, 1F);
if(!worldObj.isRemote)
worldObj.spawnEntityInWorld(new EntityManaBurst(worldObj, this, false, 0x00FF00));
} else {
MovingObjectPosition pos = raytraceFromEntity(worldObj, player, true, 5);
if(pos != null && pos.hitVec != null && !worldObj.isRemote) {
@@ -141,6 +144,62 @@ public class TileSpreader extends TileMod implements IManaCollector {
}
}
public boolean canShootBurst = true;
public void tryShootBurst() {
if(receiver == null) {
EntityManaBurst fakeBurst = getBurst(true);
TileEntity receiver = fakeBurst.getCollidedTile(true);
if(receiver != null && receiver instanceof IManaReceiver)
this.receiver = (IManaReceiver) receiver;
}
if(receiver != null) {
TileEntity tile = (TileEntity) receiver;
TileEntity tileAt = worldObj.getBlockTileEntity(tile.xCoord, tile.yCoord, tile.zCoord);
if(tileAt instanceof IManaReceiver)
receiver = (IManaReceiver) tileAt;
else receiver = null;
if(receiver != null) {
if(canShootBurst && receiver.canRecieveManaFromBursts() && !receiver.isFull()) {
EntityManaBurst burst = getBurst(false);
if(burst != null) {
mana -= burst.getMana();
worldObj.spawnEntityInWorld(burst);
canShootBurst = false;
}
}
}
}
}
public EntityManaBurst getBurst(boolean fake) {
int color = 0x00FF00;
// Apply color changes here.
EntityManaBurst burst = new EntityManaBurst(worldObj, this, fake, color);
int maxMana = 160;
// Apply max mana changes here.
int ticksBeforeManaLoss = 100;
// Apply ticks before mana loss changes here
float manaLossPerTick = 4F;
// Apply mana loss per tick changes here
if(getCurrentMana() >= maxMana || fake) {
burst.setMana(maxMana);
burst.setStartingMana(maxMana);
burst.setMinManaLoss(ticksBeforeManaLoss);
burst.setManaLossPerTick(manaLossPerTick);
return burst;
}
return null;
}
public static MovingObjectPosition raytraceFromEntity(World world, Entity player, boolean par3, double range) {
float f = 1.0F;
float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
@@ -188,4 +247,8 @@ public class TileSpreader extends TileMod implements IManaCollector {
GL11.glDisable(GL11.GL_BLEND);
}
@Override
public void onClientDisplayTick() {
}
}
@@ -13,11 +13,15 @@ package vazkii.botania.common.entity;
import java.awt.Color;
import cpw.mods.fml.common.network.PacketDispatcher;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import vazkii.botania.api.mana.IManaReceiver;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.tile.TileSpreader;
@@ -30,36 +34,66 @@ public class EntityManaBurst extends EntityThrowable {
public EntityManaBurst(World world) {
super(world);
setSize(0F, 0F);
dataWatcher.addObject(25, 0);
dataWatcher.setObjectWatched(25);
for(int i = 0; i < 8; i++) {
int j = 24 + i;
if(j == 28)
dataWatcher.addObject(j, 0F);
else dataWatcher.addObject(j, 0);
dataWatcher.setObjectWatched(j);
}
}
public EntityManaBurst(World par1World, TileSpreader spreader, boolean fake, int color) {
this(par1World);
this.fake = fake;
setBurstSourceCoords(spreader.xCoord, spreader.yCoord, spreader.zCoord);
setLocationAndAngles(spreader.xCoord + 0.5, spreader.yCoord + 0.5, spreader.zCoord + 0.5, 0, 0);
rotationYaw = -(spreader.rotationX + 90F);
rotationPitch = spreader.rotationY;
float f = 0.4F;
this.motionX = -(double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f) / 2D;
this.motionZ = -(double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f) / 2D;
this.motionY = -(double)(-MathHelper.sin((this.rotationPitch + this.func_70183_g()) / 180.0F * (float)Math.PI) * f) / 2D;
motionX = (MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f) / 2D;
motionZ = -(MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f) / 2D;
motionY = (MathHelper.sin((rotationPitch + func_70183_g()) / 180.0F * (float) Math.PI) * f) / 2D;
posX += motionX * 5;
posY += motionY * 5;
posZ += motionZ * 5;
// posX += motionX * 5;
// posY += motionY * 5;
// posZ += motionZ * 5;
setColor(color);
}
float accumulatedManaLoss = 0;
@Override
public void onUpdate() {
super.onUpdate();
particles();
if(ticksExisted > 100)
setDead();
int mana = getMana();
if(ticksExisted >= getMinManaLoss()) {
accumulatedManaLoss += getManaLossPerTick();
int loss = (int) accumulatedManaLoss;
setMana(mana - loss);
accumulatedManaLoss -= loss;
if(getMana() <= 0)
setDead();
}
}
TileEntity collidedTile = null;
boolean noParticles = false;
public TileEntity getCollidedTile(boolean noParticles) {
this.noParticles = noParticles;
while(!isDead) {
++ticksExisted;
onUpdate();
}
return collidedTile;
}
@Override
@@ -75,7 +109,7 @@ public class EntityManaBurst extends EntityThrowable {
}
public void particles() {
if(!worldObj.isRemote)
if(!worldObj.isRemote || isDead)
return;
Color color = new Color(getColor());
@@ -83,16 +117,43 @@ public class EntityManaBurst extends EntityThrowable {
float g = (float) color.getGreen() / 255F;
float b = (float) color.getBlue() / 255F;
if(fake)
Botania.proxy.sparkleFX(worldObj, posX, posY, posZ, r, g, b, 1F, 0, true);
else Botania.proxy.wispFX(worldObj, posX, posY, posZ, r, g, b, 0.5F * (float) (100 - ticksExisted) / 100F, (float) -motionX * 0.01F, (float) -motionY * 0.01F, (float) -motionZ * 0.01F);
if(fake) {
if(!noParticles)
Botania.proxy.sparkleFX(worldObj, posX, posY, posZ, r, g, b, 1F, 0, true);
} else {
int mana = getMana();
int maxMana = getStartingMana();
float size = (float) mana / (float) maxMana;
Botania.proxy.wispFX(worldObj, posX, posY, posZ, r, g, b, 0.25F * size, (float) -motionX * 0.01F, (float) -motionY * 0.01F, (float) -motionZ * 0.01F);
}
}
@Override
protected void onImpact(MovingObjectPosition movingobjectposition) {
// TODO
if(movingobjectposition.entityHit == null)
setDead();
if(movingobjectposition.entityHit == null) {
TileEntity tile = worldObj.getBlockTileEntity(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
collidedTile = tile;
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
if(tile == null || tile.xCoord != coords.posX || tile.yCoord != coords.posY || tile.zCoord != coords.posZ) {
if(!worldObj.isRemote && tile != null && tile instanceof IManaReceiver && ((IManaReceiver) tile).canRecieveManaFromBursts()) {
((IManaReceiver) tile).recieveMana(getMana());
PacketDispatcher.sendPacketToAllInDimension(tile.getDescriptionPacket(), worldObj.provider.dimensionId);
}
setDead();
}
}
}
@Override
public void setDead() {
super.setDead();
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
TileEntity tile = worldObj.getBlockTileEntity(coords.posX, coords.posY, coords.posZ);
if(tile != null && tile instanceof TileSpreader)
((TileSpreader) tile).canShootBurst = true;
}
@Override
@@ -101,11 +162,56 @@ public class EntityManaBurst extends EntityThrowable {
}
int getColor() {
return dataWatcher.getWatchableObjectInt(25);
return dataWatcher.getWatchableObjectInt(24);
}
void setColor(int color) {
dataWatcher.updateObject(25, color);
dataWatcher.updateObject(24, color);
}
public int getMana() {
return dataWatcher.getWatchableObjectInt(25);
}
public void setMana(int mana) {
dataWatcher.updateObject(25, mana);
}
public int getStartingMana() {
return dataWatcher.getWatchableObjectInt(26);
}
public void setStartingMana(int mana) {
dataWatcher.updateObject(26, mana);
}
public int getMinManaLoss() {
return dataWatcher.getWatchableObjectInt(27);
}
public void setMinManaLoss(int minManaLoss) {
dataWatcher.updateObject(27, minManaLoss);
}
public float getManaLossPerTick() {
return dataWatcher.getWatchableObjectFloat(28);
}
public void setManaLossPerTick(float mana) {
dataWatcher.updateObject(28, mana);
}
public ChunkCoordinates getBurstSourceChunkCoordinates() {
int x = dataWatcher.getWatchableObjectInt(29);
int y = dataWatcher.getWatchableObjectInt(30);
int z = dataWatcher.getWatchableObjectInt(31);
return new ChunkCoordinates(x, y, z);
}
public void setBurstSourceCoords(int x, int y, int z) {
dataWatcher.updateObject(29, x);
dataWatcher.updateObject(30, y);
dataWatcher.updateObject(31, z);
}
}