This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
2020-07-13 20:37:21 +00:00
|
|
|
package com.thebrokenrail.energonrelics.block.entity.battery;
|
|
|
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
|
|
import net.minecraft.nbt.CompoundTag;
|
|
|
|
|
|
|
|
public class BatteryCoreBlockEntity extends BlockEntity {
|
|
|
|
private long energy = 0;
|
|
|
|
|
|
|
|
public BatteryCoreBlockEntity(BlockEntityType<?> type) {
|
|
|
|
super(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CompoundTag toTag(CompoundTag tag) {
|
|
|
|
super.toTag(tag);
|
|
|
|
tag.putLong("Energy", energy);
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fromTag(BlockState state, CompoundTag tag) {
|
|
|
|
super.fromTag(state, tag);
|
2020-08-03 19:48:30 +00:00
|
|
|
energy = Math.max(0, tag.getLong("Energy"));
|
2020-07-13 20:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long getEnergy() {
|
|
|
|
return energy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEnergy(long value) {
|
2020-08-03 19:48:30 +00:00
|
|
|
if (value < 0) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
2020-07-13 20:37:21 +00:00
|
|
|
energy = value;
|
2020-07-28 20:38:21 +00:00
|
|
|
markDirty();
|
2020-07-13 20:37:21 +00:00
|
|
|
}
|
|
|
|
}
|