diff --git a/src/main/java/io/github/foundationgames/sandwichable/Sandwichable.java b/src/main/java/io/github/foundationgames/sandwichable/Sandwichable.java index 45df5f4..7be996a 100644 --- a/src/main/java/io/github/foundationgames/sandwichable/Sandwichable.java +++ b/src/main/java/io/github/foundationgames/sandwichable/Sandwichable.java @@ -21,11 +21,8 @@ import io.github.foundationgames.sandwichable.items.SandwichableGroupIconBuilder; import io.github.foundationgames.sandwichable.items.spread.SpreadType; import io.github.foundationgames.sandwichable.mixin.CriteriaAccess; -import io.github.foundationgames.sandwichable.recipe.CuttingRecipe; -import io.github.foundationgames.sandwichable.recipe.CuttingRecipeSerializer; import io.github.foundationgames.sandwichable.recipe.SandwichableRecipes; -import io.github.foundationgames.sandwichable.recipe.ToastingRecipe; -import io.github.foundationgames.sandwichable.recipe.ToastingRecipeSerializer; +import io.github.foundationgames.sandwichable.structure.SandwichableStructures; import io.github.foundationgames.sandwichable.util.AncientGrainType; import io.github.foundationgames.sandwichable.util.ExtraDispenserBehaviorRegistry; import io.github.foundationgames.sandwichable.util.Util; @@ -33,11 +30,13 @@ import io.github.foundationgames.sandwichable.worldgen.SandwichableWorldgen; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; import net.fabricmc.fabric.api.loot.v2.LootTableEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; @@ -48,13 +47,10 @@ import net.minecraft.entity.Entity; import net.minecraft.item.*; import net.minecraft.loot.LootPool; -import net.minecraft.loot.entry.ItemEntry; +import net.minecraft.loot.LootTables; +import net.minecraft.loot.entry.LootTableEntry; import net.minecraft.loot.function.LootFunctionType; -import net.minecraft.loot.function.SetCountLootFunction; -import net.minecraft.loot.provider.number.UniformLootNumberProvider; import net.minecraft.particle.ParticleTypes; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.recipe.RecipeType; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; @@ -65,12 +61,16 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.registry.Registry; +import net.minecraft.village.TradeOffer; +import net.minecraft.village.VillagerProfession; import net.minecraft.world.GameRules; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Set; + public class Sandwichable implements ModInitializer { public static final ItemGroup SANDWICHABLE_ITEMS = FabricItemGroupBuilder.build(Util.id("sandwichable"), SandwichableGroupIconBuilder::getIcon); @@ -173,16 +173,37 @@ public void onInitialize() { return ActionResult.PASS; }); + ServerLifecycleEvents.SERVER_STARTING.register(SandwichableStructures::addStructures); + + Set modifiedChests = Set.of( + LootTables.ANCIENT_CITY_CHEST, + LootTables.VILLAGE_PLAINS_CHEST, + LootTables.VILLAGE_SAVANNA_HOUSE_CHEST, + LootTables.VILLAGE_SNOWY_HOUSE_CHEST, + LootTables.VILLAGE_TAIGA_HOUSE_CHEST, + LootTables.VILLAGE_DESERT_HOUSE_CHEST + ); + LootTableEvents.MODIFY.register((resources, loot, id, table, source) -> { - if (source.isBuiltin() && ANCIENT_CITY_LOOT.equals(id)) { - table.pool(LootPool.builder().with( - ItemEntry.builder(ItemsRegistry.ANCIENT_GRAIN_SEEDS) - .apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1, 3))) - ).rolls(UniformLootNumberProvider.create(0, 2)) - ); + Identifier injectId = Util.id("inject/" + id.getPath()); + if (modifiedChests.contains(id)) { + table.pool(LootPool.builder().with(LootTableEntry.builder(injectId).weight(1).quality(0)).build()); } }); + TradeOfferHelper.registerVillagerOffers(VillagerProfession.FARMER, 1, + factories -> new TradeOffer(new ItemStack(ItemsRegistry.ONION, 26), + new ItemStack(Items.EMERALD), 16, 2, .05f)); + TradeOfferHelper.registerVillagerOffers(VillagerProfession.FARMER, 1, + factories -> new TradeOffer(new ItemStack(ItemsRegistry.TOMATO, 22), + new ItemStack(Items.EMERALD), 16, 2, .05f)); + TradeOfferHelper.registerVillagerOffers(VillagerProfession.FARMER, 1, + factories -> new TradeOffer(new ItemStack(ItemsRegistry.CUCUMBER, 15), + new ItemStack(Items.EMERALD), 16, 2, .05f)); + TradeOfferHelper.registerVillagerOffers(VillagerProfession.FARMER, 1, + factories -> new TradeOffer(new ItemStack(ItemsRegistry.LETTUCE_HEAD, 15), + new ItemStack(Items.EMERALD), 16, 2, .05f)); + if(FabricLoader.getInstance().isModLoaded("croptopia")) { CroptopiaCompat.init(); } diff --git a/src/main/java/io/github/foundationgames/sandwichable/blocks/entity/renderer/PickleJarBlockEntityRenderer.java b/src/main/java/io/github/foundationgames/sandwichable/blocks/entity/renderer/PickleJarBlockEntityRenderer.java index 69fce81..f947820 100644 --- a/src/main/java/io/github/foundationgames/sandwichable/blocks/entity/renderer/PickleJarBlockEntityRenderer.java +++ b/src/main/java/io/github/foundationgames/sandwichable/blocks/entity/renderer/PickleJarBlockEntityRenderer.java @@ -100,7 +100,6 @@ public CucumberModel(BlockEntityRendererFactory.Context ctx) { this.cucumberBottom = root.getChild("cucumber_bottom"); this.pickleTop = root.getChild("pickle_top"); this.pickleBottom = root.getChild("pickle_bottom"); - System.out.println(); } /** diff --git a/src/main/java/io/github/foundationgames/sandwichable/mixin/FishingBobberEntityMixin.java b/src/main/java/io/github/foundationgames/sandwichable/mixin/FishingBobberEntityMixin.java index 92ae233..19c64a0 100644 --- a/src/main/java/io/github/foundationgames/sandwichable/mixin/FishingBobberEntityMixin.java +++ b/src/main/java/io/github/foundationgames/sandwichable/mixin/FishingBobberEntityMixin.java @@ -2,16 +2,14 @@ import io.github.foundationgames.sandwichable.blocks.BlocksRegistry; import io.github.foundationgames.sandwichable.util.Util; -import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.projectile.FishingBobberEntity; -import net.minecraft.loot.LootTable; import net.minecraft.util.Identifier; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.ModifyArg; @Mixin(FishingBobberEntity.class) public abstract class FishingBobberEntityMixin extends Entity { @@ -22,13 +20,11 @@ public FishingBobberEntityMixin(EntityType type, World world) { throw new AssertionError("accessed dummy constructor"); } - @ModifyVariable(method = "use", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/loot/LootManager;getTable(Lnet/minecraft/util/Identifier;)Lnet/minecraft/loot/LootTable;", shift = At.Shift.AFTER, ordinal = 0), index = 5) - public LootTable sandwichable$changeLootTable(LootTable old) { - BlockState state = this.world.getBlockState(this.getBlockPos()); - System.out.println(state); - if(state.isOf(BlocksRegistry.PICKLE_BRINE)) { - return this.world.getServer().getLootManager().getTable(BRINE_LOOT_FISHING); + @ModifyArg(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/loot/LootManager;getTable(Lnet/minecraft/util/Identifier;)Lnet/minecraft/loot/LootTable;")) + public Identifier sandwichable$changeLootTable(Identifier original) { + if(this.world.getBlockState(this.getBlockPos()).isOf(BlocksRegistry.PICKLE_BRINE)) { + return BRINE_LOOT_FISHING; } - return old; + return original; } } diff --git a/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolAccess.java b/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolAccess.java deleted file mode 100644 index 1019870..0000000 --- a/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolAccess.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.foundationgames.sandwichable.mixin; - -import com.mojang.datafixers.util.Pair; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import net.minecraft.structure.pool.StructurePool; -import net.minecraft.structure.pool.StructurePoolElement; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.List; - -@Mixin(StructurePool.class) -public interface StructurePoolAccess { - @Accessor(value = "elements") - ObjectArrayList sandwichable$getElements(); - - @Accessor(value = "elementCounts") - List> sandwichable$getElementCounts(); -} diff --git a/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolAccessor.java b/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolAccessor.java new file mode 100644 index 0000000..00b35ff --- /dev/null +++ b/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolAccessor.java @@ -0,0 +1,28 @@ +package io.github.foundationgames.sandwichable.mixin; + +import com.mojang.datafixers.util.Pair; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.structure.pool.StructurePool; +import net.minecraft.structure.pool.StructurePoolElement; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(StructurePool.class) +public interface StructurePoolAccessor { + @Accessor + List> getElementCounts(); + + @Mutable + @Accessor + void setElementCounts(List> elementCounts); + + @Accessor + ObjectArrayList getElements(); + + @Mutable + @Accessor + void setElements(ObjectArrayList elements); +} diff --git a/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolsMixin.java b/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolsMixin.java deleted file mode 100644 index 7d0e06b..0000000 --- a/src/main/java/io/github/foundationgames/sandwichable/mixin/StructurePoolsMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.foundationgames.sandwichable.mixin; - -import io.github.foundationgames.sandwichable.util.Util; -import net.minecraft.structure.pool.StructurePool; -import net.minecraft.structure.pool.StructurePools; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.BuiltinRegistries; -import net.minecraft.util.registry.RegistryEntry; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(StructurePools.class) -public class StructurePoolsMixin { - @Inject(method = "register", at = @At("HEAD"), cancellable = true) - private static void sandwichable$inject(StructurePool pool, CallbackInfoReturnable> cir) { - Util.tryAddElementToPool(new Identifier("village/plains/houses"), pool, "sandwichable:village/plains/houses/plains_sandwich_stand", StructurePool.Projection.RIGID, 2); - Util.tryAddElementToPool(new Identifier("village/desert/houses"), pool, "sandwichable:village/desert/houses/desert_sandwich_stand", StructurePool.Projection.RIGID, 2); - Util.tryAddElementToPool(new Identifier("village/savanna/houses"), pool, "sandwichable:village/savanna/houses/savanna_sandwich_stand", StructurePool.Projection.RIGID, 2); - Util.tryAddElementToPool(new Identifier("village/taiga/houses"), pool, "sandwichable:village/taiga/houses/taiga_sandwich_stand", StructurePool.Projection.RIGID, 2); - Util.tryAddElementToPool(new Identifier("village/snowy/houses"), pool, "sandwichable:village/snowy/houses/snowy_sandwich_stand", StructurePool.Projection.RIGID, 2); - } -} diff --git a/src/main/java/io/github/foundationgames/sandwichable/structure/SandwichableStructures.java b/src/main/java/io/github/foundationgames/sandwichable/structure/SandwichableStructures.java new file mode 100644 index 0000000..652c508 --- /dev/null +++ b/src/main/java/io/github/foundationgames/sandwichable/structure/SandwichableStructures.java @@ -0,0 +1,51 @@ +package io.github.foundationgames.sandwichable.structure; + +import com.mojang.datafixers.util.Pair; +import io.github.foundationgames.sandwichable.mixin.StructurePoolAccessor; +import io.github.foundationgames.sandwichable.util.Util; +import net.minecraft.server.MinecraftServer; +import net.minecraft.structure.pool.SinglePoolElement; +import net.minecraft.structure.pool.StructurePool; +import net.minecraft.structure.pool.StructurePoolElement; +import net.minecraft.structure.processor.StructureProcessorList; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryEntry; +import net.minecraft.util.registry.RegistryKey; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class SandwichableStructures { + public static final int SANDWICH_STAND_CHANCE = 2; + + public static void addStructures(MinecraftServer server) { + addToStructurePool(server, new Identifier("village/plains/houses"), Util.id("village/plains/houses/plains_sandwich_stand"), new Identifier("empty"), SANDWICH_STAND_CHANCE); + addToStructurePool(server, new Identifier("village/savanna/houses"), Util.id("village/savanna/houses/savanna_sandwich_stand"), new Identifier("empty"), SANDWICH_STAND_CHANCE); + addToStructurePool(server, new Identifier("village/taiga/houses"), Util.id("village/plains/taiga/taiga_sandwich_stand"), new Identifier("empty"), SANDWICH_STAND_CHANCE); + addToStructurePool(server, new Identifier("village/snowy/houses"), Util.id("village/snowy/houses/snowy_sandwich_stand"), new Identifier("empty"), SANDWICH_STAND_CHANCE); + } + + private static void addToStructurePool(MinecraftServer server, Identifier poolId, Identifier structureId, Identifier processor, int weight) { + Optional poolGetter = server.getRegistryManager().get(Registry.STRUCTURE_POOL_KEY).getOrEmpty(poolId); + + if (poolGetter.isEmpty()) { + return; + } + StructurePool pool = poolGetter.get(); + + Optional> processorList = server.getRegistryManager().get(Registry.STRUCTURE_PROCESSOR_LIST_KEY).getEntry(RegistryKey.of(Registry.STRUCTURE_PROCESSOR_LIST_KEY, processor)); + + List pieceList = ((StructurePoolAccessor) pool).getElements(); + SinglePoolElement piece = processorList.isPresent() ? StructurePoolElement.ofProcessedSingle(structureId.toString(), processorList.orElseThrow()).apply(StructurePool.Projection.RIGID) : StructurePoolElement.ofLegacySingle(structureId.toString()).apply(StructurePool.Projection.RIGID); + + ArrayList> list = new ArrayList<>(((StructurePoolAccessor) pool).getElementCounts()); + list.add(Pair.of(piece, weight)); + ((StructurePoolAccessor) pool).setElementCounts(list); + + for (int i = 0; i < weight; ++i) { + pieceList.add(piece); + } + } +} diff --git a/src/main/java/io/github/foundationgames/sandwichable/util/Util.java b/src/main/java/io/github/foundationgames/sandwichable/util/Util.java index 0a2d979..eb89328 100644 --- a/src/main/java/io/github/foundationgames/sandwichable/util/Util.java +++ b/src/main/java/io/github/foundationgames/sandwichable/util/Util.java @@ -2,11 +2,9 @@ import com.google.common.collect.ImmutableMap; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.datafixers.util.Pair; import io.github.foundationgames.sandwichable.blocks.entity.SyncedBlockEntity; import io.github.foundationgames.sandwichable.config.ConfigInABarrel; import io.github.foundationgames.sandwichable.config.SandwichableConfig; -import io.github.foundationgames.sandwichable.mixin.StructurePoolAccess; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minecraft.block.Block; @@ -15,12 +13,7 @@ import net.minecraft.nbt.StringNbtReader; import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.ParticleTypes; -import net.minecraft.structure.pool.StructurePool; -import net.minecraft.structure.pool.StructurePoolElement; -import net.minecraft.structure.processor.StructureProcessorLists; - import net.minecraft.text.Text; - import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -69,16 +62,6 @@ public static Int2ObjectMap copyToFastUtilMap(ImmutableMa return new Int2ObjectOpenHashMap(immutableMap); } - public static void tryAddElementToPool(Identifier targetPool, StructurePool pool, String elementId, StructurePool.Projection projection, int weight) { - if(targetPool.equals(pool.getId())) { - StructurePoolElement element = StructurePoolElement.ofProcessedLegacySingle(elementId, StructureProcessorLists.EMPTY).apply(projection); - for (int i = 0; i < weight; i++) { - ((StructurePoolAccess)pool).sandwichable$getElements().add(element); - } - ((StructurePoolAccess)pool).sandwichable$getElementCounts().add(Pair.of(element, weight)); - } - } - public static void sync(SyncedBlockEntity be) { be.sync(); } diff --git a/src/main/java/io/github/foundationgames/sandwichable/villager/SandwichMakerProfession.java b/src/main/java/io/github/foundationgames/sandwichable/villager/SandwichMakerProfession.java index a43a47e..953cce9 100644 --- a/src/main/java/io/github/foundationgames/sandwichable/villager/SandwichMakerProfession.java +++ b/src/main/java/io/github/foundationgames/sandwichable/villager/SandwichMakerProfession.java @@ -1,9 +1,9 @@ package io.github.foundationgames.sandwichable.villager; -import com.google.common.collect.ImmutableMap; import io.github.foundationgames.sandwichable.blocks.BlocksRegistry; import io.github.foundationgames.sandwichable.items.ItemsRegistry; import io.github.foundationgames.sandwichable.util.Util; +import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; import net.fabricmc.fabric.api.object.builder.v1.villager.VillagerProfessionBuilder; import net.fabricmc.fabric.api.object.builder.v1.world.poi.PointOfInterestHelper; import net.minecraft.entity.Entity; @@ -13,11 +13,9 @@ import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; import net.minecraft.sound.SoundEvents; -import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.random.Random; import net.minecraft.util.registry.Registry; -import net.minecraft.util.registry.RegistryKey; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOffers; import net.minecraft.village.VillagerProfession; @@ -28,61 +26,47 @@ public class SandwichMakerProfession { - private static final Identifier SANDWICH_MAKER_POI_ID = Util.id("sandwich_maker_poi"); - public static final PointOfInterestType SANDWICH_MAKER_POI = PointOfInterestHelper.register( - SANDWICH_MAKER_POI_ID, - 1, - 1, - BlocksRegistry.SANDWICH_TABLE - ); - - public static final VillagerProfession SANDWICH_MAKER = VillagerProfessionBuilder.create() - .id(Util.id("sandwich_maker")) - .workstation(RegistryKey.of(Registry.POINT_OF_INTEREST_TYPE_KEY, SANDWICH_MAKER_POI_ID)) - .workSound(SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM) - .build(); + public static PointOfInterestType SANDWICH_MAKER_POI; + public static VillagerProfession SANDWICH_MAKER; public static void init() { - Registry.register(Registry.VILLAGER_PROFESSION, Util.id("sandwich_maker"), SANDWICH_MAKER); - TradeOffers.PROFESSION_TO_LEVELED_TRADE.put( - SANDWICH_MAKER, Util.copyToFastUtilMap(ImmutableMap.of( - 1, - new TradeOffers.Factory[]{ - new TradeOffers.BuyForOneEmeraldFactory(Items.WHEAT, 20, 16, 2), - new TradeOffers.BuyForOneEmeraldFactory(Items.BREAD, 6, 12, 2), - new TradeOffers.BuyForOneEmeraldFactory(ItemsRegistry.TOMATO, 18, 16, 2), - new TradeOffers.BuyForOneEmeraldFactory(ItemsRegistry.LETTUCE_HEAD, 14, 16, 2), - new TradeOffers.SellItemFactory(ItemsRegistry.BREAD_SLICE, 1, 10, 16, 1) - }, - 2, - new TradeOffers.Factory[]{ - new SandwichMakerProfession.SellSandwichFactory(5, SellableSandwiches.APPLE.getItems(), 6, 7), - new TradeOffers.BuyForOneEmeraldFactory(Items.BUCKET, 1, 12, 5), - new TradeOffers.BuyForOneEmeraldFactory(Items.PORKCHOP, 18, 12, 3), - new TradeOffers.SellItemFactory(ItemsRegistry.CHEESE_SLICE_REGULAR, 2, 10, 4, 1), - }, - 3, - new TradeOffers.Factory[]{ - new SandwichMakerProfession.SellSandwichFactory(10, SellableSandwiches.BACON_LETTUCE_TOMATO.getItems(), 6, 8), - new SandwichMakerProfession.SellSandwichFactory(10, SellableSandwiches.CHICKEN_CHEESE.getItems(), 6, 8), - new TradeOffers.SellItemFactory(ItemsRegistry.TOASTED_BREAD_SLICE, 1, 7, 16, 1), - new TradeOffers.BuyForOneEmeraldFactory(Items.COOKED_BEEF, 14, 12, 5), - new TradeOffers.BuyForOneEmeraldFactory(Items.POTATO, 20, 12, 4) - }, - 4, - new TradeOffers.Factory[]{ - new SandwichMakerProfession.SellSandwichFactory(16, SellableSandwiches.MEAT_LOVERS.getItems(), 6, 12), - new SandwichMakerProfession.SellSandwichFactory(16, SellableSandwiches.VEGETABLE.getItems(), 6, 12), - new TradeOffers.SellItemFactory(Items.CHARCOAL, 1, 3, 12, 5), - new TradeOffers.BuyForOneEmeraldFactory(Items.CARROT, 20, 16, 5) - }, - 5, - new TradeOffers.Factory[]{ - new SandwichMakerProfession.SellSandwichFactory(25, SellableSandwiches.GOLDEN_APPLE.getItems(), 6, 17), - new SandwichMakerProfession.SellCheeseFactory(4, 12, 6), - } - )) - ); + SANDWICH_MAKER_POI = PointOfInterestHelper.register(Util.id("sandwich_maker_poi"), 1, 1, BlocksRegistry.SANDWICH_TABLE); + SANDWICH_MAKER = Registry.register(Registry.VILLAGER_PROFESSION, Util.id("sandwich_maker"), VillagerProfessionBuilder.create() + .id(Util.id("sandwich_maker")) + .workstation(holder -> holder.value().equals(SANDWICH_MAKER_POI)) + .jobSite(holder -> holder.value().equals(SANDWICH_MAKER_POI)) + .workSound(SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM) + .build()); + TradeOfferHelper.registerVillagerOffers(SANDWICH_MAKER, 1, factories -> { + factories.add(new TradeOffers.BuyForOneEmeraldFactory(Items.WHEAT, 20, 16, 2)); + factories.add(new TradeOffers.BuyForOneEmeraldFactory(Items.BREAD, 6, 12, 2)); + factories.add(new TradeOffers.BuyForOneEmeraldFactory(ItemsRegistry.TOMATO, 18, 16, 2)); + factories.add(new TradeOffers.BuyForOneEmeraldFactory(ItemsRegistry.LETTUCE_HEAD, 14, 16, 2)); + factories.add(new TradeOffers.SellItemFactory(ItemsRegistry.BREAD_SLICE, 1, 10, 16, 1)); + }); + TradeOfferHelper.registerVillagerOffers(SANDWICH_MAKER, 2, factories -> { + factories.add(new SandwichMakerProfession.SellSandwichFactory(5, SellableSandwiches.APPLE.getItems(), 6, 7)); + factories.add(new TradeOffers.BuyForOneEmeraldFactory(Items.BUCKET, 1, 12, 5)); + factories.add(new TradeOffers.BuyForOneEmeraldFactory(Items.PORKCHOP, 18, 12, 3)); + factories.add(new TradeOffers.SellItemFactory(ItemsRegistry.CHEESE_SLICE_REGULAR, 2, 10, 4, 1)); + }); + TradeOfferHelper.registerVillagerOffers(SANDWICH_MAKER, 3, factories -> { + factories.add(new SandwichMakerProfession.SellSandwichFactory(10, SellableSandwiches.BACON_LETTUCE_TOMATO.getItems(), 6, 8)); + factories.add(new SandwichMakerProfession.SellSandwichFactory(10, SellableSandwiches.CHICKEN_CHEESE.getItems(), 6, 8)); + factories.add(new TradeOffers.SellItemFactory(ItemsRegistry.TOASTED_BREAD_SLICE, 1, 7, 16, 1)); + factories.add(new TradeOffers.BuyForOneEmeraldFactory(Items.COOKED_BEEF, 14, 12, 5)); + factories.add(new TradeOffers.BuyForOneEmeraldFactory(Items.POTATO, 20, 12, 4)); + }); + TradeOfferHelper.registerVillagerOffers(SANDWICH_MAKER, 4, factories -> { + factories.add(new SandwichMakerProfession.SellSandwichFactory(16, SellableSandwiches.MEAT_LOVERS.getItems(), 6, 12)); + factories.add(new SandwichMakerProfession.SellSandwichFactory(16, SellableSandwiches.VEGETABLE.getItems(), 6, 12)); + factories.add(new TradeOffers.SellItemFactory(Items.CHARCOAL, 1, 3, 12, 5)); + factories.add(new TradeOffers.BuyForOneEmeraldFactory(Items.CARROT, 20, 16, 5)); + }); + TradeOfferHelper.registerVillagerOffers(SANDWICH_MAKER, 5, factories -> { + factories.add(new SandwichMakerProfession.SellSandwichFactory(25, SellableSandwiches.GOLDEN_APPLE.getItems(), 6, 17)); + factories.add(new SandwichMakerProfession.SellCheeseFactory(4, 12, 6)); + }); } public static class SellCheeseFactory implements TradeOffers.Factory { @@ -135,7 +119,7 @@ public enum SellableSandwiches { VEGETABLE(new Item[]{Items.BREAD, ItemsRegistry.LETTUCE_LEAF, Items.CARROT, Items.BEETROOT, Items.BAKED_POTATO, ItemsRegistry.TOMATO_SLICE, Items.BREAD}), GOLDEN_APPLE(new Item[]{Items.BREAD, Items.GOLDEN_APPLE, Items.BREAD}); - Item[] items; + final Item[] items; SellableSandwiches(Item[] items) { this.items = items; diff --git a/src/main/resources/data/sandwichable/loot_tables/inject/chests/ancient_city.json b/src/main/resources/data/sandwichable/loot_tables/inject/chests/ancient_city.json new file mode 100644 index 0000000..d4c705d --- /dev/null +++ b/src/main/resources/data/sandwichable/loot_tables/inject/chests/ancient_city.json @@ -0,0 +1,27 @@ +{ + "pools": [ + { + "rolls": { + "min": 1.0, + "max": 2.0, + "type": "minecraft:uniform" + }, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 1.0, + "max": 3.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:ancient_grain_seeds" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_plains_house.json b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_plains_house.json new file mode 100644 index 0000000..c01dad3 --- /dev/null +++ b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_plains_house.json @@ -0,0 +1,41 @@ +{ + "pools": [ + { + "rolls": { + "min": 0.0, + "max": 2.0, + "type": "minecraft:uniform" + }, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 1.0, + "max": 3.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:onion_seeds" + }, + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 1.0, + "max": 3.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:tomato_seeds" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_savanna_house.json b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_savanna_house.json new file mode 100644 index 0000000..711d857 --- /dev/null +++ b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_savanna_house.json @@ -0,0 +1,41 @@ +{ + "pools": [ + { + "rolls": { + "min": 0.0, + "max": 2.0, + "type": "minecraft:uniform" + }, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 1.0, + "max": 3.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:tomato_seeds" + }, + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 2.0, + "max": 4.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:lettuce_seeds" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_snowy_house.json b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_snowy_house.json new file mode 100644 index 0000000..6b54adf --- /dev/null +++ b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_snowy_house.json @@ -0,0 +1,41 @@ +{ + "pools": [ + { + "rolls": { + "min": 0.0, + "max": 2.0, + "type": "minecraft:uniform" + }, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 1.0, + "max": 3.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:lettuce_seeds" + }, + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 2.0, + "max": 4.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:cucumber_seeds" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_taiga_house.json b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_taiga_house.json new file mode 100644 index 0000000..393982a --- /dev/null +++ b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/village_taiga_house.json @@ -0,0 +1,41 @@ +{ + "pools": [ + { + "rolls": { + "min": 0.0, + "max": 2.0, + "type": "minecraft:uniform" + }, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 1.0, + "max": 3.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:cucumber_seeds" + }, + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 2.0, + "max": 4.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:onion_seeds" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/villager_desert_house.json b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/villager_desert_house.json new file mode 100644 index 0000000..99b64d6 --- /dev/null +++ b/src/main/resources/data/sandwichable/loot_tables/inject/chests/village/villager_desert_house.json @@ -0,0 +1,41 @@ +{ + "pools": [ + { + "rolls": { + "min": 0.0, + "max": 2.0, + "type": "minecraft:uniform" + }, + "entries": [ + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 1.0, + "max": 3.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:lettuce_seeds" + }, + { + "type": "minecraft:item", + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "min": 2.0, + "max": 4.0, + "type": "minecraft:uniform" + } + } + ], + "name": "sandwichable:tomato_seeds" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/sandwichable.mixins.json b/src/main/resources/sandwichable.mixins.json index 01d8b58..bdc72ef 100644 --- a/src/main/resources/sandwichable.mixins.json +++ b/src/main/resources/sandwichable.mixins.json @@ -14,8 +14,7 @@ "PistonBlockMixin", "ServerPlayerEntityScreenHandlerListenerMixin", "ServerPlayerInteractionManagerMixin", - "StructurePoolAccess", - "StructurePoolsMixin", + "StructurePoolAccessor", "VillagerEntityMixin", "VillagerProfessionMixin" ],