Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TechnicianLP.FactorialRevolution.common.blocks.blockstate;
- import com.google.common.collect.ImmutableSet;
- import TechnicianLP.FactorialRevolution.common.FactorialRevolution;
- import TechnicianLP.FactorialRevolution.common.blocks.blocks.belt.BlockBelt;
- import TechnicianLP.FactorialRevolution.common.blocks.blockstate.property.EConnection;
- import TechnicianLP.FactorialRevolution.common.blocks.blockstate.property.PropertyConnection;
- import net.minecraft.block.Block;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyBool;
- import net.minecraft.block.properties.PropertyDirection;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.IStringSerializable;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraftforge.common.property.IUnlistedProperty;
- public class BeltStateSupplier extends AStateSupplier {
- /** facing of outputside */
- public static final PropertyDirection FACING = PropertyDirection.create("facing", ImmutableSet.copyOf(EnumFacing.HORIZONTALS));
- /** where do belts connect (visual) */
- public static final PropertyConnection CONNECTIONS_V = PropertyConnection.create("connections_v", true, EnumFacing.HORIZONTALS);
- /** where do belts connect (real) */
- public static final PropertyConnection CONNECTIONS_R = PropertyConnection.create("connections_r", false, EnumFacing.HORIZONTALS);
- /** what type of belt? */
- public static final PropertyEnum<BeltTier> TIER = PropertyEnum.create("tier", BeltTier.class);
- /** is this solid on the top? */
- public static final PropertyBool FRAMED = PropertyBool.create("framed");
- @Override
- public BlockStateContainer createBlockState(Block b) {
- return createBlockState(b, new IProperty[] { FACING, CONNECTIONS_V, TIER, FRAMED }, new IProperty[0], new IUnlistedProperty[] { CONNECTIONS_R });
- }
- @Override
- public IBlockState getDefaultState(IBlockStateWrapper base) {
- base.withProperty(FACING, EnumFacing.NORTH);
- // base.withProperty(CONNECTIONS_R, EConnection.______);
- base.withProperty(CONNECTIONS_V, EConnection.______);
- base.withProperty(TIER, BeltTier.BASIC);
- base.withProperty(FRAMED, false);
- return base.state;
- }
- @Override
- public IBlockState getActualState(IBlockStateWrapper state, IBlockAccess worldIn, BlockPos pos) {
- FactorialRevolution.LOGGER.info("actual state:" + state.state);
- EnumFacing facing = state.getValue(FACING);
- BeltTier tier = state.getValue(TIER);
- IBlockState south = worldIn.getBlockState(pos.offset(facing.getOpposite()));
- if (south.getBlock() instanceof BlockBelt) {
- if (south.getValue(FACING) == facing) {
- FactorialRevolution.LOGGER.info("dafuq?");
- // state.withProperty(CONNECTIONS_R,
- // state.getValue(CONNECTIONS_R).add(EnumFacing.SOUTH));
- if (south.getValue(TIER) == tier)
- state.withProperty(CONNECTIONS_V, state.getValue(CONNECTIONS_V).add(EnumFacing.SOUTH));
- }
- }
- IBlockState north = worldIn.getBlockState(pos.offset(facing));
- if (north.getBlock() instanceof BlockBelt) {
- if (north.getValue(FACING) == facing) {
- // state.withProperty(CONNECTIONS_R,
- // state.getValue(CONNECTIONS_R).add(EnumFacing.NORTH));
- if (north.getValue(TIER) == tier)
- state.withProperty(CONNECTIONS_V, state.getValue(CONNECTIONS_V).add(EnumFacing.NORTH));
- }
- }
- IBlockState west = worldIn.getBlockState(pos.offset(facing.rotateYCCW()));
- if (west.getBlock() instanceof BlockBelt) {
- if (west.getValue(FACING) == facing.rotateY()) {
- // state.withProperty(CONNECTIONS_R,
- // state.getValue(CONNECTIONS_R).add(EnumFacing.WEST));
- state.withProperty(CONNECTIONS_V, state.getValue(CONNECTIONS_V).add(EnumFacing.WEST));
- }
- }
- IBlockState east = worldIn.getBlockState(pos.offset(facing.rotateY()));
- if (east.getBlock() instanceof BlockBelt) {
- if (east.getValue(FACING) == facing.rotateYCCW()) {
- // state.withProperty(CONNECTIONS_R,
- // state.getValue(CONNECTIONS_R).add(EnumFacing.EAST));
- state.withProperty(CONNECTIONS_V, state.getValue(CONNECTIONS_V).add(EnumFacing.EAST));
- }
- }
- // EConnection real = state.getValue(CONNECTIONS_R);
- // if (real.isConnected(EnumFacing.NORTH))
- // state.withProperty(CONNECTIONS_V,
- // state.getValue(CONNECTIONS_V).add(EnumFacing.NORTH));
- // if (real.isConnected(EnumFacing.SOUTH))
- // state.withProperty(CONNECTIONS_V,
- // state.getValue(CONNECTIONS_V).add(EnumFacing.SOUTH));
- return state.state;
- }
- @Override
- public int getMetaFromState(IBlockStateWrapper state) {
- int meta = 0;
- EnumFacing facing = state.getValue(FACING);
- meta += (facing.ordinal() - 2) << 2;
- BeltTier type = state.getValue(TIER);
- meta += type.ordinal();
- return meta;
- }
- @Override
- public IBlockState getStateFromMeta(int meta, IBlockStateWrapper defalt) {
- FactorialRevolution.LOGGER.info("gsfm1: " + defalt.state);
- defalt.withProperty(FACING, EnumFacing.values()[((meta >> 2) & 3) + 2]);
- defalt.withProperty(TIER, BeltTier.values()[meta & 3]);
- FactorialRevolution.LOGGER.info("gsfm2: " + defalt.state);
- return defalt.state;
- }
- public static enum BeltTier implements IStringSerializable {
- BASIC("basic"), FAST("fast"), EXPRESS("express"), SPEEDY("speedy");
- String name;
- private BeltTier(String type) {
- name = type;
- }
- @Override
- public String getName() {
- return name;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement