-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
313 additions
and
70 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
61 changes: 61 additions & 0 deletions
61
src/main/java/me/lukasabbe/bookshelfinspector/config/Config.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,61 @@ | ||
package me.lukasabbe.bookshelfinspector.config; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class Config { | ||
public boolean lecternToggle = true; | ||
|
||
public void loadConfig(){ | ||
Path configPath = FabricLoader.getInstance().getConfigDir().resolve("bookshelfinspector-config.yml"); | ||
if(!Files.exists(configPath))createConfig(configPath); | ||
Yaml yaml = new Yaml(); | ||
try{ | ||
Map<String, Object> configMap = yaml.load(new FileReader(configPath.toFile())); | ||
if(configMap.containsKey("lectern-toggle")){ | ||
lecternToggle = (boolean) configMap.get("lectern-toggle"); | ||
} | ||
|
||
} catch (FileNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private void createConfig(Path configPath){ | ||
FabricLoader.getInstance().getModContainer("bookshelfinspector").ifPresent(modContainer -> { | ||
Path path = modContainer.findPath("bookshelfinspector-config.yml").orElseThrow(); | ||
try { | ||
Files.copy(path,configPath); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
public void saveConfig(){ | ||
Path configPath = FabricLoader.getInstance().getConfigDir().resolve("bookshelfinspector-config.yml"); | ||
if(!Files.exists(configPath))createConfig(configPath); | ||
Yaml yaml = new Yaml(); | ||
try{ | ||
Map<String, Object> configMap = yaml.load(new FileReader(configPath.toFile())); | ||
configMap.put("lectern-toggle",lecternToggle); | ||
FileWriter writer = new FileWriter(configPath.toString()); | ||
yaml.dump(configMap,writer); | ||
writer.close(); | ||
|
||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/me/lukasabbe/bookshelfinspector/config/ModMenu.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,34 @@ | ||
package me.lukasabbe.bookshelfinspector.config; | ||
|
||
import com.terraformersmc.modmenu.api.ConfigScreenFactory; | ||
import com.terraformersmc.modmenu.api.ModMenuApi; | ||
import me.lukasabbe.bookshelfinspector.BookshelfinspectorClient; | ||
import me.shedaniel.clothconfig2.api.ConfigBuilder; | ||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.text.Text; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class ModMenu implements ModMenuApi { | ||
@Override | ||
public ConfigScreenFactory<?> getModConfigScreenFactory() { | ||
return parent -> { | ||
ConfigBuilder builder = ConfigBuilder | ||
.create() | ||
.setParentScreen(parent) | ||
.setTitle(Text.translatable("bookshelfinspector.config.title")); | ||
ConfigEntryBuilder entryBuilder = builder.entryBuilder(); | ||
|
||
builder | ||
.getOrCreateCategory(Text.translatable("bookshelfinspector.config.category")) | ||
.addEntry(entryBuilder | ||
.startBooleanToggle(Text.translatable("bookshelfinspector.config.lectern.toggle"), BookshelfinspectorClient.config.lecternToggle) | ||
.setTooltip(Text.translatable("bookshelfinspector.config.lectern.toggle.tooltip")) | ||
.setDefaultValue(true) | ||
.setSaveConsumer(val -> BookshelfinspectorClient.config.lecternToggle = val).build()); | ||
builder.setSavingRunnable(BookshelfinspectorClient.config::saveConfig); | ||
return builder.build(); | ||
}; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/me/lukasabbe/bookshelfinspector/data/BookShelfData.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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package me.lukasabbe.bookshelfinspector.data; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class BookShelfData { | ||
public boolean isCurrentBookDataToggled = false; | ||
public BlockPos latestPos = null; | ||
public boolean requestSent = false; | ||
public int currentSlotInt = -1; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/me/lukasabbe/bookshelfinspector/network/LecternInventoryRequestPayload.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,19 @@ | ||
package me.lukasabbe.bookshelfinspector.network; | ||
|
||
import net.minecraft.network.RegistryByteBuf; | ||
import net.minecraft.network.codec.PacketCodec; | ||
import net.minecraft.network.packet.CustomPayload; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public record LecternInventoryRequestPayload(BlockPos pos) implements CustomPayload{ | ||
public static final CustomPayload.Id<LecternInventoryRequestPayload> ID = new CustomPayload.Id<>(BookShelfInspectorNetworkConstants.LECTERN_INVENTORY_REQUEST_PACKET_ID); | ||
|
||
public static final PacketCodec<RegistryByteBuf, LecternInventoryRequestPayload> CODEC = PacketCodec.tuple( | ||
BlockPos.PACKET_CODEC,LecternInventoryRequestPayload::pos, | ||
LecternInventoryRequestPayload::new); | ||
|
||
@Override | ||
public CustomPayload.Id<? extends CustomPayload> getId() { | ||
return ID; | ||
} | ||
} |
Oops, something went wrong.