Skip to content

Commit

Permalink
added data-driven villager trades
Browse files Browse the repository at this point in the history
  • Loading branch information
finallion committed Aug 16, 2023
1 parent 5b0c651 commit 46e3156
Show file tree
Hide file tree
Showing 54 changed files with 3,094 additions and 606 deletions.
10 changes: 4 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ version = project.mod_version
group = project.maven_group

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/releases/" }
}

dependencies {
Expand All @@ -27,7 +24,8 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.config_version}")
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ org.gradle.parallel=true
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.10
fabric_version=0.67.0+1.19.2

# Mod Properties
mod_version = 1.0.0
maven_group = com.example
archives_base_name = fabric-example-mod
config_version=8.3.103


# Dependencies
fabric_version=0.67.0+1.19.2
22 changes: 18 additions & 4 deletions src/main/java/com/finallion/villagersplus/VillagersPlus.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package com.finallion.villagersplus;

import com.finallion.villagersplus.config.VPConfig;
import com.finallion.villagersplus.init.*;
import com.finallion.villagersplus.tradeoffers.DefaultTradeOfferResourceListener;
import com.finallion.villagersplus.tradeoffers.TradeOfferManager;
import com.finallion.villagersplus.tradeoffers.TradeOfferResourceListener;
import com.finallion.villagersplus.villagers.ModPointOfInterestType;
import com.finallion.villagersplus.villagers.ModProfessions;
import com.finallion.villagersplus.villagers.ModTrades;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
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.screenhandler.v1.ScreenHandlerRegistry;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VillagersPlus implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("villagersplus");
public static final String MOD_ID = "villagersplus";
public static VPConfig CONFIG = new VPConfig();

public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.create(new Identifier(MOD_ID, "group"))
.icon(() -> new ItemStack(ModBlocks.OAK_HORTICULTURIST_TABLE_BLOCK))
Expand All @@ -26,13 +32,21 @@ public class VillagersPlus implements ModInitializer {

@Override
public void onInitialize() {
AutoConfig.register(VPConfig.class, JanksonConfigSerializer::new);
CONFIG = AutoConfig.getConfigHolder(VPConfig.class).getConfig();


ModTags.init();
ModScreen.init();
ModParticles.init();
ModBlocks.registerBlocks();
ModPointOfInterestType.registerPOIs();
ModProfessions.registerProfessions();
ModTrades.registerTradeOffers();

TradeOfferManager.registerTradeOffers();
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new DefaultTradeOfferResourceListener());
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new TradeOfferResourceListener());


ServerLifecycleEvents.SERVER_STARTING.register(ModStructures::registerJigsaws);

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.finallion.villagersplus.blockentities;

import com.finallion.villagersplus.VillagersPlus;
import com.finallion.villagersplus.blocks.OccultistTableBlock;
import com.finallion.villagersplus.init.ModBlocks;
import net.minecraft.block.BlockState;
Expand All @@ -24,8 +25,8 @@

