Skip to content

Commit

Permalink
feat: overhaul part 2 so I can see more review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu committed Jul 21, 2024
1 parent 259db88 commit c144c74
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 95 deletions.
3 changes: 3 additions & 0 deletions src/main/java/gregtech/api/capability/ILockableHandler.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package gregtech.api.capability;

import org.jetbrains.annotations.Nullable;

public interface ILockableHandler<T> {

void setLock(boolean isLocked);

boolean isLocked();

@Nullable
T getLockedObject();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class AdvancedTextWidget extends Widget {

protected final Consumer<List<ITextComponent>> textSupplier;
protected BiConsumer<String, ClickData> clickHandler;
protected List<ITextComponent> displayText = new ArrayList<>();
private List<ITextComponent> displayText = new ArrayList<>();
private final int color;

public AdvancedTextWidget(int xPosition, int yPosition, Consumer<List<ITextComponent>> text, int color) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
import gregtech.api.util.Size;
import gregtech.api.util.function.FloatConsumer;

import gregtech.api.util.function.FloatSupplier;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;

import java.util.function.Supplier;

public class UpdatedSliderWidget extends SliderWidget {

Supplier<Float> detector;
private FloatSupplier detector;

public UpdatedSliderWidget(String name, int xPosition, int yPosition, int width, int height, float min, float max,
float currentValue, FloatConsumer responder, Supplier<Float> detector) {
float currentValue, FloatConsumer responder, FloatSupplier detector) {
super(name, xPosition, yPosition, width, height, min, max, currentValue, responder);
this.detector = detector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public LockableItemStackHandler(MetaTileEntity entityToNotify, boolean isExport)
@Override
public void setLock(boolean isLocked) {
this.locked = isLocked;
if (isLocked)
if (isLocked && !this.getStackInSlot(0).isEmpty()) {
lockedItemStack = this.getStackInSlot(0).copy();
}
}

public boolean isLocked() {
Expand All @@ -31,10 +32,8 @@ public boolean isLocked() {
@NotNull
@Override
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
if (this.locked) {
if (!this.lockedItemStack.isItemEqual(stack)) {
return stack;
}
if (this.locked && !this.lockedItemStack.isItemEqual(stack)) {
return stack;
}
return super.insertItem(slot, stack, simulate);
}
Expand Down
93 changes: 48 additions & 45 deletions src/main/java/gregtech/api/items/materialitem/MetaPrefixItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ private static void registerSpecialOreDict(ItemStack item, Material material, Or
}

if (material == Materials.Plutonium239) {
OreDictUnifier.registerOre(item, prefix.name() + material.toCamelCaseString() + "239");
} else if (material == Materials.Uranium) {
OreDictUnifier.registerOre(item, prefix.name() + material.toCamelCaseString());
OreDictUnifier.registerOre(item, prefix.name() + material.toCamelCaseString() + "_239");
} else if (material == Materials.Saltpeter) {
OreDictUnifier.registerOre(item, prefix.name() + material.toCamelCaseString());
}
Expand Down Expand Up @@ -157,54 +155,59 @@ public void onUpdate(@NotNull ItemStack itemStack, @NotNull World worldIn, @NotN
super.onUpdate(itemStack, worldIn, entityIn, itemSlot, isSelected);
if (metaItems.containsKey((short) itemStack.getItemDamage()) && entityIn instanceof EntityLivingBase entity) {
if (entityIn.ticksExisted % 20 == 0) {
Material material = getMaterial(itemStack);

// Handle heat damage
if (prefix.heatDamageFunction != null) {
Material material = getMaterial(itemStack);
if (material != null) {
float heatDamage = 0.f;
if (material.hasProperty(PropertyKey.BLAST)) {
heatDamage = prefix.heatDamageFunction.apply(material.getBlastTemperature());
} else if (material.hasProperty(PropertyKey.FISSION_FUEL)) {
heatDamage = prefix.heatDamageFunction.apply(0);
}
ItemStack armor = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
if (!armor.isEmpty() && armor.getItem() instanceof ArmorMetaItem<?>) {
ArmorMetaItem<?>.ArmorMetaValueItem metaValueItem = ((ArmorMetaItem<?>) armor.getItem())
.getItem(armor);
if (metaValueItem != null) heatDamage *= metaValueItem.getArmorLogic().getHeatResistance();
}
if (heatDamage > 0.0) {
entity.attackEntityFrom(DamageSources.getHeatDamage().setDamageBypassesArmor(), heatDamage);
} else if (heatDamage < 0.0) {
entity.attackEntityFrom(DamageSources.getFrostDamage().setDamageBypassesArmor(),
-heatDamage);
}
if (material != null) {
// Handle heat damage
if (prefix.heatDamageFunction != null) {
handleHeatDamage(material, entity);
}
}

// Handle radiation damage
if (prefix.radiationDamageFunction != null) {
Material material = getMaterial(itemStack);
if (material != null) {
double radiationDamage = prefix.radiationDamageFunction.apply(material.getDecaysPerSecond());
ItemStack armor = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
if (!armor.isEmpty() && armor.getItem() instanceof ArmorMetaItem<?>) {
ArmorMetaItem<?>.ArmorMetaValueItem metaValueItem = ((ArmorMetaItem<?>) armor.getItem())
.getItem(armor);
if (metaValueItem != null) {
radiationDamage *= metaValueItem.getArmorLogic().getRadiationResistance();
}
}
if (radiationDamage > 0.0) {
entity.attackEntityFrom(DamageSources.getRadioactiveDamage().setDamageBypassesArmor(),
(float) radiationDamage);
}
// Handle radiation damage
if (prefix.radiationDamageFunction != null) {
handleRadiationDamage(material, entity);
}
}
}
}
}

private void handleHeatDamage(@NotNull Material material, @NotNull EntityLivingBase entity) {
float heatDamage = 0.f;
if (material.hasProperty(PropertyKey.BLAST)) {
heatDamage = prefix.heatDamageFunction.apply(material.getBlastTemperature());
} else if (material.hasProperty(PropertyKey.FISSION_FUEL)) {
heatDamage = prefix.heatDamageFunction.apply(0);
}
ItemStack armor = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
if (!armor.isEmpty() && armor.getItem() instanceof ArmorMetaItem<?>) {
ArmorMetaItem<?>.ArmorMetaValueItem metaValueItem = ((ArmorMetaItem<?>) armor.getItem())
.getItem(armor);
if (metaValueItem != null) heatDamage *= metaValueItem.getArmorLogic().getHeatResistance();
}
if (heatDamage > 0.0) {
entity.attackEntityFrom(DamageSources.getHeatDamage().setDamageBypassesArmor(), heatDamage);
} else if (heatDamage < 0.0) {
entity.attackEntityFrom(DamageSources.getFrostDamage().setDamageBypassesArmor(),
-heatDamage);
}
}

private void handleRadiationDamage(@NotNull Material material, EntityLivingBase entity) {
double radiationDamage = prefix.radiationDamageFunction.apply(material.getDecaysPerSecond());
ItemStack armor = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
if (!armor.isEmpty() && armor.getItem() instanceof ArmorMetaItem<?>) {
ArmorMetaItem<?>.ArmorMetaValueItem metaValueItem = ((ArmorMetaItem<?>) armor.getItem())
.getItem(armor);
if (metaValueItem != null) {
radiationDamage *= metaValueItem.getArmorLogic().getRadiationResistance();
}
}
if (radiationDamage > 0.0) {
entity.attackEntityFrom(DamageSources.getRadioactiveDamage().setDamageBypassesArmor(),
(float) radiationDamage);
}
}

@Override
@SideOnly(Side.CLIENT)
Expand All @@ -217,8 +220,8 @@ public void addInformation(@NotNull ItemStack itemStack, @Nullable World worldIn
}

/**
* For general use. Can return null if the stack metadata is an invalid material ID.
* Requires the ItemStack's item to be a MetaPrefixItem.
* For general use. Can return null if the stack metadata is an invalid material ID. Requires the ItemStack's item
* to be a MetaPrefixItem.
*
* @return the material
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import net.minecraft.util.math.BlockPos;

import org.jetbrains.annotations.Nullable;

public interface IFissionReactorHatch {

/**
*
* @param depth The depth of the reactor that needs checking
* @return If the channel directly below the hatch is valid or not
*/
boolean checkValidity(int depth);

@Nullable
BlockPos getPos();
}
64 changes: 46 additions & 18 deletions src/main/java/gregtech/api/nuclear/fission/FissionReactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ public class FissionReactor {
* {@link FissionReactor#prepareInitialConditions()}
*/
private double coolantBaseTemperature;
public double maxFuelDepletion = 1;
public double fuelDepletion = -1;
public double neutronPoisonAmount; // can kill reactor if power is lowered and this value is high
public double decayProductsAmount;
public double envTemperature = roomTemperature; // maybe gotten from config per dim
public double accumulatedHydrogen;
public double weightedGenerationTime = 2; // The mean generation time in seconds, accounting for delayed neutrons

public double maxTemperature = 2000;
private double maxFuelDepletion = 1;
private double fuelDepletion = -1;
private double neutronPoisonAmount; // can kill reactor if power is lowered and this value is high
private double decayProductsAmount;
private double envTemperature = roomTemperature; // maybe gotten from config per dim
private double accumulatedHydrogen;
private double weightedGenerationTime = 2; // The mean generation time in seconds, accounting for delayed neutrons

private double maxTemperature = 2000;
// Pascals
public double maxPressure = 15000000;
private double maxPressure = 15000000;
// In MW apparently
public double maxPower = 3; // determined by the amount of fuel in reactor and neutron matricies
private double maxPower = 3; // determined by the amount of fuel in reactor and neutron matricies
public static double zircaloyHydrogenReactionTemperature = 1500;

public double surfaceArea;
private double surfaceArea;
public static double thermalConductivity = 45; // 45 W/(m K), for steel
public static double wallThickness = 0.1;
public static double coolantWallThickness = 0.06; // Ideal for a 1-m diameter steel pipe with the given maximum
Expand All @@ -125,12 +125,12 @@ public class FissionReactor {

// very much changed here for balance purposes

public double coolantMass;
public double fuelMass;
public double structuralMass;
public boolean needsOutput;
public boolean controlRodRegulationOn = true;
public boolean isOn = false;
private double coolantMass;
private double fuelMass;
private double structuralMass;
private boolean needsOutput;
private boolean controlRodRegulationOn = true;
private boolean isOn = false;

protected static double responseFunction(double target, double current, double criticalRate) {
if (current < 0) {
Expand Down Expand Up @@ -405,6 +405,10 @@ public boolean isDepleted() {
return fuelDepletion >= maxFuelDepletion || fuelDepletion < 0;
}

public void resetFuelDepletion() {
this.fuelDepletion = 0;
}

public void prepareInitialConditions() {
coolantBaseTemperature = 0;
coolantBoilingPointStandardPressure = 0;
Expand Down Expand Up @@ -750,4 +754,28 @@ public double getFuelDepletion() {
public double getMaxFuelDepletion() {
return maxFuelDepletion;
}

public double getAccumulatedHydrogen() {
return accumulatedHydrogen;
}

public void changeFuelMass(double amount) {
fuelMass += amount;
}

public boolean needsOutput() {
return needsOutput;
}

public void setNeedsOutput(boolean needsOutput) {
this.needsOutput = needsOutput;
}

public boolean isControlRodRegulationOn() {
return controlRodRegulationOn;
}

public void setControlRodRegulationOn(boolean controlRodRegulationOn) {
this.controlRodRegulationOn = controlRodRegulationOn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ public ControlRod(double maxTemperature, boolean tipModeration, double thermalCo
this.weight = 0;
}

/**
* Normalizes the weights of a list of control rods based on the true number of fuel rod pairs.
* @param effectiveControlRods The control rods to normalize.
* @param fuelRodNum The number of fuel rods in the reactor.
*/
public static void normalizeWeights(List<ControlRod> effectiveControlRods, int fuelRodNum) {
for (ControlRod control_rod : effectiveControlRods) {
if (fuelRodNum != 1)
control_rod.weight /= (fuelRodNum * fuelRodNum) - fuelRodNum;
}
}

/**
* Determines the effect of a list of control rods based on how far they are inserted into a reactor.
* @param effectiveControlRods The list of control rods to be analyzed.
* @param insertion How far the control rods are inserted into the reactor, from 0 to 1.
* @return A number representing the reactivity change of the reactor from the control rods.
*/
public static double controlRodFactor(List<ControlRod> effectiveControlRods, double insertion) {
double crf = 0;
for (ControlRod control_rod : effectiveControlRods) {
Expand All @@ -37,26 +48,37 @@ public static double controlRodFactor(List<ControlRod> effectiveControlRods, dou
return crf;
}

/**
* @return How much the control rod affects reactivity.
*/
public double getWeight() {
return weight;
}

/**
* @param weight How much the control rod should affect reactivity.
*/
public void setWeight(double weight) {
this.weight = weight;
}

/**
* Notify the control rod of a pair of fuel rods that it is in the way of, to help increase its weight later.
*/
public void addFuelRodPair() {
relatedFuelRodPairs++;
}

public void increaseWeight() {
weight++;
}

/**
* @return Whether the control rod increases reactivity at low insertion levels (due to having a moderating tip).
*/
public boolean hasModeratorTip() {
return tipModeration;
}

/**
* Automatically calculates the control rod weight (its effect on reactivity) based on the number of fuel rod pairs that it is in the way of.
*/
public void computeWeightFromFuelRodMap() {
this.weight = relatedFuelRodPairs * 4; // 4 being a constant to help balance this out
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,8 @@ public ICoolantHandler getInputHandler() {
return inputHandler;
}

public void setInputHandler(ICoolantHandler inputHandler) {
this.inputHandler = inputHandler;
}

public ICoolantHandler getOutputHandler() {
return outputHandler;
}

public void setOutputHandler(ICoolantHandler outputHandler) {
this.outputHandler = outputHandler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public static void register() {
*/
DistilledWater.setProperty(PropertyKey.COOLANT,
new CoolantProperty(HighPressureSteam, FluidStorageKeys.LIQUID, 1., 1000,
373, 10., 2260000, 4168.)
373, 2260000, 4168.)
.setAccumulatesHydrogen(true));
}
}
Loading

0 comments on commit c144c74

Please sign in to comment.