diff --git a/.gitattributes b/.gitattributes index cc5dfffec..5c267e7c9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,20 +1,20 @@ -# Windows files (CRLF) -*.bat text eol=crlf - -# Text -*.properties text - -# Java -*.java text diff=java -*.gradle text diff=java -*.gradle.kts text diff=kotlin - -# Binary -*.class binary -*.dll binary -*.ear binary -*.jar binary -*.so binary -*.war binary - -**/.cache/* linguist-generated=true +# Windows files (CRLF) +*.bat text eol=crlf + +# Text +*.properties text + +# Java +*.java text diff=java +*.gradle text diff=java +*.gradle.kts text diff=kotlin + +# Binary +*.class binary +*.dll binary +*.ear binary +*.jar binary +*.so binary +*.war binary + +**/.cache/* linguist-generated=true diff --git a/.gitignore b/.gitignore index a8cf67018..c0afb43b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,221 +1,222 @@ - -# Created by https://www.toptal.com/developers/gitignore/api/java,gradle,jetbrains+all,eclipse,visualstudiocode -# Edit at https://www.toptal.com/developers/gitignore?templates=java,gradle,jetbrains+all,eclipse,visualstudiocode - -### Eclipse ### -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# CDT- autotools -.autotools - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - -# Annotation Processing -.apt_generated/ -.apt_generated_test/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -# Uncomment this line if you wish to ignore the project description file. -# Typically, this file would be tracked if it contains build/dependency configurations: -#.project - -### Eclipse Patch ### -# Spring Boot Tooling -.sts4-cache/ - -### Java ### -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -### JetBrains+all ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/artifacts -# .idea/compiler.xml -# .idea/jarRepositories.xml -# .idea/modules.xml -# .idea/*.iml -# .idea/modules -# *.iml -# *.ipr - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### JetBrains+all Patch ### -# Ignores the whole .idea folder and all .iml files -# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 - -.idea/ - -# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 - -*.iml -modules.xml -.idea/misc.xml -*.ipr - -# Sonarlint plugin -.idea/sonarlint - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history - -### Gradle ### -.gradle -build/ - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties - -### Gradle Patch ### -**/build/ - -# End of https://www.toptal.com/developers/gitignore/api/java,gradle,jetbrains+all,eclipse,visualstudiocode - -# FabricMC -run/ -remappedSrc/ -src/main/generated/.cache/ + +# Created by https://www.toptal.com/developers/gitignore/api/java,gradle,jetbrains+all,eclipse,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=java,gradle,jetbrains+all,eclipse,visualstudiocode + +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +### Eclipse Patch ### +# Spring Boot Tooling +.sts4-cache/ + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### JetBrains+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +### Gradle Patch ### +**/build/ + +# End of https://www.toptal.com/developers/gitignore/api/java,gradle,jetbrains+all,eclipse,visualstudiocode + +# FabricMC +run/ +remappedSrc/ +src/main/generated/.cache/ +src/main/generated/* diff --git a/gradle.properties b/gradle.properties index 430ac89dd..9bf4126dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,5 +22,5 @@ machinelib.version=0.7.0+74 badpackets.version=0.8.1 wthit.version=12.3.0 obj.version=0.4.0 -appleskin.version=mc1.20.3-2.5.1 +appleskin.version=mc1.21-3.0.5 architectury.version=13.0.6 diff --git a/src/main/generated/assets/galacticraft/lang/en_us.json b/src/main/generated/assets/galacticraft/lang/en_us.json index bc8198983..32eafb7d1 100644 --- a/src/main/generated/assets/galacticraft/lang/en_us.json +++ b/src/main/generated/assets/galacticraft/lang/en_us.json @@ -1,6 +1,6 @@ { - "biome.galacticraft.asteroid_field": "Asteroid Field", "banner_pattern.galacticraft.rocket": "Rocket", + "biome.galacticraft.asteroid_field": "Asteroid Field", "biome.galacticraft.basaltic_mare": "Basaltic Mare", "biome.galacticraft.comet_tundra": "Comet Tundra", "biome.galacticraft.lunar_highlands": "Lunar Highlands", diff --git a/src/main/generated/data/c/tags/block/ores.json b/src/main/generated/data/c/tags/block/ores.json index f63a851d9..ec49ac103 100644 --- a/src/main/generated/data/c/tags/block/ores.json +++ b/src/main/generated/data/c/tags/block/ores.json @@ -10,11 +10,11 @@ "galacticraft:deepslate_tin_ore", "galacticraft:moon_tin_ore", "galacticraft:lunaslate_tin_ore", - "galacticraft:aluminum_ore", - "galacticraft:deepslate_aluminum_ore", "galacticraft:asteroid_aluminum_ore", "galacticraft:asteroid_iron_ore", "galacticraft:asteroid_silicon_ore", + "galacticraft:aluminum_ore", + "galacticraft:deepslate_aluminum_ore", "galacticraft:desh_ore", "galacticraft:ilmenite_ore", "galacticraft:galena_ore" diff --git a/src/main/generated/data/c/tags/items/foods.json b/src/main/generated/data/c/tags/item/foods.json similarity index 80% rename from src/main/generated/data/c/tags/items/foods.json rename to src/main/generated/data/c/tags/item/foods.json index ca81c0dba..1f9ac8577 100644 --- a/src/main/generated/data/c/tags/items/foods.json +++ b/src/main/generated/data/c/tags/item/foods.json @@ -1,7 +1,5 @@ { - "replace": false, "values": [ - "galacticraft:moon_berries", "galacticraft:cheese_curd", "galacticraft:cheese_slice", "galacticraft:burger_bun", diff --git a/src/main/generated/data/c/tags/item/ores.json b/src/main/generated/data/c/tags/item/ores.json index ec49ac103..f63a851d9 100644 --- a/src/main/generated/data/c/tags/item/ores.json +++ b/src/main/generated/data/c/tags/item/ores.json @@ -10,11 +10,11 @@ "galacticraft:deepslate_tin_ore", "galacticraft:moon_tin_ore", "galacticraft:lunaslate_tin_ore", + "galacticraft:aluminum_ore", + "galacticraft:deepslate_aluminum_ore", "galacticraft:asteroid_aluminum_ore", "galacticraft:asteroid_iron_ore", "galacticraft:asteroid_silicon_ore", - "galacticraft:aluminum_ore", - "galacticraft:deepslate_aluminum_ore", "galacticraft:desh_ore", "galacticraft:ilmenite_ore", "galacticraft:galena_ore" diff --git a/src/main/generated/data/galacticraft/advancement/recipes/misc/food_canner.json b/src/main/generated/data/galacticraft/advancement/recipes/misc/food_canner.json index ecf8d58c8..2d3d1b126 100644 --- a/src/main/generated/data/galacticraft/advancement/recipes/misc/food_canner.json +++ b/src/main/generated/data/galacticraft/advancement/recipes/misc/food_canner.json @@ -5,13 +5,7 @@ "conditions": { "items": [ { -<<<<<<<< HEAD:src/main/generated/data/galacticraft/advancement/recipes/misc/food_canner.json - "items": [ - "galacticraft:oxygen_concentrator" - ] -======== - "items": "galacticraft:tin_canister" ->>>>>>>> upstream/main:src/main/generated/data/galacticraft/advancement/recipes/food/canned_beef.json + "items": "galacticraft:oxygen_concentrator" } ] }, diff --git a/src/main/generated/data/galacticraft/dimension_type/asteroid.json b/src/main/generated/data/galacticraft/dimension_type/asteroid.json index 608a264ae..0f1792058 100644 --- a/src/main/generated/data/galacticraft/dimension_type/asteroid.json +++ b/src/main/generated/data/galacticraft/dimension_type/asteroid.json @@ -13,10 +13,8 @@ "monster_spawn_block_light_limit": 0, "monster_spawn_light_level": { "type": "minecraft:uniform", - "value": { - "max_inclusive": 7, - "min_inclusive": 0 - } + "max_inclusive": 7, + "min_inclusive": 0 }, "natural": false, "piglin_safe": false, diff --git a/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_aluminum_ore.json b/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_aluminum_ore.json index ccd32ffb6..8e26a078a 100644 --- a/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_aluminum_ore.json +++ b/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_aluminum_ore.json @@ -13,18 +13,20 @@ { "condition": "minecraft:match_tool", "predicate": { - "enchantments": [ - { - "enchantment": "minecraft:silk_touch", - "levels": { - "min": 1 + "predicates": { + "minecraft:enchantments": [ + { + "enchantments": "minecraft:silk_touch", + "levels": { + "min": 1 + } } - } - ] + ] + } } } ], - "name": "minecraft:air" + "name": "galacticraft:asteroid_aluminum_ore" }, { "type": "minecraft:item", diff --git a/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_iron_ore.json b/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_iron_ore.json index 1b85b769a..2e3fc42d3 100644 --- a/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_iron_ore.json +++ b/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_iron_ore.json @@ -13,18 +13,20 @@ { "condition": "minecraft:match_tool", "predicate": { - "enchantments": [ - { - "enchantment": "minecraft:silk_touch", - "levels": { - "min": 1 + "predicates": { + "minecraft:enchantments": [ + { + "enchantments": "minecraft:silk_touch", + "levels": { + "min": 1 + } } - } - ] + ] + } } } ], - "name": "minecraft:air" + "name": "galacticraft:asteroid_iron_ore" }, { "type": "minecraft:item", diff --git a/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_silicon_ore.json b/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_silicon_ore.json index b87844929..349d60235 100644 --- a/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_silicon_ore.json +++ b/src/main/generated/data/galacticraft/loot_table/blocks/asteroid_silicon_ore.json @@ -13,18 +13,20 @@ { "condition": "minecraft:match_tool", "predicate": { - "enchantments": [ - { - "enchantment": "minecraft:silk_touch", - "levels": { - "min": 1 + "predicates": { + "minecraft:enchantments": [ + { + "enchantments": "minecraft:silk_touch", + "levels": { + "min": 1 + } } - } - ] + ] + } } } ], - "name": "minecraft:air" + "name": "galacticraft:asteroid_silicon_ore" }, { "type": "minecraft:item", diff --git a/src/main/generated/data/galacticraft/loot_table/blocks/mars_copper_ore.json b/src/main/generated/data/galacticraft/loot_table/blocks/mars_copper_ore.json index b3afbe4ec..8d46e701e 100644 --- a/src/main/generated/data/galacticraft/loot_table/blocks/mars_copper_ore.json +++ b/src/main/generated/data/galacticraft/loot_table/blocks/mars_copper_ore.json @@ -13,14 +13,16 @@ { "condition": "minecraft:match_tool", "predicate": { - "enchantments": [ - { - "enchantment": "minecraft:silk_touch", - "levels": { - "min": 1 + "predicates": { + "minecraft:enchantments": [ + { + "enchantments": "minecraft:silk_touch", + "levels": { + "min": 1 + } } - } - ] + ] + } } } ], diff --git a/src/main/generated/data/galacticraft/loot_table/blocks/mars_iron_ore.json b/src/main/generated/data/galacticraft/loot_table/blocks/mars_iron_ore.json index 7429ac44f..0b0ff1e1c 100644 --- a/src/main/generated/data/galacticraft/loot_table/blocks/mars_iron_ore.json +++ b/src/main/generated/data/galacticraft/loot_table/blocks/mars_iron_ore.json @@ -13,14 +13,16 @@ { "condition": "minecraft:match_tool", "predicate": { - "enchantments": [ - { - "enchantment": "minecraft:silk_touch", - "levels": { - "min": 1 + "predicates": { + "minecraft:enchantments": [ + { + "enchantments": "minecraft:silk_touch", + "levels": { + "min": 1 + } } - } - ] + ] + } } } ], diff --git a/src/main/generated/data/galacticraft/loot_table/blocks/mars_tin_ore.json b/src/main/generated/data/galacticraft/loot_table/blocks/mars_tin_ore.json index fd7ed36c1..8ec0be6a5 100644 --- a/src/main/generated/data/galacticraft/loot_table/blocks/mars_tin_ore.json +++ b/src/main/generated/data/galacticraft/loot_table/blocks/mars_tin_ore.json @@ -13,14 +13,16 @@ { "condition": "minecraft:match_tool", "predicate": { - "enchantments": [ - { - "enchantment": "minecraft:silk_touch", - "levels": { - "min": 1 + "predicates": { + "minecraft:enchantments": [ + { + "enchantments": "minecraft:silk_touch", + "levels": { + "min": 1 + } } - } - ] + ] + } } } ], diff --git a/src/main/generated/data/galacticraft/recipe/food_canner.json b/src/main/generated/data/galacticraft/recipe/food_canner.json index 9010619e4..2f2634f13 100644 --- a/src/main/generated/data/galacticraft/recipe/food_canner.json +++ b/src/main/generated/data/galacticraft/recipe/food_canner.json @@ -21,6 +21,7 @@ "SBS" ], "result": { - "item": "galacticraft:food_canner" + "count": 1, + "id": "galacticraft:food_canner" } } \ No newline at end of file diff --git a/src/main/java/dev/galacticraft/mod/GalacticraftClient.java b/src/main/java/dev/galacticraft/mod/GalacticraftClient.java index df47a96d6..8c03e98db 100644 --- a/src/main/java/dev/galacticraft/mod/GalacticraftClient.java +++ b/src/main/java/dev/galacticraft/mod/GalacticraftClient.java @@ -27,6 +27,7 @@ import dev.galacticraft.mod.client.GCKeyBinds; import dev.galacticraft.mod.client.gui.screen.ingame.*; import dev.galacticraft.mod.client.model.GCModelLoader; +import dev.galacticraft.mod.client.model.GCRenderTypes; import dev.galacticraft.mod.client.model.OxygenSealerSpriteProvider; import dev.galacticraft.mod.client.model.SolarPanelSpriteProvider; import dev.galacticraft.mod.client.model.types.ObjModel; @@ -49,6 +50,8 @@ import dev.galacticraft.mod.content.item.GCItems; import dev.galacticraft.mod.events.ClientEventHandler; import dev.galacticraft.mod.misc.cape.CapesLoader; +import dev.galacticraft.mod.network.c2s.OpenGcInventoryPayload; +import dev.galacticraft.mod.network.c2s.OpenRocketPayload; import dev.galacticraft.mod.particle.GCParticleTypes; import dev.galacticraft.mod.screen.GCMenuTypes; import dev.galacticraft.mod.screen.GCPlayerInventoryMenu; @@ -70,7 +73,11 @@ import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.ThrownItemRenderer; +import net.minecraft.core.component.DataComponents; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.packs.PackType; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.material.Fluids; import java.util.*; @@ -186,48 +193,49 @@ public void onInitializeClient() { LivingEntityFeatureRendererRegistrationCallback.EVENT.register((entityType, entityRenderer, registrationHelper, context) -> { }); + GCRenderTypes.init(); //couldn't be bothered finding a better way to get the texture of the items so overrides exists now List nameOverride = new ArrayList<>(); nameOverride.add(new String[]{"enchanted_golden_apple", "golden_apple"}); nameOverride.add(new String[]{"air", "lime_dye"}); ModelLoadingPlugin.register(GCModelLoader.INSTANCE); - GCRenderTypes.init(); - ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (!colorsInitialized) - { - if (client.player != null && client.level != null) - { - CANNED_FOOD_ITEMS.forEach(cannedFoodItem -> { - Optional cannedItem = CannedFoodItem.getContents(cannedFoodItem.getDefaultInstance()).findFirst(); - if (cannedItem.isPresent()) { - String nameComponent = cannedItem.toString(); - String itemName = extractInsideBrackets(nameComponent); - assert itemName != null; - String[] parts = itemName.split(":"); - String namespace = parts[0]; - String item = parts[1]; - for (String[] element: nameOverride) - { - if (parts[1].equals(element[0])) - { - item = element[1]; - } - } - ResourceLocation textureLocation = new ResourceLocation(namespace, "textures/item/" + item + ".png"); - int avgColor = getAverageColor(textureLocation); - cannedFoodItem.setColor(avgColor); - } - }); - colorsInitialized = true; - } - } - }); + //Todo: make fix for the color of the labels based of component nbt +// ClientTickEvents.END_CLIENT_TICK.register(client -> { +// if (!colorsInitialized) +// { +// if (client.player != null && client.level != null) +// { +// CANNED_FOOD_ITEMS.forEach(cannedFoodItem -> { +// Optional cannedItem = CannedFoodItem.getContents(cannedFoodItem.getDefaultInstance()).stream().findFirst(); +// if (cannedItem.isPresent()) { +// String nameComponent = cannedItem.toString(); +// String itemName = extractInsideBrackets(nameComponent); +// assert itemName != null; +// String[] parts = itemName.split(":"); +// String namespace = parts[0]; +// String item = parts[1]; +// for (String[] element: nameOverride) +// { +// if (parts[1].equals(element[0])) +// { +// item = element[1]; +// } +// } +// ResourceLocation textureLocation = new ResourceLocation(namespace, "textures/item/" + item + ".png"); +// int avgColor = getAverageColor(textureLocation); +// cannedFoodItem.setColor(avgColor); +// } +// }); +// colorsInitialized = true; +// } +// } +// }); //For every edible food create a creative item of that canned food type for (Item item : BuiltInRegistries.ITEM) { - if (item.getFoodProperties() != null) + if (item.components().has(DataComponents.FOOD)) { if (!(item instanceof CannedFoodItem)) { diff --git a/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/FoodCannerScreen.java b/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/FoodCannerScreen.java index 6acfef48c..a619f7c57 100644 --- a/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/FoodCannerScreen.java +++ b/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/FoodCannerScreen.java @@ -22,14 +22,10 @@ package dev.galacticraft.mod.client.gui.screen.ingame; -import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import dev.galacticraft.machinelib.api.menu.MachineMenu; -import dev.galacticraft.machinelib.api.menu.sync.MenuSyncHandler; import dev.galacticraft.machinelib.client.api.screen.MachineScreen; import dev.galacticraft.mod.Constant; import dev.galacticraft.mod.content.block.entity.machine.FoodCannerBlockEntity; -import dev.galacticraft.mod.machine.GCMachineStatuses; import dev.galacticraft.mod.screen.FoodCannerMenu; import dev.galacticraft.mod.util.DrawableUtil; import net.fabricmc.api.EnvType; @@ -37,9 +33,6 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; -import org.jetbrains.annotations.MustBeInvokedByOverriders; - -import java.util.function.Consumer; @Environment(EnvType.CLIENT) public class FoodCannerScreen extends MachineScreen { @@ -54,6 +47,7 @@ public FoodCannerScreen(FoodCannerMenu handler, Inventory inv, Component title) private void drawProgressBar(PoseStack matrices) { if (this.menu.state.isActive()) { int progress = this.menu.getProgress(); + System.out.println(progress); if (inBounds(progress, 1, 9)) { //transferring can diff --git a/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/OxygenSealerScreen.java b/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/OxygenSealerScreen.java index a924a00ee..05ccdd579 100644 --- a/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/OxygenSealerScreen.java +++ b/src/main/java/dev/galacticraft/mod/client/gui/screen/ingame/OxygenSealerScreen.java @@ -49,8 +49,8 @@ protected void renderForeground(GuiGraphics graphics, int mouseX, int mouseY, fl MachineStatus status = this.menu.state.getStatus(); graphics.drawString(this.font, Component.translatable(Translations.Ui.MACHINE_STATUS).append(status != null ? status.getText() : Component.empty()), this.leftPos + 50, this.topPos + 30, ChatFormatting.DARK_GRAY.getColor(), false); if (!status.equals(GCMachineStatuses.BLOCKED)) { - int insideArea = this.menu.machine.getInsideArea(); - int outsideArea = this.menu.machine.getOutsideArea(); + int insideArea = this.menu.be.getInsideArea(); + int outsideArea = this.menu.be.getOutsideArea(); graphics.drawString(this.font, Component.literal("INSIDE AREA: ").append(String.valueOf(insideArea)), this.leftPos + 50, this.topPos + 50, ChatFormatting.DARK_GRAY.getColor(), false); graphics.drawString(this.font, Component.literal("OUTSIDE AREA: ").append(String.valueOf(outsideArea)), this.leftPos + 50, this.topPos + 70, ChatFormatting.DARK_GRAY.getColor(), false); } diff --git a/src/main/java/dev/galacticraft/mod/client/render/dimension/AsteroidSkyRenderer.java b/src/main/java/dev/galacticraft/mod/client/render/dimension/AsteroidSkyRenderer.java index 6ca4ec6c6..8be3deb56 100644 --- a/src/main/java/dev/galacticraft/mod/client/render/dimension/AsteroidSkyRenderer.java +++ b/src/main/java/dev/galacticraft/mod/client/render/dimension/AsteroidSkyRenderer.java @@ -51,16 +51,16 @@ public void render(WorldRenderContext context) { RenderSystem.disableBlend(); RenderSystem.depthMask(false); - final PoseStack matrices = context.matrixStack(); - final BufferBuilder buffer = Tesselator.getInstance().getBuilder(); + PoseStack matrices = new PoseStack(); + matrices.mulPose(context.positionMatrix()); context.profiler().push("stars"); matrices.pushPose(); - matrices.mulPose(Axis.YP.rotationDegrees((context.world().getTimeOfDay(context.tickDelta()) * 360.0f) - 90F)); - matrices.mulPose(Axis.XP.rotationDegrees(context.world().getTimeOfDay(context.tickDelta()) * 360.0f)); + matrices.mulPose(Axis.YP.rotationDegrees((context.world().getTimeOfDay(context.tickCounter().getRealtimeDeltaTicks()) * 360.0f) - 90F)); + matrices.mulPose(Axis.XP.rotationDegrees((context.world().getTimeOfDay(context.tickCounter().getRealtimeDeltaTicks())) * 360.0f)); matrices.mulPose(Axis.YP.rotationDegrees(-19.0F)); - this.starManager.render(context.matrixStack(), context.projectionMatrix(), context.world(), context.tickDelta()); + this.starManager.render(matrices, context.projectionMatrix(), context.world(), context.tickCounter().getRealtimeDeltaTicks()); matrices.popPose(); context.profiler().pop(); @@ -69,19 +69,19 @@ public void render(WorldRenderContext context) { matrices.pushPose(); matrices.mulPose(Axis.YP.rotationDegrees(-90.0F)); - matrices.mulPose(Axis.XP.rotationDegrees(context.world().getTimeOfDay(context.tickDelta()) * 360.0f)); + matrices.mulPose(Axis.XP.rotationDegrees(context.world().getTimeOfDay(context.tickCounter().getRealtimeDeltaTicks()) * 360.0f)); Matrix4f matrix = matrices.last().pose(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); float size = 6.0F; RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderTexture(0, SUN_TEXTURE); - buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - buffer.vertex(matrix, -size, 100.0F, -size).uv(0.0F, 0.0F).endVertex(); - buffer.vertex(matrix, size, 100.0F, -size).uv(1.0F, 0.0F).endVertex(); - buffer.vertex(matrix, size, 100.0F, size).uv(1.0F, 1.0F).endVertex(); - buffer.vertex(matrix, -size, 100.0F, size).uv(0.0F, 1.0F).endVertex(); - BufferUploader.drawWithShader(buffer.end()); + BufferBuilder buffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); + buffer.addVertex(matrix, -size, 100.0F, -size).setUv(0.0F, 0.0F) + .addVertex(matrix, size, 100.0F, -size).setUv(1.0F, 0.0F) + .addVertex(matrix, size, 100.0F, size).setUv(1.0F, 1.0F) + .addVertex(matrix, -size, 100.0F, size).setUv(0.0F, 1.0F); + BufferUploader.drawWithShader(buffer.buildOrThrow()); matrices.popPose(); context.profiler().pop(); @@ -94,17 +94,17 @@ public void render(WorldRenderContext context) { assert Minecraft.getInstance().player != null; float earthRotation = (float) (context.world().getSharedSpawnPos().getZ() - Minecraft.getInstance().player.getZ()) * 0.01F; matrices.scale(0.6F, 0.6F, 0.6F); - matrices.mulPose(Axis.XP.rotationDegrees((context.world().getTimeOfDay(context.tickDelta()) * 360.0F) * 0.001F)); + matrices.mulPose(Axis.XP.rotationDegrees((context.world().getTimeOfDay(context.tickCounter().getRealtimeDeltaTicks()) * 360.0F) * 0.001F)); matrices.mulPose(Axis.XP.rotationDegrees(earthRotation + 200.0F)); RenderSystem.setShaderTexture(0, EARTH_TEXTURE); - buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - buffer.vertex(matrix, -size, -100.0F, size).uv(0.0F, 1.0F).endVertex(); - buffer.vertex(matrix, size, -100.0F, size).uv(1.0F, 1.0F).endVertex(); - buffer.vertex(matrix, size, -100.0F, -size).uv(1.0F, 0.0F).endVertex(); - buffer.vertex(matrix, -size, -100.0F, -size).uv(0.0F, 0.0F).endVertex(); - BufferUploader.drawWithShader(buffer.end()); + buffer = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); + buffer.addVertex(matrix, -size, -100.0F, size).setUv(0.0F, 1.0F) + .addVertex(matrix, size, -100.0F, size).setUv(1.0F, 1.0F) + .addVertex(matrix, size, -100.0F, -size).setUv(1.0F, 0.0F) + .addVertex(matrix, -size, -100.0F, -size).setUv(0.0F, 0.0F); + BufferUploader.drawWithShader(buffer.buildOrThrow()); context.profiler().pop(); matrices.popPose(); diff --git a/src/main/java/dev/galacticraft/mod/compat/AppleSkinEventHandler.java b/src/main/java/dev/galacticraft/mod/compat/AppleSkinEventHandler.java index 12ac89939..ae4c88b23 100644 --- a/src/main/java/dev/galacticraft/mod/compat/AppleSkinEventHandler.java +++ b/src/main/java/dev/galacticraft/mod/compat/AppleSkinEventHandler.java @@ -25,7 +25,6 @@ import net.minecraft.world.food.FoodProperties; import squeek.appleskin.api.AppleSkinApi; import squeek.appleskin.api.event.FoodValuesEvent; -import squeek.appleskin.api.food.FoodValues; import static dev.galacticraft.mod.content.item.CannedFoodItem.getCanFoodProperties; import static dev.galacticraft.mod.content.item.CannedFoodItem.isCannedFoodItem; @@ -41,7 +40,7 @@ public void registerEvents() { FoodProperties foodProperties = getCanFoodProperties(foodValuesEvent.itemStack); if (foodProperties != null) { - foodValuesEvent.modifiedFoodValues = new FoodValues(foodProperties.getNutrition(), foodProperties.getSaturationModifier()); + foodValuesEvent.modifiedFoodComponent = foodProperties; } } }); diff --git a/src/main/java/dev/galacticraft/mod/content/ClientCannedFoodTooltip.java b/src/main/java/dev/galacticraft/mod/content/ClientCannedFoodTooltip.java index 429d599d2..f8365f552 100644 --- a/src/main/java/dev/galacticraft/mod/content/ClientCannedFoodTooltip.java +++ b/src/main/java/dev/galacticraft/mod/content/ClientCannedFoodTooltip.java @@ -22,6 +22,7 @@ package dev.galacticraft.mod.content; +import dev.galacticraft.mod.Constant; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.Font; @@ -34,18 +35,20 @@ import net.minecraft.world.inventory.tooltip.BundleTooltip; import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.component.BundleContents; +import org.apache.commons.lang3.math.Fraction; @Environment(EnvType.CLIENT) public class ClientCannedFoodTooltip implements ClientTooltipComponent { - private static final ResourceLocation BACKGROUND_SPRITE = new ResourceLocation("container/bundle/background"); + private static final ResourceLocation BACKGROUND_SPRITE = ResourceLocation.withDefaultNamespace("container/bundle/background"); private static final int MARGIN_Y = 4; private static final int BORDER_WIDTH = 1; private static final int SLOT_SIZE_X = 18; private static final int SLOT_SIZE_Y = 20; - private final NonNullList items; + private final NonNullList contents; public ClientCannedFoodTooltip(CannedFoodTooltip cannedFoodTooltip) { - this.items = cannedFoodTooltip.getItems(); + this.contents = cannedFoodTooltip.getItems(); } public int getHeight() { @@ -67,10 +70,8 @@ private int backgroundHeight() { public void renderImage(Font textRenderer, int x, int y, GuiGraphics context) { int i = this.gridSizeX(); int j = this.gridSizeY(); - //creates a background panel over the items //context.blitSprite(BACKGROUND_SPRITE, x, y, this.backgroundWidth(), this.backgroundHeight()); - int weight = 1; - boolean bl = weight >= 64; + boolean bl = true; int k = 0; for(int l = 0; l < j; ++l) { @@ -84,12 +85,12 @@ public void renderImage(Font textRenderer, int x, int y, GuiGraphics context) { } private void renderSlot(int x, int y, int index, boolean shouldBlock, GuiGraphics context, Font textRenderer) { - if (index >= this.items.size()) { + if (index >= this.contents.size()) { //creates a ending slot used for bundle not items contained //this.blit(context, x, y, shouldBlock ? ClientCannedFoodTooltip.Texture.BLOCKED_SLOT : ClientCannedFoodTooltip.Texture.SLOT); } else { - ItemStack itemStack = (ItemStack)this.items.get(index); - this.blit(context, x, y, ClientCannedFoodTooltip.Texture.SLOT); + ItemStack itemStack = this.contents.get(index); + this.blit(context, x, y, Texture.SLOT); context.renderItem(itemStack, x + 1, y + 1, index); context.renderItemDecorations(textRenderer, itemStack, x + 1, y + 1); //used to highlight the item slot @@ -97,35 +98,35 @@ private void renderSlot(int x, int y, int index, boolean shouldBlock, GuiGraphic // if (index == 0) { // AbstractContainerScreen.renderSlotHighlight(context, x + 1, y + 1, 0); // } - } } - private void blit(GuiGraphics context, int x, int y, ClientCannedFoodTooltip.Texture sprite) { + private void blit(GuiGraphics context, int x, int y, Texture sprite) { context.blitSprite(sprite.sprite, x, y, 0, sprite.w, sprite.h); } private int gridSizeX() { - return Math.max(2, (int)Math.ceil(Math.sqrt((double)this.items.size() + 1.0))); + return Math.max(2, (int)Math.ceil(Math.sqrt((double)this.contents.size() + 1.0))); } private int gridSizeY() { - return (int)Math.ceil(((double)this.items.size() + 1.0) / (double)this.gridSizeX()); + return (int)Math.ceil(((double)this.contents.size() + 1.0) / (double)this.gridSizeX()); } @Environment(EnvType.CLIENT) private static enum Texture { - BLOCKED_SLOT(new ResourceLocation("container/bundle/blocked_slot"), 18, 20), - SLOT(new ResourceLocation("container/bundle/slot"), 18, 20); + BLOCKED_SLOT(ResourceLocation.withDefaultNamespace("container/bundle/blocked_slot"), 18, 20), + SLOT(ResourceLocation.withDefaultNamespace("container/bundle/slot"), 18, 20); public final ResourceLocation sprite; public final int w; public final int h; - private Texture(ResourceLocation resourceLocation, int j, int k) { + private Texture(final ResourceLocation resourceLocation, final int j, final int k) { this.sprite = resourceLocation; this.w = j; this.h = k; } + } } diff --git a/src/main/java/dev/galacticraft/mod/content/GCChunkGenerator.java b/src/main/java/dev/galacticraft/mod/content/GCChunkGenerator.java index 21caff80a..40b47d9ec 100644 --- a/src/main/java/dev/galacticraft/mod/content/GCChunkGenerator.java +++ b/src/main/java/dev/galacticraft/mod/content/GCChunkGenerator.java @@ -23,14 +23,11 @@ package dev.galacticraft.mod.content; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import dev.galacticraft.mod.Constant; import dev.galacticraft.mod.world.gen.custom.AsteroidChunkGenerator; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.chunk.ChunkGenerator; @@ -38,9 +35,9 @@ public class GCChunkGenerator { public static final GCChunkGeneratorRegistry CHUNK_GENERATOR = new GCChunkGeneratorRegistry(); - public static final Codec ASTEROID = CHUNK_GENERATOR.register("asteroid_chunk_generator", AsteroidChunkGenerator.CODEC); + public static final MapCodec ASTEROID = CHUNK_GENERATOR.register("asteroid_chunk_generator", AsteroidChunkGenerator.CODEC); - public static Codec register(String id, Codec codec) { + public static MapCodec register(String id, MapCodec codec) { return Registry.register(BuiltInRegistries.CHUNK_GENERATOR, Constant.id(id), codec); } diff --git a/src/main/java/dev/galacticraft/mod/content/GCChunkGeneratorRegistry.java b/src/main/java/dev/galacticraft/mod/content/GCChunkGeneratorRegistry.java index bbd57ce8f..e4a830249 100644 --- a/src/main/java/dev/galacticraft/mod/content/GCChunkGeneratorRegistry.java +++ b/src/main/java/dev/galacticraft/mod/content/GCChunkGeneratorRegistry.java @@ -23,10 +23,11 @@ package dev.galacticraft.mod.content; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.level.chunk.ChunkGenerator; -public class GCChunkGeneratorRegistry extends GCRegistry> { +public class GCChunkGeneratorRegistry extends GCRegistry> { public GCChunkGeneratorRegistry() { super(BuiltInRegistries.CHUNK_GENERATOR); } diff --git a/src/main/java/dev/galacticraft/mod/content/block/entity/machine/FoodCannerBlockEntity.java b/src/main/java/dev/galacticraft/mod/content/block/entity/machine/FoodCannerBlockEntity.java index 3c5bb843f..aae4a87bb 100644 --- a/src/main/java/dev/galacticraft/mod/content/block/entity/machine/FoodCannerBlockEntity.java +++ b/src/main/java/dev/galacticraft/mod/content/block/entity/machine/FoodCannerBlockEntity.java @@ -22,30 +22,36 @@ package dev.galacticraft.mod.content.block.entity.machine; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.galacticraft.api.component.GCDataComponents; import dev.galacticraft.api.gas.Gases; import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity; +import dev.galacticraft.machinelib.api.filter.ResourceFilters; import dev.galacticraft.machinelib.api.machine.MachineStatus; import dev.galacticraft.machinelib.api.machine.MachineStatuses; import dev.galacticraft.machinelib.api.menu.MachineMenu; +import dev.galacticraft.machinelib.api.storage.MachineEnergyStorage; +import dev.galacticraft.machinelib.api.storage.MachineFluidStorage; +import dev.galacticraft.machinelib.api.storage.MachineItemStorage; +import dev.galacticraft.machinelib.api.storage.StorageSpec; import dev.galacticraft.machinelib.api.storage.slot.FluidResourceSlot; import dev.galacticraft.machinelib.api.storage.slot.ItemResourceSlot; -import dev.galacticraft.machinelib.impl.compat.vanilla.StorageSlot; +import dev.galacticraft.machinelib.api.transfer.TransferType; import dev.galacticraft.mod.Constant; import dev.galacticraft.mod.Galacticraft; -import dev.galacticraft.mod.content.GCMachineTypes; +import dev.galacticraft.mod.content.GCBlockEntityTypes; import dev.galacticraft.mod.content.item.CannedFoodItem; import dev.galacticraft.mod.content.item.GCItems; import dev.galacticraft.mod.machine.GCMachineStatuses; -import dev.galacticraft.mod.screen.CoalGeneratorMenu; +import dev.galacticraft.mod.network.s2c.BubbleUpdatePayload; import dev.galacticraft.mod.screen.FoodCannerMenu; -import dev.galacticraft.mod.util.FluidUtil; -import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; -import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; -import net.fabricmc.fabric.api.transfer.v1.storage.Storage; -import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import dev.galacticraft.mod.screen.GCMenuTypes; +import dev.galacticraft.mod.screen.OxygenBubbleDistributorMenu; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.*; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.profiling.ProfilerFiller; @@ -54,6 +60,7 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.CustomData; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,7 +69,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.stream.Stream; import static dev.galacticraft.mod.content.item.CannedFoodItem.*; @@ -101,16 +107,87 @@ public class FoodCannerBlockEntity extends MachineBlockEntity { private ItemStack storage; + private static final StorageSpec SPEC = StorageSpec.of( + MachineItemStorage.spec( + ItemResourceSlot.builder(TransferType.TRANSFER) + .pos(8, 67) + .filter(ResourceFilters.CAN_EXTRACT_ENERGY), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(62, 13) + .filter(ResourceFilters.ofResource(GCItems.EMPTY_CANNED_FOOD)), + ItemResourceSlot.builder(TransferType.STORAGE) + .pos(62, 40) + .capacity(1) + .filter(ResourceFilters.ofResource(GCItems.EMPTY_CANNED_FOOD)), + ItemResourceSlot.builder(TransferType.OUTPUT) + .pos(62, 67), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(98, 13) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(116, 13) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(134, 13) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(152, 13) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(98, 31) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(116, 31) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(134, 31) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(152, 31) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(98, 49) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(116, 49) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(134, 49) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(152, 49) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(98, 67) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(116, 67) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(134, 67) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)), + ItemResourceSlot.builder(TransferType.INPUT) + .pos(152, 67) + .filter((item, tag) -> item != null && item.components().has(DataComponents.FOOD) && !(item instanceof CannedFoodItem)) + ), + MachineEnergyStorage.spec( + Galacticraft.CONFIG.machineEnergyStorageSize(), + Galacticraft.CONFIG.oxygenCollectorEnergyConsumptionRate() * 2, + 0 + ) + ); public FoodCannerBlockEntity(BlockPos pos, BlockState state) { - super(GCMachineTypes.FOOD_CANNER, pos, state); + super(GCBlockEntityTypes.FOOD_CANNER, pos, state, SPEC); this.storage = GCItems.CANNED_FOOD.getDefaultInstance(); } @Override protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ProfilerFiller profiler) { super.tickConstant(world, pos, state, profiler); - this.chargeFromStack(CHARGE_SLOT); + profiler.push("extract_resources"); + this.chargeFromSlot(CHARGE_SLOT); + profiler.pop(); } @Override @@ -133,7 +210,7 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ if (getProgress() == 1 && !transferring_can) { this.transferring_can = true; - this.itemStorage().getSlot(INPUT_SLOT).extractOne(); + this.itemStorage().slot(INPUT_SLOT).extractOne(); return GCMachineStatuses.TRANSFERRING_CAN; } if (getProgress() == 10) @@ -143,12 +220,12 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ if (transferring_food) { this.transferring_can = false; - this.itemStorage().getSlot(STORAGE_SLOT).insert(this.storage.getItem(), this.storage.getTag(), 1); + this.itemStorage().slot(STORAGE_SLOT).insert(this.storage.getItem(), this.storage.getComponentsPatch(), 1); } else { this.transferring_can = false; - this.itemStorage().getSlot(STORAGE_SLOT).insert(GCItems.CANNED_FOOD, 1); + this.itemStorage().slot(STORAGE_SLOT).insert(GCItems.CANNED_FOOD, 1); this.storage = GCItems.CANNED_FOOD.getDefaultInstance(); } } @@ -201,7 +278,7 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ } if (getProgress() == 37) { - if (this.itemStorage().getSlot(STORAGE_SLOT).isEmpty() && transferring_food) + if (this.itemStorage().slot(STORAGE_SLOT).isEmpty() && transferring_food) { setProgress(1); return GCMachineStatuses.MISSING_EMPTY_CAN; @@ -235,7 +312,7 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ } if (getProgress() == 53) { - if (this.itemStorage().getSlot(STORAGE_SLOT).isEmpty() && transferring_food) + if (this.itemStorage().slot(STORAGE_SLOT).isEmpty() && transferring_food) { setProgress(1); return GCMachineStatuses.MISSING_EMPTY_CAN; @@ -260,7 +337,7 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ } if (getProgress() == 79) { - if (this.itemStorage().getSlot(STORAGE_SLOT).isEmpty() && transferring_food) + if (this.itemStorage().slot(STORAGE_SLOT).isEmpty() && transferring_food) { setProgress(1); return GCMachineStatuses.MISSING_EMPTY_CAN; @@ -303,7 +380,7 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ if (getProgress() == 107) { - if (this.itemStorage().getSlot(STORAGE_SLOT).isEmpty() && transferring_food) + if (this.itemStorage().slot(STORAGE_SLOT).isEmpty() && transferring_food) { setProgress(1); resetConsumedRows(); @@ -321,8 +398,8 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ } if (this.itemStorage().getItem(STORAGE_SLOT) != this.storage) { - this.itemStorage().getSlot(STORAGE_SLOT).extractOne(); - this.itemStorage().getSlot(STORAGE_SLOT).insert(this.storage.getItem(), this.storage.getTag(), 1); + this.itemStorage().slot(STORAGE_SLOT).extractOne(); + this.itemStorage().slot(STORAGE_SLOT).insert(this.storage.getItem(), this.storage.getComponentsPatch(), 1); } if (getSize(this.storage) < MAX_FOOD && (row0 || row1 || row2 || row3)) { @@ -333,13 +410,13 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ return MachineStatuses.OUTPUT_FULL; } transferring_can = true; - this.itemStorage().getSlot(STORAGE_SLOT).extractOne(); + this.itemStorage().slot(STORAGE_SLOT).extractOne(); return GCMachineStatuses.TRANSFERRING_CAN; } if (getProgress() == 115 && transferring_can) { transferring_can = false; - this.itemStorage().getSlot(OUTPUT_SLOT).insert(this.storage.getItem(), this.storage.getTag(), 1); + this.itemStorage().slot(OUTPUT_SLOT).insert(this.storage.getItem(), this.storage.getComponentsPatch(), 1); this.storage = GCItems.CANNED_FOOD.getDefaultInstance(); resetConsumedRows(); setProgress(1); @@ -357,15 +434,15 @@ private void resetConsumedRows() { } private boolean storageContainsFood() { - return getContents(this.storage).findAny().isPresent(); + return !getContents(this.storage).isEmpty(); } private boolean inputSlotEmpty() { - return this.itemStorage().getSlot(INPUT_SLOT).isEmpty(); + return this.itemStorage().slot(INPUT_SLOT).isEmpty(); } private boolean storageSlotEmpty() { - return this.itemStorage().getSlot(STORAGE_SLOT).isEmpty(); + return this.itemStorage().slot(STORAGE_SLOT).isEmpty(); } private boolean noEnergy() { @@ -373,69 +450,69 @@ private boolean noEnergy() { } private boolean outputFull() { - return this.itemStorage().getSlot(OUTPUT_SLOT).isFull(); + return this.itemStorage().slot(OUTPUT_SLOT).isFull(); } private void clearRow(int row) { if (row == 0) { - this.itemStorage().getSlot(FOOD_INPUT_SLOT_1).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_1).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_2).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_2).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_3).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_3).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_4).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_4).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_1).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_1).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_2).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_2).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_3).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_3).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_4).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_4).getCount()); } if (row == 1) { - this.itemStorage().getSlot(FOOD_INPUT_SLOT_5).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_5).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_6).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_6).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_7).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_7).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_8).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_8).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_5).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_5).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_6).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_6).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_7).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_7).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_8).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_8).getCount()); } if (row == 2) { - this.itemStorage().getSlot(FOOD_INPUT_SLOT_9).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_9).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_10).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_10).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_11).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_11).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_12).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_12).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_9).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_9).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_10).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_10).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_11).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_11).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_12).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_12).getCount()); } if (row == 3) { - this.itemStorage().getSlot(FOOD_INPUT_SLOT_13).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_13).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_14).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_14).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_15).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_15).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_16).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_16).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_13).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_13).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_14).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_14).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_15).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_15).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_16).extract(this.itemStorage().getItem(FOOD_INPUT_SLOT_16).getCount()); } } private void clearRow(int row, List stacks) { clearRow(row); if (row == 0) { - this.itemStorage().getSlot(FOOD_INPUT_SLOT_1).insert(stacks.get(0).getItem(), stacks.get(0).getTag(), stacks.get(0).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_2).insert(stacks.get(1).getItem(), stacks.get(1).getTag(), stacks.get(1).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_3).insert(stacks.get(2).getItem(), stacks.get(2).getTag(), stacks.get(2).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_4).insert(stacks.get(3).getItem(), stacks.get(3).getTag(), stacks.get(3).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_1).insert(stacks.get(0).getItem(), stacks.get(0).getComponentsPatch(), stacks.get(0).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_2).insert(stacks.get(1).getItem(), stacks.get(1).getComponentsPatch(), stacks.get(1).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_3).insert(stacks.get(2).getItem(), stacks.get(2).getComponentsPatch(), stacks.get(2).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_4).insert(stacks.get(3).getItem(), stacks.get(3).getComponentsPatch(), stacks.get(3).getCount()); } if (row == 1) { - this.itemStorage().getSlot(FOOD_INPUT_SLOT_5).insert(stacks.get(0).getItem(), stacks.get(0).getTag(), stacks.get(0).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_6).insert(stacks.get(1).getItem(), stacks.get(1).getTag(), stacks.get(1).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_7).insert(stacks.get(2).getItem(), stacks.get(2).getTag(), stacks.get(2).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_8).insert(stacks.get(3).getItem(), stacks.get(3).getTag(), stacks.get(3).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_5).insert(stacks.get(0).getItem(), stacks.get(0).getComponentsPatch(), stacks.get(0).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_6).insert(stacks.get(1).getItem(), stacks.get(1).getComponentsPatch(), stacks.get(1).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_7).insert(stacks.get(2).getItem(), stacks.get(2).getComponentsPatch(), stacks.get(2).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_8).insert(stacks.get(3).getItem(), stacks.get(3).getComponentsPatch(), stacks.get(3).getCount()); } if (row == 2) { - this.itemStorage().getSlot(FOOD_INPUT_SLOT_9).insert(stacks.get(0).getItem(), stacks.get(0).getTag(), stacks.get(0).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_10).insert(stacks.get(1).getItem(), stacks.get(1).getTag(), stacks.get(1).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_11).insert(stacks.get(2).getItem(), stacks.get(2).getTag(), stacks.get(2).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_12).insert(stacks.get(3).getItem(), stacks.get(3).getTag(), stacks.get(3).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_9).insert(stacks.get(0).getItem(), stacks.get(0).getComponentsPatch(), stacks.get(0).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_10).insert(stacks.get(1).getItem(), stacks.get(1).getComponentsPatch(), stacks.get(1).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_11).insert(stacks.get(2).getItem(), stacks.get(2).getComponentsPatch(), stacks.get(2).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_12).insert(stacks.get(3).getItem(), stacks.get(3).getComponentsPatch(), stacks.get(3).getCount()); } if (row == 3) { - this.itemStorage().getSlot(FOOD_INPUT_SLOT_13).insert(stacks.get(0).getItem(), stacks.get(0).getTag(), stacks.get(0).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_14).insert(stacks.get(1).getItem(), stacks.get(1).getTag(), stacks.get(1).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_15).insert(stacks.get(2).getItem(), stacks.get(2).getTag(), stacks.get(2).getCount()); - this.itemStorage().getSlot(FOOD_INPUT_SLOT_16).insert(stacks.get(3).getItem(), stacks.get(3).getTag(), stacks.get(3).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_13).insert(stacks.get(0).getItem(), stacks.get(0).getComponentsPatch(), stacks.get(0).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_14).insert(stacks.get(1).getItem(), stacks.get(1).getComponentsPatch(), stacks.get(1).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_15).insert(stacks.get(2).getItem(), stacks.get(2).getComponentsPatch(), stacks.get(2).getCount()); + this.itemStorage().slot(FOOD_INPUT_SLOT_16).insert(stacks.get(3).getItem(), stacks.get(3).getComponentsPatch(), stacks.get(3).getCount()); } } @@ -444,28 +521,28 @@ private List checkRow(int row) List stacks = new ArrayList<>(); if (row == 0) { - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_1).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_1).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_1)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_2).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_2).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_2)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_3).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_3).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_3)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_4).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_4).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_4)); }else @@ -475,28 +552,28 @@ private List checkRow(int row) } if (row == 1) { - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_5).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_5).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_5)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_6).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_6).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_6)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_7).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_7).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_7)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_8).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_8).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_8)); }else @@ -506,28 +583,28 @@ private List checkRow(int row) } if (row == 2) { - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_9).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_9).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_9)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_10).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_10).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_10)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_11).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_11).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_11)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_12).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_12).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_12)); }else @@ -537,28 +614,28 @@ private List checkRow(int row) } if (row == 3) { - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_13).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_13).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_13)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_14).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_14).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_14)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_15).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_15).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_15)); }else { stacks.add(Items.AIR.getDefaultInstance()); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_16).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_16).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_16)); }else @@ -574,76 +651,76 @@ private List checkRowItems(int row) List stacks = new ArrayList<>(); if (row == 0) { - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_1).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_1).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_1)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_2).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_2).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_2)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_3).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_3).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_3)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_4).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_4).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_4)); } } if (row == 1) { - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_5).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_5).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_5)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_6).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_6).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_6)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_7).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_7).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_7)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_8).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_8).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_8)); } } if (row == 2) { - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_9).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_9).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_9)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_10).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_10).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_10)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_11).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_11).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_11)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_12).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_12).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_12)); } } if (row == 3) { - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_13).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_13).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_13)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_14).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_14).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_14)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_15).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_15).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_15)); } - if (!this.itemStorage().getSlot(FOOD_INPUT_SLOT_16).isEmpty()) + if (!this.itemStorage().slot(FOOD_INPUT_SLOT_16).isEmpty()) { stacks.add(this.itemStorage().getItem(FOOD_INPUT_SLOT_16)); } @@ -668,33 +745,32 @@ public void setProgress(int progress) { this.progress = progress; } - @Nullable @Override - public AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) { + public @Nullable MachineMenu createMenu(int syncId, Inventory inv, Player player) { if (this.getSecurity().hasAccess(player)) return new FoodCannerMenu(syncId, (ServerPlayer) player, this); return null; } @Override - public void load(CompoundTag nbt) { - super.load(nbt); - setProgress(nbt.getInt(Constant.Nbt.PROGRESS)); - this.transferring_can = nbt.getBoolean("TRANSFERRING_CAN"); - this.transferring_food = nbt.getBoolean("TRANSFERRING_FOOD"); + public void loadAdditional(CompoundTag tag, HolderLookup.Provider lookup) { + super.loadAdditional(tag, lookup); + setProgress(tag.getInt(Constant.Nbt.PROGRESS)); + this.transferring_can = tag.getBoolean("TRANSFERRING_CAN"); + this.transferring_food = tag.getBoolean("TRANSFERRING_FOOD"); ItemStack itemStack = GCItems.CANNED_FOOD.getDefaultInstance(); - itemStack.setTag(listTagToCompoundTag(nbt.getList("STORAGE", ListTag.TAG_COMPOUND))); + itemStack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(listTagToCompoundTag(tag.getList("STORAGE", ListTag.TAG_COMPOUND)))); this.storage = itemStack; } @Override - public void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); + public void saveAdditional(CompoundTag tag, HolderLookup.Provider lookup) { + super.saveAdditional(tag, lookup); tag.putInt(Constant.Nbt.PROGRESS, this.progress); tag.putBoolean("TRANSFERRING_CAN", this.transferring_can); tag.putBoolean("TRANSFERRING_FOOD", this.transferring_food); - tag.put("STORAGE", compoundTagToListTag(this.storage.getTag())); + tag.put("STORAGE", compoundTagToListTag(Objects.requireNonNull(this.storage.get(DataComponents.BLOCK_ENTITY_DATA)).copyTag())); } public static CompoundTag listTagToCompoundTag(ListTag listTag) { diff --git a/src/main/java/dev/galacticraft/mod/content/block/entity/machine/OxygenSealerBlockEntity.java b/src/main/java/dev/galacticraft/mod/content/block/entity/machine/OxygenSealerBlockEntity.java index a17834bb2..89bbf4413 100644 --- a/src/main/java/dev/galacticraft/mod/content/block/entity/machine/OxygenSealerBlockEntity.java +++ b/src/main/java/dev/galacticraft/mod/content/block/entity/machine/OxygenSealerBlockEntity.java @@ -60,6 +60,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.HashSet; +import java.util.Objects; import java.util.Set; public class OxygenSealerBlockEntity extends MachineBlockEntity { @@ -109,7 +111,7 @@ public void setLevel(Level world) { this.sealCheckTime = SEAL_CHECK_TIME; Holder> holder = world.galacticraft$getCelestialBody(); this.oxygenWorld = holder == null || holder.value().atmosphere().breathable(); - if (!world.isClientSide) ((ServerLevelAccessor) world).addSealer(this); + if (!world.isClientSide) ((ServerLevelAccessor) world).addSealer(this, Objects.requireNonNull(world.getServer()).getLevel(world.dimension())); this.outputBlocked = false; } @@ -126,7 +128,7 @@ protected void tickConstant(@NotNull ServerLevel world, @NotNull BlockPos pos, @ protected @NotNull MachineStatus tick(@NotNull ServerLevel level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull ProfilerFiller profiler) { assert level != null; if (this.energyStorage().canExtract(Galacticraft.CONFIG.oxygenCompressorEnergyConsumptionRate())) { - if (!this.fluidStorage().getSlot(OXYGEN_TANK).isEmpty()) { + if (!this.fluidStorage().slot(OXYGEN_TANK).isEmpty()) { if (this.sealCheckTime > 0) this.sealCheckTime--; if (this.sealCheckTime == 0) { diff --git a/src/main/java/dev/galacticraft/mod/content/block/machine/OxygenSealerBlock.java b/src/main/java/dev/galacticraft/mod/content/block/machine/OxygenSealerBlock.java index 694335333..486c2d152 100644 --- a/src/main/java/dev/galacticraft/mod/content/block/machine/OxygenSealerBlock.java +++ b/src/main/java/dev/galacticraft/mod/content/block/machine/OxygenSealerBlock.java @@ -22,20 +22,41 @@ package dev.galacticraft.mod.content.block.machine; +import com.mojang.serialization.MapCodec; import dev.galacticraft.machinelib.api.block.MachineBlock; +import dev.galacticraft.machinelib.api.block.entity.MachineBlockEntity; import dev.galacticraft.mod.Constant; +import dev.galacticraft.mod.content.block.entity.machine.CoalGeneratorBlockEntity; import dev.galacticraft.mod.content.block.entity.machine.OxygenCollectorBlockEntity; import dev.galacticraft.mod.content.block.entity.machine.OxygenSealerBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.DustParticleOptions; import net.minecraft.util.RandomSource; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; -public class OxygenSealerBlock extends MachineBlock { +public class OxygenSealerBlock extends MachineBlock { + private static final MapCodec CODEC = simpleCodec(OxygenSealerBlock::new); + + + public OxygenSealerBlock(Properties settings) { - super(settings, Constant.id(Constant.Block.OXYGEN_SEALER)); + super(settings); + } + + @Override + protected @NotNull MapCodec codec() { + return CODEC; + } + + + @Override + public @NotNull MachineBlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new OxygenSealerBlockEntity(pos, state); } @Override diff --git a/src/main/java/dev/galacticraft/mod/content/entity/SmallAsteroid.java b/src/main/java/dev/galacticraft/mod/content/entity/SmallAsteroid.java deleted file mode 100644 index b29f6fd7b..000000000 --- a/src/main/java/dev/galacticraft/mod/content/entity/SmallAsteroid.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2019-2024 Team Galacticraft - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package dev.galacticraft.mod.content.entity; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.level.Level; - -public class SmallAsteroid extends Entity { - - //private static final DataParameter SPIN_PITCH = EntityDataManager.createKey(EntitySmallAsteroid.class, DataSerializers.FLOAT); - //private static final DataParameter SPIN_YAW = EntityDataManager.createKey(EntitySmallAsteroid.class, DataSerializers.FLOAT); - //private static final DataParameter ASTEROID_TYPE = EntityDataManager.createKey(EntitySmallAsteroid.class, DataSerializers.VARINT); - public float spinPitch; - public float spinYaw; - public int type; - private boolean firstUpdate = true; - public SmallAsteroid(EntityType entityType, Level level) { - super(entityType, level); - } - - @Override - protected void defineSynchedData() { - - } - - @Override - protected void readAdditionalSaveData(CompoundTag nbt) { - - } - - @Override - protected void addAdditionalSaveData(CompoundTag nbt) { - - } -} diff --git a/src/main/java/dev/galacticraft/mod/content/item/CannedFoodItem.java b/src/main/java/dev/galacticraft/mod/content/item/CannedFoodItem.java index 8a86c05d4..0c78aa231 100644 --- a/src/main/java/dev/galacticraft/mod/content/item/CannedFoodItem.java +++ b/src/main/java/dev/galacticraft/mod/content/item/CannedFoodItem.java @@ -29,8 +29,11 @@ import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.ChatFormatting; import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.advancements.critereon.ItemContainerPredicate; import net.minecraft.client.Minecraft; import net.minecraft.core.NonNullList; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -47,6 +50,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.component.ItemContainerContents; import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -74,20 +78,19 @@ public class CannedFoodItem extends Item implements FabricItemStack { if (!level.isClientSide) { int consumingItems = getItemsToBeConsumed(itemStack); - assert itemStack.getTag() != null; - CompoundTag copyTag = itemStack.getTag().copy(); + DataComponentMap components = itemStack.getComponents(); super.finishUsingItem(itemStack, level, livingEntity); if (livingEntity instanceof ServerPlayer serverPlayer) { CriteriaTriggers.CONSUME_ITEM.trigger(serverPlayer, itemStack); serverPlayer.awardStat(Stats.ITEM_USED.get(this)); } ItemStack can = new ItemStack(CANNED_FOOD); - can.setTag(copyTag.copy()); + can.applyComponents(components); for (int i = 0; i < consumingItems; i++) { removeOne(can); } if (itemStack.isEmpty()) { - if (getContents(can).findAny().isEmpty()) + if (getContents(can).isEmpty()) { can = new ItemStack(EMPTY_CANNED_FOOD); } @@ -97,7 +100,7 @@ public class CannedFoodItem extends Item implements FabricItemStack { if (livingEntity instanceof Player player) { if (!player.getAbilities().instabuild) { - if (getContents(can).findAny().isEmpty()) + if (getContents(can).isEmpty()) { can = new ItemStack(EMPTY_CANNED_FOOD); } @@ -133,12 +136,12 @@ public static void registerCan(ItemStack cannedFoodType) @Override public @NotNull Component getName(ItemStack stack) { - if (getContents(stack).findAny().isEmpty()) + if (getContents(stack).isEmpty()) { return Component.translatable(Translations.Items.EMPTY_CANNED_FOOD); }else { - String result = getContents(stack) + String result = getContents(stack).stream() .map(CannedFoodItem::getItemDisplayName) .collect(new TopNCollector<>(3)); return Component.translatable(Translations.Items.CANNED_FOOD).append(Component.literal(result)); @@ -162,10 +165,10 @@ public int getColor(int layer) { @Override public @NotNull Optional getTooltipImage(ItemStack stack) { - if (getContents(stack).findAny().isPresent()) + if (!getContents(stack).isEmpty()) { NonNullList nonNullList = NonNullList.create(); - Stream stream = getContents(stack); + Stream stream = getContents(stack).stream(); Objects.requireNonNull(nonNullList); stream.forEach(nonNullList::add); return Optional.of(new CannedFoodTooltip(nonNullList)); @@ -176,21 +179,22 @@ public int getColor(int layer) { } @Override - public void appendHoverText(ItemStack stack, @Nullable Level world, List tooltip, TooltipFlag context) { - if (getContents(stack).findAny().isPresent()) { + public void appendHoverText(ItemStack stack, TooltipContext context, List tooltip, TooltipFlag type) { + if (!getContents(stack).isEmpty()) { tooltip.add(Component.translatable(Translations.Items.TOTAL_NUTRITION).append(Component.literal(String.valueOf(getTotalNutrition(stack)))).withColor(ChatFormatting.DARK_GRAY.getColor())); } } - public static Stream getContents(ItemStack stack) { - CompoundTag compoundTag = stack.getTag(); - if (compoundTag == null) { - return Stream.empty(); + public static List getContents(ItemStack stack) { + DataComponentMap components = stack.getComponents(); + if (components.isEmpty()) { + return List.of(); } else { - ListTag listTag = compoundTag.getList("Items", ListTag.TAG_COMPOUND); - Stream stream = listTag.stream(); - Objects.requireNonNull(CompoundTag.class); - return stream.map(CompoundTag.class::cast).map(ItemStack::of); + ItemContainerContents contents = components.get(DataComponents.CONTAINER); + if (contents == null) { + return List.of(); + } + return contents.stream().toList(); } } @@ -199,65 +203,56 @@ public static boolean isCannedFoodItem(ItemStack stack) { } private static void removeOne(ItemStack stack) { - CompoundTag compoundTag = stack.getOrCreateTag(); - if (compoundTag.contains("Items")) - { - ListTag listTag = compoundTag.getList("Items", 10); - if (!listTag.isEmpty()) + ItemContainerContents itemContainerContents = stack.get(DataComponents.CONTAINER); + + assert itemContainerContents != null; + List items = new ArrayList<>(itemContainerContents.stream().toList()); + if (!items.isEmpty()) { - Tag tag = listTag.get(0); - if (tag instanceof CompoundTag tagCompound) { - ItemStack itemStack = ItemStack.of(tagCompound); - int itemCount = itemStack.getCount(); - if (itemCount != 1) - { - itemStack.shrink(1); - CompoundTag compoundNew = new CompoundTag(); - itemStack.save(compoundNew); - listTag.set(0, compoundNew); - }else - { - listTag.remove(0); - } - } - if (listTag.isEmpty()) { - stack.removeTagKey("Items"); + ItemStack itemStack = items.getFirst(); + int itemCount = itemStack.getCount(); + if (itemCount != 1) + { + itemStack.shrink(1); + items.set(0, itemStack); + }else + { + items.removeFirst(); } + stack.set(DataComponents.CONTAINER, ItemContainerContents.fromItems(items)); } - } } public static void add(ItemStack cannedFood, ItemStack stack) { if (!stack.isEmpty() && stack.getItem().canFitInsideContainerItems()) { - CompoundTag compoundTag = cannedFood.getOrCreateTag(); - if (!compoundTag.contains("Items")) { - compoundTag.put("Items", new ListTag()); + if (!cannedFood.has(DataComponents.CONTAINER)) { + cannedFood.set(DataComponents.CONTAINER, ItemContainerContents.EMPTY); } + ItemContainerContents cannedFoodContainer = cannedFood.get(DataComponents.CONTAINER); + assert cannedFoodContainer != null; + List cannedFoodItems = new ArrayList<>(cannedFoodContainer.stream().toList()); - //the max that the canned food item can hold + //the max food items that the canned food item can hold int k = Math.min(stack.getCount(), MAX_FOOD); if (k != 0) { - ListTag listTag = compoundTag.getList("Items", 10); ItemStack itemStack2 = stack.copyWithCount(k); - CompoundTag compoundTag3 = new CompoundTag(); - itemStack2.save(compoundTag3); int iter = -1; - for (int i = 0; i < listTag.size(); i++) { - if (listTag.getCompound(i).get("id").getAsString().equals(compoundTag3.get("id").getAsString())) + for (int i = 0; i < cannedFoodItems.size(); i++) { + if (cannedFoodItems.get(i).getItem().toString().equals(itemStack2.getItem().toString())) { iter = i; } } if (iter == -1) { - listTag.add(0, compoundTag3); + cannedFoodItems.add(itemStack2); }else { - itemStack2.setCount(listTag.getCompound(iter).getInt("Count") + 1); - itemStack2.save(compoundTag3); - listTag.set(iter, compoundTag3); + itemStack2.setCount(cannedFoodItems.get(iter).getCount() + 1); + cannedFoodItems.set(iter, itemStack2); } + cannedFood.set(DataComponents.CONTAINER, ItemContainerContents.fromItems(cannedFoodItems)); } } } @@ -299,7 +294,7 @@ public static List addToCan(List items, ItemStack can) public static int getSize(ItemStack can) { int size = 0; - List contents = getContents(can).toList(); + List contents = getContents(can); if (!contents.isEmpty()) { //can has something inside it @@ -387,17 +382,19 @@ public static FoodProperties getCanFoodProperties(ItemStack stack) { float canSaturation = 0f; if (nutritionRequired != 0) { - Stream stream = getContents(stack); - for (ItemStack foodItem : stream.toList()) + List stream = getContents(stack); + for (ItemStack foodItem : stream) { + FoodProperties foodProperties = foodItem.get(DataComponents.FOOD); + assert foodProperties != null; int itemCount = foodItem.getCount(); for (int i = 0; i < itemCount; i++) { - canNutrition += Objects.requireNonNull(foodItem.getFoodComponent()).getNutrition(); - canSaturation += foodItem.getFoodComponent().getSaturationModifier(); + canNutrition += foodProperties.nutrition(); + canSaturation += foodProperties.saturation(); if (canNutrition >= nutritionRequired) { - return new FoodProperties.Builder().nutrition(canNutrition).saturationMod(canSaturation).build(); + return new FoodProperties.Builder().nutrition(canNutrition).saturationModifier(canSaturation).build(); } } } @@ -406,7 +403,7 @@ public static FoodProperties getCanFoodProperties(ItemStack stack) { return null; }else { - return new FoodProperties.Builder().nutrition(canNutrition).saturationMod(canSaturation).build(); + return new FoodProperties.Builder().nutrition(canNutrition).saturationModifier(canSaturation).build(); } } return null; @@ -414,13 +411,15 @@ public static FoodProperties getCanFoodProperties(ItemStack stack) { public static int getTotalNutrition(ItemStack stack) { int canNutrition = 0; - Stream stream = getContents(stack); - for (ItemStack foodItem : stream.toList()) + List stream = getContents(stack); + for (ItemStack foodItem : stream) { + FoodProperties foodProperties = foodItem.get(DataComponents.FOOD); + assert foodProperties != null; int itemCount = foodItem.getCount(); for (int i = 0; i < itemCount; i++) { - canNutrition += Objects.requireNonNull(foodItem.getFoodComponent()).getNutrition(); + canNutrition += foodProperties.nutrition(); } } return canNutrition; @@ -436,14 +435,15 @@ public static int getItemsToBeConsumed(ItemStack stack) { int itemsToBeConsumed = 0; if (nutritionRequired != 0) { - Stream stream = getContents(stack); - for (ItemStack foodItem : stream.toList()) + List stream = getContents(stack); + for (ItemStack foodItem : stream) { + FoodProperties foodProperties = foodItem.get(DataComponents.FOOD); int itemCount = foodItem.getCount(); for (int i = 0; i < itemCount; i++) { itemsToBeConsumed += 1; - canNutrition += Objects.requireNonNull(foodItem.getFoodComponent()).getNutrition(); + canNutrition += foodProperties.nutrition(); if (canNutrition >= nutritionRequired) { return itemsToBeConsumed; diff --git a/src/main/java/dev/galacticraft/mod/content/item/GCItems.java b/src/main/java/dev/galacticraft/mod/content/item/GCItems.java index 99061ff40..c81938102 100644 --- a/src/main/java/dev/galacticraft/mod/content/item/GCItems.java +++ b/src/main/java/dev/galacticraft/mod/content/item/GCItems.java @@ -28,12 +28,7 @@ import dev.galacticraft.mod.content.GCFluids; import dev.galacticraft.mod.content.GCRegistry; import dev.galacticraft.mod.content.GCRocketParts; -import dev.galacticraft.mod.util.TextureUtils; import dev.galacticraft.mod.util.Translations; -import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.model.ModelManager; import net.minecraft.core.Direction; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; @@ -43,13 +38,10 @@ import net.minecraft.world.item.*; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.DispenserBlock; -import org.intellij.lang.annotations.Identifier; import java.util.ArrayList; import java.util.List; -import static dev.galacticraft.mod.Constant.MOD_ID; - @SuppressWarnings("unused") public class GCItems { public static final GCRegistry ITEMS = new GCRegistry<>(BuiltInRegistries.ITEM); @@ -457,7 +449,7 @@ public class GCItems { public static final Item TIER_3_ROCKET_SCHEMATIC = new SchematicItem(new Item.Properties()); public static final Item ASTRO_MINER_SCHEMATIC = new SchematicItem(new Item.Properties()); - public static final CannedFoodItem CANNED_FOOD = new CannedFoodItem(new Item.Properties().food(new FoodProperties.Builder().nutrition(0).saturationMod(0).build()).stacksTo(1)); + public static final CannedFoodItem CANNED_FOOD = new CannedFoodItem(new Item.Properties().food(new FoodProperties.Builder().nutrition(0).saturationModifier(0).build()).stacksTo(1)); public static final CannedFoodItem EMPTY_CANNED_FOOD = new CannedFoodItem(new Item.Properties().food(null).stacksTo(64)); public static Item registerItem(String id, Item item) { diff --git a/src/main/java/dev/galacticraft/mod/events/GCEventHandlers.java b/src/main/java/dev/galacticraft/mod/events/GCEventHandlers.java index 5fae769ff..f0cda4d33 100644 --- a/src/main/java/dev/galacticraft/mod/events/GCEventHandlers.java +++ b/src/main/java/dev/galacticraft/mod/events/GCEventHandlers.java @@ -42,6 +42,7 @@ import net.minecraft.core.Direction; import net.minecraft.core.GlobalPos; import net.minecraft.core.Holder; +import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -52,6 +53,7 @@ import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BedBlock; @@ -73,12 +75,14 @@ public static void init() { } private static InteractionResultHolder onPlayerUseItem(Player player, Level world, InteractionHand hand) { - boolean oxygenWorld = CelestialBody.getByDimension(world).map(body -> body.atmosphere().breathable()).orElse(true); + Holder> body = world.galacticraft$getCelestialBody(); + boolean oxygenWorld = body.value().atmosphere().breathable(); + if (!oxygenWorld) { ItemStack itemStack = player.getItemInHand(hand); - if (itemStack.isEdible()) + if (itemStack.getComponents().has(DataComponents.FOOD)) { if (itemStack.getItem() instanceof CannedFoodItem) { diff --git a/src/main/java/dev/galacticraft/mod/lookup/GCApiLookupProviders.java b/src/main/java/dev/galacticraft/mod/lookup/GCApiLookupProviders.java index bb8485de7..40f47f1ef 100644 --- a/src/main/java/dev/galacticraft/mod/lookup/GCApiLookupProviders.java +++ b/src/main/java/dev/galacticraft/mod/lookup/GCApiLookupProviders.java @@ -28,10 +28,12 @@ import dev.galacticraft.mod.api.pipe.Pipe; import dev.galacticraft.mod.api.wire.Wire; import dev.galacticraft.mod.content.GCBlockEntityTypes; +import dev.galacticraft.mod.content.GCBlocks; import dev.galacticraft.mod.content.item.GCItems; import dev.galacticraft.mod.content.item.OxygenTankItem; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import team.reborn.energy.api.EnergyStorage; @@ -54,26 +56,8 @@ public class GCApiLookupProviders { GCBlockEntityTypes.OXYGEN_SEALER, GCBlockEntityTypes.OXYGEN_BUBBLE_DISTRIBUTOR, GCBlockEntityTypes.ENERGY_STORAGE_MODULE, + GCBlockEntityTypes.FOOD_CANNER, GCBlockEntityTypes.OXYGEN_STORAGE_MODULE - }; - private static final Block[] MACHINE_BLOCKS = new Block[]{ - GCBlocks.COAL_GENERATOR, - GCBlocks.BASIC_SOLAR_PANEL, - GCBlocks.ADVANCED_SOLAR_PANEL, - GCBlocks.CIRCUIT_FABRICATOR, - GCBlocks.COMPRESSOR, - GCBlocks.ELECTRIC_COMPRESSOR, - GCBlocks.ELECTRIC_FURNACE, - GCBlocks.ELECTRIC_ARC_FURNACE, - GCBlocks.REFINERY, - GCBlocks.OXYGEN_COLLECTOR, - GCBlocks.OXYGEN_COMPRESSOR, - GCBlocks.FOOD_CANNER, - GCBlocks.OXYGEN_DECOMPRESSOR, - GCBlocks.OXYGEN_SEALER, - GCBlocks.OXYGEN_BUBBLE_DISTRIBUTOR, - GCBlocks.ENERGY_STORAGE_MODULE, - GCBlocks.OXYGEN_STORAGE_MODULE }; @SuppressWarnings("rawtypes") private static final BlockEntityType[] WIRE_TYPES = new BlockEntityType[]{ diff --git a/src/main/java/dev/galacticraft/mod/machine/BlockCheck.java b/src/main/java/dev/galacticraft/mod/machine/BlockCheck.java index c6bf93187..940096edd 100644 --- a/src/main/java/dev/galacticraft/mod/machine/BlockCheck.java +++ b/src/main/java/dev/galacticraft/mod/machine/BlockCheck.java @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package dev.galacticraft.mod.machine; import net.minecraft.core.BlockPos; diff --git a/src/main/java/dev/galacticraft/mod/machine/FloodSearch.java b/src/main/java/dev/galacticraft/mod/machine/FloodSearch.java index 1856f7f4d..e40f1519b 100644 --- a/src/main/java/dev/galacticraft/mod/machine/FloodSearch.java +++ b/src/main/java/dev/galacticraft/mod/machine/FloodSearch.java @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package dev.galacticraft.mod.machine; import net.minecraft.core.BlockPos; diff --git a/src/main/java/dev/galacticraft/mod/machine/Region.java b/src/main/java/dev/galacticraft/mod/machine/Region.java index 487a28b92..bb892df1f 100644 --- a/src/main/java/dev/galacticraft/mod/machine/Region.java +++ b/src/main/java/dev/galacticraft/mod/machine/Region.java @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package dev.galacticraft.mod.machine; import net.minecraft.core.BlockPos; diff --git a/src/main/java/dev/galacticraft/mod/machine/SealerGroupings.java b/src/main/java/dev/galacticraft/mod/machine/SealerGroupings.java index bdf97b0a6..9a19f1925 100644 --- a/src/main/java/dev/galacticraft/mod/machine/SealerGroupings.java +++ b/src/main/java/dev/galacticraft/mod/machine/SealerGroupings.java @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package dev.galacticraft.mod.machine; import dev.galacticraft.mod.content.block.entity.machine.OxygenSealerBlockEntity; diff --git a/src/main/java/dev/galacticraft/mod/machine/SealerManager.java b/src/main/java/dev/galacticraft/mod/machine/SealerManager.java index 08a5938c6..df97e5bfa 100644 --- a/src/main/java/dev/galacticraft/mod/machine/SealerManager.java +++ b/src/main/java/dev/galacticraft/mod/machine/SealerManager.java @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package dev.galacticraft.mod.machine; import dev.galacticraft.mod.content.block.entity.machine.OxygenSealerBlockEntity; import net.minecraft.core.BlockPos; diff --git a/src/main/java/dev/galacticraft/mod/machine/SolidCheck.java b/src/main/java/dev/galacticraft/mod/machine/SolidCheck.java index a4ee39305..1bcab56ae 100644 --- a/src/main/java/dev/galacticraft/mod/machine/SolidCheck.java +++ b/src/main/java/dev/galacticraft/mod/machine/SolidCheck.java @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + package dev.galacticraft.mod.machine; import net.minecraft.core.BlockPos; diff --git a/src/main/java/dev/galacticraft/mod/mixin/client/ClientTooltipMixin.java b/src/main/java/dev/galacticraft/mod/mixin/client/ClientTooltipMixin.java index 16dfe1818..ca4a106da 100644 --- a/src/main/java/dev/galacticraft/mod/mixin/client/ClientTooltipMixin.java +++ b/src/main/java/dev/galacticraft/mod/mixin/client/ClientTooltipMixin.java @@ -36,7 +36,7 @@ public interface ClientTooltipMixin { @Overwrite static ClientTooltipComponent create(TooltipComponent data) { if (data instanceof BundleTooltip) { - return new ClientBundleTooltip((BundleTooltip)data); + return new ClientBundleTooltip(((BundleTooltip)data).contents()); } else if (data instanceof CannedFoodTooltip){ return new ClientCannedFoodTooltip((CannedFoodTooltip)data); } else { diff --git a/src/main/java/dev/galacticraft/mod/mixin/client/FabricItemMixin.java b/src/main/java/dev/galacticraft/mod/mixin/client/FabricItemMixin.java index b9777ba07..e7504c568 100644 --- a/src/main/java/dev/galacticraft/mod/mixin/client/FabricItemMixin.java +++ b/src/main/java/dev/galacticraft/mod/mixin/client/FabricItemMixin.java @@ -22,28 +22,57 @@ package dev.galacticraft.mod.mixin.client; +import dev.galacticraft.mod.content.item.CannedFoodItem; import net.fabricmc.fabric.api.item.v1.FabricItem; +import net.minecraft.core.component.DataComponentHolder; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.component.DataComponents; import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.lang.reflect.Field; import static dev.galacticraft.mod.content.item.CannedFoodItem.getCanFoodProperties; import static dev.galacticraft.mod.content.item.CannedFoodItem.isCannedFoodItem; -@Mixin(FabricItem.class) +@Mixin(DataComponentHolder.class) public interface FabricItemMixin { - @Overwrite - default @Nullable FoodProperties getFoodComponent(ItemStack stack) { - if (isCannedFoodItem(stack)) - { - return getCanFoodProperties(stack); - }else - { - return ((Item) this).getFoodProperties(); + @Inject(method = "get", at = @At("HEAD"), cancellable = true) + private void get(DataComponentType type, CallbackInfoReturnable cir) { + DataComponentHolder holder = (DataComponentHolder) (Object) this; + ItemStack stack = getItemStack(holder); + if (isCannedFoodItem(stack)) { + //data component holder has parent of canned food item + if (type.equals(DataComponents.FOOD)) + { + FoodProperties foodProperties = getCanFoodProperties(stack); + cir.setReturnValue((T) foodProperties); + } + } + } + + private ItemStack getItemStack(DataComponentHolder holder) { + if (holder instanceof ItemStack) { + return (ItemStack) holder; } + + try { + Field itemStackField = holder.getClass().getDeclaredField("itemStack"); + itemStackField.setAccessible(true); + return (ItemStack) itemStackField.get(holder); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + + return ItemStack.EMPTY; } } diff --git a/src/main/java/dev/galacticraft/mod/screen/FoodCannerMenu.java b/src/main/java/dev/galacticraft/mod/screen/FoodCannerMenu.java index 47211baeb..f31b15afc 100644 --- a/src/main/java/dev/galacticraft/mod/screen/FoodCannerMenu.java +++ b/src/main/java/dev/galacticraft/mod/screen/FoodCannerMenu.java @@ -23,17 +23,13 @@ package dev.galacticraft.mod.screen; import dev.galacticraft.machinelib.api.menu.MachineMenu; -import dev.galacticraft.machinelib.api.menu.sync.MenuSyncHandler; -import dev.galacticraft.mod.content.GCMachineTypes; -import dev.galacticraft.mod.content.block.entity.machine.CoalGeneratorBlockEntity; +import dev.galacticraft.machinelib.api.menu.MenuData; import dev.galacticraft.mod.content.block.entity.machine.FoodCannerBlockEntity; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Inventory; import org.jetbrains.annotations.NotNull; -import java.util.function.Consumer; - public class FoodCannerMenu extends MachineMenu { private int progress; @@ -43,22 +39,23 @@ public class FoodCannerMenu extends MachineMenu { private int forthRowConsumed; public FoodCannerMenu(int syncId, @NotNull ServerPlayer player, @NotNull FoodCannerBlockEntity machine) { - super(syncId, player, machine); + super(GCMenuTypes.FOOD_CANNER, syncId, player, machine); } - public FoodCannerMenu(int syncId, @NotNull Inventory inventory, @NotNull FriendlyByteBuf buf) { - super(syncId, inventory, buf, 8, 89, GCMachineTypes.FOOD_CANNER); + public FoodCannerMenu(int syncId, Inventory inventory, BlockPos pos) { + super(GCMenuTypes.FOOD_CANNER, syncId, inventory, pos, 8, 89); } @Override - public void registerSyncHandlers(Consumer consumer) { - super.registerSyncHandlers(consumer); + public void registerData(@NotNull MenuData data){ + super.registerData(data); + + data.registerInt(this.be::getProgress, this::setProgress); + data.registerInt(this.be::getFirstRowConsumed, this::setFirstRowConsumed); + data.registerInt(this.be::getSecondRowConsumed, this::setSecondRowConsumed); + data.registerInt(this.be::getThirdRowConsumed, this::setThirdRowConsumed); + data.registerInt(this.be::getForthRowConsumed, this::setForthRowConsumed); - consumer.accept(MenuSyncHandler.simple(this.machine::getProgress, this::setProgress)); - consumer.accept(MenuSyncHandler.simple(this.machine::getFirstRowConsumed, this::setFirstRowConsumed)); - consumer.accept(MenuSyncHandler.simple(this.machine::getSecondRowConsumed, this::setSecondRowConsumed)); - consumer.accept(MenuSyncHandler.simple(this.machine::getThirdRowConsumed, this::setThirdRowConsumed)); - consumer.accept(MenuSyncHandler.simple(this.machine::getForthRowConsumed, this::setForthRowConsumed)); } diff --git a/src/main/java/dev/galacticraft/mod/screen/GCMenuTypes.java b/src/main/java/dev/galacticraft/mod/screen/GCMenuTypes.java index 5e8365ce7..862b38be7 100644 --- a/src/main/java/dev/galacticraft/mod/screen/GCMenuTypes.java +++ b/src/main/java/dev/galacticraft/mod/screen/GCMenuTypes.java @@ -55,7 +55,7 @@ public class GCMenuTypes { public static final MenuType> OXYGEN_COMPRESSOR = SynchronizedMenuType.createSimple(MachineMenu::new); public static final MenuType> OXYGEN_DECOMPRESSOR = SynchronizedMenuType.createSimple(MachineMenu::new); - public static final MenuType FOOD_CANNER = SynchronizedMenuType.createSimple(MachineMenu::new); + public static final MenuType FOOD_CANNER = SynchronizedMenuType.create(FoodCannerMenu::new); public static final MenuType> OXYGEN_SEALER = SynchronizedMenuType.createSimple(MachineMenu::new); diff --git a/src/main/java/dev/galacticraft/mod/world/dimension/GCLevelStems.java b/src/main/java/dev/galacticraft/mod/world/dimension/GCLevelStems.java index 14cb68a8e..aa054d632 100644 --- a/src/main/java/dev/galacticraft/mod/world/dimension/GCLevelStems.java +++ b/src/main/java/dev/galacticraft/mod/world/dimension/GCLevelStems.java @@ -54,7 +54,7 @@ public static void bootstrapRegistries(@NotNull BootstrapContext cont // the returned reference may be null // context.register(MOON, new LevelStem(typeLookup.getOrThrow(GCDimensionTypes.MOON), new NoiseBasedChunkGenerator(MultiNoiseBiomeSource.createFromPreset(biomeNoiseLookup.getOrThrow(GCMultiNoiseBiomeSourceParameterLists.MOON)), noiseLookup.getOrThrow(GCNoiseGeneratorSettings.MOON)))); context.register(VENUS, new LevelStem(typeLookup.getOrThrow(GCDimensionTypes.VENUS), new NoiseBasedChunkGenerator(MultiNoiseBiomeSource.createFromPreset(biomeNoiseLookup.getOrThrow(GCMultiNoiseBiomeSourceParameterLists.VENUS)), noiseLookup.getOrThrow(GCNoiseGeneratorSettings.VENUS)))); - context.register(ASTEROID, new LevelStem(typeLookup.getOrThrow(GCDimensionTypes.ASTEROID), new AsteroidChunkGenerator(MultiNoiseBiomeSource.createFromPreset(biomeNoiseLookup.getOrThrow(GCMultiNoiseBiomeSourceParameterLists.ASTEROID)), ResourceKey.create(Registries.DIMENSION, new ResourceLocation("galacticraft", "asteroid")), 1000))); + context.register(ASTEROID, new LevelStem(typeLookup.getOrThrow(GCDimensionTypes.ASTEROID), new AsteroidChunkGenerator(MultiNoiseBiomeSource.createFromPreset(biomeNoiseLookup.getOrThrow(GCMultiNoiseBiomeSourceParameterLists.ASTEROID)), ResourceKey.create(Registries.DIMENSION, Constant.id("asteroid")), 1000))); } @Contract(value = "_ -> new", pure = true) diff --git a/src/main/java/dev/galacticraft/mod/world/gen/GCNoiseGeneratorSettings.java b/src/main/java/dev/galacticraft/mod/world/gen/GCNoiseGeneratorSettings.java index 0d92f951f..a2f527fd7 100644 --- a/src/main/java/dev/galacticraft/mod/world/gen/GCNoiseGeneratorSettings.java +++ b/src/main/java/dev/galacticraft/mod/world/gen/GCNoiseGeneratorSettings.java @@ -22,21 +22,15 @@ package dev.galacticraft.mod.world.gen; -import com.mojang.serialization.Codec; import dev.galacticraft.mod.Constant; import dev.galacticraft.mod.content.GCBlocks; -import dev.galacticraft.mod.world.gen.custom.AsteroidChunkGenerator; -import dev.galacticraft.mod.world.gen.surfacebuilder.MoonSurfaceRules; -import dev.galacticraft.mod.world.gen.surfacebuilder.VenusSurfaceRules; import dev.galacticraft.mod.world.gen.surfacerule.VenusSurfaceRules; import net.minecraft.core.HolderGetter; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.OverworldBiomeBuilder; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.*; import net.minecraft.world.level.levelgen.synth.NormalNoise; import org.jetbrains.annotations.Contract; diff --git a/src/main/java/dev/galacticraft/mod/world/gen/custom/AsteroidChunkGenerator.java b/src/main/java/dev/galacticraft/mod/world/gen/custom/AsteroidChunkGenerator.java index 6b94e0446..1654f8aec 100644 --- a/src/main/java/dev/galacticraft/mod/world/gen/custom/AsteroidChunkGenerator.java +++ b/src/main/java/dev/galacticraft/mod/world/gen/custom/AsteroidChunkGenerator.java @@ -23,6 +23,7 @@ package dev.galacticraft.mod.world.gen.custom; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import dev.galacticraft.api.perlin.NoiseModule; import dev.galacticraft.api.perlin.generator.Billowed; @@ -50,13 +51,15 @@ import net.minecraft.world.level.levelgen.*; import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.storage.*; +import org.jetbrains.annotations.NotNull; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import static dev.galacticraft.impl.internal.fabric.GalacticraftAPI.currentWorldSaveDirectory; import static dev.galacticraft.mod.world.gen.custom.AsteroidSaveData.saveDataID; @@ -133,7 +136,7 @@ public class AsteroidChunkGenerator extends ChunkGenerator { private int largeAsteroidsLastChunkZ; private final MapGenAbandonedBase dungeonGenerator = new MapGenAbandonedBase(); - public static final Codec CODEC = RecordCodecBuilder.create(instance -> + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( BiomeSource.CODEC.fieldOf("biomeSource").forGetter(generator -> generator.biomeSource), ServerLevel.RESOURCE_KEY_CODEC.fieldOf("dimensionKey").forGetter(generator -> generator.dimensionKey), @@ -496,7 +499,7 @@ private final int getTerrainHeightAt(int x, int z, float[] yModArray, int xMin, } @Override - protected Codec codec() { + protected @NotNull MapCodec codec() { return CODEC; } @@ -674,14 +677,13 @@ public int getGenDepth() { } @Override - public CompletableFuture fillFromNoise(Executor executor, Blender blender, RandomState randomState, StructureManager structureManager, ChunkAccess chunkAccess) { - + public CompletableFuture fillFromNoise(Blender blender, RandomState noiseConfig, StructureManager structureAccessor, ChunkAccess chunk) { CompletableFuture future = new CompletableFuture<>(); - executor.execute(() -> { + Minecraft.getInstance().submit(() -> { try { - // Example asynchronous operation (replace with your actual logic) - ChunkAccess result = generateChunkData(blender, randomState, structureManager, chunkAccess); + // This operation will now run on Minecraft's main thread + ChunkAccess result = generateChunkData(blender, noiseConfig, structureAccessor, chunk); future.complete(result); } catch (Exception e) { future.completeExceptionally(e); diff --git a/src/main/java/dev/galacticraft/mod/world/gen/custom/AsteroidSaveData.java b/src/main/java/dev/galacticraft/mod/world/gen/custom/AsteroidSaveData.java index e7a314a08..7c03b9390 100644 --- a/src/main/java/dev/galacticraft/mod/world/gen/custom/AsteroidSaveData.java +++ b/src/main/java/dev/galacticraft/mod/world/gen/custom/AsteroidSaveData.java @@ -25,6 +25,7 @@ import dev.galacticraft.mod.Constant; import dev.galacticraft.mod.data.GCDataGenerator; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.minecraft.core.HolderLookup; import net.minecraft.data.CachedOutput; import net.minecraft.data.DataProvider; import net.minecraft.nbt.CompoundTag; @@ -59,15 +60,14 @@ public void readFromNBT(CompoundTag nbt) this.datacompound = nbt.getCompound("asteroids"); } - @Override - public CompoundTag save(CompoundTag nbt) - { - nbt.put("asteroids", this.datacompound); - return nbt; - } - public static AsteroidSaveData load(CompoundTag compound) { String value = compound.getString("someValue"); return new AsteroidSaveData(value); } + + @Override + public CompoundTag save(CompoundTag nbt, HolderLookup.Provider registryLookup) { + nbt.put("asteroids", this.datacompound); + return nbt; + } } diff --git a/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/background.png b/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/background.png new file mode 100644 index 000000000..427b020e2 Binary files /dev/null and b/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/background.png differ diff --git a/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/background.png.mcmeta b/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/background.png.mcmeta new file mode 100644 index 000000000..2d596bf66 --- /dev/null +++ b/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/background.png.mcmeta @@ -0,0 +1,10 @@ +{ + "gui": { + "scaling": { + "type": "nine_slice", + "width": 32, + "height": 32, + "border": 4 + } + } +} diff --git a/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/blocked_slot.png b/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/blocked_slot.png new file mode 100644 index 000000000..31f79622c Binary files /dev/null and b/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/blocked_slot.png differ diff --git a/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/slot.png b/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/slot.png new file mode 100644 index 000000000..ac45847e4 Binary files /dev/null and b/src/main/resources/assets/galacticraft/textures/gui/sprites/canned_food/slot.png differ