Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.examplemod;
- import cz.grossik.farmcraft2.Main;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.util.IStringSerializable;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- public class BlockTestW extends Block {
- public static final PropertyEnum<EnumDirection> SHAPE = PropertyEnum.<EnumDirection>create("shape", EnumDirection.class);
- public BlockTestW(Material materialIn) {
- super(materialIn);
- this.setCreativeTab(Main.FarmCraft2Tab);
- this.setDefaultState(this.blockState.getBaseState().withProperty(SHAPE, EnumDirection.LEVO_KONEC));
- }
- public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
- {
- this.setDefaultFacing(worldIn, pos, state);
- }
- private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
- {
- if (!worldIn.isRemote)
- {
- EnumDirection blockrailbase$enumraildirection = (EnumDirection)state.getValue(SHAPE);
- if(worldIn.getBlockState(pos.east()).isFullBlock() && worldIn.getBlockState(pos.west()).isFullBlock() && worldIn.getBlockState(pos.east()).getBlock() != ExampleMod.testB && worldIn.getBlockState(pos.west()).getBlock() != ExampleMod.testB || worldIn.getBlockState(pos.north()).isFullBlock() && worldIn.getBlockState(pos.south()).isFullBlock() && worldIn.getBlockState(pos.north()).getBlock() != ExampleMod.testB && worldIn.getBlockState(pos.south()).getBlock() != ExampleMod.testB) {
- blockrailbase$enumraildirection = EnumDirection.OBE_KONEC;
- } else if((worldIn.getBlockState(pos.east()).isFullBlock() && worldIn.getBlockState(pos.east()).getBlock() != ExampleMod.testB) || (worldIn.getBlockState(pos.north()).isFullBlock() && worldIn.getBlockState(pos.north()).getBlock() != ExampleMod.testB)){
- blockrailbase$enumraildirection = EnumDirection.PRAVO_KONEC;
- } else if((worldIn.getBlockState(pos.west()).isFullBlock() && worldIn.getBlockState(pos.west()).getBlock() != ExampleMod.testB) || (worldIn.getBlockState(pos.south()).isFullBlock() && worldIn.getBlockState(pos.south()).getBlock() != ExampleMod.testB)){
- blockrailbase$enumraildirection = EnumDirection.LEVO_KONEC;
- } else {
- blockrailbase$enumraildirection = EnumDirection.OBE_POKRACUJE;
- }
- worldIn.setBlockState(pos, state.withProperty(SHAPE, blockrailbase$enumraildirection));
- }
- }
- public IBlockState getStateFromMeta(int meta)
- {
- return this.getDefaultState().withProperty(SHAPE, EnumDirection.byMetadata(meta));
- }
- public int getMetaFromState(IBlockState state)
- {
- return ((EnumDirection)state.getValue(SHAPE)).getMetadata();
- }
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {SHAPE});
- }
- public static enum EnumDirection implements IStringSerializable
- {
- LEVO_KONEC(0, "levo_konec"),
- PRAVO_KONEC(1, "pravo_konec"),
- OBE_KONEC(2, "obe_konec"),
- OBE_POKRACUJE(3, "obe_pokracuje");
- private static final EnumDirection[] META_LOOKUP = new EnumDirection[values().length];
- private final int meta;
- private final String name;
- private EnumDirection(int meta, String name)
- {
- this.meta = meta;
- this.name = name;
- }
- public int getMetadata()
- {
- return this.meta;
- }
- public String toString()
- {
- return this.name;
- }
- public static EnumDirection byMetadata(int meta)
- {
- if (meta < 0 || meta >= META_LOOKUP.length)
- {
- meta = 0;
- }
- return META_LOOKUP[meta];
- }
- public String getName()
- {
- return this.name;
- }
- static
- {
- for (EnumDirection blockrailbase$enumraildirection : values())
- {
- META_LOOKUP[blockrailbase$enumraildirection.getMetadata()] = blockrailbase$enumraildirection;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement