-
Notifications
You must be signed in to change notification settings - Fork 0
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
MrBunnyDc
committed
Sep 27, 2024
1 parent
6feff0a
commit 91f4717
Showing
20 changed files
with
343 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.wonejo.wuidebook.api.book; | ||
|
||
public interface Book { | ||
|
||
BookInfo getInformation (); | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
XPlat/src/main/java/de/wonejo/wuidebook/api/book/BookInfo.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,44 @@ | ||
package de.wonejo.wuidebook.api.book; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.awt.*; | ||
|
||
public interface BookInfo { | ||
|
||
static Builder builder () { | ||
return de.wonejo.wuidebook.impl.book.BookInfoImpl.builderImpl(); | ||
} | ||
|
||
ResourceLocation bookId (); | ||
|
||
ResourceLocation modelLocation (); | ||
ResourceLocation mainBookGUITexture (); | ||
ResourceLocation pageBookGUITexture (); | ||
|
||
Component title (); | ||
Component header (); | ||
Component itemName (); | ||
Component author (); | ||
|
||
Color bookColor (); | ||
|
||
boolean shouldSpawnWithBook (); | ||
|
||
interface Builder { | ||
Builder withId ( ResourceLocation pBookId ); | ||
Builder withModelLocation ( ResourceLocation pLocation ); | ||
Builder withMainBookTexture ( ResourceLocation pLocation ); | ||
Builder withPageBookTexture ( ResourceLocation pLocation ); | ||
Builder setTitle ( Component pTitle ); | ||
Builder setHeader ( Component pHeader ); | ||
Builder setItemName ( Component pItemName ); | ||
Builder setAuthor ( Component pAuthor ); | ||
Builder withBookColor ( Color pColor ); | ||
Builder shouldSpawnWithBook (); | ||
|
||
BookInfo build (); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
XPlat/src/main/java/de/wonejo/wuidebook/api/book/BookRegistry.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,63 @@ | ||
package de.wonejo.wuidebook.api.book; | ||
|
||
import com.google.common.collect.Maps; | ||
import com.mojang.datafixers.util.Pair; | ||
import de.wonejo.wuidebook.api.util.Constants; | ||
import de.wonejo.wuidebook.api.util.WuidebookRegistryException; | ||
import de.wonejo.wuidebook.impl.service.ModServices; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public final class BookRegistry { | ||
private static final Logger LOGGER = LogManager.getLogger(); | ||
private final Map<ResourceLocation, Pair<BookInfo, ResourceLocation>> bookInformation = Maps.newHashMap(); | ||
private final Map<ResourceLocation, Book> books = Maps.newHashMap(); | ||
private boolean areBooksBuilt; | ||
|
||
private BookRegistry () {} | ||
|
||
@ApiStatus.Internal | ||
public void buildBooks () { | ||
if (this.areBooksBuilt) return; | ||
if (!ModServices.ABSTRACTION.getCurrentLoadedModId().equals(Constants.MOD_ID)) throw new RuntimeException("Can not use Wuidebook buildBooks on other mods code!"); | ||
|
||
this.areBooksBuilt = true; | ||
} | ||
|
||
public void registerBook ( @NotNull BookInfo pInfo, ResourceLocation pBaseFileLocation ) { | ||
if ( this.bookInformation.putIfAbsent(pInfo.bookId(), Pair.of(pInfo, pBaseFileLocation)) != null ) | ||
throw new WuidebookRegistryException("Can not register two ( or more ) book information with id: " + pInfo.bookId() + ", it wouldn't be registered!"); | ||
} | ||
|
||
public @NotNull Book getBook (ResourceLocation pBookId ) { | ||
Book book = this.books.get(pBookId); | ||
if (!areBooksBuilt) throw new RuntimeException("Can not get wuidebook guide, books aren't build."); | ||
if ( book == null ) throw new RuntimeException("Can not get book with id: " + pBookId + " because it isn't present."); | ||
return book; | ||
} | ||
|
||
public Optional<Book> getOptBook ( ResourceLocation pBookId ) { | ||
Book book = this.books.get(pBookId); | ||
if (!areBooksBuilt) throw new RuntimeException("Can not get wuidebook guide, books aren't build."); | ||
return Optional.ofNullable(book); | ||
} | ||
|
||
public BookInfo getInfo ( ResourceLocation pBookId ) { | ||
Pair<BookInfo, ResourceLocation> pair = this.bookInformation.get(pBookId); | ||
if ( pair == null ) throw new NullPointerException("Can not get book information, there isn't a book ith id: " + pBookId); | ||
return pair.getFirst(); | ||
} | ||
|
||
public ResourceLocation getBaseFileLocation ( ResourceLocation pBookId ) { | ||
Pair<BookInfo, ResourceLocation> pair = this.bookInformation.get(pBookId); | ||
if ( pair == null ) throw new NullPointerException("Can not get base file location, there isn't a book with id: " + pBookId); | ||
return pair.getSecond(); | ||
} | ||
|
||
} |
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
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
12 changes: 12 additions & 0 deletions
12
XPlat/src/main/java/de/wonejo/wuidebook/api/util/WuidebookRegistryException.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,12 @@ | ||
package de.wonejo.wuidebook.api.util; | ||
|
||
public class WuidebookRegistryException extends RuntimeException { | ||
|
||
public WuidebookRegistryException ( String pMessage ) { | ||
super(pMessage); | ||
} | ||
|
||
public WuidebookRegistryException ( String pMessage, Throwable pThrowable ) { | ||
super(pMessage, pThrowable); | ||
} | ||
} |
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.