Advertisement
Guest User

Untitled

a guest
Mar 9th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.08 KB | None | 0 0
  1. package net.theviolentsquirrels.questsystem.block;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.properties.PropertyBool;
  5. import net.minecraft.block.properties.PropertyEnum;
  6. import net.minecraft.block.state.BlockState;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.*;
  13. import net.minecraft.world.IBlockAccess;
  14. import net.minecraft.world.World;
  15. import net.minecraftforge.fml.relauncher.Side;
  16. import net.minecraftforge.fml.relauncher.SideOnly;
  17. import net.theviolentsquirrels.questsystem.Main;
  18.  
  19. import java.util.List;
  20.  
  21. public class                                    BlockWallCustom extends Block implements IMetaBlockName {
  22.     public static final PropertyEnum<EnumType>  VARIANT = PropertyEnum.create("variant", EnumType.class);
  23.     public static final PropertyBool            UP = PropertyBool.create("up");
  24.     public static final PropertyBool            NORTH = PropertyBool.create("north");
  25.     public static final PropertyBool            EAST = PropertyBool.create("east");
  26.     public static final PropertyBool            SOUTH = PropertyBool.create("south");
  27.     public static final PropertyBool            WEST = PropertyBool.create("west");
  28.  
  29.     public                                      BlockWallCustom(String unlocalizedName, Block modelBlock) {
  30.         super (modelBlock.getMaterial());
  31.         this.setUnlocalizedName(unlocalizedName);
  32.         this.setHardness(2.0f);
  33.         this.setResistance(3.0f);
  34.         this.setStepSound(modelBlock.stepSound);
  35.         this.setCreativeTab(Main.tab);
  36.         this.setDefaultState(this.blockState.getBaseState()
  37.                 .withProperty(VARIANT, EnumType.STONEBRICK)
  38.                 .withProperty(UP, false)
  39.                 .withProperty(NORTH, false)
  40.                 .withProperty(EAST, false)
  41.                 .withProperty(SOUTH, false)
  42.                 .withProperty(WEST, false));
  43.     }
  44.  
  45.     @Override
  46.     public String                               getMetadataName(ItemStack stack) {
  47.         return (EnumType.META_LOOKUP[stack.getItemDamage()].getName());
  48.     }
  49.  
  50.     @Override
  51.     public ItemStack                            getPickBlock(MovingObjectPosition target, World world,
  52.                                                              BlockPos pos, EntityPlayer player) {
  53.         return (new ItemStack(Item.getItemFromBlock(this), 1, this.getMetaFromState(world.getBlockState(pos))));
  54.     }
  55.  
  56.     @Override
  57.     public boolean                              isFullCube() {
  58.         return (false);
  59.     }
  60.  
  61.     @Override
  62.     public boolean                              isPassable(IBlockAccess worldIn, BlockPos pos) {
  63.         return (false);
  64.     }
  65.  
  66.     @Override
  67.     public boolean                              isOpaqueCube() {
  68.         return (false);
  69.     }
  70.  
  71.     public void                                 setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
  72.         boolean                                 flag = this.canConnectTo(worldIn, pos.north());
  73.         boolean                                 flag1 = this.canConnectTo(worldIn, pos.south());
  74.         boolean                                 flag2 = this.canConnectTo(worldIn, pos.west());
  75.         boolean                                 flag3 = this.canConnectTo(worldIn, pos.east());
  76.         float                                   f = 0.25F;
  77.         float                                   f1 = 0.75F;
  78.         float                                   f2 = 0.25F;
  79.         float                                   f3 = 0.75F;
  80.         float                                   f4 = 1.0F;
  81.  
  82.         if (flag) f2 = 0.0F;
  83.         if (flag1) f3 = 1.0F;
  84.         if (flag2) f = 0.0F;
  85.         if (flag3) f1 = 1.0F;
  86.  
  87.         if (flag && flag1 && !flag2 && !flag3) {
  88.             f4 = 0.8125F;
  89.             f = 0.3125F;
  90.             f1 = 0.6875F;
  91.         } else if (!flag && !flag1 && flag2 && flag3) {
  92.             f4 = 0.8125F;
  93.             f2 = 0.3125F;
  94.             f3 = 0.6875F;
  95.         }
  96.         this.setBlockBounds(f, 0.0F, f2, f1, f4, f3);
  97.     }
  98.  
  99.     public AxisAlignedBB                        getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
  100.         this.setBlockBoundsBasedOnState(worldIn, pos);
  101.         this.maxY = 1.5D;
  102.         return (super.getCollisionBoundingBox(worldIn, pos, state));
  103.     }
  104.  
  105.     /**
  106.      * W.I.P !
  107.      * @param                                   worldIn
  108.      * @param                                   pos
  109.      * @return
  110.      */
  111.     public boolean                              canConnectTo(IBlockAccess worldIn, BlockPos pos) {
  112.         Block                                   block = worldIn.getBlockState(pos).getBlock();
  113.         /*return (block == Blocks.barrier ? false :
  114.                 (block != this && !(block instanceof BlockFenceGate) ? (block.blockMaterial.isOpaque() && block.isFullCube() ? block.blockMaterial != Material.gourd :
  115.                         false) :
  116.                         true));*/
  117.         return (block == this);
  118.     }
  119.  
  120.     @SideOnly(Side.CLIENT)
  121.     @Override
  122.     public void                                 getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
  123.         for (EnumType                           enumType : EnumType.values()) {
  124.             list.add(new ItemStack(itemIn, 1, enumType.getMetadata()));
  125.         }
  126.     }
  127.  
  128.     @Override
  129.     public int                                  damageDropped(IBlockState state) {
  130.         return (state.getValue(VARIANT).getMetadata());
  131.     }
  132.  
  133.     @SideOnly(Side.CLIENT)
  134.     @Override
  135.     public boolean                              shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
  136.         return (side == EnumFacing.DOWN ? super.shouldSideBeRendered(worldIn, pos, side) : true);
  137.     }
  138.  
  139.     @Override
  140.     public IBlockState                          getStateFromMeta(int meta) {
  141.         return (this.getDefaultState().withProperty(VARIANT, EnumType.byMetadata(meta)));
  142.     }
  143.  
  144.     @Override
  145.     public int                                  getMetaFromState(IBlockState state) {
  146.         return (state.getValue(VARIANT).getMetadata());
  147.     }
  148.  
  149.     public IBlockState                          getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
  150.         return (state
  151.                 .withProperty(UP, !worldIn.isAirBlock(pos.up()))
  152.                 .withProperty(NORTH, this.canConnectTo(worldIn, pos.north()))
  153.                 .withProperty(EAST, this.canConnectTo(worldIn, pos.east()))
  154.                 .withProperty(SOUTH, this.canConnectTo(worldIn, pos.south()))
  155.                 .withProperty(WEST, this.canConnectTo(worldIn, pos.west())));
  156.     }
  157.  
  158.     @Override
  159.     protected BlockState                        createBlockState() {
  160.         return (new BlockState(this, VARIANT, UP, NORTH, EAST, SOUTH, WEST));
  161.     }
  162.  
  163.     public enum                                 EnumType implements IStringSerializable {
  164.         STONEBRICK(0, "stonebrick"),
  165.         NETHER_BRICK(1, "nether_brick");
  166.  
  167.         private static final EnumType[]         META_LOOKUP = new EnumType[values().length];
  168.         private final int                       meta;
  169.         private final String                    name;
  170.  
  171.         EnumType(int meta, String name) {
  172.             this.meta = meta;
  173.             this.name = name;
  174.         }
  175.  
  176.         public int                              getMetadata() {
  177.             return (this.meta);
  178.         }
  179.  
  180.         public String                           toString() {
  181.             return (this.name);
  182.         }
  183.  
  184.         public static EnumType                  byMetadata(int meta) {
  185.             if (meta < 0 || meta >= META_LOOKUP.length) meta = 0;
  186.             return (META_LOOKUP[meta]);
  187.         }
  188.  
  189.         public String                           getName() {
  190.             return (this.name);
  191.         }
  192.  
  193.         static {
  194.             for (EnumType   enumType : values()) {
  195.                 META_LOOKUP[enumType.getMetadata()] = enumType;
  196.             }
  197.         }
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement