From 27217ad5ae5ebc5edd5eebc148e67d2a208b4768 Mon Sep 17 00:00:00 2001 From: KnightMiner Date: Fri, 21 Aug 2020 20:42:39 -0400 Subject: [PATCH] Greatly simplify cauldron contents No longer needs quite so many interfaces. Instead of an extension pattern, it uses a contains pattern --- src/generated/resources/.cache/cache | 56 ++--- .../recipes/recipes/cauldron/bed/undye.json | 4 +- .../cauldron/beetroot_soup/stew_large.json | 4 +- .../cauldron/beetroot_soup/stew_small.json | 4 +- .../recipes/cauldron/carpet/undye.json | 4 +- .../cauldron/carpeted_trapdoor/undye.json | 4 +- .../recipes/cauldron/concrete/black.json | 4 +- .../recipes/cauldron/concrete/blue.json | 4 +- .../recipes/cauldron/concrete/brown.json | 4 +- .../recipes/cauldron/concrete/cyan.json | 4 +- .../recipes/cauldron/concrete/gray.json | 4 +- .../recipes/cauldron/concrete/green.json | 4 +- .../recipes/cauldron/concrete/light_blue.json | 4 +- .../recipes/cauldron/concrete/light_gray.json | 4 +- .../recipes/cauldron/concrete/lime.json | 4 +- .../recipes/cauldron/concrete/magenta.json | 4 +- .../recipes/cauldron/concrete/orange.json | 4 +- .../recipes/cauldron/concrete/pink.json | 4 +- .../recipes/cauldron/concrete/purple.json | 4 +- .../recipes/cauldron/concrete/red.json | 4 +- .../recipes/cauldron/concrete/white.json | 4 +- .../recipes/cauldron/concrete/yellow.json | 4 +- .../recipes/cauldron/dry_cauldron.json | 4 +- .../recipes/cauldron/empty_water_bottle.json | 4 +- .../recipes/cauldron/fill_water_bottle.json | 4 +- .../cauldron/mushroom_stew/stew_large.json | 4 +- .../cauldron/mushroom_stew/stew_small.json | 4 +- .../cauldron/sticky_piston_cleaning.json | 4 +- .../recipes/cauldron/water_from_ice.json | 7 +- .../recipes/recipes/cauldron/wool/undye.json | 4 +- .../recipe/cauldron/CauldronContentTypes.java | 52 ++--- .../recipe/cauldron/CauldronIngredients.java | 20 +- .../contents/CauldronContentType.java | 213 ++++++++++++++++++ .../contents/EmptyCauldronContents.java | 26 ++- .../cauldron/contents/EmptyContentType.java | 36 +++ .../cauldron/contents/ICauldronColor.java | 17 -- .../cauldron/contents/ICauldronContents.java | 63 +++--- .../cauldron/contents/ICauldronDye.java | 19 -- .../cauldron/contents/ICauldronFluid.java | 25 -- .../cauldron/contents/ICauldronPotion.java | 20 -- .../cauldron/contents/NamedContentType.java | 43 ++++ .../contents/RegistryContentType.java | 44 ++++ .../contenttype/CauldronContentType.java | 97 -------- .../cauldron/contenttype/MapContentType.java | 149 ------------ .../contenttype/NamedContentType.java | 56 ----- .../contenttype/RegistryContentType.java | 80 ------- .../contenttype/SingletonContentType.java | 56 ----- .../cauldron/contenttype/package-info.java | 7 - .../ingredient/ContentMatchIngredient.java | 69 +++--- .../ingredient/ContentTypeIngredient.java | 78 ------- .../ingredient/FluidCauldronIngredient.java | 11 +- .../recipe/CauldronRecipeBuilder.java | 6 +- .../recipes/InspirationsRecipes.java | 11 +- .../recipes/RecipesClientEvents.java | 14 +- .../recipes/data/RecipesRecipeProvider.java | 7 +- .../cauldron/EmptyBucketCauldronRecipe.java | 4 +- .../cauldron/FillBucketCauldronRecipe.java | 10 +- .../cauldron/contents/CauldronColor.java | 34 --- .../cauldron/contents/CauldronContents.java | 72 ++++++ .../recipe/cauldron/contents/CauldronDye.java | 32 --- .../cauldron/contents/CauldronFluid.java | 24 -- .../cauldron/contents/CauldronPotion.java | 33 --- .../cauldron/contents/CauldronWater.java | 35 --- .../cauldron/contents/ColorContentType.java | 40 +++- .../cauldron/contents/DyeContentType.java | 28 +++ .../cauldron/contents/FluidContentType.java | 28 +++ .../cauldron/contents/PotionContentType.java | 32 +++ 67 files changed, 746 insertions(+), 1020 deletions(-) create mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/CauldronContentType.java create mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyContentType.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronColor.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronDye.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronFluid.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronPotion.java create mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/NamedContentType.java create mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/RegistryContentType.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/CauldronContentType.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/MapContentType.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/NamedContentType.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/RegistryContentType.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/SingletonContentType.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/package-info.java delete mode 100644 src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/ContentTypeIngredient.java delete mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronColor.java create mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronContents.java delete mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronDye.java delete mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronFluid.java delete mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronPotion.java delete mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronWater.java create mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/DyeContentType.java create mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/FluidContentType.java create mode 100644 src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/PotionContentType.java diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 90ad186c..1ede90bf 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -344,13 +344,13 @@ ff5fde84a7450ccb06afdc5bd0f304b35a588767 data/inspirations/recipes/recipes/cauld 0e5e751d7bcb35d50307d72a6eba56ee132f2a88 data/inspirations/recipes/recipes/cauldron/bed/pink.json 028811ba5fb23e7858d9fb95f5ed598389020431 data/inspirations/recipes/recipes/cauldron/bed/purple.json 885d69f7737ba3ba8522f82dfc7c739b22659db1 data/inspirations/recipes/recipes/cauldron/bed/red.json -118d098f311ea540b2f6d4eab4608d4ee52dc2a5 data/inspirations/recipes/recipes/cauldron/bed/undye.json +bf7624bd0b13278ab60b60dc92adae54eca88b8d data/inspirations/recipes/recipes/cauldron/bed/undye.json 89b881547d2c94cdd27981cae5da50685fd31a1c data/inspirations/recipes/recipes/cauldron/bed/white.json d50dc899aed6e6694f029a00d53db65ff615659b data/inspirations/recipes/recipes/cauldron/bed/yellow.json fe04e5bbb4df454952a6157b73be9fa5704bebb7 data/inspirations/recipes/recipes/cauldron/beetroot_soup/empty_bowl.json 93a92eda0d8f38ec22a0b0eb5028c4b6057462d3 data/inspirations/recipes/recipes/cauldron/beetroot_soup/fill_bowl.json -be2746b59e3ca2429e995dcccb0cedee9b342c97 data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_large.json -822a07bece6524bf5c8634b8dbda8ec0468b2674 data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_small.json +942cd6b327c7210c0151c07426f03504e546a160 data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_large.json +8f9e790c6897e438f4ff04ef9aecd03543fae2bb data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_small.json ebdd67116d86ac764cb4a96bd6557aaeeb02abf7 data/inspirations/recipes/recipes/cauldron/carpet/black.json 04de7b6a4cb5ad8a8dc488a6f1f8f17ff82ad3a7 data/inspirations/recipes/recipes/cauldron/carpet/blue.json 8a2a5b8f40786170e04b617a789ae590525665fa data/inspirations/recipes/recipes/cauldron/carpet/brown.json @@ -365,7 +365,7 @@ befe8bf90532875d4a39208053750c3fd7f1b1a6 data/inspirations/recipes/recipes/cauld ea91e7213978be241f269036996de0b32027a4e8 data/inspirations/recipes/recipes/cauldron/carpet/pink.json f722f6ceccb597cc27c12ab2ab4aa2d2bce9db36 data/inspirations/recipes/recipes/cauldron/carpet/purple.json fe2e2c16caa769480e2d4573b8f11ab014181150 data/inspirations/recipes/recipes/cauldron/carpet/red.json -51a482222f83be4a2376b1f23beff71cabe83542 data/inspirations/recipes/recipes/cauldron/carpet/undye.json +a8e7a8439ac65ae9a3876c7cea3482a2aec7141c data/inspirations/recipes/recipes/cauldron/carpet/undye.json 95dcb74a75afeaf78dd0f52450d804b2cdff2788 data/inspirations/recipes/recipes/cauldron/carpet/white.json b9465b154cd0ff9e1049f1e91301845ff0365ce7 data/inspirations/recipes/recipes/cauldron/carpet/yellow.json 0470b03da3e918e67ece2e1e84fa16497d6ec2dd data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/black.json @@ -382,34 +382,34 @@ b5884bb930640dd834d09b2b6b7aa77300f9c82b data/inspirations/recipes/recipes/cauld 7624d77593a563edb7b3eed074971bc668163128 data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/pink.json b5da52edeef70d69d9c1301142c1740752617164 data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/purple.json f59ee5ba86c76518f9b19ca169cf63bbae294656 data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/red.json -79738e90bd75482e6a759b3051eedad159be0963 data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/undye.json +a182da117b9c3e9ca2aba8eeda7b6fe3bd71866b data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/undye.json d5031ffbd2e8d55ffeebae5321ca28e4602965f7 data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/white.json c06892adc3f05763d07e32392359f3d432d07bb6 data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/yellow.json -132c99663e26b7150ff1444f32e275493c0a5e19 data/inspirations/recipes/recipes/cauldron/concrete/black.json -0875af1056d3155b6476bf0ff3f75192cf69dee8 data/inspirations/recipes/recipes/cauldron/concrete/blue.json -dcc5d8515a823187c828e4677e67a8ab9a3385a6 data/inspirations/recipes/recipes/cauldron/concrete/brown.json -c8e0dcc9135997bedcc0fdfe5bd6f51796c9dfcc data/inspirations/recipes/recipes/cauldron/concrete/cyan.json -e7234db22c24b2d500146e2d5d090ef1cd3d24f8 data/inspirations/recipes/recipes/cauldron/concrete/gray.json -aeac89b70f584280e5dc0a5dcdd2fd463bcf8145 data/inspirations/recipes/recipes/cauldron/concrete/green.json -fbb2c51f988fcab124e78fa21339adea574873fd data/inspirations/recipes/recipes/cauldron/concrete/light_blue.json -e924b14746782032ba7c9d42f2fc0f1690d7a461 data/inspirations/recipes/recipes/cauldron/concrete/light_gray.json -e855eacff3e29485d2afa28a7f32de2ac1282c5d data/inspirations/recipes/recipes/cauldron/concrete/lime.json -c9fe6496cfa63c35077b24203e03d998894eb884 data/inspirations/recipes/recipes/cauldron/concrete/magenta.json -fb8dc91fbfcae1dfd727f33b0060d1fcac403e44 data/inspirations/recipes/recipes/cauldron/concrete/orange.json -1f56e41330563836986cac194620aefef8b3dd5a data/inspirations/recipes/recipes/cauldron/concrete/pink.json -18c278c6376d06bb905e1440b6e56083acfe6079 data/inspirations/recipes/recipes/cauldron/concrete/purple.json -79216a840f3246b32788c9c24d62939885272acd data/inspirations/recipes/recipes/cauldron/concrete/red.json -c36d97efc6139a38362917b4f70af611a6363953 data/inspirations/recipes/recipes/cauldron/concrete/white.json -920e42339c8565472ea117b55f6e8db8f962d903 data/inspirations/recipes/recipes/cauldron/concrete/yellow.json -21f604795851709a2a5fd4b6f2e741b8f8d40bfb data/inspirations/recipes/recipes/cauldron/dry_cauldron.json +0e413ff323876212be74571c02d7a1da5029f3d2 data/inspirations/recipes/recipes/cauldron/concrete/black.json +ac46600ef33927fec3bbfeec0bab9056c3148862 data/inspirations/recipes/recipes/cauldron/concrete/blue.json +7ace4ffd7e65670f377760174703d9ba9d15aae6 data/inspirations/recipes/recipes/cauldron/concrete/brown.json +dcd2506fde5d1f5dd3c7a68acac9e3ffbea5e440 data/inspirations/recipes/recipes/cauldron/concrete/cyan.json +72d147f6b2f9f4c8e928c5f8697aa107c77d8b13 data/inspirations/recipes/recipes/cauldron/concrete/gray.json +8c45501c31a858841aa2faf25007fd19872c4767 data/inspirations/recipes/recipes/cauldron/concrete/green.json +3f728016417d3cc290da3b38abb40b2efb1b6019 data/inspirations/recipes/recipes/cauldron/concrete/light_blue.json +1dc71c0ea2e4ca03ac7cb98254609df1cfcb97bc data/inspirations/recipes/recipes/cauldron/concrete/light_gray.json +8f4a4d2b7a189037d861bdc9ad108a8af32cb946 data/inspirations/recipes/recipes/cauldron/concrete/lime.json +154c70ee9970f469480ea5fadd7d55d2ee8a55b7 data/inspirations/recipes/recipes/cauldron/concrete/magenta.json +de4d8f6200ca5bff37aee10d22d0c6960676d088 data/inspirations/recipes/recipes/cauldron/concrete/orange.json +7ffbc3ca29db34e510a6aec43b03950b2dbd0b2c data/inspirations/recipes/recipes/cauldron/concrete/pink.json +921360717b921b870883d59caf73e6fa4b2db88d data/inspirations/recipes/recipes/cauldron/concrete/purple.json +4cc35a80a7d051ba175f3109e73cc96bcce7d9a6 data/inspirations/recipes/recipes/cauldron/concrete/red.json +486abf89406b3b41d5b6ad39b497c369b3b240b0 data/inspirations/recipes/recipes/cauldron/concrete/white.json +a2a0f68bff93a511a93067c9908b2f199f0a6eca data/inspirations/recipes/recipes/cauldron/concrete/yellow.json +2365d44b42e90bfe183573bc31f1723904174685 data/inspirations/recipes/recipes/cauldron/dry_cauldron.json 76b1e9beb5a6facb9f15e8371481bbe30e683171 data/inspirations/recipes/recipes/cauldron/empty_bucket.json c49a70ef68bd82dd01a76e117d8d34377bec3e13 data/inspirations/recipes/recipes/cauldron/empty_water_bottle.json 2b54da72e999ac88c3a26fdf0704bd06ce80dc90 data/inspirations/recipes/recipes/cauldron/fill_bucket.json -d525c5e252de31c8d912d2777fe5586243446441 data/inspirations/recipes/recipes/cauldron/fill_water_bottle.json +671084a2f99a4eeb3c729ea4a139a7d80faf7f96 data/inspirations/recipes/recipes/cauldron/fill_water_bottle.json 0f1decbf0d527791fcf956bf199cfba5fa730072 data/inspirations/recipes/recipes/cauldron/mushroom_stew/empty_bowl.json def302b63a17ef3556026710133f421060c90dfc data/inspirations/recipes/recipes/cauldron/mushroom_stew/fill_bowl.json -7771be7f9473ffdafce5c992cf1428462371d16f data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_large.json -3c1c309d8e25a5075dd6628a4f73163b7e592b73 data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_small.json +67c2477abb999527c987bf7f22f26d8b1de75305 data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_large.json +c56b9b6571bce9b432e1d895f992f7704264e2aa data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_small.json 58d531cf8366510412dc96632626733c9897c5bb data/inspirations/recipes/recipes/cauldron/potato_soup/empty_bowl.json 03487ade1aaa38e408a2c7934672fe11578fd990 data/inspirations/recipes/recipes/cauldron/potato_soup/fill_bowl.json 55b751b5237c3c8dbe171f55604e7c7a94df5923 data/inspirations/recipes/recipes/cauldron/potato_soup/item.json @@ -419,8 +419,8 @@ def302b63a17ef3556026710133f421060c90dfc data/inspirations/recipes/recipes/cauld aad3506b0cc731722e532198acdb319c5435efa4 data/inspirations/recipes/recipes/cauldron/rabbit_stew/fill_bowl.json 58afa39737eecfe66d86f840732217ca757c6b05 data/inspirations/recipes/recipes/cauldron/rabbit_stew/stew_large.json 0305b565e6a256b2d29b6c95cf9a30ff106ecdb2 data/inspirations/recipes/recipes/cauldron/rabbit_stew/stew_small.json -ce008b3e79cc99e164f808cf6b49fff51c083042 data/inspirations/recipes/recipes/cauldron/sticky_piston_cleaning.json -7d457e6ccb9afc7e19e58275f9acd3309afe2a2f data/inspirations/recipes/recipes/cauldron/water_from_ice.json +0c50714d42fa8c1102739251e10803d3e7ed13d4 data/inspirations/recipes/recipes/cauldron/sticky_piston_cleaning.json +5003206cda94f6c73bf3cf395f5d167ce4a7bff2 data/inspirations/recipes/recipes/cauldron/water_from_ice.json 1b4f5bba2d11fdbadda300c14af01e08a7c32163 data/inspirations/recipes/recipes/cauldron/wool/black.json 0112a766363b620d7d24cda58b8b8f27535a0ee8 data/inspirations/recipes/recipes/cauldron/wool/blue.json 538f110b4ce42596e22a2a9adc9359cdb92c545a data/inspirations/recipes/recipes/cauldron/wool/brown.json @@ -435,7 +435,7 @@ e5b780ab9fb646624c77415a016ee491ab6e6f6d data/inspirations/recipes/recipes/cauld 7ae245acf6d4e7448c9c378da868c72f10f14ddc data/inspirations/recipes/recipes/cauldron/wool/pink.json ddd52e287e070755057c4f72fda56af4a0792495 data/inspirations/recipes/recipes/cauldron/wool/purple.json e6e68450740d059b372f2723aae830e31957cbf1 data/inspirations/recipes/recipes/cauldron/wool/red.json -1ed63722861370d4fa918626f6225bb667eeb0d9 data/inspirations/recipes/recipes/cauldron/wool/undye.json +e2b6b85b3ad1f3afb54bb096cfd012e9fe759895 data/inspirations/recipes/recipes/cauldron/wool/undye.json f4f18ecab1ff73a6257c0f5442a863b65ab66357 data/inspirations/recipes/recipes/cauldron/wool/white.json 65ce50304886a83953b3d1c71b37167e20a93caa data/inspirations/recipes/recipes/cauldron/wool/yellow.json 16a719f79bdc48f49c973b2ccd36073b4601d990 data/inspirations/recipes/tools/barometer.json diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/bed/undye.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/bed/undye.json index 32f2dbaa..720c0f45 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/bed/undye.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/bed/undye.json @@ -15,8 +15,8 @@ "tag": "minecraft:beds" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_large.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_large.json index 313f07b7..ff94a9f4 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_large.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_large.json @@ -16,8 +16,8 @@ }, "amount": 12, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 2 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_small.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_small.json index 08f2ec81..150415ae 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_small.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/beetroot_soup/stew_small.json @@ -16,8 +16,8 @@ }, "amount": 6, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1, diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/carpet/undye.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/carpet/undye.json index bd5a637f..ebb8296a 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/carpet/undye.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/carpet/undye.json @@ -15,8 +15,8 @@ "tag": "minecraft:carpets" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/undye.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/undye.json index 194f96ea..7b96f202 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/undye.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/carpeted_trapdoor/undye.json @@ -19,8 +19,8 @@ "tag": "inspirations:carpeted_trapdoors" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/black.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/black.json index 391aee92..d1b29b52 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/black.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/black.json @@ -15,8 +15,8 @@ "item": "minecraft:black_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/blue.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/blue.json index 9daaeb83..a597acac 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/blue.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/blue.json @@ -15,8 +15,8 @@ "item": "minecraft:blue_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/brown.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/brown.json index 8bb42503..e1e83015 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/brown.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/brown.json @@ -15,8 +15,8 @@ "item": "minecraft:brown_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/cyan.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/cyan.json index 91054012..5b12876b 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/cyan.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/cyan.json @@ -15,8 +15,8 @@ "item": "minecraft:cyan_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/gray.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/gray.json index c121dbde..d3e82dbd 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/gray.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/gray.json @@ -15,8 +15,8 @@ "item": "minecraft:gray_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/green.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/green.json index e6012667..a5fb1fae 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/green.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/green.json @@ -15,8 +15,8 @@ "item": "minecraft:green_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/light_blue.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/light_blue.json index 11c2b690..1a210977 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/light_blue.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/light_blue.json @@ -15,8 +15,8 @@ "item": "minecraft:light_blue_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/light_gray.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/light_gray.json index 025273fa..301e529c 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/light_gray.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/light_gray.json @@ -15,8 +15,8 @@ "item": "minecraft:light_gray_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/lime.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/lime.json index 8b9a4149..df097f29 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/lime.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/lime.json @@ -15,8 +15,8 @@ "item": "minecraft:lime_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/magenta.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/magenta.json index 5d18e56e..09b8af64 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/magenta.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/magenta.json @@ -15,8 +15,8 @@ "item": "minecraft:magenta_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/orange.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/orange.json index 3cc44836..ee002bd9 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/orange.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/orange.json @@ -15,8 +15,8 @@ "item": "minecraft:orange_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/pink.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/pink.json index 1b8a0eba..c826d815 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/pink.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/pink.json @@ -15,8 +15,8 @@ "item": "minecraft:pink_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/purple.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/purple.json index 02700160..a987e702 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/purple.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/purple.json @@ -15,8 +15,8 @@ "item": "minecraft:purple_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/red.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/red.json index ab1357d0..da15f615 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/red.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/red.json @@ -15,8 +15,8 @@ "item": "minecraft:red_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/white.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/white.json index a546fba5..487aee59 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/white.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/white.json @@ -15,8 +15,8 @@ "item": "minecraft:white_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/yellow.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/yellow.json index 28086bb1..93a13037 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/yellow.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/concrete/yellow.json @@ -15,8 +15,8 @@ "item": "minecraft:yellow_concrete_powder" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/dry_cauldron.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/dry_cauldron.json index 874ea7cc..f8c3bbd6 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/dry_cauldron.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/dry_cauldron.json @@ -15,8 +15,8 @@ "item": "minecraft:sponge" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/empty_water_bottle.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/empty_water_bottle.json index 98ad37bf..98774ccf 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/empty_water_bottle.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/empty_water_bottle.json @@ -18,8 +18,8 @@ "nbt": "{Potion:\"minecraft:water\"}" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "max": 2 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/fill_water_bottle.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/fill_water_bottle.json index 7371d814..713206a2 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/fill_water_bottle.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/fill_water_bottle.json @@ -15,8 +15,8 @@ "item": "minecraft:glass_bottle" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_large.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_large.json index 44cfde88..4fc04f0c 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_large.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_large.json @@ -16,8 +16,8 @@ }, "amount": 4, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 2 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_small.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_small.json index 34a33b2b..b1306eee 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_small.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/mushroom_stew/stew_small.json @@ -16,8 +16,8 @@ }, "amount": 2, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1, diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/sticky_piston_cleaning.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/sticky_piston_cleaning.json index 1d1eb177..67b2b5d6 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/sticky_piston_cleaning.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/sticky_piston_cleaning.json @@ -15,8 +15,8 @@ "item": "minecraft:sticky_piston" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/water_from_ice.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/water_from_ice.json index d5a4bd4b..32165975 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/water_from_ice.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/water_from_ice.json @@ -15,8 +15,8 @@ "item": "minecraft:ice" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "max": 2 @@ -24,7 +24,8 @@ }, "output": { "contents": { - "type": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "set": 3 diff --git a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/wool/undye.json b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/wool/undye.json index bbfeed10..2030a879 100644 --- a/src/generated/resources/data/inspirations/recipes/recipes/cauldron/wool/undye.json +++ b/src/generated/resources/data/inspirations/recipes/recipes/cauldron/wool/undye.json @@ -15,8 +15,8 @@ "tag": "minecraft:wool" }, "contents": { - "type": "inspirations:content_type", - "name": "inspirations:water" + "type": "inspirations:fluid", + "name": "minecraft:water" }, "level": { "min": 1 diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/CauldronContentTypes.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/CauldronContentTypes.java index 84e7eed0..d925c5dd 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/CauldronContentTypes.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/CauldronContentTypes.java @@ -6,22 +6,14 @@ import com.google.gson.JsonSyntaxException; import io.netty.handler.codec.DecoderException; import knightminer.inspirations.Inspirations; +import knightminer.inspirations.library.recipe.cauldron.contents.CauldronContentType; import knightminer.inspirations.library.recipe.cauldron.contents.EmptyCauldronContents; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronColor; +import knightminer.inspirations.library.recipe.cauldron.contents.EmptyContentType; import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronDye; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronFluid; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronPotion; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; -import knightminer.inspirations.library.recipe.cauldron.contenttype.MapContentType; -import knightminer.inspirations.library.recipe.cauldron.contenttype.NamedContentType; -import knightminer.inspirations.library.recipe.cauldron.contenttype.RegistryContentType; -import knightminer.inspirations.library.recipe.cauldron.contenttype.SingletonContentType; -import knightminer.inspirations.recipes.recipe.cauldron.contents.CauldronDye; -import knightminer.inspirations.recipes.recipe.cauldron.contents.CauldronFluid; -import knightminer.inspirations.recipes.recipe.cauldron.contents.CauldronPotion; -import knightminer.inspirations.recipes.recipe.cauldron.contents.CauldronWater; import knightminer.inspirations.recipes.recipe.cauldron.contents.ColorContentType; +import knightminer.inspirations.recipes.recipe.cauldron.contents.DyeContentType; +import knightminer.inspirations.recipes.recipe.cauldron.contents.FluidContentType; +import knightminer.inspirations.recipes.recipe.cauldron.contents.PotionContentType; import net.minecraft.fluid.Fluid; import net.minecraft.item.DyeColor; import net.minecraft.nbt.CompoundNBT; @@ -30,8 +22,6 @@ import net.minecraft.util.JSONUtils; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.Constants.NBT; -import net.minecraftforge.registries.ForgeRegistries; -import org.apache.logging.log4j.util.BiConsumer; import javax.annotation.Nullable; @@ -46,23 +36,20 @@ public class CauldronContentTypes { /* Public constants */ /** Generic water type */ - public static final SingletonContentType EMPTY = register("empty", new SingletonContentType<>(EmptyCauldronContents.class, EmptyCauldronContents.INSTANCE)); - - /** Generic water type */ - public static final SingletonContentType WATER = register("water", new SingletonContentType<>(CauldronWater.class, new CauldronWater())); + public static final EmptyContentType EMPTY = register("empty", new EmptyContentType()); /** Contains an arbitrary color */ - public static final MapContentType COLOR = register("color", new ColorContentType()); + public static final CauldronContentType COLOR = register("color", new ColorContentType()); /** Contains a specific color */ @SuppressWarnings("ConstantConditions") - public static final MapContentType DYE = register("dye", new NamedContentType<>(ICauldronDye.class, CauldronDye::new, name -> DyeColor.byTranslationKey(name, null), ICauldronDye::getDye)); + public static final CauldronContentType DYE = register("dye", new DyeContentType()); /** Contains a specific color */ - public static final MapContentType POTION = register("potion", new RegistryContentType<>(ICauldronPotion.class, CauldronPotion::new, ForgeRegistries.POTION_TYPES, ICauldronPotion::getPotion)); + public static final CauldronContentType POTION = register("potion", new PotionContentType()); /** Contains a specific fluid */ - public static final MapContentType FLUID = register("fluid", new RegistryContentType<>(ICauldronFluid.class, CauldronFluid::new, ForgeRegistries.FLUIDS, ICauldronFluid::getFluid)); + public static final CauldronContentType FLUID = register("fluid", new FluidContentType()); /** * Registers a new content type @@ -98,17 +85,6 @@ private static > T register(String name, T type return type; } - /** - * Handles the generics for an unknown type generics - * @param type Type to check - * @param contents Contents - * @param consumer Logic to run - * @param Type class - */ - private static void write(CauldronContentType type, ICauldronContents contents, BiConsumer, T> consumer) { - type.get(contents).ifPresent(cont -> consumer.accept(type, cont)); - } - /** * Gets the name for a content type * @param type Type to get @@ -131,7 +107,7 @@ public static JsonObject toJson(ICauldronContents contents) { JsonObject json = new JsonObject(); CauldronContentType type = contents.getType(); json.addProperty(KEY_TYPE, getName(type).toString()); - write(type, contents, (t,c) -> t.write(c, json)); + type.write(contents, json); return json; } @@ -158,7 +134,7 @@ public static CompoundNBT toNbt(ICauldronContents contents) { CompoundNBT nbt = new CompoundNBT(); CauldronContentType type = contents.getType(); nbt.putString(KEY_TYPE, getName(type).toString()); - write(type, contents, (t,c) -> t.write(c, nbt)); + type.write(contents, nbt); return nbt; } @@ -178,7 +154,7 @@ public static ICauldronContents read(CompoundNBT nbt) { } } } - return CauldronContentTypes.WATER.get(); + return EmptyCauldronContents.INSTANCE; } /** @@ -189,7 +165,7 @@ public static ICauldronContents read(CompoundNBT nbt) { public static void write(ICauldronContents contents, PacketBuffer buffer) { CauldronContentType type = contents.getType(); buffer.writeResourceLocation(getName(type)); - write(type, contents, (t,c) -> t.write(c, buffer)); + type.write(contents, buffer); } /** diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/CauldronIngredients.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/CauldronIngredients.java index b2795577..98e05d3e 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/CauldronIngredients.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/CauldronIngredients.java @@ -6,13 +6,9 @@ import com.google.gson.JsonSyntaxException; import io.netty.handler.codec.DecoderException; import knightminer.inspirations.Inspirations; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronColor; +import knightminer.inspirations.library.recipe.cauldron.contents.CauldronContentType; import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronDye; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronPotion; -import knightminer.inspirations.library.recipe.cauldron.contenttype.MapContentType; import knightminer.inspirations.library.recipe.cauldron.ingredient.ContentMatchIngredient; -import knightminer.inspirations.library.recipe.cauldron.ingredient.ContentTypeIngredient; import knightminer.inspirations.library.recipe.cauldron.ingredient.FluidCauldronIngredient; import knightminer.inspirations.library.recipe.cauldron.ingredient.ICauldronIngredient; import knightminer.inspirations.library.recipe.cauldron.ingredient.ICauldronIngredientSerializer; @@ -32,18 +28,16 @@ public class CauldronIngredients { /* Public constants */ /** Generic content match serializer */ - public static final ContentMatchIngredient.Serializer MATCH = register("match_content", ContentMatchIngredient.Serializer.GENERIC); - /** Generic content match serializer */ - public static final ContentTypeIngredient.Serializer TYPE = register("content_type", new ContentTypeIngredient.Serializer()); + public static final ContentMatchIngredient.Serializer MATCH = register("match_content", ContentMatchIngredient.Serializer.GENERIC); /** Fluid content match serializer */ public static final FluidCauldronIngredient.Serializer FLUID = register("fluid", new FluidCauldronIngredient.Serializer()); /** Color content match serializer */ - public static final ContentMatchIngredient.Serializer COLOR = registerMatch(CauldronContentTypes.COLOR); + public static final ContentMatchIngredient.Serializer COLOR = registerMatch(CauldronContentTypes.COLOR); /** Dye content match serializer */ - public static final ContentMatchIngredient.Serializer DYE = registerMatch(CauldronContentTypes.DYE); + public static final ContentMatchIngredient.Serializer DYE = registerMatch(CauldronContentTypes.DYE); /** Fluid content match serializer */ - public static final ContentMatchIngredient.Serializer POTION = registerMatch(CauldronContentTypes.POTION); + public static final ContentMatchIngredient.Serializer POTION = registerMatch(CauldronContentTypes.POTION); /** * Registers a new content type @@ -76,8 +70,8 @@ private static > T register(String na * @param Map value type * @return Registered serializer */ - public static ContentMatchIngredient.Serializer registerMatch(MapContentType mapType) { - ContentMatchIngredient.Serializer serializer = new ContentMatchIngredient.Serializer<>(mapType); + public static ContentMatchIngredient.Serializer registerMatch(CauldronContentType mapType) { + ContentMatchIngredient.Serializer serializer = new ContentMatchIngredient.Serializer<>(mapType); register(CauldronContentTypes.getName(mapType), serializer); return serializer; } diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/CauldronContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/CauldronContentType.java new file mode 100644 index 00000000..38860090 --- /dev/null +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/CauldronContentType.java @@ -0,0 +1,213 @@ +package knightminer.inspirations.library.recipe.cauldron.contents; + +import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; +import io.netty.handler.codec.DecoderException; +import io.netty.handler.codec.EncoderException; +import knightminer.inspirations.Inspirations; +import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; +import knightminer.inspirations.recipes.recipe.cauldron.contents.CauldronContents; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.JSONUtils; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.util.Constants.NBT; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; + +/** + * Represents a type of contents that can be stored in the cauldron + * @param Type of values contained in this type + */ +public abstract class CauldronContentType { + /** Resource location meaning no texture exists. Basically a copy of {@link net.minecraft.client.renderer.texture.MissingTextureSprite#getLocation()} that is server safe */ + public static final ResourceLocation NO_TEXTURE = Inspirations.getResource("missingno"); + + private final Map cache = new HashMap<>(); + private final Map valueOverrides = new HashMap<>(); + private final Function constructor = val -> new CauldronContents<>(this, val); + + /** + * Gets a value of the given type + * @param value Type of value + * @return Value to fetch + */ + public ICauldronContents of(T value) { + return cache.computeIfAbsent(value, constructor); + } + + + /* Overrides */ + + /** + * Causes the given instance to return a value for this type. + * @param instance Contents instance for override + * @param value Value supplier + */ + public void setValue(ICauldronContents instance, T value) { + if (instance.getType() == this) { + throw new IllegalArgumentException("Attempted to register override within the same type"); + } + valueOverrides.put(instance, value); + } + + /** + * Causes a specific value from this function to instead return the given instance. Need to call {@link #setValue(ICauldronContents, Object)} before using + * @param value Value being replaced + * @param instance Instance to use for override + */ + public void setResult(T value, ICauldronContents instance) { + Optional optional = instance.get(this); + if (optional.isPresent()) { + if (!optional.get().equals(value)) { + throw new IllegalArgumentException("Override contents does not match the value type"); + } + } else { + // add a value override if missing + valueOverrides.put(instance, value); + } + // just add it to the cache, so it will be fetched later + cache.put(value, instance); + } + + /** + * Gets the overridden value for the given instance + * @param instance Instance + * @return Optional of override value, or empty if no override exists + */ + public Optional getOverrideValue(ICauldronContents instance) { + return Optional.ofNullable(valueOverrides.get(instance)); + } + + + /* Display methods */ + + /** + * Gets the texture for the given type + * @param value Value to fetch texture + * @return Texture location + */ + public abstract ResourceLocation getTexture(T value); + + /** + * Gets the tint color for the given type, used for tint indexes + * @param value Value + * @return Tint index + */ + public int getColor(T value) { + return -1; + } + + + /* Serializing and deserializing */ + + /** + * Gets the name of the given value for writing to JSON and NBT + * @param value Value + * @return Name of the value + */ + public abstract String getName(T value); + + /** + * Gets the entry for a given value + * @param name Name + * @return Entry, or null if missing + */ + @Nullable + public abstract T getEntry(String name); + + /** + * Gets the key used for JSON and NBT + * @return JSON and NBT key + */ + public String getKey() { + return "name"; + } + + /** + * Reads the given type from NBT + * @param tag NBT tag + * @return Read value + */ + @Nullable + public ICauldronContents read(CompoundNBT tag) { + if (tag.contains(getKey(), NBT.TAG_STRING)) { + T value = getEntry(tag.getString(getKey())); + if (value != null) { + return of(value); + } + } + return null; + } + + /** + * Reads the given type from JSON + * @param json JSON object + * @return Read value= + * @throws com.google.gson.JsonSyntaxException if the JSON is invalid + */ + public ICauldronContents read(JsonObject json) { + String name = JSONUtils.getString(json, getKey()); + T value = getEntry(name); + if (value == null) { + throw new JsonSyntaxException("Invalid name '" + name + "' for type '" + CauldronContentTypes.getName(this) + "'"); + } + return of(value); + } + + /** + * Reads the given type from the packet buffer + * @param buffer Packet buffer + * @return Read value + * @throws DecoderException if the type is invalid + */ + public ICauldronContents read(PacketBuffer buffer) { + String name = buffer.readString(Short.MAX_VALUE); + T value = getEntry(name); + if (value != null) { + return of(value); + } + throw new DecoderException("Invalid name '" + name + "' for type " + this); + } + + /** + * Writes the given type to NBT + * @param contents Contents to write + * @param tag NBT tag + */ + public void write(ICauldronContents contents, CompoundNBT tag) { + contents.get(this).ifPresent(val -> tag.putString(getKey(), getName(val))); + } + + /** + * Writes the given type to JSON + * @param contents Contents to write + * @param json JSON object + */ + public void write(ICauldronContents contents, JsonObject json) { + contents.get(this).ifPresent(val -> json.addProperty(getKey(), getName(val))); + } + + /** + * Writes the given type to the packet buffer + * @param contents Contents to write + * @param buffer Packet buffer + */ + public void write(ICauldronContents contents, PacketBuffer buffer) { + Optional value = contents.get(this); + if (value.isPresent()) { + buffer.writeString(getName(value.get())); + } else { + throw new EncoderException("Invalid type for contents argument"); + } + } + + @Override + public String toString() { + return String.format("CauldronContentType[%s]", CauldronContentTypes.getName(this)); + } +} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyCauldronContents.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyCauldronContents.java index 3a57eed2..a131378c 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyCauldronContents.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyCauldronContents.java @@ -1,21 +1,39 @@ package knightminer.inspirations.library.recipe.cauldron.contents; import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; import net.minecraft.util.ResourceLocation; +import java.util.Optional; + +/** + * Cauldron contents containing nothing. Used as a default in many cases. + */ public class EmptyCauldronContents implements ICauldronContents { public static final EmptyCauldronContents INSTANCE = new EmptyCauldronContents(); - private EmptyCauldronContents() {} @Override - public ResourceLocation getTextureName() { - return NO_TEXTURE; + public Optional get(CauldronContentType type) { + return Optional.empty(); } @Override public CauldronContentType getType() { return CauldronContentTypes.EMPTY; } + + @Override + public ResourceLocation getTextureName() { + return CauldronContentType.NO_TEXTURE; + } + + @Override + public int getTintColor() { + return -1; + } + + @Override + public boolean matches(CauldronContentType type, T value) { + return type == CauldronContentTypes.EMPTY; + } } diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyContentType.java new file mode 100644 index 00000000..f3a252ee --- /dev/null +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/EmptyContentType.java @@ -0,0 +1,36 @@ +package knightminer.inspirations.library.recipe.cauldron.contents; + +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; + +/** + * Content type for the empty contents, exists to prevent errors from the empty contents having no type + */ +public class EmptyContentType extends CauldronContentType { + @Override + public ResourceLocation getTexture(Void type) { + return CauldronContentType.NO_TEXTURE; + } + + @Override + public String getName(Void value) { + return "empty"; + } + + @Nullable + @Override + public Void getEntry(String name) { + return null; + } + + @Override + public void write(ICauldronContents contents, PacketBuffer buffer) {} + + @Override + public EmptyCauldronContents read(PacketBuffer buffer) { + return EmptyCauldronContents.INSTANCE; + } + +} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronColor.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronColor.java deleted file mode 100644 index 1c3c20b0..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronColor.java +++ /dev/null @@ -1,17 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contents; - -/** - * Represents a cauldron containing an arbitrary color - */ -public interface ICauldronColor extends ICauldronContents { - /** - * Gets the color contained in these contents - * @return Contents color - */ - int getColor(); - - @Override - default int getTintColor() { - return getColor(); - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronContents.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronContents.java index d170286c..e71a09e2 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronContents.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronContents.java @@ -1,6 +1,5 @@ package knightminer.inspirations.library.recipe.cauldron.contents; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; import net.minecraft.util.ResourceLocation; import java.util.Optional; @@ -9,57 +8,63 @@ * Base interface for all cauldron contents */ public interface ICauldronContents { + /** - * Copy of {@link net.minecraft.client.renderer.texture.MissingTextureSprite#getLocation} for reference on a server. - * Used as an error state so {@link #getTextureName()} will not crash a server + * Gets this value as the given type + * @param type Type to get + * @param Type of return + * @return Value, or empty optional if this does not have the given type */ - ResourceLocation NO_TEXTURE = new ResourceLocation("missingno"); + Optional get(CauldronContentType type); + + /** + * Gets the main type of these contents, used for serializing + * @return Main content type + */ + CauldronContentType getType(); + /* Display */ /** - * Gets the name of the texture for these contents. - * Note that this method exists on the server. Use {@link net.minecraftforge.fml.DistExecutor} and return {@link #NO_TEXTURE} on the server if needed to prevent clientside access + * Gets the name of the texture for these contents. Should generally delegate to the type * @return Texture location for this contents */ ResourceLocation getTextureName(); /** - * Gets the color for this content type for tinting + * Gets the color for this content type for tinting. Should generally delegate to the type * @return Tint color */ - default int getTintColor() { - return -1; - } + int getTintColor(); - /* Serializing */ + /* Mapping */ /** - * Gets the type of this contents - * @return Content type + * Checks if these cauldron contents match the given arguments. Use this for {@link #equals(Object)} implementations + * @param type Content type + * @param value Value of the content + * @param Content class + * @return True if they match */ - CauldronContentType getType(); - - - /* Helper methods */ + boolean matches(CauldronContentType type, T value); /** - * Checks if this is the given type - * @param type Type to check - * @return True if it matches + * For consistency, hash code should be {@code 31 * type.hashCode() + value.hashCode()} + * @return Hash code for the given type and value */ - default boolean is(CauldronContentType type) { - return type.matches(this); - } + @Override + int hashCode(); /** - * Gets this type as the given value - * @param type Type to get - * @param Content type - * @return Optional of the given type, empty if wrong type + * Checks if the contents contain the given value. Unlike {@link #matches(CauldronContentType, Object)}, supports overrides. + * @param type Content type + * @param value Value of the content + * @param Content class + * @return True if get would return this value */ - default Optional as(CauldronContentType type) { - return type.get(this); + default boolean contains(CauldronContentType type, T value) { + return get(type).map(value::equals).orElse(false); } } diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronDye.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronDye.java deleted file mode 100644 index a6f19f7e..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronDye.java +++ /dev/null @@ -1,19 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contents; - -import net.minecraft.item.DyeColor; - -/** - * Represents a cauldron containing a specific dye - */ -public interface ICauldronDye extends ICauldronColor { - /** - * Gets the relevant dye for this color - * @return Dye color - */ - DyeColor getDye(); - - @Override - default int getColor() { - return getDye().getColorValue(); - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronFluid.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronFluid.java deleted file mode 100644 index f7930b11..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronFluid.java +++ /dev/null @@ -1,25 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contents; - -import net.minecraft.fluid.Fluid; -import net.minecraft.util.ResourceLocation; - -/** - * Represents a cauldron containing a specific fluid - */ -public interface ICauldronFluid extends ICauldronContents { - /** - * Gets the fluid relevant to this cauldron contents - * @return Relevant fluid - */ - Fluid getFluid(); - - @Override - default int getTintColor() { - return getFluid().getAttributes().getColor(); - } - - @Override - default ResourceLocation getTextureName() { - return getFluid().getAttributes().getStillTexture(); - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronPotion.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronPotion.java deleted file mode 100644 index f475330d..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/ICauldronPotion.java +++ /dev/null @@ -1,20 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contents; - -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionUtils; - -/** - * Represents a cauldron containing a fluid - */ -public interface ICauldronPotion extends ICauldronContents { - /** - * Gets the contained potion - * @return Cauldron potion - */ - Potion getPotion(); - - @Override - default int getTintColor() { - return PotionUtils.getPotionColor(getPotion()); - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/NamedContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/NamedContentType.java new file mode 100644 index 00000000..ac475778 --- /dev/null +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/NamedContentType.java @@ -0,0 +1,43 @@ +package knightminer.inspirations.library.recipe.cauldron.contents; + +import net.minecraft.util.IStringSerializable; + +import javax.annotation.Nullable; +import java.util.function.Function; + +/** + * Cauldron content type based on an {@link IStringSerializable} object, typically an enum + * @param Type class + */ +public abstract class NamedContentType extends CauldronContentType { + private final Function lookup; + + /** + * Creates a new type instance + * @param lookup Function to lookup a value from a string + */ + public NamedContentType(Function lookup) { + this.lookup = lookup; + } + + /** + * Gets the name of the given value for writing to JSON and NBT + * @param value Value + * @return Name of the value + */ + @Override + public String getName(T value) { + return value.getString(); + } + + /** + * Gets the entry for a given value + * @param name Name + * @return Entry, or null if missing + */ + @Override + @Nullable + public T getEntry(String name) { + return lookup.apply(name); + } +} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/RegistryContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/RegistryContentType.java new file mode 100644 index 00000000..5e533a1c --- /dev/null +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contents/RegistryContentType.java @@ -0,0 +1,44 @@ +package knightminer.inspirations.library.recipe.cauldron.contents; + +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.IForgeRegistryEntry; + +import javax.annotation.Nullable; +import java.util.Objects; + +/** + * Content type that mirrors a Forge registry + * @param Value type + */ +public abstract class RegistryContentType> extends CauldronContentType { + private final IForgeRegistry registry; + + /** + * Creates a new instance + * @param registry Forge registry instance for lookups + */ + public RegistryContentType(IForgeRegistry registry) { + this.registry = registry; + } + + @Override + public String getName(T value) { + return Objects.requireNonNull(value.getRegistryName()).toString(); + } + + @Nullable + @Override + public T getEntry(String name) { + ResourceLocation location = ResourceLocation.tryCreate(name); + if (location != null) { + // swap default value for null + T value = registry.getValue(location); + ResourceLocation defaultKey = registry.getDefaultKey(); + if (value != null && defaultKey != null && !defaultKey.equals(value.getRegistryName())) { + return value; + } + } + return null; + } +} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/CauldronContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/CauldronContentType.java deleted file mode 100644 index 6359532c..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/CauldronContentType.java +++ /dev/null @@ -1,97 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contenttype; - -import com.google.gson.JsonObject; -import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.network.PacketBuffer; - -import javax.annotation.Nullable; -import java.util.Optional; - -/** - * Represents a type of contents that can be stored in the cauldron - * @param {@link ICauldronContents} implementation for this type - */ -public abstract class CauldronContentType { - private final Class clazz; - - /** - * Creates a new instance - * @param clazz Content type class for validation - */ - protected CauldronContentType(Class clazz) { - this.clazz = clazz; - } - - /** - * Checks if the given contents matches this type - * @param contents Contents to check - * @return True if the type matches - */ - public boolean matches(ICauldronContents contents) { - return clazz.isInstance(contents); - } - - /** - * Gets the contents as this type - * @param contents Contents to fetch - * @return Type to get - */ - public Optional get(ICauldronContents contents) { - if (clazz.isInstance(contents)) { - return Optional.of(clazz.cast(contents)); - } - return Optional.empty(); - } - - /** - * Reads the given type from NBT - * @param tag NBT tag - * @return Read value - */ - @Nullable - public abstract C read(CompoundNBT tag); - - /** - * Reads the given type from JSON - * @param json JSON object - * @return Read value= - * @throws com.google.gson.JsonSyntaxException if the JSON is invalid - */ - public abstract C read(JsonObject json); - - /** - * Reads the given type from the packet buffer - * @param buffer Packet buffer - * @return Read value - * @throws io.netty.handler.codec.DecoderException if the type is invalid - */ - public abstract C read(PacketBuffer buffer); - - /** - * Writes the given type to NBT - * @param contents Contents to write - * @param tag NBT tag - */ - public abstract void write(C contents, CompoundNBT tag); - - /** - * Writes the given type to JSON - * @param contents Contents to write - * @param json JSON object - */ - public abstract void write(C contents, JsonObject json); - - /** - * Writes the given type to the packet buffer - * @param contents Contents to write - * @param buffer Packet buffer - */ - public abstract void write(C contents, PacketBuffer buffer); - - @Override - public String toString() { - return String.format("CauldronContentType[%s]", CauldronContentTypes.getName(this)); - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/MapContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/MapContentType.java deleted file mode 100644 index d9040a22..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/MapContentType.java +++ /dev/null @@ -1,149 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contenttype; - -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; -import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.JSONUtils; -import net.minecraftforge.common.util.Constants.NBT; - -import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -/** - * Represents a type of contents that can be stored in the cauldron - * @param Stored content type - * @param {@link ICauldronContents} implementation for this type - */ -public abstract class MapContentType extends CauldronContentType { - private final Map cache = new HashMap<>(); - private final Function constructor; - private final Function valueGetter; - private final String key; - - /** - * Creates a new instance with a specific key name - * @param clazz Content type class for validation - * @param constructor Constructor to create contents from the type - * @param valueGetter Function to get the value from a content type - * @param key Key to use for serializing and deserializing - */ - protected MapContentType(Class clazz, Function constructor, Function valueGetter, String key) { - super(clazz); - this.constructor = constructor; - this.valueGetter = valueGetter; - this.key = key; - } - - @SuppressWarnings("WeakerAccess") - protected MapContentType(Class clazz, Function constructor, Function valueGetter) { - this(clazz, constructor, valueGetter, "name"); - } - - /* Creation methods */ - - /** - * Adds an override to this type, preventing the default constructor - * @param value Override to fetch - * @param instance Instance to use for override - */ - @SuppressWarnings("unused") - public void addOverride(T value, C instance) { - cache.put(getName(value), instance); - } - - /** - * Gets a value of the given type - * @param value Type of value - * @return Value to fetch - */ - public C of(T value) { - return cache.computeIfAbsent(getName(value), name -> constructor.apply(value)); - } - - - /* Utils */ - - /** - * Gets the value of the given contents - * @param contents Contents - * @return Value - */ - public T getValue(C contents) { - return valueGetter.apply(contents); - } - - /** - * Gets the key used for JSON and NBT - * @return JSON and NBT key - */ - public String getKey() { - return key; - } - - /* Serializing and deserializing */ - - /** - * Gets the name of the given value - * @param value Value - * @return Name of the value - */ - public abstract String getName(T value); - - /** - * Gets the name of the given value - * @param value Value - * @return Name of the value - */ - protected final String getName(C value) { - return getName(getValue(value)); - } - - /** - * Gets the entry for a given value - * @param name Name - * @return Entry, or null if missing - */ - @Nullable - public abstract T getEntry(String name); - - /** - * Reads the given type from NBT - * @param tag Type of value - * @return Value to fetch - */ - @Nullable - @Override - public C read(CompoundNBT tag) { - if (tag.contains(key, NBT.TAG_STRING)) { - T value = getEntry(tag.getString(key)); - if (value != null) { - return of(value); - } - } - return null; - } - - @Override - public void write(C contents, CompoundNBT tag) { - tag.putString(key, getName(contents)); - } - - @Override - public C read(JsonObject json) { - String name = JSONUtils.getString(json, key); - T value = getEntry(name); - if (value == null) { - throw new JsonSyntaxException("Invalid name '" + name + "' for type '" + CauldronContentTypes.getName(this) + "'"); - } - return of(value); - } - - @Override - public void write(C contents, JsonObject json) { - json.addProperty(key, getName(contents)); - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/NamedContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/NamedContentType.java deleted file mode 100644 index c5e08951..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/NamedContentType.java +++ /dev/null @@ -1,56 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contenttype; - -import io.netty.handler.codec.DecoderException; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.IStringSerializable; - -import javax.annotation.Nullable; -import java.util.function.Function; - -/** - * Cauldron content type based on an {@link IStringSerializable} object, typically an enum - * @param Type class - * @param Contents class - */ -public class NamedContentType extends MapContentType { - private final Function lookup; - - /** - * Creates a new type instance - * @param clazz Contents class - * @param constructor Contents constructor - * @param lookup Function to lookup a value from a string - * @param valueGetter Function to get the value from a content type - */ - public NamedContentType(Class clazz, Function constructor, Function lookup, Function valueGetter) { - super(clazz, constructor, valueGetter); - this.lookup = lookup; - } - - @Override - public String getName(T value) { - return value.getString(); - } - - @Nullable - @Override - public T getEntry(String name) { - return lookup.apply(name); - } - - @Override - public C read(PacketBuffer buffer) { - String name = buffer.readString(Short.MAX_VALUE); - T value = lookup.apply(name); - if (value != null) { - return of(value); - } - throw new DecoderException("Invalid name '" + name + "' for type " + this); - } - - @Override - public void write(C contents, PacketBuffer buffer) { - buffer.writeString(getName(contents)); - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/RegistryContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/RegistryContentType.java deleted file mode 100644 index 39d417bd..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/RegistryContentType.java +++ /dev/null @@ -1,80 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contenttype; - -import io.netty.handler.codec.DecoderException; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.registries.IForgeRegistry; -import net.minecraftforge.registries.IForgeRegistryEntry; - -import javax.annotation.Nullable; -import java.util.Objects; -import java.util.function.Function; - -/** - * Content type that mirrors a Forge registry - * @param Value type - * @param Cauldron content type - */ -public class RegistryContentType> extends MapContentType { - private final IForgeRegistry registry; - - /** - * Creates a new instance - * @param clazz Class for validation - * @param constructor Class constructor - * @param registry Forge registry instance for lookups - * @param valueGetter Function to get the value from a content type - */ - public RegistryContentType(Class clazz, Function constructor, IForgeRegistry registry, Function valueGetter) { - super(clazz, constructor, valueGetter); - this.registry = registry; - } - - @Override - public String getName(T value) { - return Objects.requireNonNull(value.getRegistryName()).toString(); - } - - /** - * Gets a value for the given name - * @param name Name to fetch - * @return Value, or null if the value is the default object or not found - */ - @Nullable - private T getValue(ResourceLocation name) { - T value = registry.getValue(name); - - // swap default value for null - ResourceLocation defaultKey = registry.getDefaultKey(); - if (value != null && defaultKey != null && !defaultKey.equals(value.getRegistryName())) { - return value; - } - return null; - } - - @Nullable - @Override - public T getEntry(String name) { - ResourceLocation location = ResourceLocation.tryCreate(name); - if (location != null) { - return getValue(location); - } - return null; - } - - @Override - public C read(PacketBuffer buffer) { - ResourceLocation location = buffer.readResourceLocation(); - T value = getValue(location); - if (value != null) { - return of(value); - } - throw new DecoderException("Invalid ID '" + location + "' for cauldron content type " + this); - } - - @Override - public void write(C contents, PacketBuffer buffer) { - buffer.writeString(getName(contents)); - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/SingletonContentType.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/SingletonContentType.java deleted file mode 100644 index 39c47c35..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/SingletonContentType.java +++ /dev/null @@ -1,56 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.contenttype; - -import com.google.gson.JsonObject; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.network.PacketBuffer; - -/** - * Content type that only contains a single value - * @param Content class type - */ -public class SingletonContentType extends CauldronContentType { - private final C instance; - - /** - * Creates a new instance - * @param clazz Content type class for validation - * @param instance Instance to always return - */ - public SingletonContentType(Class clazz, C instance) { - super(clazz); - this.instance = instance; - } - - /** - * Gets the single instance of this type - * @return Instance - */ - public C get() { - return instance; - } - - @Override - public C read(CompoundNBT tag) { - return get(); - } - - @Override - public C read(JsonObject json) { - return get(); - } - - @Override - public C read(PacketBuffer buffer) { - return get(); - } - - @Override - public void write(C contents, CompoundNBT tag) {} - - @Override - public void write(C contents, JsonObject json) {} - - @Override - public void write(C contents, PacketBuffer buffer) {} -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/package-info.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/package-info.java deleted file mode 100644 index 7e3cf178..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/contenttype/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -@ParametersAreNonnullByDefault -@MethodsReturnNonnullByDefault -package knightminer.inspirations.library.recipe.cauldron.contenttype; - -import mcp.MethodsReturnNonnullByDefault; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/ContentMatchIngredient.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/ContentMatchIngredient.java index 6bbf7f8b..60ceb00f 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/ContentMatchIngredient.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/ContentMatchIngredient.java @@ -7,9 +7,8 @@ import com.google.gson.JsonSyntaxException; import io.netty.handler.codec.DecoderException; import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; +import knightminer.inspirations.library.recipe.cauldron.contents.CauldronContentType; import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; -import knightminer.inspirations.library.recipe.cauldron.contenttype.MapContentType; import net.minecraft.network.PacketBuffer; import net.minecraft.util.JSONUtils; import net.minecraft.util.ResourceLocation; @@ -24,16 +23,15 @@ import java.util.function.Function; /** - * Type that can match a value or list of values. Only supports {@link MapContentType} at this time, but the base logic can be extracted if needed. - * @param Content type to match + * Type that can match a value or list of values. * @param Value type */ -public abstract class ContentMatchIngredient implements ICauldronIngredient { +public abstract class ContentMatchIngredient implements ICauldronIngredient { private final ICauldronIngredientSerializer serializer; - protected final MapContentType type; + protected final CauldronContentType type; @SuppressWarnings("WeakerAccess") - protected ContentMatchIngredient(ICauldronIngredientSerializer serializer, MapContentType type) { + protected ContentMatchIngredient(ICauldronIngredientSerializer serializer, CauldronContentType type) { this.serializer = serializer; this.type = type; } @@ -42,11 +40,10 @@ protected ContentMatchIngredient(ICauldronIngredientSerializer serializer, Ma * Creates an instance from the given type and value * @param type Type * @param value Value - * @param Content type * @param Value type * @return Ingredient */ - public static ContentMatchIngredient of(MapContentType type, T value) { + public static ContentMatchIngredient of(CauldronContentType type, T value) { return new Single<>(Serializer.GENERIC, type, value); } @@ -54,11 +51,10 @@ public static ContentMatchIngredient of(Map * Creates an instance from the given type and values * @param type Type * @param values Values - * @param Content type * @param Value type * @return Ingredient */ - public static ContentMatchIngredient of(MapContentType type, Collection values) { + public static ContentMatchIngredient of(CauldronContentType type, Collection values) { return new Multi<>(Serializer.GENERIC, type, ImmutableSet.copyOf(values)); } @@ -66,11 +62,10 @@ public static ContentMatchIngredient of(Map * Creates an instance from the given serializer and value * @param serializer Serializer to use * @param value Value - * @param Content type * @param Value type * @return Ingredient */ - public static ContentMatchIngredient of(Serializer serializer, T value) { + public static ContentMatchIngredient of(Serializer serializer, T value) { return new Single<>(serializer, Objects.requireNonNull(serializer.type), value); } @@ -78,11 +73,10 @@ public static ContentMatchIngredient of(Ser * Creates an instance from the given serializer and values * @param serializer Serializer to use * @param values Values - * @param Content type * @param Value type * @return Ingredient */ - public static ContentMatchIngredient of(Serializer serializer, Collection values) { + public static ContentMatchIngredient of(Serializer serializer, Collection values) { return new Multi<>(serializer, Objects.requireNonNull(serializer.type), ImmutableSet.copyOf(values)); } @@ -107,8 +101,7 @@ public static ContentMatchIngredient of(Ser @Override public boolean test(ICauldronContents contents) { - return contents.as(type) - .map(type::getValue) + return contents.get(type) .map(this::testValue) .orElse(false); } @@ -119,9 +112,9 @@ public ICauldronIngredientSerializer getSerializer() { } /** Matches a single value */ - private static class Single extends ContentMatchIngredient { + private static class Single extends ContentMatchIngredient { private final T value; - private Single(ICauldronIngredientSerializer serializer, MapContentType type, T value) { + private Single(ICauldronIngredientSerializer serializer, CauldronContentType type, T value) { super(serializer, type); this.value = value; } @@ -143,9 +136,9 @@ protected void write(PacketBuffer buffer) { } /** Matches from a set */ - private static class Multi extends ContentMatchIngredient { + private static class Multi extends ContentMatchIngredient { private final Set values; - private Multi(ICauldronIngredientSerializer serializer, MapContentType type, Set values) { + private Multi(ICauldronIngredientSerializer serializer, CauldronContentType type, Set values) { super(serializer, type); this.values = values; } @@ -173,20 +166,20 @@ protected void write(PacketBuffer buffer) { } } - public static class Serializer implements ICauldronIngredientSerializer> { + public static class Serializer implements ICauldronIngredientSerializer> { /** * Generic recipe serializer, requires both JSON and packets to include the contents type */ - public static final Serializer GENERIC = new Serializer<>(); + public static final Serializer GENERIC = new Serializer<>(); @Nullable - private final MapContentType type; + private final CauldronContentType type; /** * Creates a new serializer using the given type * @param type Serializer type */ - public Serializer(MapContentType type) { + public Serializer(CauldronContentType type) { this.type = type; } @@ -201,11 +194,10 @@ private Serializer() { * Helper to get a single value from a string * @param type Content type * @param name Value name - * @param Type of contents * @param Type of value * @return Content match ingredient */ - private static ContentMatchIngredient getSingle(MapContentType type, String name) { + private static ContentMatchIngredient getSingle(CauldronContentType type, String name) { T value = type.getEntry(name); if (value == null) { throw new JsonSyntaxException("Invalid value '" + name + "' for type " + type); @@ -220,19 +212,15 @@ private static ContentMatchIngredient getS * @return Type instance * @throws RuntimeException if the type is missing or the wrong class type */ - private static MapContentType getType(ResourceLocation name, Function exception) { + private static CauldronContentType getType(ResourceLocation name, Function exception) { CauldronContentType type = CauldronContentTypes.get(name); // must exist if (type == null) { throw exception.apply("Unknown cauldron content type '" + name + "'"); } - // must match type - if (!(type instanceof MapContentType)) { - throw exception.apply("Cauldron content type '" + name + "' does not support content match"); - } // only used by generic type, so type has ?,? generics //noinspection unchecked - return (MapContentType) type; + return (CauldronContentType) type; } @@ -241,11 +229,10 @@ private static MapContentType getType(Reso * @param type Content type * @param names Value names * @param exception Exception function - * @param Type of contents * @param Type of value * @return Content match ingredient */ - private static ContentMatchIngredient getList(MapContentType type, List names, Function exception) { + private static ContentMatchIngredient getList(CauldronContentType type, List names, Function exception) { List values = new ArrayList<>(); for (String name : names) { T value = type.getEntry(name); @@ -262,9 +249,9 @@ private static ContentMatchIngredient getL } @Override - public ContentMatchIngredient read(JsonObject json) { + public ContentMatchIngredient read(JsonObject json) { // use the instance type if present - MapContentType type = this.type; + CauldronContentType type = this.type; // if generic, find a type using the match key if (type == null) { type = getType(new ResourceLocation(JSONUtils.getString(json, "match")), JsonSyntaxException::new); @@ -289,7 +276,7 @@ public ContentMatchIngredient read(JsonObject json) { } @Override - public void write(ContentMatchIngredient ingredient, JsonObject json) { + public void write(ContentMatchIngredient ingredient, JsonObject json) { if (this.type == null) { json.addProperty("match", CauldronContentTypes.getName(ingredient.type).toString()); } @@ -297,9 +284,9 @@ public void write(ContentMatchIngredient ingredient, JsonObject json) { } @Override - public ContentMatchIngredient read(PacketBuffer buffer) { + public ContentMatchIngredient read(PacketBuffer buffer) { // use the instance type if present - MapContentType type = this.type; + CauldronContentType type = this.type; // if generic, find a type using the match key if (type == null) { type = getType(buffer.readResourceLocation(), DecoderException::new); @@ -317,7 +304,7 @@ public ContentMatchIngredient read(PacketBuffer buffer) { } @Override - public void write(ContentMatchIngredient ingredient, PacketBuffer buffer) { + public void write(ContentMatchIngredient ingredient, PacketBuffer buffer) { // only write the type to the buffer if this is the generic type if (this.type == null) { buffer.writeResourceLocation(CauldronContentTypes.getName(ingredient.type)); diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/ContentTypeIngredient.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/ContentTypeIngredient.java deleted file mode 100644 index 5d98a207..00000000 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/ContentTypeIngredient.java +++ /dev/null @@ -1,78 +0,0 @@ -package knightminer.inspirations.library.recipe.cauldron.ingredient; - -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; -import io.netty.handler.codec.DecoderException; -import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.CauldronIngredients; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.JSONUtils; -import net.minecraft.util.ResourceLocation; - -import java.util.IdentityHashMap; -import java.util.Map; - -/** - * Ingredient that checks if the cauldron contains the right content type - */ -public class ContentTypeIngredient implements ICauldronIngredient { - private static final Map, ContentTypeIngredient> MAP = new IdentityHashMap<>(); - private final CauldronContentType type; - - private ContentTypeIngredient(CauldronContentType type) { - this.type = type; - } - - /** - * Gets an ingredient for the content type, or makes a new one if missing - * @param type Type to fetch - * @return Ingredient instance - */ - public static ContentTypeIngredient of(CauldronContentType type) { - return MAP.computeIfAbsent(type, ContentTypeIngredient::new); - } - - @Override - public boolean test(ICauldronContents contents) { - return contents.is(type); - } - - @Override - public ICauldronIngredientSerializer getSerializer() { - return CauldronIngredients.TYPE; - } - - public static class Serializer implements ICauldronIngredientSerializer { - @Override - public ContentTypeIngredient read(JsonObject json) { - ResourceLocation name = new ResourceLocation(JSONUtils.getString(json, "name")); - CauldronContentType type = CauldronContentTypes.get(name); - if (type == null) { - throw new JsonSyntaxException("Invalid cauldron content type '" + name + "'"); - } - return of(type); - } - - @Override - public void write(ContentTypeIngredient ingredient, JsonObject json) { - json.addProperty("name", CauldronContentTypes.getName(ingredient.type).toString()); - } - - @Override - public ContentTypeIngredient read(PacketBuffer buffer) { - ResourceLocation name = buffer.readResourceLocation(); - CauldronContentType type = CauldronContentTypes.get(name); - if (type == null) { - throw new DecoderException("Invalid cauldron content type '" + name + "'"); - } - return of(type); - } - - @Override - public void write(ContentTypeIngredient ingredient, PacketBuffer buffer) { - buffer.writeResourceLocation(CauldronContentTypes.getName(ingredient.type)); - } - } -} diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/FluidCauldronIngredient.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/FluidCauldronIngredient.java index 434286ac..2cbea033 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/FluidCauldronIngredient.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/ingredient/FluidCauldronIngredient.java @@ -5,7 +5,6 @@ import com.google.gson.JsonSyntaxException; import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; import knightminer.inspirations.library.recipe.cauldron.CauldronIngredients; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronFluid; import net.minecraft.fluid.Fluid; import net.minecraft.network.PacketBuffer; import net.minecraft.tags.FluidTags; @@ -21,7 +20,7 @@ /** * Cauldron ingredient type for fluid contents, mostly an extension of {@link ContentMatchIngredient}, but also includes tags */ -public class FluidCauldronIngredient extends ContentMatchIngredient { +public class FluidCauldronIngredient extends ContentMatchIngredient { private final ITag tag; private FluidCauldronIngredient(ITag tag) { super(CauldronIngredients.FLUID, CauldronContentTypes.FLUID); @@ -33,7 +32,7 @@ private FluidCauldronIngredient(ITag tag) { * @param fluid Fluid to match * @return Ingredient */ - public static ContentMatchIngredient of(Fluid fluid) { + public static ContentMatchIngredient of(Fluid fluid) { return of(CauldronIngredients.FLUID, fluid); } @@ -42,7 +41,7 @@ public static ContentMatchIngredient of(Fluid fluid) { * @param fluids Fluids to match * @return Ingredient */ - public static ContentMatchIngredient of(Collection fluids) { + public static ContentMatchIngredient of(Collection fluids) { return of(CauldronIngredients.FLUID, ImmutableSet.copyOf(fluids)); } @@ -74,7 +73,7 @@ protected void write(PacketBuffer buffer) { } } - public static class Serializer extends ContentMatchIngredient.Serializer { + public static class Serializer extends ContentMatchIngredient.Serializer { /** * Creates a new serializer instance */ @@ -83,7 +82,7 @@ public Serializer() { } @Override - public ContentMatchIngredient read(JsonObject json) { + public ContentMatchIngredient read(JsonObject json) { // single fluid or array if (json.has("name")) { return super.read(json); diff --git a/src/main/java/knightminer/inspirations/library/recipe/cauldron/recipe/CauldronRecipeBuilder.java b/src/main/java/knightminer/inspirations/library/recipe/cauldron/recipe/CauldronRecipeBuilder.java index 3c4eb052..310f2ab0 100644 --- a/src/main/java/knightminer/inspirations/library/recipe/cauldron/recipe/CauldronRecipeBuilder.java +++ b/src/main/java/knightminer/inspirations/library/recipe/cauldron/recipe/CauldronRecipeBuilder.java @@ -5,8 +5,6 @@ import knightminer.inspirations.library.recipe.cauldron.CauldronIngredients; import knightminer.inspirations.library.recipe.cauldron.contents.EmptyCauldronContents; import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronFluid; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronPotion; import knightminer.inspirations.library.recipe.cauldron.ingredient.ICauldronIngredient; import knightminer.inspirations.library.recipe.cauldron.util.LevelPredicate; import knightminer.inspirations.library.recipe.cauldron.util.LevelUpdate; @@ -244,13 +242,13 @@ public void build(Consumer consumer) { } if (newContents != EmptyCauldronContents.INSTANCE) { // try fluid next - Optional fluid = newContents.as(CauldronContentTypes.FLUID).map(ICauldronFluid::getFluid); + Optional fluid = newContents.get(CauldronContentTypes.FLUID); if (fluid.isPresent()) { build(consumer, Objects.requireNonNull(fluid.get().getRegistryName())); return; } // try potion - Optional potion = newContents.as(CauldronContentTypes.POTION).map(ICauldronPotion::getPotion); + Optional potion = newContents.get(CauldronContentTypes.POTION); if (potion.isPresent()) { build(consumer, Objects.requireNonNull(potion.get().getRegistryName())); return; diff --git a/src/main/java/knightminer/inspirations/recipes/InspirationsRecipes.java b/src/main/java/knightminer/inspirations/recipes/InspirationsRecipes.java index f7c7338d..65e3f9fe 100644 --- a/src/main/java/knightminer/inspirations/recipes/InspirationsRecipes.java +++ b/src/main/java/knightminer/inspirations/recipes/InspirationsRecipes.java @@ -5,13 +5,13 @@ import knightminer.inspirations.common.ModuleBase; import knightminer.inspirations.common.item.HidableItem; import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; +import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; import knightminer.inspirations.library.recipe.cauldron.recipe.CauldronRecipe; import knightminer.inspirations.recipes.data.RecipesRecipeProvider; import knightminer.inspirations.recipes.item.MixedDyedBottleItem; import knightminer.inspirations.recipes.item.SimpleDyedBottleItem; import knightminer.inspirations.recipes.recipe.cauldron.EmptyBucketCauldronRecipe; import knightminer.inspirations.recipes.recipe.cauldron.FillBucketCauldronRecipe; -import knightminer.inspirations.recipes.recipe.cauldron.contents.CauldronWater; import net.minecraft.block.Block; import net.minecraft.block.FlowingFluidBlock; import net.minecraft.block.material.Material; @@ -158,14 +158,13 @@ void registerSerializers(Register> event) { emptyBucketSerializer = registry.register(new SpecialRecipeSerializer<>(EmptyBucketCauldronRecipe::new), "cauldron_empty_bucket"); fillBucketSerializer = registry.register(new SpecialRecipeSerializer<>(FillBucketCauldronRecipe::new), "cauldron_fill_bucket"); - // add water as an override to fluids and potions - CauldronWater water = CauldronContentTypes.WATER.get(); - CauldronContentTypes.FLUID.addOverride(Fluids.WATER, water); - CauldronContentTypes.POTION.addOverride(Potions.WATER, water); + // add water as an override to potions + ICauldronContents water = CauldronContentTypes.FLUID.of(Fluids.WATER); + CauldronContentTypes.POTION.setResult(Potions.WATER, water); // add all dyes as overrides into color for (DyeColor color : DyeColor.values()) { - CauldronContentTypes.COLOR.addOverride(color.getColorValue(), CauldronContentTypes.DYE.of(color)); + CauldronContentTypes.COLOR.setResult(color.getColorValue(), CauldronContentTypes.DYE.of(color)); } } diff --git a/src/main/java/knightminer/inspirations/recipes/RecipesClientEvents.java b/src/main/java/knightminer/inspirations/recipes/RecipesClientEvents.java index 5416da98..b53c5fa9 100644 --- a/src/main/java/knightminer/inspirations/recipes/RecipesClientEvents.java +++ b/src/main/java/knightminer/inspirations/recipes/RecipesClientEvents.java @@ -3,8 +3,8 @@ import knightminer.inspirations.Inspirations; import knightminer.inspirations.common.ClientEvents; import knightminer.inspirations.recipes.item.MixedDyedBottleItem; -import knightminer.inspirations.recipes.recipe.cauldron.contents.CauldronColor; -import knightminer.inspirations.recipes.recipe.cauldron.contents.CauldronPotion; +import knightminer.inspirations.recipes.recipe.cauldron.contents.ColorContentType; +import knightminer.inspirations.recipes.recipe.cauldron.contents.PotionContentType; import net.minecraft.client.renderer.color.ItemColors; import net.minecraft.inventory.container.PlayerContainer; import net.minecraftforge.api.distmarker.Dist; @@ -14,6 +14,7 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +@SuppressWarnings("unused") @EventBusSubscriber(modid = Inspirations.modID, value = Dist.CLIENT, bus = Bus.MOD) public class RecipesClientEvents extends ClientEvents { /* TODO: reimplement @@ -45,9 +46,8 @@ static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors itemColors = event.getItemColors(); // dyed water bottles - InspirationsRecipes.simpleDyedWaterBottle.forEach((color, bottle) -> { - itemColors.register((stack, index) -> index == 1 ? color.getColorValue() : -1, bottle); - }); + InspirationsRecipes.simpleDyedWaterBottle.forEach((color, bottle) -> + itemColors.register((stack, index) -> index == 1 ? color.getColorValue() : -1, bottle)); registerItemColors(itemColors, (stack, index) -> index == 1 ? MixedDyedBottleItem.dyeFromBottle(stack) : -1, InspirationsRecipes.mixedDyedWaterBottle); } @@ -56,8 +56,8 @@ static void registerTextures(TextureStitchEvent.Pre event) { if (PlayerContainer.LOCATION_BLOCKS_TEXTURE.equals(event.getMap().getTextureLocation())) { event.addSprite(InspirationsRecipes.STILL_FLUID); event.addSprite(InspirationsRecipes.FLOWING_FLUID); - event.addSprite(CauldronColor.TEXTURE); - event.addSprite(CauldronPotion.TEXTURE); + event.addSprite(ColorContentType.TEXTURE); + event.addSprite(PotionContentType.TEXTURE); } } } diff --git a/src/main/java/knightminer/inspirations/recipes/data/RecipesRecipeProvider.java b/src/main/java/knightminer/inspirations/recipes/data/RecipesRecipeProvider.java index aa085424..4b5b315a 100644 --- a/src/main/java/knightminer/inspirations/recipes/data/RecipesRecipeProvider.java +++ b/src/main/java/knightminer/inspirations/recipes/data/RecipesRecipeProvider.java @@ -8,7 +8,6 @@ import knightminer.inspirations.library.recipe.cauldron.CauldronIngredients; import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; import knightminer.inspirations.library.recipe.cauldron.ingredient.ContentMatchIngredient; -import knightminer.inspirations.library.recipe.cauldron.ingredient.ContentTypeIngredient; import knightminer.inspirations.library.recipe.cauldron.ingredient.FluidCauldronIngredient; import knightminer.inspirations.library.recipe.cauldron.ingredient.ICauldronIngredient; import knightminer.inspirations.library.recipe.cauldron.recipe.CauldronRecipeBuilder; @@ -75,7 +74,7 @@ protected void registerRecipes(Consumer consumer) { this.consumer = consumer; String folder = "recipes/cauldron/"; - ICauldronIngredient waterIngredient = ContentTypeIngredient.of(CauldronContentTypes.WATER); + ICauldronIngredient waterIngredient = FluidCauldronIngredient.of(Fluids.WATER); Consumer cauldronRecipes = withCondition(ConfigEnabledCondition.CAULDRON_RECIPES); // vanilla recipes // @@ -129,7 +128,7 @@ protected void registerRecipes(Consumer consumer) { CauldronRecipeBuilder.cauldron(Ingredient.fromItems(Blocks.ICE), waterIngredient) .maxLevels(2) .setFull() - .setOutput(CauldronContentTypes.WATER.get()) + .setOutput(CauldronContentTypes.FLUID.of(Fluids.WATER)) .addCriterion("has_item", hasItem(Blocks.ICE)) .build(cauldronRecipes, wrapE(Fluids.WATER, folder, "_from_ice")); @@ -212,7 +211,7 @@ private void addColoredRecipes(ITag tag, EnumObject handler.drain(new FluidStack(fluid, BUCKET_VOLUME), action)) .orElse(FluidStack.EMPTY); } diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/FillBucketCauldronRecipe.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/FillBucketCauldronRecipe.java index 3fa06338..3bfd418c 100644 --- a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/FillBucketCauldronRecipe.java +++ b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/FillBucketCauldronRecipe.java @@ -1,7 +1,6 @@ package knightminer.inspirations.recipes.recipe.cauldron; import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronFluid; import knightminer.inspirations.library.recipe.cauldron.inventory.ICauldronInventory; import knightminer.inspirations.library.recipe.cauldron.inventory.IModifyableCauldronInventory; import knightminer.inspirations.library.recipe.cauldron.recipe.ICauldronRecipe; @@ -35,8 +34,7 @@ public boolean matches(ICauldronInventory inv, World worldIn) { // must be a fluid return inv.getContents() - .as(CauldronContentTypes.FLUID) - .map(ICauldronFluid::getFluid) + .get(CauldronContentTypes.FLUID) // must have a fluid handler, I really wish you could flatmap a lazy optional .map(fluid -> FluidUtil.getFluidHandler(inv.getStack()) // handler must be fillable with the given fluid and must take 1000mb @@ -48,8 +46,7 @@ public boolean matches(ICauldronInventory inv, World worldIn) { @Override public void handleRecipe(IModifyableCauldronInventory inv) { inv.getContents() - .as(CauldronContentTypes.FLUID) - .map(ICauldronFluid::getFluid) + .get(CauldronContentTypes.FLUID) // must have a fluid handler, I really wish you could flatmap a lazy optional .ifPresent(fluid -> FluidUtil.getFluidHandler(inv.getStack()).ifPresent(handler -> { // if we successfully fill the handler, update the cauldron @@ -81,8 +78,7 @@ public ItemStack getRecipeOutput() { public ItemStack getCraftingResult(ICauldronInventory inv) { // return filled bucket for the contained fluid, or empty bucket if invalid fluid return new ItemStack(inv.getContents() - .as(CauldronContentTypes.FLUID) - .map(ICauldronFluid::getFluid) + .get(CauldronContentTypes.FLUID) .map(Fluid::getFilledBucket) .orElse(Items.BUCKET)); } diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronColor.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronColor.java deleted file mode 100644 index 7a3ee155..00000000 --- a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronColor.java +++ /dev/null @@ -1,34 +0,0 @@ -package knightminer.inspirations.recipes.recipe.cauldron.contents; - -import knightminer.inspirations.Inspirations; -import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronColor; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; -import net.minecraft.util.ResourceLocation; - -/** - * Standard implementation of {@link ICauldronColor} - */ -public class CauldronColor implements ICauldronColor { - public static final ResourceLocation TEXTURE = Inspirations.getResource("block/fluid/colorless"); - - private final int color; - public CauldronColor(int color) { - this.color = color; - } - - @Override - public int getColor() { - return color; - } - - @Override - public ResourceLocation getTextureName() { - return CauldronColor.TEXTURE; - } - - @Override - public CauldronContentType getType() { - return CauldronContentTypes.COLOR; - } -} diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronContents.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronContents.java new file mode 100644 index 00000000..de3a0d8b --- /dev/null +++ b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronContents.java @@ -0,0 +1,72 @@ +package knightminer.inspirations.recipes.recipe.cauldron.contents; + +import knightminer.inspirations.library.recipe.cauldron.contents.CauldronContentType; +import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; +import net.minecraft.util.ResourceLocation; + +import java.util.Optional; + +/** + * Content type implementation. Mainly out of the library as no one should be directly constructing this class + * @param Content value type + */ +public class CauldronContents implements ICauldronContents { + private final CauldronContentType type; + private final C value; + + /** + * Creates a new instance + * @param type Content type + * @param value Content value + */ + public CauldronContents(CauldronContentType type, C value) { + this.type = type; + this.value = value; + } + + @SuppressWarnings("unchecked") + @Override + public Optional get(CauldronContentType type) { + if (type == this.type) { + return Optional.of((T)this.value); + } + return type.getOverrideValue(this); + } + + @Override + public CauldronContentType getType() { + return type; + } + + @Override + public ResourceLocation getTextureName() { + return type.getTexture(value); + } + + @Override + public int getTintColor() { + return type.getColor(value); + } + + @Override + public boolean matches(CauldronContentType type, T value) { + return this.type == type && this.value == value; + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof ICauldronContents)) { + return false; + } + ICauldronContents contents = (ICauldronContents)other; + return contents.matches(type, value); + } + + @Override + public int hashCode() { + return 31 * type.hashCode() + value.hashCode(); + } +} diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronDye.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronDye.java deleted file mode 100644 index b6a46889..00000000 --- a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronDye.java +++ /dev/null @@ -1,32 +0,0 @@ -package knightminer.inspirations.recipes.recipe.cauldron.contents; - -import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronDye; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; -import net.minecraft.item.DyeColor; -import net.minecraft.util.ResourceLocation; - -/** - * Standard implementation of {@link ICauldronDye} - */ -public class CauldronDye implements ICauldronDye { - private final DyeColor dye; - public CauldronDye(DyeColor dye) { - this.dye = dye; - } - - @Override - public DyeColor getDye() { - return dye; - } - - @Override - public ResourceLocation getTextureName() { - return CauldronColor.TEXTURE; - } - - @Override - public CauldronContentType getType() { - return CauldronContentTypes.DYE; - } -} diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronFluid.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronFluid.java deleted file mode 100644 index 7832e31f..00000000 --- a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronFluid.java +++ /dev/null @@ -1,24 +0,0 @@ -package knightminer.inspirations.recipes.recipe.cauldron.contents; - -import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronFluid; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; -import net.minecraft.fluid.Fluid; -import net.minecraftforge.registries.IRegistryDelegate; - -public class CauldronFluid implements ICauldronFluid { - private final IRegistryDelegate fluid; - public CauldronFluid(Fluid fluid) { - this.fluid = fluid.delegate; - } - - @Override - public CauldronContentType getType() { - return CauldronContentTypes.FLUID; - } - - @Override - public Fluid getFluid() { - return fluid.get(); - } -} diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronPotion.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronPotion.java deleted file mode 100644 index d361b478..00000000 --- a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronPotion.java +++ /dev/null @@ -1,33 +0,0 @@ -package knightminer.inspirations.recipes.recipe.cauldron.contents; - -import knightminer.inspirations.Inspirations; -import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronPotion; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; -import net.minecraft.potion.Potion; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.registries.IRegistryDelegate; - -public class CauldronPotion implements ICauldronPotion { - public static final ResourceLocation TEXTURE = Inspirations.getResource("block/fluid/potion"); - - private final IRegistryDelegate potion; - public CauldronPotion(Potion potion) { - this.potion = potion.delegate; - } - - @Override - public CauldronContentType getType() { - return CauldronContentTypes.POTION; - } - - @Override - public Potion getPotion() { - return potion.get(); - } - - @Override - public ResourceLocation getTextureName() { - return TEXTURE; - } -} diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronWater.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronWater.java deleted file mode 100644 index b887a99c..00000000 --- a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/CauldronWater.java +++ /dev/null @@ -1,35 +0,0 @@ -package knightminer.inspirations.recipes.recipe.cauldron.contents; - -import knightminer.inspirations.library.recipe.cauldron.CauldronContentTypes; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronFluid; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronPotion; -import knightminer.inspirations.library.recipe.cauldron.contenttype.CauldronContentType; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.Fluids; -import net.minecraft.potion.Potion; -import net.minecraft.potion.Potions; - -/** - * Class for the base water content type - */ -public class CauldronWater implements ICauldronFluid, ICauldronPotion { - @Override - public CauldronContentType getType() { - return CauldronContentTypes.WATER; - } - - @Override - public int getTintColor() { - return -1; - } - - @Override - public Fluid getFluid() { - return Fluids.WATER; - } - - @Override - public Potion getPotion() { - return Potions.WATER; - } -} diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/ColorContentType.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/ColorContentType.java index 72527ae6..aaa267ff 100644 --- a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/ColorContentType.java +++ b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/ColorContentType.java @@ -1,17 +1,34 @@ package knightminer.inspirations.recipes.recipe.cauldron.contents; -import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronColor; -import knightminer.inspirations.library.recipe.cauldron.contenttype.MapContentType; +import io.netty.handler.codec.DecoderException; +import knightminer.inspirations.Inspirations; +import knightminer.inspirations.library.recipe.cauldron.contents.CauldronContentType; +import knightminer.inspirations.library.recipe.cauldron.contents.ICauldronContents; import net.minecraft.network.PacketBuffer; +import net.minecraft.util.ResourceLocation; import javax.annotation.Nullable; +import java.util.Optional; /** - * Content type for {@link CauldronColor} + * Content type for colors in the cauldron */ -public class ColorContentType extends MapContentType { - public ColorContentType() { - super(ICauldronColor.class, CauldronColor::new, ICauldronColor::getColor, "color"); +public class ColorContentType extends CauldronContentType { + public static final ResourceLocation TEXTURE = Inspirations.getResource("block/fluid/colorless"); + + @Override + public String getKey() { + return "color"; + } + + @Override + public ResourceLocation getTexture(Integer value) { + return TEXTURE; + } + + @Override + public int getColor(Integer value) { + return value; } @Override @@ -31,12 +48,17 @@ public Integer getEntry(String name) { } @Override - public ICauldronColor read(PacketBuffer buffer) { + public ICauldronContents read(PacketBuffer buffer) { return of(buffer.readInt()); } @Override - public void write(ICauldronColor contents, PacketBuffer buffer) { - buffer.writeInt(contents.getColor()); + public void write(ICauldronContents contents, PacketBuffer buffer) { + Optional optional = contents.get(this); + if (optional.isPresent()) { + buffer.writeInt(optional.get()); + } else { + throw new DecoderException("Invalid class type for cauldron contents"); + } } } diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/DyeContentType.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/DyeContentType.java new file mode 100644 index 00000000..f8d99f8e --- /dev/null +++ b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/DyeContentType.java @@ -0,0 +1,28 @@ +package knightminer.inspirations.recipes.recipe.cauldron.contents; + +import knightminer.inspirations.library.recipe.cauldron.contents.NamedContentType; +import net.minecraft.item.DyeColor; +import net.minecraft.util.ResourceLocation; + +/** + * Content type for the 16 dye enum values + */ +public class DyeContentType extends NamedContentType { + /** + * Creates a new type instance + */ + @SuppressWarnings("ConstantConditions") + public DyeContentType() { + super(name -> DyeColor.byTranslationKey(name, null)); + } + + @Override + public ResourceLocation getTexture(DyeColor value) { + return ColorContentType.TEXTURE; + } + + @Override + public int getColor(DyeColor value) { + return value.getColorValue(); + } +} diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/FluidContentType.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/FluidContentType.java new file mode 100644 index 00000000..750e1c2a --- /dev/null +++ b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/FluidContentType.java @@ -0,0 +1,28 @@ +package knightminer.inspirations.recipes.recipe.cauldron.contents; + +import knightminer.inspirations.library.recipe.cauldron.contents.RegistryContentType; +import net.minecraft.fluid.Fluid; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistries; + +/** + * Content type for a fluid + */ +public class FluidContentType extends RegistryContentType { + /** + * Creates a new instance + */ + public FluidContentType() { + super(ForgeRegistries.FLUIDS); + } + + @Override + public ResourceLocation getTexture(Fluid fluid) { + return fluid.getAttributes().getStillTexture(); + } + + @Override + public int getColor(Fluid fluid) { + return fluid.getAttributes().getColor(); + } +} diff --git a/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/PotionContentType.java b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/PotionContentType.java new file mode 100644 index 00000000..d96c9408 --- /dev/null +++ b/src/main/java/knightminer/inspirations/recipes/recipe/cauldron/contents/PotionContentType.java @@ -0,0 +1,32 @@ +package knightminer.inspirations.recipes.recipe.cauldron.contents; + +import knightminer.inspirations.Inspirations; +import knightminer.inspirations.library.recipe.cauldron.contents.RegistryContentType; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionUtils; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistries; + +/** + * Potion content type + */ +public class PotionContentType extends RegistryContentType { + public static final ResourceLocation TEXTURE = Inspirations.getResource("block/fluid/potion"); + + /** + * Creates a new instance + */ + public PotionContentType() { + super(ForgeRegistries.POTION_TYPES); + } + + @Override + public ResourceLocation getTexture(Potion value) { + return TEXTURE; + } + + @Override + public int getColor(Potion value) { + return PotionUtils.getPotionColor(value); + } +}