2016-11-23 18:10:55 +01:00
|
|
|
/*
|
|
|
|
* This file ("CustomEnergyStorage.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-11-23 18:10:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2016-11-26 08:58:42 +01:00
|
|
|
import net.minecraftforge.energy.EnergyStorage;
|
2016-11-23 18:10:55 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class CustomEnergyStorage extends EnergyStorage {
|
2022-06-13 00:13:33 +02:00
|
|
|
boolean dirty = false;
|
2016-11-23 18:10:55 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public CustomEnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
2016-11-23 18:10:55 +01:00
|
|
|
super(capacity, maxReceive, maxExtract);
|
|
|
|
}
|
|
|
|
|
2022-06-13 00:13:33 +02:00
|
|
|
@Override
|
|
|
|
public int receiveEnergy(int maxReceive, boolean simulate) {
|
|
|
|
dirty = true;
|
|
|
|
return super.receiveEnergy(maxReceive, simulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int extractEnergy(int maxExtract, boolean simulate) {
|
|
|
|
dirty = true;
|
|
|
|
return super.extractEnergy(maxExtract, simulate);
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public int extractEnergyInternal(int maxExtract, boolean simulate) {
|
2016-11-23 18:10:55 +01:00
|
|
|
int before = this.maxExtract;
|
2016-11-26 08:58:42 +01:00
|
|
|
this.maxExtract = Integer.MAX_VALUE;
|
2016-11-23 18:10:55 +01:00
|
|
|
|
|
|
|
int toReturn = this.extractEnergy(maxExtract, simulate);
|
|
|
|
|
2016-11-26 08:58:42 +01:00
|
|
|
this.maxExtract = before;
|
2016-11-23 18:10:55 +01:00
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public int receiveEnergyInternal(int maxReceive, boolean simulate) {
|
2016-11-23 18:10:55 +01:00
|
|
|
int before = this.maxReceive;
|
2016-11-26 08:58:42 +01:00
|
|
|
this.maxReceive = Integer.MAX_VALUE;
|
2016-11-23 18:10:55 +01:00
|
|
|
|
|
|
|
int toReturn = this.receiveEnergy(maxReceive, simulate);
|
|
|
|
|
2016-11-26 08:58:42 +01:00
|
|
|
this.maxReceive = before;
|
2016-11-23 18:10:55 +01:00
|
|
|
return toReturn;
|
|
|
|
}
|
2019-02-27 19:53:05 +01:00
|
|
|
|
2022-06-13 00:13:33 +02:00
|
|
|
public boolean isDirty() {
|
|
|
|
return dirty;
|
2018-09-27 21:17:23 +02:00
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
2022-06-13 00:13:33 +02:00
|
|
|
public void clearDirty() {
|
|
|
|
dirty = false;
|
2016-11-26 20:43:50 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
public void readFromNBT(CompoundNBT compound) {
|
2022-10-15 01:58:04 +02:00
|
|
|
if (compound.contains("Energy"))
|
|
|
|
this.setEnergyStored(compound.getInt("Energy"));
|
2016-11-26 08:58:42 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
public void writeToNBT(CompoundNBT compound) {
|
2021-02-27 16:33:00 +01:00
|
|
|
compound.putInt("Energy", this.getEnergyStored());
|
2016-11-26 08:58:42 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public void setEnergyStored(int energy) {
|
2016-11-26 08:58:42 +01:00
|
|
|
this.energy = energy;
|
2022-10-13 00:49:01 +02:00
|
|
|
this.dirty = true;
|
2016-11-26 08:58:42 +01:00
|
|
|
}
|
2016-11-23 18:10:55 +01:00
|
|
|
}
|