Skip to content

Commit

Permalink
Update for Minecraft 1.20.2-pre4.
Browse files Browse the repository at this point in the history
- Update for Minecraft 1.20.2-pre4
* Update Fabric API dep; closes #155
* Major changes to piglin bartering loot methods
* Significant changes to ItemPredicates in recipe conditions
* Significant changes to Ash layer mixin
  • Loading branch information
gniftygnome committed Sep 15, 2023
1 parent e520c85 commit aef81cb
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public PhotofernBlock() {
}

@Override
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) {
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags;
import net.minecraft.advancement.criterion.InventoryChangedCriterion;
import net.minecraft.data.server.recipe.RecipeJsonProvider;
import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder;
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.predicate.NbtPredicate;
import net.minecraft.predicate.NumberRange;
import net.minecraft.predicate.item.EnchantmentPredicate;
import net.minecraft.predicate.item.ItemPredicate;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.book.RecipeCategory;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;

import java.util.List;
import java.util.function.Consumer;
import java.util.Optional;

public class CinderscapesRecipeProvider extends FabricRecipeProvider {
protected CinderscapesRecipeProvider(FabricDataOutput dataOutput) {
super(dataOutput);
}

@Override
public void generate(Consumer<RecipeJsonProvider> exporter) {
public void generate(RecipeExporter exporter) {
// vanilla recipes
ShapedRecipeJsonBuilder.create(RecipeCategory.REDSTONE, Items.COMPARATOR, 1)
.pattern(" T ")
Expand All @@ -39,8 +39,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
.input('T', Items.REDSTONE_TORCH)
.input('Q', ConventionalItemTags.QUARTZ)
.input('S', Items.STONE)
.criterion("has_quartz", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(ConventionalItemTags.QUARTZ, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(ConventionalItemTags.QUARTZ)))
.offerTo(exporter, new Identifier("minecraft", "comparator"));

ShapedRecipeJsonBuilder.create(RecipeCategory.REDSTONE, Items.DAYLIGHT_DETECTOR, 1)
Expand All @@ -50,8 +49,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
.input('G', Items.GLASS)
.input('Q', ConventionalItemTags.QUARTZ)
.input('W', ItemTags.WOODEN_SLABS)
.criterion("has_quartz", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(ConventionalItemTags.QUARTZ, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(ConventionalItemTags.QUARTZ)))
.offerTo(exporter, new Identifier("minecraft", "daylight_detector"));

ShapedRecipeJsonBuilder.create(RecipeCategory.REDSTONE, Items.OBSERVER, 1)
Expand All @@ -61,8 +59,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
.input('C', Items.COBBLESTONE)
.input('Q', ConventionalItemTags.QUARTZ)
.input('R', Items.REDSTONE)
.criterion("has_quartz", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(ConventionalItemTags.QUARTZ, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(ConventionalItemTags.QUARTZ)))
.offerTo(exporter, new Identifier("minecraft", "observer"));


Expand All @@ -84,8 +81,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
.input(CinderscapesItemTags.SULFURS)
.input(ItemTags.COALS)
.input(Items.BONE_MEAL)
.criterion("has_sulfurs", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(CinderscapesItemTags.SULFURS, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_sulfurs", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(CinderscapesItemTags.SULFURS)))
.offerTo(exporter);


Expand All @@ -110,13 +106,11 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.ROSE_QUARTZ_PILLAR, CinderscapesBlocks.ROSE_QUARTZ_BLOCK);
createSlabRecipe(RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.ROSE_QUARTZ_SLAB, Ingredient.ofItems(CinderscapesBlocks.CHISELED_ROSE_QUARTZ_BLOCK, CinderscapesBlocks.ROSE_QUARTZ_BLOCK, CinderscapesBlocks.ROSE_QUARTZ_PILLAR))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(CinderscapesItemTags.ROSE_QUARTZ_CONVERTIBLES, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(CinderscapesItemTags.ROSE_QUARTZ_CONVERTIBLES)))
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.ROSE_QUARTZ_SLAB, CinderscapesBlocks.ROSE_QUARTZ_BLOCK, 2);
createStairsRecipe(CinderscapesBlocks.ROSE_QUARTZ_STAIRS, Ingredient.ofItems(CinderscapesBlocks.CHISELED_ROSE_QUARTZ_BLOCK, CinderscapesBlocks.ROSE_QUARTZ_BLOCK, CinderscapesBlocks.ROSE_QUARTZ_PILLAR))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(CinderscapesItemTags.ROSE_QUARTZ_CONVERTIBLES, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(CinderscapesItemTags.ROSE_QUARTZ_CONVERTIBLES)))
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.ROSE_QUARTZ_STAIRS, CinderscapesBlocks.ROSE_QUARTZ_BLOCK);
offerSmelting(exporter, List.of(CinderscapesBlocks.ROSE_QUARTZ_BLOCK), RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SMOOTH_ROSE_QUARTZ, 0.1f, 200, "building_blocks");
Expand Down Expand Up @@ -147,13 +141,11 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SMOKY_QUARTZ_PILLAR, CinderscapesBlocks.SMOKY_QUARTZ_BLOCK);
createSlabRecipe(RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SMOKY_QUARTZ_SLAB, Ingredient.ofItems(CinderscapesBlocks.CHISELED_SMOKY_QUARTZ_BLOCK, CinderscapesBlocks.SMOKY_QUARTZ_BLOCK, CinderscapesBlocks.SMOKY_QUARTZ_PILLAR))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(CinderscapesItemTags.SMOKY_QUARTZ_CONVERTIBLES, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(CinderscapesItemTags.SMOKY_QUARTZ_CONVERTIBLES)))
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SMOKY_QUARTZ_SLAB, CinderscapesBlocks.SMOKY_QUARTZ_BLOCK, 2);
createStairsRecipe(CinderscapesBlocks.SMOKY_QUARTZ_STAIRS, Ingredient.ofItems(CinderscapesBlocks.CHISELED_SMOKY_QUARTZ_BLOCK, CinderscapesBlocks.SMOKY_QUARTZ_BLOCK, CinderscapesBlocks.SMOKY_QUARTZ_PILLAR))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(CinderscapesItemTags.SMOKY_QUARTZ_CONVERTIBLES, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(CinderscapesItemTags.SMOKY_QUARTZ_CONVERTIBLES)))
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SMOKY_QUARTZ_STAIRS, CinderscapesBlocks.SMOKY_QUARTZ_BLOCK);
offerSmelting(exporter, List.of(CinderscapesBlocks.SMOKY_QUARTZ_BLOCK), RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SMOOTH_SMOKY_QUARTZ, 0.1f, 200, "building_blocks");
Expand Down Expand Up @@ -184,13 +176,11 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SULFUR_QUARTZ_PILLAR, CinderscapesBlocks.SULFUR_QUARTZ_BLOCK);
createSlabRecipe(RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SULFUR_QUARTZ_SLAB, Ingredient.ofItems(CinderscapesBlocks.CHISELED_SULFUR_QUARTZ_BLOCK, CinderscapesBlocks.SULFUR_QUARTZ_BLOCK, CinderscapesBlocks.SULFUR_QUARTZ_PILLAR))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(CinderscapesItemTags.SULFUR_QUARTZ_CONVERTIBLES, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(CinderscapesItemTags.SULFUR_QUARTZ_CONVERTIBLES)))
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SULFUR_QUARTZ_SLAB, CinderscapesBlocks.SULFUR_QUARTZ_BLOCK, 2);
createStairsRecipe(CinderscapesBlocks.SULFUR_QUARTZ_STAIRS, Ingredient.ofItems(CinderscapesBlocks.CHISELED_SULFUR_QUARTZ_BLOCK, CinderscapesBlocks.SULFUR_QUARTZ_BLOCK, CinderscapesBlocks.SULFUR_QUARTZ_PILLAR))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(
new ItemPredicate(CinderscapesItemTags.SULFUR_QUARTZ_CONVERTIBLES, null, NumberRange.IntRange.ANY, NumberRange.IntRange.ANY, EnchantmentPredicate.ARRAY_OF_ANY, EnchantmentPredicate.ARRAY_OF_ANY, null, NbtPredicate.ANY)))
.criterion("has_quartz_blocks", InventoryChangedCriterion.Conditions.items(getItemTagPredicate(CinderscapesItemTags.SULFUR_QUARTZ_CONVERTIBLES)))
.offerTo(exporter);
offerStonecuttingRecipe(exporter, RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SULFUR_QUARTZ_STAIRS, CinderscapesBlocks.SULFUR_QUARTZ_BLOCK);
offerSmelting(exporter, List.of(CinderscapesBlocks.SULFUR_QUARTZ_BLOCK), RecipeCategory.BUILDING_BLOCKS, CinderscapesBlocks.SMOOTH_SULFUR_QUARTZ, 0.1f, 200, "building_blocks");
Expand Down Expand Up @@ -280,6 +270,20 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
.offerTo(exporter);
}

