ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCrystalCluster.java

139 lines
4.6 KiB
Java

package de.ellpeck.actuallyadditions.mod.blocks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Direction;
import org.apache.commons.lang3.ArrayUtils;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
import de.ellpeck.actuallyadditions.mod.gen.WorldGenLushCaves;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals;
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingBlock;
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockCrystalCluster extends Block implements IColorProvidingBlock, IColorProvidingItem {
private final TheCrystals crystal;
public BlockCrystalCluster(TheCrystals crystal) {
super(Properties.create(Material.GLASS)
.hardnessAndResistance(0.25f, 1.0f)
.sound(SoundType.GLASS)
.lightValue(7));
this.crystal = crystal;
// this.setHardness(0.25F);
// this.setResistance(1.0F);
// this.setSoundType(SoundType.GLASS);
// this.setLightOpacity(1);
// this.setLightLevel(0.7F);
}
// @Override
// public boolean isFullCube(BlockState state) {
// return false;
// }
//
// @Override
// public boolean isOpaqueCube(BlockState state) {
// return false;
// }
@Override
public BlockState getStateForPlacement(World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ, int meta, LivingEntity base) {
return this.getStateFromMeta(side.ordinal());
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(BlockDirectional.FACING, EnumFacing.byIndex(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(BlockDirectional.FACING).getIndex();
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, BlockDirectional.FACING);
}
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(BlockDirectional.FACING, rot.rotate(state.getValue(BlockDirectional.FACING)));
}
@Override
public IBlockState withMirror(IBlockState state, Mirror mirror) {
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
}
@Override
@SideOnly(Side.CLIENT)
public IBlockColor getBlockColor() {
return (state, world, pos, tintIndex) -> BlockCrystalCluster.this.crystal.clusterColor;
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Override
@SideOnly(Side.CLIENT)
public IItemColor getItemColor() {
return (stack, tintIndex) -> BlockCrystalCluster.this.crystal.clusterColor;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return InitItems.itemCrystalShard;
}
@Override
public int damageDropped(IBlockState state) {
return ArrayUtils.indexOf(WorldGenLushCaves.CRYSTAL_CLUSTERS, this);
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
return new ItemStack(this);
}
@Override
public int quantityDropped(Random random) {
return random.nextInt(5) + 2;
}
@Override
public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
return true;
}
}