-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add base class for detector covers * Fix toggle not toggling * Add screwdriver handling to CoverDetectorBase * Call super on initialSyncData in CoverDetectorBase even though parent functions are empty * Update Fluid Detector Covers to extend CoverDetectorBase * Update Item Detector Covers to extend CoverDetectorBase * Update Energy Detector Covers to extend CoverDetectorBase - with added compatibility check for inverted NBT key * Update Activity Detector Covers to extend CoverDetectorBase * Rename detector cover for activity to follow naming system on rest of cover detectors * Extract function to compute redstone from basic detector covers * Remove unused lang keys for detector messages * Update Advanced Activity detector to use utility function for calculating redstone signal strength * Make toggle function in CoverDetectorBase private as it is not needed anywhere else * Clean up * Move redstone logic related functions to own util file * Add used network key for updating inverted on Detector covers to GregtechDataCodes
- Loading branch information
Showing
18 changed files
with
293 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package gregtech.api.util; | ||
|
||
public class RedstoneUtil { | ||
|
||
/** | ||
* Compares a value against a min and max, with an option to invert the logic | ||
* | ||
* @param value value to be compared | ||
* @param maxValue the max that the value can be | ||
* @param minValue the min that the value can be | ||
* @param isInverted whether to invert the logic of this method | ||
* @return an int from 0 (value <= min) to 15 (value >= max) normally, with a ratio when the value is between min and max | ||
*/ | ||
public static int computeRedstoneBetweenValues(int value, float maxValue, float minValue, boolean isInverted) { | ||
if (value >= maxValue) { | ||
return isInverted ? 0 : 15; // value above maxValue should normally be 15, otherwise 0 | ||
} else if (value <= minValue) { | ||
return isInverted ? 15 : 0; // value below minValue should normally be 0, otherwise 15 | ||
} | ||
|
||
float ratio; | ||
if (!isInverted) { | ||
ratio = 15 * (value - minValue) / (maxValue - minValue); // value closer to max results in higher output | ||
} else { | ||
ratio = 15 * (maxValue - value) / (maxValue - minValue); // value closer to min results in higher output | ||
} | ||
|
||
return Math.round(ratio); | ||
} | ||
|
||
/** | ||
* Compares a value against a min and max, with an option to invert the logic. Has latching functionality. | ||
* | ||
* @param value value to be compared | ||
* @param maxValue the max that the value can be | ||
* @param minValue the min that the value can be | ||
* @param output the output value the function modifies | ||
* @return returns the modified output value | ||
*/ | ||
public static int computeLatchedRedstoneBetweenValues(float value, float maxValue, float minValue, boolean isInverted, int output) { | ||
if (value >= maxValue) { | ||
output = !isInverted ? 0 : 15; // value above maxValue should normally be 0, otherwise 15 | ||
} else if (value <= minValue) { | ||
output = !isInverted ? 15 : 0; // value below minValue should normally be 15, otherwise 0 | ||
} | ||
return output; | ||
} | ||
|
||
/** | ||
* Compares a current against max, with an option to invert the logic. | ||
* | ||
* @param current value to be compared | ||
* @param max the max that value can be | ||
* @param isInverted whether to invert the logic of this method | ||
* @return value 0 to 15 | ||
* @throws ArithmeticException when max is 0 | ||
*/ | ||
public static int computeRedstoneValue(long current, long max, boolean isInverted) throws ArithmeticException { | ||
int outputAmount = (int) (15 * current / max); | ||
|
||
if (isInverted) { | ||
outputAmount = 15 - outputAmount; | ||
} | ||
|
||
return outputAmount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
src/main/java/gregtech/common/covers/detector/CoverActivityDetector.java
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
src/main/java/gregtech/common/covers/detector/CoverDetectorActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package gregtech.common.covers.detector; | ||
|
||
import codechicken.lib.render.CCRenderState; | ||
import codechicken.lib.render.pipeline.IVertexOperation; | ||
import codechicken.lib.vec.Cuboid6; | ||
import codechicken.lib.vec.Matrix4; | ||
import gregtech.api.capability.GregtechTileCapabilities; | ||
import gregtech.api.capability.IWorkable; | ||
import gregtech.api.cover.ICoverable; | ||
import gregtech.client.renderer.texture.Textures; | ||
import net.minecraft.util.BlockRenderLayer; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.ITickable; | ||
|
||
public class CoverDetectorActivity extends CoverDetectorBase implements ITickable { | ||
public CoverDetectorActivity(ICoverable coverHolder, EnumFacing attachedSide) { | ||
super(coverHolder, attachedSide); | ||
} | ||
|
||
@Override | ||
public boolean canAttach() { | ||
return coverHolder.getCapability(GregtechTileCapabilities.CAPABILITY_WORKABLE, null) != null; | ||
} | ||
|
||
@Override | ||
public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, Cuboid6 plateBox, BlockRenderLayer layer) { | ||
Textures.DETECTOR_ACTIVITY.renderSided(attachedSide, plateBox, renderState, pipeline, translation); | ||
} | ||
|
||
@Override | ||
public void update() { | ||
if (this.coverHolder.getOffsetTimer() % 20 != 0) | ||
return; | ||
|
||
IWorkable workable = coverHolder.getCapability(GregtechTileCapabilities.CAPABILITY_WORKABLE, null); | ||
if (workable == null) | ||
return; | ||
|
||
if (isInverted()) setRedstoneSignalOutput(workable.isActive() && workable.isWorkingEnabled() ? 0 : 15); | ||
else setRedstoneSignalOutput(workable.isActive() && workable.isWorkingEnabled() ? 15 : 0); | ||
} | ||
} |
Oops, something went wrong.