public class OccultistTableBlockEntity extends BlockEntity {
private int levels = 0;
private final int MAX_EXP_STORAGE = 500;
private final int AMOUNT = 50;
private final int MAX_EXP_STORAGE = VillagersPlus.CONFIG.max_exp_amount;
private final int AMOUNT = VillagersPlus.CONFIG.exp_amount;

public OccultistTableBlockEntity(BlockPos pos, BlockState state) {
super(ModBlocks.OCCULTIST_TABLE_BLOCK_ENTITY, pos, state);
Expand Down Expand Up @@ -62,7 +63,6 @@ public void interact(World world, PlayerEntity player) {
player.addExperience(levels);
this.levels = 0;
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
package com.finallion.villagersplus.blocks;

import com.finallion.villagersplus.blockentities.AlchemistTableBlockEntity;
import com.finallion.villagersplus.blockentities.HorticulturistTableBlockEntity;
import com.finallion.villagersplus.blockentities.OccultistTableBlockEntity;
import com.finallion.villagersplus.init.ModTags;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.tag.BlockTags;
import net.minecraft.tag.ItemTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.intprovider.ConstantIntProvider;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
Expand Down Expand Up @@ -53,7 +43,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
ItemStack itemStack = player.getStackInHand(hand);

if (world.getBlockEntity(pos) instanceof HorticulturistTableBlockEntity blockEntity && state.get(FLOWERS) < 4) {
if (itemStack.isIn(ModTags.TALL_PLANTABLE_BLOCKS) && state.get(FLOWERS) == 0) {
if (itemStack.isIn(ModTags.TALL_PLANTABLE_ITEMS) && state.get(FLOWERS) == 0) {
blockEntity.insertFlower(itemStack, state.get(FLOWERS));

if (!player.isCreative()) {
Expand All @@ -64,8 +54,12 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, pos);
}

if (world.isClient) {
world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ITEM_CROP_PLANT, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}

return ActionResult.success(world.isClient);
} else if (itemStack.isIn(ModTags.SMALL_PLANTABLE_BLOCKS)) {
} else if (itemStack.isIn(ModTags.SMALL_PLANTABLE_ITEMS)) {
blockEntity.insertFlower(itemStack, state.get(FLOWERS));

if (!player.isCreative()) {
Expand All @@ -75,6 +69,10 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
world.setBlockState(pos, state.with(FLOWERS, state.get(FLOWERS) + 1).with(IS_TALL_FLOWER, false), 3);
world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, pos);
}

if (world.isClient) {
world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ITEM_CROP_PLANT, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}
return ActionResult.success(world.isClient);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
package com.finallion.villagersplus.blocks;

import com.finallion.villagersplus.blockentities.AlchemistTableBlockEntity;
import com.finallion.villagersplus.VillagersPlus;
import com.finallion.villagersplus.blockentities.OccultistTableBlockEntity;
import com.finallion.villagersplus.init.ModBlocks;
import com.finallion.villagersplus.init.ModParticles;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.*;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.intprovider.ConstantIntProvider;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class OccultistTableBlock extends WorkstationBlock {
public static final IntProperty FILLING;
Expand Down Expand Up @@ -70,15 +57,18 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}

if (!world.isClient()) {
if (tile.getLevels() >= 400) {
int levels = tile.getLevels();
int maxLevels = VillagersPlus.CONFIG.max_exp_amount;

if (levels >= 0.8 * maxLevels) {
state = state.with(OccultistTableBlock.FILLING, 5);
} else if (tile.getLevels() >= 300) {
} else if (levels >= 0.6 * maxLevels) {
state = state.with(OccultistTableBlock.FILLING, 4);
} else if (tile.getLevels() >= 200) {
} else if (levels >= 0.4 * maxLevels) {
state = state.with(OccultistTableBlock.FILLING, 3);
} else if (tile.getLevels() >= 100) {
} else if (levels >= 0.2 * maxLevels) {
state = state.with(OccultistTableBlock.FILLING, 2);
} else if (tile.getLevels() > 0) {
} else if (levels > 0) {
state = state.with(OccultistTableBlock.FILLING, 1);
} else {
state = state.with(OccultistTableBlock.FILLING, 0);
Expand All @@ -97,6 +87,8 @@ public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
return true;
}



public static <T extends ParticleEffect> void createParticleSpiral(World world, double x, double y, double z, double velocityX, double velocityY, double velocityZ, int length, T type, Random random) {
double yCoord = y + 1.1D; // top of block

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package com.finallion.villagersplus.blocks;

import com.finallion.villagersplus.blockentities.HorticulturistTableBlockEntity;
import com.finallion.villagersplus.blockentities.OceanographerTableBlockEntity;
import com.finallion.villagersplus.init.ModParticles;
import com.finallion.villagersplus.init.ModTags;
import com.finallion.villagersplus.util.DuckBucketable;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Bucketable;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.EntityBucketItem;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
Expand All @@ -26,8 +20,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;

Expand Down Expand Up @@ -63,7 +55,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
ItemStack itemStack = player.getStackInHand(hand);

if (world.getBlockEntity(pos) instanceof OceanographerTableBlockEntity blockEntity) {
if (itemStack.isIn(ModTags.AQUARIUM_PLANTABLE_BLOCKS) && state.get(CORALS) < 4) {
if (itemStack.isIn(ModTags.AQUARIUM_PLANTABLE_ITEMS) && state.get(CORALS) < 4) {
blockEntity.insertCoral(itemStack, state.get(CORALS));

if (!player.isCreative()) {
Expand All @@ -75,6 +67,10 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, pos);
}

if (world.isClient) {
world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_CORAL_BLOCK_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}

return ActionResult.success(world.isClient);
} else if (itemStack.getItem() instanceof EntityBucketItem bucketItem && state.get(FISH) < 1) {
blockEntity.insertCoral(itemStack, 4);
Expand All @@ -88,6 +84,8 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, pos);
}

if (world.isClient) player.playSound(SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);

return ActionResult.success(world.isClient);
}
}
Expand Down
Loading

0 comments on commit 46e3156

Please sign in to comment.