diff --git a/build.gradle b/build.gradle index 59dd2b8..0438b17 100644 --- a/build.gradle +++ b/build.gradle @@ -11,38 +11,49 @@ base { } repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. maven { url "https://maven.shedaniel.me/" } maven { url "https://maven.terraformersmc.com/releases/" } maven { url "https://pluto-mod-maven.web.app/maven" } + maven { url = "https://maven.parchmentmc.org" } + maven { url = "https://maven.quiltmc.org/repository/release" } } loom { accessWidenerPath = file("src/main/resources/plutoscoffee.accesswidener") + runs { + configureEach { + vmArg "-XX:+AllowEnhancedClassRedefinition" + vmArg "-XX:+IgnoreUnrecognizedVMOptions" + } + + server { + runDir "run/server" + } + } + } dependencies { - // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings(loom.layered { + it.mappings "org.quiltmc:quilt-mappings:${minecraft_version}+build.${quilt_mappings}:intermediary-v2" + it.parchment "org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip" + it.officialMojangMappings { nameSyntheticMembers = false } + }) modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - // Uncomment the following line to enable the deprecated Fabric API modules. - // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. - - // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" modApi "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}" - modApi "com.terraformersmc:modmenu:${project.modmenu_version}" - modApi "ml.pluto7073:pdapi:${project.pdapi_version}" + + modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}" + modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}" + + modImplementation "ml.pluto7073:pdapi:${project.minecraft_version}+${project.pdapi_version}" + + modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}" } processResources { @@ -58,9 +69,6 @@ tasks.withType(JavaCompile).configureEach { } java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. withSourcesJar() sourceCompatibility = JavaVersion.VERSION_17 @@ -73,7 +81,6 @@ jar { } } -// configure the maven publication publishing { publications { mavenJava(MavenPublication) { @@ -81,11 +88,6 @@ publishing { } } - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 87c913d..b834c6a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,20 +1,23 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G -# Fabric Properties +# Minecraft Stuff # check these on https://fabricmc.net/develop minecraft_version=1.20.1 yarn_mappings=1.20.1+build.10 -loader_version=0.15.7 +loader_version=0.15.11 +quilt_mappings=23 +parchment_version = 2023.09.03 -# Mod Properties -mod_version = 1.20.1+3.0-beta.1 +# Mod Thingies +mod_version = 1.20.1+3.0 maven_group = ml.pluto7073 archives_base_name = PlutosCoffeeMod-Fabric -# Dependencies +# Things I might be dependent on # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api fabric_version=0.92.0+1.20.1 cloth_version=11.1.118 modmenu_version=7.1.0 -pdapi_version=0.1.3 \ No newline at end of file +pdapi_version=0.2.20 +rei_version=12.0.684 \ No newline at end of file diff --git a/src/main/java/ml/pluto7073/plutoscoffee/Client.java b/src/main/java/ml/pluto7073/plutoscoffee/Client.java index 5208c80..6237803 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/Client.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/Client.java @@ -1,17 +1,25 @@ package ml.pluto7073.plutoscoffee; import ml.pluto7073.plutoscoffee.config.CoffeeConfig; +import ml.pluto7073.plutoscoffee.gui.CoffeeBrewerScreen; +import ml.pluto7073.plutoscoffee.gui.CoffeeGrindrScreen; +import ml.pluto7073.plutoscoffee.gui.EspressoMachineScreen; +import ml.pluto7073.plutoscoffee.network.ModPacketsS2C; import ml.pluto7073.plutoscoffee.registry.ModBlocks; +import ml.pluto7073.plutoscoffee.registry.ModItems; +import ml.pluto7073.plutoscoffee.registry.ModScreens; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.fabricmc.fabric.api.resource.ResourcePackActivationType; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import java.io.File; @@ -22,14 +30,23 @@ public class Client implements ClientModInitializer { public void onInitializeClient() { FabricLoader.getInstance().getModContainer(PlutosCoffee.MOD_ID).ifPresent(container -> - ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(PlutosCoffee.MOD_ID, "dark_gui"), container, Text.translatable("pack.plutoscoffee.dark_gui"),ResourcePackActivationType.NORMAL)); + ResourceManagerHelper.registerBuiltinResourcePack(new ResourceLocation(PlutosCoffee.MOD_ID, "dark_gui"), container, Component.translatable("pack.plutoscoffee.dark_gui"),ResourcePackActivationType.NORMAL)); - BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_CROP, RenderLayer.getCutout()); - BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_BREWER, RenderLayer.getCutout()); - BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_GRINDR, RenderLayer.getCutout()); - BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.ESPRESSO_MACHINE, RenderLayer.getCutout()); + ModPacketsS2C.register(); - CONFIG = new CoffeeConfig(new File("config/plutoscoffee.properties")); + MenuScreens.register(ModScreens.BREWER_MENU_TYPE, CoffeeBrewerScreen::new); + MenuScreens.register(ModScreens.GRINDR_SCREEN_HANDLER_TYPE, CoffeeGrindrScreen::new); + MenuScreens.register(ModScreens.ESPRESSO_SCREEN_HANDLER_TYPE, EspressoMachineScreen::new); + + BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_CROP, RenderType.cutout()); + BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_BREWER, RenderType.cutout()); + BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.COFFEE_GRINDR, RenderType.cutout()); + BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.ESPRESSO_MACHINE, RenderType.cutout()); + + ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : CoffeeUtil.getCoffeeColour(stack), ModItems.BREWED_COFFEE); + ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : CoffeeUtil.getLatteColour(stack), ModItems.LATTE); + + CONFIG = new CoffeeConfig(); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/CoffeeUtil.java b/src/main/java/ml/pluto7073/plutoscoffee/CoffeeUtil.java index 9c775ee..fe92060 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/CoffeeUtil.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/CoffeeUtil.java @@ -1,29 +1,26 @@ package ml.pluto7073.plutoscoffee; import com.mojang.datafixers.util.Pair; -import ml.pluto7073.pdapi.DrinkUtil; +import ml.pluto7073.pdapi.util.DrinkUtil; import ml.pluto7073.pdapi.addition.DrinkAddition; -import ml.pluto7073.pdapi.addition.DrinkAdditions; +import ml.pluto7073.pdapi.addition.DrinkAdditionManager; import ml.pluto7073.pdapi.item.AbstractCustomizableDrinkItem; import ml.pluto7073.plutoscoffee.coffee.CoffeeType; import ml.pluto7073.plutoscoffee.coffee.CoffeeTypes; import ml.pluto7073.plutoscoffee.items.BrewedCoffee; import ml.pluto7073.plutoscoffee.mixins.StructurePoolAccessor; import ml.pluto7073.plutoscoffee.registry.ModItems; -import ml.pluto7073.plutoscoffee.registry.ModMisc; import ml.pluto7073.plutoscoffee.tags.ModItemTags; import net.fabricmc.fabric.api.tag.convention.v1.TagUtil; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtList; -import net.minecraft.registry.Registry; -import net.minecraft.structure.pool.SinglePoolElement; -import net.minecraft.structure.pool.StructurePool; -import net.minecraft.structure.pool.StructurePoolElement; -import net.minecraft.util.Identifier; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.levelgen.structure.pools.SinglePoolElement; +import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement; +import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -33,8 +30,6 @@ public final class CoffeeUtil { - private static final double CAFFEINE_HALF_LIFE_TICKS = 2500.0; - private CoffeeUtil(){} public static boolean collectionContainsOnlyAll(Collection c1, Collection c2) { @@ -51,16 +46,16 @@ public static boolean collectionContainsOnlyAll(Collection c1, Collection public static CoffeeType getCoffeeType(ItemStack stack) { DrinkUtil.convertStackFromPlutosCoffee(stack); - return getCoffeeType(stack.getSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY)); + return getCoffeeType(stack.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY)); } public static ItemStack setCoffeeType(ItemStack stack, CoffeeType type) { DrinkUtil.convertStackFromPlutosCoffee(stack); - Identifier id = CoffeeTypes.getIdentifier(type); + ResourceLocation id = CoffeeTypes.getIdentifier(type); if (type == CoffeeTypes.EMPTY) { - stack.removeSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY); + stack.removeTagKey(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY); } else { - stack.getOrCreateSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", id.toString()); + stack.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", id.toString()); } return stack; } @@ -68,11 +63,11 @@ public static ItemStack setCoffeeType(ItemStack stack, CoffeeType type) { public static ItemStack getBaseCoffee(CoffeeType type) { ItemStack stack = new ItemStack(ModItems.BREWED_COFFEE); if (type == CoffeeTypes.EMPTY) return stack; - stack.getOrCreateSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", CoffeeTypes.getIdentifier(type).toString()); + stack.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", CoffeeTypes.getIdentifier(type).toString()); return stack; } - public static CoffeeType getCoffeeType(@Nullable NbtCompound nbt) { + public static CoffeeType getCoffeeType(@Nullable CompoundTag nbt) { return nbt == null ? CoffeeTypes.EMPTY : CoffeeType.byId(nbt.getString("CoffeeType")); } @@ -95,7 +90,7 @@ public static int getCoffeeColour(ItemStack stack) { public static int getCoffeeColour(DrinkAddition[] addIns) { int colour = BrewedCoffee.DEFAULT_COLOUR; - if (Arrays.stream(addIns).map(DrinkAdditions::getId).anyMatch(identifier -> identifier.toString().equals("pdapi:milk"))) { + if (Arrays.stream(addIns).map(DrinkAdditionManager::getId).anyMatch(identifier -> identifier.toString().equals("pdapi:milk"))) { colour = BrewedCoffee.COLOUR_WITH_MILK; } float r = (colour >> 16 & 255) / 255.0F; @@ -105,7 +100,7 @@ public static int getCoffeeColour(DrinkAddition[] addIns) { int allowedMilk = 3; for (DrinkAddition addition : addIns) { if (!addition.changesColor()) continue; - if (DrinkAdditions.getId(addition).toString().equals("pdapi:milk") && allowedMilk > 0) { + if (DrinkAdditionManager.getId(addition).toString().equals("pdapi:milk") && allowedMilk > 0) { allowedMilk--; continue; } @@ -122,14 +117,14 @@ public static int getCoffeeColour(DrinkAddition[] addIns) { } public static ItemStack getWithAdditions(ItemStack stack, String... additions) { - NbtList adds = new NbtList(); - if (stack.getOrCreateSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).contains("Additions")) { - adds = stack.getOrCreateSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).getList("Additions", NbtElement.STRING_TYPE); + ListTag adds = new ListTag(); + if (stack.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).contains("Additions")) { + adds = stack.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).getList("Additions", ListTag.TAG_STRING); } for (String s : additions) { adds.add(DrinkUtil.stringAsNbt(s)); } - stack.getOrCreateSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).put("Additions", adds); + stack.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).put("Additions", adds); return stack; } @@ -144,7 +139,9 @@ public static int getLatteColour(ItemStack stack) { public static int getLatteColour(DrinkAddition[] addIns) { int color = 0xFFFFFF; - if (Arrays.stream(addIns).map(DrinkAdditions::getId).anyMatch(id -> id.toString().equals("plutoscoffee:espresso_shot"))) { + if (Arrays.stream(addIns).map(DrinkAdditionManager::getId).anyMatch(id -> id.toString().equals("plutoscoffee:espresso_shot") + || id.toString().equals("plutoscoffee:blonde_espresso_shot") + || id.toString().equals("plutoscoffee:decaf_espresso_shot"))) { color = BrewedCoffee.COLOUR_WITH_MILK; } float r = (color >> 16 & 255) / 255.0F; @@ -154,7 +151,9 @@ public static int getLatteColour(DrinkAddition[] addIns) { int allowedShots = 2; for (DrinkAddition addition : addIns) { if (!addition.changesColor()) continue; - if (DrinkAdditions.getId(addition).toString().equals("plutoscoffee:espresso_shot") && allowedShots > 0) { + if ((DrinkAdditionManager.getId(addition).toString().equals("plutoscoffee:espresso_shot") || + DrinkAdditionManager.getId(addition).toString().equals("plutoscoffee:blonde_espresso_shot") || + DrinkAdditionManager.getId(addition).toString().equals("plutoscoffee:decaf_espresso_shot")) && allowedShots > 0) { allowedShots--; continue; } @@ -179,19 +178,19 @@ public static int calculateHealthBarHeightPixels(int health, int maxHeartsPerRow /** * Borrowed from the FriendsAndFoes mod by Faboslav */ - public static void addElementToStructurePool(Registry templateRegistry, Identifier poolLocation, String name, int weight) { - StructurePool pool = templateRegistry.get(poolLocation); + public static void addElementToStructurePool(Registry templateRegistry, ResourceLocation poolLocation, String name, int weight) { + StructureTemplatePool pool = templateRegistry.get(poolLocation); if (pool == null) return; - SinglePoolElement piece = SinglePoolElement.ofLegacySingle(PlutosCoffee.asId(name).toString()).apply(StructurePool.Projection.RIGID); + SinglePoolElement piece = SinglePoolElement.single(PlutosCoffee.asId(name).toString()).apply(StructureTemplatePool.Projection.RIGID); for (int i = 0; i < weight; i++) { - ((StructurePoolAccessor) pool).getElements().add(piece); + ((StructurePoolAccessor) pool).getTemplates().add(piece); } - List> pieceCounts = new ArrayList<>(((StructurePoolAccessor) pool).getElementCounts()); + List> pieceCounts = new ArrayList<>(((StructurePoolAccessor) pool).getRawTemplates()); pieceCounts.add(new Pair<>(piece, weight)); - ((StructurePoolAccessor) pool).setElementCounts(pieceCounts); + ((StructurePoolAccessor) pool).setRawTemplates(pieceCounts); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/PlutosCoffee.java b/src/main/java/ml/pluto7073/plutoscoffee/PlutosCoffee.java index de2df9d..a941145 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/PlutosCoffee.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/PlutosCoffee.java @@ -1,27 +1,24 @@ package ml.pluto7073.plutoscoffee; import ml.pluto7073.plutoscoffee.coffee.CoffeeGrounds; +import ml.pluto7073.plutoscoffee.coffee.MachineWaterSources; import ml.pluto7073.plutoscoffee.registry.*; -import ml.pluto7073.plutoscoffee.version.VersionChecker; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.fabricmc.fabric.api.object.builder.v1.villager.VillagerProfessionBuilder; -import net.fabricmc.fabric.api.object.builder.v1.villager.VillagerTypeHelper; -import net.minecraft.registry.Registry; -import net.minecraft.registry.RegistryKeys; +import net.fabricmc.fabric.api.resource.ResourceManagerHelper; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; -import net.minecraft.structure.pool.StructurePool; -import net.minecraft.util.Identifier; +import net.minecraft.server.packs.PackType; +import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class PlutosCoffee implements ModInitializer { public static final String MOD_ID = "plutoscoffee"; - public static final Logger logger = LogManager.getLogger("PlutosCoffeeMod"); - public static final int MOD_VERSION = 10; - - private static boolean loadLaterDone = false; + public static final Logger LOGGER = LogManager.getLogger("PlutosCoffeeMod"); @Override public void onInitialize() { @@ -31,38 +28,42 @@ public void onInitialize() { ModScreens.init(); ModStats.registerStats(); CoffeeGrounds.init(); + ModRecipes.init(); + ModSounds.init(); ModPointOfInterests.init(); ModVillagerProfessions.init(); ModVillagerProfessions.postInit(); ServerLifecycleEvents.SERVER_STARTING.register(PlutosCoffee::initStructurePoolElements); + ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener(new MachineWaterSources()); - logger.info("Pluto's Coffee Mod Initialized"); - } - - public static void loadLater() { - if (loadLaterDone) return; - VersionChecker.checkOutdated(); - if (VersionChecker.isOutdated()) { - logger.warn("Pluto's Coffee Mod is outdated, please download the new version from Curseforge or Github"); - } else { - logger.info("Pluto's Coffee Mod is up to date"); - } - loadLaterDone = true; + LOGGER.info("Pluto's Coffee Mod Initialized"); } /** * Borrowed from FriendsAndFoes by Faboslav */ public static void initStructurePoolElements(MinecraftServer server) { - Registry templatePoolRegistry = server.getRegistryManager().get(RegistryKeys.TEMPLATE_POOL); + Registry templatePoolRegistry = server.registryAccess().registryOrThrow(Registries.TEMPLATE_POOL); - Identifier snowyLocation = new Identifier("minecraft:village/snowy/houses"); + ResourceLocation snowyLocation = new ResourceLocation("minecraft:village/snowy/houses"); CoffeeUtil.addElementToStructurePool(templatePoolRegistry, snowyLocation, "village/snowy/houses/snowy_cafe", 2); + + ResourceLocation plainsLocation = new ResourceLocation("minecraft:village/plains/houses"); + CoffeeUtil.addElementToStructurePool(templatePoolRegistry, plainsLocation, "village/plains/houses/plains_cafe", 2); + + ResourceLocation desertLocation = new ResourceLocation("minecraft:village/desert/houses"); + CoffeeUtil.addElementToStructurePool(templatePoolRegistry, desertLocation, "village/desert/houses/desert_cafe", 2); + + ResourceLocation savannaLocation = new ResourceLocation("minecraft:village/savanna/houses"); + CoffeeUtil.addElementToStructurePool(templatePoolRegistry, savannaLocation, "village/savanna/houses/savanna_cafe", 2); + + ResourceLocation taigaLocation = new ResourceLocation("minecraft:village/taiga/houses"); + CoffeeUtil.addElementToStructurePool(templatePoolRegistry, taigaLocation, "village/taiga/houses/taiga_cafe", 2); } - public static Identifier asId(String id) { - return new Identifier(MOD_ID, id); + public static ResourceLocation asId(String id) { + return new ResourceLocation(MOD_ID, id); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlock.java b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlock.java index 2b335f7..67fbce4 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlock.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlock.java @@ -1,136 +1,131 @@ package ml.pluto7073.plutoscoffee.blocks; import ml.pluto7073.plutoscoffee.registry.ModBlocks; -import ml.pluto7073.plutoscoffee.registry.ModItems; import ml.pluto7073.plutoscoffee.registry.ModStats; -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityTicker; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.pathing.NavigationType; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.particle.ParticleTypes; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.ItemScatterer; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.util.RandomSource; +import net.minecraft.world.Containers; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable; -public class CoffeeBrewerBlock extends BlockWithEntity { +@SuppressWarnings("deprecation") +@MethodsReturnNonnullByDefault +public class CoffeeBrewerBlock extends BaseEntityBlock { /** * 0 - No Bottle
* 1 - Empty Bottle
* 2 - Filled Bottle */ - public static final IntProperty BOTTLE_PROPERTY; + public static final IntegerProperty BOTTLE_PROPERTY; protected static final VoxelShape SHAPE; - public CoffeeBrewerBlock(Settings settings) { + public CoffeeBrewerBlock(Properties settings) { super(settings); - this.setDefaultState(this.stateManager.getDefaultState().with(BOTTLE_PROPERTY, 0)); + this.registerDefaultState(this.stateDefinition.any().setValue(BOTTLE_PROPERTY, 0)); } - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.MODEL; + public RenderShape getRenderShape(BlockState state) { + return RenderShape.MODEL; } - public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new CoffeeBrewerBlockEntity(pos, state); } @Nullable - public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { - return world.isClient ? null : checkType(type, ModBlocks.COFFEE_BREWER_BLOCK_ENTITY_TYPE, CoffeeBrewerBlockEntity::tick); + public BlockEntityTicker getTicker(Level level, BlockState state, BlockEntityType type) { + return level.isClientSide ? null : createTickerHelper(type, ModBlocks.COFFEE_BREWER_BLOCK_ENTITY_TYPE, CoffeeBrewerBlockEntity::tick); } - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { return SHAPE; } - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (world.isClient) { - return ActionResult.SUCCESS; + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (level.isClientSide) { + return InteractionResult.SUCCESS; } else { - BlockEntity blockEntity = world.getBlockEntity(pos); + BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof CoffeeBrewerBlockEntity) { - player.openHandledScreen((CoffeeBrewerBlockEntity) blockEntity); - player.incrementStat(ModStats.INTERACT_WITH_COFFEE_BREWER); + player.openMenu((CoffeeBrewerBlockEntity) blockEntity); + player.awardStat(ModStats.INTERACT_WITH_COFFEE_BREWER); } - return ActionResult.CONSUME; + return InteractionResult.CONSUME; } } - public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { - if (stack.hasCustomName()) { + public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { + if (stack.hasCustomHoverName()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof CoffeeBrewerBlockEntity) { - ((CoffeeBrewerBlockEntity) blockEntity).setCustomName(stack.getName()); + ((CoffeeBrewerBlockEntity) blockEntity).setCustomName(stack.getHoverName()); } } } - public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { + public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) { double x = pos.getX() + 0.4 + (double) random.nextFloat() * 0.2; double y = pos.getY() + 0.3 + (double) random.nextFloat() * 0.3; double z = pos.getZ() + 0.4 + (double) random.nextFloat() * 0.2; - BlockEntity entity = world.getBlockEntity(pos); + BlockEntity entity = level.getBlockEntity(pos); if (!(entity instanceof CoffeeBrewerBlockEntity)) return; - if (((CoffeeBrewerBlockEntity) entity).propertyDelegate.get(CoffeeBrewerBlockEntity.BREW_TIME_PROPERTY_INDEX) > 0) - world.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0); + if (((CoffeeBrewerBlockEntity) entity).containerData.get(CoffeeBrewerBlockEntity.BREW_TIME_PROPERTY_INDEX) > 0) + level.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0); } - public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { - if (!state.isOf(newState.getBlock())) { - BlockEntity blockEntity = world.getBlockEntity(pos); + public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) { + if (!state.is(newState.getBlock())) { + BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof CoffeeBrewerBlockEntity) { - ItemScatterer.spawn(world, pos, (CoffeeBrewerBlockEntity) blockEntity); + Containers.dropContents(level, pos, (CoffeeBrewerBlockEntity) blockEntity); } - super.onStateReplaced(state, world, pos, newState, moved); + super.onRemove(state, level, pos, newState, movedByPiston); } } - public boolean hasComparatorOutput(BlockState state) { + public boolean hasAnalogOutputSignal(BlockState state) { return true; } - public int getComparatorOutput(BlockState state, World world, BlockPos pos) { - return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos)); + public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { + return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(world.getBlockEntity(pos)); } @Override - protected void appendProperties(StateManager.Builder builder) { + protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(BOTTLE_PROPERTY); } - public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { + public boolean isPathfindable(BlockState state, BlockGetter level, BlockPos pos, PathComputationType type) { return false; } - @Override - public Item asItem() { - return ModItems.COFFEE_BREWER; - } - - @Override - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { - return new ItemStack(ModItems.COFFEE_BREWER, 1); - } - static { - BOTTLE_PROPERTY = IntProperty.of("bottle", 0, 2); - SHAPE = Block.createCuboidShape(5, 0, 5, 11, 8, 11); + BOTTLE_PROPERTY = IntegerProperty.create("bottle", 0, 2); + SHAPE = Block.box(5, 0, 5, 11, 8, 11); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlockEntity.java b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlockEntity.java index 4eabb14..68e7dc5 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlockEntity.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlockEntity.java @@ -1,59 +1,73 @@ package ml.pluto7073.plutoscoffee.blocks; import ml.pluto7073.pdapi.item.AbstractCustomizableDrinkItem; +import ml.pluto7073.pdapi.util.BasicSingleStorage; import ml.pluto7073.plutoscoffee.CoffeeUtil; import ml.pluto7073.plutoscoffee.coffee.CoffeeType; import ml.pluto7073.plutoscoffee.coffee.CoffeeTypes; -import ml.pluto7073.plutoscoffee.gui.CoffeeBrewerScreenHandler; +import ml.pluto7073.plutoscoffee.coffee.MachineWaterSources; +import ml.pluto7073.plutoscoffee.gui.CoffeeBrewerMenu; import ml.pluto7073.plutoscoffee.registry.ModBlocks; import ml.pluto7073.plutoscoffee.registry.ModItems; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.LockableContainerBlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventories; -import net.minecraft.inventory.SidedInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.screen.PropertyDelegate; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.Text; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; +import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; +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.storage.base.FilteringStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.WorldlyContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; +import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; import java.util.Iterator; -public class CoffeeBrewerBlockEntity extends LockableContainerBlockEntity implements SidedInventory { +import static ml.pluto7073.plutoscoffee.blocks.EspressoMachineBlockEntity.WATER; + +@SuppressWarnings("UnstableApiUsage") +@MethodsReturnNonnullByDefault +public class CoffeeBrewerBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer { private static final int INPUT_SLOT_INDEX = 0; //Coffee Grounds Go Here private static final int FUEL_SLOT_INDEX = 1; //Water Bucket Goes Here private static final int[] TOP_SLOTS = {0}; private static final int[] BOTTOM_SLOTS = {0, 2}; private static final int[] SIDE_SLOTS = {1, 2}; - public static final int MAX_FUEL_USES = 6; + private static final int WATER_FOR_COFFEE = 16200; public static final int BREW_TIME_PROPERTY_INDEX = 0; public static final int FUEL_PROPERTY_INDEX = 1; public static final int PROPERTY_COUNT = 2; - private DefaultedList inventory; + private NonNullList inventory; int brewTime; private int lastTickSlot; private Item itemBrewing; - int fuel; - protected final PropertyDelegate propertyDelegate; + private final BasicSingleStorage water = + new BasicSingleStorage(WATER, 81000, this::setChanged); + public final Storage insert = FilteringStorage.insertOnlyOf(water); + protected final ContainerData containerData; public CoffeeBrewerBlockEntity(BlockPos pos, BlockState state) { super (ModBlocks.COFFEE_BREWER_BLOCK_ENTITY_TYPE, pos, state); - inventory = DefaultedList.ofSize(3, ItemStack.EMPTY); - propertyDelegate = new PropertyDelegate() { + inventory = NonNullList.withSize(3, ItemStack.EMPTY); + containerData = new ContainerData() { public int get(int index) { return switch (index) { case BREW_TIME_PROPERTY_INDEX -> CoffeeBrewerBlockEntity.this.brewTime; - case FUEL_PROPERTY_INDEX -> CoffeeBrewerBlockEntity.this.fuel; + case FUEL_PROPERTY_INDEX -> (int) CoffeeBrewerBlockEntity.this.water.amount; default -> 0; }; } @@ -61,21 +75,21 @@ public int get(int index) { public void set(int index, int value) { switch (index) { case BREW_TIME_PROPERTY_INDEX -> CoffeeBrewerBlockEntity.this.brewTime = value; - case FUEL_PROPERTY_INDEX -> CoffeeBrewerBlockEntity.this.fuel = value; + case FUEL_PROPERTY_INDEX -> CoffeeBrewerBlockEntity.this.water.amount = value; } } - public int size() { + public int getCount() { return PROPERTY_COUNT; } }; } - protected Text getContainerName() { - return Text.translatable("container.coffee_brewer"); + protected Component getDefaultName() { + return Component.translatable("container.coffee_brewer"); } - public int size() { + public int getContainerSize() { return inventory.size(); } @@ -92,14 +106,21 @@ public boolean isEmpty() { return false; } - public static void tick(World world, BlockPos pos, BlockState state, CoffeeBrewerBlockEntity blockEntity) { + public static void tick(Level level, BlockPos pos, BlockState state, CoffeeBrewerBlockEntity blockEntity) { ItemStack fuelStack = blockEntity.inventory.get(FUEL_SLOT_INDEX); - if (blockEntity.fuel <= 0 && fuelStack.isOf(Items.WATER_BUCKET)) { - blockEntity.fuel = MAX_FUEL_USES; - //noinspection DataFlowIssue - fuelStack = new ItemStack(Items.WATER_BUCKET.getRecipeRemainder(), 1); - blockEntity.inventory.set(FUEL_SLOT_INDEX, fuelStack); - markDirty(world, pos, state); + int waterAmount = MachineWaterSources.getWaterAmount(fuelStack); + trans: try (Transaction transaction = Transaction.openOuter()) { + long waterInserted = blockEntity.water.insert(WATER, waterAmount, transaction); + if (waterAmount - waterInserted > 2025) { + transaction.abort(); + break trans; + } + Item source = fuelStack.getItem().getCraftingRemainingItem(); + if (fuelStack.is(ConventionalItemTags.POTIONS)) { + source = Items.GLASS_BOTTLE; + } + blockEntity.setItem(FUEL_SLOT_INDEX, source == null ? ItemStack.EMPTY : new ItemStack(source)); + transaction.commit(); } boolean recipe = canCraft(blockEntity.inventory); @@ -110,17 +131,17 @@ public static void tick(World world, BlockPos pos, BlockState state, CoffeeBrewe --blockEntity.brewTime; boolean done = blockEntity.brewTime == 0; if (done && recipe) { - --blockEntity.fuel; - craft(world, pos, blockEntity.inventory); - markDirty(world, pos, state); - } else if (!recipe || !inputStack.isOf(blockEntity.itemBrewing)) { + blockEntity.water.amount -= WATER_FOR_COFFEE; + craft(level, pos, blockEntity.inventory); + setChanged(level, pos, state); + } else if (!recipe || !inputStack.is(blockEntity.itemBrewing)) { blockEntity.brewTime = 0; - markDirty(world, pos, state); + setChanged(level, pos, state); } - } else if (recipe && blockEntity.fuel > 0) { + } else if (recipe && blockEntity.water.amount >= WATER_FOR_COFFEE) { blockEntity.brewTime = 600; blockEntity.itemBrewing = inputStack.getItem(); - markDirty(world, pos, state); + setChanged(level, pos, state); } int slotEmpty = blockEntity.getEmptySlot(); @@ -131,25 +152,25 @@ public static void tick(World world, BlockPos pos, BlockState state, CoffeeBrewe return; } - blockState = blockState.with(CoffeeBrewerBlock.BOTTLE_PROPERTY, slotEmpty); + blockState = blockState.setValue(CoffeeBrewerBlock.BOTTLE_PROPERTY, slotEmpty); - world.setBlockState(pos, blockState, 2); + level.setBlock(pos, blockState, 2); } } private int getEmptySlot() { if (inventory.get(2).isEmpty()) { return 0; - } else if (inventory.get(2).isOf(Items.GLASS_BOTTLE)) { + } else if (inventory.get(2).is(Items.GLASS_BOTTLE)) { return 1; - } else if (inventory.get(2).isOf(ModItems.BREWED_COFFEE)) { + } else if (inventory.get(2).is(ModItems.BREWED_COFFEE)) { return 2; } else { return 0; } } - private static boolean canCraft(DefaultedList slots) { + private static boolean canCraft(NonNullList slots) { ItemStack input = slots.get(INPUT_SLOT_INDEX); if (input.isEmpty()) { return false; @@ -157,62 +178,62 @@ private static boolean canCraft(DefaultedList slots) { return false; } else { ItemStack base = slots.get(2); - return base.isOf(Items.GLASS_BOTTLE); + return base.is(Items.GLASS_BOTTLE); } } - private static void craft(World world, BlockPos pos, DefaultedList slots) { + private static void craft(Level level, BlockPos pos, NonNullList slots) { ItemStack input = slots.get(INPUT_SLOT_INDEX); CoffeeType type = CoffeeTypes.getFromGrounds(input.getItem()); ItemStack result = new ItemStack(ModItems.BREWED_COFFEE, 1); - result.getOrCreateSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", CoffeeTypes.getId(type)); + result.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", CoffeeTypes.getId(type)); slots.set(2, result); - input.decrement(1); + input.shrink(1); slots.set(INPUT_SLOT_INDEX, input); - world.syncWorldEvent(10001, pos, 0); + level.levelEvent(10001, pos, 0); } - public void readNbt(NbtCompound nbt) { - super.readNbt(nbt); - inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY); - Inventories.readNbt(nbt, inventory); + public void load(CompoundTag nbt) { + super.load(nbt); + inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); + ContainerHelper.loadAllItems(nbt, inventory); brewTime = nbt.getShort("BrewTime"); - fuel = nbt.getByte("Fuel"); + water.amount = nbt.getInt("Fuel"); } - protected void writeNbt(NbtCompound nbt) { - super.writeNbt(nbt); + protected void saveAdditional(CompoundTag nbt) { + super.saveAdditional(nbt); nbt.putShort("BrewTime", (short) brewTime); - Inventories.writeNbt(nbt, this.inventory); - nbt.putByte("Fuel", (byte) fuel); + ContainerHelper.saveAllItems(nbt, this.inventory); + nbt.putInt("Fuel", (int) water.amount); } - public ItemStack getStack(int slot) { + public ItemStack getItem(int slot) { return slot >= 0 && slot < inventory.size() ? inventory.get(slot) : ItemStack.EMPTY; } - public ItemStack removeStack(int slot, int amount) { - return Inventories.splitStack(inventory, slot, amount); + public ItemStack removeItem(int slot, int amount) { + return ContainerHelper.removeItem(inventory, slot, amount); } - public ItemStack removeStack(int slot) { - return Inventories.removeStack(inventory, slot); + public ItemStack removeItemNoUpdate(int slot) { + return ContainerHelper.takeItem(inventory, slot); } - public void setStack(int slot, ItemStack stack) { + public void setItem(int slot, ItemStack stack) { if (slot >= 0 && slot < inventory.size()) { inventory.set(slot, stack); } } - public boolean canPlayerUse(PlayerEntity player) { + public boolean stillValid(Player player) { //noinspection DataFlowIssue - if (world.getBlockEntity(pos) != this) { + if (level.getBlockEntity(worldPosition) != this) { return false; } else { - return !(player.squaredDistanceTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5) > 64.0); + return !(player.distanceToSqr(worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5) > 64.0); } } @@ -220,13 +241,13 @@ public boolean isValid(int slot, ItemStack stack) { if (slot == INPUT_SLOT_INDEX) { return CoffeeUtil.isItemACoffeeGround(stack.getItem()); } else if (slot == FUEL_SLOT_INDEX) { - return stack.isOf(Items.WATER_BUCKET); + return stack.is(Items.WATER_BUCKET); } else { - return stack.isOf(Items.GLASS_BOTTLE) && getStack(slot).isEmpty(); + return stack.is(Items.GLASS_BOTTLE) && getItem(slot).isEmpty(); } } - public int[] getAvailableSlots(Direction side) { + public int[] getSlotsForFace(Direction side) { if (side == Direction.UP) { return TOP_SLOTS; } else { @@ -234,20 +255,20 @@ public int[] getAvailableSlots(Direction side) { } } - public boolean canInsert(int slot, ItemStack stack, @Nullable Direction dir) { + public boolean canPlaceItemThroughFace(int slot, ItemStack stack, @Nullable Direction dir) { return isValid(slot, stack); } - public boolean canExtract(int slot, ItemStack stack, Direction dir) { + public boolean canTakeItemThroughFace(int slot, ItemStack stack, Direction dir) { return slot != INPUT_SLOT_INDEX; } - public void clear() { + public void clearContent() { inventory.clear(); } - protected ScreenHandler createScreenHandler(int syncId, PlayerInventory inventory) { - return new CoffeeBrewerScreenHandler(syncId, inventory, this, propertyDelegate); + protected AbstractContainerMenu createMenu(int syncId, Inventory inventory) { + return new CoffeeBrewerMenu(syncId, inventory, this, containerData); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeCrop.java b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeCrop.java index 7221011..4340a28 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeCrop.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeCrop.java @@ -3,73 +3,69 @@ import ml.pluto7073.plutoscoffee.registry.ModItems; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CropBlock; -import net.minecraft.block.ShapeContext; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemConvertible; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvents; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.event.GameEvent; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CropBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +@SuppressWarnings("deprecation") +@MethodsReturnNonnullByDefault public class CoffeeCrop extends CropBlock { - private static final VoxelShape[] AGE_TO_SHAPE = new VoxelShape[]{Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 3.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 5.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 7.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 9.0D, 16.0D)}; + private static final VoxelShape[] AGE_TO_SHAPE = new VoxelShape[] { + Block.box(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D), + Block.box(0.0D, 0.0D, 0.0D, 16.0D, 3.0D, 16.0D), + Block.box(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D), + Block.box(0.0D, 0.0D, 0.0D, 16.0D, 5.0D, 16.0D), + Block.box(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D), + Block.box(0.0D, 0.0D, 0.0D, 16.0D, 7.0D, 16.0D), + Block.box(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D), + Block.box(0.0D, 0.0D, 0.0D, 16.0D, 9.0D, 16.0D)}; - public CoffeeCrop(Settings settings) { + public CoffeeCrop(Properties settings) { super(settings); } @Environment(EnvType.CLIENT) - protected ItemConvertible getSeedsItem() { + protected ItemLike getBaseSeedId() { return ModItems.COFFEE_BERRY; } - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return AGE_TO_SHAPE[state.get(this.getAgeProperty())]; + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + return AGE_TO_SHAPE[state.getValue(this.getAgeProperty())]; } @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - int age = state.get(AGE); + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + int age = state.getValue(AGE); boolean fullyGrown = age == 7; - if (!fullyGrown && player.getStackInHand(hand).isOf(Items.BONE_MEAL)) { - return ActionResult.PASS; + if (!fullyGrown && player.getItemInHand(hand).is(Items.BONE_MEAL)) { + return InteractionResult.PASS; } else if (age >= 7) { - int rand = 1 + world.random.nextInt(2); - dropStack(world, pos, new ItemStack(ModItems.COFFEE_BERRY, rand + (fullyGrown ? 1 : 0))); - world.playSound(null, pos, SoundEvents.BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4f); - BlockState blockState = state.with(AGE, 5); - world.setBlockState(pos, blockState, 2); - world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState)); - return ActionResult.success(world.isClient); + int rand = 1 + level.random.nextInt(2); + popResource(level, pos, new ItemStack(ModItems.COFFEE_BERRY, rand + (fullyGrown ? 1 : 0))); + level.playSound(null, pos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + level.random.nextFloat() * 0.4f); + BlockState blockState = state.setValue(AGE, 5); + level.setBlock(pos, blockState, 2); + level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, blockState)); + return InteractionResult.sidedSuccess(level.isClientSide); } else { - return super.onUse(state, world, pos, player, hand, hit); + return super.use(state, level, pos, player, hand, hit); } } - @Override - public boolean emitsRedstonePower(BlockState state) { - return false; - } - - @Override - public boolean hasSidedTransparency(BlockState state) { - return true; - } - - @Override - public int getOpacity(BlockState state, BlockView world, BlockPos pos) { - return 0; - } - } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeGrindrBlock.java b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeGrindrBlock.java index d92fcb2..cfb858e 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeGrindrBlock.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeGrindrBlock.java @@ -1,136 +1,128 @@ package ml.pluto7073.plutoscoffee.blocks; import ml.pluto7073.plutoscoffee.registry.ModBlocks; -import ml.pluto7073.plutoscoffee.registry.ModItems; import ml.pluto7073.plutoscoffee.registry.ModStats; -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityTicker; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.pathing.NavigationType; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.state.property.IntProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.ItemScatterer; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; - -public class CoffeeGrindrBlock extends BlockWithEntity { +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.Containers; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; + +@SuppressWarnings("deprecation") +@MethodsReturnNonnullByDefault +public class CoffeeGrindrBlock extends BaseEntityBlock { public static final BooleanProperty FULL_PROPERTY; public static final DirectionProperty FACING_PROPERTY; protected static final VoxelShape SHAPE; - public CoffeeGrindrBlock(Settings settings) { - super(settings); - this.setDefaultState(this.getStateManager().getDefaultState() - .with(FULL_PROPERTY, false) - .with(FACING_PROPERTY, Direction.NORTH)); + public CoffeeGrindrBlock(Properties properties) { + super(properties); + this.registerDefaultState(this.getStateDefinition().any() + .setValue(FULL_PROPERTY, false) + .setValue(FACING_PROPERTY, Direction.NORTH)); } @Override - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.MODEL; + public RenderShape getRenderShape(BlockState state) { + return RenderShape.MODEL; } @Override - public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new CoffeeGrindrBlockEntity(pos, state); } @Override - public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { - return world.isClient ? null : checkType(type, ModBlocks.COFFEE_GRINDR_BLOCK_ENTITY_TYPE, CoffeeGrindrBlockEntity::tick); + public BlockEntityTicker getTicker(Level level, BlockState state, BlockEntityType type) { + return level.isClientSide ? null : createTickerHelper(type, ModBlocks.COFFEE_GRINDR_BLOCK_ENTITY_TYPE, CoffeeGrindrBlockEntity::tick); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { return SHAPE; } @Override - protected void appendProperties(StateManager.Builder builder) { + protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FULL_PROPERTY).add(FACING_PROPERTY); } @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (world.isClient) { - return ActionResult.SUCCESS; + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (level.isClientSide) { + return InteractionResult.SUCCESS; } else { - BlockEntity blockEntity = world.getBlockEntity(pos); + BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof CoffeeGrindrBlockEntity) { - player.openHandledScreen((CoffeeGrindrBlockEntity) blockEntity); - player.incrementStat(ModStats.INTERACT_WITH_COFFEE_GRINDR); + player.openMenu((CoffeeGrindrBlockEntity) blockEntity); + player.awardStat(ModStats.INTERACT_WITH_COFFEE_GRINDR); } - return ActionResult.CONSUME; + return InteractionResult.CONSUME; } } - public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { - if (stack.hasCustomName()) { - BlockEntity blockEntity = world.getBlockEntity(pos); + public void setPlacedBy(Level level, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { + if (stack.hasCustomHoverName()) { + BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof CoffeeGrindrBlockEntity) { - ((CoffeeGrindrBlockEntity) blockEntity).setCustomName(stack.getName()); + ((CoffeeGrindrBlockEntity) blockEntity).setCustomName(stack.getHoverName()); } } } - public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { - if (!state.isOf(newState.getBlock())) { - BlockEntity blockEntity = world.getBlockEntity(pos); + public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean moved) { + if (!state.is(newState.getBlock())) { + BlockEntity blockEntity = level.getBlockEntity(pos); if (blockEntity instanceof CoffeeGrindrBlockEntity) { - ItemScatterer.spawn(world, pos, (CoffeeGrindrBlockEntity) blockEntity); + Containers.dropContents(level, pos, (CoffeeGrindrBlockEntity) blockEntity); } - super.onStateReplaced(state, world, pos, newState, moved); + super.onRemove(state, level, pos, newState, moved); } } - public boolean hasComparatorOutput(BlockState state) { + public boolean hasAnalogOutputSignal(BlockState state) { return true; } - public int getComparatorOutput(BlockState state, World world, BlockPos pos) { - return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos)); + public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) { + return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos)); } - public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { + public boolean isPathfindable(BlockState state, BlockGetter world, BlockPos pos, PathComputationType type) { return false; } - public BlockState getPlacementState(ItemPlacementContext ctx) { - return this.getDefaultState().with(FACING_PROPERTY, ctx.getHorizontalPlayerFacing().getOpposite()); - } - - @Override - public Item asItem() { - return ModItems.COFFEE_GRINDR; - } - - @Override - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { - return new ItemStack(ModItems.COFFEE_GRINDR, 1); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return this.defaultBlockState().setValue(FACING_PROPERTY, ctx.getHorizontalDirection().getOpposite()); } static { - FULL_PROPERTY = BooleanProperty.of("full"); - FACING_PROPERTY = Properties.HORIZONTAL_FACING; - SHAPE = Block.createCuboidShape(3, 0, 3, 13, 16, 13); + FULL_PROPERTY = BooleanProperty.create("full"); + FACING_PROPERTY = BlockStateProperties.HORIZONTAL_FACING; + SHAPE = Block.box(3, 0, 3, 13, 16, 13); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeGrindrBlockEntity.java b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeGrindrBlockEntity.java index a094cb0..f268f72 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeGrindrBlockEntity.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeGrindrBlockEntity.java @@ -2,27 +2,29 @@ import ml.pluto7073.plutoscoffee.CoffeeUtil; import ml.pluto7073.plutoscoffee.coffee.CoffeeGrounds; -import ml.pluto7073.plutoscoffee.gui.CoffeeGrindrScreenHandler; +import ml.pluto7073.plutoscoffee.gui.CoffeeGrindrMenu; import ml.pluto7073.plutoscoffee.registry.ModBlocks; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.LockableContainerBlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventories; -import net.minecraft.inventory.SidedInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.screen.PropertyDelegate; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.Text; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.WorldlyContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; +import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; -public class CoffeeGrindrBlockEntity extends LockableContainerBlockEntity implements SidedInventory { +@MethodsReturnNonnullByDefault +public class CoffeeGrindrBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer { private static final int INPUT_SLOT_INDEX = 0; // Beans go here private static final int OUTPUT_SLOT_INDEX = 1; // Grounds come out here @@ -31,18 +33,18 @@ public class CoffeeGrindrBlockEntity extends LockableContainerBlockEntity implem private static final int[] SIDE_SLOTS = {1}; public static final int GRIND_TIME_PROPERTY_INDEX = 0; - private DefaultedList inventory; + private NonNullList inventory; int grindTime; private boolean lastTickSlot; private Item itemGrinding; - protected final PropertyDelegate propertyDelegate; + protected final ContainerData containerData; public CoffeeGrindrBlockEntity(BlockPos blockPos, BlockState blockState) { super(ModBlocks.COFFEE_GRINDR_BLOCK_ENTITY_TYPE, blockPos, blockState); - inventory = DefaultedList.ofSize(2, ItemStack.EMPTY); - propertyDelegate = new PropertyDelegate() { + inventory = NonNullList.withSize(2, ItemStack.EMPTY); + containerData = new ContainerData() { @Override public int get(int index) { return switch (index) { @@ -59,19 +61,19 @@ public void set(int index, int value) { } @Override - public int size() { + public int getCount() { return 1; } }; } @Override - protected Text getContainerName() { - return Text.translatable("container.coffee_grinder"); + protected Component getDefaultName() { + return Component.translatable("container.coffee_grinder"); } @Override - public int size() { + public int getContainerSize() { return inventory.size(); } @@ -83,7 +85,7 @@ public boolean isEmpty() { return true; } - public static void tick(World world, BlockPos pos, BlockState state, CoffeeGrindrBlockEntity blockEntity) { + public static void tick(Level level, BlockPos pos, BlockState state, CoffeeGrindrBlockEntity blockEntity) { boolean recipe = canCraft(blockEntity.inventory); boolean grinding = blockEntity.grindTime > 0; @@ -92,16 +94,16 @@ public static void tick(World world, BlockPos pos, BlockState state, CoffeeGrind --blockEntity.grindTime; boolean done = blockEntity.grindTime == 0; if (done && recipe) { - craft(world, pos, blockEntity.inventory); - markDirty(world, pos, state); - } else if (!recipe || !inputStack.isOf(blockEntity.itemGrinding)) { + craft(level, pos, blockEntity.inventory); + setChanged(level, pos, state); + } else if (!recipe || !inputStack.is(blockEntity.itemGrinding)) { blockEntity.grindTime = 0; - markDirty(world, pos, state); + setChanged(level, pos, state); } } else if (recipe) { blockEntity.grindTime = 20; blockEntity.itemGrinding = inputStack.getItem(); - markDirty(world, pos, state); + setChanged(level, pos, state); } boolean slotEmpty = blockEntity.getEmptySlot(); @@ -112,9 +114,9 @@ public static void tick(World world, BlockPos pos, BlockState state, CoffeeGrind return; } - blockState = blockState.with(CoffeeGrindrBlock.FULL_PROPERTY, slotEmpty); + blockState = blockState.setValue(CoffeeGrindrBlock.FULL_PROPERTY, slotEmpty); - world.setBlockState(pos, blockState, 2); + level.setBlock(pos, blockState, 2); } } @@ -122,7 +124,7 @@ private boolean getEmptySlot() { return !inventory.get(1).isEmpty(); } - private static boolean canCraft(DefaultedList slots) { + private static boolean canCraft(NonNullList slots) { ItemStack input = slots.get(INPUT_SLOT_INDEX); if (input.isEmpty()) return false; else if (!CoffeeUtil.isItemACoffeeBean(input.getItem())) return false; @@ -130,64 +132,64 @@ private static boolean canCraft(DefaultedList slots) { ItemStack output = slots.get(OUTPUT_SLOT_INDEX); if (output.isEmpty()) return true; - return output.isOf(CoffeeGrounds.getGrounds(input.getItem())) && output.getCount() <= output.getItem().getMaxCount() - 4; + return output.is(CoffeeGrounds.getGrounds(input.getItem())) && output.getCount() <= output.getItem().getMaxStackSize() - 4; } } - private static void craft(World world, BlockPos pos, DefaultedList slots) { + private static void craft(Level level, BlockPos pos, NonNullList slots) { ItemStack input = slots.get(INPUT_SLOT_INDEX); Item groundsResult = CoffeeGrounds.getGrounds(input.getItem()); ItemStack result = slots.get(OUTPUT_SLOT_INDEX); - if (result.isOf(groundsResult)) { - result.increment(4); + if (result.is(groundsResult)) { + result.grow(4); } result = result.isEmpty() ? new ItemStack(groundsResult, 4) : result; slots.set(OUTPUT_SLOT_INDEX, result); - input.decrement(1); + input.shrink(1); slots.set(INPUT_SLOT_INDEX, input); - world.syncWorldEvent(10002, pos, 0); + level.levelEvent(10002, pos, 0); } - public void readNbt(NbtCompound nbt) { - super.readNbt(nbt); - inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY); - Inventories.readNbt(nbt, inventory); + public void load(CompoundTag nbt) { + super.load(nbt); + inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); + ContainerHelper.loadAllItems(nbt, inventory); grindTime = nbt.getShort("GrindTime"); } - protected void writeNbt(NbtCompound nbt) { - super.writeNbt(nbt); + protected void saveAdditional(CompoundTag nbt) { + super.saveAdditional(nbt); nbt.putShort("GrindTime", (short) grindTime); - Inventories.writeNbt(nbt, this.inventory); + ContainerHelper.saveAllItems(nbt, this.inventory); } - public ItemStack getStack(int slot) { + public ItemStack getItem(int slot) { return slot >= 0 && slot < inventory.size() ? inventory.get(slot) : ItemStack.EMPTY; } - public ItemStack removeStack(int slot, int amount) { - return Inventories.splitStack(inventory, slot, amount); + public ItemStack removeItem(int slot, int amount) { + return ContainerHelper.removeItem(inventory, slot, amount); } - public ItemStack removeStack(int slot) { - return Inventories.removeStack(inventory, slot); + public ItemStack removeItemNoUpdate(int slot) { + return ContainerHelper.takeItem(inventory, slot); } - public void setStack(int slot, ItemStack stack) { + public void setItem(int slot, ItemStack stack) { if (slot >= 0 && slot < inventory.size()) { inventory.set(slot, stack); } } - public boolean canPlayerUse(PlayerEntity player) { + public boolean stillValid(Player player) { //noinspection DataFlowIssue - if (world.getBlockEntity(pos) != this) { + if (level.getBlockEntity(worldPosition) != this) { return false; } else { - return !(player.squaredDistanceTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5) > 64.0); + return !(player.distanceToSqr(worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5) > 64.0); } } @@ -199,7 +201,7 @@ public boolean isValid(int slot, ItemStack stack) { } } - public int[] getAvailableSlots(Direction side) { + public int[] getSlotsForFace(Direction side) { if (side == Direction.UP) { return TOP_SLOTS; } else { @@ -207,20 +209,20 @@ public int[] getAvailableSlots(Direction side) { } } - public boolean canInsert(int slot, ItemStack stack, @Nullable Direction dir) { + public boolean canPlaceItemThroughFace(int slot, ItemStack stack, @Nullable Direction dir) { return isValid(slot, stack); } - public boolean canExtract(int slot, ItemStack stack, Direction dir) { + public boolean canTakeItemThroughFace(int slot, ItemStack stack, Direction dir) { return slot != INPUT_SLOT_INDEX; } - public void clear() { + public void clearContent() { inventory.clear(); } - protected ScreenHandler createScreenHandler(int syncId, PlayerInventory inventory) { - return new CoffeeGrindrScreenHandler(syncId, inventory, this, propertyDelegate); + protected AbstractContainerMenu createMenu(int syncId, Inventory inventory) { + return new CoffeeGrindrMenu(syncId, inventory, this, containerData); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/blocks/EspressoMachineBlock.java b/src/main/java/ml/pluto7073/plutoscoffee/blocks/EspressoMachineBlock.java index 57ad58c..37106d2 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/blocks/EspressoMachineBlock.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/blocks/EspressoMachineBlock.java @@ -3,36 +3,40 @@ import ml.pluto7073.plutoscoffee.registry.ModBlocks; import ml.pluto7073.plutoscoffee.registry.ModItems; import ml.pluto7073.plutoscoffee.registry.ModStats; -import net.minecraft.block.*; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityTicker; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.pathing.NavigationType; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.particle.ParticleTypes; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.state.StateManager; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.ItemScatterer; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.random.Random; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.util.RandomSource; +import net.minecraft.world.Containers; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable; -public class EspressoMachineBlock extends BlockWithEntity { +@SuppressWarnings("deprecation") +@MethodsReturnNonnullByDefault +public class EspressoMachineBlock extends BaseEntityBlock { public static final BooleanProperty HAS_ESPRESSO; public static final BooleanProperty PULLING; @@ -41,108 +45,100 @@ public class EspressoMachineBlock extends BlockWithEntity { protected static VoxelShape SHAPE; - public EspressoMachineBlock(Settings settings) { + public EspressoMachineBlock(Properties settings) { super(settings); - this.setDefaultState(this.getDefaultState() - .with(HAS_ESPRESSO, false) - .with(PULLING, false) - .with(HAS_MILK, false) - .with(FACING, Direction.NORTH)); + this.registerDefaultState(this.defaultBlockState() + .setValue(HAS_ESPRESSO, false) + .setValue(PULLING, false) + .setValue(HAS_MILK, false) + .setValue(FACING, Direction.NORTH)); } - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.MODEL; + public RenderShape getRenderShape(BlockState state) { + return RenderShape.MODEL; } - public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new EspressoMachineBlockEntity(pos, state); } @Nullable - public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { - return world.isClient ? null : checkType(type, ModBlocks.ESPRESSO_MACHINE_BLOCK_ENTITY_TYPE, EspressoMachineBlockEntity::tick); + public BlockEntityTicker getTicker(Level level, BlockState state, BlockEntityType type) { + return level.isClientSide ? null : createTickerHelper(type, ModBlocks.ESPRESSO_MACHINE_BLOCK_ENTITY_TYPE, EspressoMachineBlockEntity::tick); } - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { return SHAPE; } - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (world.isClient) { - return ActionResult.SUCCESS; + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (world.isClientSide) { + return InteractionResult.SUCCESS; } else { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof EspressoMachineBlockEntity) { - player.openHandledScreen((EspressoMachineBlockEntity) blockEntity); - player.incrementStat(ModStats.INTERACT_WITH_ESPRESSO_MACHINE); + player.openMenu((EspressoMachineBlockEntity) blockEntity); + player.awardStat(ModStats.INTERACT_WITH_ESPRESSO_MACHINE); } - return ActionResult.CONSUME; + return InteractionResult.CONSUME; } } - public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { - if (stack.hasCustomName()) { + public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { + if (stack.hasCustomHoverName()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof EspressoMachineBlockEntity) { - ((EspressoMachineBlockEntity) blockEntity).setCustomName(stack.getName()); + ((EspressoMachineBlockEntity) blockEntity).setCustomName(stack.getHoverName()); } } } - public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { + public void animateTick(BlockState state, Level world, BlockPos pos, RandomSource random) { double x = pos.getX() + 0.4 + (double) random.nextFloat() * 0.2; double y = pos.getY() + 0.3 + (double) random.nextFloat() * 0.3; double z = pos.getZ() + 0.4 + (double) random.nextFloat() * 0.2; BlockEntity entity = world.getBlockEntity(pos); if (!(entity instanceof CoffeeBrewerBlockEntity)) return; - if (state.get(PULLING)) + if (state.getValue(PULLING)) world.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0); } - public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { - if (!state.isOf(newState.getBlock())) { + public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean moved) { + if (!state.is(newState.getBlock())) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof EspressoMachineBlockEntity) { - ItemScatterer.spawn(world, pos, (EspressoMachineBlockEntity) blockEntity); + Containers.dropContents(world, pos, (EspressoMachineBlockEntity) blockEntity); } - super.onStateReplaced(state, world, pos, newState, moved); + super.onRemove(state, world, pos, newState, moved); } } - public boolean hasComparatorOutput(BlockState state) { + public boolean hasAnalogOutputSignal(BlockState state) { return true; } - public int getComparatorOutput(BlockState state, World world, BlockPos pos) { - return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos)); + public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { + return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(world.getBlockEntity(pos)); } - protected void appendProperties(StateManager.Builder builder) { + protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(HAS_ESPRESSO).add(HAS_MILK).add(PULLING).add(FACING); } - public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { + public boolean isPathfindable(BlockState state, BlockGetter world, BlockPos pos, PathComputationType type) { return false; } - public Item asItem() { - return ModItems.ESPRESSO_MACHINE; - } - - public BlockState getPlacementState(ItemPlacementContext ctx) { - return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite()); - } - - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { - return new ItemStack(ModItems.ESPRESSO_MACHINE, 1); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getOpposite()); } static { - SHAPE = Block.createCuboidShape(1, 0, 1, 15, 13, 15); - HAS_ESPRESSO = BooleanProperty.of("has_espresso"); - HAS_MILK = BooleanProperty.of("has_milk"); - PULLING = BooleanProperty.of("pulling"); - FACING = Properties.HORIZONTAL_FACING; + SHAPE = Block.box(1, 0, 1, 15, 13, 15); + HAS_ESPRESSO = BooleanProperty.create("has_espresso"); + HAS_MILK = BooleanProperty.create("has_milk"); + PULLING = BooleanProperty.create("pulling"); + FACING = BlockStateProperties.HORIZONTAL_FACING; } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/blocks/EspressoMachineBlockEntity.java b/src/main/java/ml/pluto7073/plutoscoffee/blocks/EspressoMachineBlockEntity.java index f44c3ae..badb6ad 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/blocks/EspressoMachineBlockEntity.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/blocks/EspressoMachineBlockEntity.java @@ -1,32 +1,57 @@ package ml.pluto7073.plutoscoffee.blocks; -import ml.pluto7073.pdapi.DrinkUtil; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import ml.pluto7073.pdapi.item.AbstractCustomizableDrinkItem; -import ml.pluto7073.pdapi.item.PDItems; -import ml.pluto7073.plutoscoffee.CoffeeUtil; -import ml.pluto7073.plutoscoffee.gui.EspressoMachineScreenHandler; +import ml.pluto7073.pdapi.tag.PDTags; +import ml.pluto7073.pdapi.util.BasicSingleStorage; +import ml.pluto7073.plutoscoffee.coffee.MachineWaterSources; +import ml.pluto7073.plutoscoffee.gui.EspressoMachineMenu; +import ml.pluto7073.plutoscoffee.recipe.PullingRecipe; import ml.pluto7073.plutoscoffee.registry.ModBlocks; import ml.pluto7073.plutoscoffee.registry.ModItems; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.LockableContainerBlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventories; -import net.minecraft.inventory.SidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; -import net.minecraft.screen.PropertyDelegate; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.Text; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; +import ml.pluto7073.plutoscoffee.registry.ModRecipes; +import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.fluid.base.SingleFluidStorage; +import net.fabricmc.fabric.api.transfer.v1.storage.Storage; +import net.fabricmc.fabric.api.transfer.v1.storage.base.FilteringStorage; +import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Container; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.WorldlyContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.RecipeHolder; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluids; import org.jetbrains.annotations.Nullable; -public class EspressoMachineBlockEntity extends LockableContainerBlockEntity implements SidedInventory { +import java.util.Optional; + +@SuppressWarnings("UnstableApiUsage") +@MethodsReturnNonnullByDefault +public class EspressoMachineBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder { + + public static final FluidVariant WATER = FluidVariant.of(Fluids.WATER); public static final int GROUNDS_SLOT_INDEX = 0; public static final int WATER_SLOT_INDEX = 1; @@ -38,31 +63,42 @@ public class EspressoMachineBlockEntity extends LockableContainerBlockEntity imp private static final int[] TOP_SLOTS = { GROUNDS_SLOT_INDEX, MILK_SLOT_INDEX }; private static final int[] BOTTOM_SLOTS = { GROUNDS_SLOT_INDEX, MILK_SLOT_INDEX, ESPRESSO_SLOT_INDEX, TRASH_SLOT_INDEX }; private static final int[] SIDE_SLOTS = { WATER_SLOT_INDEX, MILK_SLOT_INDEX, ESPRESSO_SLOT_INDEX }; - public static final int MAX_WATER_USES = 24; + public static final int WATER_TO_ESPRESSO = 4050; + public static final int WATER_TO_STEAM = 2025; public static final int PULL_TIME_PROPERTY_INDEX = 0; public static final int STEAM_TIME_PROPERTY_INDEX = 1; public static final int WATER_PROPERTY_INDEX = 2; - public static final int PROPERTY_COUNT = 3; + public static final int TOTAL_PULL_TIME_PROPERTY_INDEX = 3; + public static final int PROPERTY_COUNT = 4; - private DefaultedList inventory; + private NonNullList inventory; private int pullTime; private int steamTime; private boolean lastTickEspresso, lastTickMilk; - int water; - protected final PropertyDelegate propertyDelegate; + protected final ContainerData containerData; + private final RecipeManager.CachedCheck matchGetter; + private final Object2IntOpenHashMap recipesUsed; + private final SingleFluidStorage waterStorage = new BasicSingleStorage(WATER, FluidConstants.BUCKET, this::setChanged); + public final Storage insert = FilteringStorage.insertOnlyOf(waterStorage); public EspressoMachineBlockEntity(BlockPos pos, BlockState state) { super(ModBlocks.ESPRESSO_MACHINE_BLOCK_ENTITY_TYPE, pos, state); - this.inventory = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY); - this.propertyDelegate = new PropertyDelegate() { + this.inventory = NonNullList.withSize(INVENTORY_SIZE, ItemStack.EMPTY); + this.containerData = new ContainerData() { @Override public int get(int index) { return switch (index) { case PULL_TIME_PROPERTY_INDEX -> pullTime; case STEAM_TIME_PROPERTY_INDEX -> steamTime; - case WATER_PROPERTY_INDEX -> water; + case WATER_PROPERTY_INDEX -> (int) waterStorage.amount; + case TOTAL_PULL_TIME_PROPERTY_INDEX -> { + if (getItem(GROUNDS_SLOT_INDEX).isEmpty()) yield 400; + Optional recipe = matchGetter.getRecipeFor(EspressoMachineBlockEntity.this, level); + if (recipe.isEmpty()) yield 400; + yield recipe.get().pullTime; + } default -> 0; }; } @@ -72,22 +108,24 @@ public void set(int index, int value) { switch (index) { case PULL_TIME_PROPERTY_INDEX -> pullTime = value; case STEAM_TIME_PROPERTY_INDEX -> steamTime = value; - case WATER_PROPERTY_INDEX -> water = value; + case WATER_PROPERTY_INDEX -> waterStorage.amount = value; } } @Override - public int size() { + public int getCount() { return PROPERTY_COUNT; } }; + this.matchGetter = RecipeManager.createCheck(ModRecipes.PULLING_RECIPE_TYPE); + this.recipesUsed = new Object2IntOpenHashMap<>(); } - protected Text getContainerName() { - return Text.translatable("container.espresso_machine"); + protected Component getDefaultName() { + return Component.translatable("container.espresso_machine"); } - public int size() { return inventory.size(); } + public int getContainerSize() { return inventory.size(); } public boolean isEmpty() { for (ItemStack stack : inventory) { @@ -96,38 +134,53 @@ public boolean isEmpty() { return true; } - public static void tick(World world, BlockPos pos, BlockState state, EspressoMachineBlockEntity blockEntity) { + public static void tick(Level level, BlockPos pos, BlockState state, EspressoMachineBlockEntity blockEntity) { ItemStack fuelStack = blockEntity.inventory.get(WATER_SLOT_INDEX); - if (blockEntity.water <= 0 && fuelStack.isOf(Items.WATER_BUCKET)) { - blockEntity.water = MAX_WATER_USES; - //noinspection DataFlowIssue - fuelStack = new ItemStack(Items.WATER_BUCKET.getRecipeRemainder(), 1); - blockEntity.inventory.set(WATER_SLOT_INDEX, fuelStack); - markDirty(world, pos, state); + int waterAmount = MachineWaterSources.getWaterAmount(fuelStack); + trans: try (Transaction transaction = Transaction.openOuter()) { + long waterInserted = blockEntity.waterStorage.insert(WATER, waterAmount, transaction); + if (waterAmount - waterInserted > 2025) { + transaction.abort(); + break trans; + } + Item source = fuelStack.getItem().getCraftingRemainingItem(); + if (fuelStack.is(ConventionalItemTags.POTIONS)) { + source = Items.GLASS_BOTTLE; + } + blockEntity.setItem(WATER_SLOT_INDEX, source == null ? ItemStack.EMPTY : new ItemStack(source)); + transaction.commit(); } // Espresso Section - boolean recipe = canPull(blockEntity.inventory); - boolean pulling = blockEntity.pullTime > 0; + PullingRecipe recipe; + + if (blockEntity.inventory.get(GROUNDS_SLOT_INDEX).isEmpty()) { + recipe = null; + } else { + recipe = blockEntity.matchGetter.getRecipeFor(blockEntity, level).orElse(null); + } + + boolean canPull = canPull(blockEntity.inventory, recipe); + boolean pulling = blockEntity.pullTime > 0 && recipe != null; if (pulling) { --blockEntity.pullTime; boolean done = blockEntity.pullTime == 0; - state = state.with(EspressoMachineBlock.PULLING, true); - if (done && recipe) { - blockEntity.water -= 2; - pull(world, pos, blockEntity.inventory); - state = state.with(EspressoMachineBlock.PULLING, false); - markDirty(world, pos, state); - } else if (!recipe) { + state = state.setValue(EspressoMachineBlock.PULLING, true); + if (done && canPull) { + blockEntity.waterStorage.amount -= WATER_TO_ESPRESSO; + pull(level, pos, blockEntity, recipe); + state = state.setValue(EspressoMachineBlock.PULLING, false); + setChanged(level, pos, state); + } else if (!canPull) { blockEntity.pullTime = 0; - state = state.with(EspressoMachineBlock.PULLING, false); - markDirty(world, pos, state); + state = state.setValue(EspressoMachineBlock.PULLING, false); + setChanged(level, pos, state); } - } else if (recipe && blockEntity.water > 1) { - blockEntity.pullTime = 400; - markDirty(world, pos, state); + } else if (canPull && blockEntity.waterStorage.amount >= WATER_TO_ESPRESSO) { + blockEntity.pullTime = recipe.pullTime; + setChanged(level, pos, state); } boolean hasEspresso = !blockEntity.inventory.get(ESPRESSO_SLOT_INDEX).isEmpty() || !blockEntity.inventory.get(ESPRESSO_SLOT_2_INDEX).isEmpty(); if (hasEspresso != blockEntity.lastTickEspresso) { @@ -136,9 +189,9 @@ public static void tick(World world, BlockPos pos, BlockState state, EspressoMac return; } - state = state.with(EspressoMachineBlock.HAS_ESPRESSO, hasEspresso); + state = state.setValue(EspressoMachineBlock.HAS_ESPRESSO, hasEspresso); - world.setBlockState(pos, state, 2); + level.setBlock(pos, state, 2); } boolean hasMilk = !blockEntity.inventory.get(MILK_SLOT_INDEX).isEmpty(); @@ -148,126 +201,141 @@ public static void tick(World world, BlockPos pos, BlockState state, EspressoMac return; } - state = state.with(EspressoMachineBlock.HAS_MILK, hasMilk); + state = state.setValue(EspressoMachineBlock.HAS_MILK, hasMilk); - world.setBlockState(pos, state, 2); + level.setBlock(pos, state, 2); } ItemStack milkStack = blockEntity.inventory.get(MILK_SLOT_INDEX); - boolean steaming = milkStack.isOf(PDItems.MILK_BOTTLE) || milkStack.isOf(ModItems.LATTE); + boolean steaming = (milkStack.is(PDTags.MILK_BOTTLES) || milkStack.is(ModItems.LATTE)) && blockEntity.waterStorage.amount >= WATER_TO_STEAM; if (steaming) { blockEntity.steamTime++; if (blockEntity.steamTime > 600) blockEntity.steamTime = 600; - if (milkStack.isOf(PDItems.MILK_BOTTLE) && blockEntity.steamTime >= 400) { + if (milkStack.is(PDTags.MILK_BOTTLES) && blockEntity.steamTime >= 400) { milkStack = new ItemStack(ModItems.LATTE); - } else if (milkStack.isOf(ModItems.LATTE) && blockEntity.steamTime >= 500) { - NbtList resAdds = new NbtList(); - resAdds.add(DrinkUtil.stringAsNbt("pdapi:burnt")); - milkStack.getOrCreateSubNbt(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).put("Additions", resAdds); + } else if (milkStack.is(ModItems.LATTE) && blockEntity.steamTime >= 500) { + ListTag resAdds = new ListTag(); + if (!resAdds.contains(StringTag.valueOf("pdapi:burnt"))) resAdds.add(StringTag.valueOf("pdapi:burnt")); + milkStack.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).put("Additions", resAdds); } blockEntity.inventory.set(MILK_SLOT_INDEX, milkStack); } else { + if (blockEntity.steamLastTick) { + if (blockEntity.steamTime >= 400) blockEntity.waterStorage.amount -= WATER_TO_STEAM; + } blockEntity.steamTime = 0; } + + blockEntity.steamLastTick = steaming; } - private static boolean canPull(DefaultedList slots) { - ItemStack input = slots.get(GROUNDS_SLOT_INDEX); + private boolean steamLastTick = false; + + private static boolean canPull(NonNullList slots, PullingRecipe recipe) { + if (recipe == null) return false; + ItemStack grounds = slots.get(GROUNDS_SLOT_INDEX); + if (grounds.getCount() < recipe.groundsRequired) return false; ItemStack trash = slots.get(TRASH_SLOT_INDEX); - if (input.isEmpty()) return false; - if (input.getCount() < 2) return false; - if (!input.isOf(ModItems.GROUND_ESPRESSO_ROAST)) return false; - if (trash.getCount() > trash.getItem().getMaxCount() - 2) return false; - if (!(trash.isOf(ModItems.USED_COFFEE_GROUNDS) || trash.isEmpty())) return false; - return slots.get(ESPRESSO_SLOT_INDEX).isOf(Items.GLASS_BOTTLE) || slots.get(ESPRESSO_SLOT_2_INDEX).isOf(Items.GLASS_BOTTLE); + if (trash.getCount() > trash.getItem().getMaxStackSize() - recipe.groundsRequired) return false; + return trash.is(ModItems.USED_COFFEE_GROUNDS) || trash.isEmpty(); } - private static void pull(World world, BlockPos pos, DefaultedList slots) { - ItemStack input = slots.get(GROUNDS_SLOT_INDEX); - ItemStack trash = slots.get(TRASH_SLOT_INDEX); - input.decrement(2); + private static void pull(Level level, BlockPos pos, Container slots, PullingRecipe recipe) { + ItemStack input = slots.getItem(GROUNDS_SLOT_INDEX); + ItemStack trash = slots.getItem(TRASH_SLOT_INDEX); + input.shrink(recipe.groundsRequired); if (trash.isEmpty()) { - trash = new ItemStack(ModItems.USED_COFFEE_GROUNDS, 2); + trash = new ItemStack(ModItems.USED_COFFEE_GROUNDS, recipe.groundsRequired); } else { - trash.increment(2); + trash.grow(recipe.groundsRequired); } - ItemStack out1 = slots.get(ESPRESSO_SLOT_INDEX), - out2 = slots.get(ESPRESSO_SLOT_2_INDEX); + ItemStack out1 = slots.getItem(ESPRESSO_SLOT_INDEX), + out2 = slots.getItem(ESPRESSO_SLOT_2_INDEX); - if (out1.isOf(Items.GLASS_BOTTLE)) { - out1 = new ItemStack(ModItems.ESPRESSO_SHOT, 1); - slots.set(ESPRESSO_SLOT_INDEX, out1); + if (recipe.base.test(out1)) { + out1 = recipe.assemble(slots, level.registryAccess()); + slots.setItem(ESPRESSO_SLOT_INDEX, out1); } - if (out2.isOf(Items.GLASS_BOTTLE)) { - out2 = new ItemStack(ModItems.ESPRESSO_SHOT, 1); - slots.set(ESPRESSO_SLOT_2_INDEX, out2); + if (recipe.base.test(out2)) { + out2 = recipe.assemble(slots, level.registryAccess()); + slots.setItem(ESPRESSO_SLOT_2_INDEX, out2); } - slots.set(GROUNDS_SLOT_INDEX, input); - slots.set(TRASH_SLOT_INDEX, trash); + slots.setItem(GROUNDS_SLOT_INDEX, input); + slots.setItem(TRASH_SLOT_INDEX, trash); - world.syncWorldEvent(10003, pos, 0); + level.levelEvent(10003, pos, 0); } - public void readNbt(NbtCompound nbt) { - super.readNbt(nbt); - inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY); - Inventories.readNbt(nbt, inventory); + public void load(CompoundTag nbt) { + super.load(nbt); + inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); + ContainerHelper.loadAllItems(nbt, inventory); pullTime = nbt.getShort("PullTime"); - water = nbt.getShort("Water"); + if (nbt.contains("Variant")) + waterStorage.variant = FluidVariant.fromNbt(nbt.getCompound("Variant")); + waterStorage.amount = nbt.getInt("Water"); steamTime = nbt.getShort("SteamTime"); + CompoundTag used = nbt.getCompound("RecipesUsed"); + for (String s : used.getAllKeys()) { + recipesUsed.put(new ResourceLocation(s), used.getInt(s)); + } } - protected void writeNbt(NbtCompound nbt) { - super.writeNbt(nbt); - Inventories.writeNbt(nbt, inventory); + protected void saveAdditional(CompoundTag nbt) { + super.saveAdditional(nbt); + ContainerHelper.saveAllItems(nbt, inventory); nbt.putShort("PullTime", (short) pullTime); - nbt.putShort("Water", (short) water); + nbt.put("Variant", waterStorage.variant.toNbt()); + nbt.putInt("Water", (int) waterStorage.amount); nbt.putShort("SteamTime", (short) steamTime); + CompoundTag used = new CompoundTag(); + recipesUsed.forEach((id, i) -> used.putInt(id.toString(), i)); + nbt.put("RecipesUsed", used); } - public ItemStack getStack(int slot) { + public ItemStack getItem(int slot) { return slot >= 0 && slot < inventory.size() ? inventory.get(slot) : ItemStack.EMPTY; } - public ItemStack removeStack(int slot, int amount) { - return Inventories.splitStack(inventory, slot, amount); + public ItemStack removeItem(int slot, int amount) { + return ContainerHelper.removeItem(inventory, slot, amount); } - public ItemStack removeStack(int slot) { - return Inventories.removeStack(inventory, slot); + public ItemStack removeItemNoUpdate(int slot) { + return ContainerHelper.takeItem(inventory, slot); } - public void setStack(int slot, ItemStack stack) { + public void setItem(int slot, ItemStack stack) { if (slot >= 0 && slot < inventory.size()) { inventory.set(slot, stack); } } - public boolean canPlayerUse(PlayerEntity player) { + public boolean stillValid(Player player) { //noinspection DataFlowIssue - if (world.getBlockEntity(pos) != this) { + if (level.getBlockEntity(worldPosition) != this) { return false; } else { - return !(player.squaredDistanceTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5) > 64.0); + return !(player.distanceToSqr(worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5) > 64.0); } } public boolean isValid(int slot, ItemStack stack) { return switch (slot) { - case GROUNDS_SLOT_INDEX -> stack.isOf(ModItems.GROUND_ESPRESSO_ROAST); - case ESPRESSO_SLOT_INDEX,ESPRESSO_SLOT_2_INDEX -> getStack(slot).isEmpty() && stack.isOf(Items.GLASS_BOTTLE); - case MILK_SLOT_INDEX -> getStack(slot).isEmpty() && (stack.isOf(PDItems.MILK_BOTTLE) || stack.isOf(ModItems.LATTE)); - case WATER_SLOT_INDEX -> stack.isOf(Items.WATER_BUCKET); + case GROUNDS_SLOT_INDEX -> stack.is(ModItems.GROUND_ESPRESSO_ROAST); + case ESPRESSO_SLOT_INDEX,ESPRESSO_SLOT_2_INDEX -> getItem(slot).isEmpty() && stack.is(Items.GLASS_BOTTLE); + case MILK_SLOT_INDEX -> getItem(slot).isEmpty() && (stack.is(PDTags.MILK_BOTTLES) || stack.is(ModItems.LATTE)); + case WATER_SLOT_INDEX -> stack.is(Items.WATER_BUCKET); default -> false; }; } - public int[] getAvailableSlots(Direction side) { + public int[] getSlotsForFace(Direction side) { if (side == Direction.UP) { return TOP_SLOTS; } else { @@ -275,20 +343,34 @@ public int[] getAvailableSlots(Direction side) { } } - public boolean canInsert(int slot, ItemStack stack, @Nullable Direction dir) { + public boolean canPlaceItemThroughFace(int slot, ItemStack stack, @Nullable Direction dir) { return isValid(slot, stack); } - public boolean canExtract(int slot, ItemStack stack, Direction dir) { + public boolean canTakeItemThroughFace(int slot, ItemStack stack, Direction dir) { return slot != GROUNDS_SLOT_INDEX; } - public void clear() { + public void clearContent() { inventory.clear(); } - protected ScreenHandler createScreenHandler(int syncId, PlayerInventory inventory) { - return new EspressoMachineScreenHandler(syncId, inventory, this, propertyDelegate); + protected AbstractContainerMenu createMenu(int syncId, Inventory inventory) { + return new EspressoMachineMenu(syncId, inventory, this, containerData); + } + + @Override + public void setRecipeUsed(@Nullable Recipe recipe) { + if (recipe != null) { + ResourceLocation resourceLocation = recipe.getId(); + this.recipesUsed.addTo(resourceLocation, 1); + } + + } + + @Nullable + public Recipe getRecipeUsed() { + return null; } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeGrounds.java b/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeGrounds.java index 3912ce3..46b887e 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeGrounds.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeGrounds.java @@ -1,8 +1,8 @@ package ml.pluto7073.plutoscoffee.coffee; +import com.google.common.collect.ImmutableMap; import ml.pluto7073.plutoscoffee.registry.ModItems; -import ml.pluto7073.plutoscoffee.tags.ModItemTags; -import net.minecraft.item.Item; +import net.minecraft.world.item.Item; import java.util.HashMap; @@ -24,11 +24,16 @@ public static Item getBeans(Item groundsItem) { return GROUNDS_TO_BEANS_REGISTRY.get(groundsItem); } + public static ImmutableMap getBeansToGroundsRegistry() { + return ImmutableMap.copyOf(BEANS_TO_GROUNDS_REGISTRY); + } + static { register(ModItems.LIGHT_ROAST_BEAN, ModItems.GROUND_LIGHT_ROAST); register(ModItems.MEDIUM_ROAST_BEAN, ModItems.GROUND_MEDIUM_ROAST); register(ModItems.DARK_ROAST_BEAN, ModItems.GROUND_DARK_ROAST); register(ModItems.ESPRESSO_ROAST_BEAN, ModItems.GROUND_ESPRESSO_ROAST); + register(ModItems.DECAF_ROAST_BEAN, ModItems.GROUND_DECAF_ROAST); } public static void init() {} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeType.java b/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeType.java index 3b552c9..97b61b7 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeType.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeType.java @@ -1,41 +1,40 @@ package ml.pluto7073.plutoscoffee.coffee; -import ml.pluto7073.pdapi.addition.OnDrink; import ml.pluto7073.plutoscoffee.PlutosCoffee; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; -import net.minecraft.world.World; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; public class CoffeeType { private final String baseName; private final Item grounds; - private final OnDrink action; private final int caffeineContent; @SuppressWarnings("unused") public static final String ZELDA = null; public static CoffeeType byId(String id) { + CoffeeType type; if (id.contains(":")) { - return CoffeeTypes.REGISTRY.get(new Identifier(id.replace("\"", ""))); + type = CoffeeTypes.REGISTRY.get(new ResourceLocation(id.replace("\"", ""))); + } else { + type = CoffeeTypes.REGISTRY.get(new ResourceLocation(PlutosCoffee.MOD_ID, id.replace("\"", ""))); } - return CoffeeTypes.REGISTRY.get(new Identifier(PlutosCoffee.MOD_ID, id.replace("\"", ""))); + if (type == null) { + type = CoffeeTypes.EMPTY; + } + return type; } /** * * @param baseName the id used in registering the coffee type * @param grounds the item to be used to brew the coffee - * @param action do this when this coffee type is drank * @param caffeineContent amount in mg of caffeine to add to the drinker. */ - public CoffeeType(String baseName, Item grounds, OnDrink action, int caffeineContent) { + public CoffeeType(String baseName, Item grounds, int caffeineContent) { this.baseName = baseName; this.grounds = grounds; - this.action = action; this.caffeineContent = caffeineContent; } @@ -47,10 +46,6 @@ public Item getGrounds() { return grounds; } - public void onDrink(ItemStack stack, World world, LivingEntity user) { - action.onDrink(stack, world, user); - } - public int getCaffeineContent() { return caffeineContent; } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeTypes.java b/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeTypes.java index 100d925..3ab15f3 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeTypes.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/coffee/CoffeeTypes.java @@ -1,12 +1,10 @@ package ml.pluto7073.plutoscoffee.coffee; import ml.pluto7073.plutoscoffee.registry.ModItems; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.item.Item; -import net.minecraft.item.Items; -import net.minecraft.registry.Registries; -import net.minecraft.util.Identifier; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; import java.util.HashMap; import java.util.Map; @@ -14,16 +12,17 @@ public class CoffeeTypes { - public static final Map REGISTRY = new HashMap<>(); + public static final Map REGISTRY = new HashMap<>(); public static final CoffeeType EMPTY; public static final CoffeeType LIGHT_ROAST; public static final CoffeeType MEDIUM_ROAST; public static final CoffeeType DARK_ROAST; public static final CoffeeType ESPRESSO; + public static final CoffeeType DECAF; public static CoffeeType register(String id, CoffeeType type) { - REGISTRY.put(new Identifier("plutoscoffee", id), type); + REGISTRY.put(new ResourceLocation("plutoscoffee", id), type); return type; } @@ -31,37 +30,32 @@ public static String getId(CoffeeType type) { return getIdentifier(type).getPath(); } - public static Identifier getIdentifier(CoffeeType type) { - Set keySet = REGISTRY.keySet(); - for (Identifier i : keySet) { + public static ResourceLocation getIdentifier(CoffeeType type) { + Set keySet = REGISTRY.keySet(); + for (ResourceLocation i : keySet) { if (REGISTRY.get(i).equals(type)) { return i; } } - return new Identifier("plutoscoffee:empty"); + return new ResourceLocation("plutoscoffee:empty"); } public static CoffeeType getFromGrounds(Item grounds) { - for (Identifier i : REGISTRY.keySet()) { + for (ResourceLocation i : REGISTRY.keySet()) { if (REGISTRY.get(i).getGrounds() == grounds) { return REGISTRY.get(i); } } - throw new IllegalArgumentException("No Such CoffeeType with Grounds: " + Registries.ITEM.getId(grounds)); + throw new IllegalArgumentException("No Such CoffeeType with Grounds: " + BuiltInRegistries.ITEM.getId(grounds)); } static { - EMPTY = register("empty", new CoffeeType("empty", Items.AIR, (stack, world, user) -> {}, 0)); - LIGHT_ROAST = register("light_roast", new CoffeeType("light_roast", ModItems.GROUND_LIGHT_ROAST, (stack, world, user) -> { - //TODO: Light roast exclusives - }, 125)); - MEDIUM_ROAST = register("medium_roast", new CoffeeType("medium_roast", ModItems.GROUND_MEDIUM_ROAST, (stack, world, user) -> { - }, 120)); - DARK_ROAST = register("dark_roast", new CoffeeType("dark_roast", ModItems.GROUND_DARK_ROAST, (stack, world, user) -> { - //TODO: Dark roast exclusives - }, 115)); - ESPRESSO = register("espresso", new CoffeeType("espresso", ModItems.GROUND_ESPRESSO_ROAST, (stack, world, user) -> { - }, 100)); + EMPTY = register("empty", new CoffeeType("empty", Items.AIR, 0)); + LIGHT_ROAST = register("light_roast", new CoffeeType("light_roast", ModItems.GROUND_LIGHT_ROAST, 125)); + MEDIUM_ROAST = register("medium_roast", new CoffeeType("medium_roast", ModItems.GROUND_MEDIUM_ROAST, 120)); + DARK_ROAST = register("dark_roast", new CoffeeType("dark_roast", ModItems.GROUND_DARK_ROAST, 115)); + ESPRESSO = register("espresso", new CoffeeType("espresso", ModItems.GROUND_ESPRESSO_ROAST, 100)); + DECAF = register("decaf", new CoffeeType("decaf", ModItems.GROUND_DECAF_ROAST, 7)); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/coffee/MachineWaterSource.java b/src/main/java/ml/pluto7073/plutoscoffee/coffee/MachineWaterSource.java new file mode 100644 index 0000000..fa71f62 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/coffee/MachineWaterSource.java @@ -0,0 +1,17 @@ +package ml.pluto7073.plutoscoffee.coffee; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.item.crafting.Ingredient; + +public record MachineWaterSource(Ingredient ingredient, int waterAmount) { + + public static MachineWaterSource read(FriendlyByteBuf buf) { + return new MachineWaterSource(Ingredient.fromNetwork(buf), buf.readInt()); + } + + public static void write(FriendlyByteBuf buf, MachineWaterSource source) { + source.ingredient.toNetwork(buf); + buf.writeInt(source.waterAmount); + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/coffee/MachineWaterSources.java b/src/main/java/ml/pluto7073/plutoscoffee/coffee/MachineWaterSources.java new file mode 100644 index 0000000..7530c2d --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/coffee/MachineWaterSources.java @@ -0,0 +1,100 @@ +package ml.pluto7073.plutoscoffee.coffee; + +import com.google.gson.JsonObject; +import ml.pluto7073.plutoscoffee.PlutosCoffee; +import ml.pluto7073.plutoscoffee.network.s2c.SyncMachineWaterSourcesRegistryS2CPacket; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; +import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.packs.resources.Resource; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.item.crafting.Ingredient; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public class MachineWaterSources implements SimpleSynchronousResourceReloadListener { + + private static final ResourceLocation PHASE = PlutosCoffee.asId("phase/water_sources"); + private static final HashMap REGISTRY = new HashMap<>(); + + public MachineWaterSources() { + ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.register(PHASE, (player, joined) -> send(player)); + } + + public static void resetRegistry() { + REGISTRY.clear(); + } + + public static MachineWaterSource register(ResourceLocation id, MachineWaterSource source) { + REGISTRY.put(id, source); + return source; + } + + public static MachineWaterSource get(ResourceLocation id) { + return REGISTRY.get(id); + } + + public static Ingredient asIngredient() { + ArrayList list = new ArrayList<>(); + for (MachineWaterSource s : REGISTRY.values()) { + list.addAll(Stream.of(s.ingredient().getItems()).peek(stack -> { + if (stack.is(ConventionalItemTags.POTIONS)) { + PotionUtils.setPotion(stack, Potions.WATER); + } + }).toList()); + } + return Ingredient.of(list.stream()); + } + + public static int getWaterAmount(ItemStack item) { + for (MachineWaterSource s : REGISTRY.values()) { + if (s.ingredient().test(item)) return s.waterAmount(); + } + return 0; + } + + public static void send(ServerPlayer player) { + ServerPlayNetworking.send(player, new SyncMachineWaterSourcesRegistryS2CPacket(REGISTRY)); + } + + @Override + public ResourceLocation getFabricId() { + return PHASE; + } + + @Override + public void onResourceManagerReload(ResourceManager resourceManager) { + REGISTRY.clear(); + + for (Map.Entry e : + resourceManager.listResources("machine_water_sources", id -> id.getPath().endsWith(".json")).entrySet()) { + ResourceLocation id = e.getKey().withPath(path -> path.replace("machine_water_sources/", "").replace(".json", "")); + try (InputStream stream = e.getValue().open()) { + JsonObject data = GsonHelper.parse(new InputStreamReader(stream)); + MachineWaterSource source = fromJson(data); + register(id, source); + } catch (Exception ex) { + PlutosCoffee.LOGGER.error("Failed to load Coffee Machine Water Source {}", id, ex); + } + } + } + + private static MachineWaterSource fromJson(JsonObject data) { + Ingredient source = Ingredient.fromJson(GsonHelper.getAsJsonObject(data, "source")); + int water = GsonHelper.getAsInt(data, "water"); + return new MachineWaterSource(source, water); + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeModMenuApiImpl.java b/src/main/java/ml/pluto7073/plutoscoffee/compat/modmenu/CoffeeModMenuApiImpl.java similarity index 59% rename from src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeModMenuApiImpl.java rename to src/main/java/ml/pluto7073/plutoscoffee/compat/modmenu/CoffeeModMenuApiImpl.java index 1a33a5a..0854381 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeModMenuApiImpl.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/compat/modmenu/CoffeeModMenuApiImpl.java @@ -1,4 +1,4 @@ -package ml.pluto7073.plutoscoffee.config; +package ml.pluto7073.plutoscoffee.compat.modmenu; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; @@ -6,10 +6,8 @@ import me.shedaniel.clothconfig2.api.ConfigCategory; import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; import ml.pluto7073.plutoscoffee.Client; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; - -import java.io.File; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; public class CoffeeModMenuApiImpl implements ModMenuApi { @@ -18,17 +16,17 @@ public ConfigScreenFactory getModConfigScreenFactory() { return (parent) -> { ConfigBuilder builder = ConfigBuilder.create() .setParentScreen(parent) - .setTitle(Text.translatable("title.plutoscoffee.config")) - .setSavingRunnable(() -> Client.CONFIG.save(new File("config/plutoscoffee.properties"))) - .setDefaultBackgroundTexture(new Identifier("minecraft:textures/gui/options_background.png")); + .setTitle(Component.translatable("title.plutoscoffee.config")) + .setSavingRunnable(() -> Client.CONFIG.save()) + .setDefaultBackgroundTexture(new ResourceLocation("minecraft:textures/gui/options_background.png")); - ConfigCategory category = builder.getOrCreateCategory(Text.translatable("title.plutoscoffee.config")); + ConfigCategory category = builder.getOrCreateCategory(Component.translatable("title.plutoscoffee.config")); ConfigEntryBuilder entryBuilder = builder.entryBuilder(); - category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("config.plutoscoffee.shouldShowCoffeeBar"), Client.CONFIG.shouldShowCoffeeBar()) + category.addEntry(entryBuilder.startBooleanToggle(Component.translatable("config.plutoscoffee.shouldShowCoffeeBar"), Client.CONFIG.shouldShowCoffeeBar()) .setDefaultValue(true) - .setTooltip(Text.translatable("config.plutoscoffee.shouldShowCoffeeBar.tooltip")) + .setTooltip(Component.translatable("config.plutoscoffee.shouldShowCoffeeBar.tooltip")) .setSaveConsumer(newVal -> Client.CONFIG.setShouldShowCoffeeBar(newVal)) .build()); diff --git a/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/CoffeeREI.java b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/CoffeeREI.java new file mode 100644 index 0000000..a915d10 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/CoffeeREI.java @@ -0,0 +1,54 @@ +package ml.pluto7073.plutoscoffee.compat.rei; + +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.category.ButtonArea; +import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; +import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; +import me.shedaniel.rei.api.common.display.basic.BasicDisplay; +import me.shedaniel.rei.api.common.util.EntryStacks; +import ml.pluto7073.plutoscoffee.PlutosCoffee; +import ml.pluto7073.plutoscoffee.coffee.CoffeeGrounds; +import ml.pluto7073.plutoscoffee.compat.rei.category.GrindingCategory; +import ml.pluto7073.plutoscoffee.compat.rei.category.PullingCategory; +import ml.pluto7073.plutoscoffee.compat.rei.display.GrindingDisplay; +import ml.pluto7073.plutoscoffee.compat.rei.display.PullingDisplay; +import ml.pluto7073.plutoscoffee.recipe.PullingRecipe; +import ml.pluto7073.plutoscoffee.registry.ModItems; +import ml.pluto7073.plutoscoffee.registry.ModRecipes; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; + +public class CoffeeREI implements REIClientPlugin { + + public static final CategoryIdentifier PULLING_DISPLAY = CategoryIdentifier.of(PlutosCoffee.asId("pulling")); + public static final CategoryIdentifier GRINDING_DISPLAY = CategoryIdentifier.of(PlutosCoffee.asId("grinding")); + + @Override + public void registerCategories(CategoryRegistry registry) { + registry.add(new PullingCategory()); + registry.configure(PULLING_DISPLAY, configuration -> configuration.setPlusButtonArea(ButtonArea.defaultArea())); + registry.addWorkstations(PULLING_DISPLAY, EntryStacks.of(ModItems.ESPRESSO_MACHINE)); + + registry.add(new GrindingCategory()); + registry.addWorkstations(GRINDING_DISPLAY, EntryStacks.of(ModItems.COFFEE_GRINDR)); + } + + @Override + public void registerDisplays(DisplayRegistry registry) { + registry.registerRecipeFiller(PullingRecipe.class, ModRecipes.PULLING_RECIPE_TYPE, PullingDisplay::new); + registry.registerFiller(GrindingRecipe.class, GrindingDisplay::new); + + CoffeeGrounds.getBeansToGroundsRegistry().forEach((beans, grounds) -> registry.add(new GrindingRecipe(Ingredient.of(beans), new ItemStack(grounds)))); + } + + @Override + public void registerDisplaySerializer(DisplaySerializerRegistry registry) { + registry.register(PULLING_DISPLAY, BasicDisplay.Serializer.ofRecipeLess(PullingDisplay::new, (display, tag) -> { + tag.putInt("pullTime", display.getPullTime()); + tag.putInt("groundsRequired", display.getGroundsRequired()); + })); + registry.register(GRINDING_DISPLAY, GrindingDisplay.serializer()); + } +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/GrindingRecipe.java b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/GrindingRecipe.java new file mode 100644 index 0000000..8fba3b4 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/GrindingRecipe.java @@ -0,0 +1,8 @@ +package ml.pluto7073.plutoscoffee.compat.rei; + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; + +public record GrindingRecipe(Ingredient beans, ItemStack grounds) { + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/category/GrindingCategory.java b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/category/GrindingCategory.java new file mode 100644 index 0000000..1a54b8e --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/category/GrindingCategory.java @@ -0,0 +1,50 @@ +package ml.pluto7073.plutoscoffee.compat.rei.category; + +import com.google.common.collect.Lists; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.util.EntryStacks; +import ml.pluto7073.plutoscoffee.compat.rei.CoffeeREI; +import ml.pluto7073.plutoscoffee.compat.rei.display.GrindingDisplay; +import ml.pluto7073.plutoscoffee.registry.ModItems; +import net.minecraft.network.chat.Component; + +import java.util.List; + +public class GrindingCategory implements DisplayCategory { + @Override + public CategoryIdentifier getCategoryIdentifier() { + return CoffeeREI.GRINDING_DISPLAY; + } + + @Override + public List setupDisplay(GrindingDisplay display, Rectangle bounds) { + Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 13); + List widgets = Lists.newArrayList(); + widgets.add(Widgets.createRecipeBase(bounds)); + widgets.add(Widgets.createArrow(new Point(startPoint.x + 27, startPoint.y + 4))); + widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61, startPoint.y + 5))); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 5)) + .entries(display.getOutputEntries().get(0)) + .disableBackground() + .markOutput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 4, startPoint.y + 5)) + .entries(display.getInputEntries().get(0)).markInput()); + return widgets; + } + + @Override + public Component getTitle() { + return Component.translatable("title.category.grinding"); + } + + @Override + public Renderer getIcon() { + return EntryStacks.of(ModItems.COFFEE_GRINDR); + } +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/category/PullingCategory.java b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/category/PullingCategory.java new file mode 100644 index 0000000..49a48fa --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/category/PullingCategory.java @@ -0,0 +1,87 @@ +package ml.pluto7073.plutoscoffee.compat.rei.category; + +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.DrawableConsumer; +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.util.EntryIngredients; +import me.shedaniel.rei.api.common.util.EntryStacks; +import ml.pluto7073.plutoscoffee.coffee.MachineWaterSources; +import ml.pluto7073.plutoscoffee.compat.rei.CoffeeREI; +import ml.pluto7073.plutoscoffee.compat.rei.display.PullingDisplay; +import ml.pluto7073.plutoscoffee.registry.ModGuiTextures; +import ml.pluto7073.plutoscoffee.registry.ModItems; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; + +import java.util.ArrayList; +import java.util.List; + +public class PullingCategory implements DisplayCategory { + + @Override + public List setupDisplay(PullingDisplay display, Rectangle bounds) { + ArrayList widgets = new ArrayList<>(); + widgets.add(Widgets.createRecipeBase(bounds)); + Point origin = new Point(bounds.getCenterX() - 41, bounds.getMinY() - 16); + + widgets.add(Widgets.createArrow(new Point(origin.x + 27, origin.y + 91))); + + widgets.add(Widgets.createSlot( + new Point(origin.x - 6, origin.y + 40)) + .markInput().entries(EntryIngredients.ofIngredient(MachineWaterSources.asIngredient())) + ); + widgets.add(Widgets.createSlot( + new Point(origin.x + 14, origin.y + 40)) + .markInput().entries(display.getInputEntries().get(0)) + ); + widgets.add(Widgets.createSlot( + new Point(origin.x + 2, origin.y + 91)) + .markInput().entries(display.getInputEntries().get(1)) + ); + widgets.add(Widgets.createResultSlotBackground(new Point(origin.x + 61, origin.y + 91))); + widgets.add(Widgets.createSlot( + new Point(origin.x + 61, origin.y + 91)).disableBackground() + .markOutput().entries(display.getOutputEntries().get(0)) + ); + widgets.add(Widgets.createTooltip(new Rectangle(origin.x + 7, origin.y + 58, 9, 28), Component.translatable("category.pulling.pullTime.tooltip", display.getPullTime() / 20))); + widgets.add(Widgets.createDrawableWidget(new DrawableConsumer() { + int tick = 0; + + @Override + public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + int n = (int) (28.0F * (1.0F - (float) tick / display.getPullTime())); + ModGuiTextures.PROGRESS_OUTLINE.render(graphics, origin.x + 7, origin.y + 58); + ModGuiTextures.PROGRESS_ARROW.renderOnMenu(graphics, origin.x + 7, origin.y + 58, 9, n); + tick--; + if (tick <= 0) tick = display.getPullTime(); + } + })); + return widgets; + } + + @Override + public int getDisplayHeight() { + return DisplayCategory.super.getDisplayHeight() + 48; + } + + @Override + public Renderer getIcon() { + return EntryStacks.of(ModItems.ESPRESSO_MACHINE); + } + + @Override + public Component getTitle() { + return Component.translatable("title.category.pulling"); + } + + @Override + public CategoryIdentifier getCategoryIdentifier() { + return CoffeeREI.PULLING_DISPLAY; + } +} \ No newline at end of file diff --git a/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/display/GrindingDisplay.java b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/display/GrindingDisplay.java new file mode 100644 index 0000000..7eaf465 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/display/GrindingDisplay.java @@ -0,0 +1,65 @@ +package ml.pluto7073.plutoscoffee.compat.rei.display; + +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.DisplaySerializer; +import me.shedaniel.rei.api.common.display.basic.BasicDisplay; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.EntryIngredients; +import me.shedaniel.rei.api.common.util.EntryStacks; +import ml.pluto7073.plutoscoffee.compat.rei.CoffeeREI; +import ml.pluto7073.plutoscoffee.compat.rei.GrindingRecipe; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; + +import java.util.List; + +public class GrindingDisplay extends BasicDisplay { + + private final EntryIngredient beans; + private final EntryStack grounds; + + public GrindingDisplay(GrindingRecipe recipe) { + this(recipe.beans(), recipe.grounds()); + } + + public GrindingDisplay(Ingredient beans, ItemStack grounds) { + this(EntryIngredients.ofIngredient(beans), EntryStacks.of(grounds)); + } + + public GrindingDisplay(EntryIngredient beans, EntryStack grounds) { + super(List.of(beans), List.of(EntryIngredient.of(grounds))); + this.beans = beans; + this.grounds = grounds; + } + + @Override + public CategoryIdentifier getCategoryIdentifier() { + return CoffeeREI.GRINDING_DISPLAY; + } + + public static DisplaySerializer serializer() { + return new DisplaySerializer<>() { + @Override + public CompoundTag save(CompoundTag tag, GrindingDisplay display) { + tag.put("beans", display.beans.saveIngredient()); + tag.put("grounds", display.grounds.saveStack()); + return tag; + } + + @Override + public GrindingDisplay read(CompoundTag tag) { + EntryIngredient beans = EntryIngredient.read(tag.getList("beans", Tag.TAG_COMPOUND)); + EntryStack grounds = EntryStack.read(tag.getCompound("grounds")); + return new GrindingDisplay(beans, grounds); + } + }; + } + + public EntryStack getGrounds() { + return grounds; + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/display/PullingDisplay.java b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/display/PullingDisplay.java new file mode 100644 index 0000000..8b54fbb --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/compat/rei/display/PullingDisplay.java @@ -0,0 +1,50 @@ +package ml.pluto7073.plutoscoffee.compat.rei.display; + +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.basic.BasicDisplay; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.registry.RecipeManagerContext; +import me.shedaniel.rei.api.common.util.EntryIngredients; +import ml.pluto7073.plutoscoffee.compat.rei.CoffeeREI; +import ml.pluto7073.plutoscoffee.recipe.PullingRecipe; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.crafting.Recipe; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +public class PullingDisplay extends BasicDisplay { + + private final int groundsRequired; + private final int pullTime; + + public PullingDisplay(PullingRecipe recipe) { + this(List.of(EntryIngredients.ofIngredient(recipe.grounds), EntryIngredients.ofIngredient(recipe.base)), Collections.singletonList(EntryIngredients.of(recipe.getResultItem())), + recipe, recipe.groundsRequired, recipe.pullTime); + } + + public PullingDisplay(List inputs, List outputs, CompoundTag tag) { + this(inputs, outputs, RecipeManagerContext.getInstance().byId(tag, "location"), tag.getInt("groundsRequired"), tag.getInt("pullTime")); + } + + public PullingDisplay(List inputs, List outputs, Recipe recipe, int groundsRequired, int pullTime) { + super(inputs, outputs, Optional.ofNullable(recipe).map(Recipe::getId)); + this.groundsRequired = groundsRequired; + this.pullTime = pullTime; + } + + @Override + public CategoryIdentifier getCategoryIdentifier() { + return CoffeeREI.PULLING_DISPLAY; + } + + public int getGroundsRequired() { + return groundsRequired; + } + + public int getPullTime() { + return pullTime; + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java b/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java index 48bc777..6783de5 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/config/CoffeeConfig.java @@ -1,55 +1,23 @@ package ml.pluto7073.plutoscoffee.config; +import ml.pluto7073.pdapi.config.BaseConfig; import ml.pluto7073.plutoscoffee.PlutosCoffee; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Properties; +public class CoffeeConfig extends BaseConfig { -public class CoffeeConfig { - - private final Properties properties; - - public CoffeeConfig(File configFile) { - properties = new Properties(); - loadDefaults(); - - if (!configFile.exists()) return; - try { - properties.load(new FileReader(configFile)); - } catch (IOException e) { - PlutosCoffee.logger.error("Failed to load mod config", e); - } - } - - private void loadDefaults() { - properties.put("shouldShowCoffeeBar", "true"); + public CoffeeConfig() { + super("plutoscoffee", "client", PlutosCoffee.LOGGER); } - - public void save(File configFile) { - if (!configFile.exists()) { - try { - configFile.createNewFile(); - } catch (IOException e) { - PlutosCoffee.logger.error("Failed to create config file", e); - } - } - - try (FileWriter writer = new FileWriter(configFile)) { - properties.store(writer, "Pluto's Coffee Mod Config"); - } catch (IOException e) { - PlutosCoffee.logger.error("Failed to save mod config", e); - } - } - public boolean shouldShowCoffeeBar() { - return Boolean.parseBoolean((String) properties.get("shouldShowCoffeeBar")); + return getBoolean("shouldShowCoffeeBar"); } public void setShouldShowCoffeeBar(boolean state) { - properties.put("shouldShowCoffeeBar", String.valueOf(state)); + setBoolean("shouldShowCoffeeBar", state); } + @Override + public void initConfig() { + setBoolean("shouldShowCoffeeBar", true); + } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerMenu.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerMenu.java new file mode 100644 index 0000000..2e42bd2 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerMenu.java @@ -0,0 +1,176 @@ +package ml.pluto7073.plutoscoffee.gui; + +import ml.pluto7073.plutoscoffee.CoffeeUtil; +import ml.pluto7073.plutoscoffee.blocks.CoffeeBrewerBlockEntity; +import ml.pluto7073.plutoscoffee.coffee.MachineWaterSources; +import ml.pluto7073.plutoscoffee.registry.ModScreens; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.SimpleContainerData; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +@MethodsReturnNonnullByDefault +public class CoffeeBrewerMenu extends AbstractContainerMenu { + + private final Container inventory; + private final ContainerData propertyDelegate; + private final Slot ingredientSlot; + + public CoffeeBrewerMenu(int syncId, Inventory inventory) { + this(syncId, inventory, new SimpleContainer(3), new SimpleContainerData(2)); + } + + public CoffeeBrewerMenu(int syncId, Inventory inventory, Container container, ContainerData containerData) { + super(ModScreens.BREWER_MENU_TYPE, syncId); + checkContainerSize(container, 3); + checkContainerDataCount(containerData, CoffeeBrewerBlockEntity.PROPERTY_COUNT); + this.inventory = container; + this.propertyDelegate = containerData; + //Input Slots + this.addSlot(new CoffeeSlot(container, 2, 79, 58)); + this.ingredientSlot = this.addSlot(new IngredientSlot(container, 0, 79, 17)); + this.addSlot(new FuelSlot(container, 1, 17, 17)); + this.addDataSlots(containerData); + + //Player Inventory & Hotbar Slots + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + + for (int i = 0; i < 9; ++i) { + this.addSlot(new Slot(inventory, i, 8 + i * 18, 142)); + } + } + + public boolean stillValid(Player player) { + return inventory.stillValid(player); + } + + public ItemStack quickMoveStack(Player player, int index) { + ItemStack stack = ItemStack.EMPTY; + Slot slot = slots.get(index); + if (slot.hasItem()) { + ItemStack slotStack = slot.getItem(); + stack = slotStack.copy(); + if (index != 2 && index != 1 && index != 0) { // Source is from Player Inventory or Hotbar + if (CoffeeBrewerMenu.FuelSlot.matches(stack)) { // To Water Slot + if (this.moveItemStackTo(slotStack, 1, 2, false) || this.ingredientSlot.mayPlace(slotStack) && !this.moveItemStackTo(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } else if (ingredientSlot.mayPlace(slotStack)) { // To Ingredient Slot + if (!this.moveItemStackTo(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } else if (CoffeeBrewerMenu.CoffeeSlot.matches(stack) && stack.getCount() == 1) { // To Coffee Grounds Slot + if (!this.moveItemStackTo(slotStack, 2, 3, false)) { + return ItemStack.EMPTY; + } + } else if (index >= 3 && index < 30) { // Player Inventory to Hotbar + if (!moveItemStackTo(slotStack, 30, 39, false)) { + return ItemStack.EMPTY; + } + } else if (index >= 30 && index < 39) { // Hotbar to Player Inventory + if (!moveItemStackTo(slotStack, 3, 30, false)) { + return ItemStack.EMPTY; + } + } else if (!moveItemStackTo(slotStack, 3, 39, false)) { // To Next Available Slot In Player Inventory or Hotbar + return ItemStack.EMPTY; + } + } else { // Source is from Coffee Brewer + if (!moveItemStackTo(slotStack, 3, 39, true)) { // To Anywhere in Player Inventory or Hotbar + return ItemStack.EMPTY; + } + + slot.onQuickCraft(slotStack, stack); + } + + if (slotStack.isEmpty()) { + slot.set(ItemStack.EMPTY); + } else { + slot.setChanged(); + } + + if (slotStack.getCount() == stack.getCount()) { + return ItemStack.EMPTY; + } + + slot.onTake(player, slotStack); + } + + return stack; + } + + public int getFuel() { + return this.propertyDelegate.get(1); + } + + public int getBrewTime() { + return this.propertyDelegate.get(0); + } + + static class CoffeeSlot extends Slot { + + public CoffeeSlot(Container container, int i, int j, int k) { + super (container, i, j, k); + } + + public boolean mayPlace(ItemStack stack) { + return matches(stack); + } + + public int getMaxStackSize() { + return 1; + } + + public static boolean matches(ItemStack stack) { + return stack.is(Items.GLASS_BOTTLE); + } + + } + + private static class IngredientSlot extends Slot { + + public IngredientSlot(Container container, int i, int j, int k) { + super(container, i, j, k); + } + + public boolean mayPlace(ItemStack stack) { + return CoffeeUtil.isItemACoffeeGround(stack.getItem()); + } + + public int getMaxStackSize() { + return 64; + } + + } + + private static class FuelSlot extends Slot { + + public FuelSlot(Container container, int i, int j, int k) { + super(container, i, j, k); + } + + public boolean mayPlace(ItemStack stack) { + return matches(stack); + } + + public static boolean matches(ItemStack stack) { + return MachineWaterSources.getWaterAmount(stack) > 0; + } + + public int getMaxStackSize() { + return 1; + } + + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreen.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreen.java index fc9aebd..b168231 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreen.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreen.java @@ -1,55 +1,62 @@ package ml.pluto7073.plutoscoffee.gui; -import ml.pluto7073.plutoscoffee.PlutosCoffee; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; +import ml.pluto7073.plutoscoffee.registry.ModGuiTextures; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.player.Inventory; -public class CoffeeBrewerScreen extends HandledScreen { +public class CoffeeBrewerScreen extends AbstractContainerScreen { - private static final Identifier TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/container/coffee_brewer.png"); private static final int[] BUBBLE_PROGRESS = {29, 24, 20, 16, 11, 6, 0}; - public CoffeeBrewerScreen(CoffeeBrewerScreenHandler handler, PlayerInventory inventory, Text title) { + public CoffeeBrewerScreen(CoffeeBrewerMenu handler, Inventory inventory, Component title) { super(handler, inventory, title); } protected void init() { super.init(); - this.titleX = (this.backgroundWidth - this.textRenderer.getWidth(this.title)) / 2; + this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2; } @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - this.renderBackground(context); - super.render(context, mouseX, mouseY, delta); - this.drawMouseoverTooltip(context, mouseX, mouseY); + public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + int i = (this.width - this.imageWidth) / 2; + int j = (this.height - this.imageHeight) / 2; + this.renderBackground(graphics); + super.render(graphics, mouseX, mouseY, delta); + this.renderTooltip(graphics, mouseX, mouseY); + if (mouseX >= i + 60 && mouseX <= i + 78 && mouseY >= j + 44 && mouseY <= j + 48) { + graphics.renderTooltip(this.font, Component.translatable("container.machine.water_tooltip", menu.getFuel() / 81), mouseX, mouseY); + } } @Override - protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { - int i = (this.width - this.backgroundWidth) / 2; - int j = (this.height - this.backgroundHeight) / 2; - context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight); - int k = handler.getFuel(); - int l = MathHelper.clamp((18 * k + 6 - 1) / 6, 0, 18); + protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) { + int i = (this.width - this.imageWidth) / 2; + int j = (this.height - this.imageHeight) / 2; + //graphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight); + ModGuiTextures.BREWER.render(graphics, i, j); + int k = menu.getFuel(); + int l = Mth.clamp((18 * k + 81000 - 1) / 81000, 0, 18); if (l > 0) { - context.drawTexture(TEXTURE, i + 60, j + 44, 176, 29, l, 4); + //graphics.blit(TEXTURE, i + 60, j + 44, 176, 29, l, 4); + ModGuiTextures.WATER.renderOnMenu(graphics, i + 60, j + 44, l, 4); } - int m = handler.getBrewTime(); + int m = menu.getBrewTime(); if (m > 0) { int n = (int) (28.0F * (1.0F - (float) m / 600.0F)); if (n > 0) { - context.drawTexture(TEXTURE, i + 97, j + 16, 176, 0, 9, n); + ModGuiTextures.PROGRESS_ARROW.renderOnMenu(graphics, i + 97, j + 16, 9, n); + //graphics.blit(TEXTURE, i + 97, j + 16, 176, 0, 9, n); } n = BUBBLE_PROGRESS[m / 2 % 7]; if (n > 0) { - context.drawTexture(TEXTURE, i + 63, j + 14 + 29 - n, 185, 29 - n, 12, n); + ModGuiTextures.PROGRESS_BUBBLE.renderCustomUV(graphics, i + 63, j + 43 - n, 185, 29 - n, 12, n); + //graphics.blit(TEXTURE, i + 63, j + 14 + 29 - n, 185, 29 - n, 12, n); } } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreenHandler.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreenHandler.java deleted file mode 100644 index 77c7855..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreenHandler.java +++ /dev/null @@ -1,171 +0,0 @@ -package ml.pluto7073.plutoscoffee.gui; - -import ml.pluto7073.plutoscoffee.CoffeeUtil; -import ml.pluto7073.plutoscoffee.registry.ModScreens; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.screen.ArrayPropertyDelegate; -import net.minecraft.screen.PropertyDelegate; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; - -public class CoffeeBrewerScreenHandler extends ScreenHandler { - - private final Inventory inventory; - private final PropertyDelegate propertyDelegate; - private final Slot ingredientSlot; - - public CoffeeBrewerScreenHandler(int syncId, PlayerInventory inventory) { - this(syncId, inventory, new SimpleInventory(3), new ArrayPropertyDelegate(2)); - } - - public CoffeeBrewerScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory, PropertyDelegate propertyDelegate) { - super(ModScreens.BREWER_SCREEN_HANDLER_TYPE, syncId); - checkSize(inventory, 3); - this.inventory = inventory; - this.propertyDelegate = propertyDelegate; - //Input Slots - this.addSlot(new CoffeeSlot(inventory, 2, 79, 58)); - this.ingredientSlot = this.addSlot(new IngredientSlot(inventory, 0, 79, 17)); - this.addSlot(new FuelSlot(inventory, 1, 17, 17)); - this.addProperties(propertyDelegate); - - //Player Inventory & Hotbar Slots - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); - } - } - - public boolean canUse(PlayerEntity player) { - return inventory.canPlayerUse(player); - } - - public ItemStack quickMove(PlayerEntity player, int index) { - ItemStack stack = ItemStack.EMPTY; - Slot slot = slots.get(index); - if (slot.hasStack()) { - ItemStack slotStack = slot.getStack(); - stack = slotStack.copy(); - if (index != 2 && index != 1 && index != 0) { // Source is from Player Inventory or Hotbar - if (CoffeeBrewerScreenHandler.FuelSlot.matches(stack)) { // To Water Slot - if (this.insertItem(slotStack, 1, 2, false) || this.ingredientSlot.canInsert(slotStack) && !this.insertItem(slotStack, 0, 1, false)) { - return ItemStack.EMPTY; - } - } else if (ingredientSlot.canInsert(slotStack)) { // To Ingredient Slot - if (!this.insertItem(slotStack, 0, 1, false)) { - return ItemStack.EMPTY; - } - } else if (CoffeeBrewerScreenHandler.CoffeeSlot.matches(stack) && stack.getCount() == 1) { // To Coffee Grounds Slot - if (!this.insertItem(slotStack, 2, 3, false)) { - return ItemStack.EMPTY; - } - } else if (index >= 3 && index < 30) { // Player Inventory to Hotbar - if (!insertItem(slotStack, 30, 39, false)) { - return ItemStack.EMPTY; - } - } else if (index >= 30 && index < 39) { // Hotbar to Player Inventory - if (!insertItem(slotStack, 3, 30, false)) { - return ItemStack.EMPTY; - } - } else if (!insertItem(slotStack, 3, 39, false)) { // To Next Available Slot In Player Inventory or Hotbar - return ItemStack.EMPTY; - } - } else { // Source is from Coffee Brewer - if (!insertItem(slotStack, 3, 39, true)) { // To Anywhere in Player Inventory or Hotbar - return ItemStack.EMPTY; - } - - slot.onQuickTransfer(slotStack, stack); - } - - if (slotStack.isEmpty()) { - slot.setStack(ItemStack.EMPTY); - } else { - slot.markDirty(); - } - - if (slotStack.getCount() == stack.getCount()) { - return ItemStack.EMPTY; - } - - slot.onTakeItem(player, slotStack); - } - - return stack; - } - - public int getFuel() { - return this.propertyDelegate.get(1); - } - - public int getBrewTime() { - return this.propertyDelegate.get(0); - } - - static class CoffeeSlot extends Slot { - - public CoffeeSlot(Inventory inventory, int i, int j, int k) { - super (inventory, i, j, k); - } - - public boolean canInsert(ItemStack stack) { - return matches(stack); - } - - public int getMaxItemCount() { - return 1; - } - - public static boolean matches(ItemStack stack) { - return stack.isOf(Items.GLASS_BOTTLE); - } - - } - - private static class IngredientSlot extends Slot { - - public IngredientSlot(Inventory inventory, int i, int j, int k) { - super(inventory, i, j, k); - } - - public boolean canInsert(ItemStack stack) { - return CoffeeUtil.isItemACoffeeGround(stack.getItem()); - } - - public int getMaxItemCount() { - return 64; - } - - } - - private static class FuelSlot extends Slot { - - public FuelSlot(Inventory inventory, int i, int j, int k) { - super(inventory, i, j, k); - } - - public boolean canInsert(ItemStack stack) { - return matches(stack); - } - - public static boolean matches(ItemStack stack) { - return stack.isOf(Items.WATER_BUCKET); - } - - public int getMaxItemCount() { - return 1; - } - - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrMenu.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrMenu.java new file mode 100644 index 0000000..2bc1fc5 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrMenu.java @@ -0,0 +1,141 @@ +package ml.pluto7073.plutoscoffee.gui; + +import ml.pluto7073.plutoscoffee.CoffeeUtil; +import ml.pluto7073.plutoscoffee.registry.ModScreens; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.SimpleContainerData; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; + +@MethodsReturnNonnullByDefault +public class CoffeeGrindrMenu extends AbstractContainerMenu { + + private final Container container; + private final ContainerData containerData; + private final Slot ingredientSlot; + + public CoffeeGrindrMenu(int syncId, Inventory inventory) { + this(syncId, inventory, new SimpleContainer(2), new SimpleContainerData(1)); + } + + public CoffeeGrindrMenu(int syncId, Inventory playerInventory, Container container, ContainerData containerData) { + super(ModScreens.GRINDR_SCREEN_HANDLER_TYPE, syncId); + checkContainerSize(container, 2); + this.container = container; + this.containerData = containerData; + // Input Slot + this.addSlot(new CoffeeGrindrMenu.GroundsSlot(container, 1, 79, 58)); + this.ingredientSlot = this.addSlot(new CoffeeGrindrMenu.IngredientSlot(container, 0, 79, 17)); + this.addDataSlots(containerData); + + // Player Inventory & Hotbar Slots + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + + for (int i = 0; i < 9; ++i) { + this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); + } + } + + public boolean stillValid(Player player) { + return container.stillValid(player); + } + + public ItemStack quickMoveStack(Player player, int index) { + ItemStack stack = ItemStack.EMPTY; + Slot slot = slots.get(index); + if (slot.hasItem()) { + ItemStack slotStack = slot.getItem(); + stack = slotStack.copy(); + if (index != 1 && index != 0) { // Source is from Player Inventory or Hotbar + if (ingredientSlot.mayPlace(slotStack)) { // To Ingredient Slot + if (!this.moveItemStackTo(slotStack, 0, 1, false)) { + return ItemStack.EMPTY; + } + } else if (CoffeeGrindrMenu.GroundsSlot.matches(stack) && stack.getCount() == 1) { // To Coffee Grounds Slot + if (!this.moveItemStackTo(slotStack, 1, 2, false)) { + return ItemStack.EMPTY; + } + } else if (index >= 2 && index < 29) { // Player Inventory to Hotbar + if (!moveItemStackTo(slotStack, 29, 38, false)) { + return ItemStack.EMPTY; + } + } else if (index >= 29 && index < 38) { // Hotbar to Player Inventory + if (!moveItemStackTo(slotStack, 2, 29, false)) { + return ItemStack.EMPTY; + } + } else if (!moveItemStackTo(slotStack, 2, 38, false)) { // To Next Available Slot In Player Inventory or Hotbar + return ItemStack.EMPTY; + } + } else { // Source is from Coffee Brewer + if (!moveItemStackTo(slotStack, 2, 38, true)) { // To Anywhere in Player Inventory or Hotbar + return ItemStack.EMPTY; + } + + slot.onQuickCraft(slotStack, stack); + } + + if (slotStack.isEmpty()) { + slot.set(ItemStack.EMPTY); + } else { + slot.setChanged(); + } + + if (slotStack.getCount() == stack.getCount()) { + return ItemStack.EMPTY; + } + + slot.onTake(player, slotStack); + } + + return stack; + } + + public int getGrindTime() { + return this.containerData.get(0); + } + + static class GroundsSlot extends Slot { + public GroundsSlot(Container inventory, int index, int x, int y) { + super(inventory, index, x, y); + } + + public boolean mayPlace(ItemStack stack) { + return false; + } + + public int getMaxStackSize() { + return 64; + } + + public static boolean matches(ItemStack stack) { + return CoffeeUtil.isItemACoffeeGround(stack.getItem()); + } + } + + private static class IngredientSlot extends Slot { + + public IngredientSlot(Container inventory, int index, int x, int y) { + super(inventory, index, x, y); + } + + public boolean mayPlace(ItemStack stack) { + return CoffeeUtil.isItemACoffeeBean(stack.getItem()); + } + + public int getMaxStackSize() { + return 64; + } + } + +} + diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrScreen.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrScreen.java index a760619..9e11803 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrScreen.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrScreen.java @@ -1,43 +1,41 @@ package ml.pluto7073.plutoscoffee.gui; -import ml.pluto7073.plutoscoffee.PlutosCoffee; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; +import ml.pluto7073.plutoscoffee.registry.ModGuiTextures; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; -public class CoffeeGrindrScreen extends HandledScreen { +public class CoffeeGrindrScreen extends AbstractContainerScreen { - private static final Identifier TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/container/coffee_grinder.png"); - - public CoffeeGrindrScreen(CoffeeGrindrScreenHandler handler, PlayerInventory inventory, Text title) { + public CoffeeGrindrScreen(CoffeeGrindrMenu handler, Inventory inventory, Component title) { super(handler, inventory, title); } protected void init() { super.init(); - this.titleX = (this.backgroundWidth - this.textRenderer.getWidth(this.title)) / 2; + this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2; } @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics context, int mouseX, int mouseY, float delta) { this.renderBackground(context); super.render(context, mouseX, mouseY, delta); - this.drawMouseoverTooltip(context, mouseX, mouseY); + this.renderTooltip(context, mouseX, mouseY); } - protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { - int i = (this.width - this.backgroundWidth) / 2; - int j = (this.height - this.backgroundHeight) / 2; - context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight); + protected void renderBg(GuiGraphics context, float delta, int mouseX, int mouseY) { + int i = (this.width - this.imageWidth) / 2; + int j = (this.height - this.imageHeight) / 2; + //context.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight); + ModGuiTextures.GRINDR.render(context, i, j); - int m = handler.getGrindTime(); + int m = menu.getGrindTime(); if (m > 0) { int n = (int) (28.0F * (1.0F - (float) m / 20.0F)); if (n > 0) { - context.drawTexture(TEXTURE, i + 97, j + 16, 176, 0, 9, n); + //context.blit(TEXTURE, i + 97, j + 16, 176, 0, 9, n); + ModGuiTextures.PROGRESS_ARROW.renderOnMenu(context, i + 97, j + 16, 9, n); } } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrScreenHandler.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrScreenHandler.java deleted file mode 100644 index f24a154..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeGrindrScreenHandler.java +++ /dev/null @@ -1,138 +0,0 @@ -package ml.pluto7073.plutoscoffee.gui; - -import ml.pluto7073.plutoscoffee.CoffeeUtil; -import ml.pluto7073.plutoscoffee.registry.ModScreens; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.ArrayPropertyDelegate; -import net.minecraft.screen.PropertyDelegate; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; - -public class CoffeeGrindrScreenHandler extends ScreenHandler { - - private final Inventory inventory; - private final PropertyDelegate propertyDelegate; - private final Slot ingredientSlot; - - public CoffeeGrindrScreenHandler(int syncId, PlayerInventory inventory) { - this(syncId, inventory, new SimpleInventory(2), new ArrayPropertyDelegate(1)); - } - - public CoffeeGrindrScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory, PropertyDelegate propertyDelegate) { - super(ModScreens.GRINDR_SCREEN_HANDLER_TYPE, syncId); - checkSize(inventory, 2); - this.inventory = inventory; - this.propertyDelegate = propertyDelegate; - // Input Slot - this.addSlot(new CoffeeGrindrScreenHandler.GroundsSlot(inventory, 1, 79, 58)); - this.ingredientSlot = this.addSlot(new CoffeeGrindrScreenHandler.IngredientSlot(inventory, 0, 79, 17)); - this.addProperties(propertyDelegate); - - // Player Inventory & Hotbar Slots - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); - } - } - - public boolean canUse(PlayerEntity player) { - return inventory.canPlayerUse(player); - } - - public ItemStack quickMove(PlayerEntity player, int index) { - ItemStack stack = ItemStack.EMPTY; - Slot slot = slots.get(index); - if (slot.hasStack()) { - ItemStack slotStack = slot.getStack(); - stack = slotStack.copy(); - if (index != 1 && index != 0) { // Source is from Player Inventory or Hotbar - if (ingredientSlot.canInsert(slotStack)) { // To Ingredient Slot - if (!this.insertItem(slotStack, 0, 1, false)) { - return ItemStack.EMPTY; - } - } else if (CoffeeGrindrScreenHandler.GroundsSlot.matches(stack) && stack.getCount() == 1) { // To Coffee Grounds Slot - if (!this.insertItem(slotStack, 1, 2, false)) { - return ItemStack.EMPTY; - } - } else if (index >= 2 && index < 29) { // Player Inventory to Hotbar - if (!insertItem(slotStack, 29, 38, false)) { - return ItemStack.EMPTY; - } - } else if (index >= 29 && index < 38) { // Hotbar to Player Inventory - if (!insertItem(slotStack, 2, 29, false)) { - return ItemStack.EMPTY; - } - } else if (!insertItem(slotStack, 2, 38, false)) { // To Next Available Slot In Player Inventory or Hotbar - return ItemStack.EMPTY; - } - } else { // Source is from Coffee Brewer - if (!insertItem(slotStack, 2, 38, true)) { // To Anywhere in Player Inventory or Hotbar - return ItemStack.EMPTY; - } - - slot.onQuickTransfer(slotStack, stack); - } - - if (slotStack.isEmpty()) { - slot.setStack(ItemStack.EMPTY); - } else { - slot.markDirty(); - } - - if (slotStack.getCount() == stack.getCount()) { - return ItemStack.EMPTY; - } - - slot.onTakeItem(player, slotStack); - } - - return stack; - } - - public int getGrindTime() { - return this.propertyDelegate.get(0); - } - - static class GroundsSlot extends Slot { - public GroundsSlot(Inventory inventory, int index, int x, int y) { - super(inventory, index, x, y); - } - - public boolean canInsert(ItemStack stack) { - return false; - } - - public int getMaxItemCount() { - return 64; - } - - public static boolean matches(ItemStack stack) { - return CoffeeUtil.isItemACoffeeGround(stack.getItem()); - } - } - - private static class IngredientSlot extends Slot { - - public IngredientSlot(Inventory inventory, int index, int x, int y) { - super(inventory, index, x, y); - } - - public boolean canInsert(ItemStack stack) { - return CoffeeUtil.isItemACoffeeBean(stack.getItem()); - } - - public int getMaxItemCount() { - return 64; - } - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineMenu.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineMenu.java new file mode 100644 index 0000000..43e6b11 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineMenu.java @@ -0,0 +1,154 @@ +package ml.pluto7073.plutoscoffee.gui; + +import ml.pluto7073.pdapi.tag.PDTags; +import ml.pluto7073.plutoscoffee.blocks.EspressoMachineBlockEntity; +import ml.pluto7073.plutoscoffee.coffee.MachineWaterSources; +import ml.pluto7073.plutoscoffee.recipe.PullingRecipe; +import ml.pluto7073.plutoscoffee.registry.ModItems; +import ml.pluto7073.plutoscoffee.registry.ModScreens; +import ml.pluto7073.plutoscoffee.tags.ModItemTags; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.SimpleContainerData; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +@MethodsReturnNonnullByDefault +public class EspressoMachineMenu extends AbstractContainerMenu { + + private final Container container; + private final ContainerData containerData; + private final Slot groundsSlot; + + public EspressoMachineMenu(int syncId, Inventory playerInventory) { + this(syncId, playerInventory, new SimpleContainer(EspressoMachineBlockEntity.INVENTORY_SIZE), new SimpleContainerData(EspressoMachineBlockEntity.PROPERTY_COUNT)); + } + + public EspressoMachineMenu(int syncId, Inventory playerInventory, Container container, ContainerData containerData) { + super(ModScreens.ESPRESSO_SCREEN_HANDLER_TYPE, syncId); + checkContainerSize(container, EspressoMachineBlockEntity.INVENTORY_SIZE); + this.container = container; + this.containerData = containerData; + //Input Slots + this.addSlot(new EspressoSlot(container, EspressoMachineBlockEntity.ESPRESSO_SLOT_INDEX, 67, 58)); + this.addSlot(new EspressoSlot(container, EspressoMachineBlockEntity.ESPRESSO_SLOT_2_INDEX, 91, 58)); + this.groundsSlot = this.addSlot(new GroundsSlot(container, EspressoMachineBlockEntity.GROUNDS_SLOT_INDEX, 79, 17)); + this.addSlot(new WaterSlot(container, EspressoMachineBlockEntity.WATER_SLOT_INDEX, 17, 17)); + this.addSlot(new TrashSlot(container, EspressoMachineBlockEntity.TRASH_SLOT_INDEX, 17, 46)); + this.addSlot(new MilkSlot(container, EspressoMachineBlockEntity.MILK_SLOT_INDEX, 136, 26)); + this.addDataSlots(containerData); + + //Player Inventory & Hotbar Slots + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + + for (int i = 0; i < 9; ++i) { + this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); + } + } + + public boolean stillValid(Player player) { + return container.stillValid(player); + } + + public ItemStack quickMoveStack(Player player, int index) { + return ItemStack.EMPTY; // TODO + } + + public int getWater() { + return this.containerData.get(EspressoMachineBlockEntity.WATER_PROPERTY_INDEX); + } + + public int getPullTime() { + return this.containerData.get(EspressoMachineBlockEntity.PULL_TIME_PROPERTY_INDEX); + } + + public int getSteamTime() { + return this.containerData.get(EspressoMachineBlockEntity.STEAM_TIME_PROPERTY_INDEX); + } + + public int getTotalPullTime() { + return this.containerData.get(EspressoMachineBlockEntity.TOTAL_PULL_TIME_PROPERTY_INDEX); + } + + private static class EspressoSlot extends Slot { + public EspressoSlot(Container container, int index, int x, int y) { + super(container, index, x, y); + } + + public boolean mayPlace(ItemStack stack) { + return true; + } + + public int getMaxStackSize() { + return 1; + } + + } + + private static class GroundsSlot extends Slot { + public GroundsSlot(Container container, int index, int x, int y) { + super(container, index, x, y); + } + + public boolean mayPlace(ItemStack stack) { + return stack.is(ModItemTags.COFFEE_GROUNDS); + } + + public int getMaxStackSize() { + return 64; + } + } + + private static class WaterSlot extends Slot { + public WaterSlot(Container container, int index, int x, int y) { + super(container, index, x, y); + } + + public boolean mayPlace(ItemStack stack) { + return matches(stack); + } + + public static boolean matches(ItemStack stack) { + return MachineWaterSources.getWaterAmount(stack) > 0; + } + + public int getMaxStackSize() { + return 1; + } + } + + private static class TrashSlot extends Slot { + public TrashSlot(Container container, int index, int x, int y) { + super(container, index, x, y); + } + + public boolean mayPlace(ItemStack stack) { + return false; + } + + public int getMaxStackSize() { return 64; } + } + + private static class MilkSlot extends Slot { + public MilkSlot(Container container, int index, int x, int y) { + super(container, index, x, y); + } + + public boolean mayPlace(ItemStack stack) { + return stack.is(PDTags.MILK_BOTTLES) || stack.is(ModItems.LATTE); + } + + public int getMaxStackSize() { return 1; } + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineScreen.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineScreen.java index 8e742d0..d95baa7 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineScreen.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineScreen.java @@ -1,57 +1,64 @@ package ml.pluto7073.plutoscoffee.gui; -import ml.pluto7073.plutoscoffee.PlutosCoffee; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; +import ml.pluto7073.plutoscoffee.registry.ModGuiTextures; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.player.Inventory; -public class EspressoMachineScreen extends HandledScreen { +public class EspressoMachineScreen extends AbstractContainerScreen { - private static final Identifier TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/container/espresso_machine.png"); private static final int[] BUBBLE_PROGRESS = {29, 24, 20, 16, 11, 6, 0}; - public EspressoMachineScreen(EspressoMachineScreenHandler handler, PlayerInventory inventory, Text title) { + public EspressoMachineScreen(EspressoMachineMenu handler, Inventory inventory, Component title) { super(handler, inventory, title); } protected void init() { super.init(); - this.titleX = (this.backgroundWidth - this.textRenderer.getWidth(this.title)) / 2; + this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2; } - public void render(DrawContext context, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics context, int mouseX, int mouseY, float delta) { + int i = (this.width - this.imageWidth) / 2; + int j = (this.height - this.imageHeight) / 2; this.renderBackground(context); super.render(context, mouseX, mouseY, delta); - this.drawMouseoverTooltip(context, mouseX, mouseY); + this.renderTooltip(context, mouseX, mouseY); + if (mouseX >= i + 60 && mouseX <= i + 78 && mouseY >= j + 44 && mouseY <= j + 48) { + context.renderTooltip(this.font, Component.translatable("container.machine.water_tooltip", menu.getWater() / 81), mouseX, mouseY); + } } - protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { - int i = (this.width - this.backgroundWidth) / 2; - int j = (this.height - this.backgroundHeight) / 2; - context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight); - int k = handler.getWater(); - int l = MathHelper.clamp((18 * k + 24 - 1) / 24, 0, 18); + protected void renderBg(GuiGraphics context, float delta, int mouseX, int mouseY) { + int i = (this.width - this.imageWidth) / 2; + int j = (this.height - this.imageHeight) / 2; + //context.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight); + ModGuiTextures.ESPRESSO_MACHINE.render(context, i, j); + int k = menu.getWater(); + int l = Mth.clamp((18 * k + 81000 - 1) / 81000, 0, 18); if (l > 0) { - context.drawTexture(TEXTURE, i + 60, j + 44, 176, 29, l, 4); + //context.blit(TEXTURE, i + 60, j + 44, 176, 29, l, 4); + ModGuiTextures.WATER.renderOnMenu(context, i + 60, j + 44, l, 4); } - int m = handler.getPullTime(); + int m = menu.getPullTime(); if (m > 0) { - int n = (int) (28.0F * (1.0F - m / 400.0F)); + int n = (int) (28.0F * (1.0F - (float) m / menu.getTotalPullTime())); if (n > 0) { - context.drawTexture(TEXTURE, i + 97, j + 16, 176, 0, 9, n); + //context.blit(TEXTURE, i + 97, j + 16, 176, 0, 9, n); + ModGuiTextures.PROGRESS_ARROW.renderOnMenu(context, i + 97, j + 16, 9, n); } n = BUBBLE_PROGRESS[m / 2 % 7]; if (n > 0) { - context.drawTexture(TEXTURE, i + 63, j + 14 + 29 - n, 185, 29 - n, 12, n); + //context.blit(TEXTURE, i + 63, j + 14 + 29 - n, 185, 29 - n, 12, n); + ModGuiTextures.PROGRESS_BUBBLE.renderCustomUV(context, i + 63, j + 43 - n, 185, 29 - n, 12, n); } } - m = handler.getSteamTime(); + m = menu.getSteamTime(); if (m > 0 && m <= 600) { int n = (int) (32.0F * (m / 600.0F)); if (n > 0) { @@ -59,18 +66,18 @@ protected void drawBackground(DrawContext context, float delta, int mouseX, int if (m < 400) temp = 0; else if (m < 500) temp = 1; else temp = 2; - int tempU = switch (temp) { - case 0 -> 181; - case 1 -> 186; - case 2 -> 176; - default -> 191; - }; - context.drawTexture(TEXTURE, i + 128, j + 52 - n, tempU, 33, 5, n); + switch (temp) { + case 0 -> ModGuiTextures.STEAM_COLD.renderOnMenu(context, i + 128, j + 52 - n, 5, n); + case 1 -> ModGuiTextures.STEAM_HOT.renderOnMenu(context, i + 128, j + 52 - n, 5, n); + case 2 -> ModGuiTextures.STEAM_BURNT.renderOnMenu(context, i + 128, j + 52 - n, 5, n); + } + //context.blit(TEXTURE, i + 128, j + 52 - n, tempU, 33, 5, n); } n = BUBBLE_PROGRESS[(600 - m) / 2 % 7]; if (n > 0) { - context.drawTexture(TEXTURE, i + 138, j + 44 + 29 - n, 185, 29 - n, 12, n); + ModGuiTextures.PROGRESS_BUBBLE.renderCustomUV(context, i + 138, j + 73 - n, 185, 29 - n, 12, n); + //context.blit(TEXTURE, i + 138, j + 44 + 29 - n, 185, 29 - n, 12, n); } } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineScreenHandler.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineScreenHandler.java deleted file mode 100644 index cc11cb3..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/EspressoMachineScreenHandler.java +++ /dev/null @@ -1,148 +0,0 @@ -package ml.pluto7073.plutoscoffee.gui; - -import ml.pluto7073.pdapi.item.PDItems; -import ml.pluto7073.plutoscoffee.blocks.EspressoMachineBlockEntity; -import ml.pluto7073.plutoscoffee.registry.ModItems; -import ml.pluto7073.plutoscoffee.registry.ModScreens; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.screen.ArrayPropertyDelegate; -import net.minecraft.screen.PropertyDelegate; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; - -public class EspressoMachineScreenHandler extends ScreenHandler { - - private final Inventory inventory; - private final PropertyDelegate propertyDelegate; - private final Slot groundsSlot; - - public EspressoMachineScreenHandler(int syncId, PlayerInventory playerInventory) { - this(syncId, playerInventory, new SimpleInventory(EspressoMachineBlockEntity.INVENTORY_SIZE), new ArrayPropertyDelegate(EspressoMachineBlockEntity.PROPERTY_COUNT)); - } - - public EspressoMachineScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory, PropertyDelegate propertyDelegate) { - super(ModScreens.ESPRESSO_SCREEN_HANDLER_TYPE, syncId); - checkSize(inventory, EspressoMachineBlockEntity.INVENTORY_SIZE); - this.inventory = inventory; - this.propertyDelegate = propertyDelegate; - //Input Slots - this.addSlot(new EspressoSlot(inventory, EspressoMachineBlockEntity.ESPRESSO_SLOT_INDEX, 67, 58)); - this.addSlot(new EspressoSlot(inventory, EspressoMachineBlockEntity.ESPRESSO_SLOT_2_INDEX, 91, 58)); - this.groundsSlot = this.addSlot(new GroundsSlot(inventory, EspressoMachineBlockEntity.GROUNDS_SLOT_INDEX, 79, 17)); - this.addSlot(new WaterSlot(inventory, EspressoMachineBlockEntity.WATER_SLOT_INDEX, 17, 17)); - this.addSlot(new TrashSlot(inventory, EspressoMachineBlockEntity.TRASH_SLOT_INDEX, 17, 46)); - this.addSlot(new MilkSlot(inventory, EspressoMachineBlockEntity.MILK_SLOT_INDEX, 136, 26)); - this.addProperties(propertyDelegate); - - //Player Inventory & Hotbar Slots - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (int i = 0; i < 9; ++i) { - this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); - } - } - - public boolean canUse(PlayerEntity player) { - return inventory.canPlayerUse(player); - } - - public ItemStack quickMove(PlayerEntity player, int index) { - return ItemStack.EMPTY; // TODO - } - - public int getWater() { - return this.propertyDelegate.get(EspressoMachineBlockEntity.WATER_PROPERTY_INDEX); - } - - public int getPullTime() { - return this.propertyDelegate.get(EspressoMachineBlockEntity.PULL_TIME_PROPERTY_INDEX); - } - - public int getSteamTime() { - return this.propertyDelegate.get(EspressoMachineBlockEntity.STEAM_TIME_PROPERTY_INDEX); - } - - private static class EspressoSlot extends Slot { - public EspressoSlot(Inventory inventory, int index, int x, int y) { - super(inventory, index, x, y); - } - - public boolean canInsert(ItemStack stack) { - return matches(stack); - } - - public int getMaxItemCount() { - return 1; - } - - public static boolean matches(ItemStack stack) { - return stack.isOf(Items.GLASS_BOTTLE); - } - } - - private static class GroundsSlot extends Slot { - public GroundsSlot(Inventory inventory, int index, int x, int y) { - super(inventory, index, x, y); - } - - public boolean canInsert(ItemStack stack) { - return stack.isOf(ModItems.GROUND_ESPRESSO_ROAST); - } - - public int getMaxItemCount() { - return 64; - } - } - - private static class WaterSlot extends Slot { - public WaterSlot(Inventory inventory, int index, int x, int y) { - super(inventory, index, x, y); - } - - public boolean canInsert(ItemStack stack) { - return matches(stack); - } - - public static boolean matches(ItemStack stack) { - return stack.isOf(Items.WATER_BUCKET); - } - - public int getMaxItemCount() { - return 1; - } - } - - private static class TrashSlot extends Slot { - public TrashSlot(Inventory inventory, int index, int x, int y) { - super(inventory, index, x, y); - } - - public boolean canInsert(ItemStack stack) { - return false; - } - - public int getMaxItemCount() { return 64; } - } - - private static class MilkSlot extends Slot { - public MilkSlot(Inventory inventory, int index, int x, int y) { - super(inventory, index, x, y); - } - - public boolean canInsert(ItemStack stack) { - return stack.isOf(PDItems.MILK_BOTTLE) || stack.isOf(ModItems.LATTE); - } - - public int getMaxItemCount() { return 1; } - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/VersionWarningScreen.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/VersionWarningScreen.java deleted file mode 100644 index dfe3dbc..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/VersionWarningScreen.java +++ /dev/null @@ -1,82 +0,0 @@ -package ml.pluto7073.plutoscoffee.gui; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ConfirmLinkScreen; -import net.minecraft.client.gui.screen.WarningScreen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Util; - -import java.net.URI; -import java.net.URISyntaxException; - -@Environment(EnvType.CLIENT) -public class VersionWarningScreen extends WarningScreen { - - private static final Text HEADER; - private static final Text MESSAGE; - private static final Text NARRATED; - - private static final String LATEST_RELEASE_LINK = "https://pluto7073.github.io/files/latest-coffeemod-release.html"; - - private URI link; - - public VersionWarningScreen() { - super(HEADER, MESSAGE, NARRATED); - } - - @Override - protected void initButtons(int yOffset) { - this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("plutosmods.version.okay"), - (buttonWidget) -> { - if (this.client != null) - this.client.setScreen(null); - }).dimensions(this.width / 2 - 155, 100 + yOffset, 150, 20).build()); - this.addDrawableChild(new ButtonWidget.Builder(Text.translatable("plutosmods.version.open_mod_page"), - (buttonWidget) -> { - URI uRI; - try { - uRI = new URI(LATEST_RELEASE_LINK); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - //noinspection DataFlowIssue - if (this.client.options.getChatLinksPrompt().getValue()) { - this.link = uRI; - this.client.setScreen(new ConfirmLinkScreen(this::confirmLink, LATEST_RELEASE_LINK, false)); - } else { - this.openLink(uRI); - this.client.setScreen(null); - } - }).dimensions(this.width / 2 + 5, 100 + yOffset, 150, 20).build()); - } - - @Override - protected void drawTitle(DrawContext context) { - context.drawTextWithShadow(this.textRenderer, this.title, (this.width / 2) - (this.textRenderer.getWidth(this.title) / 2), 30, 16777215); - } - - private void confirmLink(boolean open) { - if (open) { - this.openLink(this.link); - } - - this.link = null; - if (this.client != null) - this.client.setScreen(null); - } - - private void openLink(URI link) { - Util.getOperatingSystem().open(link); - } - - static { - HEADER = Text.translatable("plutosmods.version.header.plutoscoffee").formatted(Formatting.BOLD); - MESSAGE = Text.translatable("plutosmods.version.message"); - NARRATED = HEADER.copy().append("\n").append(MESSAGE); - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/items/BrewedCoffee.java b/src/main/java/ml/pluto7073/plutoscoffee/items/BrewedCoffee.java index a32928b..99ad3ad 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/items/BrewedCoffee.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/items/BrewedCoffee.java @@ -5,66 +5,60 @@ import ml.pluto7073.plutoscoffee.coffee.CoffeeType; import ml.pluto7073.plutoscoffee.coffee.CoffeeTypes; import ml.pluto7073.plutoscoffee.registry.ModStats; -import net.minecraft.advancement.criterion.Criteria; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsage; -import net.minecraft.item.Items; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; -import net.minecraft.util.*; -import net.minecraft.world.World; -import net.minecraft.world.event.GameEvent; +import net.minecraft.ChatFormatting; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; import java.util.List; +@MethodsReturnNonnullByDefault public class BrewedCoffee extends AbstractCustomizableDrinkItem { public static final int DEFAULT_COLOUR = 0x160A02; public static final int COLOUR_WITH_MILK = 0x885737; - public BrewedCoffee(Settings settings) { - super(Items.GLASS_BOTTLE, Temperature.HOT, settings); + public BrewedCoffee(Properties properties) { + super(Items.GLASS_BOTTLE, Temperature.HOT, properties); } @Override - public ItemStack getDefaultStack() { - return CoffeeUtil.setCoffeeType(super.getDefaultStack(), CoffeeTypes.MEDIUM_ROAST); + public ItemStack getDefaultInstance() { + return CoffeeUtil.setCoffeeType(super.getDefaultInstance(), CoffeeTypes.MEDIUM_ROAST); } @Override - public int getCaffeineContent(ItemStack stack) { - return CoffeeUtil.getCoffeeType(stack).getCaffeineContent() + super.getCaffeineContent(stack); + public int getChemicalContent(String name, ItemStack stack) { + int total = super.getChemicalContent(name, stack); + if (!"caffeine".equals(name)) return total; + CoffeeType type = CoffeeUtil.getCoffeeType(stack); + if (type == null) return total; + return type.getCaffeineContent() + total; } @Override - public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { - PlayerEntity playerEntity = user instanceof PlayerEntity ? (PlayerEntity) user : null; + public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity user) { + Player player = user instanceof Player ? (Player) user : null; - if (!world.isClient) { - CoffeeType type = CoffeeUtil.getCoffeeType(stack); - type.onDrink(stack, world, user); + if (player != null) { + player.awardStat(ModStats.DRINK_COFFEE); } - if (playerEntity != null) { - playerEntity.incrementStat(ModStats.DRINK_COFFEE); - } - - return super.finishUsing(stack, world, user); + return super.finishUsingItem(stack, level, user); } @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { + public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag context) { if (CoffeeUtil.getCoffeeType(stack) != CoffeeTypes.EMPTY && CoffeeUtil.getCoffeeType(stack) != null) - tooltip.add(Text.translatable(CoffeeUtil.getCoffeeType(stack).getTranslationKey()).formatted(Formatting.GRAY)); - super.appendTooltip(stack, world, tooltip, context); + tooltip.add(Component.translatable(CoffeeUtil.getCoffeeType(stack).getTranslationKey()).withStyle(ChatFormatting.GRAY)); + super.appendHoverText(stack, level, tooltip, context); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/items/CoffeeBean.java b/src/main/java/ml/pluto7073/plutoscoffee/items/CoffeeBean.java index 8ebe7a0..22304ce 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/items/CoffeeBean.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/items/CoffeeBean.java @@ -1,23 +1,29 @@ package ml.pluto7073.plutoscoffee.items; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.item.FoodComponent; -import net.minecraft.item.Item; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.item.Item; public class CoffeeBean extends Item { - public static FoodComponent.Builder COFFEE_BEAN_FOOD_COMPONENT = new FoodComponent.Builder() - .snack() - .alwaysEdible() - .hunger(1) - .saturationModifier(0.5f) - .statusEffect(new StatusEffectInstance(StatusEffects.SPEED, 20 * 10), 1) - .statusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, 20 * 10), 1) - .statusEffect(new StatusEffectInstance(StatusEffects.HASTE, 20 * 10), 1); + public static FoodProperties.Builder COFFEE_BEAN_FOOD_COMPONENT = new FoodProperties.Builder() + .fast() + .alwaysEat() + .nutrition(1) + .saturationMod(0.5f) + .effect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 20 * 10), 1) + .effect(new MobEffectInstance(MobEffects.JUMP, 20 * 10), 1) + .effect(new MobEffectInstance(MobEffects.DIG_SPEED, 20 * 10), 1); + + public static FoodProperties.Builder DECAF_BEAN_FOOD_COMPONENT = new FoodProperties.Builder() + .fast() + .alwaysEat() + .nutrition(1) + .saturationMod(0); public CoffeeBean() { - super(new Item.Settings()); + super(new Item.Properties()); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/items/EspressoShotItem.java b/src/main/java/ml/pluto7073/plutoscoffee/items/EspressoShotItem.java index 7cdef52..6fbe903 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/items/EspressoShotItem.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/items/EspressoShotItem.java @@ -1,88 +1,84 @@ package ml.pluto7073.plutoscoffee.items; -import ml.pluto7073.pdapi.DrinkUtil; -import ml.pluto7073.plutoscoffee.CoffeeUtil; +import ml.pluto7073.pdapi.addition.chemicals.ConsumableChemicalRegistry; import ml.pluto7073.plutoscoffee.registry.ModStats; -import net.minecraft.advancement.criterion.Criteria; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsage; -import net.minecraft.item.Items; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; -import net.minecraft.util.UseAction; -import net.minecraft.world.World; -import net.minecraft.world.event.GameEvent; +import net.minecraft.ChatFormatting; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.*; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.gameevent.GameEvent; import org.jetbrains.annotations.Nullable; import java.util.List; +@MethodsReturnNonnullByDefault public class EspressoShotItem extends Item { private static final int MAX_USE_TIME = 32; - public static final int CAFFEINE_CONTENT = 85; - public EspressoShotItem(Settings settings) { + protected final int caffeine; + + public EspressoShotItem(int caffeine, Item.Properties settings) { super(settings); + this.caffeine = caffeine; } @Override - public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { - PlayerEntity playerEntity = user instanceof PlayerEntity ? (PlayerEntity) user : null; - if (playerEntity instanceof ServerPlayerEntity) { - Criteria.CONSUME_ITEM.trigger((ServerPlayerEntity)playerEntity, stack); + public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity user) { + Player player = user instanceof Player ? (Player) user : null; + if (player instanceof ServerPlayer) { + CriteriaTriggers.CONSUME_ITEM.trigger((ServerPlayer) player, stack); } - if (!world.isClient) { - if (playerEntity != null) { - float currentCaffeine = DrinkUtil.getPlayerCaffeine(playerEntity); - currentCaffeine += CAFFEINE_CONTENT; - DrinkUtil.setPlayerCaffeine(playerEntity, currentCaffeine); + if (!level.isClientSide) { + if (player != null) { + ConsumableChemicalRegistry.CAFFEINE.add(player, caffeine); } } - if (playerEntity != null) { - playerEntity.incrementStat(Stats.USED.getOrCreateStat(this)); - playerEntity.incrementStat(ModStats.DRINK_COFFEE); - if (!playerEntity.getAbilities().creativeMode) { - stack.decrement(1); + if (player != null) { + player.awardStat(Stats.ITEM_USED.get(this)); + player.awardStat(ModStats.DRINK_COFFEE); + if (!player.getAbilities().instabuild) { + stack.shrink(1); } } - if (playerEntity == null || !playerEntity.getAbilities().creativeMode) { + if (player == null || !player.getAbilities().instabuild) { if (stack.isEmpty()) { return new ItemStack(Items.GLASS_BOTTLE); } - if (playerEntity != null) { - playerEntity.getInventory().insertStack(new ItemStack(Items.GLASS_BOTTLE)); + if (player != null) { + player.getInventory().add(new ItemStack(Items.GLASS_BOTTLE)); } } - user.emitGameEvent(GameEvent.DRINK); + user.gameEvent(GameEvent.DRINK); return stack; } - public int getMaxUseTime(ItemStack stack) { + public int getUseDuration(ItemStack stack) { return MAX_USE_TIME; } - public UseAction getUseAction(ItemStack stack) { - return UseAction.DRINK; + public UseAnim getUseAnimation(ItemStack stack) { + return UseAnim.DRINK; } - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { - return ItemUsage.consumeHeldItem(world, user, hand); + public InteractionResultHolder use(Level level, Player user, InteractionHand hand) { + return ItemUtils.startUsingInstantly(level, user, hand); } - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - tooltip.add(Text.translatable("tooltip.pdapi.caffeine_content", CAFFEINE_CONTENT).formatted(Formatting.AQUA)); + public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag context) { + if (context.isCreative() || context.isAdvanced()) tooltip.add(Component.translatable("tooltip.pdapi.caffeine_content", caffeine).withStyle(ChatFormatting.AQUA)); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/items/LatteItem.java b/src/main/java/ml/pluto7073/plutoscoffee/items/LatteItem.java index e428916..6303906 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/items/LatteItem.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/items/LatteItem.java @@ -1,54 +1,40 @@ package ml.pluto7073.plutoscoffee.items; -import ml.pluto7073.pdapi.DrinkUtil; import ml.pluto7073.pdapi.item.AbstractCustomizableDrinkItem; -import ml.pluto7073.plutoscoffee.CoffeeUtil; import ml.pluto7073.plutoscoffee.registry.ModItems; import ml.pluto7073.plutoscoffee.registry.ModStats; -import net.minecraft.advancement.criterion.Criteria; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsage; -import net.minecraft.item.Items; -import net.minecraft.nbt.NbtList; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; -import net.minecraft.util.*; -import net.minecraft.world.World; -import net.minecraft.world.event.GameEvent; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; + +@MethodsReturnNonnullByDefault public class LatteItem extends AbstractCustomizableDrinkItem { - public LatteItem(Settings settings) { + public LatteItem(Properties settings) { super(Items.GLASS_BOTTLE, Temperature.HOT, settings); } - public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { - PlayerEntity playerEntity = user instanceof PlayerEntity ? (PlayerEntity) user : null; + public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity user) { + Player playerEntity = user instanceof Player ? (Player) user : null; if (playerEntity != null) { - playerEntity.incrementStat(ModStats.DRINK_COFFEE); + playerEntity.awardStat(ModStats.DRINK_COFFEE); } - return super.finishUsing(stack, world, user); + return super.finishUsingItem(stack, level, user); } public static ItemStack getStandardLatte() { ItemStack stack = new ItemStack(ModItems.LATTE); - NbtList adds = new NbtList(); - adds.add(DrinkUtil.stringAsNbt("plutoscoffee:espresso_shot")); - adds.add(DrinkUtil.stringAsNbt("plutoscoffee:espresso_shot")); - stack.getOrCreateSubNbt(DRINK_DATA_NBT_KEY).put("Additions", adds); + ListTag adds = new ListTag(); + adds.add(StringTag.valueOf("plutoscoffee:espresso_shot")); + adds.add(StringTag.valueOf("plutoscoffee:espresso_shot")); + stack.getOrCreateTagElement(DRINK_DATA_NBT_KEY).put("Additions", adds); return stack; } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/ComposterBlockMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/ComposterBlockMixin.java index 2197ce1..3305611 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/ComposterBlockMixin.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/mixins/ComposterBlockMixin.java @@ -1,8 +1,8 @@ package ml.pluto7073.plutoscoffee.mixins; import ml.pluto7073.plutoscoffee.registry.ModItems; -import net.minecraft.block.ComposterBlock; -import net.minecraft.item.ItemConvertible; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.ComposterBlock; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -13,16 +13,16 @@ public class ComposterBlockMixin { @Shadow - private static void registerCompostableItem(float levelIncreaseChance, ItemConvertible item) { + private static void add(float levelIncreaseChance, ItemLike item) { } - @Inject(at = @At("TAIL"), method = "registerDefaultCompostableItems") + @Inject(at = @At("TAIL"), method = "bootStrap") private static void teatime_registerModCompostItems(CallbackInfo ci) { - registerCompostableItem(0.3F, ModItems.COFFEE_BERRY); - registerCompostableItem(0.75F, ModItems.USED_COFFEE_GROUNDS); - registerCompostableItem(0.3f, ModItems.GROUND_LIGHT_ROAST); - registerCompostableItem(0.3f, ModItems.GROUND_MEDIUM_ROAST); - registerCompostableItem(0.3f, ModItems.GROUND_DARK_ROAST); + add(0.3F, ModItems.COFFEE_BERRY); + add(0.75F, ModItems.USED_COFFEE_GROUNDS); + add(0.3f, ModItems.GROUND_LIGHT_ROAST); + add(0.3f, ModItems.GROUND_MEDIUM_ROAST); + add(0.3f, ModItems.GROUND_DARK_ROAST); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/EntityMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/EntityMixin.java deleted file mode 100644 index 60478b2..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/EntityMixin.java +++ /dev/null @@ -1,11 +0,0 @@ -package ml.pluto7073.plutoscoffee.mixins; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.data.DataTracker; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(Entity.class) -public abstract class EntityMixin { - @Shadow public abstract DataTracker getDataTracker(); -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/LivingEntityMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/LivingEntityMixin.java deleted file mode 100644 index 1661f56..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/LivingEntityMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package ml.pluto7073.plutoscoffee.mixins; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffectInstance; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(LivingEntity.class) -public abstract class LivingEntityMixin extends EntityMixin { - @Shadow public abstract boolean addStatusEffect(StatusEffectInstance effect, @Nullable Entity source); - - @Shadow public abstract boolean addStatusEffect(StatusEffectInstance effect); -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/PlayerEntityMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/PlayerEntityMixin.java deleted file mode 100644 index 76e8805..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/PlayerEntityMixin.java +++ /dev/null @@ -1,8 +0,0 @@ -package ml.pluto7073.plutoscoffee.mixins; - -import net.minecraft.entity.player.PlayerEntity; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(PlayerEntity.class) -public abstract class PlayerEntityMixin extends LivingEntityMixin { -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/ServerPlayerEntityMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/ServerPlayerEntityMixin.java deleted file mode 100644 index 53162ef..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/ServerPlayerEntityMixin.java +++ /dev/null @@ -1,34 +0,0 @@ -package ml.pluto7073.plutoscoffee.mixins; - -import ml.pluto7073.pdapi.entity.PDTrackedData; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.server.network.ServerPlayerEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ServerPlayerEntity.class) -public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin { - - @Inject(at = @At("HEAD"), method = "tick") - public void plutoscoffee$caffeineLevelEffects(CallbackInfo ci) { - float caffeine = this.getDataTracker().get(PDTrackedData.PLAYER_CAFFEINE_AMOUNT); - - if (caffeine >= 100) { - this.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 600)); - } if (caffeine >= 150) { - this.addStatusEffect(new StatusEffectInstance(StatusEffects.HASTE, 600)); - } if (caffeine >= 450) { - this.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 600, 1)); - } if (caffeine >= 500) { - this.addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, 600)); - } if (caffeine >= 600) { - this.addStatusEffect(new StatusEffectInstance(StatusEffects.HASTE, 600, 1)); - } if (caffeine >= 700) { - this.addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, 600, 1)); - } - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/StructurePoolAccessor.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/StructurePoolAccessor.java index d218872..d7f14c9 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/StructurePoolAccessor.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/mixins/StructurePoolAccessor.java @@ -2,8 +2,8 @@ import com.mojang.datafixers.util.Pair; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import net.minecraft.structure.pool.StructurePool; -import net.minecraft.structure.pool.StructurePoolElement; +import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement; +import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; @@ -13,21 +13,21 @@ /** * Borrowed from FriendsAndFoes by Faboslav */ -@Mixin(StructurePool.class) +@Mixin(StructureTemplatePool.class) public interface StructurePoolAccessor { - @Accessor("elementCounts") - List> getElementCounts(); + @Accessor("rawTemplates") + List> getRawTemplates(); @Mutable - @Accessor("elementCounts") - void setElementCounts(List> elementCounts); + @Accessor("rawTemplates") + void setRawTemplates(List> rawTemplates); - @Accessor("elements") - ObjectArrayList getElements(); + @Accessor("templates") + ObjectArrayList getTemplates(); @Mutable - @Accessor("elements") - void setElements(ObjectArrayList elements); + @Accessor("templates") + void setTemplates(ObjectArrayList elements); } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/HandledScreensMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/HandledScreensMixin.java deleted file mode 100644 index e0fbaec..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/HandledScreensMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package ml.pluto7073.plutoscoffee.mixins.client; - -import ml.pluto7073.plutoscoffee.gui.CoffeeBrewerScreen; -import ml.pluto7073.plutoscoffee.gui.CoffeeGrindrScreen; -import ml.pluto7073.plutoscoffee.gui.EspressoMachineScreen; -import ml.pluto7073.plutoscoffee.registry.ModScreens; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.HandledScreens; -import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Environment(EnvType.CLIENT) -@Mixin(HandledScreens.class) -public class HandledScreensMixin { - - @Shadow - public static > void register(ScreenHandlerType type, HandledScreens.Provider provider) { - } - - @Inject(at = @At("TAIL"), method = "") - private static void plutoscoffee_clInitInject(CallbackInfo ci) { - register(ModScreens.BREWER_SCREEN_HANDLER_TYPE, CoffeeBrewerScreen::new); - register(ModScreens.GRINDR_SCREEN_HANDLER_TYPE, CoffeeGrindrScreen::new); - register(ModScreens.ESPRESSO_SCREEN_HANDLER_TYPE, EspressoMachineScreen::new); - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java index 58511a0..815a053 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java @@ -1,63 +1,60 @@ package ml.pluto7073.plutoscoffee.mixins.client; -import ml.pluto7073.pdapi.DrinkUtil; +import ml.pluto7073.pdapi.util.DrinkUtil; import ml.pluto7073.plutoscoffee.Client; -import ml.pluto7073.plutoscoffee.PlutosCoffee; import ml.pluto7073.plutoscoffee.CoffeeUtil; +import ml.pluto7073.plutoscoffee.registry.ModGuiTextures; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.registry.tag.FluidTags; -import net.minecraft.util.Identifier; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.tags.FluidTags; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.GameType; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Environment(EnvType.CLIENT) -@Mixin(InGameHud.class) +@Mixin(Gui.class) public abstract class InGameHudMixin { - @Unique private static final Identifier CAFFEINE_OUTLINE_TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/caffeine_content/outline.png"); - @Unique private static final Identifier CAFFEINE_FILL_TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/caffeine_content/fill.png"); - @Unique private static final Identifier ICONS = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/pc_icons.png"); + @Shadow @Final private Minecraft minecraft; - @Shadow @Final private MinecraftClient client; + @Shadow protected abstract Player getCameraPlayer(); - @Shadow protected abstract PlayerEntity getCameraPlayer(); + @Shadow private int screenWidth; - @Shadow private int scaledWidth; + @Shadow private int screenHeight; - @Shadow private int scaledHeight; + @Shadow protected abstract LivingEntity getPlayerVehicleWithHealth(); - @Shadow protected abstract LivingEntity getRiddenEntity(); - - @Inject(at = @At("TAIL"), method = "renderStatusBars") - public void plutoscoffee_renderCaffeineContentDisplay(DrawContext context, CallbackInfo ci) { + @Inject(at = @At("HEAD"), method = "render") + public void plutoscoffee_renderCaffeineContentDisplay(GuiGraphics graphics, float partialTick, CallbackInfo ci) { if (!Client.CONFIG.shouldShowCoffeeBar()) return; - PlayerEntity playerEntity = this.getCameraPlayer(); + Player playerEntity = this.getCameraPlayer(); + //noinspection DataFlowIssue + if (this.minecraft.gameMode.getPlayerMode() == GameType.CREATIVE) return; if (playerEntity == null) return; - this.client.getProfiler().push("caffeineDisplay"); + this.minecraft.getProfiler().push("caffeineDisplay"); - int centerX = this.scaledWidth / 2; - int baseYValue = this.scaledHeight - 49; + int centerX = this.screenWidth / 2; + int baseYValue = this.screenHeight - 49; - int max = playerEntity.getMaxAir(); - int maxOrCurrent = Math.min(playerEntity.getAir(), max); + int max = playerEntity.getMaxAirSupply(); + int maxOrCurrent = Math.min(playerEntity.getAirSupply(), max); - if (playerEntity.isSubmergedIn(FluidTags.WATER) || maxOrCurrent < max) { + if (playerEntity.isEyeInFluid(FluidTags.WATER) || maxOrCurrent < max) { baseYValue -= 10; } - LivingEntity ridden = this.getRiddenEntity(); + LivingEntity ridden = this.getPlayerVehicleWithHealth(); if (FabricLoader.getInstance().isModLoaded("dehydration") && !playerEntity.isCreative() && ridden == null) { baseYValue -= 10; @@ -72,10 +69,12 @@ public void plutoscoffee_renderCaffeineContentDisplay(DrawContext context, Callb float currentCaffeine = Math.min(3000f, DrinkUtil.getPlayerCaffeine(playerEntity)); int scaledCaffeineOutput = Math.round(currentCaffeine * (71f/3000f)); - context.drawTexture(ICONS, centerX + 10, baseYValue, 0, 0, 80, 8, 80, 16); - context.drawTexture(ICONS, centerX + 10, baseYValue, 0, 9, scaledCaffeineOutput, 8, 80, 16); + //graphics.blit(ICONS, centerX + 10, baseYValue, 0, 0, 80, 8, 80, 16); + //graphics.blit(ICONS, centerX + 10, baseYValue, 0, 9, scaledCaffeineOutput, 8, 80, 16); + ModGuiTextures.CAFFEINE_DISPLAY_OUTLINE.renderSection(graphics, centerX + 10, baseYValue, 80, 8); + ModGuiTextures.CAFFEINE_DISPLAY_FILL.renderSection(graphics, centerX + 10, baseYValue - 1, scaledCaffeineOutput, 8); - this.client.getProfiler().pop(); + this.minecraft.getProfiler().pop(); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/ItemColorsMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/ItemColorsMixin.java deleted file mode 100644 index bb6d4dd..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/ItemColorsMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package ml.pluto7073.plutoscoffee.mixins.client; - -import ml.pluto7073.plutoscoffee.CoffeeUtil; -import ml.pluto7073.plutoscoffee.registry.ModItems; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.color.block.BlockColors; -import net.minecraft.client.color.item.ItemColors; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ItemColors.class) -@Environment(EnvType.CLIENT) -public class ItemColorsMixin { - - @Inject(at = @At("TAIL"), method = "create", cancellable = true) - private static void plutoscoffee_createInject(BlockColors blockColors, CallbackInfoReturnable cir) { - ItemColors itemColors = cir.getReturnValue(); - itemColors.register((stack, tintIndex) -> tintIndex > 0 ? -1 : CoffeeUtil.getCoffeeColour(stack), ModItems.BREWED_COFFEE); - itemColors.register((stack, tintIndex) -> tintIndex > 0 ? -1 : CoffeeUtil.getLatteColour(stack), ModItems.LATTE); - cir.setReturnValue(itemColors); - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/MinecraftClientMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/MinecraftClientMixin.java deleted file mode 100644 index a2cc121..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/MinecraftClientMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package ml.pluto7073.plutoscoffee.mixins.client; - -import ml.pluto7073.plutoscoffee.PlutosCoffee; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftClient.class) -@Environment(EnvType.CLIENT) -public class MinecraftClientMixin { - - @Inject(at = @At("HEAD"), method = "tick") - public void plutoscoffee_onFirstTick(CallbackInfo ci) { - PlutosCoffee.loadLater(); - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/ResourceReloadLoggerMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/ResourceReloadLoggerMixin.java deleted file mode 100644 index 9bed6c7..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/ResourceReloadLoggerMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package ml.pluto7073.plutoscoffee.mixins.client; - - -import ml.pluto7073.plutoscoffee.version.VersionChecker; -import net.minecraft.client.resource.ResourceReloadLogger; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ResourceReloadLogger.class) -public class ResourceReloadLoggerMixin { - - @Inject(at = @At("TAIL"), method = "finish") - public void plutoscoffee_onFinishResourceReload(CallbackInfo ci) { - VersionChecker.showWarningScreen(); - } - -} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/network/ModPacketsS2C.java b/src/main/java/ml/pluto7073/plutoscoffee/network/ModPacketsS2C.java new file mode 100644 index 0000000..09e665f --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/network/ModPacketsS2C.java @@ -0,0 +1,29 @@ +package ml.pluto7073.plutoscoffee.network; + +import ml.pluto7073.plutoscoffee.coffee.MachineWaterSources; +import ml.pluto7073.plutoscoffee.network.s2c.SyncMachineWaterSourcesRegistryS2CPacket; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.minecraft.client.player.LocalPlayer; + +public class ModPacketsS2C { + + @Environment(EnvType.CLIENT) + public static void register() { + + ClientPlayConnectionEvents.INIT.register((handler, client) -> + ClientPlayNetworking.registerGlobalReceiver(SyncMachineWaterSourcesRegistryS2CPacket.TYPE, ModPacketsS2C::receiveWaterSources)); + + } + + @Environment(EnvType.CLIENT) + private static void receiveWaterSources(SyncMachineWaterSourcesRegistryS2CPacket packet, LocalPlayer player, PacketSender sender) { + MachineWaterSources.resetRegistry(); + + packet.map().forEach(MachineWaterSources::register); + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/network/s2c/SyncMachineWaterSourcesRegistryS2CPacket.java b/src/main/java/ml/pluto7073/plutoscoffee/network/s2c/SyncMachineWaterSourcesRegistryS2CPacket.java new file mode 100644 index 0000000..659156d --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/network/s2c/SyncMachineWaterSourcesRegistryS2CPacket.java @@ -0,0 +1,30 @@ +package ml.pluto7073.plutoscoffee.network.s2c; + +import ml.pluto7073.plutoscoffee.PlutosCoffee; +import ml.pluto7073.plutoscoffee.coffee.MachineWaterSource; +import net.fabricmc.fabric.api.networking.v1.FabricPacket; +import net.fabricmc.fabric.api.networking.v1.PacketType; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; + +import java.util.Map; + +public record SyncMachineWaterSourcesRegistryS2CPacket(Map map) implements FabricPacket { + + public static final PacketType TYPE = + PacketType.create(PlutosCoffee.asId("s2c/sync_machine_water_sources"), SyncMachineWaterSourcesRegistryS2CPacket::read); + + private static SyncMachineWaterSourcesRegistryS2CPacket read(FriendlyByteBuf buf) { + return new SyncMachineWaterSourcesRegistryS2CPacket(buf.readMap(FriendlyByteBuf::readResourceLocation, MachineWaterSource::read)); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeMap(map, FriendlyByteBuf::writeResourceLocation, MachineWaterSource::write); + } + + @Override + public PacketType getType() { + return TYPE; + } +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/recipe/PullingRecipe.java b/src/main/java/ml/pluto7073/plutoscoffee/recipe/PullingRecipe.java new file mode 100644 index 0000000..51890a1 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/recipe/PullingRecipe.java @@ -0,0 +1,114 @@ +package ml.pluto7073.plutoscoffee.recipe; + +import com.google.gson.JsonObject; +import ml.pluto7073.plutoscoffee.blocks.EspressoMachineBlockEntity; +import ml.pluto7073.plutoscoffee.registry.ModRecipes; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.core.NonNullList; +import net.minecraft.core.RegistryAccess; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.*; +import net.minecraft.world.level.Level; + +@MethodsReturnNonnullByDefault +public class PullingRecipe implements Recipe { + + private final ResourceLocation id; + public final Ingredient grounds, base; + public final int groundsRequired, pullTime; + final ItemStack result; + + public PullingRecipe(ResourceLocation id, Ingredient grounds, Ingredient base, int groundsRequired, int pullTime, ItemStack result) { + this.id = id; + this.grounds = grounds; + this.base = base; + this.groundsRequired = groundsRequired; + this.pullTime = pullTime; + this.result = result; + } + + @Override + public boolean matches(Container container, Level level) { + ItemStack groundsStack = container.getItem(EspressoMachineBlockEntity.GROUNDS_SLOT_INDEX); + ItemStack baseStack1 = container.getItem(EspressoMachineBlockEntity.ESPRESSO_SLOT_INDEX); + ItemStack baseStack2 = container.getItem(EspressoMachineBlockEntity.ESPRESSO_SLOT_2_INDEX); + return grounds.test(groundsStack) && groundsStack.getCount() >= groundsRequired && (base.test(baseStack1) || base.test(baseStack2)); + } + + @Override + public ItemStack assemble(Container inventory, RegistryAccess registryManager) { + return result.copy(); + } + + @Override + public boolean canCraftInDimensions(int width, int height) { + return true; + } + + @Override + public ItemStack getResultItem(RegistryAccess registryManager) { + return result.copy(); + } + + public ItemStack getResultItem() { + return result.copy(); + } + + @Override + public ResourceLocation getId() { + return id; + } + + @Override + public NonNullList getIngredients() { + return NonNullList.of(grounds, base); + } + + @Override + public RecipeSerializer getSerializer() { + return ModRecipes.PULLING_RECIPE_SERIALIZER; + } + + @Override + public RecipeType getType() { + return ModRecipes.PULLING_RECIPE_TYPE; + } + + public static class Serializer implements RecipeSerializer { + + @Override + public PullingRecipe fromJson(ResourceLocation id, JsonObject json) { + Ingredient grounds = Ingredient.fromJson(GsonHelper.getAsJsonObject(json, "grounds")); + Ingredient base = Ingredient.fromJson(GsonHelper.getAsJsonObject(json, "base")); + int groundsRequired = GsonHelper.getAsInt(json, "groundsRequired"); + int pullTime = GsonHelper.getAsInt(json, "pullTime", 400); + ItemStack result = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(json, "result")); + return new PullingRecipe(id, grounds, base, groundsRequired, pullTime, result); + } + + @Override + public PullingRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) { + Ingredient grounds = Ingredient.fromNetwork(buf); + Ingredient base = Ingredient.fromNetwork(buf); + int groundsCount = buf.readInt(); + int pullTime = buf.readInt(); + ItemStack result = buf.readItem(); + return new PullingRecipe(id, grounds, base, groundsCount, pullTime, result); + } + + @Override + public void toNetwork(FriendlyByteBuf buf, PullingRecipe recipe) { + recipe.grounds.toNetwork(buf); + recipe.base.toNetwork(buf); + buf.writeInt(recipe.groundsRequired); + buf.writeInt(recipe.pullTime); + buf.writeItem(recipe.result); + } + + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModBlocks.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModBlocks.java index 5f912cf..bc6a035 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModBlocks.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModBlocks.java @@ -1,45 +1,41 @@ package ml.pluto7073.plutoscoffee.registry; -import com.mojang.datafixers.types.Type; import ml.pluto7073.plutoscoffee.PlutosCoffee; import ml.pluto7073.plutoscoffee.blocks.*; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.Block; -import net.minecraft.block.MapColor; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.enums.Instrument; -import net.minecraft.block.piston.PistonBehavior; -import net.minecraft.datafixer.TypeReferences; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.sound.BlockSoundGroup; -import net.minecraft.util.Identifier; -import net.minecraft.util.Util; - +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.material.MapColor; +import net.minecraft.world.level.material.PushReaction; + +@SuppressWarnings("UnstableApiUsage") public class ModBlocks { - public static final Block COFFEE_CROP = new CoffeeCrop(AbstractBlock.Settings.create().mapColor(MapColor.DARK_GREEN).noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP).pistonBehavior(PistonBehavior.DESTROY)); - public static final Block COFFEE_BREWER = new CoffeeBrewerBlock(AbstractBlock.Settings.create().mapColor(MapColor.IRON_GRAY).requiresTool().strength(0.5F).luminance((state) -> 1).nonOpaque()); - public static final Block COFFEE_GRINDR = new CoffeeGrindrBlock(AbstractBlock.Settings.create().mapColor(MapColor.IRON_GRAY).requiresTool().strength(0.5F).luminance((state) -> 1).nonOpaque()); - public static final Block ESPRESSO_MACHINE = new EspressoMachineBlock(FabricBlockSettings.create().mapColor(MapColor.IRON_GRAY).requiresTool().strength(0.5f).luminance(state -> 1).nonOpaque()); + public static final Block COFFEE_CROP = new CoffeeCrop(FabricBlockSettings.create().mapColor(MapColor.COLOR_GREEN).noCollision().ticksRandomly().breakInstantly().sounds(SoundType.CROP).pistonBehavior(PushReaction.DESTROY)); + public static final Block COFFEE_BREWER = new CoffeeBrewerBlock(FabricBlockSettings.create().mapColor(MapColor.COLOR_GRAY).requiresTool().strength(0.5F).luminance((state) -> 1).nonOpaque()); + public static final Block COFFEE_GRINDR = new CoffeeGrindrBlock(FabricBlockSettings.create().mapColor(MapColor.COLOR_GRAY).requiresTool().strength(0.5F).luminance((state) -> 1).nonOpaque()); + public static final Block ESPRESSO_MACHINE = new EspressoMachineBlock(FabricBlockSettings.create().mapColor(MapColor.COLOR_GRAY).requiresTool().strength(0.5f).luminance(state -> 1).nonOpaque()); - public static final BlockEntityType COFFEE_BREWER_BLOCK_ENTITY_TYPE = create("coffee_brewer", BlockEntityType.Builder.create(CoffeeBrewerBlockEntity::new, COFFEE_BREWER)); - public static final BlockEntityType COFFEE_GRINDR_BLOCK_ENTITY_TYPE = create("coffee_grinder", BlockEntityType.Builder.create(CoffeeGrindrBlockEntity::new, COFFEE_GRINDR)); - public static final BlockEntityType ESPRESSO_MACHINE_BLOCK_ENTITY_TYPE = create("espresso_machine", BlockEntityType.Builder.create(EspressoMachineBlockEntity::new, ESPRESSO_MACHINE)); + public static final BlockEntityType COFFEE_BREWER_BLOCK_ENTITY_TYPE = create(BlockEntityType.Builder.of(CoffeeBrewerBlockEntity::new, COFFEE_BREWER)); + public static final BlockEntityType COFFEE_GRINDR_BLOCK_ENTITY_TYPE = create(BlockEntityType.Builder.of(CoffeeGrindrBlockEntity::new, COFFEE_GRINDR)); + public static final BlockEntityType ESPRESSO_MACHINE_BLOCK_ENTITY_TYPE = create(BlockEntityType.Builder.of(EspressoMachineBlockEntity::new, ESPRESSO_MACHINE)); private static void register(String id, Block block) { - Registry.register(Registries.BLOCK, new Identifier(PlutosCoffee.MOD_ID, id), block); + Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(PlutosCoffee.MOD_ID, id), block); } private static void register(String id, BlockEntityType entityType) { - Registry.register(Registries.BLOCK_ENTITY_TYPE, id, entityType); + Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, id, entityType); } - private static BlockEntityType create(String id, BlockEntityType.Builder builder) { - Type type = Util.getChoiceType(TypeReferences.BLOCK_ENTITY, id); - return builder.build(type); + private static BlockEntityType create(BlockEntityType.Builder builder) { + return builder.build(null); } public static void init() { @@ -51,5 +47,8 @@ public static void init() { register("coffee_brewer", COFFEE_BREWER_BLOCK_ENTITY_TYPE); register("coffee_grinder", COFFEE_GRINDR_BLOCK_ENTITY_TYPE); register("espresso_machine", ESPRESSO_MACHINE_BLOCK_ENTITY_TYPE); + + FluidStorage.SIDED.registerForBlockEntity((entity, dir) -> entity.insert, ESPRESSO_MACHINE_BLOCK_ENTITY_TYPE); + FluidStorage.SIDED.registerForBlockEntity((entity, dir) -> entity.insert, COFFEE_BREWER_BLOCK_ENTITY_TYPE); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModGuiTextures.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModGuiTextures.java new file mode 100644 index 0000000..ab9fd3f --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModGuiTextures.java @@ -0,0 +1,77 @@ +package ml.pluto7073.plutoscoffee.registry; + +import com.mojang.blaze3d.systems.RenderSystem; +import ml.pluto7073.plutoscoffee.PlutosCoffee; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.resources.ResourceLocation; + +public enum ModGuiTextures { + + CAFFEINE_DISPLAY_OUTLINE(0, 0, 80, 8), + CAFFEINE_DISPLAY_FILL(0, 8, 80, 8), + BREWER("container/coffee_brewer", 176, 166), + PROGRESS_ARROW("container/coffee_brewer", 176, 0, 9, 28), + PROGRESS_OUTLINE("container/coffee_brewer", 97, 16, 9, 28), + PROGRESS_BUBBLE("container/coffee_brewer", 185, 29, 9, 29), + WATER("container/coffee_brewer", 176, 29, 18, 4), + GRINDR("container/coffee_grinder", 176, 166), + ESPRESSO_MACHINE("container/espresso_machine", 176, 166), + STEAM_COLD("container/espresso_machine", 181, 33, 5, 32), + STEAM_HOT("container/espresso_machine", 186, 33, 5, 32), + STEAM_BURNT("container/espresso_machine", 176, 33, 5, 32); + + public final ResourceLocation id; + public final int width, height; + public final int startX, startY; + public final int fullWidth, fullHeight; + + ModGuiTextures(String id, int w, int h) { + this(id, 0, 0, w, h); + } + + ModGuiTextures(String id, int startX, int startY, int width, int height) { + this(id, startX, startY, width, height, width, height); + } + + ModGuiTextures(int startX, int startY, int width, int height) { + this("pc_icons", startX, startY, width, height, 80, 16); + } + + ModGuiTextures(String id, int startX, int startY, int width, int height, int fullWidth, int fullHeight) { + this.id = PlutosCoffee.asId("textures/gui/" + id + ".png"); + this.width = width; + this.height = height; + this.startX = startX; + this.startY = startY; + this.fullHeight = fullHeight; + this.fullWidth = fullWidth; + } + + @Environment(EnvType.CLIENT) + public void bind() { + RenderSystem.setShaderTexture(0, id); + } + + @Environment(EnvType.CLIENT) + public void render(GuiGraphics graphics, int x, int y) { + graphics.blit(id, x, y, startX, startY, width, height); + } + + @Environment(EnvType.CLIENT) + public void renderOnMenu(GuiGraphics graphics, int x, int y, int w, int h) { + graphics.blit(id, x, y, startX, startY, w, h); + } + + @Environment(EnvType.CLIENT) + public void renderCustomUV(GuiGraphics graphics, int x, int y, int u, int v, int w, int h) { + graphics.blit(id, x, y, u, v, w, h); + } + + @Environment(EnvType.CLIENT) + public void renderSection(GuiGraphics graphics, int x, int y, int w, int h) { + graphics.blit(id, x, y, startX, startY, w, h, fullWidth, fullHeight); + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModItems.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModItems.java index 87c624a..b24a7db 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModItems.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModItems.java @@ -2,40 +2,43 @@ import ml.pluto7073.plutoscoffee.PlutosCoffee; import ml.pluto7073.plutoscoffee.items.*; -import net.minecraft.block.Block; -import net.minecraft.item.AliasedBlockItem; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.Items; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.util.Identifier; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemNameBlockItem; +import net.minecraft.world.item.Items; public class ModItems { - public static final Item COFFEE_BERRY = new AliasedBlockItem(ModBlocks.COFFEE_CROP, new Item.Settings()); - public static final Item COFFEE_BREWER = new BlockItem(ModBlocks.COFFEE_BREWER, new Item.Settings()); - public static final Item COFFEE_GRINDR = new BlockItem(ModBlocks.COFFEE_GRINDR, new Item.Settings()); - public static final Item ESPRESSO_MACHINE = new BlockItem(ModBlocks.ESPRESSO_MACHINE, new Item.Settings()); + public static final Item COFFEE_BERRY = new ItemNameBlockItem(ModBlocks.COFFEE_CROP, new Item.Properties()); + public static final Item COFFEE_BREWER = new BlockItem(ModBlocks.COFFEE_BREWER, new Item.Properties()); + public static final Item COFFEE_GRINDR = new BlockItem(ModBlocks.COFFEE_GRINDR, new Item.Properties()); + public static final Item ESPRESSO_MACHINE = new BlockItem(ModBlocks.ESPRESSO_MACHINE, new Item.Properties()); public static final Item COFFEE_BEAN = new CoffeeBean(); - public static final Item LIGHT_ROAST_BEAN = new Item(new Item.Settings().food(CoffeeBean.COFFEE_BEAN_FOOD_COMPONENT.build())); - public static final Item MEDIUM_ROAST_BEAN = new Item(new Item.Settings().food(CoffeeBean.COFFEE_BEAN_FOOD_COMPONENT.build())); - public static final Item DARK_ROAST_BEAN = new Item(new Item.Settings().food(CoffeeBean.COFFEE_BEAN_FOOD_COMPONENT.build())); - public static final Item ESPRESSO_ROAST_BEAN = new Item(new Item.Settings().food(CoffeeBean.COFFEE_BEAN_FOOD_COMPONENT.build())); - public static final Item GROUND_LIGHT_ROAST = new Item(new Item.Settings()); - public static final Item GROUND_MEDIUM_ROAST = new Item(new Item.Settings()); - public static final Item GROUND_DARK_ROAST = new Item(new Item.Settings()); - public static final Item GROUND_ESPRESSO_ROAST = new Item(new Item.Settings()); - public static final Item USED_COFFEE_GROUNDS = new Item(new Item.Settings()); - public static final Item CARAMEL = new Item(new Item.Settings().recipeRemainder(Items.GLASS_BOTTLE).maxCount(16)); - public static final Item MOCHA_SAUCE = new Item(new Item.Settings().recipeRemainder(Items.GLASS_BOTTLE).maxCount(16)); + public static final Item LIGHT_ROAST_BEAN = new Item(new Item.Properties().food(CoffeeBean.COFFEE_BEAN_FOOD_COMPONENT.build())); + public static final Item MEDIUM_ROAST_BEAN = new Item(new Item.Properties().food(CoffeeBean.COFFEE_BEAN_FOOD_COMPONENT.build())); + public static final Item DARK_ROAST_BEAN = new Item(new Item.Properties().food(CoffeeBean.COFFEE_BEAN_FOOD_COMPONENT.build())); + public static final Item ESPRESSO_ROAST_BEAN = new Item(new Item.Properties().food(CoffeeBean.COFFEE_BEAN_FOOD_COMPONENT.build())); + public static final Item DECAF_ROAST_BEAN = new Item(new Item.Properties().food(CoffeeBean.DECAF_BEAN_FOOD_COMPONENT.build())); + public static final Item GROUND_LIGHT_ROAST = new Item(new Item.Properties()); + public static final Item GROUND_MEDIUM_ROAST = new Item(new Item.Properties()); + public static final Item GROUND_DARK_ROAST = new Item(new Item.Properties()); + public static final Item GROUND_ESPRESSO_ROAST = new Item(new Item.Properties()); + public static final Item GROUND_DECAF_ROAST = new Item(new Item.Properties()); + public static final Item USED_COFFEE_GROUNDS = new Item(new Item.Properties()); + public static final Item CARAMEL = new Item(new Item.Properties().craftRemainder(Items.GLASS_BOTTLE).stacksTo(16)); + public static final Item MOCHA_SAUCE = new Item(new Item.Properties().craftRemainder(Items.GLASS_BOTTLE).stacksTo(16)); - public static final Item BREWED_COFFEE = new BrewedCoffee(new Item.Settings().maxCount(1)); - public static final Item ESPRESSO_SHOT = new EspressoShotItem(new Item.Settings().maxCount(16).recipeRemainder(Items.GLASS_BOTTLE)); - public static final Item LATTE = new LatteItem(new Item.Settings().maxCount(1)); + public static final Item BREWED_COFFEE = new BrewedCoffee(new Item.Properties().stacksTo(1)); + public static final Item BLONDE_ESPRESSO_SHOT = new EspressoShotItem(85, new Item.Properties().stacksTo(16).craftRemainder(Items.GLASS_BOTTLE)); + public static final Item ESPRESSO_SHOT = new EspressoShotItem(75, new Item.Properties().stacksTo(16).craftRemainder(Items.GLASS_BOTTLE)); + public static final Item DECAF_ESPRESSO_SHOT = new EspressoShotItem(2, new Item.Properties().craftRemainder(Items.GLASS_BOTTLE).stacksTo(16)); + public static final Item LATTE = new LatteItem(new Item.Properties().stacksTo(1)); private static void register(String id, Item item) { - Registry.register(Registries.ITEM, new Identifier(PlutosCoffee.MOD_ID, id), item); + Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(PlutosCoffee.MOD_ID, id), item); } public static void init() { @@ -51,8 +54,12 @@ public static void init() { register("ground_dark_roast", GROUND_DARK_ROAST); register("espresso_roast_bean", ESPRESSO_ROAST_BEAN); register("espresso_grounds", GROUND_ESPRESSO_ROAST); + register("decaf_roast_bean", DECAF_ROAST_BEAN); + register("ground_decaf_roast", GROUND_DECAF_ROAST); register("brewed_coffee", BREWED_COFFEE); + register("blonde_espresso_shot", BLONDE_ESPRESSO_SHOT); register("espresso_shot", ESPRESSO_SHOT); + register("decaf_espresso_shot", DECAF_ESPRESSO_SHOT); register("latte", LATTE); register("used_coffee_grounds", USED_COFFEE_GROUNDS); diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModMisc.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModMisc.java index ed836df..63e024d 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModMisc.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModMisc.java @@ -1,65 +1,63 @@ package ml.pluto7073.plutoscoffee.registry; +import ml.pluto7073.pdapi.item.AbstractCustomizableDrinkItem; import ml.pluto7073.pdapi.item.PDItems; import ml.pluto7073.plutoscoffee.PlutosCoffee; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.Recipe; -import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; public class ModMisc { // Item Groups - public static final RegistryKey PC_GROUP; + public static final ResourceKey PC_GROUP; public static void init() {} - public static , T extends Recipe> S registerRecipeSerializer(String id, S serializer) { - return Registry.register(Registries.RECIPE_SERIALIZER, new Identifier(PlutosCoffee.MOD_ID, id), serializer); - } - static { // Item Groups - PC_GROUP = RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(PlutosCoffee.MOD_ID, "pc_group")); - Registry.register(Registries.ITEM_GROUP, PC_GROUP, FabricItemGroup.builder().icon(() -> new ItemStack(ModItems.MEDIUM_ROAST_BEAN)) - .displayName(Text.translatable("itemGroup.plutoscoffee.pc_group")) + PC_GROUP = ResourceKey.create(Registries.CREATIVE_MODE_TAB, PlutosCoffee.asId("pc_group")); + Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, PC_GROUP, FabricItemGroup.builder().icon(() -> new ItemStack(ModItems.MEDIUM_ROAST_BEAN)) + .title(Component.translatable("itemGroup.plutoscoffee.pc_group")) .build()); ItemGroupEvents.modifyEntriesEvent(PC_GROUP).register(stacks -> { - stacks.add(new ItemStack(ModItems.COFFEE_BREWER, 1)); - stacks.add(new ItemStack(ModItems.COFFEE_GRINDR, 1)); - stacks.add(new ItemStack(ModItems.ESPRESSO_MACHINE, 1)); - stacks.add(new ItemStack(PDItems.DRINK_WORKSTATION, 1)); - stacks.add(new ItemStack(ModItems.COFFEE_BERRY, 1)); - stacks.add(new ItemStack(ModItems.COFFEE_BEAN, 1)); - stacks.add(new ItemStack(ModItems.LIGHT_ROAST_BEAN, 1)); - stacks.add(new ItemStack(ModItems.MEDIUM_ROAST_BEAN, 1)); - stacks.add(new ItemStack(ModItems.DARK_ROAST_BEAN, 1)); - stacks.add(new ItemStack(ModItems.ESPRESSO_ROAST_BEAN, 1)); - stacks.add(new ItemStack(ModItems.GROUND_LIGHT_ROAST, 1)); - stacks.add(new ItemStack(ModItems.GROUND_MEDIUM_ROAST, 1)); - stacks.add(new ItemStack(ModItems.GROUND_DARK_ROAST, 1)); - stacks.add(new ItemStack(ModItems.GROUND_ESPRESSO_ROAST, 1)); + stacks.accept(new ItemStack(ModItems.COFFEE_BREWER, 1)); + stacks.accept(new ItemStack(ModItems.COFFEE_GRINDR, 1)); + stacks.accept(new ItemStack(ModItems.ESPRESSO_MACHINE, 1)); + stacks.accept(new ItemStack(PDItems.DRINK_WORKSTATION, 1)); + stacks.accept(new ItemStack(ModItems.COFFEE_BERRY, 1)); + stacks.accept(new ItemStack(ModItems.COFFEE_BEAN, 1)); + stacks.accept(new ItemStack(ModItems.LIGHT_ROAST_BEAN, 1)); + stacks.accept(new ItemStack(ModItems.MEDIUM_ROAST_BEAN, 1)); + stacks.accept(new ItemStack(ModItems.DARK_ROAST_BEAN, 1)); + stacks.accept(new ItemStack(ModItems.ESPRESSO_ROAST_BEAN, 1)); + stacks.accept(new ItemStack(ModItems.DECAF_ROAST_BEAN)); + stacks.accept(new ItemStack(ModItems.GROUND_LIGHT_ROAST, 1)); + stacks.accept(new ItemStack(ModItems.GROUND_MEDIUM_ROAST, 1)); + stacks.accept(new ItemStack(ModItems.GROUND_DARK_ROAST, 1)); + stacks.accept(new ItemStack(ModItems.GROUND_ESPRESSO_ROAST, 1)); + stacks.accept(new ItemStack(ModItems.GROUND_DECAF_ROAST)); ItemStack lightRoast = new ItemStack(ModItems.BREWED_COFFEE, 1); - lightRoast.getOrCreateSubNbt("Coffee").putString("CoffeeType", "light_roast"); + lightRoast.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", "light_roast"); ItemStack mediumRoast = lightRoast.copy(); - mediumRoast.getOrCreateSubNbt("Coffee").putString("CoffeeType", "medium_roast"); + mediumRoast.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", "medium_roast"); ItemStack darkRoast = mediumRoast.copy(); - darkRoast.getOrCreateSubNbt("Coffee").putString("CoffeeType", "dark_roast"); - stacks.add(lightRoast); - stacks.add(mediumRoast); - stacks.add(darkRoast); - stacks.add(new ItemStack(ModItems.ESPRESSO_SHOT)); - stacks.add(new ItemStack(ModItems.CARAMEL)); - stacks.add(new ItemStack(PDItems.MILK_BOTTLE)); - stacks.add(new ItemStack(ModItems.MOCHA_SAUCE)); + darkRoast.getOrCreateTagElement(AbstractCustomizableDrinkItem.DRINK_DATA_NBT_KEY).putString("CoffeeType", "dark_roast"); + stacks.accept(lightRoast); + stacks.accept(mediumRoast); + stacks.accept(darkRoast); + stacks.accept(new ItemStack(ModItems.BLONDE_ESPRESSO_SHOT)); + stacks.accept(new ItemStack(ModItems.ESPRESSO_SHOT)); + stacks.accept(new ItemStack(ModItems.DECAF_ESPRESSO_SHOT)); + stacks.accept(new ItemStack(ModItems.CARAMEL)); + stacks.accept(new ItemStack(PDItems.MILK_BOTTLE)); + stacks.accept(new ItemStack(ModItems.MOCHA_SAUCE)); }); } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModPointOfInterests.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModPointOfInterests.java index 4812e8a..66444cf 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModPointOfInterests.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModPointOfInterests.java @@ -4,31 +4,27 @@ import ml.pluto7073.pdapi.block.PDBlocks; import ml.pluto7073.plutoscoffee.PlutosCoffee; import net.fabricmc.fabric.api.object.builder.v1.world.poi.PointOfInterestHelper; -import net.minecraft.block.Block; -import net.minecraft.registry.Registries; -import net.minecraft.registry.RegistryKey; -import net.minecraft.world.poi.PointOfInterestType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.entity.ai.village.poi.PoiType; +import net.minecraft.world.level.block.Block; public class ModPointOfInterests { - public static final RegistryKey DRINK_WORKSTATION; + public static final ResourceKey DRINK_WORKSTATION; static { DRINK_WORKSTATION = create("drink_workstation", 1, 1, PDBlocks.DRINK_WORKSTATION); } - private static RegistryKey create(String name, int ticketCount, int searchDistance, Block block) { - RegistryKey key = RegistryKey.of(Registries.POINT_OF_INTEREST_TYPE.getKey(), PlutosCoffee.asId(name)); - PointOfInterestHelper.register(PlutosCoffee.asId(name), ticketCount, searchDistance, ImmutableSet.copyOf(block.getStateManager().getStates())); + private static ResourceKey create(String name, int ticketCount, int searchDistance, Block block) { + ResourceKey key = ResourceKey.create(BuiltInRegistries.POINT_OF_INTEREST_TYPE.key(), PlutosCoffee.asId(name)); + PointOfInterestHelper.register(PlutosCoffee.asId(name), ticketCount, searchDistance, ImmutableSet.copyOf(block.getStateDefinition().getPossibleStates())); return key; } public static void init() { - PlutosCoffee.logger.info("Drink Workstation POI Registered"); - } - - private static PointOfInterestType get(RegistryKey key) { - return Registries.POINT_OF_INTEREST_TYPE.get(key); + PlutosCoffee.LOGGER.info("Drink Workstation POI Registered"); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModRecipes.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModRecipes.java new file mode 100644 index 0000000..fe68f97 --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModRecipes.java @@ -0,0 +1,26 @@ +package ml.pluto7073.plutoscoffee.registry; + +import ml.pluto7073.plutoscoffee.PlutosCoffee; +import ml.pluto7073.plutoscoffee.recipe.PullingRecipe; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; + +public class ModRecipes { + + public static final RecipeType PULLING_RECIPE_TYPE = Registry.register(BuiltInRegistries.RECIPE_TYPE, PlutosCoffee.asId("pulling"), new RecipeType() { + public String toString() { + return "plutoscoffee:pulling"; + } + }); + public static final RecipeSerializer PULLING_RECIPE_SERIALIZER = registerRecipeSerializer("pulling", new PullingRecipe.Serializer()); + + private static , T extends Recipe> S registerRecipeSerializer(String id, S serializer) { + return Registry.register(BuiltInRegistries.RECIPE_SERIALIZER, PlutosCoffee.asId(id), serializer); + } + + public static void init() {} + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModScreens.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModScreens.java index 3e6736c..415506d 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModScreens.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModScreens.java @@ -1,32 +1,29 @@ package ml.pluto7073.plutoscoffee.registry; import ml.pluto7073.plutoscoffee.PlutosCoffee; -import ml.pluto7073.plutoscoffee.gui.CoffeeBrewerScreenHandler; -import ml.pluto7073.plutoscoffee.gui.CoffeeGrindrScreenHandler; -import ml.pluto7073.plutoscoffee.gui.EspressoMachineScreenHandler; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.resource.featuretoggle.FeatureFlags; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.util.Identifier; +import ml.pluto7073.plutoscoffee.gui.*; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.flag.FeatureFlags; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; public class ModScreens { - public static final ScreenHandlerType BREWER_SCREEN_HANDLER_TYPE; - public static final ScreenHandlerType GRINDR_SCREEN_HANDLER_TYPE; - public static final ScreenHandlerType ESPRESSO_SCREEN_HANDLER_TYPE; + public static final MenuType BREWER_MENU_TYPE; + public static final MenuType GRINDR_SCREEN_HANDLER_TYPE; + public static final MenuType ESPRESSO_SCREEN_HANDLER_TYPE; public static void init() {} - private static ScreenHandlerType register(String id, ScreenHandlerType.Factory factory) { - return Registry.register(Registries.SCREEN_HANDLER, new Identifier(PlutosCoffee.MOD_ID, id), new ScreenHandlerType<>(factory, FeatureFlags.VANILLA_FEATURES)); + private static MenuType register(String id, MenuType.MenuSupplier factory) { + return Registry.register(BuiltInRegistries.MENU, PlutosCoffee.asId(id), new MenuType<>(factory, FeatureFlags.VANILLA_SET)); } static { - BREWER_SCREEN_HANDLER_TYPE = register("coffee_brewer", CoffeeBrewerScreenHandler::new); - GRINDR_SCREEN_HANDLER_TYPE = register("coffee_grinder", CoffeeGrindrScreenHandler::new); - ESPRESSO_SCREEN_HANDLER_TYPE = register("espresso_machine", EspressoMachineScreenHandler::new); + BREWER_MENU_TYPE = register("coffee_brewer", CoffeeBrewerMenu::new); + GRINDR_SCREEN_HANDLER_TYPE = register("coffee_grinder", CoffeeGrindrMenu::new); + ESPRESSO_SCREEN_HANDLER_TYPE = register("espresso_machine", EspressoMachineMenu::new); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModSounds.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModSounds.java new file mode 100644 index 0000000..a633fcc --- /dev/null +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModSounds.java @@ -0,0 +1,16 @@ +package ml.pluto7073.plutoscoffee.registry; + +import ml.pluto7073.plutoscoffee.PlutosCoffee; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.sounds.SoundEvent; + +public class ModSounds { + + public static final SoundEvent COFFEE_GRINDER = SoundEvent.createVariableRangeEvent(PlutosCoffee.asId("block.coffee_grinder.grind")); + + public static void init() { + Registry.register(BuiltInRegistries.SOUND_EVENT, PlutosCoffee.asId("block.coffee_grinder.grind"), COFFEE_GRINDER); + } + +} diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModStats.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModStats.java index 81c5364..d3ee4db 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModStats.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModStats.java @@ -1,28 +1,28 @@ package ml.pluto7073.plutoscoffee.registry; import ml.pluto7073.plutoscoffee.PlutosCoffee; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.stat.StatFormatter; -import net.minecraft.stat.Stats; -import net.minecraft.util.Identifier; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.stats.StatFormatter; +import net.minecraft.stats.Stats; public class ModStats { - public static final Identifier DRINK_COFFEE = new Identifier(PlutosCoffee.MOD_ID, "drink_coffee"); - public static final Identifier INTERACT_WITH_COFFEE_BREWER = new Identifier(PlutosCoffee.MOD_ID, "interact_with_coffee_brewer"); - public static final Identifier INTERACT_WITH_COFFEE_GRINDR = new Identifier(PlutosCoffee.MOD_ID, "interact_with_coffee_grinder"); - public static final Identifier INTERACT_WITH_ESPRESSO_MACHINE = new Identifier(PlutosCoffee.MOD_ID, "interact_with_espresso_machine"); + public static final ResourceLocation DRINK_COFFEE = new ResourceLocation(PlutosCoffee.MOD_ID, "drink_coffee"); + public static final ResourceLocation INTERACT_WITH_COFFEE_BREWER = new ResourceLocation(PlutosCoffee.MOD_ID, "interact_with_coffee_brewer"); + public static final ResourceLocation INTERACT_WITH_COFFEE_GRINDR = new ResourceLocation(PlutosCoffee.MOD_ID, "interact_with_coffee_grinder"); + public static final ResourceLocation INTERACT_WITH_ESPRESSO_MACHINE = new ResourceLocation(PlutosCoffee.MOD_ID, "interact_with_espresso_machine"); public static void registerStats() { - Registry.register(Registries.CUSTOM_STAT, DRINK_COFFEE.getPath(), DRINK_COFFEE); - Stats.CUSTOM.getOrCreateStat(DRINK_COFFEE, StatFormatter.DEFAULT); - Registry.register(Registries.CUSTOM_STAT, INTERACT_WITH_COFFEE_BREWER.getPath(), INTERACT_WITH_COFFEE_BREWER); - Stats.CUSTOM.getOrCreateStat(INTERACT_WITH_COFFEE_BREWER, StatFormatter.DEFAULT); - Registry.register(Registries.CUSTOM_STAT, INTERACT_WITH_COFFEE_GRINDR.getPath(), INTERACT_WITH_COFFEE_GRINDR); - Stats.CUSTOM.getOrCreateStat(INTERACT_WITH_COFFEE_GRINDR, StatFormatter.DEFAULT); - Registry.register(Registries.CUSTOM_STAT, INTERACT_WITH_ESPRESSO_MACHINE.getPath(), INTERACT_WITH_ESPRESSO_MACHINE); - Stats.CUSTOM.getOrCreateStat(INTERACT_WITH_ESPRESSO_MACHINE, StatFormatter.DEFAULT); + Registry.register(BuiltInRegistries.CUSTOM_STAT, DRINK_COFFEE.getPath(), DRINK_COFFEE); + Stats.CUSTOM.get(DRINK_COFFEE, StatFormatter.DEFAULT); + Registry.register(BuiltInRegistries.CUSTOM_STAT, INTERACT_WITH_COFFEE_BREWER.getPath(), INTERACT_WITH_COFFEE_BREWER); + Stats.CUSTOM.get(INTERACT_WITH_COFFEE_BREWER, StatFormatter.DEFAULT); + Registry.register(BuiltInRegistries.CUSTOM_STAT, INTERACT_WITH_COFFEE_GRINDR.getPath(), INTERACT_WITH_COFFEE_GRINDR); + Stats.CUSTOM.get(INTERACT_WITH_COFFEE_GRINDR, StatFormatter.DEFAULT); + Registry.register(BuiltInRegistries.CUSTOM_STAT, INTERACT_WITH_ESPRESSO_MACHINE.getPath(), INTERACT_WITH_ESPRESSO_MACHINE); + Stats.CUSTOM.get(INTERACT_WITH_ESPRESSO_MACHINE, StatFormatter.DEFAULT); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModVillagerProfessions.java b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModVillagerProfessions.java index 1a4adeb..6e92c5b 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/registry/ModVillagerProfessions.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/registry/ModVillagerProfessions.java @@ -8,13 +8,14 @@ import ml.pluto7073.plutoscoffee.PlutosCoffee; import ml.pluto7073.plutoscoffee.coffee.CoffeeTypes; import ml.pluto7073.plutoscoffee.items.LatteItem; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.sound.SoundEvents; -import net.minecraft.village.TradeOffers; -import net.minecraft.village.VillagerProfession; -import net.minecraft.world.poi.PointOfInterestType; +import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.entity.ai.village.poi.PoiType; +import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraft.world.entity.npc.VillagerTrades; import java.util.function.Predicate; @@ -22,7 +23,7 @@ public class ModVillagerProfessions { public static final VillagerProfession BARISTA; - private static final Predicate> WORKSTATION_PREDICATE = (entry) -> entry.matchesKey(ModPointOfInterests.DRINK_WORKSTATION); + private static final Predicate> WORKSTATION_PREDICATE = (entry) -> entry.is(ModPointOfInterests.DRINK_WORKSTATION); static { BARISTA = register("barista", @@ -32,7 +33,7 @@ public class ModVillagerProfessions { WORKSTATION_PREDICATE, ImmutableSet.of(), ImmutableSet.of(), - SoundEvents.ENTITY_VILLAGER_WORK_CLERIC + SoundEvents.VILLAGER_WORK_CLERIC ) ); } @@ -40,42 +41,43 @@ public class ModVillagerProfessions { public static void init() {} public static void postInit() { - TradeOffers.PROFESSION_TO_LEVELED_TRADE.put(BARISTA, new Int2ObjectOpenHashMap<>(ImmutableMap.of( - 1, new TradeOffers.Factory[]{ - new TradeOffers.BuyForOneEmeraldFactory(ModItems.COFFEE_BERRY, 24, 16, 2), - new TradeOffers.SellItemFactory(ModItems.MOCHA_SAUCE, 1, 3, 16, 2), - new TradeOffers.BuyForOneEmeraldFactory(ModItems.COFFEE_BEAN, 22, 16, 2), - new TradeOffers.BuyForOneEmeraldFactory(ModItems.USED_COFFEE_GROUNDS, 26, 16, 2) + VillagerTrades.TRADES.put(BARISTA, new Int2ObjectOpenHashMap<>(ImmutableMap.of( + 1, new VillagerTrades.ItemListing[]{ + new VillagerTrades.EmeraldForItems(ModItems.COFFEE_BERRY, 24, 16, 2), + new VillagerTrades.ItemsForEmeralds(ModItems.MOCHA_SAUCE, 1, 3, 16, 2), + new VillagerTrades.EmeraldForItems(ModItems.COFFEE_BEAN, 22, 16, 2), + new VillagerTrades.EmeraldForItems(ModItems.USED_COFFEE_GROUNDS, 26, 16, 2) }, - 2, new TradeOffers.Factory[]{ - new TradeOffers.ProcessItemFactory(ModItems.LIGHT_ROAST_BEAN, 3, 2, ModItems.GROUND_LIGHT_ROAST, 12, 12, 5), - new TradeOffers.ProcessItemFactory(ModItems.MEDIUM_ROAST_BEAN, 3, 2, ModItems.GROUND_MEDIUM_ROAST, 12, 12, 5), - new TradeOffers.ProcessItemFactory(ModItems.DARK_ROAST_BEAN, 3, 2, ModItems.GROUND_DARK_ROAST, 12, 12, 5), - new TradeOffers.ProcessItemFactory(ModItems.ESPRESSO_ROAST_BEAN, 3, 2, ModItems.GROUND_ESPRESSO_ROAST, 12, 12, 5) + 2, new VillagerTrades.ItemListing[]{ + new VillagerTrades.ItemsAndEmeraldsToItems(ModItems.LIGHT_ROAST_BEAN, 3, 2, ModItems.GROUND_LIGHT_ROAST, 12, 12, 5), + new VillagerTrades.ItemsAndEmeraldsToItems(ModItems.MEDIUM_ROAST_BEAN, 3, 2, ModItems.GROUND_MEDIUM_ROAST, 12, 12, 5), + new VillagerTrades.ItemsAndEmeraldsToItems(ModItems.DARK_ROAST_BEAN, 3, 2, ModItems.GROUND_DARK_ROAST, 12, 12, 5), + new VillagerTrades.ItemsAndEmeraldsToItems(ModItems.ESPRESSO_ROAST_BEAN, 3, 2, ModItems.GROUND_ESPRESSO_ROAST, 12, 12, 5) }, - 3, new TradeOffers.Factory[]{ - new TradeOffers.SellItemFactory(CoffeeUtil.getBaseCoffee(CoffeeTypes.LIGHT_ROAST), 3, 1, 12, 10), - new TradeOffers.SellItemFactory(CoffeeUtil.getBaseCoffee(CoffeeTypes.MEDIUM_ROAST), 3, 1, 12, 10), - new TradeOffers.SellItemFactory(CoffeeUtil.getBaseCoffee(CoffeeTypes.DARK_ROAST), 3, 1, 12, 10), - new TradeOffers.SellItemFactory(LatteItem.getStandardLatte(), 5, 1, 12, 15), - new TradeOffers.BuyForOneEmeraldFactory(PDItems.MILK_BOTTLE, 16, 12, 5) + 3, new VillagerTrades.ItemListing[]{ + new VillagerTrades.ItemsForEmeralds(CoffeeUtil.getBaseCoffee(CoffeeTypes.LIGHT_ROAST), 3, 1, 12, 10), + new VillagerTrades.ItemsForEmeralds(CoffeeUtil.getBaseCoffee(CoffeeTypes.MEDIUM_ROAST), 3, 1, 12, 10), + new VillagerTrades.ItemsForEmeralds(CoffeeUtil.getBaseCoffee(CoffeeTypes.DARK_ROAST), 3, 1, 12, 10), + new VillagerTrades.ItemsForEmeralds(LatteItem.getStandardLatte(), 5, 1, 12, 15), + new VillagerTrades.EmeraldForItems(PDItems.MILK_BOTTLE, 16, 12, 5) }, - 4, new TradeOffers.Factory[] { - new TradeOffers.SellItemFactory(CoffeeUtil.getWithAdditions(LatteItem.getStandardLatte(), "pdapi:chorus_fruit"), 10, 1, 12, 20), - new TradeOffers.SellItemFactory(CoffeeUtil.getWithAdditions(LatteItem.getStandardLatte(), "pdapi:glow_berries"), 7, 1, 12, 20), - new TradeOffers.SellItemFactory(CoffeeUtil.getWithAdditions(LatteItem.getStandardLatte(), "pdapi:honey", "pdapi:sugar"), 5, 1, 12, 20), - new TradeOffers.SellItemFactory(CoffeeUtil.getWithAdditions(LatteItem.getStandardLatte(), "plutoscoffee:mocha_syrup", "plutoscoffee:caramel"), 8, 1, 12, 20) + 4, new VillagerTrades.ItemListing[] { + new VillagerTrades.ItemsForEmeralds(CoffeeUtil.getWithAdditions(LatteItem.getStandardLatte(), "pdapi:chorus_fruit"), 10, 1, 12, 20), + new VillagerTrades.ItemsForEmeralds(CoffeeUtil.getWithAdditions(LatteItem.getStandardLatte(), "pdapi:glow_berries"), 7, 1, 12, 20), + new VillagerTrades.ItemsForEmeralds(CoffeeUtil.getWithAdditions(LatteItem.getStandardLatte(), "pdapi:honey", "pdapi:sugar"), 5, 1, 12, 20), + new VillagerTrades.ItemsForEmeralds(CoffeeUtil.getWithAdditions(LatteItem.getStandardLatte(), "plutoscoffee:mocha_syrup", "plutoscoffee:caramel"), 8, 1, 12, 20), + new VillagerTrades.ItemsAndEmeraldsToItems(ModItems.DARK_ROAST_BEAN, 16, 2, ModItems.DECAF_ROAST_BEAN, 16, 12, 20) }, - 5, new TradeOffers.Factory[]{ - new TradeOffers.SellItemFactory(ModItems.COFFEE_BREWER, 24, 1, 12, 25), - new TradeOffers.SellItemFactory(ModItems.COFFEE_GRINDR, 20, 1, 12, 25), - new TradeOffers.SellItemFactory(ModItems.ESPRESSO_MACHINE, 30, 1, 12, 25) + 5, new VillagerTrades.ItemListing[]{ + new VillagerTrades.ItemsForEmeralds(ModItems.COFFEE_BREWER, 24, 1, 12, 25), + new VillagerTrades.ItemsForEmeralds(ModItems.COFFEE_GRINDR, 20, 1, 12, 25), + new VillagerTrades.ItemsForEmeralds(ModItems.ESPRESSO_MACHINE, 30, 1, 12, 25) } ))); } private static VillagerProfession register(String id, VillagerProfession profession ) { - return Registry.register(Registries.VILLAGER_PROFESSION, PlutosCoffee.asId(id), profession); + return Registry.register(BuiltInRegistries.VILLAGER_PROFESSION, PlutosCoffee.asId(id), profession); } } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/tags/ModItemTags.java b/src/main/java/ml/pluto7073/plutoscoffee/tags/ModItemTags.java index 25fbb93..3b0a484 100644 --- a/src/main/java/ml/pluto7073/plutoscoffee/tags/ModItemTags.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/tags/ModItemTags.java @@ -1,14 +1,13 @@ package ml.pluto7073.plutoscoffee.tags; import ml.pluto7073.plutoscoffee.PlutosCoffee; -import net.minecraft.item.Item; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.util.Identifier; +import net.minecraft.core.registries.Registries; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; public class ModItemTags { - public static final TagKey COFFEE_BEANS = TagKey.of(RegistryKeys.ITEM, new Identifier(PlutosCoffee.MOD_ID, "roasted_coffee_beans")); - public static final TagKey COFFEE_GROUNDS = TagKey.of(RegistryKeys.ITEM, new Identifier(PlutosCoffee.MOD_ID, "ground_coffee_beans")); + public static final TagKey COFFEE_BEANS = TagKey.create(Registries.ITEM, PlutosCoffee.asId("roasted_coffee_beans")); + public static final TagKey COFFEE_GROUNDS = TagKey.create(Registries.ITEM, PlutosCoffee.asId("ground_coffee_beans")); } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/version/VersionChecker.java b/src/main/java/ml/pluto7073/plutoscoffee/version/VersionChecker.java deleted file mode 100644 index 00532b9..0000000 --- a/src/main/java/ml/pluto7073/plutoscoffee/version/VersionChecker.java +++ /dev/null @@ -1,41 +0,0 @@ -package ml.pluto7073.plutoscoffee.version; - -import ml.pluto7073.plutoscoffee.PlutosCoffee; -import ml.pluto7073.plutoscoffee.gui.VersionWarningScreen; -import net.minecraft.client.MinecraftClient; - -import java.io.*; -import java.net.URL; - -public class VersionChecker { - - private static final String VERSION_LINK = "https://pluto7073.github.io/files/coffee-version-number.txt"; - - private static boolean outdated; - private static boolean screenShown = false; - - public static void checkOutdated() { - try (BufferedInputStream bis = new BufferedInputStream(new URL(VERSION_LINK).openStream())) { - BufferedReader reader = new BufferedReader(new InputStreamReader(bis)); - int recentVersion = Integer.parseInt(reader.readLine()); - reader.close(); - bis.close(); - outdated = recentVersion > PlutosCoffee.MOD_VERSION; - } catch (IOException e) { - PlutosCoffee.logger.error("An error occurred in loading VersionChecker, will assume mod is up-to-date.", e); - outdated = false; - } - } - - public static boolean isOutdated() { - return outdated; - } - - public static void showWarningScreen() { - if (screenShown) return; - screenShown = true; - if (!isOutdated()) return; - MinecraftClient.getInstance().setScreen(new VersionWarningScreen()); - } - -} diff --git a/src/main/resources/assets/plutoscoffee/blockstates/espresso_machine.json b/src/main/resources/assets/plutoscoffee/blockstates/espresso_machine.json index f2bc92b..33db116 100644 --- a/src/main/resources/assets/plutoscoffee/blockstates/espresso_machine.json +++ b/src/main/resources/assets/plutoscoffee/blockstates/espresso_machine.json @@ -35,14 +35,6 @@ "facing": "west" } }, - { - "apply": { - "model": "plutoscoffee:block/espresso_machine_milk" - }, - "when": { - "has_milk": "true" - } - }, { "apply": { "model": "plutoscoffee:block/espresso_machine_milk" diff --git a/src/main/resources/assets/plutoscoffee/lang/en_us.json b/src/main/resources/assets/plutoscoffee/lang/en_us.json index 9838365..0796f4a 100644 --- a/src/main/resources/assets/plutoscoffee/lang/en_us.json +++ b/src/main/resources/assets/plutoscoffee/lang/en_us.json @@ -7,8 +7,6 @@ "block.plutoscoffee.coffee_brewer": "Coffee Brewer", "block.plutoscoffee.coffee_grinder": "Coffee Grinder", "block.plutoscoffee.espresso_machine": "Espresso Machine", - "item.plutoscoffee.chocolate_coffee_bean": "Mocha Bean", - "item.plutoscoffee.chocolate_ground_coffee": "Ground Mocha Bean", "item.plutoscoffee.caramel": "Caramel", "item.plutoscoffee.medium_roast_bean": "Medium Roast Bean", "item.plutoscoffee.ground_medium_roast": "Medium Roast Grounds", @@ -16,31 +14,42 @@ "item.plutoscoffee.espresso_roast_bean": "Espresso Roast Bean", "item.plutoscoffee.ground_dark_roast": "Dark Roast Grounds", "item.plutoscoffee.espresso_grounds": "Espresso Grounds", + "item.plutoscoffee.decaf_roast_bean": "Decaffeinated Coffee Bean", + "item.plutoscoffee.ground_decaf_roast": "Ground Decaf", "item.plutoscoffee.brewed_coffee": "Brewed Coffee", + "item.plutoscoffee.blonde_espresso_shot": "Blonde Espresso Shot", "item.plutoscoffee.espresso_shot": "Espresso Shot", + "item.plutoscoffee.decaf_espresso_shot": "Decaf Espresso Shot", "item.plutoscoffee.latte": "Latte", "item.plutoscoffee.mocha_syrup": "Mocha Syrup", "item.plutoscoffee.used_coffee_grounds": "Used Coffee Grounds", - "plutosmods.version.header.plutoscoffee": "Pluto's Coffee Mod Out of Date", - "plutosmods.version.message": "Please download the new version from Curseforge, Modrinth, or Github!", - "plutosmods.version.open_mod_page": "Open Mod Page", - "plutosmods.version.okay": "Okay", "coffee_type.plutoscoffee.light_roast": "Light Roast", "coffee_type.plutoscoffee.medium_roast": "Medium Roast", "coffee_type.plutoscoffee.dark_roast": "Dark Roast", "coffee_type.plutoscoffee.espresso": "Espresso", + "coffee_type.plutoscoffee.decaf": "Decaf", "drink_addition.plutoscoffee.caramel": "Caramel x%1$s", "drink_addition.plutoscoffee.mocha_syrup": "Mocha Syrup x%1$s", "drink_addition.plutoscoffee.espresso_shot": "Espresso Shot x%1$s", + "drink_addition.plutoscoffee.blonde_espresso_shot": "Blonde Espresso Shot x%1$s", + "drink_addition.plutoscoffee.decaf_espresso_shot": "Decaf Espresso Shot x%1$s", "container.coffee_grinder": "Coffee Grinder", "container.coffee_brewer": "Coffee Brewer", "container.espresso_machine": "Espresso Machine", + "container.machine.water_tooltip": "%1$smB of Water", "itemGroup.plutoscoffee.pc_group": "Pluto's Coffee Mod Items", "stat.plutoscoffee.drink_coffee": "Bottles of Coffee Drank", "stat.plutoscoffee.interact_with_coffee_brewer": "Interactions with Coffee Brewer", "title.plutoscoffee.config": "Pluto's Coffee Mod Settings", + "title.category.pulling": "Espresso Pulling", + "title.category.grinding": "Coffee Grinding", + "category.pulling.pullTime.tooltip": "Shot Pulling Time: %1$s", "config.plutoscoffee.shouldShowCoffeeBar": "Show Current Caffeine Levels", "config.plutoscoffee.shouldShowCoffeeBar.tooltip": "Whether or not to show the current amount of caffeine in your system above the hunger bar", "pack.plutoscoffee.dark_gui": "Dark GUI", - "entity.minecraft.villager.barista": "Barista" + "entity.minecraft.villager.barista": "Barista", + "drink.plutoscoffee.caffe_latte": "Caffè Latte", + "drink.plutoscoffee.mocha": "Mocha", + "drink.plutoscoffee.sweet_caramel_latte": "Sweet Caramel Latte", + "drink.plutoscoffee.red_eye": "Red Eye" } diff --git a/src/main/resources/assets/plutoscoffee/models/item/blonde_espresso_shot.json b/src/main/resources/assets/plutoscoffee/models/item/blonde_espresso_shot.json new file mode 100644 index 0000000..8a80fd9 --- /dev/null +++ b/src/main/resources/assets/plutoscoffee/models/item/blonde_espresso_shot.json @@ -0,0 +1,3 @@ +{ + "parent": "plutoscoffee:item/espresso_shot" +} \ No newline at end of file diff --git a/src/main/resources/assets/plutoscoffee/models/item/decaf_espresso_shot.json b/src/main/resources/assets/plutoscoffee/models/item/decaf_espresso_shot.json new file mode 100644 index 0000000..8a80fd9 --- /dev/null +++ b/src/main/resources/assets/plutoscoffee/models/item/decaf_espresso_shot.json @@ -0,0 +1,3 @@ +{ + "parent": "plutoscoffee:item/espresso_shot" +} \ No newline at end of file diff --git a/src/main/resources/assets/plutoscoffee/models/item/decaf_roast_bean.json b/src/main/resources/assets/plutoscoffee/models/item/decaf_roast_bean.json new file mode 100644 index 0000000..5099905 --- /dev/null +++ b/src/main/resources/assets/plutoscoffee/models/item/decaf_roast_bean.json @@ -0,0 +1,3 @@ +{ + "parent": "plutoscoffee:item/dark_roast_bean" +} \ No newline at end of file diff --git a/src/main/resources/assets/plutoscoffee/models/item/ground_decaf_roast.json b/src/main/resources/assets/plutoscoffee/models/item/ground_decaf_roast.json new file mode 100644 index 0000000..4fb019b --- /dev/null +++ b/src/main/resources/assets/plutoscoffee/models/item/ground_decaf_roast.json @@ -0,0 +1,3 @@ +{ + "parent": "plutoscoffee:item/ground_dark_roast" +} \ No newline at end of file diff --git a/src/main/resources/assets/plutoscoffee/sounds.json b/src/main/resources/assets/plutoscoffee/sounds.json new file mode 100644 index 0000000..3621168 --- /dev/null +++ b/src/main/resources/assets/plutoscoffee/sounds.json @@ -0,0 +1,8 @@ +{ + "block.coffee_grinder.grind": { + "sounds": [ + "block/coffee_grinder/grind" + ], + "subtitle": "subtitles.block.coffee_grinder.grind" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/plutoscoffee/sounds/block/coffee_grinder/grind.ogg b/src/main/resources/assets/plutoscoffee/sounds/block/coffee_grinder/grind.ogg new file mode 100644 index 0000000..92c1816 Binary files /dev/null and b/src/main/resources/assets/plutoscoffee/sounds/block/coffee_grinder/grind.ogg differ diff --git a/src/main/resources/data/minecraft/tags/point_of_interest_type/acquirable_job_site.json b/src/main/resources/data/minecraft/tags/point_of_interest_type/acquirable_job_site.json index c4b704c..a6390ab 100644 --- a/src/main/resources/data/minecraft/tags/point_of_interest_type/acquirable_job_site.json +++ b/src/main/resources/data/minecraft/tags/point_of_interest_type/acquirable_job_site.json @@ -1,6 +1,6 @@ { "replace": false, "values": [ - "plutoscoffee:espresso_machine" + "plutoscoffee:drink_workstation" ] } \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/advancements/husbandry/drink_burnt_latte.json b/src/main/resources/data/plutoscoffee/advancements/husbandry/drink_burnt_latte.json new file mode 100644 index 0000000..41a4c93 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/advancements/husbandry/drink_burnt_latte.json @@ -0,0 +1,27 @@ +{ + "display": { + "icon": { + "item": "minecraft:campfire" + }, + "title": "Ouch that Burns!", + "description": "Drink a burnt latte (why did you do this?)", + "frame": "goal", + "show_toast": true, + "announce_to_chat": true, + "hidden": false + }, + "parent": "plutoscoffee:husbandry/obtain_coffee_cherry", + "criteria": { + "requirement": { + "trigger": "minecraft:consume_item", + "conditions": { + "item": { + "items": [ + "plutoscoffee:latte" + ], + "nbt": "{DrinkData:{Additions:[\"pdapi:burnt\"]}}" + } + } + } + } +} diff --git a/src/main/resources/data/plutoscoffee/advancements/husbandry/drinking_diamonds.json b/src/main/resources/data/plutoscoffee/advancements/husbandry/drinking_diamonds.json index 98db5f1..c9d4233 100644 --- a/src/main/resources/data/plutoscoffee/advancements/husbandry/drinking_diamonds.json +++ b/src/main/resources/data/plutoscoffee/advancements/husbandry/drinking_diamonds.json @@ -20,7 +20,7 @@ "plutoscoffee:brewed_coffee", "plutoscoffee:latte" ], - "nbt": "{Coffee:{Additions:[\"pdapi:diamond\"]}}" + "nbt": "{DrinkData:{Additions:[\"pdapi:diamond\"]}}" } } } diff --git a/src/main/resources/data/plutoscoffee/advancements/husbandry/sweet_coffee.json b/src/main/resources/data/plutoscoffee/advancements/husbandry/sweet_coffee.json index 8b641bc..47b925f 100644 --- a/src/main/resources/data/plutoscoffee/advancements/husbandry/sweet_coffee.json +++ b/src/main/resources/data/plutoscoffee/advancements/husbandry/sweet_coffee.json @@ -19,7 +19,7 @@ "items": [ "plutoscoffee:brewed_coffee" ], - "nbt": "{Coffee:{Additions:[\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\"]}}" + "nbt": "{DrinkData:{Additions:[\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:milk\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\",\"pdapi:sugar\"]}}" } } } diff --git a/src/main/resources/data/plutoscoffee/advancements/husbandry/whyy.json b/src/main/resources/data/plutoscoffee/advancements/husbandry/whyy.json index 4256ee5..26e38dd 100644 --- a/src/main/resources/data/plutoscoffee/advancements/husbandry/whyy.json +++ b/src/main/resources/data/plutoscoffee/advancements/husbandry/whyy.json @@ -20,7 +20,7 @@ "plutoscoffee:brewed_coffee", "plutoscoffee:latte" ], - "nbt": "{Coffee:{Additions:[\"pdapi:netherite\"]}}" + "nbt": "{DrinkData:{Additions:[\"pdapi:netherite\"]}}" } } } diff --git a/src/main/resources/data/plutoscoffee/drink_additions/blonde_espresso_shot.json b/src/main/resources/data/plutoscoffee/drink_additions/blonde_espresso_shot.json new file mode 100644 index 0000000..570f981 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/drink_additions/blonde_espresso_shot.json @@ -0,0 +1,5 @@ +{ + "changesColor": true, + "color": 1444354, + "caffeine": 85 +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/drink_additions/caramel.json b/src/main/resources/data/plutoscoffee/drink_additions/caramel.json index 7131f26..108ba56 100644 --- a/src/main/resources/data/plutoscoffee/drink_additions/caramel.json +++ b/src/main/resources/data/plutoscoffee/drink_additions/caramel.json @@ -2,12 +2,6 @@ "changesColor": true, "color": 5711373, "onDrinkActions": [ - { - "type": "pdapi:apply_status_effect", - "effect": "minecraft:health_boost", - "duration": 2400, - "amplifier": 2 - }, { "type": "pdapi:apply_status_effect", "effect": "minecraft:regeneration", @@ -17,7 +11,7 @@ { "type": "pdapi:apply_status_effect", "effect": "minecraft:absorption", - "duration": 200, + "duration": 400, "amplifier": 0 } ] diff --git a/src/main/resources/data/plutoscoffee/drink_additions/decaf_espresso_shot.json b/src/main/resources/data/plutoscoffee/drink_additions/decaf_espresso_shot.json new file mode 100644 index 0000000..7a50a81 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/drink_additions/decaf_espresso_shot.json @@ -0,0 +1,5 @@ +{ + "changesColor": true, + "color": 1444354, + "caffeine": 2 +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/drink_additions/espresso_shot.json b/src/main/resources/data/plutoscoffee/drink_additions/espresso_shot.json index 570f981..3b1ac25 100644 --- a/src/main/resources/data/plutoscoffee/drink_additions/espresso_shot.json +++ b/src/main/resources/data/plutoscoffee/drink_additions/espresso_shot.json @@ -1,5 +1,5 @@ { "changesColor": true, "color": 1444354, - "caffeine": 85 + "caffeine": 75 } \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/loot_tables/blocks/espresso_machine.json b/src/main/resources/data/plutoscoffee/loot_tables/blocks/espresso_machine.json new file mode 100644 index 0000000..c213359 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/loot_tables/blocks/espresso_machine.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "plutoscoffee:espresso_machine", + "functions": [ + { + "function": "minecraft:set_count", + "count": 1, + "add": false + } + ] + } + ] + } + ] +} diff --git a/src/main/resources/data/plutoscoffee/machine_water_sources/potion.json b/src/main/resources/data/plutoscoffee/machine_water_sources/potion.json new file mode 100644 index 0000000..208641d --- /dev/null +++ b/src/main/resources/data/plutoscoffee/machine_water_sources/potion.json @@ -0,0 +1,6 @@ +{ + "source": { + "tag": "c:potions" + }, + "water": 20250 +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/machine_water_sources/water_bucket.json b/src/main/resources/data/plutoscoffee/machine_water_sources/water_bucket.json new file mode 100644 index 0000000..cc27d25 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/machine_water_sources/water_bucket.json @@ -0,0 +1,6 @@ +{ + "source": { + "tag": "c:water_buckets" + }, + "water": 81000 +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/add_blonde_espresso.json b/src/main/resources/data/plutoscoffee/recipes/add_blonde_espresso.json new file mode 100644 index 0000000..9cc4728 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/recipes/add_blonde_espresso.json @@ -0,0 +1,10 @@ +{ + "type": "pdapi:drink_workstation", + "base": { + "tag": "pdapi:workstation_drinks" + }, + "addition": { + "item": "plutoscoffee:blonde_espresso_shot" + }, + "result": "plutoscoffee:blonde_espresso_shot" +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/add_decaf_espresso.json b/src/main/resources/data/plutoscoffee/recipes/add_decaf_espresso.json new file mode 100644 index 0000000..f1013ef --- /dev/null +++ b/src/main/resources/data/plutoscoffee/recipes/add_decaf_espresso.json @@ -0,0 +1,10 @@ +{ + "type": "pdapi:drink_workstation", + "base": { + "tag": "pdapi:workstation_drinks" + }, + "addition": { + "item": "plutoscoffee:decaf_espresso_shot" + }, + "result": "plutoscoffee:decaf_espresso_shot" +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/blonde_espresso_shot.json b/src/main/resources/data/plutoscoffee/recipes/blonde_espresso_shot.json new file mode 100644 index 0000000..fbc36dd --- /dev/null +++ b/src/main/resources/data/plutoscoffee/recipes/blonde_espresso_shot.json @@ -0,0 +1,15 @@ +{ + "type": "plutoscoffee:pulling", + "grounds": { + "item": "plutoscoffee:ground_coffee" + }, + "base": { + "item": "minecraft:glass_bottle" + }, + "groundsRequired": 2, + "pullTime": 400, + "result": { + "item": "plutoscoffee:blonde_espresso_shot", + "count": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_milk.json b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_milk.json index 1806cf0..a1219bb 100644 --- a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_milk.json +++ b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_milk.json @@ -4,7 +4,7 @@ "item": "plutoscoffee:brewed_coffee" }, "addition": { - "item": "plutoscoffee:milk_bottle" + "tag": "c:milk/milk_bottle" }, "result": "pdapi:milk" } \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/coffee_bean_pressing.json b/src/main/resources/data/plutoscoffee/recipes/coffee_bean_pressing.json new file mode 100644 index 0000000..cd1c712 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/recipes/coffee_bean_pressing.json @@ -0,0 +1,24 @@ +{ + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "create" + ] + } + ], + "type": "create:pressing", + "ingredients": [ + { + "item": "plutoscoffee:coffee_berry" + } + ], + "results": [ + { + "item": "plutoscoffee:coffee_bean" + }, + { + "item": "plutoscoffee:coffee_bean" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/decaf_espresso_shot.json b/src/main/resources/data/plutoscoffee/recipes/decaf_espresso_shot.json new file mode 100644 index 0000000..87c13c2 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/recipes/decaf_espresso_shot.json @@ -0,0 +1,15 @@ +{ + "type": "plutoscoffee:pulling", + "grounds": { + "item": "plutoscoffee:ground_decaf_roast" + }, + "base": { + "item": "minecraft:glass_bottle" + }, + "groundsRequired": 2, + "pullTime": 400, + "result": { + "item": "plutoscoffee:decaf_espresso_shot", + "count": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/espresso_shot.json b/src/main/resources/data/plutoscoffee/recipes/espresso_shot.json new file mode 100644 index 0000000..94c4b70 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/recipes/espresso_shot.json @@ -0,0 +1,15 @@ +{ + "type": "plutoscoffee:pulling", + "grounds": { + "item": "plutoscoffee:espresso_grounds" + }, + "base": { + "item": "minecraft:glass_bottle" + }, + "groundsRequired": 2, + "pullTime": 400, + "result": { + "item": "plutoscoffee:espresso_shot", + "count": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/specialty_drinks/caffe_latte.json b/src/main/resources/data/plutoscoffee/specialty_drinks/caffe_latte.json new file mode 100644 index 0000000..4e00233 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/specialty_drinks/caffe_latte.json @@ -0,0 +1,15 @@ +{ + "type": "pdapi:specialty_drink", + "base": "plutoscoffee:latte", + "additions": [ + "plutoscoffee:espresso_shot", + "plutoscoffee:espresso_shot" + ], + "caffeine": 150, + "color": 8935223, + "onDrinkActions": [ + { + "type": "pdapi:clear_harmful_effects" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/specialty_drinks/mocha.json b/src/main/resources/data/plutoscoffee/specialty_drinks/mocha.json new file mode 100644 index 0000000..88c6f00 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/specialty_drinks/mocha.json @@ -0,0 +1,22 @@ +{ + "type": "pdapi:specialty_drink", + "base": "plutoscoffee:latte", + "additions": [ + "plutoscoffee:mocha_syrup", + "plutoscoffee:mocha_syrup", + "plutoscoffee:espresso_shot", + "plutoscoffee:espresso_shot" + ], + "caffeine": 150, + "color": 1839885, + "onDrinkActions": [ + { + "type": "pdapi:restore_hunger", + "food": 12, + "saturation": 10 + }, + { + "type": "pdapi:clear_harmful_effects" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/specialty_drinks/red_eye.json b/src/main/resources/data/plutoscoffee/specialty_drinks/red_eye.json new file mode 100644 index 0000000..7501e4f --- /dev/null +++ b/src/main/resources/data/plutoscoffee/specialty_drinks/red_eye.json @@ -0,0 +1,19 @@ +{ + "type": "pdapi:specialty_drink", + "base": "plutoscoffee:brewed_coffee", + "additions": [ + "plutoscoffee:espresso_shot", + "plutoscoffee:espresso_shot", + "plutoscoffee:espresso_shot" + ], + "caffeine": 350, + "color": 985088, + "onDrinkActions": [ + { + "type": "pdapi:apply_status_effect", + "effect": "minecraft:haste", + "duration": 2400, + "amplifier": 2 + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/specialty_drinks/sweet_caramel_latte.json b/src/main/resources/data/plutoscoffee/specialty_drinks/sweet_caramel_latte.json new file mode 100644 index 0000000..a744295 --- /dev/null +++ b/src/main/resources/data/plutoscoffee/specialty_drinks/sweet_caramel_latte.json @@ -0,0 +1,38 @@ +{ + "type": "pdapi:specialty_drink", + "base": "plutoscoffee:latte", + "additions": [ + "pdapi:honey", + "plutoscoffee:caramel", + "plutoscoffee:caramel", + "plutoscoffee:espresso_shot", + "plutoscoffee:espresso_shot" + ], + "caffeine": 150, + "color": 8872502, + "onDrinkActions": [ + { + "type": "pdapi:apply_status_effect", + "effect": "minecraft:health_boost", + "duration": 2400, + "amplifier": 2 + }, + { + "type": "pdapi:apply_status_effect", + "effect": "minecraft:regeneration", + "duration": 200, + "amplifier": 0 + }, + { + "type": "pdapi:apply_status_effect", + "effect": "minecraft:absorption", + "duration": 200, + "amplifier": 0 + }, + { + "type": "pdapi:restore_hunger", + "food": 3, + "saturation": 10 + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/structures/village/desert/houses/desert_cafe.nbt b/src/main/resources/data/plutoscoffee/structures/village/desert/houses/desert_cafe.nbt new file mode 100644 index 0000000..e35ad65 Binary files /dev/null and b/src/main/resources/data/plutoscoffee/structures/village/desert/houses/desert_cafe.nbt differ diff --git a/src/main/resources/data/plutoscoffee/structures/village/plains/houses/plains_cafe.nbt b/src/main/resources/data/plutoscoffee/structures/village/plains/houses/plains_cafe.nbt new file mode 100644 index 0000000..3f3e168 Binary files /dev/null and b/src/main/resources/data/plutoscoffee/structures/village/plains/houses/plains_cafe.nbt differ diff --git a/src/main/resources/data/plutoscoffee/structures/village/savanna/houses/savanna_cafe.nbt b/src/main/resources/data/plutoscoffee/structures/village/savanna/houses/savanna_cafe.nbt new file mode 100644 index 0000000..0ddad64 Binary files /dev/null and b/src/main/resources/data/plutoscoffee/structures/village/savanna/houses/savanna_cafe.nbt differ diff --git a/src/main/resources/data/plutoscoffee/structures/village/taiga/houses/taiga_cafe.nbt b/src/main/resources/data/plutoscoffee/structures/village/taiga/houses/taiga_cafe.nbt new file mode 100644 index 0000000..5067a17 Binary files /dev/null and b/src/main/resources/data/plutoscoffee/structures/village/taiga/houses/taiga_cafe.nbt differ diff --git a/src/main/resources/data/plutoscoffee/tags/items/ground_coffee_beans.json b/src/main/resources/data/plutoscoffee/tags/items/ground_coffee_beans.json index 9c5654d..552fe7f 100644 --- a/src/main/resources/data/plutoscoffee/tags/items/ground_coffee_beans.json +++ b/src/main/resources/data/plutoscoffee/tags/items/ground_coffee_beans.json @@ -4,6 +4,7 @@ "plutoscoffee:ground_coffee", "plutoscoffee:ground_medium_roast", "plutoscoffee:ground_dark_roast", - "plutoscoffee:espresso_grounds" + "plutoscoffee:espresso_grounds", + "plutoscoffee:ground_decaf_roast" ] } \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/tags/items/roasted_coffee_beans.json b/src/main/resources/data/plutoscoffee/tags/items/roasted_coffee_beans.json index 8344f1d..7e4d2e3 100644 --- a/src/main/resources/data/plutoscoffee/tags/items/roasted_coffee_beans.json +++ b/src/main/resources/data/plutoscoffee/tags/items/roasted_coffee_beans.json @@ -4,6 +4,7 @@ "plutoscoffee:roasted_coffee_bean", "plutoscoffee:medium_roast_bean", "plutoscoffee:dark_roast_bean", - "plutoscoffee:espresso_roast_bean" + "plutoscoffee:espresso_roast_bean", + "plutoscoffee:decaf_roast_bean" ] } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f59cba4..509b38e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -41,7 +41,10 @@ "ml.pluto7073.plutoscoffee.Client" ], "modmenu": [ - "ml.pluto7073.plutoscoffee.config.CoffeeModMenuApiImpl" + "ml.pluto7073.plutoscoffee.compat.modmenu.CoffeeModMenuApiImpl" + ], + "rei_client": [ + "ml.pluto7073.plutoscoffee.compat.rei.CoffeeREI" ] }, "mixins": [ @@ -51,14 +54,15 @@ "depends": { "fabricloader": ">=0.15.7", - "fabric": "*", + "fabric-api": "*", "minecraft": "~1.20.1", "java": ">=17", "cloth-config": ">=11.1.118", - "pdapi": ">=0.1.2+1.20.1" + "pdapi": ">=0.1.4" }, "suggests": { "flamingo": "*", - "modmenu": "*" + "modmenu": "*", + "rei": "*" } } diff --git a/src/main/resources/plutoscoffee.mixins.json b/src/main/resources/plutoscoffee.mixins.json index 20cc44a..b764e86 100644 --- a/src/main/resources/plutoscoffee.mixins.json +++ b/src/main/resources/plutoscoffee.mixins.json @@ -5,18 +5,10 @@ "compatibilityLevel": "JAVA_17", "mixins": [ "ComposterBlockMixin", - "EntityMixin", - "LivingEntityMixin", - "PlayerEntityMixin", - "ServerPlayerEntityMixin", "StructurePoolAccessor" ], "client": [ - "client.HandledScreensMixin", - "client.InGameHudMixin", - "client.ItemColorsMixin", - "client.MinecraftClientMixin", - "client.ResourceReloadLoggerMixin" + "client.InGameHudMixin" ], "injectors": { "defaultRequire": 1