Skip to content

Commit

Permalink
Fix creative mode search, add CCOrganItem interface and NBT organ sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
Tigereye504 committed Jul 13, 2023
1 parent 125fcba commit 764632b
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 20 deletions.
21 changes: 17 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -43,6 +43,12 @@ repositories {
//maven { url "https://oss.sonatype.org/service/local/repositories/snapshots/content"} //for a misbehaving requiem prereq?
}

configurations.all {
resolutionStrategy {
force("net.fabricmc:fabric-loader:$loader_version")
}
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand Down Expand Up @@ -72,9 +78,16 @@ dependencies {
// modRuntimeOnly "io.github.ladysnake:requiem-core:${project.requiem_version}"
// modRuntimeOnly "io.github.ladysnake:requiem:${project.requiem_version}"

modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
modRuntimeOnly "dev.architectury:architectury:${project.architectury_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
modCompileOnly("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"){
exclude group: "net.fabricmc", module: "fabric-loader"
exclude group: "dev.architectury", module: "architectury"
}
//modRuntimeOnly("dev.architectury:architectury:${project.architectury_version}"){
// exclude group: "net.fabricmc", module: "fabric-loader"
//}
modCompileOnly ("me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"){
exclude group: "net.fabricmc", module: "fabric-loader"
}


// Jar-in-Jar dependencies
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://fabricmc.net/use
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.19
loader_version=0.14.21

# Mod Properties
mod_version = 2.16.5
mod_version = 2.16.6-test
maven_group = net.tigereye.chestcavity
archives_base_name = chestcavity

Expand All @@ -19,7 +19,7 @@ org.gradle.jvmargs=-Xmx1G
# Other mods
architectury_version=6.5.77
cloth_config_version=8.2.88
mod_menus_version=4.0.0
rei_version = 9.1.595
mod_menus_version=4.2.0-beta.2
rei_version = 9.1.619
requiem_version = 2.0.0-beta.16
#fiber_version = 0.23.0-2
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
import com.google.gson.Gson;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import net.minecraft.util.registry.Registry;
import net.tigereye.chestcavity.ChestCavity;
import org.jetbrains.annotations.NotNull;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class OrganManager implements SimpleSynchronousResourceReloadListener {
private static final String RESOURCE_LOCATION = "organs";
private static final String NBT_KEY = "organData";
private final OrganSerializer SERIALIZER = new OrganSerializer();
public static Map<Identifier, OrganData> GeneratedOrganData = new HashMap<>();

Expand Down Expand Up @@ -55,4 +60,24 @@ public static boolean isTrueOrgan(Item item){
}
return false;
}

public static OrganData readNBTOrganData(ItemStack itemStack) {
NbtCompound nbt = itemStack.getSubNbt(NBT_KEY);
if(nbt != null) {
return readNBTOrganData(nbt);
}
return null;
}

public static OrganData readNBTOrganData(@NotNull NbtCompound nbt) {
OrganData organData = new OrganData();
organData.pseudoOrgan = nbt.getBoolean("pseudoOrgan");
for (String key:
nbt.getKeys()) {
if(!key.equals("pseudoOrgan")){
organData.organScores.put(new Identifier(key),nbt.getFloat(key));
}
}
return organData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.tigereye.chestcavity.interfaces;

import net.tigereye.chestcavity.chestcavities.organs.OrganData;

public interface CCOrganItem {

public OrganData getOrganData();
}
14 changes: 7 additions & 7 deletions src/main/java/net/tigereye/chestcavity/mixin/MixinItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.World;
import net.tigereye.chestcavity.chestcavities.organs.OrganManager;
import net.tigereye.chestcavity.chestcavities.organs.OrganData;
import net.tigereye.chestcavity.util.ChestCavityUtil;
import net.tigereye.chestcavity.util.OrganUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -25,13 +26,12 @@ public class MixinItem {

@Inject(at = @At("HEAD"), method = "appendTooltip")
public void chestCavityItemAppendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context, CallbackInfo info){
//((Item)(Object)this)
Identifier id = Registry.ITEM.getId(((Item)(Object)this));
if(OrganManager.GeneratedOrganData.containsKey(id)){
OrganData data = OrganManager.GeneratedOrganData.get(id);
if(!data.pseudoOrgan && world.isClient){
OrganUtil.displayOrganQuality(data.organScores,tooltip);
OrganUtil.displayCompatibility(stack,world,tooltip,context);
if(world != null) {
Identifier id = Registry.ITEM.getId(((Item) (Object) this));
OrganData data = ChestCavityUtil.lookupOrgan(stack, null);
if (data != null && !data.pseudoOrgan && world.isClient) {
OrganUtil.displayOrganQuality(data.organScores, tooltip);
OrganUtil.displayCompatibility(stack, world, tooltip, context);
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/net/tigereye/chestcavity/util/ChestCavityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.tigereye.chestcavity.chestcavities.organs.OrganManager;
import net.tigereye.chestcavity.chestcavities.organs.OrganData;
import net.tigereye.chestcavity.compat.requiem.CCRequiem;
import net.tigereye.chestcavity.interfaces.CCOrganItem;
import net.tigereye.chestcavity.interfaces.ChestCavityEntity;
import net.tigereye.chestcavity.listeners.*;
import net.tigereye.chestcavity.registration.*;
Expand Down Expand Up @@ -491,11 +492,23 @@ public static boolean isHydroPhobicOrAllergic(LivingEntity entity){
return false;
}

protected static OrganData lookupOrgan(ItemStack itemStack, ChestCavityType cct){
OrganData organData = cct.catchExceptionalOrgan(itemStack);
public static OrganData lookupOrgan(ItemStack itemStack, ChestCavityType cct){
OrganData organData = null;
if(cct != null) {
organData = cct.catchExceptionalOrgan(itemStack);
}
if(organData != null){ //check for exceptional organs
return organData;
}
else{
organData = OrganManager.readNBTOrganData(itemStack);
}
if(organData != null){
return organData;
}
else if(itemStack.getItem() instanceof CCOrganItem oItem){
return oItem.getOrganData();
}
else if(OrganManager.hasEntry(itemStack.getItem())){ //check for normal organs
return OrganManager.getEntry(itemStack.getItem());
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/net/tigereye/chestcavity/util/OrganUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ public static void displayOrganQuality(Map<Identifier,Float> organQualityMap, Li
@Environment(EnvType.CLIENT)
public static void displayCompatibility(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {

NbtCompound tag = itemStack.getNbt();
NbtCompound tag = itemStack.getOrCreateNbt();
String textString;
boolean uuidMatch = false;
int compatLevel = 0;
PlayerEntity serverPlayer = null;
net.minecraft.server.MinecraftServer server = world.getServer();
net.minecraft.server.MinecraftServer server = null;
if(world != null) {
server = world.getServer();
}
if(server == null) {
server = MinecraftClient.getInstance().getServer();
}
Expand Down

0 comments on commit 764632b

Please sign in to comment.