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

147 lines
4.7 KiB
Java
Raw Normal View History

2017-02-13 23:17:08 +01:00
/*
* This file ("BlockCrystalCluster.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2017 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.blocks;
2019-05-02 09:10:29 +02:00
import java.util.Random;
import org.apache.commons.lang3.ArrayUtils;
2017-02-13 23:17:08 +01:00
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;
2021-02-26 22:15:48 +01:00
import net.minecraft.block.state.BlockState;
2017-02-13 23:17:08 +01:00
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.EntityLivingBase;
2021-02-26 22:15:48 +01:00
import net.minecraft.entity.player.PlayerEntity;
2017-02-13 23:17:08 +01:00
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;
2017-02-13 23:17:08 +01:00
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
2021-02-26 22:15:48 +01:00
import net.minecraftforge.fml.relauncher.OnlyIn;
2017-02-13 23:17:08 +01:00
2019-05-02 09:10:29 +02:00
public class BlockCrystalCluster extends BlockBase implements IColorProvidingBlock, IColorProvidingItem {
2017-02-13 23:17:08 +01:00
private final TheCrystals crystal;
2019-05-02 09:10:29 +02:00
public BlockCrystalCluster(String name, TheCrystals crystal) {
2017-02-13 23:17:08 +01:00
super(Material.GLASS, name);
this.crystal = crystal;
this.setHardness(0.25F);
this.setResistance(1.0F);
this.setSoundType(SoundType.GLASS);
this.setLightOpacity(1);
this.setLightLevel(0.7F);
}
@Override
2021-02-26 22:15:48 +01:00
public boolean isFullCube(BlockState state) {
2017-02-13 23:17:08 +01:00
return false;
}
@Override
2021-02-26 22:15:48 +01:00
public boolean isOpaqueCube(BlockState state) {
2017-02-13 23:17:08 +01:00
return false;
}
@Override
2021-02-26 22:15:48 +01:00
public BlockState getStateForPlacement(World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int meta, EntityLivingBase base) {
2017-02-13 23:17:08 +01:00
return this.getStateFromMeta(side.ordinal());
}
@Override
2019-05-02 09:10:29 +02:00
public EnumRarity getRarity(ItemStack stack) {
2017-02-13 23:17:08 +01:00
return EnumRarity.EPIC;
}
@Override
2021-02-26 22:15:48 +01:00
public BlockState getStateFromMeta(int meta) {
2018-08-04 04:22:20 +02:00
return this.getDefaultState().withProperty(BlockDirectional.FACING, EnumFacing.byIndex(meta));
2017-02-13 23:17:08 +01:00
}
@Override
2021-02-26 22:15:48 +01:00
public int getMetaFromState(BlockState state) {
2017-02-13 23:17:08 +01:00
return state.getValue(BlockDirectional.FACING).getIndex();
}
@Override
2019-05-02 09:10:29 +02:00
protected BlockStateContainer createBlockState() {
2017-02-13 23:17:08 +01:00
return new BlockStateContainer(this, BlockDirectional.FACING);
}
@Override
2021-02-26 22:15:48 +01:00
public BlockState withRotation(BlockState state, Rotation rot) {
2017-02-13 23:17:08 +01:00
return state.withProperty(BlockDirectional.FACING, rot.rotate(state.getValue(BlockDirectional.FACING)));
}
@Override
2021-02-26 22:15:48 +01:00
public BlockState withMirror(BlockState state, Mirror mirror) {
2017-02-13 23:17:08 +01:00
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
}
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2019-05-02 09:10:29 +02:00
public IBlockColor getBlockColor() {
2019-02-27 19:53:05 +01:00
return (state, world, pos, tintIndex) -> BlockCrystalCluster.this.crystal.clusterColor;
2017-02-13 23:17:08 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
public BlockRenderLayer getRenderLayer() {
2017-02-13 23:17:08 +01:00
return BlockRenderLayer.TRANSLUCENT;
}
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2019-05-02 09:10:29 +02:00
public IItemColor getItemColor() {
2019-02-27 19:53:05 +01:00
return (stack, tintIndex) -> BlockCrystalCluster.this.crystal.clusterColor;
2017-02-13 23:17:08 +01:00
}
@Override
2021-02-26 22:15:48 +01:00
public Item getItemDropped(BlockState state, Random rand, int fortune) {
2017-02-13 23:17:08 +01:00
return InitItems.itemCrystalShard;
}
@Override
2021-02-26 22:15:48 +01:00
public int damageDropped(BlockState state) {
2017-02-13 23:17:08 +01:00
return ArrayUtils.indexOf(WorldGenLushCaves.CRYSTAL_CLUSTERS, this);
}
@Override
2021-02-26 22:15:48 +01:00
public ItemStack getPickBlock(BlockState state, RayTraceResult target, World world, BlockPos pos, PlayerEntity player) {
return new ItemStack(this);
}
2017-02-13 23:17:08 +01:00
@Override
2019-05-02 09:10:29 +02:00
public int quantityDropped(Random random) {
return random.nextInt(5) + 2;
2017-02-13 23:17:08 +01:00
}
2017-02-14 20:48:01 +01:00
@Override
2021-02-26 22:15:48 +01:00
public boolean canSilkHarvest(World world, BlockPos pos, BlockState state, PlayerEntity player) {
2017-02-14 20:48:01 +01:00
return true;
}
2021-02-26 22:15:48 +01:00
}