Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ExplorersCompass {
public static final DataComponentType<Integer> SEARCH_RADIUS_COMPONENT = DataComponentType.<Integer>builder().persistent(Codec.INT).networkSynchronized(ByteBufCodecs.VAR_INT).build();
public static final DataComponentType<Integer> SAMPLES_COMPONENT = DataComponentType.<Integer>builder().persistent(Codec.INT).networkSynchronized(ByteBufCodecs.VAR_INT).build();
public static final DataComponentType<Boolean> DISPLAY_COORDS_COMPONENT = DataComponentType.<Boolean>builder().persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL).build();
public static final DataComponentType<Boolean> LOCKED_COMPONENT = DataComponentType.<Boolean>builder().persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL).build();

public static boolean canTeleport;
public static List<ResourceLocation> allowedStructureKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class General {
public final ForgeConfigSpec.IntValue maxRadius;
public final ForgeConfigSpec.ConfigValue<List<String>> structureBlacklist;
public final ForgeConfigSpec.IntValue maxSamples;
public final ForgeConfigSpec.BooleanValue singleUse;

General(ForgeConfigSpec.Builder builder) {
String desc;
Expand All @@ -45,6 +46,9 @@ public static class General {
desc = "The maximum number of samples to be taken when searching for a structure.";
maxSamples = builder.comment(desc).defineInRange("maxSamples", 100000, 0, 100000000);

desc = "Limit the compass to single use per item";
singleUse = builder.comment(desc).define("singleUse", false);

builder.pop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -43,17 +44,28 @@ public ExplorersCompassItem() {

@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
final boolean singleUse = ConfigHandler.GENERAL.singleUse.get();

if (!player.isCrouching()) {
if (level.isClientSide()) {
final ItemStack stack = ItemUtils.getHeldItem(player, ExplorersCompass.explorersCompass);
GuiWrapper.openGUI(level, player, stack);
final ItemStack stack = ItemUtils.getHeldItem(player, ExplorersCompass.explorersCompass);

if (!singleUse || !stack.getOrDefault(ExplorersCompass.LOCKED_COMPONENT, false)) {
if (level.isClientSide()) {
GuiWrapper.openGUI(level, player, stack);
} else {
final ServerLevel serverLevel = (ServerLevel) level;
final ServerPlayer serverPlayer = (ServerPlayer) player;
final boolean canTeleport = ConfigHandler.GENERAL.allowTeleport.get() && PlayerUtils.canTeleport(player.getServer(), player);
ExplorersCompass.network.send(new SyncPacket(canTeleport, StructureUtils.getAllowedStructureKeys(serverLevel), StructureUtils.getGeneratingDimensionsForAllowedStructures(serverLevel), StructureUtils.getStructureKeysToTypeKeys(serverLevel), StructureUtils.getTypeKeysToStructureKeys(serverLevel)), PacketDistributor.PLAYER.with(serverPlayer));
}

if (singleUse) {
stack.set(ExplorersCompass.LOCKED_COMPONENT, true);
}
} else {
final ServerLevel serverLevel = (ServerLevel) level;
final ServerPlayer serverPlayer = (ServerPlayer) player;
final boolean canTeleport = ConfigHandler.GENERAL.allowTeleport.get() && PlayerUtils.canTeleport(player.getServer(), player);
ExplorersCompass.network.send(new SyncPacket(canTeleport, StructureUtils.getAllowedStructureKeys(serverLevel), StructureUtils.getGeneratingDimensionsForAllowedStructures(serverLevel), StructureUtils.getStructureKeysToTypeKeys(serverLevel), StructureUtils.getTypeKeysToStructureKeys(serverLevel)), PacketDistributor.PLAYER.with(serverPlayer));
player.displayClientMessage(Component.translatable("string.explorerscompass.locked"), true);
}
} else {
} else if (!singleUse) {
workerManager.stop();
workerManager.clear();
setState(player.getItemInHand(hand), null, CompassState.INACTIVE, player);
Expand Down Expand Up @@ -242,4 +254,12 @@ public boolean shouldDisplayCoordinates(ItemStack stack) {
return true;
}

@Override
public boolean isFoil(ItemStack stack) {
if (ConfigHandler.GENERAL.singleUse.get()) {
return stack.getOrDefault(ExplorersCompass.LOCKED_COMPONENT, false);
}

return super.isFoil(stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static void registerItems(RegisterEvent e) {
registry.register(ResourceLocation.fromNamespaceAndPath(ExplorersCompass.MODID, "search_radius"), ExplorersCompass.SEARCH_RADIUS_COMPONENT);
registry.register(ResourceLocation.fromNamespaceAndPath(ExplorersCompass.MODID, "samples"), ExplorersCompass.SAMPLES_COMPONENT);
registry.register(ResourceLocation.fromNamespaceAndPath(ExplorersCompass.MODID, "display_coords"), ExplorersCompass.DISPLAY_COORDS_COMPONENT);
registry.register(ResourceLocation.fromNamespaceAndPath(ExplorersCompass.MODID, "locked"), ExplorersCompass.LOCKED_COMPONENT);
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/assets/explorerscompass/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,8 @@
"structure.minecraft.village_plains": "Village Plains",
"structure.minecraft.village_savanna": "Village Savanna",
"structure.minecraft.village_snowy": "Village Snowy",
"structure.minecraft.village_taiga": "Village Taiga"
"structure.minecraft.village_taiga": "Village Taiga",

"_comment": "STRINGS - MESSAGES",
"string.explorerscompass.locked": "Compass is locked, disable single use mode to enable multiple searches per item."
}