mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-13 16:54:08 +00:00
Fix apiary not retaining AuraCharge state
This commit is contained in:
1 parent
051cc96514
commit
0fd8b319de
9 files changed
+341
-173
No files matched your search
@@ -0,0 +1,4 @@
|
||||
package magicbees.api.bees;
|
||||
|
||||
public interface IAuraChargeType {
|
||||
}
|
||||
@@ -15,23 +15,32 @@ public interface IMagicApiaryAuraProvider {
|
||||
*
|
||||
* @return True if a charge is given; false otherwise.
|
||||
*/
|
||||
public boolean getMutationCharge();
|
||||
|
||||
boolean getMutationCharge();
|
||||
|
||||
/**
|
||||
* Requests a mutation charge from the aura provider. If true is returned, the
|
||||
* aura provider should decrement its internal charge by one. If there are no
|
||||
* charges remaining, it should return false.
|
||||
*
|
||||
*
|
||||
* @return True if a charge is given; false otherwise.
|
||||
*/
|
||||
public boolean getDeathRateCharge();
|
||||
|
||||
boolean getDeathRateCharge();
|
||||
|
||||
/**
|
||||
* Requests a mutation charge from the aura provider. If true is returned, the
|
||||
* aura provider should decrement its internal charge by one. If there are no
|
||||
* charges remaining, it should return false.
|
||||
*
|
||||
*
|
||||
* @return True if a charge is given; false otherwise.
|
||||
*/
|
||||
public boolean getProductionCharge();
|
||||
boolean getProductionCharge();
|
||||
|
||||
/**
|
||||
* Requests a mutation charge from the aura provider. If true is returned, the
|
||||
* aura provider should decrement its internal charge by one. If there are no
|
||||
* charges remaining, it should return false.
|
||||
*
|
||||
* @return True if a charge is given; false otherwise.
|
||||
*/
|
||||
boolean getCharge(IAuraChargeType auraChargeType);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package magicbees.bees;
|
||||
|
||||
import magicbees.api.bees.IAuraChargeType;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
|
||||
public enum AuraChargeType implements IAuraChargeType {
|
||||
MUTATION(Aspect.WATER, 850, 11),
|
||||
DEATH(Aspect.ENTROPY, 400, 5),
|
||||
PRODUCTION(Aspect.AIR, 300, 3);
|
||||
|
||||
public final int duration;
|
||||
public final Aspect aspect;
|
||||
/** The number of ticks to count between draining vis from the environment **/
|
||||
public final int tickRate;
|
||||
public final int flag = 1 << ordinal();
|
||||
|
||||
AuraChargeType(Aspect aspect, int duration, int tickRate) {
|
||||
this.aspect = aspect;
|
||||
this.duration = duration;
|
||||
this.tickRate = tickRate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package magicbees.main.utils.net;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
import magicbees.main.utils.ChunkCoords;
|
||||
import magicbees.main.utils.LogHelper;
|
||||
import magicbees.main.utils.net.NetworkEventHandler.EventType;
|
||||
import magicbees.tileentity.AuraCharges;
|
||||
import magicbees.tileentity.ITileEntityAuraCharged;
|
||||
|
||||
public class EventAuraChargeUpdate extends EventCoords {
|
||||
|
||||
private int flags;
|
||||
|
||||
public EventAuraChargeUpdate(ChunkCoords position, AuraCharges auraCharges) {
|
||||
super(EventType.AURA_CHARGE_UPDATE, position);
|
||||
flags = auraCharges.writeToFlags();
|
||||
}
|
||||
|
||||
public EventAuraChargeUpdate(DataInputStream byteStream) {
|
||||
super(EventType.FLAGS_UPDATE, byteStream);
|
||||
|
||||
this.readDataFromInputStream(byteStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeDataToOutputStream(DataOutputStream byteStream) {
|
||||
super.writeDataToOutputStream(byteStream);
|
||||
|
||||
try {
|
||||
byteStream.writeInt(flags);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LogHelper.error("Could not write EventAuraChargeUpdate data to stream.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readDataFromInputStream(DataInputStream byteStream) {
|
||||
super.readDataFromInputStream(byteStream);
|
||||
|
||||
try {
|
||||
this.flags = byteStream.readInt();
|
||||
}
|
||||
catch (IOException e) {
|
||||
LogHelper.error("Could not read EventAuraChargeUpdate data from stream.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(EntityPlayerMP player) {
|
||||
TileEntity tile = FMLClientHandler.instance().getClient().theWorld.getTileEntity(getCoords().x, getCoords().y, getCoords().z);
|
||||
|
||||
if (tile != null && tile instanceof ITileEntityAuraCharged) {
|
||||
AuraCharges auraCharges = ((ITileEntityAuraCharged) tile).getAuraCharges();
|
||||
auraCharges.readFromFlags(flags);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,9 @@ import magicbees.main.utils.ChunkCoords;
|
||||
import magicbees.main.utils.LogHelper;
|
||||
import magicbees.main.utils.VersionInfo;
|
||||
import magicbees.main.utils.error.InvalidEventTypeIndexException;
|
||||
import magicbees.tileentity.AuraCharges;
|
||||
import magicbees.tileentity.ITileEntityAuraCharged;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
@@ -35,6 +38,7 @@ public class NetworkEventHandler {
|
||||
UNKNOWN,
|
||||
INVENTORY_UPDATE,
|
||||
FLAGS_UPDATE,
|
||||
AURA_CHARGE_UPDATE
|
||||
;
|
||||
}
|
||||
|
||||
@@ -68,6 +72,13 @@ public class NetworkEventHandler {
|
||||
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
public <T extends TileEntity & ITileEntityAuraCharged> void sendAuraChargeUpdate(T entity, AuraCharges auraCharges) {
|
||||
EventAuraChargeUpdate event = new EventAuraChargeUpdate(new ChunkCoords(entity), auraCharges);
|
||||
FMLProxyPacket packet = event.getPacket();
|
||||
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
private void sendPacket(FMLProxyPacket packet) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
@@ -102,6 +113,10 @@ public class NetworkEventHandler {
|
||||
EventFlagsUpdate eventData = new EventFlagsUpdate(data);
|
||||
eventData.process(player);
|
||||
}
|
||||
else if (eventId == EventType.AURA_CHARGE_UPDATE.ordinal()) {
|
||||
EventAuraChargeUpdate evenData = new EventAuraChargeUpdate(data);
|
||||
evenData.process(player);
|
||||
}
|
||||
else {
|
||||
throw new InvalidEventTypeIndexException("");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package magicbees.tileentity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import magicbees.bees.AuraChargeType;
|
||||
|
||||
public class AuraCharges {
|
||||
private static final String auraChargesTagName = "AuraCharges";
|
||||
|
||||
private final Map<AuraChargeType, Long> charges = new HashMap<AuraChargeType, Long>(AuraChargeType.values().length);
|
||||
|
||||
public void start(AuraChargeType auraChargeType, World worldObj) {
|
||||
charges.put(auraChargeType, worldObj.getTotalWorldTime());
|
||||
}
|
||||
|
||||
public boolean isActive(AuraChargeType auraChargeType) {
|
||||
return charges.keySet().contains(auraChargeType);
|
||||
}
|
||||
|
||||
public boolean isExpired(AuraChargeType auraChargeType, World worldObj) {
|
||||
Long chargeStart = charges.get(auraChargeType);
|
||||
return chargeStart == null || chargeStart + auraChargeType.duration <= worldObj.getTotalWorldTime();
|
||||
}
|
||||
|
||||
public void stop(AuraChargeType AuraChargeType) {
|
||||
charges.remove(AuraChargeType);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbtTagCompound) {
|
||||
NBTTagCompound auraChargeTags = new NBTTagCompound();
|
||||
for (Map.Entry<AuraChargeType, Long> chargeEntry : charges.entrySet()) {
|
||||
String chargeName = chargeEntry.getKey().toString();
|
||||
Long chargeStart = chargeEntry.getValue();
|
||||
auraChargeTags.setLong(chargeName, chargeStart);
|
||||
}
|
||||
nbtTagCompound.setTag(auraChargesTagName, auraChargeTags);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
||||
NBTTagCompound auraChargeTags = nbtTagCompound.getCompoundTag(auraChargesTagName);
|
||||
for (AuraChargeType auraCharge : AuraChargeType.values()) {
|
||||
String chargeName = auraCharge.toString();
|
||||
Long chargeStart = auraChargeTags.getLong(chargeName);
|
||||
if (chargeStart > 0) {
|
||||
charges.put(auraCharge, chargeStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int writeToFlags() {
|
||||
int flags = 0;
|
||||
for (AuraChargeType auraChargeType : charges.keySet()) {
|
||||
flags |= auraChargeType.flag;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void readFromFlags(int flags) {
|
||||
charges.clear();
|
||||
for (AuraChargeType auraCharge : AuraChargeType.values()) {
|
||||
if ((flags & auraCharge.flag) > 0) {
|
||||
charges.put(auraCharge, 0L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package magicbees.tileentity;
|
||||
|
||||
public interface ITileEntityAuraCharged {
|
||||
AuraCharges getAuraCharges();
|
||||
}
|
||||
@@ -4,13 +4,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import magicbees.bees.AuraChargeType;
|
||||
import magicbees.api.bees.IMagicApiaryAuraProvider;
|
||||
import magicbees.bees.BeeManager;
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.main.MagicBees;
|
||||
import magicbees.main.utils.ChunkCoords;
|
||||
import magicbees.main.utils.ItemStackUtils;
|
||||
import magicbees.main.utils.LogHelper;
|
||||
import magicbees.main.utils.net.EventAuraChargeUpdate;
|
||||
import magicbees.main.utils.net.NetworkEventHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
@@ -19,6 +20,7 @@ import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
@@ -41,7 +43,7 @@ import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class TileEntityMagicApiary extends TileEntity implements ISidedInventory, IBeeHousing, ITileEntityFlags {
|
||||
public class TileEntityMagicApiary extends TileEntity implements ISidedInventory, IBeeHousing, ITileEntityAuraCharged {
|
||||
|
||||
public static final String tileEntityName = CommonProxy.DOMAIN + ".magicApiary";
|
||||
private GameProfile ownerProfile;
|
||||
@@ -55,9 +57,6 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
private static final int SLOT_PRODUCTS_COUNT = 7;
|
||||
|
||||
private static final int AURAPROVIDER_SEARCH_RADIUS = 6;
|
||||
private static int CHARGE_TIME_MUTATION = 850;
|
||||
private static int CHARGE_TIME_DEATH = 400;
|
||||
private static int CHARGE_TIME_PRODUCTION = 300;
|
||||
|
||||
private IBeekeepingLogic logic;
|
||||
private IMagicApiaryAuraProvider auraProvider;
|
||||
@@ -66,22 +65,14 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
private int displayHealthMax = 0;
|
||||
private int displayHealth = 0;
|
||||
private boolean init = false;
|
||||
|
||||
private static final int OFFSET_MUTATION = 0;
|
||||
private static final int OFFSET_DEATH = 1;
|
||||
private static final int OFFSET_PRODUCTION = 2;
|
||||
private static final int FLAG_MUTATIONCHARGE = 1 << OFFSET_MUTATION;
|
||||
private static final int FLAG_DEATHCHARGE = 1 << OFFSET_DEATH;
|
||||
private static final int FLAG_PRODUCTIONCHARGE = 1 << OFFSET_PRODUCTION;
|
||||
private long[] chargeTimestamps = new long[3];
|
||||
private int flags;
|
||||
|
||||
|
||||
private final AuraCharges auraCharges = new AuraCharges();
|
||||
|
||||
private IErrorState errorState = ErrorStateRegistry.getErrorState("ok");
|
||||
|
||||
private ItemStack[] items;
|
||||
|
||||
public TileEntityMagicApiary(){
|
||||
flags = 0;
|
||||
items = new ItemStack[12];
|
||||
logic = BeeManager.beeRoot.createBeekeepingLogic(this);
|
||||
}
|
||||
@@ -518,11 +509,8 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
}
|
||||
|
||||
ChunkCoords.writeToNBT(this.auraProviderPosition, compound);
|
||||
|
||||
compound.setInteger("flags", this.flags);
|
||||
compound.setLong("timestamp0", chargeTimestamps[0]);
|
||||
compound.setLong("timestamp1", chargeTimestamps[1]);
|
||||
compound.setLong("timestamp2", chargeTimestamps[2]);
|
||||
|
||||
auraCharges.writeToNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -532,7 +520,7 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
NBTTagList items = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < items.tagCount(); i++) {
|
||||
NBTTagCompound item = (NBTTagCompound)items.getCompoundTagAt(i);
|
||||
NBTTagCompound item = items.getCompoundTagAt(i);
|
||||
int slot = item.getByte("Slot");
|
||||
|
||||
if (slot >= 0 && slot < getSizeInventory()) {
|
||||
@@ -543,12 +531,16 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
int biomeId = compound.getInteger("BiomeId");
|
||||
biome = BiomeGenBase.getBiome(biomeId);
|
||||
logic.readFromNBT(compound);
|
||||
|
||||
|
||||
this.auraProviderPosition = ChunkCoords.readFromNBT(compound);
|
||||
this.flags = compound.getInteger("flags");
|
||||
this.chargeTimestamps[0] = compound.getLong("timestamp0");
|
||||
this.chargeTimestamps[1] = compound.getLong("timestamp1");
|
||||
this.chargeTimestamps[2] = compound.getLong("timestamp2");
|
||||
|
||||
auraCharges.readFromNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
EventAuraChargeUpdate event = new EventAuraChargeUpdate(new ChunkCoords(this), auraCharges);
|
||||
return event.getPacket();
|
||||
}
|
||||
|
||||
public float getExactTemperature() {
|
||||
@@ -561,7 +553,7 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (init == false) {
|
||||
if (!init) {
|
||||
init = true;
|
||||
updateBiome();
|
||||
}
|
||||
@@ -640,81 +632,52 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
}
|
||||
|
||||
public boolean isProductionBoosted() {
|
||||
return (flags & FLAG_PRODUCTIONCHARGE) == FLAG_PRODUCTIONCHARGE;
|
||||
return auraCharges.isActive(AuraChargeType.PRODUCTION);
|
||||
}
|
||||
|
||||
public boolean isDeathRateBoosted() {
|
||||
return (flags & FLAG_DEATHCHARGE) == FLAG_DEATHCHARGE;
|
||||
return auraCharges.isActive(AuraChargeType.DEATH);
|
||||
}
|
||||
|
||||
public boolean isMutationBoosted() {
|
||||
return (flags & FLAG_MUTATIONCHARGE) == FLAG_MUTATIONCHARGE;
|
||||
return auraCharges.isActive(AuraChargeType.MUTATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
if (!worldObj.isRemote) {
|
||||
NetworkEventHandler.getInstance().sendFlagsUpdate(this, new int[] {flags});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAuraProvider() {
|
||||
if (worldObj.getTotalWorldTime() % 10 != 0) {
|
||||
return;
|
||||
}
|
||||
if (!locationHasAuraProvider(auraProviderPosition)) {
|
||||
if (getAuraProvider(auraProviderPosition) == null) {
|
||||
this.auraProvider = null;
|
||||
this.auraProviderPosition = null;
|
||||
return;
|
||||
}
|
||||
|
||||
int oldFlags = flags;
|
||||
if (!isMutationBoosted() && this.auraProvider.getMutationCharge()) {
|
||||
flags |= FLAG_MUTATIONCHARGE;
|
||||
chargeTimestamps[OFFSET_MUTATION] = worldObj.getTotalWorldTime();
|
||||
}
|
||||
|
||||
if (!isDeathRateBoosted() && this.auraProvider.getDeathRateCharge()) {
|
||||
flags |= FLAG_DEATHCHARGE;
|
||||
chargeTimestamps[OFFSET_DEATH] = worldObj.getTotalWorldTime();
|
||||
}
|
||||
|
||||
if (!isProductionBoosted() && this.auraProvider.getProductionCharge()) {
|
||||
flags |= FLAG_PRODUCTIONCHARGE;
|
||||
chargeTimestamps[OFFSET_PRODUCTION] = worldObj.getTotalWorldTime();
|
||||
}
|
||||
boolean auraChargesChanged = false;
|
||||
for (AuraChargeType chargeType : AuraChargeType.values()) {
|
||||
if (!auraCharges.isActive(chargeType) && auraProvider.getCharge(chargeType)) {
|
||||
auraCharges.start(chargeType, worldObj);
|
||||
auraChargesChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldFlags != flags) {
|
||||
NetworkEventHandler.getInstance().sendFlagsUpdate(this, new int[] {flags});
|
||||
if (auraChargesChanged) {
|
||||
NetworkEventHandler.getInstance().sendAuraChargeUpdate(this, auraCharges);
|
||||
}
|
||||
}
|
||||
|
||||
private void tickCharges() {
|
||||
int oldFlags = flags;
|
||||
if (isMutationBoosted()) {
|
||||
if (chargeTimestamps[OFFSET_MUTATION] + CHARGE_TIME_MUTATION <= worldObj.getTotalWorldTime()) {
|
||||
if (auraProvider == null || !this.auraProvider.getMutationCharge()) {
|
||||
flags = flags & ~FLAG_MUTATIONCHARGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isDeathRateBoosted()) {
|
||||
if (chargeTimestamps[OFFSET_DEATH] + CHARGE_TIME_DEATH <= worldObj.getTotalWorldTime()) {
|
||||
if (auraProvider == null || !this.auraProvider.getDeathRateCharge()) {
|
||||
flags = flags & ~FLAG_DEATHCHARGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isProductionBoosted()) {
|
||||
if (chargeTimestamps[OFFSET_PRODUCTION] + CHARGE_TIME_PRODUCTION <= worldObj.getTotalWorldTime()) {
|
||||
if (auraProvider == null || !this.auraProvider.getProductionCharge()) {
|
||||
flags = flags & ~FLAG_PRODUCTIONCHARGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oldFlags != flags) {
|
||||
NetworkEventHandler.getInstance().sendFlagsUpdate(this, new int[] {flags});
|
||||
boolean auraChargesChanged = false;
|
||||
|
||||
for (AuraChargeType chargeType : AuraChargeType.values()) {
|
||||
if (auraCharges.isActive(chargeType) && auraCharges.isExpired(chargeType, worldObj) && (auraProvider == null || !auraProvider.getCharge(chargeType))) {
|
||||
auraCharges.stop(chargeType);
|
||||
auraChargesChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (auraChargesChanged) {
|
||||
NetworkEventHandler.getInstance().sendAuraChargeUpdate(this, auraCharges);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,20 +685,20 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
if (worldObj.getTotalWorldTime() % 5 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.auraProviderPosition == null) {
|
||||
List<Chunk> chunks = getChunksInSearchRange();
|
||||
for (Chunk chunk : chunks) {
|
||||
if (searchChunkForBooster(chunk)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!locationHasAuraProvider(auraProviderPosition)) {
|
||||
this.auraProviderPosition = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.auraProviderPosition == null) {
|
||||
List<Chunk> chunks = getChunksInSearchRange();
|
||||
for (Chunk chunk : chunks) {
|
||||
if (searchChunkForBooster(chunk)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.auraProvider = getAuraProvider(auraProviderPosition);
|
||||
if (auraProvider == null) {
|
||||
this.auraProviderPosition = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<Chunk> getChunksInSearchRange() {
|
||||
@@ -777,11 +740,11 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
auraProviderPosition = new ChunkCoords(worldObj.provider.dimensionId, x, y, z);
|
||||
}
|
||||
|
||||
private boolean locationHasAuraProvider(ChunkCoords coords) {
|
||||
return locationHasAuraProvider(coords.x, coords.y, coords.z);
|
||||
private IMagicApiaryAuraProvider getAuraProvider(ChunkCoords coords) {
|
||||
return getAuraProvider(coords.x, coords.y, coords.z);
|
||||
}
|
||||
|
||||
private boolean locationHasAuraProvider(int x, int y, int z) {
|
||||
private IMagicApiaryAuraProvider getAuraProvider(int x, int y, int z) {
|
||||
Chunk chunk = worldObj.getChunkFromBlockCoords(x, z);
|
||||
x %= 16;
|
||||
z %= 16;
|
||||
@@ -793,16 +756,14 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
}
|
||||
ChunkPosition cPos = new ChunkPosition(x, y, z);
|
||||
TileEntity entity = (TileEntity)chunk.chunkTileEntityMap.get(cPos);
|
||||
if (entity != null && entity instanceof IMagicApiaryAuraProvider) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!(entity instanceof IMagicApiaryAuraProvider)) {
|
||||
return null;
|
||||
}
|
||||
return (IMagicApiaryAuraProvider)entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(int[] flagArray) {
|
||||
if (flagArray.length == 1) {
|
||||
this.flags = flagArray[0];
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public AuraCharges getAuraCharges() {
|
||||
return auraCharges;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
package magicbees.tileentity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import magicbees.api.bees.IAuraChargeType;
|
||||
import magicbees.bees.AuraChargeType;
|
||||
import magicbees.api.bees.IMagicApiaryAuraProvider;
|
||||
import magicbees.main.CommonProxy;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -12,45 +17,51 @@ public class TileEntityVisAuraProvider extends TileEntity implements IMagicApiar
|
||||
public static final String tileEntityName = CommonProxy.DOMAIN + ".visAuraProvider";
|
||||
|
||||
private static final int MAX_CHARGES = 10;
|
||||
int currentMutationCharges;
|
||||
int currentDeathCharges;
|
||||
int currentProductionCharges;
|
||||
|
||||
private static final int VIS_PER_CHARGE = 8;
|
||||
private static Aspect ASPECT_MUTATION = Aspect.WATER;
|
||||
private static Aspect ASPECT_DEATH = Aspect.ENTROPY;
|
||||
private static Aspect ASPECT_PRODUCTION = Aspect.AIR;
|
||||
int currentMutationVis;
|
||||
int currentDeathVis;
|
||||
int currentProductionVis;
|
||||
|
||||
|
||||
private static class AuraCharge {
|
||||
int charges;
|
||||
int vis;
|
||||
|
||||
public int[] toArray() {
|
||||
return new int[]{charges, vis};
|
||||
}
|
||||
|
||||
public void fromArray(int[] array) {
|
||||
if (array.length == 2) {
|
||||
charges = array[0];
|
||||
vis = array[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<AuraChargeType, AuraCharge> currentCharges;
|
||||
|
||||
public TileEntityVisAuraProvider() {
|
||||
super();
|
||||
|
||||
AuraChargeType[] auraChargeTypes = AuraChargeType.values();
|
||||
currentCharges = new HashMap<AuraChargeType, AuraCharge>(auraChargeTypes.length);
|
||||
for (AuraChargeType auraChargeType : auraChargeTypes) {
|
||||
currentCharges.put(auraChargeType, new AuraCharge());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
long modTickRate = worldObj.getTotalWorldTime();
|
||||
if (currentProductionCharges < MAX_CHARGES && modTickRate % 3 == 0) {
|
||||
currentProductionVis += getVisFromNet(ASPECT_PRODUCTION);
|
||||
if (currentProductionVis >= VIS_PER_CHARGE) {
|
||||
currentProductionVis -= VIS_PER_CHARGE;
|
||||
++currentProductionCharges;
|
||||
}
|
||||
}
|
||||
if (currentDeathCharges < MAX_CHARGES && modTickRate % 5 == 0) {
|
||||
currentDeathVis += getVisFromNet(ASPECT_DEATH);
|
||||
if (currentDeathVis >= VIS_PER_CHARGE) {
|
||||
currentDeathVis -= VIS_PER_CHARGE;
|
||||
++currentDeathCharges;
|
||||
}
|
||||
}
|
||||
if (currentMutationCharges < MAX_CHARGES && modTickRate % 11 == 0) {
|
||||
currentMutationCharges += getVisFromNet(ASPECT_MUTATION);
|
||||
if (currentMutationCharges >= VIS_PER_CHARGE) {
|
||||
currentMutationCharges -= VIS_PER_CHARGE;
|
||||
++currentMutationCharges;
|
||||
long tick = worldObj.getTotalWorldTime();
|
||||
|
||||
for (Map.Entry<AuraChargeType, AuraCharge> currentCharge : currentCharges.entrySet()) {
|
||||
AuraChargeType type = currentCharge.getKey();
|
||||
AuraCharge auraCharge = currentCharge.getValue();
|
||||
|
||||
if (auraCharge.charges < MAX_CHARGES && (tick % type.tickRate) == 0) {
|
||||
auraCharge.vis += getVisFromNet(type.aspect);
|
||||
if (auraCharge.vis >= VIS_PER_CHARGE) {
|
||||
auraCharge.vis -= VIS_PER_CHARGE;
|
||||
auraCharge.charges++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,52 +72,54 @@ public class TileEntityVisAuraProvider extends TileEntity implements IMagicApiar
|
||||
|
||||
@Override
|
||||
public boolean getMutationCharge() {
|
||||
if (this.currentMutationCharges > 0) {
|
||||
--this.currentMutationCharges;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getCharge(AuraChargeType.MUTATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDeathRateCharge() {
|
||||
if (this.currentDeathCharges > 0) {
|
||||
--this.currentDeathCharges;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getCharge(AuraChargeType.DEATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getProductionCharge() {
|
||||
if (this.currentProductionCharges > 0) {
|
||||
--this.currentProductionCharges;
|
||||
return getCharge(AuraChargeType.PRODUCTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getCharge(IAuraChargeType auraChargeType) {
|
||||
AuraCharge auraCharge = currentCharges.get(auraChargeType);
|
||||
if (auraCharge == null) {
|
||||
return false;
|
||||
}
|
||||
if (auraCharge.charges > 0) {
|
||||
auraCharge.charges--;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
this.currentMutationCharges = tag.getInteger("mutationCharges");
|
||||
this.currentMutationVis = tag.getInteger("mutationVis");
|
||||
this.currentDeathCharges = tag.getInteger("deathCharges");
|
||||
this.currentDeathVis = tag.getInteger("deathVis");
|
||||
this.currentProductionCharges = tag.getInteger("productionCharges");
|
||||
this.currentProductionVis = tag.getInteger("productionVis");
|
||||
|
||||
for (Map.Entry<AuraChargeType, AuraCharge> charge : currentCharges.entrySet()) {
|
||||
String auraName = charge.getKey().toString();
|
||||
int[] array = tag.getIntArray(auraName);
|
||||
AuraCharge auraCharge = charge.getValue();
|
||||
auraCharge.fromArray(array);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
tag.setInteger("mutationCharges", currentMutationCharges);
|
||||
tag.setInteger("mutationVis", currentMutationVis);
|
||||
tag.setInteger("deathCharges", currentDeathCharges);
|
||||
tag.setInteger("deathVis", currentDeathVis);
|
||||
tag.setInteger("productionCharges", currentProductionCharges);
|
||||
tag.setInteger("productionVis", currentProductionVis);
|
||||
|
||||
for (Map.Entry<AuraChargeType, AuraCharge> charge : currentCharges.entrySet()) {
|
||||
String auraName = charge.getKey().toString();
|
||||
AuraCharge auraCharge = charge.getValue();
|
||||
int[] array = auraCharge.toArray();
|
||||
tag.setIntArray(auraName, array);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user