Skip to content

Commit

Permalink
Fungal forest villager type
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-makes-code committed Sep 13, 2024
1 parent 25167f4 commit e3ada2e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import dev.sweetberry.wwizardry.content.net.NetworkingInitializer;
import dev.sweetberry.wwizardry.content.recipe.RecipeInitializer;
import dev.sweetberry.wwizardry.content.sounds.SoundInitializer;
import dev.sweetberry.wwizardry.content.villager.VillagerInitializer;
import dev.sweetberry.wwizardry.content.world.WorldgenInitializer;
import net.minecraft.advancements.CriterionTrigger;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.RecipeSerializer;
Expand Down Expand Up @@ -49,5 +51,6 @@ public static void listenToAll(RegistryCallback<?> listener) {
SoundInitializer.SOUNDS.listen((RegistryCallback<SoundEvent>) listener);
EntityInitializer.ENTITIES.listen((RegistryCallback<EntityType<?>>) listener);
MapInitializer.MAP_DECORATION_TYPE.listen((RegistryCallback<MapDecorationType>) listener);
VillagerInitializer.VILLAGER_TYPES.listen((RegistryCallback<VillagerType>) listener);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package dev.sweetberry.wwizardry.content.trades;
package dev.sweetberry.wwizardry.content.villager;

import dev.sweetberry.wwizardry.WanderingWizardry;
import dev.sweetberry.wwizardry.api.Lazy;
import dev.sweetberry.wwizardry.api.registry.RegistryContext;
import dev.sweetberry.wwizardry.content.datagen.DatagenInitializer;
import dev.sweetberry.wwizardry.content.item.ItemInitializer;
import dev.sweetberry.wwizardry.content.map.MapInitializer;
import dev.sweetberry.wwizardry.content.world.WorldgenInitializer;
import dev.sweetberry.wwizardry.mixin.Accessor_VillagerType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.StructureTags;
import net.minecraft.tags.TagKey;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Expand All @@ -31,12 +33,12 @@
import java.util.Optional;
import java.util.function.Supplier;

public class TradeInitializer {
public class VillagerInitializer {
public static final RegistryContext<VillagerType> VILLAGER_TYPES = new RegistryContext<>(BuiltInRegistries.VILLAGER_TYPE);

public static final Lazy<VillagerType> FUNGAL_FOREST_VILLAGER = registerType("fungal_forest", () -> new VillagerType("fungal_forest"));

public static final TagKey<Structure> ON_LAB_EXPLORER_MAPS = TagKey.create(Registries.STRUCTURE, WanderingWizardry.id("on_lab_explorer_maps"));
void a() {
// cost, destination, displayName, destinationType, maxUsage, villagerXp
new VillagerTrades.TreasureMapForEmeralds(13, ON_LAB_EXPLORER_MAPS, "filled_map.wwizardry.sculk_lab", MapInitializer.holder(MapInitializer.SCULK_LAB), 12, 5);
}

public static final VillagerTrades.ItemListing[][] WANDERING_TRADER_OFFERS = new VillagerTrades.ItemListing[][] {
{
Expand Down Expand Up @@ -73,6 +75,14 @@ void a() {
}
};

public static Lazy<VillagerType> registerType(String id, Supplier<VillagerType> type) {
return VILLAGER_TYPES.register(WanderingWizardry.id(id), type);
}

public static void addToBiomes() {
Accessor_VillagerType.getBY_BIOME().put(WorldgenInitializer.FUNGAL_FOREST, FUNGAL_FOREST_VILLAGER.get());
}

public static class TreasureMapForEmeralds implements VillagerTrades.ItemListing {
private final int emeraldCost;
private final TagKey<Structure> destination;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.sweetberry.wwizardry.mixin;

import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.biome.Biome;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Map;

@Mixin(VillagerType.class)
public interface Accessor_VillagerType {
@Accessor
static Map<ResourceKey<Biome>, VillagerType> getBY_BIOME() {
throw new IllegalCallerException("How?");
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ public net.minecraft.world.level.block.PressurePlateBlock <init>(Lnet/minecraft/
public net.minecraft.world.level.block.DoorBlock <init>(Lnet/minecraft/world/level/block/state/properties/BlockSetType;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
public net.minecraft.world.level.block.TrapDoorBlock <init>(Lnet/minecraft/world/level/block/state/properties/BlockSetType;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
public net.minecraft.world.level.block.SaplingBlock <init>(Lnet/minecraft/world/level/block/grower/TreeGrower;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
public net.minecraft.world.entity.npc.VillagerType <init>(Ljava/lang/String;)V
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions common/src/main/resources/wwizardry.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ accessible class net/minecraft/world/entity/npc/VillagerTrades$ItemsForEmeralds
accessible class net/minecraft/world/entity/npc/VillagerTrades$TreasureMapForEmeralds
accessible class net/minecraft/server/level/ServerPlayer$RespawnPosAngle


accessible method net/minecraft/world/level/block/StairBlock <init> (Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
accessible method net/minecraft/world/level/block/IronBarsBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
accessible method net/minecraft/world/level/block/TransparentBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
Expand All @@ -14,6 +15,7 @@ accessible method net/minecraft/world/level/block/PressurePlateBlock <init> (Lne
accessible method net/minecraft/world/level/block/DoorBlock <init> (Lnet/minecraft/world/level/block/state/properties/BlockSetType;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
accessible method net/minecraft/world/level/block/TrapDoorBlock <init> (Lnet/minecraft/world/level/block/state/properties/BlockSetType;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
accessible method net/minecraft/world/level/block/SaplingBlock <init> (Lnet/minecraft/world/level/block/grower/TreeGrower;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
accessible method net/minecraft/world/entity/npc/VillagerType <init> (Ljava/lang/String;)V

accessible method net/minecraft/world/level/block/entity/BlockEntity saveAdditional (Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/core/HolderLookup$Provider;)V
accessible method net/minecraft/world/level/block/entity/BlockEntity loadAdditional (Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/core/HolderLookup$Provider;)V
3 changes: 2 additions & 1 deletion common/src/main/resources/wwizardry.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"mixins": [
"Accessor_AxeItem",
"Accessor_BeaconBlockEntity",
"Accessor_BlockBehaviour",
"Accessor_BlockEntityType",
"Accessor_BlockSetType",
"Accessor_PlayerRespawnLogic",
"Accessor_PotionBrewing",
"Accessor_ServerPlayer",
"Accessor_StructureProcessor",
"Accessor_VillagerType",
"Accessor_WoodType",
"Accessor_BlockBehaviour",
"Mixin_BeaconBlockEntity",
"Mixin_Boat",
"Mixin_ChestBoat",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
package dev.sweetberry.wwizardry.fabric;

import dev.sweetberry.wwizardry.WanderingWizardry;
import dev.sweetberry.wwizardry.api.component.Component;
import dev.sweetberry.wwizardry.api.net.PacketRegistry;
import dev.sweetberry.wwizardry.client.content.events.ClientEvents;
import dev.sweetberry.wwizardry.content.ContentInitializer;
import dev.sweetberry.wwizardry.content.block.BlockInitializer;
import dev.sweetberry.wwizardry.content.component.ComponentInitializer;
import dev.sweetberry.wwizardry.content.events.UseBlockHandler;
import dev.sweetberry.wwizardry.content.net.packet.ComponentSyncPacket;
import dev.sweetberry.wwizardry.content.trades.TradeInitializer;
import dev.sweetberry.wwizardry.content.villager.VillagerInitializer;
import dev.sweetberry.wwizardry.content.world.WorldgenInitializer;
import dev.sweetberry.wwizardry.fabric.component.FabricComponents;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.fabricmc.fabric.api.biome.v1.ModificationPhase;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.networking.v1.EntityTrackingEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
import net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.renderer.blockentity.SignRenderer;
import net.minecraft.core.Registry;

import java.util.List;
Expand Down Expand Up @@ -76,12 +71,14 @@ public void onInitialize() {
OxidizableBlocksRegistry.registerWaxableBlockPair(waxable.getFirst().get(), waxable.getSecond().get());
for (var waxable : BlockInitializer.WEATHERABLES)
OxidizableBlocksRegistry.registerOxidizableBlockPair(waxable.getFirst().get(), waxable.getSecond().get());

VillagerInitializer.addToBiomes();
}

private static void addWanderingTradesFor(int level) {
TradeOfferHelper.registerWanderingTraderOffers(
level,
offers -> offers.addAll(List.of(TradeInitializer.WANDERING_TRADER_OFFERS[level-1]))
offers -> offers.addAll(List.of(VillagerInitializer.WANDERING_TRADER_OFFERS[level-1]))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import dev.sweetberry.wwizardry.client.WanderingWizardryClient;
import dev.sweetberry.wwizardry.client.content.events.ItemTooltipHandler;
import dev.sweetberry.wwizardry.content.events.UseBlockHandler;
import dev.sweetberry.wwizardry.content.trades.TradeInitializer;
import net.minecraft.client.renderer.entity.BoatRenderer;
import dev.sweetberry.wwizardry.content.villager.VillagerInitializer;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.block.TransparentBlock;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.RenderTooltipEvent;
Expand All @@ -28,8 +26,8 @@ public static void init() {

@SubscribeEvent
public static void onWanderingTrades(WandererTradesEvent ev) {
ev.getGenericTrades().addAll(Arrays.stream(TradeInitializer.WANDERING_TRADER_OFFERS[0]).toList());
ev.getRareTrades().addAll(Arrays.stream(TradeInitializer.WANDERING_TRADER_OFFERS[1]).toList());
ev.getGenericTrades().addAll(Arrays.stream(VillagerInitializer.WANDERING_TRADER_OFFERS[0]).toList());
ev.getRareTrades().addAll(Arrays.stream(VillagerInitializer.WANDERING_TRADER_OFFERS[1]).toList());
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.sweetberry.wwizardry.content.ContentInitializer;
import dev.sweetberry.wwizardry.content.block.BlockInitializer;
import dev.sweetberry.wwizardry.content.entity.EntityInitializer;
import dev.sweetberry.wwizardry.content.villager.VillagerInitializer;
import dev.sweetberry.wwizardry.neoforge.component.NeoForgeComponents;
import dev.sweetberry.wwizardry.neoforge.networking.NeoForgeNetworking;
import net.minecraft.client.renderer.item.ItemProperties;
Expand Down Expand Up @@ -72,6 +73,7 @@ public void registerToRegistries(RegisterEvent event) {
}));

BlockInitializer.registerSecondaryBlockFunctions();
VillagerInitializer.addToBiomes();
}

@SubscribeEvent
Expand Down

0 comments on commit e3ada2e

Please sign in to comment.