Skip to content

Commit

Permalink
Fix some issues with the AuraControl merge and track whether aura inf…
Browse files Browse the repository at this point in the history
…o was ever set for a chunk
  • Loading branch information
TheCodex6824 committed Aug 29, 2024
1 parent 82901c6 commit 73ec72e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,62 @@

package thecodex6824.thaumcraftfix.api.aura;

import java.util.Optional;

/**
* Capability that holds the statistics for an controlAura chunk,
* Capability that holds the statistics for an aura chunk,
* at the time it was generated. Useful for detecting modifications
* to the controlAura, or restoring it to its original values. Mods (including FeatureControl)
* can, and are expected to, modify this at worldgen time to reflect the final values
* of the generated controlAura.
* to the aura, or restoring it to its original values. Mods can,
* and are expected to, modify this at worldgen time to reflect the final values
* of the generated aura.
*
* In the event this mod is installed after worldgen time, aura
* information will not have been recorded. In this case,
* the getter methods of this capability should return empty Optional instances.
* Using Optional here allows callers to differentiate between the lack of aura
* information and auras that actually have zero values.
*/
public interface IOriginalAuraInfo {

/**
* Returns the base controlAura level, also known as the vis cap.
* @return The base controlAura level
* Returns the base aura level, also known as the vis cap.
* An empty Optional means that this value was never recorded.
* @return The base aura level
*/
public short getBase();
public Optional<Short> getBase();

/**
* Sets the base controlAura level.
* @param newBase The new base controlAura level
* Sets the base aura level.
* @param newBase The new base aura level
*/
public void setBase(short newBase);

/**
* Returns the amount of vis in the controlAura, which can be
* Returns the amount of vis in the aura, which can be
* different from the vis cap.
* An empty Optional means that this value was never recorded.
* @return The vis level
*/
public float getVis();
public Optional<Float> getVis();

/**
* Sets the amount of vis in the controlAura.
* Sets the amount of vis in the aura.
* @param newVis The new vis level
*/
public void setVis(float newVis);

/**
* Returns the amount of flux in the controlAura. Vanilla Thaumcraft
* Returns the amount of flux in the aura. Vanilla Thaumcraft
* barely adds any flux, if any, at worldgen time, but mods
* like Thaumic Augmentation may add some as part of their
* worldgen.
* An empty Optional means that this value was never recorded.
* @return The amount of flux in the controlAura
*/
public float getFlux();
public Optional<Float> getFlux();

/**
* Sets the amount of flux in the controlAura.
* Sets the amount of flux in the aura.
* @param newFlux The new flux level
*/
public void setFlux(float newFlux);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

package thecodex6824.thaumcraftfix.api.aura;

import java.util.Optional;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.common.util.INBTSerializable;

/**
Expand All @@ -29,56 +32,76 @@
*/
public class OriginalAuraInfo implements IOriginalAuraInfo, INBTSerializable<NBTTagCompound> {

protected short base;
protected float vis;
protected float flux;
protected static final String KEY_BASE = "base";
protected static final String KEY_VIS = "vis";
protected static final String KEY_FLUX = "flux";

protected Optional<Short> base;
protected Optional<Float> vis;
protected Optional<Float> flux;

public OriginalAuraInfo() {}
public OriginalAuraInfo() {
base = Optional.empty();
vis = Optional.empty();
flux = Optional.empty();
}

@Override
public short getBase() {
public Optional<Short> getBase() {
return base;
}

@Override
public void setBase(short newBase) {
base = newBase;
base = Optional.of(newBase);
}

@Override
public float getVis() {
public Optional<Float> getVis() {
return vis;
}

@Override
public void setVis(float newVis) {
vis = newVis;
vis = Optional.of(newVis);
}

@Override
public float getFlux() {
public Optional<Float> getFlux() {
return flux;
}

@Override
public void setFlux(float newFlux) {
flux = newFlux;
flux = Optional.of(newFlux);
}

@Override
public NBTTagCompound serializeNBT() {
NBTTagCompound tag = new NBTTagCompound();
tag.setShort("base", base);
tag.setFloat("vis", vis);
tag.setFloat("flux", flux);
if (base.isPresent()) {
tag.setShort(KEY_BASE, base.get());
}
if (vis.isPresent()) {
tag.setFloat(KEY_VIS, vis.get());
}
if (flux.isPresent()) {
tag.setFloat(KEY_FLUX, flux.get());
}
return tag;
}

@Override
public void deserializeNBT(NBTTagCompound nbt) {
base = nbt.getShort("base");
vis = nbt.getFloat("vis");
flux = nbt.getFloat("flux");
if (nbt.hasKey(KEY_BASE, NBT.TAG_SHORT)) {
base = Optional.of(nbt.getShort("base"));
}
if (nbt.hasKey(KEY_VIS, NBT.TAG_FLOAT)) {
vis = Optional.of(nbt.getFloat("vis"));
}
if (nbt.hasKey(KEY_FLUX, NBT.TAG_FLOAT)) {
flux = Optional.of(nbt.getFloat("flux"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class FeatureTransformers {

public static final class Hooks {

public static int generateAura(int original, Chunk chunk) {
public static int shouldGenerateAura(int original, Chunk chunk) {
if (original >= 0 || !FeatureControl.isControllingAuraGen()) {
return original;
}
Expand Down

0 comments on commit 73ec72e

Please sign in to comment.