Created
April 10, 2019 18:04
-
-
Save LatvianModder/c9f4510493ac21e65ff6f9ac539d11f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.latmod.mods.wallcables.block; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.material.MapColor; | |
import net.minecraft.block.material.Material; | |
import net.minecraft.block.properties.PropertyEnum; | |
import net.minecraft.block.properties.PropertyInteger; | |
import net.minecraft.block.state.BlockStateContainer; | |
import net.minecraft.block.state.IBlockState; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.world.IBlockAccess; | |
import net.minecraft.world.World; | |
/** | |
* @author LatvianModder | |
*/ | |
public class BlockTruss extends Block | |
{ | |
public static final EnumFacing.Axis[] AXES = EnumFacing.Axis.values(); | |
public static final PropertyEnum<EnumFacing.Axis> AXIS = PropertyEnum.create("axis", EnumFacing.Axis.class); | |
public static final PropertyInteger N = PropertyInteger.create("n", 0, 1); | |
public static final PropertyInteger S = PropertyInteger.create("s", 0, 1); | |
public static final PropertyInteger W = PropertyInteger.create("w", 0, 1); | |
public static final PropertyInteger E = PropertyInteger.create("e", 0, 1); | |
public BlockTruss() | |
{ | |
super(Material.IRON, MapColor.WHITE_STAINED_HARDENED_CLAY); | |
setHardness(0.6F); | |
setDefaultState(blockState.getBaseState() | |
.withProperty(AXIS, EnumFacing.Axis.Y) | |
.withProperty(N, 0) | |
.withProperty(S, 0) | |
.withProperty(W, 0) | |
.withProperty(E, 0)); | |
} | |
@Override | |
protected BlockStateContainer createBlockState() | |
{ | |
return new BlockStateContainer(this, AXIS, N, S, W, E); | |
} | |
@Override | |
@Deprecated | |
public IBlockState getStateFromMeta(int meta) | |
{ | |
return getDefaultState().withProperty(AXIS, AXES[meta]); | |
} | |
@Override | |
public int getMetaFromState(IBlockState state) | |
{ | |
return state.getValue(AXIS).ordinal(); | |
} | |
@Override | |
@Deprecated | |
public boolean isOpaqueCube(IBlockState state) | |
{ | |
return false; | |
} | |
@Override | |
@Deprecated | |
public boolean isFullBlock(IBlockState state) | |
{ | |
return false; | |
} | |
@Override | |
@Deprecated | |
public boolean isFullCube(IBlockState state) | |
{ | |
return false; | |
} | |
@Override | |
@Deprecated | |
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) | |
{ | |
if (state.getValue(AXIS) == EnumFacing.Axis.Y) | |
{ | |
if (canConnect(world, pos, EnumFacing.NORTH)) | |
{ | |
state = state.withProperty(N, 1); | |
} | |
if (canConnect(world, pos, EnumFacing.SOUTH)) | |
{ | |
state = state.withProperty(S, 1); | |
} | |
if (canConnect(world, pos, EnumFacing.WEST)) | |
{ | |
state = state.withProperty(W, 1); | |
} | |
if (canConnect(world, pos, EnumFacing.EAST)) | |
{ | |
state = state.withProperty(E, 1); | |
} | |
} | |
return state; | |
} | |
private boolean canConnect(IBlockAccess world, BlockPos pos, EnumFacing facing) | |
{ | |
IBlockState state = world.getBlockState(pos.offset(facing)); | |
return state.getBlock() == this && state.getValue(AXIS) == facing.getAxis(); | |
} | |
@Override | |
@Deprecated | |
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) | |
{ | |
switch (facing.getAxis()) | |
{ | |
case X: | |
return getDefaultState().withProperty(AXIS, EnumFacing.Axis.X); | |
case Z: | |
return getDefaultState().withProperty(AXIS, EnumFacing.Axis.Z); | |
default: | |
return getDefaultState().withProperty(AXIS, EnumFacing.Axis.Y); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment