ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java

77 lines
2.1 KiB
Java
Raw Normal View History

/*
* 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
*/
package de.ellpeck.actuallyadditions.mod.tile;
2024-03-02 21:23:08 +01:00
import net.minecraft.nbt.CompoundTag;
2024-03-04 20:21:48 +01:00
import net.neoforged.neoforge.energy.EnergyStorage;
2019-05-02 09:10:29 +02:00
public class CustomEnergyStorage extends EnergyStorage {
2022-06-13 00:13:33 +02:00
boolean dirty = false;
2019-05-02 09:10:29 +02:00
public CustomEnergyStorage(int capacity, int maxReceive, int maxExtract) {
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) {
int before = this.maxExtract;
2016-11-26 08:58:42 +01:00
this.maxExtract = Integer.MAX_VALUE;
int toReturn = this.extractEnergy(maxExtract, simulate);
2016-11-26 08:58:42 +01:00
this.maxExtract = before;
return toReturn;
}
2019-05-02 09:10:29 +02:00
public int receiveEnergyInternal(int maxReceive, boolean simulate) {
int before = this.maxReceive;
2016-11-26 08:58:42 +01:00
this.maxReceive = Integer.MAX_VALUE;
int toReturn = this.receiveEnergy(maxReceive, simulate);
2016-11-26 08:58:42 +01:00
this.maxReceive = before;
return toReturn;
}
2019-02-27 19:53:05 +01:00
2022-06-13 00:13:33 +02:00
public boolean isDirty() {
return dirty;
}
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
}
2024-03-02 21:23:08 +01:00
public void readFromNBT(CompoundTag 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
}
2024-03-02 21:23:08 +01:00
public void writeToNBT(CompoundTag 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;
this.dirty = true;
2016-11-26 08:58:42 +01:00
}
}