2024-01-18 20:52:59 +01:00
|
|
|
package com.minelittlepony.unicopia.block;
|
|
|
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2024-10-03 16:35:28 +02:00
|
|
|
import com.minelittlepony.unicopia.util.serialization.CodecUtils;
|
2024-02-02 23:35:42 +01:00
|
|
|
import com.mojang.serialization.Codec;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
|
|
|
|
|
|
import net.minecraft.block.BedBlock;
|
2024-01-18 20:52:59 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2024-02-02 23:35:42 +01:00
|
|
|
import net.minecraft.registry.Registries;
|
2024-01-18 20:52:59 +01:00
|
|
|
import net.minecraft.util.math.random.Random;
|
|
|
|
|
|
|
|
public class GoldenOakLeavesBlock extends FruitBearingBlock {
|
2024-02-02 23:35:42 +01:00
|
|
|
private static final MapCodec<GoldenOakLeavesBlock> CODEC = RecordCodecBuilder.<GoldenOakLeavesBlock>mapCodec(instance -> instance.group(
|
|
|
|
Codec.INT.fieldOf("overlay").forGetter(b -> b.overlay),
|
|
|
|
CodecUtils.supplierOf(Registries.BLOCK.getCodec()).fieldOf("fruit").forGetter(b -> b.fruit),
|
|
|
|
CodecUtils.supplierOf(ItemStack.CODEC).fieldOf("rotten_fruit").forGetter(b -> b.rottenFruitSupplier),
|
|
|
|
BedBlock.createSettingsCodec()
|
|
|
|
).apply(instance, GoldenOakLeavesBlock::new));
|
|
|
|
|
|
|
|
public GoldenOakLeavesBlock(int overlay, Supplier<Block> fruit, Supplier<ItemStack> rottenFruitSupplier, Settings settings) {
|
|
|
|
super(overlay, fruit, rottenFruitSupplier, settings);
|
|
|
|
}
|
2024-01-18 20:52:59 +01:00
|
|
|
|
2024-02-02 23:35:42 +01:00
|
|
|
@Override
|
|
|
|
public MapCodec<? extends GoldenOakLeavesBlock> getCodec() {
|
|
|
|
return CODEC;
|
2024-01-18 20:52:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean shouldAdvance(Random random) {
|
|
|
|
return random.nextInt(1000) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-10 19:16:15 +01:00
|
|
|
public BlockState getPlacedFruitState(Random random) {
|
2024-01-18 20:52:59 +01:00
|
|
|
return super.getPlacedFruitState(random).with(EnchantedFruitBlock.ENCHANTED, random.nextInt(1000) == 0);
|
|
|
|
}
|
|
|
|
}
|