Everything was done

This commit is contained in:
Andrew 2023-03-26 16:20:21 +07:00
commit 89a89a6e21
108 changed files with 4570 additions and 0 deletions

View file

@ -0,0 +1,153 @@
package xyz.nuark.mods.electromana.tile;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
import vazkii.botania.api.mana.IManaReceiver;
import xyz.nuark.mods.electromana.ElectroMana;
import xyz.nuark.mods.electromana.ElectroManaStructures;
import xyz.nuark.mods.electromana.ElectroManaTiles;
import xyz.nuark.mods.electromana.capabilities.ManaAltarEnergyStorage;
import xyz.nuark.mods.electromana.structure.StructureType;
import xyz.nuark.mods.electromana.utils.BrokenStructureException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
// m'kay
// 1 hour for full pool = 3600 seconds
// Full pool = 2000000 points of mana
//
// Each second adds 555 mana to the pool (if presented) -> a little more than 1 hour to fill a full pool
public class ExquisiteManaAltarTile extends BaseManaAltarTile {
protected boolean hasMultiblock = false;
protected int ticksFormed = 0;
protected StructureType _structure;
public ManaAltarEnergyStorage energyStorage;
private LazyOptional<ManaAltarEnergyStorage> energy;
public ExquisiteManaAltarTile() {
super(ElectroManaTiles.EXQUISITE_MANA_ALTAR_TILE.get());
_structure = this.getRequiredStructureType();
this.energyStorage = new ManaAltarEnergyStorage(this, 0);
this.energy = LazyOptional.of(() -> this.energyStorage);
}
@Override
public void tick() {
if (!this.hasMultiblock) {
return;
}
ticksFormed += 1;
IManaReceiver mr = this.getUpperManaPool();
if (mr == null || mr.isFull() || (ticksFormed % 20) != 0) {
return;
}
this.getCapability(CapabilityEnergy.ENERGY).ifPresent(energyStorage -> {
ManaAltarEnergyStorage mts = (ManaAltarEnergyStorage) energyStorage;
int mxe = 1_000_000;
boolean canExtractEnergy = mts.consumeEnergy(mxe, true) == mxe;
if (canExtractEnergy) {
mts.consumeEnergy(mxe, false);
mr.receiveMana(555); // Y 555? See heading of class
}
});
}
public boolean validateMultiblock() throws BrokenStructureException {
if (getWorld().isRemote()) {
return this.hasMultiblock;
}
if (this.getRequiredStructureType() == null) {
resetMultiblockState();
return false;
}
boolean prevFound = this.hasMultiblock;
boolean found = _structure.check(getWorld(), getPos());
if (prevFound != found) {
ElectroMana.getLOGGER().info(
"Structure match updated: " + this.getClass().getName() + " at " + this.getPos() +
" (" + this.hasMultiblock + " -> " + found + ")"
);
this.hasMultiblock = found;
this.markForUpdate();
}
return this.hasMultiblock;
}
private void resetMultiblockState() {
ticksFormed = 0;
if (this.hasMultiblock) {
this.hasMultiblock = false;
this.markForUpdate();
}
}
@Nullable
@Override
public StructureType getRequiredStructureType() {
return ElectroManaStructures.EXQUISITE_MANA_ALTAR_STRUCTURE;
}
public void markForUpdate() {
if (getWorld() != null) {
BlockState thisState = this.getBlockState();
getWorld().notifyBlockUpdate(getPos(), thisState, thisState, 3);
}
markDirty();
}
@Override
public void read(BlockState stateIn, CompoundNBT compound) {
super.read(stateIn, compound);
energy.ifPresent(h -> h.deserializeNBT(compound.getCompound("energy")));
this.hasMultiblock = compound.getBoolean("hasMultiblock");
}
@Override
public CompoundNBT write(CompoundNBT compound) {
energy.ifPresent(h -> compound.put("energy", h.serializeNBT()));
compound.putBoolean("hasMultiblock", this.hasMultiblock);
return super.write(compound);
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, final @Nullable Direction side) {
if (cap == CapabilityEnergy.ENERGY)
return energy.cast();
return super.getCapability(cap, side);
}
@Override
public ITextComponent getDisplayName() {
return new StringTextComponent("Exquisite Mana Altar");
}
@Nullable
@Override
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) {
return null;
}
public boolean hasMultiblock() {
return hasMultiblock;
}
}