mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-13 00:37:57 +00:00
Merge pull request #777 from soundlogic2236/Squash
Made mana bursts and mana spreader's have more addon friendly code.
This commit is contained in:
commit
09ee7a63b5
5 files changed
+122
-37
No files matched your search
@@ -60,4 +60,6 @@ public interface IManaBurst {
|
||||
|
||||
public int getTicksExisted();
|
||||
|
||||
public void setFake(boolean fake);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* This class was created by <SoundLogic>. 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 @ [Apr 18, 2015, 7:30:00 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.mana;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Any TileEntity that implements this is considered a Mana Spreader,
|
||||
* by which can fire mana bursts as a spreader.
|
||||
*
|
||||
*/
|
||||
public interface IManaSpreader extends IManaBlock {
|
||||
|
||||
public float getRotationX();
|
||||
|
||||
public float getRotationY();
|
||||
|
||||
public void setCanShoot(boolean canShoot);
|
||||
|
||||
public int getBurstParticleTick();
|
||||
|
||||
public void setBurstParticleTick(int i);
|
||||
|
||||
public int getLastBurstDeathTick();
|
||||
|
||||
public void setLastBurstDeathTick(int ticksExisted);
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@API(owner = "Botania", apiVersion = "42", provides = "BotaniaAPI")
|
||||
@API(owner = "Botania", apiVersion = "43", provides = "BotaniaAPI")
|
||||
package vazkii.botania.api;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
@@ -43,6 +43,7 @@ import vazkii.botania.api.mana.ILensEffect;
|
||||
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.IThrottledPacket;
|
||||
import vazkii.botania.api.mana.ManaNetworkEvent;
|
||||
import vazkii.botania.api.wand.IWandBindable;
|
||||
@@ -57,7 +58,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 {
|
||||
public class TileSpreader extends TileSimpleInventory implements IManaCollector, IWandBindable, IKeyLocked, IThrottledPacket, IManaSpreader {
|
||||
|
||||
private static final int MAX_MANA = 1000;
|
||||
private static final int ULTRA_MAX_MANA = 6400;
|
||||
@@ -592,4 +593,39 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
|
||||
public void markDispatchable() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotationX() {
|
||||
return rotationX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotationY() {
|
||||
return rotationY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanShoot(boolean canShoot) {
|
||||
canShootBurst = canShoot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBurstParticleTick() {
|
||||
return burstParticleTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBurstParticleTick(int i) {
|
||||
burstParticleTick = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLastBurstDeathTick() {
|
||||
return lastBurstDeathTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastBurstDeathTick(int i) {
|
||||
lastBurstDeathTick = i;
|
||||
}
|
||||
}
|
||||
@@ -40,10 +40,10 @@ import vazkii.botania.api.mana.ILensEffect;
|
||||
import vazkii.botania.api.mana.IManaCollector;
|
||||
import vazkii.botania.api.mana.IManaCollisionGhost;
|
||||
import vazkii.botania.api.mana.IManaReceiver;
|
||||
import vazkii.botania.api.mana.IManaSpreader;
|
||||
import vazkii.botania.api.mana.IManaTrigger;
|
||||
import vazkii.botania.api.mana.IThrottledPacket;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.tile.mana.TileSpreader;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
import vazkii.botania.common.item.equipment.bauble.ItemTinyPlanet;
|
||||
@@ -93,14 +93,17 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
|
||||
}
|
||||
}
|
||||
|
||||
public EntityManaBurst(TileSpreader spreader, boolean fake) {
|
||||
this(spreader.getWorldObj());
|
||||
public EntityManaBurst(IManaSpreader spreader, boolean fake) {
|
||||
this(((TileEntity)spreader).getWorldObj());
|
||||
|
||||
TileEntity tile = (TileEntity) spreader;
|
||||
|
||||
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;
|
||||
setBurstSourceCoords(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
setLocationAndAngles(tile.xCoord + 0.5, tile.yCoord + 0.5, tile.zCoord + 0.5, 0, 0);
|
||||
rotationYaw = -(spreader.getRotationX() + 90F);
|
||||
rotationPitch = spreader.getRotationY();
|
||||
|
||||
float f = 0.4F;
|
||||
double mx = MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI) * f / 2D;
|
||||
@@ -352,8 +355,8 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
|
||||
if(!fake && !isDead) {
|
||||
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
|
||||
TileEntity tile = worldObj.getTileEntity(coords.posX, coords.posY, coords.posZ);
|
||||
if(tile != null && tile instanceof TileSpreader)
|
||||
((TileSpreader) tile).canShootBurst = false;
|
||||
if(tile != null && tile instanceof IManaSpreader)
|
||||
((IManaSpreader) tile).setCanShoot(false);
|
||||
}
|
||||
|
||||
ILensEffect lens = getLensInstance();
|
||||
@@ -394,8 +397,8 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity collidedTile = null;
|
||||
boolean noParticles = false;
|
||||
public TileEntity collidedTile = null;
|
||||
public boolean noParticles = false;
|
||||
|
||||
public TileEntity getCollidedTile(boolean noParticles) {
|
||||
this.noParticles = noParticles;
|
||||
@@ -564,16 +567,8 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
|
||||
collidedTile = tile;
|
||||
|
||||
if(tile == null || tile.xCoord != coords.posX || tile.yCoord != coords.posY || tile.zCoord != coords.posZ) {
|
||||
if(!fake && !noParticles && (!worldObj.isRemote || tile instanceof IClientManaHandler) && tile != null && tile instanceof IManaReceiver && ((IManaReceiver) tile).canRecieveManaFromBursts()) {
|
||||
int mana = getMana();
|
||||
if(tile instanceof IManaCollector)
|
||||
mana *= ((IManaCollector) tile).getManaYieldMultiplier(this);
|
||||
|
||||
((IManaReceiver) tile).recieveMana(mana);
|
||||
if(tile instanceof IThrottledPacket)
|
||||
((IThrottledPacket) tile).markDispatchable();
|
||||
else VanillaPacketDispatcher.dispatchTEToNearbyPlayers(worldObj, tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
}
|
||||
if(!fake && !noParticles && (!worldObj.isRemote || tile instanceof IClientManaHandler) && tile != null && tile instanceof IManaReceiver && ((IManaReceiver) tile).canRecieveManaFromBursts())
|
||||
onRecieverImpact((IManaReceiver) tile, tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
|
||||
if(block instanceof IManaTrigger)
|
||||
((IManaTrigger) block).onBurstCollision(this, worldObj, movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
|
||||
@@ -614,6 +609,17 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
|
||||
setDead();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onRecieverImpact(IManaReceiver tile, int x, int y, int z) {
|
||||
int mana = getMana();
|
||||
if(tile instanceof IManaCollector)
|
||||
mana *= ((IManaCollector) tile).getManaYieldMultiplier(this);
|
||||
|
||||
tile.recieveMana(mana);
|
||||
if(tile instanceof IThrottledPacket)
|
||||
((IThrottledPacket) tile).markDispatchable();
|
||||
else VanillaPacketDispatcher.dispatchTEToNearbyPlayers(worldObj, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDead() {
|
||||
@@ -622,8 +628,8 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
|
||||
if(!fake) {
|
||||
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
|
||||
TileEntity tile = worldObj.getTileEntity(coords.posX, coords.posY, coords.posZ);
|
||||
if(tile != null && tile instanceof TileSpreader)
|
||||
((TileSpreader) tile).canShootBurst = true;
|
||||
if(tile != null && tile instanceof IManaSpreader)
|
||||
((IManaSpreader) tile).setCanShoot(true);
|
||||
} else setDeathTicksForFakeParticle();
|
||||
}
|
||||
|
||||
@@ -637,6 +643,11 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
|
||||
return fake;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFake(boolean fake) {
|
||||
this.fake = fake;
|
||||
}
|
||||
|
||||
public void setScanBeam() {
|
||||
scanBeam = true;
|
||||
}
|
||||
@@ -770,33 +781,33 @@ public class EntityManaBurst extends EntityThrowable implements IManaBurst {
|
||||
return x + ":" + y + ":" + z;
|
||||
}
|
||||
|
||||
private boolean shouldDoFakeParticles() {
|
||||
public boolean shouldDoFakeParticles() {
|
||||
if(ConfigHandler.staticWandBeam)
|
||||
return true;
|
||||
|
||||
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
|
||||
TileEntity tile = worldObj.getTileEntity(coords.posX, coords.posY, coords.posZ);
|
||||
if(tile != null && tile instanceof TileSpreader)
|
||||
return getMana() != getStartingMana() && fullManaLastTick || Math.abs(((TileSpreader) tile).burstParticleTick - getTicksExisted()) < 4;
|
||||
if(tile != null && tile instanceof IManaSpreader)
|
||||
return getMana() != getStartingMana() && fullManaLastTick || Math.abs(((IManaSpreader) tile).getBurstParticleTick() - getTicksExisted()) < 4;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void incrementFakeParticleTick() {
|
||||
public void incrementFakeParticleTick() {
|
||||
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
|
||||
TileEntity tile = worldObj.getTileEntity(coords.posX, coords.posY, coords.posZ);
|
||||
if(tile != null && tile instanceof TileSpreader) {
|
||||
TileSpreader spreader = (TileSpreader) tile;
|
||||
spreader.burstParticleTick += 2;
|
||||
if(spreader.lastBurstDeathTick != -1 && spreader.burstParticleTick > spreader.lastBurstDeathTick)
|
||||
spreader.burstParticleTick = 0;
|
||||
if(tile != null && tile instanceof IManaSpreader) {
|
||||
IManaSpreader spreader = (IManaSpreader) tile;
|
||||
spreader.setBurstParticleTick(spreader.getBurstParticleTick()+2);
|
||||
if(spreader.getLastBurstDeathTick() != -1 && spreader.getBurstParticleTick() > spreader.getLastBurstDeathTick())
|
||||
spreader.setBurstParticleTick(0);
|
||||
}
|
||||
}
|
||||
|
||||
private void setDeathTicksForFakeParticle() {
|
||||
public void setDeathTicksForFakeParticle() {
|
||||
ChunkCoordinates coords = getBurstSourceChunkCoordinates();
|
||||
TileEntity tile = worldObj.getTileEntity(coords.posX, coords.posY, coords.posZ);
|
||||
if(tile != null && tile instanceof TileSpreader)
|
||||
((TileSpreader) tile).lastBurstDeathTick = getTicksExisted();
|
||||
if(tile != null && tile instanceof IManaSpreader)
|
||||
((IManaSpreader) tile).setLastBurstDeathTick(getTicksExisted());
|
||||
}
|
||||
|
||||
public static class PositionProperties {
|
||||
|
||||
Reference in new issue
Block a user