Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Experiments #155

Draft
wants to merge 7 commits into
base: 1.19
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@
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;
import io.github.foundationgames.sandwichable.villager.SandwichMakerProfession;
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;
Expand All @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -173,16 +173,37 @@ public void onInitialize() {
return ActionResult.PASS;
});

ServerLifecycleEvents.SERVER_STARTING.register(SandwichableStructures::addStructures);

Set<Identifier> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Pair<StructurePoolElement, Integer>> getElementCounts();

@Mutable
@Accessor
void setElementCounts(List<Pair<StructurePoolElement, Integer>> elementCounts);

@Accessor
ObjectArrayList<StructurePoolElement> getElements();

@Mutable
@Accessor
void setElements(ObjectArrayList<StructurePoolElement> elements);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<StructurePool> poolGetter = server.getRegistryManager().get(Registry.STRUCTURE_POOL_KEY).getOrEmpty(poolId);

if (poolGetter.isEmpty()) {
return;
}
StructurePool pool = poolGetter.get();

Optional<RegistryEntry<StructureProcessorList>> processorList = server.getRegistryManager().get(Registry.STRUCTURE_PROCESSOR_LIST_KEY).getEntry(RegistryKey.of(Registry.STRUCTURE_PROCESSOR_LIST_KEY, processor));

List<StructurePoolElement> 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<Pair<StructurePoolElement, Integer>> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -69,16 +62,6 @@ public static Int2ObjectMap<TradeOffers.Factory[]> 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();
}
Expand Down
Loading