mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-07 22:16:44 +01:00
Add a rarity factor in to tree drops
This commit is contained in:
parent
9314e144e0
commit
a01466cf01
12 changed files with 30 additions and 11 deletions
|
@ -236,7 +236,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
|
|||
BlockState below = world.getBlockState(down);
|
||||
|
||||
if (below.isAir()) {
|
||||
return Stream.of(tree.pickRandomStack(treeState));
|
||||
return Stream.of(tree.pickRandomStack(world.random, treeState));
|
||||
}
|
||||
|
||||
return Stream.empty();
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface TreeType {
|
||||
|
@ -21,7 +22,8 @@ public interface TreeType {
|
|||
false,
|
||||
Set.of(),
|
||||
Set.of(),
|
||||
Weighted.of()
|
||||
Weighted.of(),
|
||||
0
|
||||
);
|
||||
Direction[] WIDE_DIRS = new Direction[] { Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST };
|
||||
|
||||
|
@ -158,7 +160,7 @@ public interface TreeType {
|
|||
return isLeaves(state) || isLog(state);
|
||||
}
|
||||
|
||||
ItemStack pickRandomStack(BlockState state);
|
||||
ItemStack pickRandomStack(Random random, BlockState state);
|
||||
|
||||
boolean isWide();
|
||||
|
||||
|
@ -186,8 +188,8 @@ public interface TreeType {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack pickRandomStack(BlockState state) {
|
||||
return (isLeaves(state) ? leaves : logs).pickRandomStack(state);
|
||||
public ItemStack pickRandomStack(Random random, BlockState state) {
|
||||
return (isLeaves(state) ? leaves : logs).pickRandomStack(random, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.block.LeavesBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public record TreeTypeImpl (
|
||||
|
@ -15,7 +16,8 @@ public record TreeTypeImpl (
|
|||
boolean wideTrunk,
|
||||
Set<Identifier> logs,
|
||||
Set<Identifier> leaves,
|
||||
Supplier<Optional<Supplier<ItemStack>>> pool
|
||||
Supplier<Optional<Supplier<ItemStack>>> pool,
|
||||
int rarity
|
||||
) implements TreeType {
|
||||
@Override
|
||||
public boolean isLeaves(BlockState state) {
|
||||
|
@ -33,8 +35,11 @@ public record TreeTypeImpl (
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack pickRandomStack(BlockState state) {
|
||||
return pool.get().map(Supplier::get).orElse(ItemStack.EMPTY);
|
||||
public ItemStack pickRandomStack(Random random, BlockState state) {
|
||||
if (rarity <= 0 || random.nextInt(rarity) == 0) {
|
||||
return pool.get().map(Supplier::get).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private static boolean findMatch(Set<Identifier> ids, BlockState state) {
|
||||
|
|
|
@ -57,12 +57,14 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour
|
|||
final Set<Identifier> leaves;
|
||||
final Set<Drop> drops;
|
||||
final boolean wideTrunk;
|
||||
final int rarity;
|
||||
|
||||
public TreeTypeDef(PacketByteBuf buffer) {
|
||||
logs = new HashSet<>(buffer.readList(PacketByteBuf::readIdentifier));
|
||||
leaves = new HashSet<>(buffer.readList(PacketByteBuf::readIdentifier));
|
||||
drops = new HashSet<>(buffer.readList(Drop::new));
|
||||
wideTrunk = buffer.readBoolean();
|
||||
rarity = buffer.readInt();
|
||||
}
|
||||
|
||||
public TreeType toTreeType(Identifier id) {
|
||||
|
@ -71,7 +73,8 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour
|
|||
wideTrunk,
|
||||
Objects.requireNonNull(logs, "TreeType must have logs"),
|
||||
Objects.requireNonNull(leaves, "TreeType must have leaves"),
|
||||
Weighted.of(weighted -> drops.forEach(drop -> drop.appendDrop(weighted)))
|
||||
Weighted.of(weighted -> drops.forEach(drop -> drop.appendDrop(weighted))),
|
||||
rarity
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -80,6 +83,7 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour
|
|||
buffer.writeCollection(leaves, PacketByteBuf::writeIdentifier);
|
||||
buffer.writeCollection(drops, (a, b) -> b.write(a));
|
||||
buffer.writeBoolean(wideTrunk);
|
||||
buffer.writeInt(rarity);
|
||||
}
|
||||
|
||||
static class Drop {
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.tag.BlockTags;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TreeTypes {
|
||||
|
@ -62,12 +63,12 @@ public class TreeTypes {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack pickRandomStack(BlockState state) {
|
||||
public ItemStack pickRandomStack(Random random, BlockState state) {
|
||||
TreeType type = get(state);
|
||||
if (type == TreeType.NONE) {
|
||||
type = get(Blocks.OAK_LOG.getDefaultState());
|
||||
}
|
||||
return type.pickRandomStack(state);
|
||||
return type.pickRandomStack(random, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"logs": [ "minecraft:acacia_log", "minecraft:acacia_wood" ],
|
||||
"leaves": [ "minecraft:acacia_leaves" ],
|
||||
"rarity": 5,
|
||||
"drops": [
|
||||
{ "weight": 1, "item": "unicopia:rotten_apple" },
|
||||
{ "weight": 2, "item": "unicopia:sweet_apple" },
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"logs": [ "minecraft:oak_log", "minecraft:oak_wood" ],
|
||||
"leaves": [ "minecraft:azalea_leaves", "minecraft:flowering_azalea_leaves" ],
|
||||
"rarity": 5,
|
||||
"drops": [
|
||||
{ "weight": 1, "item": "unicopia:sour_apple" },
|
||||
{ "weight": 2, "item": "unicopia:green_apple" },
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"logs": [ "minecraft:birch_log", "minecraft:birch_wood" ],
|
||||
"leaves": [ "minecraft:birch_leaves" ],
|
||||
"rarity": 5,
|
||||
"drops": [
|
||||
{ "weight": 1, "item": "unicopia:rotten_apple" },
|
||||
{ "weight": 2, "item": "unicopia:sweet_apple" },
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"logs": [ "minecraft:dark_oak_log", "minecraft:dark_oak_wood" ],
|
||||
"leaves": [ "minecraft:dark_oak_leaves" ],
|
||||
"wideTrunk": true,
|
||||
"rarity": 5,
|
||||
"drops": [
|
||||
{ "weight": 1, "item": "unicopia:rotten_apple" },
|
||||
{ "weight": 2, "item": "unicopia:sweet_apple" },
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"logs": [ "minecraft:jungle_log", "minecraft:jungle_wood" ],
|
||||
"leaves": [ "minecraft:jungle_leaves" ],
|
||||
"wideTrunk": true,
|
||||
"rarity": 5,
|
||||
"drops": [
|
||||
{ "weight": 5, "item": "unicopia:green_apple" },
|
||||
{ "weight": 2, "item": "unicopia:sweet_apple" },
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"logs": [ "minecraft:oak_log", "minecraft:oak_wood" ],
|
||||
"leaves": [ "minecraft:oak_leaves" ],
|
||||
"rarity": 3,
|
||||
"drops": [
|
||||
{ "weight": 1, "item": "unicopia:rotten_apple" },
|
||||
{ "weight": 2, "item": "unicopia:acorn" },
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"logs": [ "minecraft:spruce_log", "minecraft:spruce_wood" ],
|
||||
"leaves": [ "minecraft:spruce_leaves" ],
|
||||
"wideTrunk": true,
|
||||
"rarity": 3,
|
||||
"drops": [
|
||||
{ "weight": 1, "item": "unicopia:pinecone" },
|
||||
{ "weight": 4, "item": "unicopia:stick" }
|
||||
|
|
Loading…
Reference in a new issue