mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
Fluxfield uses FE instead of RF, delete RF api files. Closes #2117
This commit is contained in:
8 files changed
+70
-186
No files matched your search
@@ -103,7 +103,6 @@ public class Botania {
|
||||
public static boolean bloodMagicLoaded = false;
|
||||
public static boolean coloredLightsLoaded = false;
|
||||
public static boolean etFuturumLoaded = false;
|
||||
public static boolean rfApiLoaded = false;
|
||||
public static boolean storageDrawersLoaded = false;
|
||||
|
||||
@Instance(LibMisc.MOD_ID)
|
||||
@@ -123,7 +122,6 @@ public class Botania {
|
||||
bloodMagicLoaded = Loader.isModLoaded("bloodmagic"); // Psh, noob
|
||||
coloredLightsLoaded = Loader.isModLoaded("easycoloredlights");
|
||||
etFuturumLoaded = Loader.isModLoaded("etfuturum");
|
||||
rfApiLoaded = ModAPIManager.INSTANCE.hasAPI("CoFHAPI|energy");
|
||||
storageDrawersLoaded = Loader.isModLoaded("storagedrawers");
|
||||
|
||||
BotaniaAPI.internalHandler = new InternalMethodHandler();
|
||||
|
||||
@@ -38,14 +38,6 @@ public class BlockRFGenerator extends BlockMod implements ILexiconable {
|
||||
setSoundType(SoundType.STONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "CoFHAPI|energy")
|
||||
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos tilePos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile != null && tile instanceof TileRFGenerator)
|
||||
((TileRFGenerator) tile).onNeighborTileChange(tilePos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state) {
|
||||
return true;
|
||||
|
||||
@@ -13,106 +13,112 @@ package vazkii.botania.common.block.tile.mana;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import vazkii.botania.api.mana.IManaReceiver;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.tile.TileMod;
|
||||
|
||||
@Optional.Interface(iface = "cofh.api.energy.IEnergyConnection", modid = "CoFHAPI|energy")
|
||||
public class TileRFGenerator extends TileMod implements IManaReceiver, IEnergyConnection {
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
private static final int CONVERSION_RATE = 10;
|
||||
private static final int MAX_MANA = 1280 * CONVERSION_RATE;
|
||||
public class TileRFGenerator extends TileMod implements IManaReceiver {
|
||||
|
||||
private static final int MANA_TO_FE = 10;
|
||||
private static final int MAX_ENERGY = 1280 * MANA_TO_FE;
|
||||
|
||||
private static final String TAG_MANA = "mana";
|
||||
int mana = 0;
|
||||
int energy = 0;
|
||||
|
||||
// Thanks to skyboy for help with this cuz I'm a noob with RF
|
||||
private final EnumMap<EnumFacing, IEnergyReceiver> receiverCache = new EnumMap<>(EnumFacing.class);
|
||||
private boolean deadCache;
|
||||
private final IEnergyStorage energyHandler = new IEnergyStorage() {
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
// todo allow pulling?
|
||||
@Override public boolean canExtract() { return false; }
|
||||
@Override public int extractEnergy(int maxExtract, boolean simulate) { return 0; }
|
||||
|
||||
@Override public int receiveEnergy(int maxReceive, boolean simulate) { return 0; }
|
||||
@Override public boolean canReceive() { return false; }
|
||||
};
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "CoFHAPI|energy")
|
||||
public void validate() {
|
||||
super.validate();
|
||||
deadCache = true;
|
||||
public boolean hasCapability(@Nonnull Capability<?> cap, @Nullable EnumFacing side) {
|
||||
return cap == CapabilityEnergy.ENERGY || super.hasCapability(cap, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getCapability(@Nonnull Capability<T> cap, @Nullable EnumFacing side) {
|
||||
if(cap == CapabilityEnergy.ENERGY) {
|
||||
return CapabilityEnergy.ENERGY.cast(energyHandler);
|
||||
} else return super.getCapability(cap, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if(!world.isRemote && Botania.rfApiLoaded) {
|
||||
if(deadCache)
|
||||
reCache();
|
||||
|
||||
int transfer = Math.min(mana, 160 * CONVERSION_RATE);
|
||||
mana -= transfer;
|
||||
mana += transmitEnergy(transfer);
|
||||
if(!world.isRemote) {
|
||||
int transfer = Math.min(energy, 160 * MANA_TO_FE);
|
||||
energy -= transfer;
|
||||
energy += transmitEnergy(transfer);
|
||||
}
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "CoFHAPI|energy")
|
||||
private final int transmitEnergy(int energy) {
|
||||
for(Map.Entry<EnumFacing, IEnergyReceiver> e : receiverCache.entrySet()) {
|
||||
IEnergyReceiver tile = e.getValue();
|
||||
if (tile == null)
|
||||
private int transmitEnergy(int energy) {
|
||||
for(EnumFacing e : EnumFacing.VALUES) {
|
||||
BlockPos neighbor = getPos().offset(e);
|
||||
if(!world.isBlockLoaded(neighbor))
|
||||
continue;
|
||||
|
||||
energy -= tile.receiveEnergy(e.getKey().getOpposite(), energy, false);
|
||||
TileEntity te = world.getTileEntity(neighbor);
|
||||
if(te == null)
|
||||
continue;
|
||||
|
||||
if (energy <= 0)
|
||||
return 0;
|
||||
IEnergyStorage storage = null;
|
||||
|
||||
if(te.hasCapability(CapabilityEnergy.ENERGY, e.getOpposite())) {
|
||||
storage = te.getCapability(CapabilityEnergy.ENERGY, e.getOpposite());
|
||||
} else if(te.hasCapability(CapabilityEnergy.ENERGY, null)) {
|
||||
storage = te.getCapability(CapabilityEnergy.ENERGY, null);
|
||||
}
|
||||
|
||||
if(storage != null) {
|
||||
energy -= storage.receiveEnergy(energy, false);
|
||||
|
||||
if (energy <= 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "CoFHAPI|energy")
|
||||
private void reCache() {
|
||||
if(deadCache) {
|
||||
for(EnumFacing dir : EnumFacing.VALUES)
|
||||
onNeighborTileChange(pos.offset(dir));
|
||||
deadCache = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "CoFHAPI|energy")
|
||||
public void onNeighborTileChange(BlockPos pos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
BlockPos q = getPos();
|
||||
EnumFacing side = EnumFacing.getFacingFromVector(pos.getX() - q.getX(), pos.getY() - q.getY(), pos.getZ() - q.getZ());
|
||||
|
||||
addCache(tile, side);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "CoFHAPI|energy")
|
||||
private void addCache(TileEntity tile, EnumFacing side) {
|
||||
receiverCache.remove(side);
|
||||
|
||||
if(tile instanceof IEnergyReceiver) {
|
||||
receiverCache.put(side, (IEnergyReceiver)tile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentMana() {
|
||||
return mana / CONVERSION_RATE;
|
||||
return energy / MANA_TO_FE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFull() {
|
||||
return mana >= MAX_MANA;
|
||||
return energy >= MAX_ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recieveMana(int mana) {
|
||||
this.mana = Math.min(MAX_MANA, this.mana + mana * CONVERSION_RATE);
|
||||
this.energy = Math.min(MAX_ENERGY, this.energy + mana * MANA_TO_FE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,17 +128,12 @@ public class TileRFGenerator extends TileMod implements IManaReceiver, IEnergyCo
|
||||
|
||||
@Override
|
||||
public void writePacketNBT(NBTTagCompound cmp) {
|
||||
cmp.setInteger(TAG_MANA, mana);
|
||||
cmp.setInteger(TAG_MANA, energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readPacketNBT(NBTTagCompound cmp) {
|
||||
mana = cmp.getInteger(TAG_MANA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
return true;
|
||||
energy = cmp.getInteger(TAG_MANA);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user