Skip to content

Commit

Permalink
Fix issue with sign edits not saving
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHaws committed Jun 30, 2024
1 parent 119c650 commit 14ab6c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
25 changes: 16 additions & 9 deletions src/main/java/io/chaws/textutilities/handlers/SignEditHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.item.SignChangingItem;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
Expand Down Expand Up @@ -43,24 +44,30 @@ private static ActionResult onUseSignBlock(
return ActionResult.PASS;
}

// Dyes and Ink Sacs can be applied to signs directly when they are in the main hand
if (isHolding(player, Hand.MAIN_HAND, Items.INK_SAC) ||
isHolding(player, Hand.MAIN_HAND, Items.GLOW_INK_SAC) ||
isHoldingDye(player, Hand.MAIN_HAND)
) {
if (signBlock.isWaxed()) {
player.sendMessage(Text.literal("Waxed signs cannot be edited."), true);
return ActionResult.PASS;
}

if (!isHoldingSign(player)) {
return ActionResult.PASS;
}

if (!signBlock.isWaxed()) {
player.openEditSignScreen(signBlock, true);
} else {
player.sendMessage(Text.literal("Sign is not editable"), true);
// Dyes, Ink Sacs, etc can be applied to signs directly when they are in the main hand
if (isHoldingSignChangingItem(player, Hand.MAIN_HAND)) {
return ActionResult.PASS;
}

var editorId = signBlock.getEditor();
var playerId = player.getUuid();

if (editorId != null && editorId != playerId) {
player.sendMessage(Text.literal("Sign is being edited by someone else."), true);
return ActionResult.FAIL;
}

signBlock.setEditor(playerId);
player.openEditSignScreen(signBlock, true);
return ActionResult.SUCCESS;
}
}
4 changes: 4 additions & 0 deletions src/main/java/io/chaws/textutilities/utils/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public static boolean isHoldingSign(PlayerEntity player, Hand hand) {
public static boolean isHoldingDye(PlayerEntity player, Hand hand) {
return isHolding(player, hand, x -> x.getItem() instanceof DyeItem);
}

public static boolean isHoldingSignChangingItem(PlayerEntity player, Hand hand) {
return isHolding(player, hand, x -> x.getItem() instanceof SignChangingItem);
}
}
12 changes: 5 additions & 7 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@
"environment": "client"
}
],
"includes": {
"cloth-config": "*"
},
"depends": {
"fabricloader": ">=0.15",
"fabric": "*",
"java": ">=17",
"minecraft": ">=1.20.4",
"java": ">=17"
"fabric": "*",
"fabricloader": ">=0.15",
"cloth-config": "*"
},
"suggests": {
"modmenu": ">=8"
"modmenu": ">=9"
},
"conflicts": {
"clickthrough": "*",
Expand Down

0 comments on commit 14ab6c4

Please sign in to comment.