// Returns an ItemPredicate matching any item in the provided ItemTag key.
private static ItemPredicate getItemTagPredicate(TagKey<Item> itemTagKey) {
return new ItemPredicate(
Optional.of(itemTagKey),
Optional.empty(),
NumberRange.IntRange.ANY,
NumberRange.IntRange.ANY,
List.of(),
List.of(),
Optional.empty(),
Optional.empty()
);
}

@Override
protected Identifier getRecipeIdentifier(Identifier identifier) {
return new Identifier(Cinderscapes.NAMESPACE, identifier.getPath());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
package com.terraformersmc.cinderscapes.init;

import com.terraformersmc.cinderscapes.Cinderscapes;
import com.terraformersmc.cinderscapes.loottables.IntegratedEntry;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.condition.LootCondition;
import net.minecraft.loot.entry.LootPoolEntryType;
import net.minecraft.loot.function.LootFunction;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.function.SetCountLootFunction;
import net.minecraft.loot.provider.number.UniformLootNumberProvider;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.VillagerProfession;

public class CinderscapesTrades {
private static final Identifier BARTERING_LOOT_TABLE_ID = new Identifier("minecraft", "gameplay/piglin_bartering");

public static final LootPoolEntryType INTEGRATED = Registry.register(Registries.LOOT_POOL_ENTRY_TYPE, Cinderscapes.id("integrated"), new LootPoolEntryType(new IntegratedEntry.Serializer()));

public static void init() {

LootTableEvents.MODIFY.register((resourceManager, manager, id, supplier, setter) -> {
if (BARTERING_LOOT_TABLE_ID.equals(id)) {
supplier.modifyPools((pools) -> {
pools .with(new IntegratedEntry(CinderscapesItems.ROSE_QUARTZ, 20, 0, new LootCondition[]{}, new LootFunction[]{SetCountLootFunction.builder(UniformLootNumberProvider.create(5, 12)).build()}))
.with(new IntegratedEntry(CinderscapesItems.SMOKY_QUARTZ, 20, 0, new LootCondition[]{}, new LootFunction[]{SetCountLootFunction.builder(UniformLootNumberProvider.create(5, 12)).build()}))
.with(new IntegratedEntry(CinderscapesItems.SULFUR_QUARTZ, 20, 0, new LootCondition[]{}, new LootFunction[]{SetCountLootFunction.builder(UniformLootNumberProvider.create(5, 12)).build()}));
pools .with(ItemEntry.builder(CinderscapesItems.ROSE_QUARTZ).weight(20).quality(0).apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(5, 12))).build())
.with(ItemEntry.builder(CinderscapesItems.SMOKY_QUARTZ).weight(20).quality(0).apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(5, 12))).build())
.with(ItemEntry.builder(CinderscapesItems.SULFUR_QUARTZ).weight(20).quality(0).apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(5, 12))).build());
});
}
});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.world.MutableWorldProperties;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.dimension.DimensionType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -33,10 +31,18 @@ protected MixinServerWorld(MutableWorldProperties properties, RegistryKey<World>
}

// TODO: Revisit this and make it easier to read
@Inject(method="tickChunk", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/server/world/ServerWorld;getBiome(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/registry/entry/RegistryEntry;", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
private void cinderscapes$tickChunk(WorldChunk chunk, int randomTickSpeed, CallbackInfo callback, ChunkPos chunkPos, boolean bl, int i, int j, Profiler profiler, BlockPos blockPos2, BlockPos blockPos3) {
// And fix having two calls to getBiome (maybe requires MixinExtras)
@Inject(method="tickIceAndSnow",
at = @At(value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/server/world/ServerWorld;getBiome(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/registry/entry/RegistryEntry;",
ordinal = 0,
shift = At.Shift.AFTER
),
locals = LocalCapture.NO_CAPTURE
)
private void cinderscapes$tickAsh(boolean raining, BlockPos tickPos, CallbackInfo ci) {
if (CinderscapesConfig.INSTANCE.enableAshFall) {
BlockPos pos = this.getRandomPosInChunk(i, 0, j, 15);
BlockPos pos = tickPos.mutableCopy();
BlockState state = getBlockState(pos);
RegistryEntry<Biome> biome = this.getBiome(pos);

Expand Down
Loading

0 comments on commit aef81cb

Please sign in to comment.