diff --git a/.github/workflows/cicd-workflow.yml b/.github/workflows/cicd-workflow.yml index 289e122..5992343 100644 --- a/.github/workflows/cicd-workflow.yml +++ b/.github/workflows/cicd-workflow.yml @@ -16,12 +16,12 @@ jobs: uses: cech12/MinecraftModActions/.github/workflows/build.yml@main with: java-version: 17 - gametest: - needs: build - name: Game Test - uses: cech12/MinecraftModActions/.github/workflows/gametest.yml@main - with: - java-version: 17 +# gametest: +# needs: build +# name: Game Test +# uses: cech12/MinecraftModActions/.github/workflows/gametest.yml@main +# with: +# java-version: 17 codeql: needs: build name: CodeQL @@ -29,7 +29,8 @@ jobs: with: java-version: 17 publish-github: - needs: [ gametest, codeql ] +# needs: [ gametest, codeql ] + needs: codeql if: startsWith(github.ref, 'refs/tags/') name: Publish Github uses: cech12/MinecraftModActions/.github/workflows/publish-github.yml@main @@ -48,10 +49,9 @@ jobs: java-version: 17 curseforge-id: 436874 game-versions: | - 1.20.1 + 1.20.2 release-type: release loaders: | - neoforge forge secrets: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -65,10 +65,9 @@ jobs: java-version: 17 modrinth-id: IsSapAeq game-versions: | - 1.20.1 + 1.20.2 release-type: release loaders: | - neoforge forge secrets: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eefda7..90f486d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Forge Recommended Versioning](https://mcforge.readthedocs.io/en/latest/conventions/versioning/). +## [1.20.2-2.2.0.0] - 2023-10-26 +### Changed +- update and move back to Forge 1.20.2-48.0.23 (from NeoForge) until it is stable +- Temporary deactivation of The One Probe support until it is ported to 1.20.2 +- deactivate game tests, because they are not working yet + ## [1.20.1-2.1.0.0] - 2023-08-09 ### Changed - Changed Forge to NeoForge 1.20.1-47.1.54 (compatible with Forge 47.1.0) diff --git a/build.gradle b/build.gradle index 462035e..bee8f5d 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'eclipse' id 'idea' id 'maven-publish' - id 'net.neoforged.gradle' version '[6.0,6.2)' + id 'net.minecraftforge.gradle' version '[6.0,6.2)' } version = "${minecraft_version}-${mod_version}" @@ -106,7 +106,7 @@ repositories { } dependencies { - minecraft "net.neoforged:forge:${project.minecraft_version}-${project.forge_version}" + minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}" // compile against the JEI API but do not include it at runtime compileOnly fg.deobf("mezz.jei:jei-${project.minecraft_version}-common-api:${project.jei_version}") @@ -114,7 +114,7 @@ dependencies { // at runtime, use the full JEI jar runtimeOnly fg.deobf("mezz.jei:jei-${project.minecraft_version}-forge:${project.jei_version}") - implementation fg.deobf("mcjty.theoneprobe:theoneprobe:$top_version") {transitive = false} + //implementation fg.deobf("mcjty.theoneprobe:theoneprobe:$top_version") {transitive = false} } tasks.named('processResources', ProcessResources).configure { diff --git a/gradle.properties b/gradle.properties index 999a805..943b485 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,14 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false ## Environment Properties -minecraft_version=1.20.1 -minecraft_version_range=[1.20.1,1.21) -forge_version=47.1.54 -forge_version_range=[47.1.0,) -loader_version_range=[47,) +minecraft_version=1.20.2 +minecraft_version_range=[1.20.2,1.21) +forge_version=48.0.23 +forge_version_range=[48.0.23,) +loader_version_range=[48,) mod_id=solarcooker -mod_version=2.1.0.0 +mod_version=2.2.0.0 mod_group_id=cech12.solarcooker mod_name=Solar Cooker mod_authors=Cech12 @@ -21,8 +21,8 @@ mod_issue_tracker=https://github.com/cech12/SolarCooker/issues mod_description=A mod which adds a Solar Cooker. # jei -jei_version=15.2.0.23 -jei_version_range=[15.2.0.23,) +jei_version=16.0.0.28 +jei_version_range=[16.0.0.28,) #the one probe top_version=1.20.1-10.0.1-3 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 46671ac..80187ac 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle index 09a3d08..291d399 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,8 +2,8 @@ pluginManagement { repositories { gradlePluginPortal() maven { - name = 'NeoForge' - url = 'https://maven.neoforged.net' + name = 'MinecraftForge' + url = 'https://maven.minecraftforge.net/' } } } diff --git a/src/main/java/cech12/solarcooker/SolarCookerMod.java b/src/main/java/cech12/solarcooker/SolarCookerMod.java index 9238a5d..463a0a0 100644 --- a/src/main/java/cech12/solarcooker/SolarCookerMod.java +++ b/src/main/java/cech12/solarcooker/SolarCookerMod.java @@ -2,7 +2,7 @@ import cech12.solarcooker.client.SolarCookerBlockEntityRenderer; import cech12.solarcooker.client.SolarCookerScreen; -import cech12.solarcooker.compat.TOPCompat; +//import cech12.solarcooker.compat.TOPCompat; import cech12.solarcooker.config.ServerConfig; import cech12.solarcooker.init.ModBlockEntityTypes; import cech12.solarcooker.init.ModBlocks; @@ -49,7 +49,7 @@ public SolarCookerMod() { ServerConfig.loadConfig(ServerConfig.SERVER_CONFIG, FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath()).resolve(MOD_ID + "-server.toml")); //The One Probe registration. if (ModList.get().isLoaded("theoneprobe")) { - TOPCompat.register(); + //TOPCompat.register(); } } diff --git a/src/main/java/cech12/solarcooker/block/SolarCookerBlock.java b/src/main/java/cech12/solarcooker/block/SolarCookerBlock.java index 922a2c9..abd935d 100644 --- a/src/main/java/cech12/solarcooker/block/SolarCookerBlock.java +++ b/src/main/java/cech12/solarcooker/block/SolarCookerBlock.java @@ -22,7 +22,6 @@ import javax.annotation.Nullable; import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraftforge.network.NetworkHooks; public class SolarCookerBlock extends AbstractSolarCookerBlock { @@ -50,7 +49,7 @@ public BlockEntityTicker getTicker(@Nonnull Level lev protected void interactWith(Level worldIn, @Nonnull BlockPos pos, @Nonnull Player player) { BlockEntity blockEntity = worldIn.getBlockEntity(pos); if (blockEntity instanceof SolarCookerBlockEntity && player instanceof ServerPlayer) { - NetworkHooks.openScreen((ServerPlayer) player, (SolarCookerBlockEntity) blockEntity, pos); + player.openMenu((SolarCookerBlockEntity) blockEntity); } } diff --git a/src/main/java/cech12/solarcooker/blockentity/AbstractSolarCookerBlockEntity.java b/src/main/java/cech12/solarcooker/blockentity/AbstractSolarCookerBlockEntity.java index ff1b359..28acb66 100644 --- a/src/main/java/cech12/solarcooker/blockentity/AbstractSolarCookerBlockEntity.java +++ b/src/main/java/cech12/solarcooker/blockentity/AbstractSolarCookerBlockEntity.java @@ -8,13 +8,15 @@ import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.RecipeCraftingHolder; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.LidBlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.entity.ExperienceOrb; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.StackedContentsCompatible; -import net.minecraft.world.inventory.RecipeHolder; import net.minecraft.world.WorldlyContainer; import net.minecraft.world.ContainerHelper; import net.minecraft.world.item.ItemStack; @@ -47,7 +49,11 @@ import javax.annotation.Nullable; import java.util.List; -public abstract class AbstractSolarCookerBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible, LidBlockEntity { +public abstract class AbstractSolarCookerBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeCraftingHolder, StackedContentsCompatible, LidBlockEntity { + + public static final int CONTAINER_IS_SUNLIT = 0; + public static final int CONTAINER_COOK_TIME = 1; + public static final int CONTAINER_COOK_TIME_TOTAL = 2; private static final int[] SLOTS = new int[]{0, 1}; private static final int[] SLOTS_UP = new int[]{}; @@ -77,9 +83,35 @@ public AbstractSolarCookerBlockEntity(BlockEntityType tileTypeIn, BlockPos po this.specificRecipeType = specificRecipeTypeIn; } - protected AbstractCookingRecipe curRecipe; + protected RecipeHolder curRecipe; protected ItemStack failedMatch = ItemStack.EMPTY; + protected final ContainerData dataAccess = new ContainerData() { + public int get(int index) { + return switch (index) { + case CONTAINER_IS_SUNLIT -> AbstractSolarCookerBlockEntity.this.isSunlit() ? 1 : 0; + case CONTAINER_COOK_TIME -> AbstractSolarCookerBlockEntity.this.cookTime; + case CONTAINER_COOK_TIME_TOTAL -> AbstractSolarCookerBlockEntity.this.cookTimeTotal; + default -> 0; + }; + } + + public void set(int index, int value) { + switch (index) { + //case CONTAINER_IS_SUNLIT: break; //do nothing + case CONTAINER_COOK_TIME: + AbstractSolarCookerBlockEntity.this.cookTime = value; + break; + case CONTAINER_COOK_TIME_TOTAL: + AbstractSolarCookerBlockEntity.this.cookTimeTotal = value; + } + } + + public int getCount() { + return 3; + } + }; + private boolean hasShiningBlockAbove() { if (this.level != null && !this.level.isClientSide) { BlockPos checkPos = this.worldPosition.above(); @@ -163,7 +195,7 @@ public static void tick(Level level, BlockPos pos, BlockState state, AbstractSol entity.calculateLidAngle(); boolean isSunlit = entity.isSunlit(); if (isSunlit && !entity.items.get(INPUT).isEmpty()) { - AbstractCookingRecipe recipe = entity.getRecipe(); + RecipeHolder recipe = entity.getRecipe(); if (entity.canSmelt(recipe)) { entity.cookTime++; if (entity.cookTime == entity.cookTimeTotal) { @@ -280,9 +312,9 @@ private void playSound(SoundEvent soundIn) { } } - protected boolean canSmelt(@Nullable Recipe recipe) { + protected boolean canSmelt(@Nullable RecipeHolder recipe) { if (!this.items.get(INPUT).isEmpty() && recipe != null) { - ItemStack recipeOutput = ((Recipe) recipe).assemble(this, this.getLevel().registryAccess()); + ItemStack recipeOutput = ((Recipe) recipe.value()).assemble(this, this.getLevel().registryAccess()); if (!recipeOutput.isEmpty()) { ItemStack output = this.items.get(OUTPUT); if (output.isEmpty()) return true; @@ -293,10 +325,10 @@ protected boolean canSmelt(@Nullable Recipe recipe) { return false; } - private void smeltItem(@Nullable Recipe recipe) { + private void smeltItem(@Nullable RecipeHolder recipe) { if (recipe != null && this.canSmelt(recipe)) { ItemStack itemstack = this.items.get(INPUT); - ItemStack itemstack1 = ((Recipe) recipe).assemble(this, this.getLevel().registryAccess()); + ItemStack itemstack1 = ((Recipe) recipe.value()).assemble(this, this.getLevel().registryAccess()); ItemStack itemstack2 = this.items.get(OUTPUT); if (itemstack2.isEmpty()) { this.items.set(1, itemstack1.copy()); @@ -313,33 +345,33 @@ private void smeltItem(@Nullable Recipe recipe) { } protected int getRecipeCookTime() { - AbstractCookingRecipe rec = getRecipe(); + RecipeHolder rec = getRecipe(); if (rec == null) { return 200; } this.checkForReflectors(); double reflectorFactor = (this.reflectorCount > 0) ? 1 - ((1 - ServerConfig.MAX_REFLECTOR_TIME_FACTOR.get()) / 4.0D) * this.reflectorCount : 1; - if (this.specificRecipeType.getClass().isInstance(rec.getType())) { - return (int) (rec.getCookingTime() * reflectorFactor); + if (this.specificRecipeType.getClass().isInstance(rec.value().getType())) { + return (int) (rec.value().getCookingTime() * reflectorFactor); } - return (int) (rec.getCookingTime() * (ServerConfig.COOK_TIME_FACTOR.get() * reflectorFactor)); + return (int) (rec.value().getCookingTime() * (ServerConfig.COOK_TIME_FACTOR.get() * reflectorFactor)); } @SuppressWarnings("unchecked") - protected AbstractCookingRecipe getRecipe() { + protected RecipeHolder getRecipe() { ItemStack input = this.getItem(INPUT); if (input.isEmpty() || input == failedMatch) { return null; } - if (this.level != null && curRecipe != null && curRecipe.matches(this, level)) { + if (this.level != null && curRecipe != null && curRecipe.value().matches(this, level)) { return curRecipe; } else { - AbstractCookingRecipe rec = null; + RecipeHolder rec = null; if (this.level != null) { rec = this.level.getRecipeManager().getRecipeFor((RecipeType) this.specificRecipeType, this, this.level).orElse(null); if (rec == null && ServerConfig.VANILLA_RECIPES_ENABLED.get()) { rec = this.level.getRecipeManager().getRecipesFor((RecipeType) ServerConfig.getRecipeType(), this, this.level) - .stream().filter(abstractCookingRecipe -> ServerConfig.isRecipeNotBlacklisted(abstractCookingRecipe.getId())).findFirst().orElse(null); + .stream().filter(abstractCookingRecipe -> ServerConfig.isRecipeNotBlacklisted(abstractCookingRecipe.id())).findFirst().orElse(null); } } if (rec == null) { @@ -493,31 +525,31 @@ public void clearContent() { } @Override - public void setRecipeUsed(@Nullable Recipe recipe) { + public void setRecipeUsed(@Nullable RecipeHolder recipe) { if (recipe != null) { - this.usedRecipes.addTo(recipe.getId(), 1); + this.usedRecipes.addTo(recipe.id(), 1); } } @Override @Nullable - public Recipe getRecipeUsed() { + public RecipeHolder getRecipeUsed() { return null; } public void awardUsedRecipesAndPopExperience(Player p_235645_1_) { - List> list = this.getRecipesToAwardAndPopExperience(p_235645_1_.level(), p_235645_1_.position()); + List> list = this.getRecipesToAwardAndPopExperience(p_235645_1_.level(), p_235645_1_.position()); p_235645_1_.awardRecipes(list); this.usedRecipes.clear(); } - public List> getRecipesToAwardAndPopExperience(Level p_235640_1_, Vec3 p_235640_2_) { - List> list = Lists.newArrayList(); + public List> getRecipesToAwardAndPopExperience(Level p_235640_1_, Vec3 p_235640_2_) { + List> list = Lists.newArrayList(); for(Object2IntMap.Entry entry : this.usedRecipes.object2IntEntrySet()) { - p_235640_1_.getRecipeManager().byKey(entry.getKey()).ifPresent((p_235642_4_) -> { - list.add(p_235642_4_); - createExperience(p_235640_1_, p_235640_2_, entry.getIntValue(), ((AbstractCookingRecipe)p_235642_4_).getExperience()); + p_235640_1_.getRecipeManager().byKey(entry.getKey()).ifPresent((recipeHolder) -> { + list.add(recipeHolder); + createExperience(p_235640_1_, p_235640_2_, entry.getIntValue(), ((AbstractCookingRecipe)recipeHolder.value()).getExperience()); }); } diff --git a/src/main/java/cech12/solarcooker/blockentity/SolarCookerBlockEntity.java b/src/main/java/cech12/solarcooker/blockentity/SolarCookerBlockEntity.java index 54c22d9..c9e075b 100644 --- a/src/main/java/cech12/solarcooker/blockentity/SolarCookerBlockEntity.java +++ b/src/main/java/cech12/solarcooker/blockentity/SolarCookerBlockEntity.java @@ -26,7 +26,7 @@ protected Component getDefaultName() { @Override @Nonnull protected AbstractContainerMenu createMenu(int id, @Nonnull Inventory player) { - return new SolarCookerContainer(ModRecipeTypes.SOLAR_COOKING.get(), id, player, this); + return new SolarCookerContainer(ModRecipeTypes.SOLAR_COOKING.get(), id, player, this, this.dataAccess); } } diff --git a/src/main/java/cech12/solarcooker/client/SolarCookerScreen.java b/src/main/java/cech12/solarcooker/client/SolarCookerScreen.java index ab6f166..921605b 100644 --- a/src/main/java/cech12/solarcooker/client/SolarCookerScreen.java +++ b/src/main/java/cech12/solarcooker/client/SolarCookerScreen.java @@ -27,10 +27,10 @@ public void init() { } @Override - public void render(@Nonnull GuiGraphics guiGraphics, int p_230430_2_, int p_230430_3_, float p_230430_4_) { - this.renderBackground(guiGraphics); - super.render(guiGraphics, p_230430_2_, p_230430_3_, p_230430_4_); - this.renderTooltip(guiGraphics, p_230430_2_, p_230430_3_); + public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { + this.renderBackground(guiGraphics, mouseX, mouseY, partialTicks); + super.render(guiGraphics, mouseX, mouseY, partialTicks); + this.renderTooltip(guiGraphics, mouseX, mouseY); } @Override diff --git a/src/main/java/cech12/solarcooker/compat/TOPCompat.java b/src/main/java/cech12/solarcooker/compat/TOPCompat.java index d2b5cc8..efb45d7 100644 --- a/src/main/java/cech12/solarcooker/compat/TOPCompat.java +++ b/src/main/java/cech12/solarcooker/compat/TOPCompat.java @@ -1,5 +1,5 @@ package cech12.solarcooker.compat; - +/* import cech12.solarcooker.SolarCookerMod; import cech12.solarcooker.blockentity.AbstractSolarCookerBlockEntity; import mcjty.theoneprobe.api.ElementAlignment; @@ -60,3 +60,4 @@ public void addProbeInfo(ProbeMode probeMode, IProbeInfo iProbeInfo, Player play } } } + */ diff --git a/src/main/java/cech12/solarcooker/crafting/SolarCookingRecipe.java b/src/main/java/cech12/solarcooker/crafting/SolarCookingRecipe.java index e45376b..8ea01ea 100644 --- a/src/main/java/cech12/solarcooker/crafting/SolarCookingRecipe.java +++ b/src/main/java/cech12/solarcooker/crafting/SolarCookingRecipe.java @@ -10,7 +10,6 @@ import net.minecraft.world.item.crafting.SimpleCookingSerializer; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.Ingredient; -import net.minecraft.resources.ResourceLocation; import javax.annotation.Nonnull; @@ -18,12 +17,12 @@ public class SolarCookingRecipe extends AbstractCookingRecipe { public static final SimpleCookingSerializer SERIALIZER = new SimpleCookingSerializer<>(SolarCookingRecipe::new, 200); - public SolarCookingRecipe(ResourceLocation p_i50031_1_, String p_i50031_2_, CookingBookCategory category, Ingredient p_i50031_3_, ItemStack p_i50031_4_, float p_i50031_5_, int p_i50031_6_) { - super(ModRecipeTypes.SOLAR_COOKING.get(), p_i50031_1_, p_i50031_2_, category, p_i50031_3_, p_i50031_4_, p_i50031_5_, p_i50031_6_); + public SolarCookingRecipe(String p_i50031_2_, CookingBookCategory category, Ingredient p_i50031_3_, ItemStack p_i50031_4_, float p_i50031_5_, int p_i50031_6_) { + super(ModRecipeTypes.SOLAR_COOKING.get(), p_i50031_2_, category, p_i50031_3_, p_i50031_4_, p_i50031_5_, p_i50031_6_); } public static SolarCookingRecipe convert(@Nonnull AbstractCookingRecipe recipe, RegistryAccess registryAccess) { - return new SolarCookingRecipe(recipe.getId(), recipe.getGroup(), recipe.category(), recipe.getIngredients().get(0), recipe.getResultItem(registryAccess), recipe.getExperience(), (int) (recipe.getCookingTime() * ServerConfig.COOK_TIME_FACTOR.get())); + return new SolarCookingRecipe(recipe.getGroup(), recipe.category(), recipe.getIngredients().get(0), recipe.getResultItem(registryAccess), recipe.getExperience(), (int) (recipe.getCookingTime() * ServerConfig.COOK_TIME_FACTOR.get())); } @Override diff --git a/src/main/java/cech12/solarcooker/init/ModMenuTypes.java b/src/main/java/cech12/solarcooker/init/ModMenuTypes.java index 3cf1a73..981a79f 100644 --- a/src/main/java/cech12/solarcooker/init/ModMenuTypes.java +++ b/src/main/java/cech12/solarcooker/init/ModMenuTypes.java @@ -2,7 +2,6 @@ import cech12.solarcooker.SolarCookerMod; import cech12.solarcooker.inventory.SolarCookerContainer; -import net.minecraft.core.BlockPos; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraftforge.common.extensions.IForgeMenuType; @@ -14,9 +13,6 @@ public class ModMenuTypes { public static final DeferredRegister> MENU_TYPES = DeferredRegister.create(ForgeRegistries.MENU_TYPES, SolarCookerMod.MOD_ID); - public static final RegistryObject> SOLAR_COOKER = MENU_TYPES.register("solarcooker", () -> IForgeMenuType.create((pWindowID, pInventory, pData) -> { - BlockPos pos = pData.readBlockPos(); - return new SolarCookerContainer(ModRecipeTypes.SOLAR_COOKING.get(), pWindowID, pInventory, pos); - })); + public static final RegistryObject> SOLAR_COOKER = MENU_TYPES.register("solarcooker", () -> IForgeMenuType.create((pWindowID, pInventory, pData) -> new SolarCookerContainer(ModRecipeTypes.SOLAR_COOKING.get(), pWindowID, pInventory))); } diff --git a/src/main/java/cech12/solarcooker/inventory/SolarCookerContainer.java b/src/main/java/cech12/solarcooker/inventory/SolarCookerContainer.java index fdd5717..c5531e9 100644 --- a/src/main/java/cech12/solarcooker/inventory/SolarCookerContainer.java +++ b/src/main/java/cech12/solarcooker/inventory/SolarCookerContainer.java @@ -1,17 +1,16 @@ package cech12.solarcooker.inventory; +import cech12.solarcooker.blockentity.AbstractSolarCookerBlockEntity; import cech12.solarcooker.config.ServerConfig; import cech12.solarcooker.init.ModMenuTypes; -import cech12.solarcooker.blockentity.AbstractSolarCookerBlockEntity; +import net.minecraft.world.Container; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.SimpleContainer; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.*; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.AbstractCookingRecipe; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -20,15 +19,17 @@ public class SolarCookerContainer extends AbstractContainerMenu { private final RecipeType specificRecipeType; - private final AbstractSolarCookerBlockEntity cooker; + private final Container cooker; + private final ContainerData data; protected final Level world; public SolarCookerContainer(RecipeType specificRecipeTypeIn, int id, - Inventory playerInventoryIn, AbstractSolarCookerBlockEntity cooker) { + Inventory playerInventoryIn, Container cooker, ContainerData data) { super(ModMenuTypes.SOLAR_COOKER.get(), id); this.specificRecipeType = specificRecipeTypeIn; checkContainerSize(cooker, 2); this.cooker = cooker; + this.data = data; cooker.startOpen(playerInventoryIn.player); this.world = playerInventoryIn.player.level(); @@ -45,11 +46,12 @@ public SolarCookerContainer(RecipeType specific for(int playerHotbarSlot = 0; playerHotbarSlot < 9; ++playerHotbarSlot) { this.addSlot(new Slot(playerInventoryIn, playerHotbarSlot, 8 + playerHotbarSlot * 18, 142)); } + + this.addDataSlots(this.data); } - public SolarCookerContainer(RecipeType specificRecipeTypeIn, int id, - Inventory playerInventoryIn, BlockPos pos) { - this(specificRecipeTypeIn, id, playerInventoryIn, (AbstractSolarCookerBlockEntity) playerInventoryIn.player.level().getBlockEntity(pos)); + public SolarCookerContainer(RecipeType specificRecipeTypeIn, int id, Inventory playerInventoryIn) { + this(specificRecipeTypeIn, id, playerInventoryIn, new SimpleContainer(2), new SimpleContainerData(3)); } @Override @@ -118,7 +120,7 @@ protected boolean hasRecipe(ItemStack stack) { } if (ServerConfig.VANILLA_RECIPES_ENABLED.get()) { return this.world.getRecipeManager().getRecipesFor(ServerConfig.getRecipeType(), new SimpleContainer(stack), this.world) - .stream().anyMatch(abstractCookingRecipe -> ServerConfig.isRecipeNotBlacklisted(abstractCookingRecipe.getId())); + .stream().anyMatch(abstractCookingRecipe -> ServerConfig.isRecipeNotBlacklisted(abstractCookingRecipe.id())); } } return false; @@ -135,18 +137,18 @@ public void removed(@Nonnull Player playerIn) { @OnlyIn(Dist.CLIENT) public int getCookProgressionScaled() { - int i = this.cooker.getCookTime(); - int j = this.cooker.getCookTimeTotal(); + int i = this.data.get(AbstractSolarCookerBlockEntity.CONTAINER_COOK_TIME); + int j = this.data.get(AbstractSolarCookerBlockEntity.CONTAINER_COOK_TIME_TOTAL); return j != 0 && i != 0 ? i * 24 / j : 0; } @OnlyIn(Dist.CLIENT) public boolean isBurning() { - return this.cooker.getCookTime() > 0; + return this.data.get(AbstractSolarCookerBlockEntity.CONTAINER_COOK_TIME) > 0; } @OnlyIn(Dist.CLIENT) public boolean isSunlit() { - return this.cooker.isSunlit(); + return this.data.get(AbstractSolarCookerBlockEntity.CONTAINER_IS_SUNLIT) > 0; } } diff --git a/src/main/java/cech12/solarcooker/jei/SolarCookerJEIPlugin.java b/src/main/java/cech12/solarcooker/jei/SolarCookerJEIPlugin.java index f8ad137..861278f 100644 --- a/src/main/java/cech12/solarcooker/jei/SolarCookerJEIPlugin.java +++ b/src/main/java/cech12/solarcooker/jei/SolarCookerJEIPlugin.java @@ -14,6 +14,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.resources.ResourceLocation; @@ -47,8 +48,8 @@ public void registerRecipes(@Nonnull IRecipeRegistration registration) { if (ServerConfig.VANILLA_RECIPES_ENABLED.get()) { registration.addRecipes(solarCookingCategory.getRecipeType(), manager.getAllRecipesFor(ServerConfig.getRecipeType()).stream() - .filter(recipe -> ServerConfig.isRecipeNotBlacklisted(recipe.getId())) - .map(recipe -> SolarCookingRecipe.convert(recipe, player.level().registryAccess())) + .filter(recipe -> ServerConfig.isRecipeNotBlacklisted(recipe.id())) + .map(recipe -> new RecipeHolder<>(recipe.id(), SolarCookingRecipe.convert(recipe.value(), player.level().registryAccess()))) .collect(Collectors.toList())); } } diff --git a/src/main/java/cech12/solarcooker/jei/SolarCookingCategory.java b/src/main/java/cech12/solarcooker/jei/SolarCookingCategory.java index da9a4cb..4fb148d 100644 --- a/src/main/java/cech12/solarcooker/jei/SolarCookingCategory.java +++ b/src/main/java/cech12/solarcooker/jei/SolarCookingCategory.java @@ -7,6 +7,7 @@ import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.recipe.RecipeType; import mezz.jei.library.plugins.vanilla.cooking.AbstractCookingCategory; +import net.minecraft.world.item.crafting.RecipeHolder; import javax.annotation.Nonnull; @@ -18,8 +19,9 @@ public SolarCookingCategory(IGuiHelper guiHelper) { @Override @Nonnull - public RecipeType getRecipeType() { - return new RecipeType<>(ModRecipeTypes.SOLAR_COOKING.getId(), SolarCookingRecipe.class); + public RecipeType> getRecipeType() { + Class> holderClass = (Class>) (Object) RecipeHolder.class; + return new RecipeType<>(ModRecipeTypes.SOLAR_COOKING.getId(), holderClass); } }