Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package degubi.teamcraft.things.blocks;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockFenceGate;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyBool;
- import net.minecraft.block.state.BlockState;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.BlockPos;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumWorldBlockLayer;
- import net.minecraft.world.ColorizerFoliage;
- import net.minecraft.world.EnumSkyBlock;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraft.world.biome.BiomeColorHelper;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import degubi.teamcraft.TeamCraft;
- public class Walls extends Block{
- private Block blocktoget;
- public static final PropertyBool UP = PropertyBool.create("up");
- public static final PropertyBool NORTH = PropertyBool.create("north");
- public static final PropertyBool EAST = PropertyBool.create("east");
- public static final PropertyBool SOUTH = PropertyBool.create("south");
- public static final PropertyBool WEST = PropertyBool.create("west");
- public Walls(Block block){
- super(block.getMaterial());
- setHarvestLevel("pickaxe", 1);
- blocktoget = block;
- setHardness(block.blockHardness);
- setStepSound(block.stepSound);
- setResistance(block.blockResistance);
- setCreativeTab(TeamCraft.tcmtabBlocks);
- }
- @SideOnly(Side.CLIENT)
- public EnumWorldBlockLayer getBlockLayer() {
- if(blocktoget == Blocks.leaves){
- return EnumWorldBlockLayer.CUTOUT_MIPPED;
- }if(blocktoget == Blocks.ice){
- return EnumWorldBlockLayer.TRANSLUCENT;
- }
- return super.getBlockLayer();
- }
- public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
- {
- return false;
- }
- public boolean isOpaqueCube()
- {
- return false;
- }
- public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
- {
- boolean flag = this.canConnectTo(worldIn, pos.north());
- boolean flag1 = this.canConnectTo(worldIn, pos.south());
- boolean flag2 = this.canConnectTo(worldIn, pos.west());
- boolean flag3 = this.canConnectTo(worldIn, pos.east());
- float f = 0.25F;
- float f1 = 0.75F;
- float f2 = 0.25F;
- float f3 = 0.75F;
- float f4 = 1.0F;
- if (flag)
- {
- f2 = 0.0F;
- }
- if (flag1)
- {
- f3 = 1.0F;
- }
- if (flag2)
- {
- f = 0.0F;
- }
- if (flag3)
- {
- f1 = 1.0F;
- }
- if (flag && flag1 && !flag2 && !flag3)
- {
- f4 = 0.8125F;
- f = 0.3125F;
- f1 = 0.6875F;
- }
- else if (!flag && !flag1 && flag2 && flag3)
- {
- f4 = 0.8125F;
- f2 = 0.3125F;
- f3 = 0.6875F;
- }
- this.setBlockBounds(f, 0.0F, f2, f1, f4, f3);
- }
- public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
- {
- this.setBlockBoundsBasedOnState(worldIn, pos);
- this.maxY = 1.5D;
- return super.getCollisionBoundingBox(worldIn, pos, state);
- }
- public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos)
- {
- Block block = worldIn.getBlockState(pos).getBlock();
- return block == Blocks.barrier ? false : (block != this && !(block instanceof BlockFenceGate) ? (block.getMaterial().isOpaque() && block.isFullCube() ? block.getMaterial() != Material.gourd : false) : true);
- }
- @SideOnly(Side.CLIENT)
- public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
- {
- return side == EnumFacing.DOWN ? super.shouldSideBeRendered(worldIn, pos, side) : true;
- }
- public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
- {
- if (blocktoget == Blocks.ice && world.getLightFor(EnumSkyBlock.BLOCK, pos) > 11 - this.getLightOpacity()){
- if (!world.provider.isSurfaceWorld()){
- world.setBlockToAir(pos);}
- this.dropBlockAsItem(world, pos, world.getBlockState(pos), 0);
- world.setBlockState(pos, Blocks.water.getDefaultState());
- }
- }
- public IBlockState getStateFromMeta(int meta)
- {
- return getDefaultState();
- }
- public int getMetaFromState(IBlockState state)
- {
- return 0;
- }
- public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
- {
- return state.withProperty(UP, Boolean.valueOf(!worldIn.isAirBlock(pos.up()))).withProperty(NORTH, Boolean.valueOf(this.canConnectTo(worldIn, pos.north()))).withProperty(EAST, Boolean.valueOf(this.canConnectTo(worldIn, pos.east()))).withProperty(SOUTH, Boolean.valueOf(this.canConnectTo(worldIn, pos.south()))).withProperty(WEST, Boolean.valueOf(this.canConnectTo(worldIn, pos.west())));
- }
- protected BlockState createBlockState()
- {
- return new BlockState(this, new IProperty[] {UP, NORTH, EAST, WEST, SOUTH});
- }
- @SideOnly(Side.CLIENT)
- public int getBlockColor()
- {
- if(blocktoget == Blocks.leaves){
- return ColorizerFoliage.getFoliageColor(0.5D, 1.0D);
- }
- return super.getBlockColor();
- }
- @SideOnly(Side.CLIENT)
- public int getRenderColor(IBlockState state)
- {
- if(blocktoget == Blocks.leaves){
- ColorizerFoliage.getFoliageColorBasic();
- }
- return super.getRenderColor(state);
- }
- @SideOnly(Side.CLIENT)
- public int colorMultiplier(IBlockAccess acc, BlockPos pos, int renderPass)
- {
- if(blocktoget == Blocks.leaves){
- if(this == TeamCraft.SpruceLeafBush){
- return ColorizerFoliage.getFoliageColorPine();
- }else if(this == TeamCraft.BirchLeafBush){
- return ColorizerFoliage.getFoliageColorBirch();
- }else{
- return BiomeColorHelper.getFoliageColorAtPos(acc, pos);
- }
- }
- return super.colorMultiplier(acc, pos, renderPass);
- }
- public boolean canPlaceTorchOnTop(IBlockAccess world, BlockPos pos)
- {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement