2018-10-15 18:36:46 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.Helper;
|
2018-11-11 17:09:26 +01:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2018-10-15 18:36:46 +02:00
|
|
|
import de.ellpeck.naturesaura.reg.*;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.LeavesBlock;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.material.MaterialColor;
|
2018-10-15 18:36:46 +02:00
|
|
|
import net.minecraft.client.renderer.color.IBlockColor;
|
|
|
|
import net.minecraft.client.renderer.color.IItemColor;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.state.IntegerProperty;
|
|
|
|
import net.minecraft.state.StateContainer;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.util.Direction;
|
2018-10-15 18:36:46 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.world.biome.BiomeColors;
|
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-10-15 18:36:46 +02:00
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
public class BlockGoldenLeaves extends LeavesBlock implements
|
2018-10-15 18:36:46 +02:00
|
|
|
IModItem, IModelProvider, IColorProvidingBlock, IColorProvidingItem {
|
|
|
|
|
|
|
|
private static final int HIGHEST_STAGE = 3;
|
2019-11-04 19:08:49 +01:00
|
|
|
private static final IntegerProperty STAGE = IntegerProperty.create("stage", 0, HIGHEST_STAGE);
|
2018-10-15 18:36:46 +02:00
|
|
|
|
|
|
|
public BlockGoldenLeaves() {
|
2019-11-04 19:08:49 +01:00
|
|
|
super(ModBlocks.prop(Material.LEAVES, MaterialColor.GOLD));
|
2018-11-29 17:58:47 +01:00
|
|
|
ModRegistry.add(this);
|
2018-10-15 18:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return "golden_leaves";
|
|
|
|
}
|
|
|
|
|
2018-11-11 17:09:26 +01:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-11-04 19:08:49 +01:00
|
|
|
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
|
|
|
if (stateIn.get(STAGE) == HIGHEST_STAGE && rand.nextFloat() >= 0.75F)
|
2018-11-13 00:36:47 +01:00
|
|
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
2018-11-11 17:09:26 +01:00
|
|
|
pos.getX() + rand.nextFloat(),
|
|
|
|
pos.getY() + rand.nextFloat(),
|
|
|
|
pos.getZ() + rand.nextFloat(),
|
|
|
|
0F, 0F, 0F,
|
|
|
|
0xF2FF00, 0.5F + rand.nextFloat(), 50, 0F, false, true);
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
/* Replaced by json loot tables
|
2018-10-15 18:36:46 +02:00
|
|
|
@Override
|
|
|
|
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
|
|
|
|
NonNullList<ItemStack> drops = NonNullList.create();
|
|
|
|
this.getDrops(drops, world, pos, world.getBlockState(pos), fortune);
|
|
|
|
return drops;
|
|
|
|
}
|
2019-11-04 19:08:49 +01:00
|
|
|
*/
|
2018-10-15 18:36:46 +02:00
|
|
|
|
|
|
|
@Override
|
2019-11-04 19:08:49 +01:00
|
|
|
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
|
|
|
super.fillStateContainer(builder);
|
|
|
|
builder.add(STAGE);
|
2018-10-15 18:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-10-15 18:36:46 +02:00
|
|
|
public IBlockColor getBlockColor() {
|
|
|
|
return (state, worldIn, pos, tintIndex) -> {
|
|
|
|
int color = 0xF2FF00;
|
|
|
|
if (state != null && worldIn != null && pos != null) {
|
2019-11-04 19:08:49 +01:00
|
|
|
int foliage = BiomeColors.getFoliageColor(worldIn, pos);
|
|
|
|
return Helper.blendColors(color, foliage, state.get(STAGE) / (float) HIGHEST_STAGE);
|
2018-10-15 18:36:46 +02:00
|
|
|
} else {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-10-15 18:36:46 +02:00
|
|
|
public IItemColor getItemColor() {
|
|
|
|
return (stack, tintIndex) -> 0xF2FF00;
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
/* Replaced by json loot tables
|
2018-10-15 18:36:46 +02:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, BlockState state, int fortune) {
|
2018-10-15 18:36:46 +02:00
|
|
|
Random rand = world instanceof World ? ((World) world).rand : RANDOM;
|
|
|
|
if (state.getValue(STAGE) < HIGHEST_STAGE) {
|
|
|
|
if (rand.nextFloat() >= 0.75F) {
|
|
|
|
drops.add(new ItemStack(ModItems.GOLD_FIBER));
|
|
|
|
}
|
|
|
|
} else if (rand.nextFloat() >= 0.25F) {
|
|
|
|
drops.add(new ItemStack(ModItems.GOLD_LEAF));
|
|
|
|
}
|
|
|
|
}
|
2019-11-04 19:08:49 +01:00
|
|
|
*/
|
|
|
|
|
2018-10-15 18:36:46 +02:00
|
|
|
|
|
|
|
@Override
|
2019-11-04 19:08:49 +01:00
|
|
|
public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
|
|
|
|
super.tick(state, worldIn, pos, random);
|
2018-10-15 18:36:46 +02:00
|
|
|
if (!worldIn.isRemote) {
|
2019-11-04 19:08:49 +01:00
|
|
|
int stage = state.get(STAGE);
|
2018-10-15 18:36:46 +02:00
|
|
|
if (stage < HIGHEST_STAGE) {
|
2019-11-04 19:08:49 +01:00
|
|
|
worldIn.setBlockState(pos, state.with(STAGE, stage + 1));
|
2018-10-15 18:36:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stage > 1) {
|
2019-11-04 19:08:49 +01:00
|
|
|
BlockPos offset = pos.offset(Direction.random(random));
|
2018-11-13 17:13:27 +01:00
|
|
|
if (worldIn.isBlockLoaded(offset))
|
|
|
|
convert(worldIn, offset);
|
2018-10-15 18:36:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean convert(World world, BlockPos pos) {
|
2019-10-20 22:30:49 +02:00
|
|
|
BlockState state = world.getBlockState(pos);
|
2019-11-04 19:08:49 +01:00
|
|
|
if (state.getBlock().isFoliage(state, world, pos) &&
|
2018-11-08 12:24:21 +01:00
|
|
|
!(state.getBlock() instanceof BlockAncientLeaves || state.getBlock() instanceof BlockGoldenLeaves)) {
|
2018-10-15 18:36:46 +02:00
|
|
|
if (!world.isRemote) {
|
|
|
|
world.setBlockState(pos, ModBlocks.GOLDEN_LEAVES.getDefaultState()
|
2019-11-04 19:08:49 +01:00
|
|
|
.with(DISTANCE, state.has(DISTANCE) ? state.get(DISTANCE) : 1)
|
|
|
|
.with(PERSISTENT, state.has(PERSISTENT) ? state.get(PERSISTENT) : false));
|
2018-10-15 18:36:46 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|