diff --git a/src/main/java/gregtech/api/capability/ILockableHandler.java b/src/main/java/gregtech/api/capability/ILockableHandler.java index 9ca39d64626..4b51c14b504 100644 --- a/src/main/java/gregtech/api/capability/ILockableHandler.java +++ b/src/main/java/gregtech/api/capability/ILockableHandler.java @@ -1,10 +1,13 @@ package gregtech.api.capability; +import org.jetbrains.annotations.Nullable; + public interface ILockableHandler { void setLock(boolean isLocked); boolean isLocked(); + @Nullable T getLockedObject(); } diff --git a/src/main/java/gregtech/api/gui/widgets/AdvancedTextWidget.java b/src/main/java/gregtech/api/gui/widgets/AdvancedTextWidget.java index 540925a7b23..02cfc268de0 100644 --- a/src/main/java/gregtech/api/gui/widgets/AdvancedTextWidget.java +++ b/src/main/java/gregtech/api/gui/widgets/AdvancedTextWidget.java @@ -43,7 +43,7 @@ public class AdvancedTextWidget extends Widget { protected final Consumer> textSupplier; protected BiConsumer clickHandler; - protected List displayText = new ArrayList<>(); + private List displayText = new ArrayList<>(); private final int color; public AdvancedTextWidget(int xPosition, int yPosition, Consumer> text, int color) { diff --git a/src/main/java/gregtech/api/gui/widgets/UpdatedSliderWidget.java b/src/main/java/gregtech/api/gui/widgets/UpdatedSliderWidget.java index dab355a2901..9b02c3e1924 100644 --- a/src/main/java/gregtech/api/gui/widgets/UpdatedSliderWidget.java +++ b/src/main/java/gregtech/api/gui/widgets/UpdatedSliderWidget.java @@ -5,6 +5,8 @@ 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; @@ -12,10 +14,10 @@ public class UpdatedSliderWidget extends SliderWidget { - Supplier 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 detector) { + float currentValue, FloatConsumer responder, FloatSupplier detector) { super(name, xPosition, yPosition, width, height, min, max, currentValue, responder); this.detector = detector; } diff --git a/src/main/java/gregtech/api/items/itemhandlers/LockableItemStackHandler.java b/src/main/java/gregtech/api/items/itemhandlers/LockableItemStackHandler.java index 3dbc57faaa8..4b178af38c4 100644 --- a/src/main/java/gregtech/api/items/itemhandlers/LockableItemStackHandler.java +++ b/src/main/java/gregtech/api/items/itemhandlers/LockableItemStackHandler.java @@ -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() { @@ -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); } diff --git a/src/main/java/gregtech/api/items/materialitem/MetaPrefixItem.java b/src/main/java/gregtech/api/items/materialitem/MetaPrefixItem.java index b55a8ee86b3..0c939184016 100644 --- a/src/main/java/gregtech/api/items/materialitem/MetaPrefixItem.java +++ b/src/main/java/gregtech/api/items/materialitem/MetaPrefixItem.java @@ -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()); } @@ -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) @@ -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 */ diff --git a/src/main/java/gregtech/api/metatileentity/multiblock/IFissionReactorHatch.java b/src/main/java/gregtech/api/metatileentity/multiblock/IFissionReactorHatch.java index cefb92647bb..29e07dc1c82 100644 --- a/src/main/java/gregtech/api/metatileentity/multiblock/IFissionReactorHatch.java +++ b/src/main/java/gregtech/api/metatileentity/multiblock/IFissionReactorHatch.java @@ -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(); } diff --git a/src/main/java/gregtech/api/nuclear/fission/FissionReactor.java b/src/main/java/gregtech/api/nuclear/fission/FissionReactor.java index f13e1d1e543..fbcfa796c6b 100644 --- a/src/main/java/gregtech/api/nuclear/fission/FissionReactor.java +++ b/src/main/java/gregtech/api/nuclear/fission/FissionReactor.java @@ -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 @@ -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) { @@ -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; @@ -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; + } } diff --git a/src/main/java/gregtech/api/nuclear/fission/components/ControlRod.java b/src/main/java/gregtech/api/nuclear/fission/components/ControlRod.java index 1a8590a0cb9..4cec68be8dd 100644 --- a/src/main/java/gregtech/api/nuclear/fission/components/ControlRod.java +++ b/src/main/java/gregtech/api/nuclear/fission/components/ControlRod.java @@ -14,6 +14,11 @@ 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 effectiveControlRods, int fuelRodNum) { for (ControlRod control_rod : effectiveControlRods) { if (fuelRodNum != 1) @@ -21,6 +26,12 @@ public static void normalizeWeights(List effectiveControlRods, int f } } + /** + * 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 effectiveControlRods, double insertion) { double crf = 0; for (ControlRod control_rod : effectiveControlRods) { @@ -37,26 +48,37 @@ public static double controlRodFactor(List 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 } diff --git a/src/main/java/gregtech/api/nuclear/fission/components/CoolantChannel.java b/src/main/java/gregtech/api/nuclear/fission/components/CoolantChannel.java index b360fa27034..b70f2b4e7eb 100644 --- a/src/main/java/gregtech/api/nuclear/fission/components/CoolantChannel.java +++ b/src/main/java/gregtech/api/nuclear/fission/components/CoolantChannel.java @@ -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; - } } diff --git a/src/main/java/gregtech/api/unification/material/materials/MaterialFlagAddition.java b/src/main/java/gregtech/api/unification/material/materials/MaterialFlagAddition.java index 4fb96a5d170..2e2f11b3610 100644 --- a/src/main/java/gregtech/api/unification/material/materials/MaterialFlagAddition.java +++ b/src/main/java/gregtech/api/unification/material/materials/MaterialFlagAddition.java @@ -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)); } } diff --git a/src/main/java/gregtech/api/unification/material/materials/UnknownCompositionMaterials.java b/src/main/java/gregtech/api/unification/material/materials/UnknownCompositionMaterials.java index 1531b799564..c317d921342 100644 --- a/src/main/java/gregtech/api/unification/material/materials/UnknownCompositionMaterials.java +++ b/src/main/java/gregtech/api/unification/material/materials/UnknownCompositionMaterials.java @@ -6,6 +6,8 @@ import gregtech.api.fluids.store.FluidStorageKeys; import gregtech.api.unification.material.Material; +import gregtech.api.unification.material.info.MaterialIconSet; + import net.minecraftforge.fluids.FluidRegistry; import static gregtech.api.unification.material.Materials.*; @@ -334,6 +336,7 @@ public static void register() { Corium = new Material.Builder(1560, gregtechId("corium")) .liquid(new FluidBuilder().temperature(2500).block().density(8.0D).viscosity(10000)) .color(0x7A6B50) + .iconSet(DULL) .flags(NO_UNIFICATION, STICKY, GLOWING) .build(); @@ -648,8 +651,8 @@ public static void register() { .fluid().color(0xD5D69C).build(); SpentUraniumFuelSolution = new Material.Builder(1651, gregtechId("spent_uranium_fuel_solution")) - .liquid(new FluidBuilder()) - .color(0x5B5B5B).build(); // TODO color + .liquid() + .color(0x384536).build(); RadonRichGasMixture = new Material.Builder(1652, gregtechId("radon_rich_gas_mixture")) .gas() diff --git a/src/main/java/gregtech/api/util/function/FloatSupplier.java b/src/main/java/gregtech/api/util/function/FloatSupplier.java new file mode 100644 index 00000000000..68e56818b63 --- /dev/null +++ b/src/main/java/gregtech/api/util/function/FloatSupplier.java @@ -0,0 +1,6 @@ +package gregtech.api.util.function; + +@FunctionalInterface +public interface FloatSupplier { + float get(); +} diff --git a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityFissionReactor.java b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityFissionReactor.java index 6f4ab72cde3..8962f8cbb7f 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityFissionReactor.java +++ b/src/main/java/gregtech/common/metatileentities/multi/MetaTileEntityFissionReactor.java @@ -216,12 +216,12 @@ public double getFillPercentage(int index) { */ public void toggleControlRodRegulation(boolean b) { if (fissionReactor != null) { - this.fissionReactor.controlRodRegulationOn = b; + this.fissionReactor.setControlRodRegulationOn(b); } } public boolean areControlRodsRegulated() { - return fissionReactor != null && this.fissionReactor.controlRodRegulationOn; + return fissionReactor != null && this.fissionReactor.isControlRodRegulationOn(); } @Override @@ -390,23 +390,23 @@ public void updateFormedValid() { } for (IFuelRodHandler fuelImport : this.getAbilities(MultiblockAbility.IMPORT_FUEL_ROD)) { - if (fissionReactor.needsOutput) { + if (fissionReactor.needsOutput()) { // TODO ((MetaTileEntityFuelRodImportBus) fuelImport).getExportHatch(this.height - 1) // .getExportItems().insertItem(0, // OreDictUnifier.get(OrePrefix.fuelRodHotDepleted, // fuelImport.getPartialFuel()), // false); - this.fissionReactor.fuelMass -= 60; + this.fissionReactor.changeFuelMass(-60); } if (canWork) { fuelImport.getStackHandler().extractItem(0, 1, false); needsReset |= fuelImport.setPartialFuel(fuelImport.getFuel()); - this.fissionReactor.fuelMass += 60; + this.fissionReactor.changeFuelMass(60); } } if (canWork) { - fissionReactor.needsOutput = true; - this.fissionReactor.fuelDepletion = 0.; + fissionReactor.setNeedsOutput(true); + this.fissionReactor.resetFuelDepletion(); if (needsReset) { fissionReactor.computeGeometry(); @@ -423,7 +423,7 @@ public void updateFormedValid() { boolean melts = this.fissionReactor.checkForMeltdown(); boolean explodes = this.fissionReactor.checkForExplosion(); - double hydrogen = this.fissionReactor.accumulatedHydrogen; + double hydrogen = this.fissionReactor.getAccumulatedHydrogen(); if (melts) { this.performMeltdownEffects(); } @@ -872,7 +872,7 @@ private void lockAndPrepareReactor() { FuelRod component; fuelIn.setFuel(property); foundFuel = true; - if (fissionReactor.fuelDepletion == 0 || fuelIn.getPartialFuel() == null) { + if (fissionReactor.getFuelDepletion() == 0 || fuelIn.getPartialFuel() == null) { fuelIn.setPartialFuel(property); component = new FuelRod(property.getMaxTemperature(), 1, property, 650); fuelIn.setInternalFuelRod(component);