mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-21 04:32:23 +00:00
Some more work on getting the power system ready for usage.
This commit is contained in:
1 parent
d16cbbea73
commit
b2e4041b42
7 files changed
+138
-72
No files matched your search
@@ -12,9 +12,11 @@
|
||||
package vazkii.botania.client.core.proxy;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import vazkii.botania.api.LexiconEntry;
|
||||
import vazkii.botania.api.mana.IManaCollector;
|
||||
import vazkii.botania.client.core.handler.HUDHandler;
|
||||
import vazkii.botania.client.fx.FXSparkle;
|
||||
import vazkii.botania.client.fx.FXWisp;
|
||||
@@ -32,6 +34,7 @@ import vazkii.botania.client.render.tile.RenderTileSpreader;
|
||||
import vazkii.botania.common.block.tile.TileAltar;
|
||||
import vazkii.botania.common.block.tile.TilePool;
|
||||
import vazkii.botania.common.block.tile.TileSpreader;
|
||||
import vazkii.botania.common.core.handler.ManaNetworkHandler;
|
||||
import vazkii.botania.common.core.proxy.CommonProxy;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
@@ -69,11 +72,18 @@ public class ClientProxy extends CommonProxy {
|
||||
GuiLexicon.currentOpenLexicon = new GuiLexiconEntry(entry, new GuiLexiconIndex(entry.category));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void twigWandClientUpdate() {
|
||||
for(TileEntity tile : ManaNetworkHandler.instance.getAllInWorld(ManaNetworkHandler.instance.manaCollectors, Minecraft.getMinecraft().thePlayer.dimension)) {
|
||||
if(tile instanceof IManaCollector)
|
||||
((IManaCollector) tile).onClientDisplayTick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sparkleFX(World world, double x, double y, double z, float r, float g, float b, float size, int m, boolean fake) {
|
||||
FXSparkle sparkle = new FXSparkle(world, x, y, z, size, r, g, b, m);
|
||||
sparkle.fake = fake;
|
||||
// sparkle.noClip = true;
|
||||
sparkle.fake = sparkle.noClip = fake;
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect(sparkle);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import vazkii.botania.common.lib.LibBlockNames;
|
||||
|
||||
public class TilePool extends TileSimpleInventory implements IManaPool {
|
||||
|
||||
public static final int MAX_MANA = 10000000;
|
||||
public static final int MAX_MANA = 1000000;
|
||||
|
||||
private static final String TAG_MANA = "mana";
|
||||
private static final String TAG_KNOWN_MANA = "knownMana";
|
||||
|
||||
@@ -25,11 +25,13 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import vazkii.botania.api.internal.ManaNetworkEvent;
|
||||
import vazkii.botania.api.mana.IManaCollector;
|
||||
import vazkii.botania.api.mana.IManaPool;
|
||||
import vazkii.botania.api.mana.IManaReceiver;
|
||||
import vazkii.botania.client.core.helper.Vector3;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
@@ -49,7 +51,7 @@ public class TileSpreader extends TileMod implements IManaCollector {
|
||||
int knownMana = -1;
|
||||
public float rotationX, rotationY;
|
||||
boolean added = false;
|
||||
|
||||
|
||||
IManaReceiver receiver = null;
|
||||
|
||||
@Override
|
||||
@@ -80,7 +82,29 @@ public class TileSpreader extends TileMod implements IManaCollector {
|
||||
ManaNetworkEvent.addCollector(this);
|
||||
added = true;
|
||||
}
|
||||
tryShootBurst();
|
||||
|
||||
boolean redstone = false;
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
TileEntity tileAt = worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
|
||||
if(tileAt instanceof IManaPool) {
|
||||
IManaPool pool = (IManaPool) tileAt;
|
||||
int manaInPool = pool.getCurrentMana();
|
||||
if(manaInPool > 0 && !isFull()) {
|
||||
int manaMissing = MAX_MANA - mana;
|
||||
int manaToRemove = Math.min(manaInPool, manaMissing);
|
||||
pool.recieveMana(-manaToRemove);
|
||||
recieveMana(manaToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
int redstoneSide = worldObj.getIndirectPowerLevelTo(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir.ordinal());
|
||||
if(redstoneSide > 0)
|
||||
redstone = true;
|
||||
}
|
||||
|
||||
if(!redstone)
|
||||
tryShootBurst();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,6 +122,14 @@ public class TileSpreader extends TileMod implements IManaCollector {
|
||||
|
||||
if(cmp.hasKey(TAG_KNOWN_MANA))
|
||||
knownMana = cmp.getInteger(TAG_KNOWN_MANA);
|
||||
|
||||
if(worldObj.isRemote) {
|
||||
EntityManaBurst fakeBurst = getBurst(true);
|
||||
TileEntity receiver = fakeBurst.getCollidedTile(true);
|
||||
if(receiver != null && receiver instanceof IManaReceiver)
|
||||
this.receiver = (IManaReceiver) receiver;
|
||||
else this.receiver = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,12 +157,12 @@ public class TileSpreader extends TileMod implements IManaCollector {
|
||||
double x = pos.hitVec.xCoord - xCoord - 0.5;
|
||||
double y = pos.hitVec.yCoord - yCoord - 0.5;
|
||||
double z = pos.hitVec.zCoord - zCoord - 0.5;
|
||||
|
||||
|
||||
if(pos.sideHit != 0 && pos.sideHit != 1) {
|
||||
Vector3 clickVector = new Vector3(x, 0, z);
|
||||
Vector3 relative = new Vector3(-0.5, 0, 0);
|
||||
double angle = Math.acos(clickVector.dotProduct(relative) / (relative.mag() * clickVector.mag())) * 180D / Math.PI;
|
||||
|
||||
|
||||
rotationX = (float) angle;
|
||||
if(clickVector.z < 0)
|
||||
rotationX = 360 - rotationX;
|
||||
@@ -139,13 +171,19 @@ public class TileSpreader extends TileMod implements IManaCollector {
|
||||
double angle = y * 180;
|
||||
rotationY = (float) angle;
|
||||
|
||||
EntityManaBurst fakeBurst = getBurst(true);
|
||||
TileEntity receiver = fakeBurst.getCollidedTile(true);
|
||||
if(receiver != null && receiver instanceof IManaReceiver)
|
||||
this.receiver = (IManaReceiver) receiver;
|
||||
else this.receiver = null;
|
||||
|
||||
PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean canShootBurst = true;
|
||||
|
||||
|
||||
public void tryShootBurst() {
|
||||
if(receiver == null) {
|
||||
EntityManaBurst fakeBurst = getBurst(true);
|
||||
@@ -153,14 +191,14 @@ public class TileSpreader extends TileMod implements IManaCollector {
|
||||
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);
|
||||
@@ -173,33 +211,33 @@ public class TileSpreader extends TileMod implements IManaCollector {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
@@ -249,6 +287,7 @@ public class TileSpreader extends TileMod implements IManaCollector {
|
||||
|
||||
@Override
|
||||
public void onClientDisplayTick() {
|
||||
EntityManaBurst burst = getBurst(true);
|
||||
burst.getCollidedTile(false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -97,6 +97,12 @@ public final class ManaNetworkHandler {
|
||||
tiles.add(tile);
|
||||
}
|
||||
|
||||
public List<TileEntity> getAllInWorld(Map<Integer, List<TileEntity>> map, int dim) {
|
||||
if(!map.containsKey(dim))
|
||||
return new ArrayList();
|
||||
return map.get(dim);
|
||||
}
|
||||
|
||||
public int getAmount(Map<Integer, List<TileEntity>> map, int dim) {
|
||||
if(!map.containsKey(dim))
|
||||
return 0;
|
||||
|
||||
@@ -63,6 +63,10 @@ public class CommonProxy {
|
||||
public void setEntryToOpen(LexiconEntry entry) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public void twigWandClientUpdate() {
|
||||
|
||||
}
|
||||
|
||||
public void sparkleFX(World world, double x, double y, double z, float r, float g, float b, float size, int m) {
|
||||
sparkleFX(world, x, y, z, r, g, b, size, m, false);
|
||||
|
||||
@@ -28,9 +28,9 @@ import vazkii.botania.common.block.tile.TileSpreader;
|
||||
public class EntityManaBurst extends EntityThrowable {
|
||||
|
||||
private static final String TAG_COLOR = "color";
|
||||
|
||||
|
||||
boolean fake = false;
|
||||
|
||||
|
||||
public EntityManaBurst(World world) {
|
||||
super(world);
|
||||
setSize(0F, 0F);
|
||||
@@ -43,100 +43,98 @@ public class EntityManaBurst extends EntityThrowable {
|
||||
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;
|
||||
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;
|
||||
setColor(color);
|
||||
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;
|
||||
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
|
||||
float accumulatedManaLoss = 0;
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
particles();
|
||||
|
||||
|
||||
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
|
||||
public void writeEntityToNBT(NBTTagCompound par1nbtTagCompound) {
|
||||
super.writeEntityToNBT(par1nbtTagCompound);
|
||||
par1nbtTagCompound.setInteger(TAG_COLOR, getColor());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readEntityFromNBT(NBTTagCompound par1nbtTagCompound) {
|
||||
super.readEntityFromNBT(par1nbtTagCompound);
|
||||
setColor(par1nbtTagCompound.getInteger(TAG_COLOR));
|
||||
}
|
||||
|
||||
|
||||
public void particles() {
|
||||
if(!worldObj.isRemote || isDead)
|
||||
return;
|
||||
|
||||
|
||||
Color color = new Color(getColor());
|
||||
float r = (float) color.getRed() / 255F;
|
||||
float g = (float) color.getGreen() / 255F;
|
||||
float b = (float) color.getBlue() / 255F;
|
||||
|
||||
int mana = getMana();
|
||||
int maxMana = getStartingMana();
|
||||
float size = (float) mana / (float) maxMana;
|
||||
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);
|
||||
}
|
||||
Botania.proxy.sparkleFX(worldObj, posX, posY, posZ, r, g, b, 0.4F * size, 1, true);
|
||||
} else
|
||||
Botania.proxy.wispFX(worldObj, posX, posY, posZ, r, g, b, 0.2F * size, (float) -motionX * 0.01F, (float) -motionY * 0.01F, (float) -motionZ * 0.01F);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onImpact(MovingObjectPosition movingobjectposition) {
|
||||
if(movingobjectposition.entityHit == null) {
|
||||
TileEntity tile = worldObj.getBlockTileEntity(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
|
||||
collidedTile = tile;
|
||||
|
||||
|
||||
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
|
||||
if((!fake || noParticles) && tile != null && (tile.xCoord != coords.posX || tile.yCoord != coords.posY || tile.zCoord != coords.posZ))
|
||||
collidedTile = tile;
|
||||
|
||||
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()) {
|
||||
if((!fake || noParticles) && !worldObj.isRemote && tile != null && tile instanceof IManaReceiver && ((IManaReceiver) tile).canRecieveManaFromBursts()) {
|
||||
((IManaReceiver) tile).recieveMana(getMana());
|
||||
PacketDispatcher.sendPacketToAllInDimension(tile.getDescriptionPacket(), worldObj.provider.dimensionId);
|
||||
}
|
||||
@@ -145,17 +143,19 @@ public class EntityManaBurst extends EntityThrowable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
|
||||
if(!fake) {
|
||||
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
|
||||
TileEntity tile = worldObj.getBlockTileEntity(coords.posX, coords.posY, coords.posZ);
|
||||
if(tile != null && tile instanceof TileSpreader)
|
||||
((TileSpreader) tile).canShootBurst = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected float getGravityVelocity() {
|
||||
return 0F;
|
||||
@@ -164,43 +164,43 @@ public class EntityManaBurst extends EntityThrowable {
|
||||
int getColor() {
|
||||
return dataWatcher.getWatchableObjectInt(24);
|
||||
}
|
||||
|
||||
|
||||
void setColor(int 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);
|
||||
@@ -208,7 +208,7 @@ public class EntityManaBurst extends EntityThrowable {
|
||||
|
||||
return new ChunkCoordinates(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
public void setBurstSourceCoords(int x, int y, int z) {
|
||||
dataWatcher.updateObject(29, x);
|
||||
dataWatcher.updateObject(30, y);
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.FakePlayer;
|
||||
import vazkii.botania.api.IWandable;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.lib.LibItemIDs;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
@@ -63,6 +64,12 @@ public class ItemTwigWand extends Item16Colors {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
|
||||
if(par3Entity instanceof EntityPlayer && ((EntityPlayer) par3Entity).getCurrentEquippedItem() == par1ItemStack)
|
||||
Botania.proxy.twigWandClientUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IconRegister par1IconRegister) {
|
||||
|
||||
Reference in new issue
Block a user