-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 8e4a137
Showing
29 changed files
with
1,139 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
* text eol=lf | ||
*.bat text eol=crlf | ||
*.patch text eol=lf | ||
*.java text eol=lf | ||
*.gradle text eol=crlf | ||
*.png binary | ||
*.gif binary | ||
*.exe binary | ||
*.dll binary | ||
*.jar binary | ||
*.lzma binary | ||
*.zip binary | ||
*.pyd binary | ||
*.cfg text eol=lf | ||
*.jks binary |
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,25 @@ | ||
# eclipse | ||
bin | ||
*.launch | ||
.settings | ||
.metadata | ||
.classpath | ||
.project | ||
|
||
# idea | ||
out | ||
*.ipr | ||
*.iws | ||
*.iml | ||
.idea/* | ||
!.idea/scopes | ||
.idea | ||
|
||
# gradle | ||
build | ||
.gradle | ||
|
||
# other | ||
eclipse | ||
run | ||
artifacts |
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,52 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' | ||
id 'maven-publish' | ||
} | ||
|
||
archivesBaseName = "${mod_name}-common-${minecraft_version}" | ||
|
||
minecraft { | ||
version(minecraft_version) | ||
runs { | ||
if (project.hasProperty('common_runs_enabled') ? project.findProperty('common_runs_enabled').toBoolean() : true) { | ||
|
||
server(project.hasProperty('common_server_run_name') ? project.findProperty('common_server_run_name') : 'vanilla_server') { | ||
workingDirectory(this.file("run")) | ||
} | ||
client(project.hasProperty('common_client_run_name') ? project.findProperty('common_client_run_name') : 'vanilla_client') { | ||
workingDirectory(this.file("run")) | ||
} | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5' | ||
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' | ||
} | ||
|
||
processResources { | ||
def buildProps = project.properties.clone() | ||
|
||
filesMatching(['pack.mcmeta']) { | ||
expand buildProps | ||
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
groupId project.group | ||
artifactId project.archivesBaseName | ||
version project.version | ||
from components.java | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://" + System.getenv("local_maven") | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Common/src/main/java/me/hypherionmc/morecreativetabs/Logger.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,17 @@ | ||
package me.hypherionmc.morecreativetabs; | ||
|
||
public class Logger { | ||
|
||
public static void error(String message) { | ||
ModConstants.logger.error("[MoreCreativeTabs] " + message); | ||
} | ||
|
||
public static void info(String message) { | ||
ModConstants.logger.info("[MoreCreativeTabs] " + message); | ||
} | ||
|
||
public static void warn(String message) { | ||
ModConstants.logger.warn("[MoreCreativeTabs] " + message); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
Common/src/main/java/me/hypherionmc/morecreativetabs/ModConstants.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,9 @@ | ||
package me.hypherionmc.morecreativetabs; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class ModConstants { | ||
public static final String MOD_ID = "morecreativetabs"; | ||
public static final Logger logger = LogManager.getLogger("MoreCreativeTabs"); | ||
} |
108 changes: 108 additions & 0 deletions
108
Common/src/main/java/me/hypherionmc/morecreativetabs/client/CustomCreativeTabManager.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,108 @@ | ||
package me.hypherionmc.morecreativetabs.client; | ||
|
||
import com.google.gson.Gson; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import me.hypherionmc.morecreativetabs.Logger; | ||
import net.minecraft.core.NonNullList; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.TagParser; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.resources.ResourceManager; | ||
import net.minecraft.world.item.CreativeModeTab; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
public class CustomCreativeTabManager { | ||
|
||
public static Set<Item> hidden_stacks = new HashSet<>(); | ||
public static Set<CreativeModeTab> custom_tabs = new HashSet<>(); | ||
public static Set<String> disabled_tabs = new HashSet<>(); | ||
|
||
public static void loadEntries(ResourceManager manager, Collection<ResourceLocation> entries, TabCreator creator) { | ||
for (ResourceLocation location : entries) { | ||
Logger.info("Processing " + location.toString()); | ||
|
||
try (InputStream stream = manager.getResource(location).getInputStream()) { | ||
TabJsonHelper json = new Gson().fromJson(new InputStreamReader(stream), TabJsonHelper.class); | ||
|
||
if (json.tab_enabled) { | ||
ArrayList<ItemStack> tabItems = new ArrayList<>(); | ||
|
||
json.tab_items.forEach(item -> { | ||
ItemStack stack = getItemStack(item.name); | ||
if (stack != ItemStack.EMPTY) { | ||
if (item.hide_old_tab) { | ||
hidden_stacks.add(stack.getItem()); | ||
} | ||
if (item.nbt != null && !item.nbt.isEmpty()) { | ||
try { | ||
CompoundTag tag = TagParser.parseTag(item.nbt); | ||
stack.setTag(tag); | ||
} catch (CommandSyntaxException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
tabItems.add(stack); | ||
} | ||
}); | ||
|
||
custom_tabs.add(creator.createTab(json, tabItems)); | ||
} | ||
|
||
} catch (Exception e) { | ||
Logger.error("Failed to process creative tab"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
public static CreativeModeTab defaultTabCreator(TabJsonHelper json, List<ItemStack> tabItems) { | ||
CreativeModeTab customTab = new CreativeModeTab(-1, "morecreativetabs." + json.tab_name) { | ||
|
||
@Override | ||
public String getBackgroundSuffix() { | ||
return json.tab_background == null ? super.getBackgroundSuffix() : json.tab_background; | ||
} | ||
|
||
@Override | ||
public ItemStack makeIcon() { | ||
AtomicReference<ItemStack> icon = new AtomicReference<>(ItemStack.EMPTY); | ||
Registry.ITEM.getOptional(new ResourceLocation(json.tab_icon)).ifPresent(item -> { | ||
icon.set(new ItemStack(item)); | ||
}); | ||
return icon.get(); | ||
} | ||
|
||
@Override | ||
public void fillItemList(NonNullList<ItemStack> itemStacks) { | ||
itemStacks.clear(); | ||
itemStacks.addAll(tabItems); | ||
} | ||
}; | ||
return customTab; | ||
} | ||
|
||
public static void loadDisabledTabs(ResourceManager manager, ResourceLocation location) { | ||
Logger.info("Processing " + location.toString()); | ||
|
||
try (InputStream stream = manager.getResource(location).getInputStream()) { | ||
DisabledTabsJsonHelper json = new Gson().fromJson(new InputStreamReader(stream), DisabledTabsJsonHelper.class); | ||
disabled_tabs.addAll(json.disabled_tabs); | ||
} catch (Exception e) { | ||
Logger.error("Failed to process disabled tabs"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private static ItemStack getItemStack(String jsonItem) { | ||
Optional<Item> itemOptional = Registry.ITEM.getOptional(new ResourceLocation(jsonItem)); | ||
return itemOptional.map(ItemStack::new).orElse(ItemStack.EMPTY); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
Common/src/main/java/me/hypherionmc/morecreativetabs/client/DisabledTabsJsonHelper.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,7 @@ | ||
package me.hypherionmc.morecreativetabs.client; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class DisabledTabsJsonHelper { | ||
public ArrayList<String> disabled_tabs; | ||
} |
12 changes: 12 additions & 0 deletions
12
Common/src/main/java/me/hypherionmc/morecreativetabs/client/TabCreator.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 me.hypherionmc.morecreativetabs.client; | ||
|
||
import net.minecraft.world.item.CreativeModeTab; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.List; | ||
|
||
public interface TabCreator { | ||
|
||
public CreativeModeTab createTab(TabJsonHelper jsonHelper, List<ItemStack> stacks); | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
Common/src/main/java/me/hypherionmc/morecreativetabs/client/TabJsonHelper.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,18 @@ | ||
package me.hypherionmc.morecreativetabs.client; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class TabJsonHelper { | ||
|
||
public boolean tab_enabled; | ||
public String tab_name; | ||
public String tab_icon; | ||
public String tab_background; | ||
public ArrayList<TabItem> tab_items; | ||
|
||
public static class TabItem { | ||
public String name; | ||
public boolean hide_old_tab; | ||
public String nbt; | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"pack": { | ||
"description": "${mod_name}", | ||
"pack_format": 8 | ||
} | ||
} |
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,79 @@ | ||
plugins { | ||
id 'fabric-loom' version '0.10-SNAPSHOT' | ||
id 'maven-publish' | ||
id 'idea' | ||
} | ||
|
||
archivesBaseName = "${mod_name}-fabric-${minecraft_version}" | ||
|
||
dependencies { | ||
minecraft "com.mojang:minecraft:${minecraft_version}" | ||
mappings loom.officialMojangMappings() | ||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" | ||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" | ||
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' | ||
implementation project(":Common") | ||
} | ||
|
||
loom { | ||
runs { | ||
client { | ||
client() | ||
setConfigName("Fabric Client") | ||
ideConfigGenerated(true) | ||
runDir("run") | ||
} | ||
server { | ||
server() | ||
setConfigName("Fabric Server") | ||
ideConfigGenerated(true) | ||
runDir("run") | ||
} | ||
} | ||
} | ||
|
||
processResources { | ||
from project(":Common").sourceSets.main.resources | ||
inputs.property "version", project.version | ||
|
||
filesMatching("fabric.mod.json") { | ||
expand "version": project.version | ||
} | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
source(project(":Common").sourceSets.main.allSource) | ||
} | ||
|
||
jar { | ||
from("LICENSE") { | ||
rename { "${it}_${mod_name}" } | ||
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
groupId project.group | ||
artifactId project.archivesBaseName | ||
version project.version | ||
from components.java | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
url "file://" + System.getenv("local_maven") | ||
} | ||
} | ||
|
||
task delDevJar { | ||
doLast { | ||
def tree = fileTree("build/libs") | ||
tree.include '**/*-dev.jar' | ||
tree.each { it.delete() } | ||
} | ||
} | ||
|
||
build.finalizedBy delDevJar | ||
} |
Oops, something went wrong.