Skip to content

Commit

Permalink
[Feature] Client actions now display as redstone ore.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlignedCookie88 committed Nov 18, 2024
1 parent 7645ba4 commit 826c401
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.alignedcookie88.fireclient.FireClient;
import com.alignedcookie88.fireclient.FireFunction;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.block.entity.SignText;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -21,9 +25,22 @@ public class SignBlockEntityMixin {
@Inject(method = "getFrontText", at = @At("HEAD"), cancellable = true)
public void getFrontText(CallbackInfoReturnable<SignText> cir) {
SignText original = this.frontText;
if (Objects.equals(original.getMessage(0, false).getString(), "CALL FUNCTION")) {
if (original.getMessage(1, false).getString().startsWith("fireclient.")) {
boolean isAlreadyKnown = Objects.equals(original.getMessage(0, false).getString(), "CLIENT ACTION");
if (isAlreadyKnown || Objects.equals(original.getMessage(0, false).getString(), "CALL FUNCTION")) {
if (isAlreadyKnown || original.getMessage(1, false).getString().startsWith("fireclient.")) {
String functionId = original.getMessage(1, false).getString().replaceFirst("fireclient\\.", "");

BlockPos pos = ((SignBlockEntity) (Object) this).getPos();
BlockPos oreBlock = pos.mutableCopy().add(1, 0, 0);
World world = ((SignBlockEntity) (Object) this).getWorld();

if (world.isChunkLoaded(oreBlock) && world.getBlockState(oreBlock).getBlock() != Blocks.REDSTONE_ORE) {
world.setBlockState(oreBlock, Blocks.REDSTONE_ORE.getDefaultState());
}

if (isAlreadyKnown)
return;

for (FireFunction function : FireClient.functionRegistry) {
if (Objects.equals(function.getID(), functionId)) {
SignText newSignText = original
Expand Down

0 comments on commit 826c401

Please sign in to comment.