Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.56 KB | None | 0 0
  1. package com.maideniles.calumsmod.blocks.tracks;
  2.  
  3. import com.google.common.collect.Lists;
  4. import com.google.common.collect.Sets;
  5. import com.maideniles.calumsmod.CalumsMod;
  6. import com.maideniles.calumsmod.init.ModBlocks;
  7. import com.maideniles.calumsmod.init.ModItems;
  8. import com.maideniles.calumsmod.util.IHasModel;
  9.  
  10. import java.util.EnumSet;
  11. import java.util.List;
  12. import java.util.Random;
  13. import java.util.Set;
  14. import javax.annotation.Nullable;
  15.  
  16. import net.minecraft.block.Block;
  17. import net.minecraft.block.BlockObserver;
  18. import net.minecraft.block.BlockRedstoneDiode;
  19. import net.minecraft.block.BlockRedstoneRepeater;
  20. import net.minecraft.block.material.Material;
  21. import net.minecraft.block.properties.IProperty;
  22. import net.minecraft.block.properties.PropertyEnum;
  23. import net.minecraft.block.properties.PropertyInteger;
  24. import net.minecraft.block.state.BlockFaceShape;
  25. import net.minecraft.block.state.BlockStateContainer;
  26. import net.minecraft.block.state.IBlockState;
  27. import net.minecraft.init.Blocks;
  28. import net.minecraft.init.Items;
  29. import net.minecraft.item.Item;
  30. import net.minecraft.item.ItemBlock;
  31. import net.minecraft.item.ItemStack;
  32. import net.minecraft.util.BlockRenderLayer;
  33. import net.minecraft.util.EnumFacing;
  34. import net.minecraft.util.EnumParticleTypes;
  35. import net.minecraft.util.IStringSerializable;
  36. import net.minecraft.util.Mirror;
  37. import net.minecraft.util.Rotation;
  38. import net.minecraft.util.math.AxisAlignedBB;
  39. import net.minecraft.util.math.BlockPos;
  40. import net.minecraft.util.math.MathHelper;
  41. import net.minecraft.world.IBlockAccess;
  42. import net.minecraft.world.World;
  43. import net.minecraftforge.fml.relauncher.Side;
  44. import net.minecraftforge.fml.relauncher.SideOnly;
  45.  
  46. public class BlockTrackWire extends Block implements IHasModel
  47. {
  48.     public static final PropertyEnum<BlockTrackWire.EnumAttachPosition> NORTH = PropertyEnum.<BlockTrackWire.EnumAttachPosition>create("north", BlockTrackWire.EnumAttachPosition.class);
  49.     public static final PropertyEnum<BlockTrackWire.EnumAttachPosition> EAST = PropertyEnum.<BlockTrackWire.EnumAttachPosition>create("east", BlockTrackWire.EnumAttachPosition.class);
  50.     public static final PropertyEnum<BlockTrackWire.EnumAttachPosition> SOUTH = PropertyEnum.<BlockTrackWire.EnumAttachPosition>create("south", BlockTrackWire.EnumAttachPosition.class);
  51.     public static final PropertyEnum<BlockTrackWire.EnumAttachPosition> WEST = PropertyEnum.<BlockTrackWire.EnumAttachPosition>create("west", BlockTrackWire.EnumAttachPosition.class);
  52.     public static final PropertyInteger POWER = PropertyInteger.create("power", 0, 15);
  53.     protected static final AxisAlignedBB[] TRACK_WIRE_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D)};
  54.     private boolean canProvidePower = true;
  55.     /** List of blocks to update with redstone. */
  56.     private final Set<BlockPos> blocksNeedingUpdate = Sets.<BlockPos>newHashSet();
  57.  
  58.     public BlockTrackWire(String name, Material materialIn)
  59.     {
  60.         super(Material.CIRCUITS);
  61.         setUnlocalizedName(name);
  62.         setRegistryName(name);
  63.         this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, BlockTrackWire.EnumAttachPosition.NONE).withProperty(EAST, BlockTrackWire.EnumAttachPosition.NONE).withProperty(SOUTH, BlockTrackWire.EnumAttachPosition.NONE).withProperty(WEST, BlockTrackWire.EnumAttachPosition.NONE).withProperty(POWER, Integer.valueOf(0)));
  64.    
  65.         this.setCreativeTab(CalumsMod.calumsmodblocks);
  66.          
  67.        
  68.         ModBlocks.BLOCKS.add(this);
  69.         ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
  70.        
  71.     }
  72.  
  73.     public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
  74.     {
  75.         return TRACK_WIRE_AABB[getAABBIndex(state.getActualState(source, pos))];
  76.     }
  77.  
  78.     private static int getAABBIndex(IBlockState state)
  79.     {
  80.         int i = 0;
  81.         boolean flag = state.getValue(NORTH) != BlockTrackWire.EnumAttachPosition.NONE;
  82.         boolean flag1 = state.getValue(EAST) != BlockTrackWire.EnumAttachPosition.NONE;
  83.         boolean flag2 = state.getValue(SOUTH) != BlockTrackWire.EnumAttachPosition.NONE;
  84.         boolean flag3 = state.getValue(WEST) != BlockTrackWire.EnumAttachPosition.NONE;
  85.  
  86.         if (flag || flag2 && !flag && !flag1 && !flag3)
  87.         {
  88.             i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
  89.         }
  90.  
  91.         if (flag1 || flag3 && !flag && !flag1 && !flag2)
  92.         {
  93.             i |= 1 << EnumFacing.EAST.getHorizontalIndex();
  94.         }
  95.  
  96.         if (flag2 || flag && !flag1 && !flag2 && !flag3)
  97.         {
  98.             i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
  99.         }
  100.  
  101.         if (flag3 || flag1 && !flag && !flag2 && !flag3)
  102.         {
  103.             i |= 1 << EnumFacing.WEST.getHorizontalIndex();
  104.         }
  105.  
  106.         return i;
  107.     }
  108.  
  109.     /**
  110.      * Get the actual Block state of this Block at the given position. This applies properties not visible in the
  111.      * metadata, such as fence connections.
  112.      */
  113.     public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
  114.     {
  115.         state = state.withProperty(WEST, this.getAttachPosition(worldIn, pos, EnumFacing.WEST));
  116.         state = state.withProperty(EAST, this.getAttachPosition(worldIn, pos, EnumFacing.EAST));
  117.         state = state.withProperty(NORTH, this.getAttachPosition(worldIn, pos, EnumFacing.NORTH));
  118.         state = state.withProperty(SOUTH, this.getAttachPosition(worldIn, pos, EnumFacing.SOUTH));
  119.         return state;
  120.     }
  121.  
  122.     private BlockTrackWire.EnumAttachPosition getAttachPosition(IBlockAccess worldIn, BlockPos pos, EnumFacing direction)
  123.     {
  124.         BlockPos blockpos = pos.offset(direction);
  125.         IBlockState iblockstate = worldIn.getBlockState(pos.offset(direction));
  126.  
  127.         if (!canConnectTo(worldIn.getBlockState(blockpos), direction, worldIn, blockpos) && (iblockstate.isNormalCube() || !canConnectUpwardsTo(worldIn, blockpos.down())))
  128.         {
  129.             IBlockState iblockstate1 = worldIn.getBlockState(pos.up());
  130.  
  131.             if (!iblockstate1.isNormalCube())
  132.             {
  133.                 boolean flag = worldIn.getBlockState(blockpos).isSideSolid(worldIn, blockpos, EnumFacing.UP) || worldIn.getBlockState(blockpos).getBlock() == Blocks.GLOWSTONE;
  134.  
  135.                 if (flag && canConnectUpwardsTo(worldIn, blockpos.up()))
  136.                 {
  137.                     if (iblockstate.isBlockNormalCube())
  138.                     {
  139.                         return BlockTrackWire.EnumAttachPosition.UP;
  140.                     }
  141.  
  142.                     return BlockTrackWire.EnumAttachPosition.SIDE;
  143.                 }
  144.             }
  145.  
  146.             return BlockTrackWire.EnumAttachPosition.NONE;
  147.         }
  148.         else
  149.         {
  150.             return BlockTrackWire.EnumAttachPosition.SIDE;
  151.         }
  152.     }
  153.  
  154.     @Nullable
  155.     public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
  156.     {
  157.         return NULL_AABB;
  158.     }
  159.  
  160.     /**
  161.      * Used to determine ambient occlusion and culling when rebuilding chunks for render
  162.      */
  163.     public boolean isOpaqueCube(IBlockState state)
  164.     {
  165.         return false;
  166.     }
  167.  
  168.     public boolean isFullCube(IBlockState state)
  169.     {
  170.         return false;
  171.     }
  172.  
  173.     /**
  174.      * Checks if this block can be placed exactly at the given position.
  175.      */
  176.     public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
  177.     {
  178.         IBlockState downState = worldIn.getBlockState(pos.down());
  179.         return downState.isTopSolid() || downState.getBlockFaceShape(worldIn, pos.down(), EnumFacing.UP) == BlockFaceShape.SOLID || worldIn.getBlockState(pos.down()).getBlock() == Blocks.GLOWSTONE;
  180.     }
  181.  
  182.     private IBlockState updateSurroundingRedstone(World worldIn, BlockPos pos, IBlockState state)
  183.     {
  184.         state = this.calculateCurrentChanges(worldIn, pos, pos, state);
  185.         List<BlockPos> list = Lists.newArrayList(this.blocksNeedingUpdate);
  186.         this.blocksNeedingUpdate.clear();
  187.  
  188.         for (BlockPos blockpos : list)
  189.         {
  190.             worldIn.notifyNeighborsOfStateChange(blockpos, this, false);
  191.         }
  192.  
  193.         return state;
  194.     }
  195.  
  196.     private IBlockState calculateCurrentChanges(World worldIn, BlockPos pos1, BlockPos pos2, IBlockState state)
  197.     {
  198.         IBlockState iblockstate = state;
  199.         int i = ((Integer)state.getValue(POWER)).intValue();
  200.         int j = 0;
  201.         j = this.getMaxCurrentStrength(worldIn, pos2, j);
  202.         this.canProvidePower = false;
  203.         int k = worldIn.isBlockIndirectlyGettingPowered(pos1);
  204.         this.canProvidePower = true;
  205.  
  206.         if (k > 0 && k > j - 1)
  207.         {
  208.             j = k;
  209.         }
  210.  
  211.         int l = 0;
  212.  
  213.         for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  214.         {
  215.             BlockPos blockpos = pos1.offset(enumfacing);
  216.             boolean flag = blockpos.getX() != pos2.getX() || blockpos.getZ() != pos2.getZ();
  217.  
  218.             if (flag)
  219.             {
  220.                 l = this.getMaxCurrentStrength(worldIn, blockpos, l);
  221.             }
  222.  
  223.             if (worldIn.getBlockState(blockpos).isNormalCube() && !worldIn.getBlockState(pos1.up()).isNormalCube())
  224.             {
  225.                 if (flag && pos1.getY() >= pos2.getY())
  226.                 {
  227.                     l = this.getMaxCurrentStrength(worldIn, blockpos.up(), l);
  228.                 }
  229.             }
  230.             else if (!worldIn.getBlockState(blockpos).isNormalCube() && flag && pos1.getY() <= pos2.getY())
  231.             {
  232.                 l = this.getMaxCurrentStrength(worldIn, blockpos.down(), l);
  233.             }
  234.         }
  235.  
  236.         if (l > j)
  237.         {
  238.             j = l - 1;
  239.         }
  240.         else if (j > 0)
  241.         {
  242.             --j;
  243.         }
  244.         else
  245.         {
  246.             j = 0;
  247.         }
  248.  
  249.         if (k > j - 1)
  250.         {
  251.             j = k;
  252.         }
  253.  
  254.         if (i != j)
  255.         {
  256.             state = state.withProperty(POWER, Integer.valueOf(j));
  257.  
  258.             if (worldIn.getBlockState(pos1) == iblockstate)
  259.             {
  260.                 worldIn.setBlockState(pos1, state, 2);
  261.             }
  262.  
  263.             this.blocksNeedingUpdate.add(pos1);
  264.  
  265.             for (EnumFacing enumfacing1 : EnumFacing.values())
  266.             {
  267.                 this.blocksNeedingUpdate.add(pos1.offset(enumfacing1));
  268.             }
  269.         }
  270.  
  271.         return state;
  272.     }
  273.  
  274.     /**
  275.      * Calls World.notifyNeighborsOfStateChange() for all neighboring blocks, but only if the given block is a redstone
  276.      * wire.
  277.      */
  278.     private void notifyWireNeighborsOfStateChange(World worldIn, BlockPos pos)
  279.     {
  280.         if (worldIn.getBlockState(pos).getBlock() == this)
  281.         {
  282.             worldIn.notifyNeighborsOfStateChange(pos, this, false);
  283.  
  284.             for (EnumFacing enumfacing : EnumFacing.values())
  285.             {
  286.                 worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, false);
  287.             }
  288.         }
  289.     }
  290.  
  291.     /**
  292.      * Called after the block is set in the Chunk data, but before the Tile Entity is set
  293.      */
  294.     public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  295.     {
  296.         if (!worldIn.isRemote)
  297.         {
  298.             this.updateSurroundingRedstone(worldIn, pos, state);
  299.  
  300.             for (EnumFacing enumfacing : EnumFacing.Plane.VERTICAL)
  301.             {
  302.                 worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, false);
  303.             }
  304.  
  305.             for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
  306.             {
  307.                 this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
  308.             }
  309.  
  310.             for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
  311.             {
  312.                 BlockPos blockpos = pos.offset(enumfacing2);
  313.  
  314.                 if (worldIn.getBlockState(blockpos).isNormalCube())
  315.                 {
  316.                     this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
  317.                 }
  318.                 else
  319.                 {
  320.                     this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
  321.                 }
  322.             }
  323.         }
  324.     }
  325.  
  326.     /**
  327.      * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
  328.      */
  329.     public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
  330.     {
  331.         super.breakBlock(worldIn, pos, state);
  332.  
  333.         if (!worldIn.isRemote)
  334.         {
  335.             for (EnumFacing enumfacing : EnumFacing.values())
  336.             {
  337.                 worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, false);
  338.             }
  339.  
  340.             this.updateSurroundingRedstone(worldIn, pos, state);
  341.  
  342.             for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
  343.             {
  344.                 this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
  345.             }
  346.  
  347.             for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
  348.             {
  349.                 BlockPos blockpos = pos.offset(enumfacing2);
  350.  
  351.                 if (worldIn.getBlockState(blockpos).isNormalCube())
  352.                 {
  353.                     this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
  354.                 }
  355.                 else
  356.                 {
  357.                     this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
  358.                 }
  359.             }
  360.         }
  361.     }
  362.  
  363.     private int getMaxCurrentStrength(World worldIn, BlockPos pos, int strength)
  364.     {
  365.         if (worldIn.getBlockState(pos).getBlock() != this)
  366.         {
  367.             return strength;
  368.         }
  369.         else
  370.         {
  371.             int i = ((Integer)worldIn.getBlockState(pos).getValue(POWER)).intValue();
  372.             return i > strength ? i : strength;
  373.         }
  374.     }
  375.  
  376.     /**
  377.      * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
  378.      * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
  379.      * block, etc.
  380.      */
  381.     public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
  382.     {
  383.         if (!worldIn.isRemote)
  384.         {
  385.             if (this.canPlaceBlockAt(worldIn, pos))
  386.             {
  387.                 this.updateSurroundingRedstone(worldIn, pos, state);
  388.             }
  389.             else
  390.             {
  391.                 this.dropBlockAsItem(worldIn, pos, state, 0);
  392.                 worldIn.setBlockToAir(pos);
  393.             }
  394.         }
  395.     }
  396.  
  397.     /**
  398.      * Get the Item that this Block should drop when harvested.
  399.      */
  400.     public Item getItemDropped(IBlockState state, Random rand, int fortune)
  401.     {
  402.         return Items.REDSTONE;
  403.     }
  404.  
  405.     public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
  406.     {
  407.         return !this.canProvidePower ? 0 : blockState.getWeakPower(blockAccess, pos, side);
  408.     }
  409.  
  410.     public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
  411.     {
  412.         if (!this.canProvidePower)
  413.         {
  414.             return 0;
  415.         }
  416.         else
  417.         {
  418.             int i = ((Integer)blockState.getValue(POWER)).intValue();
  419.  
  420.             if (i == 0)
  421.             {
  422.                 return 0;
  423.             }
  424.             else if (side == EnumFacing.UP)
  425.             {
  426.                 return i;
  427.             }
  428.             else
  429.             {
  430.                 EnumSet<EnumFacing> enumset = EnumSet.<EnumFacing>noneOf(EnumFacing.class);
  431.  
  432.                 for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  433.                 {
  434.                     if (this.isPowerSourceAt(blockAccess, pos, enumfacing))
  435.                     {
  436.                         enumset.add(enumfacing);
  437.                     }
  438.                 }
  439.  
  440.                 if (side.getAxis().isHorizontal() && enumset.isEmpty())
  441.                 {
  442.                     return i;
  443.                 }
  444.                 else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY()))
  445.                 {
  446.                     return i;
  447.                 }
  448.                 else
  449.                 {
  450.                     return 0;
  451.                 }
  452.             }
  453.         }
  454.     }
  455.  
  456.     private boolean isPowerSourceAt(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
  457.     {
  458.         BlockPos blockpos = pos.offset(side);
  459.         IBlockState iblockstate = worldIn.getBlockState(blockpos);
  460.         boolean flag = iblockstate.isNormalCube();
  461.         boolean flag1 = worldIn.getBlockState(pos.up()).isNormalCube();
  462.  
  463.         if (!flag1 && flag && canConnectUpwardsTo(worldIn, blockpos.up()))
  464.         {
  465.             return true;
  466.         }
  467.         else if (canConnectTo(iblockstate, side, worldIn, pos))
  468.         {
  469.             return true;
  470.         }
  471.         else if (iblockstate.getBlock() == Blocks.POWERED_REPEATER && iblockstate.getValue(BlockRedstoneDiode.FACING) == side)
  472.         {
  473.             return true;
  474.         }
  475.         else
  476.         {
  477.             return !flag && canConnectUpwardsTo(worldIn, blockpos.down());
  478.         }
  479.     }
  480.  
  481.     protected static boolean canConnectUpwardsTo(IBlockAccess worldIn, BlockPos pos)
  482.     {
  483.         return canConnectTo(worldIn.getBlockState(pos), null, worldIn, pos);
  484.     }
  485.  
  486.     protected static boolean canConnectTo(IBlockState blockState, @Nullable EnumFacing side, IBlockAccess world, BlockPos pos)
  487.     {
  488.         Block block = blockState.getBlock();
  489.  
  490.         if (block == ModBlocks.TRACK_WIRE)
  491.         {
  492.             return true;
  493.         }
  494.         else if (Blocks.UNPOWERED_REPEATER.isSameDiode(blockState))
  495.         {
  496.             EnumFacing enumfacing = (EnumFacing)blockState.getValue(BlockRedstoneRepeater.FACING);
  497.             return enumfacing == side || enumfacing.getOpposite() == side;
  498.         }
  499.         else if (Blocks.OBSERVER == blockState.getBlock())
  500.         {
  501.             return side == blockState.getValue(BlockObserver.FACING);
  502.         }
  503.         else
  504.         {
  505.             return blockState.getBlock().canConnectRedstone(blockState, world, pos, side);
  506.         }
  507.     }
  508.  
  509.     /**
  510.      * Can this block provide power. Only wire currently seems to have this change based on its state.
  511.      */
  512.     public boolean canProvidePower(IBlockState state)
  513.     {
  514.         return this.canProvidePower;
  515.     }
  516.  
  517.     @SideOnly(Side.CLIENT)
  518.     public static int colorMultiplier(int p_176337_0_)
  519.     {
  520.         float f = (float)p_176337_0_ / 15.0F;
  521.         float f1 = f * 0.6F + 0.4F;
  522.  
  523.         if (p_176337_0_ == 0)
  524.         {
  525.             f1 = 0.3F;
  526.         }
  527.  
  528.         float f2 = f * f * 0.7F - 0.5F;
  529.         float f3 = f * f * 0.6F - 0.7F;
  530.  
  531.         if (f2 < 0.0F)
  532.         {
  533.             f2 = 0.0F;
  534.         }
  535.  
  536.         if (f3 < 0.0F)
  537.         {
  538.             f3 = 0.0F;
  539.         }
  540.  
  541.         int i = MathHelper.clamp((int)(f1 * 255.0F), 0, 255);
  542.         int j = MathHelper.clamp((int)(f2 * 255.0F), 0, 255);
  543.         int k = MathHelper.clamp((int)(f3 * 255.0F), 0, 255);
  544.         return -16777216 | i << 16 | j << 8 | k;
  545.     }
  546.  
  547.     @SideOnly(Side.CLIENT)
  548.     public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
  549.     {
  550.         int i = ((Integer)stateIn.getValue(POWER)).intValue();
  551.  
  552.         if (i != 0)
  553.         {
  554.             double d0 = (double)pos.getX() + 0.5D + ((double)rand.nextFloat() - 0.5D) * 0.2D;
  555.             double d1 = (double)((float)pos.getY() + 0.0625F);
  556.             double d2 = (double)pos.getZ() + 0.5D + ((double)rand.nextFloat() - 0.5D) * 0.2D;
  557.             float f = (float)i / 15.0F;
  558.             float f1 = f * 0.6F + 0.4F;
  559.             float f2 = Math.max(0.0F, f * f * 0.7F - 0.5F);
  560.             float f3 = Math.max(0.0F, f * f * 0.6F - 0.7F);
  561.             worldIn.spawnParticle(EnumParticleTypes.REDSTONE, d0, d1, d2, (double)f1, (double)f2, (double)f3);
  562.         }
  563.     }
  564.  
  565.     public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
  566.     {
  567.         return new ItemStack(Items.REDSTONE);
  568.     }
  569.  
  570.     /**
  571.      * Convert the given metadata into a BlockState for this Block
  572.      */
  573.     public IBlockState getStateFromMeta(int meta)
  574.     {
  575.         return this.getDefaultState().withProperty(POWER, Integer.valueOf(meta));
  576.     }
  577.  
  578.     @SideOnly(Side.CLIENT)
  579.     public BlockRenderLayer getBlockLayer()
  580.     {
  581.         return BlockRenderLayer.CUTOUT;
  582.     }
  583.  
  584.     /**
  585.      * Convert the BlockState into the correct metadata value
  586.      */
  587.     public int getMetaFromState(IBlockState state)
  588.     {
  589.         return ((Integer)state.getValue(POWER)).intValue();
  590.     }
  591.  
  592.     /**
  593.      * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
  594.      * blockstate.
  595.      */
  596.     public IBlockState withRotation(IBlockState state, Rotation rot)
  597.     {
  598.         switch (rot)
  599.         {
  600.             case CLOCKWISE_180:
  601.                 return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST)).withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST));
  602.             case COUNTERCLOCKWISE_90:
  603.                 return state.withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH));
  604.             case CLOCKWISE_90:
  605.                 return state.withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH)).withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH));
  606.             default:
  607.                 return state;
  608.         }
  609.     }
  610.  
  611.     /**
  612.      * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
  613.      * blockstate.
  614.      */
  615.     public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
  616.     {
  617.         switch (mirrorIn)
  618.         {
  619.             case LEFT_RIGHT:
  620.                 return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH));
  621.             case FRONT_BACK:
  622.                 return state.withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST));
  623.             default:
  624.                 return super.withMirror(state, mirrorIn);
  625.         }
  626.     }
  627.  
  628.     protected BlockStateContainer createBlockState()
  629.     {
  630.         return new BlockStateContainer(this, new IProperty[] {NORTH, EAST, SOUTH, WEST, POWER});
  631.     }
  632.  
  633.     /**
  634.      * Get the geometry of the queried face at the given position and state. This is used to decide whether things like
  635.      * buttons are allowed to be placed on the face, or how glass panes connect to the face, among other things.
  636.      * <p>
  637.      * Common values are {@code SOLID}, which is the default, and {@code UNDEFINED}, which represents something that
  638.      * does not fit the other descriptions and will generally cause other things not to connect to the face.
  639.      *
  640.      * @return an approximation of the form of the given face
  641.      */
  642.     public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
  643.     {
  644.         return BlockFaceShape.UNDEFINED;
  645.     }
  646.  
  647.     static enum EnumAttachPosition implements IStringSerializable
  648.     {
  649.         UP("up"),
  650.         SIDE("side"),
  651.         NONE("none");
  652.  
  653.         private final String name;
  654.  
  655.         private EnumAttachPosition(String name)
  656.         {
  657.             this.name = name;
  658.         }
  659.  
  660.         public String toString()
  661.         {
  662.             return this.getName();
  663.         }
  664.  
  665.         public String getName()
  666.         {
  667.             return this.name;
  668.         }
  669.     }
  670.    
  671.     @Override  
  672.       public void registerModels() {
  673.           CalumsMod.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
  674.       }
  675.    
  676. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement