Skip to content

Commit e004b26

Browse files
committed
Address misc TODOs and fix being unable to lock bins, and mekasuit losing power on relog
1 parent fafaf1d commit e004b26

File tree

20 files changed

+65
-78
lines changed

20 files changed

+65
-78
lines changed

src/api/java/mekanism/api/chemical/merged/BoxedChemical.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class BoxedChemical implements IHasTextComponent {
6565
*/
6666
public static BoxedChemical box(Chemical<?> chemical) {
6767
if (chemical.isEmptyType()) {
68-
//TODO - 1.21: Do we care that this can lose the type of chemical as it uses a single instance that always has a type of gas?
68+
//TODO: Do we care that this can lose the type of chemical as it uses a single instance that always has a type of gas?
6969
return EMPTY;
7070
}
7171
return new BoxedChemical(ChemicalType.getTypeFor(chemical), chemical);

src/api/java/mekanism/api/chemical/merged/BoxedChemicalStack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class BoxedChemicalStack implements IHasTextComponent {
6666
*/
6767
public static BoxedChemicalStack box(ChemicalStack<?> chemicalStack) {
6868
if (chemicalStack.isEmpty()) {
69-
//TODO - 1.21: Do we care that this can lose the type of chemical as it uses a single instance that always has a type of gas?
69+
//TODO: Do we care that this can lose the type of chemical as it uses a single instance that always has a type of gas?
7070
return EMPTY;
7171
}
7272
return new BoxedChemicalStack(ChemicalType.getTypeFor(chemicalStack), chemicalStack);

src/api/java/mekanism/api/math/FloatingLong.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,28 @@
2323
@NothingNullByDefault
2424
public class FloatingLong extends Number implements Comparable<FloatingLong> {
2525

26+
//we don't lose accuracy due to using a double, and because for some reason it seems like
27+
// the codecs occasionally have issues being parsed
2628
public static final Codec<FloatingLong> CODEC = new PrimitiveCodec<>() {
2729
@Override
2830
public <T> DataResult<FloatingLong> read(DynamicOps<T> ops, T input) {
29-
return ops.getNumberValue(input).flatMap(number -> fromNumber(number, true));
31+
return ops.getStringValue(input).flatMap(number -> {
32+
try {
33+
return DataResult.success(parseFloatingLong(number, true));
34+
} catch (NumberFormatException e) {
35+
return DataResult.error(e::getMessage);
36+
}
37+
});
3038
}
3139

3240
@Override
3341
public <T> T write(DynamicOps<T> ops, FloatingLong value) {
34-
return ops.createNumeric(value);
42+
return ops.createString(value.toString());
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "FloatingLong";
3548
}
3649
};
3750
public static final Codec<FloatingLong> NONZERO_CODEC = CODEC.validate(f -> {
@@ -45,7 +58,7 @@ public <T> T write(DynamicOps<T> ops, FloatingLong value) {
4558
// as in general it will still provide an improvement
4659
ByteBufCodecs.VAR_LONG, FloatingLong::getValue,
4760
ByteBufCodecs.SHORT, FloatingLong::getDecimal,
48-
FloatingLong::create
61+
FloatingLong::createConst
4962
);
5063
private static final DecimalFormat df = new DecimalFormat("0.0000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
5164

@@ -1208,27 +1221,6 @@ public static FloatingLong parseFloatingLong(String string, boolean isConstant)
12081221
return isConstant ? createConst(value, decimal) : create(value, decimal);
12091222
}
12101223

1211-
private static DataResult<FloatingLong> fromNumber(Number number, boolean isConstant) {
1212-
if (number instanceof Integer || number instanceof Long || number instanceof Short || number instanceof Byte || number instanceof BigInteger) {
1213-
long longValue = number.longValue();
1214-
if (longValue < 0) {
1215-
return DataResult.error(() -> "Number must be positive");
1216-
}
1217-
return DataResult.success(isConstant ? createConst(longValue, (short) 0) : create(longValue, (short) 0));
1218-
} else if (number instanceof BigDecimal decimal) {
1219-
try {
1220-
long longValue = decimal.longValueExact();
1221-
return DataResult.success(isConstant ? createConst(longValue, (short) 0) : create(longValue, (short) 0));
1222-
} catch (ArithmeticException ignored) {
1223-
}
1224-
}
1225-
try {
1226-
return DataResult.success(parseFloatingLong(number.toString(), isConstant));
1227-
} catch (NumberFormatException e) {
1228-
return DataResult.error(e::getMessage);
1229-
}
1230-
}
1231-
12321224
/**
12331225
* Parses the decimal out of a string argument and gets the representation as a short. The characters in the string must all be decimal digits, with a decimal point
12341226
* being valid to convey where the decimal starts.

src/generators/java/mekanism/generators/common/block/turbine/BlockTurbineRotor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected ItemInteractionResult useItemOn(@NotNull ItemStack stack, @NotNull Blo
4646
if (!player.isCreative()) {
4747
stack.shrink(1);
4848
}
49+
return ItemInteractionResult.CONSUME;
4950
}
5051
}
5152
} else if (stack.isEmpty()) {
@@ -54,6 +55,7 @@ protected ItemInteractionResult useItemOn(@NotNull ItemStack stack, @NotNull Blo
5455
player.setItemInHand(hand, GeneratorsItems.TURBINE_BLADE.getItemStack());
5556
player.getInventory().setChanged();
5657
}
58+
return ItemInteractionResult.CONSUME;
5759
}
5860
} else if (stack.getItem() instanceof ItemTurbineBlade) {
5961
if (stack.getCount() < stack.getMaxStackSize()) {
@@ -62,6 +64,7 @@ protected ItemInteractionResult useItemOn(@NotNull ItemStack stack, @NotNull Blo
6264
stack.grow(1);
6365
player.getInventory().setChanged();
6466
}
67+
return ItemInteractionResult.CONSUME;
6568
}
6669
}
6770
}

src/main/java/mekanism/client/model/BaseModelCache.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ protected JSONModelData registerJSON(ResourceLocation rl) {
7777
protected JSONModelData registerJSONAndBake(ResourceLocation rl) {
7878
ModelManager modelManager = Minecraft.getInstance().getModelManager();
7979
ModelBakery modelBakery = modelManager.getModelBakery();
80-
//TODO - 1.21: Test this
8180
ModelResourceLocation mrl = ModelResourceLocation.standalone(rl);
8281
ModelBaker baker = modelBakery.new ModelBakerImpl(
8382
(modelLoc, material) -> material.sprite(),

src/main/java/mekanism/client/render/MekanismRenderType.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ private static RenderType createStandard(String name, ResourceLocation resourceL
8181
.setTextureState(new RenderStateShard.TextureStateShard(resourceLocation, false, false))
8282
.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
8383
.createCompositeState(true);
84-
//TODO - 1.21: Check the shader implementation that it doesn't need things to change
8584
return create("mek_flame", DefaultVertexFormat.POSITION_TEX_COLOR, Mode.QUADS, 256, true, false, state);
8685
});
8786

@@ -110,7 +109,6 @@ private static RenderType createStandard(String name, ResourceLocation resourceL
110109
.setTransparencyState(LIGHTNING_TRANSPARENCY)
111110
.setOutputState(RenderType.TRANSLUCENT_TARGET)
112111
.createCompositeState(true);
113-
//TODO - 1.21: Check the shader implementation that it doesn't need things to change
114112
return create("mek_sps", DefaultVertexFormat.POSITION_TEX_COLOR, Mode.QUADS, 256, true, true, state);
115113
});
116114
}

src/main/java/mekanism/client/render/transmitter/RenderTransmitterBase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
public abstract class RenderTransmitterBase<TRANSMITTER extends TileEntityTransmitter> extends MekanismTileEntityRenderer<TRANSMITTER> {
4242

4343
public static final ResourceLocation MODEL_LOCATION = MekanismUtils.getResource(ResourceType.MODEL, "transmitter_contents.obj");
44-
//TODO - 1.21: Test this
4544
private static final ModelResourceLocation MODEL_VARIANT = ModelResourceLocation.standalone(MODEL_LOCATION);
4645
private static final IGeometryBakingContext contentsConfiguration = StandaloneGeometryBakingContext.builder()
4746
.withGui3d(false)

src/main/java/mekanism/common/attachments/containers/chemical/ComponentBackedChemicalTank.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ public ChemicalAttributeValidator getAttributeValidator() {
7979
return attributeValidator == null ? IChemicalTank.super.getAttributeValidator() : attributeValidator;
8080
}
8181

82-
protected long getRate(@Nullable AutomationType automationType) {
82+
protected long getInsertRate(@Nullable AutomationType automationType) {
83+
//Allow unknown or manual interaction to bypass rate limit for the item
84+
return automationType == null || automationType == AutomationType.MANUAL ? Long.MAX_VALUE : rate.getAsLong();
85+
}
86+
87+
protected long getExtractRate(@Nullable AutomationType automationType) {
8388
//Allow unknown or manual interaction to bypass rate limit for the item
8489
return automationType == null || automationType == AutomationType.MANUAL ? Long.MAX_VALUE : rate.getAsLong();
8590
}
@@ -104,7 +109,7 @@ public STACK insert(STACK stack, Action action, AutomationType automationType) {
104109
}
105110
ATTACHED attachedChemicals = getAttached();
106111
STACK stored = getContents(attachedChemicals);
107-
long needed = Math.min(getRate(automationType), getNeeded(stored));
112+
long needed = Math.min(getInsertRate(automationType), getNeeded(stored));
108113
if (needed <= 0) {
109114
//Fail if we are a full tank or our rate is zero
110115
return stack;
@@ -139,7 +144,7 @@ protected STACK extract(ATTACHED attachedChemicals, STACK stored, long amount, A
139144
}
140145
//Note: While we technically could just return the stack itself if we are removing all that we have, it would require a lot more checks
141146
// We also are limiting it by the rate this tank has
142-
long size = Math.min(Math.min(getRate(automationType), stored.getAmount()), amount);
147+
long size = Math.min(Math.min(getExtractRate(automationType), stored.getAmount()), amount);
143148
if (size == 0) {
144149
return getEmptyStack();
145150
}
@@ -188,9 +193,11 @@ public long growStack(long amount, Action action) {
188193
return 0;
189194
} else if (amount > 0) {
190195
//Cap adding amount at how much we need, so that we don't risk integer overflow
191-
amount = Math.min(Math.min(amount, getNeeded(stored)), getRate(null));
196+
//If we are increasing the stack's size, use the insert rate
197+
amount = Math.min(Math.min(amount, getNeeded(stored)), getInsertRate(null));
192198
} else if (amount < 0) {
193-
amount = Math.max(amount, -getRate(null));
199+
//If we are decreasing the stack's size, use the extract rate
200+
amount = Math.max(amount, -getExtractRate(null));
194201
}
195202
long newSize = setStackSize(attachedChemicals, stored, current + amount, action);
196203
return newSize - current;

src/main/java/mekanism/common/attachments/containers/energy/ComponentBackedEnergyContainer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ protected void setContents(AttachedEnergy attachedEnergy, FloatingLong energy) {
7373
super.setContents(attachedEnergy, clampEnergy(energy));
7474
}
7575

76-
protected FloatingLong getRate(@Nullable AutomationType automationType) {
76+
protected FloatingLong getInsertRate(@Nullable AutomationType automationType) {
77+
//Allow unknown or manual interaction to bypass rate limit for the item
78+
return automationType == null || automationType == AutomationType.MANUAL ? FloatingLong.MAX_VALUE : rate.get();
79+
}
80+
81+
protected FloatingLong getExtractRate(@Nullable AutomationType automationType) {
7782
//Allow unknown or manual interaction to bypass rate limit for the item
7883
return automationType == null || automationType == AutomationType.MANUAL ? FloatingLong.MAX_VALUE : rate.get();
7984
}
@@ -85,7 +90,7 @@ public FloatingLong insert(FloatingLong amount, Action action, AutomationType au
8590
}
8691
AttachedEnergy attachedEnergy = getAttached();
8792
FloatingLong stored = getContents(attachedEnergy);
88-
FloatingLong needed = getRate(automationType).min(getNeeded(stored));
93+
FloatingLong needed = getInsertRate(automationType).min(getNeeded(stored));
8994
if (needed.isZero()) {
9095
//Fail if we are a full container or our rate is zero
9196
return amount;
@@ -109,7 +114,7 @@ public FloatingLong extract(FloatingLong amount, Action action, AutomationType a
109114
if (stored.isZero() || !canExtract.test(automationType)) {
110115
return FloatingLong.ZERO;
111116
}
112-
FloatingLong ret = getRate(automationType).min(stored).min(amount).copy();
117+
FloatingLong ret = getExtractRate(automationType).min(stored).min(amount).copy();
113118
if (!ret.isZero() && action.execute()) {
114119
//Note: this also will mark that the contents changed
115120
setContents(attachedEnergy, stored.subtract(ret));

src/main/java/mekanism/common/attachments/containers/energy/EnergyContainersBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
public class EnergyContainersBuilder {
1616

17-
private static final IBasicContainerCreator<? extends ComponentBackedEnergyContainer> MEKASUIT = (type, attachedTo, containerIndex) -> new ComponentBackedNoClampEnergyContainer(attachedTo, containerIndex, BasicEnergyContainer.manualOnly,
18-
BasicEnergyContainer.alwaysTrue,
19-
() -> ModuleEnergyUnit.getChargeRate(attachedTo, MekanismConfig.gear.mekaSuitBaseChargeRate.get()),
20-
() -> ModuleEnergyUnit.getEnergyCapacity(attachedTo, MekanismConfig.gear.mekaSuitBaseEnergyCapacity.get())
17+
private static final IBasicContainerCreator<? extends ComponentBackedEnergyContainer> MEKASUIT = (type, attachedTo, containerIndex) -> new ComponentBackedNoClampEnergyContainer(
18+
attachedTo, containerIndex, BasicEnergyContainer.manualOnly, BasicEnergyContainer.alwaysTrue,
19+
() -> ModuleEnergyUnit.getChargeRate(attachedTo, MekanismConfig.gear.mekaSuitBaseChargeRate),
20+
() -> ModuleEnergyUnit.getEnergyCapacity(attachedTo, MekanismConfig.gear.mekaSuitBaseEnergyCapacity)
2121
);
2222

2323
public static EnergyContainersBuilder builder() {

0 commit comments

Comments
 (0)