-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal: move redstone query logic to static libs
- Loading branch information
Showing
7 changed files
with
165 additions
and
215 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
35 changes: 35 additions & 0 deletions
35
core/src/main/java/mrtjp/projectred/core/RedstoneCenterLookup.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,35 @@ | ||
package mrtjp.projectred.core; | ||
|
||
import codechicken.multipart.api.RedstoneInteractions; | ||
import codechicken.multipart.api.part.MultiPart; | ||
import codechicken.multipart.api.part.redstone.RedstonePart; | ||
import mrtjp.projectred.core.part.IRedwireEmitter; | ||
import mrtjp.projectred.core.part.IRedwirePart; | ||
|
||
public class RedstoneCenterLookup { | ||
|
||
public static int resolveSignal(CenterLookup lookup, boolean diminishRedwire) { | ||
if (lookup.part instanceof IRedwirePart rw) { | ||
|
||
int signal = rw.getRedwireSignal(lookup.otherDirection); | ||
if (diminishRedwire && rw.diminishOnSide(lookup.otherDirection)) { | ||
signal--; | ||
} | ||
return Math.max(0, signal); | ||
} | ||
|
||
if (lookup.part instanceof IRedwireEmitter rwe) { | ||
return rwe.getRedwireSignal(lookup.otherDirection); | ||
} | ||
|
||
if (lookup.part instanceof RedstonePart rw) { | ||
return Math.max(rw.strongPowerLevel(lookup.otherDirection), rw.weakPowerLevel(lookup.otherDirection)); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public static int resolveVanillaSignal(CenterLookup lookup, MultiPart part) { | ||
return RedstoneInteractions.getPowerTo(part, lookup.direction) * 17; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
core/src/main/java/mrtjp/projectred/core/RedstoneFaceLookup.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,60 @@ | ||
package mrtjp.projectred.core; | ||
|
||
import codechicken.multipart.api.RedstoneInteractions; | ||
import codechicken.multipart.api.part.MultiPart; | ||
import codechicken.multipart.api.part.redstone.FaceRedstonePart; | ||
import mrtjp.projectred.core.part.IRedwireEmitter; | ||
import mrtjp.projectred.core.part.IRedwirePart; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.RedStoneWireBlock; | ||
|
||
public class RedstoneFaceLookup { | ||
|
||
public static int resolveSignal(FaceLookup lookup, boolean diminishRedwire) { | ||
|
||
if (lookup.part instanceof IRedwirePart rp) { | ||
int signal = rp.getRedwireSignal(lookup.otherRotation); | ||
if (diminishRedwire && rp.diminishOnSide(lookup.otherRotation)) { | ||
signal--; | ||
} | ||
return Math.max(0, signal); | ||
} | ||
|
||
if (lookup.part instanceof IRedwireEmitter rwe) { | ||
return rwe.getRedwireSignal(lookup.otherRotation); | ||
} | ||
|
||
if (lookup.part instanceof FaceRedstonePart fp) { | ||
int s = lookup.otherDir; | ||
return Math.max(fp.strongPowerLevel(s), fp.weakPowerLevel(s)) * 17; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public static int resolveVanillaSignal(FaceLookup lookup, MultiPart part, boolean strong, boolean limitDust) { | ||
int signal; | ||
|
||
// Dust signal | ||
if (lookup.block == Blocks.REDSTONE_WIRE) { | ||
signal = Math.max(lookup.state.getValue(RedStoneWireBlock.POWER) - 1, 0); | ||
if (limitDust) { | ||
return signal; | ||
} | ||
} | ||
|
||
// Strong signal | ||
signal = RedstoneInteractions.getPowerTo(part, lookup.dir) * 17; | ||
if (signal > 0 || strong) { | ||
return signal; | ||
} | ||
|
||
// Weak signal | ||
if (lookup.state.isRedstoneConductor(lookup.world, lookup.otherPos)) { | ||
signal = lookup.world.getBestNeighborSignal(lookup.otherPos) * 17; | ||
} | ||
|
||
return signal; | ||
} | ||
|
||
} |
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
Oops, something went wrong.