Advertisement
Earthcomputer

BlockRedstoneWire.java

Oct 7th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 22.67 KB | None | 0 0
  1. package net.minecraft.block;
  2.  
  3. import com.google.common.collect.ImmutableMap;
  4. import com.google.common.collect.Lists;
  5. import com.google.common.collect.Maps;
  6. import com.google.common.collect.Sets;
  7. import java.util.EnumSet;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Random;
  11. import java.util.Set;
  12. import javax.annotation.Nullable;
  13. import net.minecraft.block.state.BlockFaceShape;
  14. import net.minecraft.block.state.IBlockState;
  15. import net.minecraft.init.Blocks;
  16. import net.minecraft.item.BlockItemUseContext;
  17. import net.minecraft.particles.RedstoneParticleData;
  18. import net.minecraft.state.EnumProperty;
  19. import net.minecraft.state.IntegerProperty;
  20. import net.minecraft.state.StateContainer;
  21. import net.minecraft.state.properties.BlockStateProperties;
  22. import net.minecraft.state.properties.RedstoneSide;
  23. import net.minecraft.util.BlockRenderLayer;
  24. import net.minecraft.util.EnumFacing;
  25. import net.minecraft.util.Mirror;
  26. import net.minecraft.util.Rotation;
  27. import net.minecraft.util.math.BlockPos;
  28. import net.minecraft.util.math.MathHelper;
  29. import net.minecraft.util.math.shapes.VoxelShape;
  30. import net.minecraft.world.IBlockReader;
  31. import net.minecraft.world.IWorld;
  32. import net.minecraft.world.IWorldReaderBase;
  33. import net.minecraft.world.World;
  34. import net.minecraftforge.api.distmarker.Dist;
  35. import net.minecraftforge.api.distmarker.OnlyIn;
  36.  
  37. public class BlockRedstoneWire extends Block
  38. {
  39.     public static final EnumProperty<RedstoneSide> NORTH = BlockStateProperties.REDSTONE_NORTH;
  40.     public static final EnumProperty<RedstoneSide> EAST = BlockStateProperties.REDSTONE_EAST;
  41.     public static final EnumProperty<RedstoneSide> SOUTH = BlockStateProperties.REDSTONE_SOUTH;
  42.     public static final EnumProperty<RedstoneSide> WEST = BlockStateProperties.REDSTONE_WEST;
  43.     public static final IntegerProperty POWER = BlockStateProperties.POWER_0_15;
  44.     public static final Map<EnumFacing, EnumProperty<RedstoneSide>> FACING_PROPERTY_MAP = Maps.newEnumMap(ImmutableMap.of(EnumFacing.NORTH, NORTH, EnumFacing.EAST, EAST, EnumFacing.SOUTH, SOUTH, EnumFacing.WEST, WEST));
  45.     protected static final VoxelShape[] SHAPES = new VoxelShape[] {Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D)};
  46.     private boolean canProvidePower = true;
  47.     private final Set<BlockPos> blocksNeedingUpdate = Sets.<BlockPos>newHashSet();
  48.  
  49.     public BlockRedstoneWire(Block.Properties builder)
  50.     {
  51.         super(builder);
  52.         this.setDefaultState((IBlockState)((IBlockState)((IBlockState)((IBlockState)((IBlockState)(this.stateContainer.getBaseState()).with(NORTH, RedstoneSide.NONE)).with(EAST, RedstoneSide.NONE)).with(SOUTH, RedstoneSide.NONE)).with(WEST, RedstoneSide.NONE)).with(POWER, Integer.valueOf(0)));
  53.     }
  54.  
  55.     public VoxelShape getShape(IBlockState state, IBlockReader worldIn, BlockPos pos)
  56.     {
  57.         return SHAPES[getAABBIndex(state)];
  58.     }
  59.  
  60.     private static int getAABBIndex(IBlockState state)
  61.     {
  62.         int i = 0;
  63.         boolean flag = state.get(NORTH) != RedstoneSide.NONE;
  64.         boolean flag1 = state.get(EAST) != RedstoneSide.NONE;
  65.         boolean flag2 = state.get(SOUTH) != RedstoneSide.NONE;
  66.         boolean flag3 = state.get(WEST) != RedstoneSide.NONE;
  67.  
  68.         if (flag || flag2 && !flag && !flag1 && !flag3)
  69.         {
  70.             i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
  71.         }
  72.  
  73.         if (flag1 || flag3 && !flag && !flag1 && !flag2)
  74.         {
  75.             i |= 1 << EnumFacing.EAST.getHorizontalIndex();
  76.         }
  77.  
  78.         if (flag2 || flag && !flag1 && !flag2 && !flag3)
  79.         {
  80.             i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
  81.         }
  82.  
  83.         if (flag3 || flag1 && !flag && !flag2 && !flag3)
  84.         {
  85.             i |= 1 << EnumFacing.WEST.getHorizontalIndex();
  86.         }
  87.  
  88.         return i;
  89.     }
  90.  
  91.     public IBlockState getStateForPlacement(BlockItemUseContext context)
  92.     {
  93.         IBlockReader iblockreader = context.getWorld();
  94.         BlockPos blockpos = context.getPos();
  95.         return (IBlockState)((IBlockState)((IBlockState)((IBlockState)this.getDefaultState().with(WEST, this.getSide(iblockreader, blockpos, EnumFacing.WEST))).with(EAST, this.getSide(iblockreader, blockpos, EnumFacing.EAST))).with(NORTH, this.getSide(iblockreader, blockpos, EnumFacing.NORTH))).with(SOUTH, this.getSide(iblockreader, blockpos, EnumFacing.SOUTH));
  96.     }
  97.  
  98.     public IBlockState updatePostPlacement(IBlockState stateIn, EnumFacing facing, IBlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos)
  99.     {
  100.         if (facing == EnumFacing.DOWN)
  101.         {
  102.             return stateIn;
  103.         }
  104.         else
  105.         {
  106.             return facing == EnumFacing.UP ? (IBlockState)((IBlockState)((IBlockState)((IBlockState)stateIn.with(WEST, this.getSide(worldIn, currentPos, EnumFacing.WEST))).with(EAST, this.getSide(worldIn, currentPos, EnumFacing.EAST))).with(NORTH, this.getSide(worldIn, currentPos, EnumFacing.NORTH))).with(SOUTH, this.getSide(worldIn, currentPos, EnumFacing.SOUTH)) : (IBlockState)stateIn.with(FACING_PROPERTY_MAP.get(facing), this.getSide(worldIn, currentPos, facing));
  107.         }
  108.     }
  109.  
  110.     public void updateDiagonalNeighbors(IBlockState state, IWorld worldIn, BlockPos pos, int flags)
  111.     {
  112.         try (BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain())
  113.         {
  114.             for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  115.             {
  116.                 RedstoneSide redstoneside = (RedstoneSide)state.get(FACING_PROPERTY_MAP.get(enumfacing));
  117.  
  118.                 if (redstoneside != RedstoneSide.NONE && worldIn.getBlockState(blockpos$pooledmutableblockpos.setPos(pos).move(enumfacing)).getBlock() != this)
  119.                 {
  120.                     blockpos$pooledmutableblockpos.move(EnumFacing.DOWN);
  121.                     IBlockState iblockstate = worldIn.getBlockState(blockpos$pooledmutableblockpos);
  122.  
  123.                     if (iblockstate.getBlock() != Blocks.OBSERVER)
  124.                     {
  125.                         BlockPos blockpos = blockpos$pooledmutableblockpos.offset(enumfacing.getOpposite());
  126.                         IBlockState iblockstate1 = iblockstate.updatePostPlacement(enumfacing.getOpposite(), worldIn.getBlockState(blockpos), worldIn, blockpos$pooledmutableblockpos, blockpos);
  127.                         replaceBlock(iblockstate, iblockstate1, worldIn, blockpos$pooledmutableblockpos, flags);
  128.                     }
  129.  
  130.                     blockpos$pooledmutableblockpos.setPos(pos).move(enumfacing).move(EnumFacing.UP);
  131.                     IBlockState iblockstate3 = worldIn.getBlockState(blockpos$pooledmutableblockpos);
  132.  
  133.                     if (iblockstate3.getBlock() != Blocks.OBSERVER)
  134.                     {
  135.                         BlockPos blockpos1 = blockpos$pooledmutableblockpos.offset(enumfacing.getOpposite());
  136.                         IBlockState iblockstate2 = iblockstate3.updatePostPlacement(enumfacing.getOpposite(), worldIn.getBlockState(blockpos1), worldIn, blockpos$pooledmutableblockpos, blockpos1);
  137.                         replaceBlock(iblockstate3, iblockstate2, worldIn, blockpos$pooledmutableblockpos, flags);
  138.                     }
  139.                 }
  140.             }
  141.         }
  142.     }
  143.  
  144.     private RedstoneSide getSide(IBlockReader worldIn, BlockPos pos, EnumFacing face)
  145.     {
  146.         BlockPos blockpos = pos.offset(face);
  147.         IBlockState iblockstate = worldIn.getBlockState(pos.offset(face));
  148.         IBlockState iblockstate1 = worldIn.getBlockState(pos.up());
  149.  
  150.         if (!iblockstate1.isNormalCube())
  151.         {
  152.             boolean flag = worldIn.getBlockState(blockpos).isTopSolid() || worldIn.getBlockState(blockpos).getBlock() == Blocks.GLOWSTONE;
  153.  
  154.             if (flag && canConnectUpwardsTo(worldIn.getBlockState(blockpos.up())))
  155.             {
  156.                 if (iblockstate.isBlockNormalCube())
  157.                 {
  158.                     return RedstoneSide.UP;
  159.                 }
  160.  
  161.                 return RedstoneSide.SIDE;
  162.             }
  163.         }
  164.  
  165.         return !canConnectTo(worldIn.getBlockState(blockpos), face) && (iblockstate.isNormalCube() || !canConnectUpwardsTo(worldIn.getBlockState(blockpos.down()))) ? RedstoneSide.NONE : RedstoneSide.SIDE;
  166.     }
  167.  
  168.     public boolean isFullCube(IBlockState state)
  169.     {
  170.         return false;
  171.     }
  172.  
  173.     public boolean isValidPosition(IBlockState state, IWorldReaderBase worldIn, BlockPos pos)
  174.     {
  175.         IBlockState iblockstate = worldIn.getBlockState(pos.down());
  176.         return iblockstate.isTopSolid() || iblockstate.getBlock() == Blocks.GLOWSTONE;
  177.     }
  178.  
  179.     private IBlockState updateSurroundingRedstone(World worldIn, BlockPos pos, IBlockState state)
  180.     {
  181.         state = this.func_212568_b(worldIn, pos, state);
  182.         List<BlockPos> list = Lists.newArrayList(this.blocksNeedingUpdate);
  183.         this.blocksNeedingUpdate.clear();
  184.  
  185.         for (BlockPos blockpos : list)
  186.         {
  187.             worldIn.notifyNeighborsOfStateChange(blockpos, this);
  188.         }
  189.  
  190.         return state;
  191.     }
  192.  
  193.     private IBlockState func_212568_b(World p_212568_1_, BlockPos p_212568_2_, IBlockState p_212568_3_)
  194.     {
  195.         IBlockState iblockstate = p_212568_3_;
  196.         int i = p_212568_3_.get(POWER);
  197.         int j = 0;
  198.         j = this.func_212567_a(j, p_212568_3_);
  199.         this.canProvidePower = false;
  200.         int k = p_212568_1_.getRedstonePowerFromNeighbors(p_212568_2_);
  201.         this.canProvidePower = true;
  202.  
  203.         if (k > 0 && k > j - 1)
  204.         {
  205.             j = k;
  206.         }
  207.  
  208.         int l = 0;
  209.  
  210.         for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  211.         {
  212.             BlockPos blockpos = p_212568_2_.offset(enumfacing);
  213.             boolean flag = blockpos.getX() != p_212568_2_.getX() || blockpos.getZ() != p_212568_2_.getZ();
  214.             IBlockState iblockstate1 = p_212568_1_.getBlockState(blockpos);
  215.  
  216.             if (flag)
  217.             {
  218.                 l = this.func_212567_a(l, iblockstate1);
  219.             }
  220.  
  221.             if (iblockstate1.isNormalCube() && !p_212568_1_.getBlockState(p_212568_2_.up()).isNormalCube())
  222.             {
  223.                 if (flag && p_212568_2_.getY() >= p_212568_2_.getY())
  224.                 {
  225.                     l = this.func_212567_a(l, p_212568_1_.getBlockState(blockpos.up()));
  226.                 }
  227.             }
  228.             else if (!iblockstate1.isNormalCube() && flag && p_212568_2_.getY() <= p_212568_2_.getY())
  229.             {
  230.                 l = this.func_212567_a(l, p_212568_1_.getBlockState(blockpos.down()));
  231.             }
  232.         }
  233.  
  234.         if (l > j)
  235.         {
  236.             j = l - 1;
  237.         }
  238.         else if (j > 0)
  239.         {
  240.             --j;
  241.         }
  242.         else
  243.         {
  244.             j = 0;
  245.         }
  246.  
  247.         if (k > j - 1)
  248.         {
  249.             j = k;
  250.         }
  251.  
  252.         if (i != j)
  253.         {
  254.             p_212568_3_ = (IBlockState)p_212568_3_.with(POWER, Integer.valueOf(j));
  255.  
  256.             if (p_212568_1_.getBlockState(p_212568_2_) == iblockstate)
  257.             {
  258.                 p_212568_1_.setBlockState(p_212568_2_, p_212568_3_, 2);
  259.             }
  260.  
  261.             this.blocksNeedingUpdate.add(p_212568_2_);
  262.  
  263.             for (EnumFacing enumfacing1 : EnumFacing.values())
  264.             {
  265.                 this.blocksNeedingUpdate.add(p_212568_2_.offset(enumfacing1));
  266.             }
  267.         }
  268.  
  269.         return p_212568_3_;
  270.     }
  271.  
  272.     private void notifyWireNeighborsOfStateChange(World worldIn, BlockPos pos)
  273.     {
  274.         if (worldIn.getBlockState(pos).getBlock() == this)
  275.         {
  276.             worldIn.notifyNeighborsOfStateChange(pos, this);
  277.  
  278.             for (EnumFacing enumfacing : EnumFacing.values())
  279.             {
  280.                 worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
  281.             }
  282.         }
  283.     }
  284.  
  285.     public void onBlockAdded(IBlockState state, World worldIn, BlockPos pos, IBlockState oldState)
  286.     {
  287.         if (oldState.getBlock() != state.getBlock() && !worldIn.isRemote)
  288.         {
  289.             this.updateSurroundingRedstone(worldIn, pos, state);
  290.  
  291.             for (EnumFacing enumfacing : EnumFacing.Plane.VERTICAL)
  292.             {
  293.                 worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
  294.             }
  295.  
  296.             for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
  297.             {
  298.                 this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
  299.             }
  300.  
  301.             for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
  302.             {
  303.                 BlockPos blockpos = pos.offset(enumfacing2);
  304.  
  305.                 if (worldIn.getBlockState(blockpos).isNormalCube())
  306.                 {
  307.                     this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
  308.                 }
  309.                 else
  310.                 {
  311.                     this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
  312.                 }
  313.             }
  314.         }
  315.     }
  316.  
  317.     public void onReplaced(IBlockState state, World worldIn, BlockPos pos, IBlockState newState, boolean isMoving)
  318.     {
  319.         if (!isMoving && state.getBlock() != newState.getBlock())
  320.         {
  321.             super.onReplaced(state, worldIn, pos, newState, isMoving);
  322.  
  323.             if (!worldIn.isRemote)
  324.             {
  325.                 for (EnumFacing enumfacing : EnumFacing.values())
  326.                 {
  327.                     worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
  328.                 }
  329.  
  330.                 this.updateSurroundingRedstone(worldIn, pos, state);
  331.  
  332.                 for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
  333.                 {
  334.                     this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
  335.                 }
  336.  
  337.                 for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
  338.                 {
  339.                     BlockPos blockpos = pos.offset(enumfacing2);
  340.  
  341.                     if (worldIn.getBlockState(blockpos).isNormalCube())
  342.                     {
  343.                         this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
  344.                     }
  345.                     else
  346.                     {
  347.                         this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
  348.                     }
  349.                 }
  350.             }
  351.         }
  352.     }
  353.  
  354.     private int func_212567_a(int p_212567_1_, IBlockState p_212567_2_)
  355.     {
  356.         if (p_212567_2_.getBlock() != this)
  357.         {
  358.             return p_212567_1_;
  359.         }
  360.         else
  361.         {
  362.             int i = p_212567_2_.get(POWER);
  363.             return i > p_212567_1_ ? i : p_212567_1_;
  364.         }
  365.     }
  366.  
  367.     public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
  368.     {
  369.         if (!worldIn.isRemote)
  370.         {
  371.             if (state.isValidPosition(worldIn, pos))
  372.             {
  373.                 this.updateSurroundingRedstone(worldIn, pos, state);
  374.             }
  375.             else
  376.             {
  377.                 state.dropBlockAsItem(worldIn, pos, 0);
  378.                 worldIn.removeBlock(pos);
  379.             }
  380.         }
  381.     }
  382.  
  383.     public int getStrongPower(IBlockState blockState, IBlockReader blockAccess, BlockPos pos, EnumFacing side)
  384.     {
  385.         return !this.canProvidePower ? 0 : blockState.getWeakPower(blockAccess, pos, side);
  386.     }
  387.  
  388.     public int getWeakPower(IBlockState blockState, IBlockReader blockAccess, BlockPos pos, EnumFacing side)
  389.     {
  390.         if (!this.canProvidePower)
  391.         {
  392.             return 0;
  393.         }
  394.         else
  395.         {
  396.             int i = blockState.get(POWER);
  397.  
  398.             if (i == 0)
  399.             {
  400.                 return 0;
  401.             }
  402.             else if (side == EnumFacing.UP)
  403.             {
  404.                 return i;
  405.             }
  406.             else
  407.             {
  408.                 EnumSet<EnumFacing> enumset = EnumSet.<EnumFacing>noneOf(EnumFacing.class);
  409.  
  410.                 for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
  411.                 {
  412.                     if (this.isPowerSourceAt(blockAccess, pos, enumfacing))
  413.                     {
  414.                         enumset.add(enumfacing);
  415.                     }
  416.                 }
  417.  
  418.                 if (side.getAxis().isHorizontal() && enumset.isEmpty())
  419.                 {
  420.                     return i;
  421.                 }
  422.                 else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY()))
  423.                 {
  424.                     return i;
  425.                 }
  426.                 else
  427.                 {
  428.                     return 0;
  429.                 }
  430.             }
  431.         }
  432.     }
  433.  
  434.     private boolean isPowerSourceAt(IBlockReader worldIn, BlockPos pos, EnumFacing side)
  435.     {
  436.         BlockPos blockpos = pos.offset(side);
  437.         IBlockState iblockstate = worldIn.getBlockState(blockpos);
  438.         boolean flag = iblockstate.isNormalCube();
  439.         boolean flag1 = worldIn.getBlockState(pos.up()).isNormalCube();
  440.  
  441.         if (!flag1 && flag && canConnectUpwardsTo(worldIn, blockpos.up()))
  442.         {
  443.             return true;
  444.         }
  445.         else if (canConnectTo(iblockstate, side))
  446.         {
  447.             return true;
  448.         }
  449.         else if (iblockstate.getBlock() == Blocks.REPEATER && iblockstate.get(BlockRedstoneDiode.POWERED) && iblockstate.get(BlockRedstoneDiode.HORIZONTAL_FACING) == side)
  450.         {
  451.             return true;
  452.         }
  453.         else
  454.         {
  455.             return !flag && canConnectUpwardsTo(worldIn, blockpos.down());
  456.         }
  457.     }
  458.  
  459.     protected static boolean canConnectUpwardsTo(IBlockReader worldIn, BlockPos pos)
  460.     {
  461.         return canConnectUpwardsTo(worldIn.getBlockState(pos));
  462.     }
  463.  
  464.     protected static boolean canConnectUpwardsTo(IBlockState state)
  465.     {
  466.         return canConnectTo(state, (EnumFacing)null);
  467.     }
  468.  
  469.     protected static boolean canConnectTo(IBlockState blockState, @Nullable EnumFacing side)
  470.     {
  471.         Block block = blockState.getBlock();
  472.  
  473.         if (block == Blocks.REDSTONE_WIRE)
  474.         {
  475.             return true;
  476.         }
  477.         else if (blockState.getBlock() == Blocks.REPEATER)
  478.         {
  479.             EnumFacing enumfacing = (EnumFacing)blockState.get(BlockRedstoneRepeater.HORIZONTAL_FACING);
  480.             return enumfacing == side || enumfacing.getOpposite() == side;
  481.         }
  482.         else if (Blocks.OBSERVER == blockState.getBlock())
  483.         {
  484.             return side == blockState.get(BlockObserver.FACING);
  485.         }
  486.         else
  487.         {
  488.             return blockState.canProvidePower() && side != null;
  489.         }
  490.     }
  491.  
  492.     public boolean canProvidePower(IBlockState state)
  493.     {
  494.         return this.canProvidePower;
  495.     }
  496.  
  497.     @OnlyIn(Dist.CLIENT)
  498.     public static int colorMultiplier(int p_176337_0_)
  499.     {
  500.         float f = (float)p_176337_0_ / 15.0F;
  501.         float f1 = f * 0.6F + 0.4F;
  502.  
  503.         if (p_176337_0_ == 0)
  504.         {
  505.             f1 = 0.3F;
  506.         }
  507.  
  508.         float f2 = f * f * 0.7F - 0.5F;
  509.         float f3 = f * f * 0.6F - 0.7F;
  510.  
  511.         if (f2 < 0.0F)
  512.         {
  513.             f2 = 0.0F;
  514.         }
  515.  
  516.         if (f3 < 0.0F)
  517.         {
  518.             f3 = 0.0F;
  519.         }
  520.  
  521.         int i = MathHelper.clamp((int)(f1 * 255.0F), 0, 255);
  522.         int j = MathHelper.clamp((int)(f2 * 255.0F), 0, 255);
  523.         int k = MathHelper.clamp((int)(f3 * 255.0F), 0, 255);
  524.         return -16777216 | i << 16 | j << 8 | k;
  525.     }
  526.  
  527.     @OnlyIn(Dist.CLIENT)
  528.     public void animateTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
  529.     {
  530.         int i = stateIn.get(POWER);
  531.  
  532.         if (i != 0)
  533.         {
  534.             double d0 = (double)pos.getX() + 0.5D + ((double)rand.nextFloat() - 0.5D) * 0.2D;
  535.             double d1 = (double)((float)pos.getY() + 0.0625F);
  536.             double d2 = (double)pos.getZ() + 0.5D + ((double)rand.nextFloat() - 0.5D) * 0.2D;
  537.             float f = (float)i / 15.0F;
  538.             float f1 = f * 0.6F + 0.4F;
  539.             float f2 = Math.max(0.0F, f * f * 0.7F - 0.5F);
  540.             float f3 = Math.max(0.0F, f * f * 0.6F - 0.7F);
  541.             worldIn.spawnParticle(new RedstoneParticleData(f1, f2, f3, 1.0F), d0, d1, d2, 0.0D, 0.0D, 0.0D);
  542.         }
  543.     }
  544.  
  545.     public BlockRenderLayer getRenderLayer()
  546.     {
  547.         return BlockRenderLayer.CUTOUT;
  548.     }
  549.  
  550.     public IBlockState rotate(IBlockState state, Rotation rot)
  551.     {
  552.         switch (rot)
  553.         {
  554.             case CLOCKWISE_180:
  555.                 return (IBlockState)((IBlockState)((IBlockState)((IBlockState)state.with(NORTH, state.get(SOUTH))).with(EAST, state.get(WEST))).with(SOUTH, state.get(NORTH))).with(WEST, state.get(EAST));
  556.             case COUNTERCLOCKWISE_90:
  557.                 return (IBlockState)((IBlockState)((IBlockState)((IBlockState)state.with(NORTH, state.get(EAST))).with(EAST, state.get(SOUTH))).with(SOUTH, state.get(WEST))).with(WEST, state.get(NORTH));
  558.             case CLOCKWISE_90:
  559.                 return (IBlockState)((IBlockState)((IBlockState)((IBlockState)state.with(NORTH, state.get(WEST))).with(EAST, state.get(NORTH))).with(SOUTH, state.get(EAST))).with(WEST, state.get(SOUTH));
  560.             default:
  561.                 return state;
  562.         }
  563.     }
  564.  
  565.     public IBlockState mirror(IBlockState state, Mirror mirrorIn)
  566.     {
  567.         switch (mirrorIn)
  568.         {
  569.             case LEFT_RIGHT:
  570.                 return (IBlockState)((IBlockState)state.with(NORTH, state.get(SOUTH))).with(SOUTH, state.get(NORTH));
  571.             case FRONT_BACK:
  572.                 return (IBlockState)((IBlockState)state.with(EAST, state.get(WEST))).with(WEST, state.get(EAST));
  573.             default:
  574.                 return super.mirror(state, mirrorIn);
  575.         }
  576.     }
  577.  
  578.     protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder)
  579.     {
  580.         builder.add(NORTH, EAST, SOUTH, WEST, POWER);
  581.     }
  582.  
  583.     public BlockFaceShape getBlockFaceShape(IBlockReader worldIn, IBlockState state, BlockPos pos, EnumFacing face)
  584.     {
  585.         return BlockFaceShape.UNDEFINED;
  586.     }
  587. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement