mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-15 17:44:55 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e348dbc5d | ||
|
|
39114ec429 | ||
|
|
3b82fe3bd0 | ||
|
|
2667334252 | ||
|
|
be39e2c3c3 | ||
|
|
40eece7d77 |
No files matched your search
@@ -55,6 +55,9 @@ sourceSets {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'http://maven.epoxide.xyz'
|
||||
}
|
||||
maven {
|
||||
url "http://dvs1.progwml6.com/files/maven"
|
||||
}
|
||||
@@ -65,6 +68,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
deobfCompile "net.darkhax.tesla:Tesla:${tesla_version}"
|
||||
deobfCompile "mezz.jei:jei_${mcversion}:${jei_version}:api"
|
||||
runtime "mezz.jei:jei_${mcversion}:${jei_version}"
|
||||
deobfCompile "net.industrial-craft:industrialcraft-2:${ic2_version}:api"
|
||||
|
||||
+5
-4
@@ -1,10 +1,11 @@
|
||||
mcversion=1.10
|
||||
forgeversion=12.18.0.1989-1.10.0
|
||||
mcversion=1.10.2
|
||||
forgeversion=12.18.0.2005-1.10.0
|
||||
mcp_mappings=snapshot_20160525
|
||||
|
||||
jei_version=3.7.0.+
|
||||
tesla_version=1.9.4-1.1.0.24
|
||||
jei_version=3.7.3.221
|
||||
ic2_version=2.5.5-ex19
|
||||
|
||||
version_major=5
|
||||
version_minor=1
|
||||
version_patch=6
|
||||
version_patch=8
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#Tue Jun 21 15:23:47 PDT 2016
|
||||
#Mon Sep 14 12:28:28 PDT 2015
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.apiculture.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -23,6 +24,7 @@ import forestry.core.tiles.IActivatable;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyReceiver, IActivatable, IAlvearyComponent.Climatiser {
|
||||
|
||||
@@ -143,4 +145,18 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
return energyManager.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -104,8 +104,10 @@ public abstract class EntityMinecartForestry extends EntityMinecart implements I
|
||||
@Override
|
||||
public void killMinecart(DamageSource damageSource) {
|
||||
super.killMinecart(damageSource);
|
||||
Block block = getDisplayTile().getBlock();
|
||||
entityDropItem(new ItemStack(block, 1, block.getMetaFromState(getDisplayTile())), 0.0F);
|
||||
if (this.worldObj.getGameRules().getBoolean("doEntityDrops")) {
|
||||
Block block = getDisplayTile().getBlock();
|
||||
entityDropItem(new ItemStack(block), 0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
// fix cart contents rendering as black in the End dimension
|
||||
|
||||
@@ -113,7 +113,7 @@ public abstract class AlleleSpecies extends Allele implements IAlleleSpeciesBuil
|
||||
|
||||
@Override
|
||||
public ItemStack[] getResearchBounty(World world, GameProfile researcher, IIndividual individual, int bountyLevel) {
|
||||
if (world.rand.nextFloat() < bountyLevel / 32.0f) {
|
||||
if (world.rand.nextFloat() < bountyLevel / 16.0f) {
|
||||
List<? extends IMutation> allMutations = getRoot().getCombinations(this);
|
||||
if (!allMutations.isEmpty()) {
|
||||
List<IMutation> unresearchedMutations = new ArrayList<>();
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import forestry.api.genetics.IGenome;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
@@ -292,17 +293,9 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory> {
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
HashMap<IMutation, IAllele> combinations = new HashMap<>();
|
||||
|
||||
ISpeciesRoot speciesRoot = individual.getGenome().getSpeciesRoot();
|
||||
|
||||
for (IMutation mutation : speciesRoot.getCombinations(individual.getGenome().getPrimary())) {
|
||||
combinations.put(mutation, individual.getGenome().getPrimary());
|
||||
}
|
||||
|
||||
for (IMutation mutation : speciesRoot.getCombinations(individual.getGenome().getSecondary())) {
|
||||
combinations.put(mutation, individual.getGenome().getSecondary());
|
||||
}
|
||||
IGenome genome = individual.getGenome();
|
||||
ISpeciesRoot speciesRoot = genome.getSpeciesRoot();
|
||||
IAlleleSpecies species = genome.getPrimary();
|
||||
|
||||
int columnWidth = 50;
|
||||
int x = 0;
|
||||
@@ -310,17 +303,16 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory> {
|
||||
EntityPlayer player = Proxies.common.getPlayer();
|
||||
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.worldObj, player.getGameProfile());
|
||||
|
||||
for (Map.Entry<IMutation, IAllele> mutation : combinations.entrySet()) {
|
||||
|
||||
if (breedingTracker.isDiscovered(mutation.getKey())) {
|
||||
drawMutationInfo(mutation.getKey(), mutation.getValue(), COLUMN_0 + x, breedingTracker);
|
||||
for (IMutation mutation : speciesRoot.getCombinations(species)) {
|
||||
if (breedingTracker.isDiscovered(mutation)) {
|
||||
drawMutationInfo(mutation, species, COLUMN_0 + x, breedingTracker);
|
||||
} else {
|
||||
// Do not display secret undiscovered mutations.
|
||||
if (mutation.getKey().isSecret()) {
|
||||
if (mutation.isSecret()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
drawUnknownMutation(mutation.getKey(), COLUMN_0 + x, breedingTracker);
|
||||
drawUnknownMutation(mutation, COLUMN_0 + x, breedingTracker);
|
||||
}
|
||||
|
||||
x += columnWidth;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -251,22 +252,17 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -33,6 +34,7 @@ import forestry.core.utils.BlockUtil;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public abstract class TileEngine extends TileBase implements IEnergyConnection, IActivatable {
|
||||
private static final int CANT_SEND_ENERGY_TIME = 20;
|
||||
@@ -294,4 +296,19 @@ public abstract class TileEngine extends TileBase implements IEnergyConnection,
|
||||
public EnergyManager getEnergyManager() {
|
||||
return energyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -352,8 +352,9 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && inventory != null){
|
||||
SidedInvWrapper sidedInvWrapper = new SidedInvWrapper(inventory, facing);
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(sidedInvWrapper);
|
||||
@@ -362,8 +363,8 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && inventory != null){
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && inventory != null){
|
||||
return true;
|
||||
}
|
||||
return super.hasCapability(capability, facing);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -27,6 +28,7 @@ import forestry.core.render.TankRenderInfo;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
//@Optional.Interface(iface = "buildcraft.api.tiles.IHasWork", modid = "BuildCraftAPI|tiles")
|
||||
public abstract class TilePowered extends TileBase implements IRenderableTile, IEnergyReceiver, IPowerHandler, ISpeedUpgradable, IStreamableGui {
|
||||
@@ -218,4 +220,19 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
return energyManager.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import cofh.api.energy.IEnergyReceiver;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileEngine;
|
||||
import forestry.energy.EnergyManager;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.BlockOldLog;
|
||||
@@ -51,12 +52,19 @@ public abstract class BlockUtil {
|
||||
}
|
||||
|
||||
public static boolean isEnergyReceiverOrEngine(EnumFacing side, TileEntity tile) {
|
||||
if (!(tile instanceof IEnergyReceiver) && !(tile instanceof TileEngine)) {
|
||||
return false;
|
||||
}
|
||||
if (tile != null) {
|
||||
if (EnergyManager.TESLA_CONSUMER != null) {
|
||||
if (tile.hasCapability(EnergyManager.TESLA_CONSUMER, side)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
IEnergyConnection receptor = (IEnergyConnection) tile;
|
||||
return receptor.canConnectEnergy(side);
|
||||
if (tile instanceof IEnergyReceiver || (tile instanceof TileEngine)) {
|
||||
IEnergyConnection receptor = (IEnergyConnection) tile;
|
||||
return receptor.canConnectEnergy(side);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean tryPlantCocoaPod(World world, BlockPos pos) {
|
||||
|
||||
@@ -2,6 +2,9 @@ package forestry.energy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.darkhax.tesla.api.ITeslaConsumer;
|
||||
import net.darkhax.tesla.api.ITeslaHolder;
|
||||
import net.darkhax.tesla.api.ITeslaProducer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -13,11 +16,25 @@ import forestry.core.network.IStreamable;
|
||||
import forestry.core.tiles.TileEngine;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
@Optional.InterfaceList({
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaConsumer", modid = "Tesla"),
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaProducer", modid = "Tesla"),
|
||||
@Optional.Interface(iface = "net.darkhax.tesla.api.ITeslaHolder", modid = "Tesla")
|
||||
})
|
||||
public class EnergyManager implements IEnergyReceiver, ITeslaConsumer, ITeslaProducer, ITeslaHolder, IEnergyProvider, IStreamable {
|
||||
@CapabilityInject(ITeslaConsumer.class)
|
||||
public static Capability<ITeslaConsumer> TESLA_CONSUMER = null;
|
||||
@CapabilityInject(ITeslaProducer.class)
|
||||
public static Capability<ITeslaProducer> TESLA_PRODUCER = null;
|
||||
@CapabilityInject(ITeslaHolder.class)
|
||||
public static Capability<ITeslaHolder> TESLA_HOLDER = null;
|
||||
|
||||
public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreamable {
|
||||
private enum EnergyTransferMode {
|
||||
EXTRACT, RECEIVE, BOTH
|
||||
}
|
||||
@@ -63,7 +80,6 @@ public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreama
|
||||
|
||||
/* NBT */
|
||||
public EnergyManager readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
NBTTagCompound energyManagerNBT = nbt.getCompoundTag("EnergyManager");
|
||||
NBTTagCompound energyStorageNBT = energyManagerNBT.getCompoundTag("EnergyStorage");
|
||||
energyStorage.readFromNBT(energyStorageNBT);
|
||||
@@ -72,7 +88,6 @@ public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreama
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
NBTTagCompound energyStorageNBT = new NBTTagCompound();
|
||||
energyStorage.writeToNBT(energyStorageNBT);
|
||||
|
||||
@@ -188,16 +203,18 @@ public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreama
|
||||
*/
|
||||
public int sendEnergy(EnumFacing orientation, TileEntity tile, int amount, boolean simulate) {
|
||||
int sent = 0;
|
||||
if (BlockUtil.isEnergyReceiverOrEngine(orientation.getOpposite(), tile)) {
|
||||
if (tile != null) {
|
||||
int extractable = energyStorage.extractEnergy(amount, true);
|
||||
if (extractable > 0) {
|
||||
|
||||
if (tile instanceof IEnergyReceiver) {
|
||||
EnumFacing side = orientation.getOpposite();
|
||||
if (TESLA_CONSUMER != null && tile.hasCapability(TESLA_CONSUMER, side)) {
|
||||
sent = sendEnergyTesla(tile, side, extractable, simulate);
|
||||
} else if (tile instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver receptor = (IEnergyReceiver) tile;
|
||||
sent = receptor.receiveEnergy(orientation.getOpposite(), extractable, simulate);
|
||||
} else if (tile instanceof TileEngine) {
|
||||
sent = receptor.receiveEnergy(side, extractable, simulate);
|
||||
} else if (tile instanceof TileEngine) { // engine chaining
|
||||
TileEngine receptor = (TileEngine) tile;
|
||||
sent = receptor.getEnergyManager().receiveEnergy(orientation.getOpposite(), extractable, simulate);
|
||||
sent = receptor.getEnergyManager().receiveEnergy(side, extractable, simulate);
|
||||
}
|
||||
|
||||
energyStorage.extractEnergy(sent, simulate);
|
||||
@@ -219,4 +236,62 @@ public class EnergyManager implements IEnergyReceiver, IEnergyProvider, IStreama
|
||||
public void generateEnergy(int amount) {
|
||||
energyStorage.modifyEnergyStored(amount);
|
||||
}
|
||||
|
||||
public boolean hasCapability(Capability<?> capability) {
|
||||
if (capability == TESLA_PRODUCER && canExtract()) {
|
||||
return true;
|
||||
} else if (capability == TESLA_CONSUMER && canReceive()) {
|
||||
return true;
|
||||
} else if (capability == TESLA_HOLDER) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T> T getCapability(Capability<T> capability) {
|
||||
if (capability == TESLA_PRODUCER && canExtract()) {
|
||||
return TESLA_PRODUCER.cast(this);
|
||||
} else if (capability == TESLA_CONSUMER && canReceive()) {
|
||||
return TESLA_CONSUMER.cast(this);
|
||||
} else if (capability == TESLA_HOLDER) {
|
||||
return TESLA_HOLDER.cast(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
public static int sendEnergyTesla(TileEntity tile, EnumFacing side, int amount, boolean simulate) {
|
||||
ITeslaConsumer consumer = tile.getCapability(TESLA_CONSUMER, side);
|
||||
return (int) consumer.givePower(amount, simulate);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
@Override
|
||||
public long givePower(long power, boolean simulated) {
|
||||
if (!canReceive()) {
|
||||
return 0;
|
||||
}
|
||||
return energyStorage.receiveEnergy(power, simulated);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
@Override
|
||||
public long takePower(long power, boolean simulated) {
|
||||
if (!canExtract()) {
|
||||
return 0;
|
||||
}
|
||||
return energyStorage.extractEnergy(power, simulated);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
@Override
|
||||
public long getStoredPower() {
|
||||
return energyStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "Tesla")
|
||||
@Override
|
||||
public long getCapacity() {
|
||||
return energyStorage.getMaxEnergyStored();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package forestry.energy;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class EnergyStorage {
|
||||
|
||||
protected int energy;
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public EnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public EnergyStorage readFromNBT(NBTTagCompound nbt) {
|
||||
this.energy = nbt.getInteger("Energy");
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
if (energy < 0) {
|
||||
energy = 0;
|
||||
}
|
||||
nbt.setInteger("Energy", energy);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public EnergyStorage setCapacity(int capacity) {
|
||||
this.capacity = capacity;
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public EnergyStorage setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EnergyStorage setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EnergyStorage setMaxExtract(int maxExtract) {
|
||||
this.maxExtract = maxExtract;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMaxReceive() {
|
||||
return maxReceive;
|
||||
}
|
||||
|
||||
public int getMaxExtract() {
|
||||
return maxExtract;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow for server to client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
|
||||
* are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void setEnergyStored(int energy) {
|
||||
if (energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (energy < 0) {
|
||||
this.energy = 0;
|
||||
} else {
|
||||
this.energy = energy;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
|
||||
* externally, as not all IEnergyHandlers are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void modifyEnergyStored(int energy) {
|
||||
this.energy += energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* IEnergyStorage */
|
||||
public int receiveEnergy(long maxReceive, boolean simulate) {
|
||||
int energyReceived = (int) Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
}
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
public int extractEnergy(long maxExtract, boolean simulate) {
|
||||
int energyExtracted = (int) Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
|
||||
if (!simulate) {
|
||||
energy -= energyExtracted;
|
||||
}
|
||||
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
public int getEnergyStored() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
public int getMaxEnergyStored() {
|
||||
return capacity;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,10 @@
|
||||
package forestry.energy.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.energy.EnergyManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
@@ -293,22 +295,17 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.energy.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -215,15 +216,16 @@ public class TileEuGenerator extends TileBase implements ISidedInventory, ILiqui
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -167,22 +168,17 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
|
||||
@@ -250,22 +250,17 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -320,22 +321,17 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -324,21 +325,16 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -520,21 +521,16 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -161,22 +162,17 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -257,22 +258,17 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -187,22 +188,17 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
|
||||
}
|
||||
return null;
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.farming.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -21,6 +22,7 @@ import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public class TileFarmGearbox extends TileFarm implements IEnergyReceiver, IEnergyHandler, IFarmComponent.Active {
|
||||
|
||||
@@ -117,4 +119,18 @@ public class TileFarmGearbox extends TileFarm implements IEnergyReceiver, IEnerg
|
||||
return energyManager.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public class TileGreenhouseGearbox extends TileGreenhouse implements IEnergyReceiver, IEnergyHandler {
|
||||
|
||||
@@ -59,4 +63,25 @@ public class TileGreenhouseGearbox extends TileGreenhouse implements IEnergyRece
|
||||
return getMultiblockLogic().getController().getEnergyManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
EnergyManager energyManager = getEnergyManager();
|
||||
if (energyManager != null && energyManager.hasCapability(capability)) {
|
||||
return true;
|
||||
}
|
||||
return super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
EnergyManager energyManager = getEnergyManager();
|
||||
if (energyManager != null) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
}
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user