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