public class BlockRedstoneComparator extends BlockRedstoneDiode implements ITileEntityProvider {
  public static final PropertyBool POWERED = PropertyBool.create("powered");
  public static final PropertyEnum<BlockRedstoneComparator.Mode> MODE =
      PropertyEnum.<BlockRedstoneComparator.Mode>create("mode", BlockRedstoneComparator.Mode.class);

  public BlockRedstoneComparator(boolean powered) {
    super(powered);
    this.setDefaultState(
        this.blockState
            .getBaseState()
            .withProperty(FACING, EnumFacing.NORTH)
            .withProperty(POWERED, Boolean.valueOf(false))
            .withProperty(MODE, BlockRedstoneComparator.Mode.COMPARE));
    this.isBlockContainer = true;
  }

  /** Gets the localized name of this block. Used for the statistics page. */
  public String getLocalizedName() {
    return I18n.translateToLocal("item.comparator.name");
  }

  /** Get the Item that this Block should drop when harvested. */
  @Nullable
  public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    return Items.COMPARATOR;
  }

  public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
    return new ItemStack(Items.COMPARATOR);
  }

  protected int getDelay(IBlockState state) {
    return 2;
  }

  protected IBlockState getPoweredState(IBlockState unpoweredState) {
    Boolean obool = (Boolean) unpoweredState.getValue(POWERED);
    BlockRedstoneComparator.Mode blockredstonecomparator$mode =
        (BlockRedstoneComparator.Mode) unpoweredState.getValue(MODE);
    EnumFacing enumfacing = (EnumFacing) unpoweredState.getValue(FACING);
    return Blocks.POWERED_COMPARATOR
        .getDefaultState()
        .withProperty(FACING, enumfacing)
        .withProperty(POWERED, obool)
        .withProperty(MODE, blockredstonecomparator$mode);
  }

  protected IBlockState getUnpoweredState(IBlockState poweredState) {
    Boolean obool = (Boolean) poweredState.getValue(POWERED);
    BlockRedstoneComparator.Mode blockredstonecomparator$mode =
        (BlockRedstoneComparator.Mode) poweredState.getValue(MODE);
    EnumFacing enumfacing = (EnumFacing) poweredState.getValue(FACING);
    return Blocks.UNPOWERED_COMPARATOR
        .getDefaultState()
        .withProperty(FACING, enumfacing)
        .withProperty(POWERED, obool)
        .withProperty(MODE, blockredstonecomparator$mode);
  }

  protected boolean isPowered(IBlockState state) {
    return this.isRepeaterPowered || ((Boolean) state.getValue(POWERED)).booleanValue();
  }

  protected int getActiveSignal(IBlockAccess worldIn, BlockPos pos, IBlockState state) {
    TileEntity tileentity = worldIn.getTileEntity(pos);
    return tileentity instanceof TileEntityComparator
        ? ((TileEntityComparator) tileentity).getOutputSignal()
        : 0;
  }

  private int calculateOutput(World worldIn, BlockPos pos, IBlockState state) {
    return state.getValue(MODE) == BlockRedstoneComparator.Mode.SUBTRACT
        ? Math.max(
            this.calculateInputStrength(worldIn, pos, state)
                - this.getPowerOnSides(worldIn, pos, state),
            0)
        : this.calculateInputStrength(worldIn, pos, state);
  }

  protected boolean shouldBePowered(World worldIn, BlockPos pos, IBlockState state) {
    int i = this.calculateInputStrength(worldIn, pos, state);

    if (i >= 15) {
      return true;
    } else if (i == 0) {
      return false;
    } else {
      int j = this.getPowerOnSides(worldIn, pos, state);
      return j == 0 ? true : i >= j;
    }
  }

  protected int calculateInputStrength(World worldIn, BlockPos pos, IBlockState state) {
    int i = super.calculateInputStrength(worldIn, pos, state);
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
    BlockPos blockpos = pos.offset(enumfacing);
    IBlockState iblockstate = worldIn.getBlockState(blockpos);

    if (iblockstate.hasComparatorInputOverride()) {
      i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
    } else if (i < 15 && iblockstate.isNormalCube()) {
      blockpos = blockpos.offset(enumfacing);
      iblockstate = worldIn.getBlockState(blockpos);

      if (iblockstate.hasComparatorInputOverride()) {
        i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
      } else if (iblockstate.getMaterial() == Material.AIR) {
        EntityItemFrame entityitemframe = this.findItemFrame(worldIn, enumfacing, blockpos);

        if (entityitemframe != null) {
          i = entityitemframe.getAnalogOutput();
        }
      }
    }

    return i;
  }

  @Nullable
  private EntityItemFrame findItemFrame(World worldIn, final EnumFacing facing, BlockPos pos) {
    List<EntityItemFrame> list =
        worldIn.<EntityItemFrame>getEntitiesWithinAABB(
            EntityItemFrame.class,
            new AxisAlignedBB(
                (double) pos.getX(),
                (double) pos.getY(),
                (double) pos.getZ(),
                (double) (pos.getX() + 1),
                (double) (pos.getY() + 1),
                (double) (pos.getZ() + 1)),
            new Predicate<Entity>() {
              public boolean apply(@Nullable Entity p_apply_1_) {
                return p_apply_1_ != null && p_apply_1_.getHorizontalFacing() == facing;
              }
            });
    return list.size() == 1 ? (EntityItemFrame) list.get(0) : null;
  }

  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumHand hand,
      @Nullable ItemStack heldItem,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (!playerIn.capabilities.allowEdit) {
      return false;
    } else {
      state = state.cycleProperty(MODE);
      float f = state.getValue(MODE) == BlockRedstoneComparator.Mode.SUBTRACT ? 0.55F : 0.5F;
      worldIn.playSound(
          playerIn, pos, SoundEvents.BLOCK_COMPARATOR_CLICK, SoundCategory.BLOCKS, 0.3F, f);
      worldIn.setBlockState(pos, state, 2);
      this.onStateChange(worldIn, pos, state);
      return true;
    }
  }

  protected void updateState(World worldIn, BlockPos pos, IBlockState state) {
    if (!worldIn.isBlockTickPending(pos, this)) {
      int i = this.calculateOutput(worldIn, pos, state);
      TileEntity tileentity = worldIn.getTileEntity(pos);
      int j =
          tileentity instanceof TileEntityComparator
              ? ((TileEntityComparator) tileentity).getOutputSignal()
              : 0;

      if (i != j || this.isPowered(state) != this.shouldBePowered(worldIn, pos, state)) {
        if (this.isFacingTowardsRepeater(worldIn, pos, state)) {
          worldIn.updateBlockTick(pos, this, 2, -1);
        } else {
          worldIn.updateBlockTick(pos, this, 2, 0);
        }
      }
    }
  }

  private void onStateChange(World worldIn, BlockPos pos, IBlockState state) {
    int i = this.calculateOutput(worldIn, pos, state);
    TileEntity tileentity = worldIn.getTileEntity(pos);
    int j = 0;

    if (tileentity instanceof TileEntityComparator) {
      TileEntityComparator tileentitycomparator = (TileEntityComparator) tileentity;
      j = tileentitycomparator.getOutputSignal();
      tileentitycomparator.setOutputSignal(i);
    }

    if (j != i || state.getValue(MODE) == BlockRedstoneComparator.Mode.COMPARE) {
      boolean flag1 = this.shouldBePowered(worldIn, pos, state);
      boolean flag = this.isPowered(state);

      if (flag && !flag1) {
        worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)), 2);
      } else if (!flag && flag1) {
        worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 2);
      }

      this.notifyNeighbors(worldIn, pos, state);
    }
  }

  public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (this.isRepeaterPowered) {
      worldIn.setBlockState(
          pos, this.getUnpoweredState(state).withProperty(POWERED, Boolean.valueOf(true)), 4);
    }

    this.onStateChange(worldIn, pos, state);
  }

  public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    super.onBlockAdded(worldIn, pos, state);
    worldIn.setTileEntity(pos, this.createNewTileEntity(worldIn, 0));
  }

  public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    super.breakBlock(worldIn, pos, state);
    worldIn.removeTileEntity(pos);
    this.notifyNeighbors(worldIn, pos, state);
  }

  /**
   * Called on both Client and Server when World#addBlockEvent is called. On the Server, this may
   * perform additional changes to the world, like pistons replacing the block with an extended
   * base. On the client, the update may involve replacing tile entities, playing sounds, or
   * performing other visual actions to reflect the server side changes.
   *
   * @param state The block state retrieved from the block position prior to this method being
   *     invoked
   * @param pos The position of the block event. Can be used to retrieve tile entities.
   */
  public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
    super.eventReceived(state, worldIn, pos, id, param);
    TileEntity tileentity = worldIn.getTileEntity(pos);
    return tileentity == null ? false : tileentity.receiveClientEvent(id, param);
  }

  /** Returns a new instance of a block's tile entity class. Called on placing the block. */
  public TileEntity createNewTileEntity(World worldIn, int meta) {
    return new TileEntityComparator();
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    return this.getDefaultState()
        .withProperty(FACING, EnumFacing.getHorizontal(meta))
        .withProperty(POWERED, Boolean.valueOf((meta & 8) > 0))
        .withProperty(
            MODE,
            (meta & 4) > 0
                ? BlockRedstoneComparator.Mode.SUBTRACT
                : BlockRedstoneComparator.Mode.COMPARE);
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;
    i = i | ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();

    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      i |= 8;
    }

    if (state.getValue(MODE) == BlockRedstoneComparator.Mode.SUBTRACT) {
      i |= 4;
    }

    return i;
  }

  /**
   * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable,
   * returns the passed blockstate.
   */
  public IBlockState withRotation(IBlockState state, Rotation rot) {
    return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
  }

  /**
   * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns
   * the passed blockstate.
   */
  public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
    return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING)));
  }

  protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] {FACING, MODE, POWERED});
  }

  /**
   * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments
   * to the IBlockstate
   */
  public IBlockState onBlockPlaced(
      World worldIn,
      BlockPos pos,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ,
      int meta,
      EntityLivingBase placer) {
    return this.getDefaultState()
        .withProperty(FACING, placer.getHorizontalFacing().getOpposite())
        .withProperty(POWERED, Boolean.valueOf(false))
        .withProperty(MODE, BlockRedstoneComparator.Mode.COMPARE);
  }

  @Override
  public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
    if (pos.getY() == neighbor.getY() && world instanceof World) {
      neighborChanged(
          world.getBlockState(pos), (World) world, pos, world.getBlockState(neighbor).getBlock());
    }
  }

  @Override
  public boolean getWeakChanges(IBlockAccess world, BlockPos pos) {
    return true;
  }

  public static enum Mode implements IStringSerializable {
    COMPARE("compare"),
    SUBTRACT("subtract");

    private final String name;

    private Mode(String name) {
      this.name = name;
    }

    public String toString() {
      return this.name;
    }

    public String getName() {
      return this.name;
    }
  }
}
public class BlockJukebox extends BlockContainer {
  public static final PropertyBool HAS_RECORD = PropertyBool.create("has_record");

  public static void func_189873_a(DataFixer p_189873_0_) {
    p_189873_0_.registerWalker(
        FixTypes.BLOCK_ENTITY, new ItemStackData("RecordPlayer", new String[] {"RecordItem"}));
  }

  protected BlockJukebox() {
    super(Material.WOOD, MapColor.DIRT);
    this.setDefaultState(
        this.blockState.getBaseState().withProperty(HAS_RECORD, Boolean.valueOf(false)));
    this.setCreativeTab(CreativeTabs.DECORATIONS);
  }

  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumHand hand,
      @Nullable ItemStack heldItem,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (((Boolean) state.getValue(HAS_RECORD)).booleanValue()) {
      this.dropRecord(worldIn, pos, state);
      state = state.withProperty(HAS_RECORD, Boolean.valueOf(false));
      worldIn.setBlockState(pos, state, 2);
      return true;
    } else {
      return false;
    }
  }

  public void insertRecord(World worldIn, BlockPos pos, IBlockState state, ItemStack recordStack) {
    if (!worldIn.isRemote) {
      TileEntity tileentity = worldIn.getTileEntity(pos);

      if (tileentity instanceof BlockJukebox.TileEntityJukebox) {
        ((BlockJukebox.TileEntityJukebox) tileentity).setRecord(recordStack.copy());
        worldIn.setBlockState(pos, state.withProperty(HAS_RECORD, Boolean.valueOf(true)), 2);
      }
    }
  }

  private void dropRecord(World worldIn, BlockPos pos, IBlockState state) {
    if (!worldIn.isRemote) {
      TileEntity tileentity = worldIn.getTileEntity(pos);

      if (tileentity instanceof BlockJukebox.TileEntityJukebox) {
        BlockJukebox.TileEntityJukebox blockjukebox$tileentityjukebox =
            (BlockJukebox.TileEntityJukebox) tileentity;
        ItemStack itemstack = blockjukebox$tileentityjukebox.getRecord();

        if (itemstack != null) {
          worldIn.playEvent(1010, pos, 0);
          worldIn.playRecord(pos, (SoundEvent) null);
          blockjukebox$tileentityjukebox.setRecord((ItemStack) null);
          float f = 0.7F;
          double d0 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
          double d1 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.06000000238418579D + 0.6D;
          double d2 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
          ItemStack itemstack1 = itemstack.copy();
          EntityItem entityitem =
              new EntityItem(
                  worldIn,
                  (double) pos.getX() + d0,
                  (double) pos.getY() + d1,
                  (double) pos.getZ() + d2,
                  itemstack1);
          entityitem.setDefaultPickupDelay();
          worldIn.spawnEntityInWorld(entityitem);
        }
      }
    }
  }

  public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    this.dropRecord(worldIn, pos, state);
    super.breakBlock(worldIn, pos, state);
  }

  /** Spawns this Block's drops into the World as EntityItems. */
  public void dropBlockAsItemWithChance(
      World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) {
    if (!worldIn.isRemote) {
      super.dropBlockAsItemWithChance(worldIn, pos, state, chance, 0);
    }
  }

  /** Returns a new instance of a block's tile entity class. Called on placing the block. */
  public TileEntity createNewTileEntity(World worldIn, int meta) {
    return new BlockJukebox.TileEntityJukebox();
  }

  public boolean hasComparatorInputOverride(IBlockState state) {
    return true;
  }

  public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) {
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (tileentity instanceof BlockJukebox.TileEntityJukebox) {
      ItemStack itemstack = ((BlockJukebox.TileEntityJukebox) tileentity).getRecord();

      if (itemstack != null) {
        return Item.getIdFromItem(itemstack.getItem()) + 1 - Item.getIdFromItem(Items.RECORD_13);
      }
    }

    return 0;
  }

  /**
   * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids,
   * -1 is no render
   */
  public EnumBlockRenderType getRenderType(IBlockState state) {
    return EnumBlockRenderType.MODEL;
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    return this.getDefaultState().withProperty(HAS_RECORD, Boolean.valueOf(meta > 0));
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    return ((Boolean) state.getValue(HAS_RECORD)).booleanValue() ? 1 : 0;
  }

  protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] {HAS_RECORD});
  }

  public static class TileEntityJukebox extends TileEntity {
    private ItemStack record;

    public void readFromNBT(NBTTagCompound compound) {
      super.readFromNBT(compound);

      if (compound.hasKey("RecordItem", 10)) {
        this.setRecord(ItemStack.loadItemStackFromNBT(compound.getCompoundTag("RecordItem")));
      } else if (compound.getInteger("Record") > 0) {
        this.setRecord(new ItemStack(Item.getItemById(compound.getInteger("Record"))));
      }
    }

    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
      super.writeToNBT(compound);

      if (this.getRecord() != null) {
        compound.setTag("RecordItem", this.getRecord().writeToNBT(new NBTTagCompound()));
      }

      return compound;
    }

    @Nullable
    public ItemStack getRecord() {
      return this.record;
    }

    public void setRecord(@Nullable ItemStack recordStack) {
      this.record = recordStack;
      this.markDirty();
    }
  }
}
示例#3
0
public class ElectricFurnaceAdv extends BlockContainerTomsMod {
  public static final PropertyDirection FACING =
      PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
  public static final PropertyBool ACTIVE = PropertyBool.create("active");

  public ElectricFurnaceAdv() {
    super(Material.IRON);
  }

  @Override
  public TileEntity createNewTileEntity(World worldIn, int meta) {
    return new TileEntityElectricFurnaceAdv();
  }

  @Override
  public IBlockState onBlockPlaced(
      World worldIn,
      BlockPos pos,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ,
      int meta,
      EntityLivingBase placer) {
    EnumFacing f = TomsModUtils.getDirectionFacing(placer, false);
    return this.getDefaultState().withProperty(FACING, f.getOpposite()).withProperty(ACTIVE, false);
  }

  @Override
  protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] {FACING, ACTIVE});
  }
  /** Convert the given metadata into a BlockState for this Block */
  @Override
  public IBlockState getStateFromMeta(int meta) {
    EnumFacing enumfacing = EnumFacing.getFront(meta % 6);

    if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
      enumfacing = EnumFacing.NORTH;
    }
    // System.out.println("getState");
    return this.getDefaultState().withProperty(FACING, enumfacing).withProperty(ACTIVE, meta > 5);
  }

  /** Convert the BlockState into the correct metadata value */
  @Override
  public int getMetaFromState(IBlockState state) { // System.out.println("getMeta");
    return state.getValue(FACING).getIndex() + (state.getValue(ACTIVE) ? 6 : 0);
  }

  @Override
  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumHand hand,
      ItemStack heldItem,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (!worldIn.isRemote)
      playerIn.openGui(
          CoreInit.modInstance,
          GuiIDs.electricFurnaceAdv.ordinal(),
          worldIn,
          pos.getX(),
          pos.getY(),
          pos.getZ());
    return true;
  }
}
示例#4
0
public class BlockSponge extends Block {
  public static final PropertyBool WET_PROP = PropertyBool.create("wet");

  protected BlockSponge() {
    super(Material.sponge);
    this.setDefaultState(
        this.blockState.getBaseState().withProperty(WET_PROP, Boolean.valueOf(false)));
    this.setCreativeTab(CreativeTabs.tabBlock);
  }

  /** Get the damage value that this Block should drop */
  public int damageDropped(IBlockState state) {
    return ((Boolean) state.getValue(WET_PROP)).booleanValue() ? 1 : 0;
  }

  public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    this.setWet(worldIn, pos, state);
  }

  public void onNeighborBlockChange(
      World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
    this.setWet(worldIn, pos, state);
    super.onNeighborBlockChange(worldIn, pos, state, neighborBlock);
  }

  protected void setWet(World worldIn, BlockPos p_176311_2_, IBlockState p_176311_3_) {
    if (!((Boolean) p_176311_3_.getValue(WET_PROP)).booleanValue()
        && this.absorbWater(worldIn, p_176311_2_)) {
      worldIn.setBlockState(
          p_176311_2_, p_176311_3_.withProperty(WET_PROP, Boolean.valueOf(true)), 2);
      worldIn.playAuxSFX(2001, p_176311_2_, Block.getIdFromBlock(Blocks.water));
    }
  }

  private boolean absorbWater(World worldIn, BlockPos p_176312_2_) {
    LinkedList var3 = Lists.newLinkedList();
    ArrayList var4 = Lists.newArrayList();
    var3.add(new Tuple(p_176312_2_, Integer.valueOf(0)));
    int var5 = 0;
    BlockPos var7;

    while (!var3.isEmpty()) {
      Tuple var6 = (Tuple) var3.poll();
      var7 = (BlockPos) var6.getFirst();
      int var8 = ((Integer) var6.getSecond()).intValue();
      EnumFacing[] var9 = EnumFacing.values();
      int var10 = var9.length;

      for (int var11 = 0; var11 < var10; ++var11) {
        EnumFacing var12 = var9[var11];
        BlockPos var13 = var7.offset(var12);

        if (worldIn.getBlockState(var13).getBlock().getMaterial() == Material.water) {
          worldIn.setBlockState(var13, Blocks.air.getDefaultState(), 2);
          var4.add(var13);
          ++var5;

          if (var8 < 6) {
            var3.add(new Tuple(var13, Integer.valueOf(var8 + 1)));
          }
        }
      }

      if (var5 > 64) {
        break;
      }
    }

    Iterator var14 = var4.iterator();

    while (var14.hasNext()) {
      var7 = (BlockPos) var14.next();
      worldIn.notifyNeighborsOfStateChange(var7, Blocks.air);
    }

    return var5 > 0;
  }

  /** returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */
  public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
    list.add(new ItemStack(itemIn, 1, 0));
    list.add(new ItemStack(itemIn, 1, 1));
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    return this.getDefaultState().withProperty(WET_PROP, Boolean.valueOf((meta & 1) == 1));
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    return ((Boolean) state.getValue(WET_PROP)).booleanValue() ? 1 : 0;
  }

  protected BlockState createBlockState() {
    return new BlockState(this, new IProperty[] {WET_PROP});
  }

  public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (((Boolean) state.getValue(WET_PROP)).booleanValue()) {
      EnumFacing var5 = EnumFacing.random(rand);

      if (var5 != EnumFacing.UP && !World.doesBlockHaveSolidTopSurface(worldIn, pos.offset(var5))) {
        double var6 = (double) pos.getX();
        double var8 = (double) pos.getY();
        double var10 = (double) pos.getZ();

        if (var5 == EnumFacing.DOWN) {
          var8 -= 0.05D;
          var6 += rand.nextDouble();
          var10 += rand.nextDouble();
        } else {
          var8 += rand.nextDouble() * 0.8D;

          if (var5.getAxis() == EnumFacing.Axis.X) {
            var10 += rand.nextDouble();

            if (var5 == EnumFacing.EAST) {
              ++var6;
            } else {
              var6 += 0.05D;
            }
          } else {
            var6 += rand.nextDouble();

            if (var5 == EnumFacing.SOUTH) {
              ++var10;
            } else {
              var10 += 0.05D;
            }
          }
        }

        worldIn.spawnParticle(
            EnumParticleTypes.DRIP_WATER, var6, var8, var10, 0.0D, 0.0D, 0.0D, new int[0]);
      }
    }
  }
}
public class BlockKeypadFurnace extends BlockOwnable {

  public static final PropertyDirection FACING =
      PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
  public static final PropertyBool OPEN = PropertyBool.create("open");

  public BlockKeypadFurnace(Material materialIn) {
    super(materialIn);
  }

  /**
   * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the
   * shared face of two adjacent blocks and also whether the player can attach torches, redstone
   * wire, etc to this block.
   */
  public boolean isOpaqueCube() {
    return false;
  }

  /**
   * If this block doesn't render as an ordinary block it will return False (examples: signs,
   * buttons, stairs, etc)
   */
  public boolean isNormalCube() {
    return false;
  }

  public boolean onBlockActivated(
      World par1World,
      BlockPos pos,
      IBlockState state,
      EntityPlayer par5EntityPlayer,
      EnumFacing side,
      float par7,
      float par8,
      float par9) {
    if (!par1World.isRemote) {
      if (par5EntityPlayer.getCurrentEquippedItem() == null
          || (par5EntityPlayer.getCurrentEquippedItem() != null
              && par5EntityPlayer.getCurrentEquippedItem().getItem()
                  != mod_SecurityCraft.Codebreaker)) {
        TileEntityKeypadFurnace TE = (TileEntityKeypadFurnace) par1World.getTileEntity(pos);
        if (TE.getPassword() != null && !TE.getPassword().isEmpty()) {
          par5EntityPlayer.openGui(
              mod_SecurityCraft.instance,
              GuiHandler.INSERT_PASSWORD_ID,
              par1World,
              pos.getX(),
              pos.getY(),
              pos.getZ());
        } else {
          par5EntityPlayer.openGui(
              mod_SecurityCraft.instance,
              GuiHandler.SETUP_PASSWORD_ID,
              par1World,
              pos.getX(),
              pos.getY(),
              pos.getZ());
        }
      } else {
        if (mod_SecurityCraft.instance.configHandler.allowCodebreakerItem) {
          if (((IPasswordProtected) par1World.getTileEntity(pos)).getPassword() != null) {
            activate(par1World, pos, par5EntityPlayer);
          }
        } else {
          PlayerUtils.sendMessageToPlayer(
              par5EntityPlayer,
              StatCollector.translateToLocal("tile.keypadFurnace.name"),
              StatCollector.translateToLocal("messages.codebreakerDisabled"),
              EnumChatFormatting.RED);
        }
      }
    }

    return true;
  }

  public static void activate(World par1World, BlockPos pos, EntityPlayer player) {
    if (!BlockUtils.getBlockPropertyAsBoolean(par1World, pos, BlockKeypadFurnace.OPEN)) {
      BlockUtils.setBlockProperty(par1World, pos, BlockKeypadFurnace.OPEN, true, false);
    }

    par1World.playAuxSFXAtEntity((EntityPlayer) null, 1006, pos, 0);
    player.openGui(mod_SecurityCraft.instance, 16, par1World, pos.getX(), pos.getY(), pos.getZ());
  }

  public IBlockState onBlockPlaced(
      World worldIn,
      BlockPos pos,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ,
      int meta,
      EntityLivingBase placer) {
    return this.getDefaultState()
        .withProperty(FACING, placer.getHorizontalFacing().getOpposite())
        .withProperty(OPEN, false);
  }

  @SideOnly(Side.CLIENT)
  public IBlockState getStateForEntityRender(IBlockState state) {
    return this.getDefaultState().withProperty(FACING, EnumFacing.SOUTH);
  }

  public IBlockState getStateFromMeta(int meta) {
    if (meta <= 5) {
      return this.getDefaultState()
          .withProperty(
              FACING,
              EnumFacing.values()[meta].getAxis() == EnumFacing.Axis.Y
                  ? EnumFacing.NORTH
                  : EnumFacing.values()[meta])
          .withProperty(OPEN, false);
    } else {
      return this.getDefaultState()
          .withProperty(FACING, EnumFacing.values()[meta - 6])
          .withProperty(OPEN, true);
    }
  }

  public int getMetaFromState(IBlockState state) {
    if (((Boolean) state.getValue(OPEN)).booleanValue()) {
      return (((EnumFacing) state.getValue(FACING)).getIndex() + 6);
    } else {
      return ((EnumFacing) state.getValue(FACING)).getIndex();
    }
  }

  protected BlockState createBlockState() {
    return new BlockState(this, new IProperty[] {FACING, OPEN});
  }

  public TileEntity createNewTileEntity(World var1, int var2) {
    return new TileEntityKeypadFurnace();
  }
}
示例#6
0
public class BlockNuke extends BlockBase {

  public static final PropertyBool EXPLODE = PropertyBool.create("explode");

  public BlockNuke() {
    super(Material.tnt);
    this.setDefaultState(
        this.blockState.getBaseState().withProperty(EXPLODE, Boolean.valueOf(false)));
    this.setCreativeTab(UReference.things);
  }

  @Override
  public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    super.onBlockAdded(worldIn, pos, state);

    if (worldIn.isBlockPowered(pos)) {
      this.onBlockDestroyedByPlayer(
          worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
      worldIn.setBlockToAir(pos);
    }
  }

  @Override
  public void onNeighborBlockChange(
      World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
    if (worldIn.isBlockPowered(pos)) {
      this.onBlockDestroyedByPlayer(
          worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
      worldIn.setBlockToAir(pos);
    }
  }

  @Override
  public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) {
    if (!worldIn.isRemote) {
      EntityNukePrimed entitytntprimed =
          new EntityNukePrimed(
              worldIn,
              pos.getX() + 0.5F,
              pos.getY() + 0.5F,
              pos.getZ() + 0.5F,
              explosionIn.getExplosivePlacedBy());
      entitytntprimed.fuse =
          worldIn.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
      worldIn.spawnEntityInWorld(entitytntprimed);
    }
  }

  @Override
  public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {
    this.explode(worldIn, pos, state, (EntityLivingBase) null);
  }

  public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter) {
    if (!worldIn.isRemote) {
      if (((Boolean) state.getValue(EXPLODE)).booleanValue()) {
        // float power = 2F + (((5000) / 10369F) * 18F);
        // ProcessHandler.addProcess(new NuclearExplosion(worldIn, pos.getX(), pos.getY(),
        // pos.getZ(), power));
        EntityNukePrimed entitytntprimed =
            new EntityNukePrimed(
                worldIn, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, igniter);
        worldIn.spawnEntityInWorld(entitytntprimed);
        worldIn.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F);
      }
    }
  }

  @Override
  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (playerIn.getCurrentEquippedItem() != null) {
      Item item = playerIn.getCurrentEquippedItem().getItem();

      if (item == Items.flint_and_steel || item == Items.fire_charge) {
        this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);
        worldIn.setBlockToAir(pos);

        if (item == Items.flint_and_steel) {
          playerIn.getCurrentEquippedItem().damageItem(1, playerIn);
        } else if (!playerIn.capabilities.isCreativeMode) {
          --playerIn.getCurrentEquippedItem().stackSize;
        }

        return true;
      }
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
  }

  @Override
  public void onEntityCollidedWithBlock(
      World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
    if (!worldIn.isRemote && entityIn instanceof EntityArrow) {
      EntityArrow entityarrow = (EntityArrow) entityIn;

      if (entityarrow.isBurning()) {
        this.explode(
            worldIn,
            pos,
            worldIn.getBlockState(pos).withProperty(EXPLODE, Boolean.valueOf(true)),
            entityarrow.shootingEntity instanceof EntityLivingBase
                ? (EntityLivingBase) entityarrow.shootingEntity
                : null);
        worldIn.setBlockToAir(pos);
      }
    }
  }

  @Override
  public boolean canDropFromExplosion(Explosion explosionIn) {
    return false;
  }

  @Override
  public IBlockState getStateFromMeta(int meta) {
    return this.getDefaultState().withProperty(EXPLODE, Boolean.valueOf((meta & 1) > 0));
  }

  @Override
  public int getMetaFromState(IBlockState state) {
    return ((Boolean) state.getValue(EXPLODE)).booleanValue() ? 1 : 0;
  }

  @Override
  protected BlockState createBlockState() {
    return new BlockState(this, new IProperty[] {EXPLODE});
  }
}
示例#7
0
public class BlockPistonBase extends Block {
  public static final PropertyDirection FACING = PropertyDirection.create("facing");
  public static final PropertyBool EXTENDED = PropertyBool.create("extended");

  /** This piston is the sticky one? */
  private final boolean isSticky;

  public BlockPistonBase(boolean isSticky) {
    super(Material.piston);
    this.setDefaultState(
        this.blockState
            .getBaseState()
            .withProperty(FACING, EnumFacing.NORTH)
            .withProperty(EXTENDED, Boolean.valueOf(false)));
    this.isSticky = isSticky;
    this.setStepSound(soundTypePiston);
    this.setHardness(0.5F);
    this.setCreativeTab(CreativeTabs.tabRedstone);
  }

  /** Used to determine ambient occlusion and culling when rebuilding chunks for render */
  public boolean isOpaqueCube() {
    return false;
  }

  /** Called by ItemBlocks after a block is set in the world, to allow post-place logic */
  public void onBlockPlacedBy(
      World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    worldIn.setBlockState(
        pos, state.withProperty(FACING, getFacingFromEntity(worldIn, pos, placer)), 2);

    if (!worldIn.isRemote) {
      this.checkForMove(worldIn, pos, state);
    }
  }

  /** Called when a neighboring block changes. */
  public void onNeighborBlockChange(
      World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
    if (!worldIn.isRemote) {
      this.checkForMove(worldIn, pos, state);
    }
  }

  public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    if (!worldIn.isRemote && worldIn.getTileEntity(pos) == null) {
      this.checkForMove(worldIn, pos, state);
    }
  }

  /**
   * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments
   * to the IBlockstate
   */
  public IBlockState onBlockPlaced(
      World worldIn,
      BlockPos pos,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ,
      int meta,
      EntityLivingBase placer) {
    return this.getDefaultState()
        .withProperty(FACING, getFacingFromEntity(worldIn, pos, placer))
        .withProperty(EXTENDED, Boolean.valueOf(false));
  }

  private void checkForMove(World worldIn, BlockPos pos, IBlockState state) {
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
    boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing);

    if (flag && !((Boolean) state.getValue(EXTENDED)).booleanValue()) {
      if ((new BlockPistonStructureHelper(worldIn, pos, enumfacing, true)).canMove()) {
        worldIn.addBlockEvent(pos, this, 0, enumfacing.getIndex());
      }
    } else if (!flag && ((Boolean) state.getValue(EXTENDED)).booleanValue()) {
      worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(false)), 2);
      worldIn.addBlockEvent(pos, this, 1, enumfacing.getIndex());
    }
  }

  private boolean shouldBeExtended(World worldIn, BlockPos pos, EnumFacing facing) {
    for (EnumFacing enumfacing : EnumFacing.values()) {
      if (enumfacing != facing && worldIn.isSidePowered(pos.offset(enumfacing), enumfacing)) {
        return true;
      }
    }

    if (worldIn.isSidePowered(pos, EnumFacing.DOWN)) {
      return true;
    } else {
      BlockPos blockpos = pos.up();

      for (EnumFacing enumfacing1 : EnumFacing.values()) {
        if (enumfacing1 != EnumFacing.DOWN
            && worldIn.isSidePowered(blockpos.offset(enumfacing1), enumfacing1)) {
          return true;
        }
      }

      return false;
    }
  }

  /** Called on both Client and Server when World#addBlockEvent is called */
  public boolean onBlockEventReceived(
      World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) {
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);

    if (!worldIn.isRemote) {
      boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing);

      if (flag && eventID == 1) {
        worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2);
        return false;
      }

      if (!flag && eventID == 0) {
        return false;
      }
    }

    if (eventID == 0) {
      if (!this.doMove(worldIn, pos, enumfacing, true)) {
        return false;
      }

      worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2);
      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "tile.piston.out",
          0.5F,
          worldIn.rand.nextFloat() * 0.25F + 0.6F);
    } else if (eventID == 1) {
      TileEntity tileentity1 = worldIn.getTileEntity(pos.offset(enumfacing));

      if (tileentity1 instanceof TileEntityPiston) {
        ((TileEntityPiston) tileentity1).clearPistonTileEntity();
      }

      worldIn.setBlockState(
          pos,
          Blocks.piston_extension
              .getDefaultState()
              .withProperty(BlockPistonMoving.FACING, enumfacing)
              .withProperty(
                  BlockPistonMoving.TYPE,
                  this.isSticky
                      ? BlockPistonExtension.EnumPistonType.STICKY
                      : BlockPistonExtension.EnumPistonType.DEFAULT),
          3);
      worldIn.setTileEntity(
          pos,
          BlockPistonMoving.newTileEntity(
              this.getStateFromMeta(eventParam), enumfacing, false, true));

      if (this.isSticky) {
        BlockPos blockpos =
            pos.add(
                enumfacing.getFrontOffsetX() * 2,
                enumfacing.getFrontOffsetY() * 2,
                enumfacing.getFrontOffsetZ() * 2);
        Block block = worldIn.getBlockState(blockpos).getBlock();
        boolean flag1 = false;

        if (block == Blocks.piston_extension) {
          TileEntity tileentity = worldIn.getTileEntity(blockpos);

          if (tileentity instanceof TileEntityPiston) {
            TileEntityPiston tileentitypiston = (TileEntityPiston) tileentity;

            if (tileentitypiston.getFacing() == enumfacing && tileentitypiston.isExtending()) {
              tileentitypiston.clearPistonTileEntity();
              flag1 = true;
            }
          }
        }

        if (!flag1
            && block.getMaterial() != Material.air
            && canPush(block, worldIn, blockpos, enumfacing.getOpposite(), false)
            && (block.getMobilityFlag() == 0
                || block == Blocks.piston
                || block == Blocks.sticky_piston)) {
          this.doMove(worldIn, pos, enumfacing, false);
        }
      } else {
        worldIn.setBlockToAir(pos.offset(enumfacing));
      }

      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "tile.piston.in",
          0.5F,
          worldIn.rand.nextFloat() * 0.15F + 0.6F);
    }

    return true;
  }

  public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
    IBlockState iblockstate = worldIn.getBlockState(pos);

    if (iblockstate.getBlock() == this
        && ((Boolean) iblockstate.getValue(EXTENDED)).booleanValue()) {
      float f = 0.25F;
      EnumFacing enumfacing = (EnumFacing) iblockstate.getValue(FACING);

      if (enumfacing != null) {
        switch (enumfacing) {
          case DOWN:
            this.setBlockBounds(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
            break;

          case UP:
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
            break;

          case NORTH:
            this.setBlockBounds(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
            break;

          case SOUTH:
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
            break;

          case WEST:
            this.setBlockBounds(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
            break;

          case EAST:
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
        }
      }
    } else {
      this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    }
  }

  /** Sets the block's bounds for rendering it as an item */
  public void setBlockBoundsForItemRender() {
    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
  }

  /** Add all collision boxes of this Block to the list that intersect with the given mask. */
  public void addCollisionBoxesToList(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      AxisAlignedBB mask,
      List<AxisAlignedBB> list,
      Entity collidingEntity) {
    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  }

  public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
    this.setBlockBoundsBasedOnState(worldIn, pos);
    return super.getCollisionBoundingBox(worldIn, pos, state);
  }

  public boolean isFullCube() {
    return false;
  }

  public static EnumFacing getFacing(int meta) {
    int i = meta & 7;
    return i > 5 ? null : EnumFacing.getFront(i);
  }

  public static EnumFacing getFacingFromEntity(
      World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn) {
    if (MathHelper.abs((float) entityIn.posX - (float) clickedBlock.getX()) < 2.0F
        && MathHelper.abs((float) entityIn.posZ - (float) clickedBlock.getZ()) < 2.0F) {
      double d0 = entityIn.posY + (double) entityIn.getEyeHeight();

      if (d0 - (double) clickedBlock.getY() > 2.0D) {
        return EnumFacing.UP;
      }

      if ((double) clickedBlock.getY() - d0 > 0.0D) {
        return EnumFacing.DOWN;
      }
    }

    return entityIn.getHorizontalFacing().getOpposite();
  }

  public static boolean canPush(
      Block blockIn, World worldIn, BlockPos pos, EnumFacing direction, boolean allowDestroy) {
    if (blockIn == Blocks.obsidian) {
      return false;
    } else if (!worldIn.getWorldBorder().contains(pos)) {
      return false;
    } else if (pos.getY() >= 0 && (direction != EnumFacing.DOWN || pos.getY() != 0)) {
      if (pos.getY() <= worldIn.getHeight() - 1
          && (direction != EnumFacing.UP || pos.getY() != worldIn.getHeight() - 1)) {
        if (blockIn != Blocks.piston && blockIn != Blocks.sticky_piston) {
          if (blockIn.getBlockHardness(worldIn, pos) == -1.0F) {
            return false;
          }

          if (blockIn.getMobilityFlag() == 2) {
            return false;
          }

          if (blockIn.getMobilityFlag() == 1) {
            if (!allowDestroy) {
              return false;
            }

            return true;
          }
        } else if (((Boolean) worldIn.getBlockState(pos).getValue(EXTENDED)).booleanValue()) {
          return false;
        }

        return !(blockIn instanceof ITileEntityProvider);
      } else {
        return false;
      }
    } else {
      return false;
    }
  }

  private boolean doMove(World worldIn, BlockPos pos, EnumFacing direction, boolean extending) {
    if (!extending) {
      worldIn.setBlockToAir(pos.offset(direction));
    }

    BlockPistonStructureHelper blockpistonstructurehelper =
        new BlockPistonStructureHelper(worldIn, pos, direction, extending);
    List<BlockPos> list = blockpistonstructurehelper.getBlocksToMove();
    List<BlockPos> list1 = blockpistonstructurehelper.getBlocksToDestroy();

    if (!blockpistonstructurehelper.canMove()) {
      return false;
    } else {
      int i = list.size() + list1.size();
      Block[] ablock = new Block[i];
      EnumFacing enumfacing = extending ? direction : direction.getOpposite();

      for (int j = list1.size() - 1; j >= 0; --j) {
        BlockPos blockpos = (BlockPos) list1.get(j);
        Block block = worldIn.getBlockState(blockpos).getBlock();
        block.dropBlockAsItem(worldIn, blockpos, worldIn.getBlockState(blockpos), 0);
        worldIn.setBlockToAir(blockpos);
        --i;
        ablock[i] = block;
      }

      for (int k = list.size() - 1; k >= 0; --k) {
        BlockPos blockpos2 = (BlockPos) list.get(k);
        IBlockState iblockstate = worldIn.getBlockState(blockpos2);
        Block block1 = iblockstate.getBlock();
        block1.getMetaFromState(iblockstate);
        worldIn.setBlockToAir(blockpos2);
        blockpos2 = blockpos2.offset(enumfacing);
        worldIn.setBlockState(
            blockpos2,
            Blocks.piston_extension.getDefaultState().withProperty(FACING, direction),
            4);
        worldIn.setTileEntity(
            blockpos2, BlockPistonMoving.newTileEntity(iblockstate, direction, extending, false));
        --i;
        ablock[i] = block1;
      }

      BlockPos blockpos1 = pos.offset(direction);

      if (extending) {
        BlockPistonExtension.EnumPistonType blockpistonextension$enumpistontype =
            this.isSticky
                ? BlockPistonExtension.EnumPistonType.STICKY
                : BlockPistonExtension.EnumPistonType.DEFAULT;
        IBlockState iblockstate1 =
            Blocks.piston_head
                .getDefaultState()
                .withProperty(BlockPistonExtension.FACING, direction)
                .withProperty(BlockPistonExtension.TYPE, blockpistonextension$enumpistontype);
        IBlockState iblockstate2 =
            Blocks.piston_extension
                .getDefaultState()
                .withProperty(BlockPistonMoving.FACING, direction)
                .withProperty(
                    BlockPistonMoving.TYPE,
                    this.isSticky
                        ? BlockPistonExtension.EnumPistonType.STICKY
                        : BlockPistonExtension.EnumPistonType.DEFAULT);
        worldIn.setBlockState(blockpos1, iblockstate2, 4);
        worldIn.setTileEntity(
            blockpos1, BlockPistonMoving.newTileEntity(iblockstate1, direction, true, false));
      }

      for (int l = list1.size() - 1; l >= 0; --l) {
        worldIn.notifyNeighborsOfStateChange((BlockPos) list1.get(l), ablock[i++]);
      }

      for (int i1 = list.size() - 1; i1 >= 0; --i1) {
        worldIn.notifyNeighborsOfStateChange((BlockPos) list.get(i1), ablock[i++]);
      }

      if (extending) {
        worldIn.notifyNeighborsOfStateChange(blockpos1, Blocks.piston_head);
        worldIn.notifyNeighborsOfStateChange(pos, this);
      }

      return true;
    }
  }

  /**
   * Possibly modify the given BlockState before rendering it on an Entity (Minecarts, Endermen,
   * ...)
   */
  public IBlockState getStateForEntityRender(IBlockState state) {
    return this.getDefaultState().withProperty(FACING, EnumFacing.UP);
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    return this.getDefaultState()
        .withProperty(FACING, getFacing(meta))
        .withProperty(EXTENDED, Boolean.valueOf((meta & 8) > 0));
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;
    i = i | ((EnumFacing) state.getValue(FACING)).getIndex();

    if (((Boolean) state.getValue(EXTENDED)).booleanValue()) {
      i |= 8;
    }

    return i;
  }

  protected BlockState createBlockState() {
    return new BlockState(this, new IProperty[] {FACING, EXTENDED});
  }
}
public class TutoBlockStateMultiState extends Block implements ITutoBlockState {
  public static final PropertyEnum DARK = PropertyEnum.create("dark", EnumType.class);
  public static final PropertyBool POWERED = PropertyBool.create("powered");
  public static final PropertyInteger COLOR = PropertyInteger.create("color", 0, 3);

  public TutoBlockStateMultiState(Material material) {
    super(material);
    this.setDefaultState(
        getDefaultState()
            .withProperty(POWERED, Boolean.valueOf(false))
            .withProperty(COLOR, 0)
            .withProperty(DARK, EnumType.BLACK));
    this.setCreativeTab(CreativeTabs.tabDecorations);
  }

  @Override
  public IBlockState getStateFromMeta(int meta) {
    IBlockState state = this.getDefaultState().withProperty(COLOR, (meta & 3) % 4);

    switch (meta & 8) {
      case 0:
        state = state.withProperty(DARK, EnumType.BLACK);
        break;
      case 8:
        state = state.withProperty(DARK, EnumType.WHITE);
    }

    switch (meta & 4) {
      case 4:
        state = state.withProperty(POWERED, Boolean.valueOf(false));
      case 12:
        state = state.withProperty(POWERED, Boolean.valueOf(true));
    }

    return state;
  }

  @Override
  public int getMetaFromState(IBlockState state) {
    byte b0 = 0;
    int i;

    i = b0 | ((Integer) state.getValue(COLOR)).intValue();

    if (state.getValue(DARK) == EnumType.WHITE) i |= 8;
    i |= (((Boolean) state.getValue(POWERED)).booleanValue() == true) ? 4 : 0;

    return i;
  }

  @Override
  public int damageDropped(IBlockState state) {
    byte b0 = 0;
    int i;

    i = b0 | ((Integer) state.getValue(COLOR)).intValue();

    if (state.getValue(DARK) == EnumType.WHITE) i |= 8;
    i |= (((Boolean) state.getValue(POWERED)).booleanValue() == true) ? 4 : 0;

    return i;
  }

  @Override
  protected BlockState createBlockState() {
    return new BlockState(this, new IProperty[] {DARK, POWERED, COLOR});
  }

  @Override
  public void onNeighborBlockChange(
      World world, BlockPos pos, IBlockState state, Block neighborBlock) {
    boolean flag = world.isBlockPowered(pos);
    state = world.getBlockState(pos);

    world.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)));
  }

  @Override
  public boolean onBlockActivated(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    state = world.getBlockState(pos);
    int i = ((Integer) state.getValue(COLOR)).intValue();
    if (world.isBlockPowered(pos)) {
      world.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)));
    }

    if (((Boolean) state.getValue(POWERED)).booleanValue() == true) {
      if (i < 3) {
        world.setBlockState(pos, state.withProperty(COLOR, i + 1));
      } else if (i == 3) {
        world.setBlockState(pos, state.withProperty(COLOR, 0));
      } else {
        return false;
      }
    } else {
      return false;
    }

    return true;
  }

  @Override
  public void getSubBlocks(Item item, CreativeTabs tab, List list) {
    list.add(new ItemStack(this, 1, 0));
    list.add(new ItemStack(this, 1, 8));
  }

  @Override
  public String getUnlocalizedName(int metadata) {
    String varName = metadata < 8 ? "black" : "white";

    return super.getUnlocalizedName() + "." + varName;
  }

  public enum EnumType implements IStringSerializable {
    BLACK("black", 0),
    WHITE("white", 1);

    private static final EnumType[] METADATA = new EnumType[values().length];
    private final String name;
    private final int metadata;

    private EnumType(String name, int metadata) {
      this.name = name;
      this.metadata = metadata;
    }

    @Override
    public String getName() {
      return name;
    }

    @Override
    public String toString() {
      return name;
    }

    public int getMetadata() {
      return metadata;
    }

    public static EnumType getStateFromMeta(int metadata) {
      if (metadata < 0 || metadata >= METADATA.length) {
        metadata = 0;
      }

      return METADATA[metadata];
    }

    static {
      EnumType[] var0 = values();
      int var1 = var0.length;

      for (int var2 = 0; var2 < var1; var2++) {
        EnumType var3 = var0[var2];
        METADATA[var3.getMetadata()] = var3;
      }
    }
  }
}
示例#9
0
public abstract class BlockButton extends Block {
  public static final PropertyDirection FACING = PropertyDirection.create("facing");
  public static final PropertyBool POWERED = PropertyBool.create("powered");
  private final boolean wooden;

  protected BlockButton(boolean wooden) {
    super(Material.circuits);
    this.setDefaultState(
        this.blockState
            .getBaseState()
            .withProperty(FACING, EnumFacing.NORTH)
            .withProperty(POWERED, Boolean.valueOf(false)));
    this.setTickRandomly(true);
    this.setCreativeTab(CreativeTabs.tabRedstone);
    this.wooden = wooden;
  }

  public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
    return null;
  }

  /** How many world ticks before ticking */
  public int tickRate(World worldIn) {
    return this.wooden ? 30 : 20;
  }

  /** Used to determine ambient occlusion and culling when rebuilding chunks for render */
  public boolean isOpaqueCube() {
    return false;
  }

  public boolean isFullCube() {
    return false;
  }

  /** Check whether this Block can be placed on the given side */
  public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) {
    return func_181088_a(worldIn, pos, side.getOpposite());
  }

  public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
    for (EnumFacing enumfacing : EnumFacing.values()) {
      if (func_181088_a(worldIn, pos, enumfacing)) {
        return true;
      }
    }

    return false;
  }

  protected static boolean func_181088_a(
      World p_181088_0_, BlockPos p_181088_1_, EnumFacing p_181088_2_) {
    return p_181088_2_ == EnumFacing.DOWN
            && World.doesBlockHaveSolidTopSurface(p_181088_0_, p_181088_1_.down())
        ? true
        : p_181088_0_.isSideSolid(p_181088_1_.offset(p_181088_2_), p_181088_2_.getOpposite());
  }

  /**
   * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments
   * to the IBlockstate
   */
  public IBlockState onBlockPlaced(
      World worldIn,
      BlockPos pos,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ,
      int meta,
      EntityLivingBase placer) {
    return func_181088_a(worldIn, pos, facing.getOpposite())
        ? this.getDefaultState()
            .withProperty(FACING, facing)
            .withProperty(POWERED, Boolean.valueOf(false))
        : this.getDefaultState()
            .withProperty(FACING, EnumFacing.DOWN)
            .withProperty(POWERED, Boolean.valueOf(false));
  }

  /** Called when a neighboring block changes. */
  public void onNeighborBlockChange(
      World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
    if (this.checkForDrop(worldIn, pos, state)
        && !func_181088_a(worldIn, pos, ((EnumFacing) state.getValue(FACING)).getOpposite())) {
      this.dropBlockAsItem(worldIn, pos, state, 0);
      worldIn.setBlockToAir(pos);
    }
  }

  private boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state) {
    if (this.canPlaceBlockAt(worldIn, pos)) {
      return true;
    } else {
      this.dropBlockAsItem(worldIn, pos, state, 0);
      worldIn.setBlockToAir(pos);
      return false;
    }
  }

  public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
    this.updateBlockBounds(worldIn.getBlockState(pos));
  }

  private void updateBlockBounds(IBlockState state) {
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
    boolean flag = ((Boolean) state.getValue(POWERED)).booleanValue();
    float f = 0.25F;
    float f1 = 0.375F;
    float f2 = (float) (flag ? 1 : 2) / 16.0F;
    float f3 = 0.125F;
    float f4 = 0.1875F;

    switch (enumfacing) {
      case EAST:
        this.setBlockBounds(0.0F, 0.375F, 0.3125F, f2, 0.625F, 0.6875F);
        break;
      case WEST:
        this.setBlockBounds(1.0F - f2, 0.375F, 0.3125F, 1.0F, 0.625F, 0.6875F);
        break;
      case SOUTH:
        this.setBlockBounds(0.3125F, 0.375F, 0.0F, 0.6875F, 0.625F, f2);
        break;
      case NORTH:
        this.setBlockBounds(0.3125F, 0.375F, 1.0F - f2, 0.6875F, 0.625F, 1.0F);
        break;
      case UP:
        this.setBlockBounds(0.3125F, 0.0F, 0.375F, 0.6875F, 0.0F + f2, 0.625F);
        break;
      case DOWN:
        this.setBlockBounds(0.3125F, 1.0F - f2, 0.375F, 0.6875F, 1.0F, 0.625F);
    }
  }

  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      return true;
    } else {
      worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3);
      worldIn.markBlockRangeForRenderUpdate(pos, pos);
      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "random.click",
          0.3F,
          0.6F);
      this.notifyNeighbors(worldIn, pos, (EnumFacing) state.getValue(FACING));
      worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
      return true;
    }
  }

  public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      this.notifyNeighbors(worldIn, pos, (EnumFacing) state.getValue(FACING));
    }

    super.breakBlock(worldIn, pos, state);
  }

  public int getWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side) {
    return ((Boolean) state.getValue(POWERED)).booleanValue() ? 15 : 0;
  }

  public int getStrongPower(
      IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side) {
    return !((Boolean) state.getValue(POWERED)).booleanValue()
        ? 0
        : (state.getValue(FACING) == side ? 15 : 0);
  }

  /**
   * Can this block provide power. Only wire currently seems to have this change based on its state.
   */
  public boolean canProvidePower() {
    return true;
  }

  /** Called randomly when setTickRandomly is set to true (used by e.g. crops to grow, etc.) */
  public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random) {}

  public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (!worldIn.isRemote) {
      if (((Boolean) state.getValue(POWERED)).booleanValue()) {
        if (this.wooden) {
          this.checkForArrows(worldIn, pos, state);
        } else {
          worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)));
          this.notifyNeighbors(worldIn, pos, (EnumFacing) state.getValue(FACING));
          worldIn.playSoundEffect(
              (double) pos.getX() + 0.5D,
              (double) pos.getY() + 0.5D,
              (double) pos.getZ() + 0.5D,
              "random.click",
              0.3F,
              0.5F);
          worldIn.markBlockRangeForRenderUpdate(pos, pos);
        }
      }
    }
  }

  /** Sets the block's bounds for rendering it as an item */
  public void setBlockBoundsForItemRender() {
    float f = 0.1875F;
    float f1 = 0.125F;
    float f2 = 0.125F;
    this.setBlockBounds(0.5F - f, 0.5F - f1, 0.5F - f2, 0.5F + f, 0.5F + f1, 0.5F + f2);
  }

  /** Called When an Entity Collided with the Block */
  public void onEntityCollidedWithBlock(
      World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
    if (!worldIn.isRemote) {
      if (this.wooden) {
        if (!((Boolean) state.getValue(POWERED)).booleanValue()) {
          this.checkForArrows(worldIn, pos, state);
        }
      }
    }
  }

  private void checkForArrows(World worldIn, BlockPos pos, IBlockState state) {
    this.updateBlockBounds(state);
    List<? extends Entity> list =
        worldIn.<Entity>getEntitiesWithinAABB(
            EntityArrow.class,
            new AxisAlignedBB(
                (double) pos.getX() + this.minX,
                (double) pos.getY() + this.minY,
                (double) pos.getZ() + this.minZ,
                (double) pos.getX() + this.maxX,
                (double) pos.getY() + this.maxY,
                (double) pos.getZ() + this.maxZ));
    boolean flag = !list.isEmpty();
    boolean flag1 = ((Boolean) state.getValue(POWERED)).booleanValue();

    if (flag && !flag1) {
      worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)));
      this.notifyNeighbors(worldIn, pos, (EnumFacing) state.getValue(FACING));
      worldIn.markBlockRangeForRenderUpdate(pos, pos);
      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "random.click",
          0.3F,
          0.6F);
    }

    if (!flag && flag1) {
      worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)));
      this.notifyNeighbors(worldIn, pos, (EnumFacing) state.getValue(FACING));
      worldIn.markBlockRangeForRenderUpdate(pos, pos);
      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "random.click",
          0.3F,
          0.5F);
    }

    if (flag) {
      worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
    }
  }

  private void notifyNeighbors(World worldIn, BlockPos pos, EnumFacing facing) {
    worldIn.notifyNeighborsOfStateChange(pos, this);
    worldIn.notifyNeighborsOfStateChange(pos.offset(facing.getOpposite()), this);
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    EnumFacing enumfacing;

    switch (meta & 7) {
      case 0:
        enumfacing = EnumFacing.DOWN;
        break;
      case 1:
        enumfacing = EnumFacing.EAST;
        break;
      case 2:
        enumfacing = EnumFacing.WEST;
        break;
      case 3:
        enumfacing = EnumFacing.SOUTH;
        break;
      case 4:
        enumfacing = EnumFacing.NORTH;
        break;
      case 5:
      default:
        enumfacing = EnumFacing.UP;
    }

    return this.getDefaultState()
        .withProperty(FACING, enumfacing)
        .withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i;

    switch ((EnumFacing) state.getValue(FACING)) {
      case EAST:
        i = 1;
        break;
      case WEST:
        i = 2;
        break;
      case SOUTH:
        i = 3;
        break;
      case NORTH:
        i = 4;
        break;
      case UP:
      default:
        i = 5;
        break;
      case DOWN:
        i = 0;
    }

    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      i |= 8;
    }

    return i;
  }

  protected BlockState createBlockState() {
    return new BlockState(this, new IProperty[] {FACING, POWERED});
  }
}
示例#10
0
public class BlockWall extends Block {
  public static final PropertyBool field_176256_a = PropertyBool.create("up");
  public static final PropertyBool field_176254_b = PropertyBool.create("north");
  public static final PropertyBool field_176257_M = PropertyBool.create("east");
  public static final PropertyBool field_176258_N = PropertyBool.create("south");
  public static final PropertyBool field_176259_O = PropertyBool.create("west");
  public static final PropertyEnum field_176255_P =
      PropertyEnum.create("variant", BlockWall.EnumType.class);
  private static final String __OBFID = "CL_00000331";

  public BlockWall(Block p_i45435_1_) {
    super(p_i45435_1_.blockMaterial);
    this.setDefaultState(
        this.blockState
            .getBaseState()
            .withProperty(field_176256_a, Boolean.valueOf(false))
            .withProperty(field_176254_b, Boolean.valueOf(false))
            .withProperty(field_176257_M, Boolean.valueOf(false))
            .withProperty(field_176258_N, Boolean.valueOf(false))
            .withProperty(field_176259_O, Boolean.valueOf(false))
            .withProperty(field_176255_P, BlockWall.EnumType.NORMAL));
    this.setHardness(p_i45435_1_.blockHardness);
    this.setResistance(p_i45435_1_.blockResistance / 3.0F);
    this.setStepSound(p_i45435_1_.stepSound);
    this.setCreativeTab(CreativeTabs.tabBlock);
  }

  public boolean isFullCube() {
    return false;
  }

  public boolean isPassable(IBlockAccess blockAccess, BlockPos pos) {
    return false;
  }

  public boolean isOpaqueCube() {
    return false;
  }

  public void setBlockBoundsBasedOnState(IBlockAccess access, BlockPos pos) {
    boolean var3 = this.func_176253_e(access, pos.offsetNorth());
    boolean var4 = this.func_176253_e(access, pos.offsetSouth());
    boolean var5 = this.func_176253_e(access, pos.offsetWest());
    boolean var6 = this.func_176253_e(access, pos.offsetEast());
    float var7 = 0.25F;
    float var8 = 0.75F;
    float var9 = 0.25F;
    float var10 = 0.75F;
    float var11 = 1.0F;

    if (var3) {
      var9 = 0.0F;
    }

    if (var4) {
      var10 = 1.0F;
    }

    if (var5) {
      var7 = 0.0F;
    }

    if (var6) {
      var8 = 1.0F;
    }

    if (var3 && var4 && !var5 && !var6) {
      var11 = 0.8125F;
      var7 = 0.3125F;
      var8 = 0.6875F;
    } else if (!var3 && !var4 && var5 && var6) {
      var11 = 0.8125F;
      var9 = 0.3125F;
      var10 = 0.6875F;
    }

    this.setBlockBounds(var7, 0.0F, var9, var8, var11, var10);
  }

  public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
    this.setBlockBoundsBasedOnState(worldIn, pos);
    this.maxY = 1.5D;
    return super.getCollisionBoundingBox(worldIn, pos, state);
  }

  public boolean func_176253_e(IBlockAccess p_176253_1_, BlockPos p_176253_2_) {
    Block var3 = p_176253_1_.getBlockState(p_176253_2_).getBlock();
    return var3 == Blocks.barrier
        ? false
        : (var3 != this && !(var3 instanceof BlockFenceGate)
            ? (var3.blockMaterial.isOpaque() && var3.isFullCube()
                ? var3.blockMaterial != Material.gourd
                : false)
            : true);
  }

  /** Get the damage value that this Block should drop */
  public int damageDropped(IBlockState state) {
    return ((BlockWall.EnumType) state.getValue(field_176255_P)).func_176657_a();
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    return this.getDefaultState()
        .withProperty(field_176255_P, BlockWall.EnumType.func_176660_a(meta));
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    return ((BlockWall.EnumType) state.getValue(field_176255_P)).func_176657_a();
  }

  /**
   * Get the actual Block state of this Block at the given position. This applies properties not
   * visible in the metadata, such as fence connections.
   */
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    return state
        .withProperty(field_176256_a, Boolean.valueOf(!worldIn.isAirBlock(pos.offsetUp())))
        .withProperty(
            field_176254_b, Boolean.valueOf(this.func_176253_e(worldIn, pos.offsetNorth())))
        .withProperty(
            field_176257_M, Boolean.valueOf(this.func_176253_e(worldIn, pos.offsetEast())))
        .withProperty(
            field_176258_N, Boolean.valueOf(this.func_176253_e(worldIn, pos.offsetSouth())))
        .withProperty(
            field_176259_O, Boolean.valueOf(this.func_176253_e(worldIn, pos.offsetWest())));
  }

  protected BlockState createBlockState() {
    return new BlockState(
        this,
        new IProperty[] {
          field_176256_a,
          field_176254_b,
          field_176257_M,
          field_176259_O,
          field_176258_N,
          field_176255_P
        });
  }

  public static enum EnumType implements IStringSerializable {
    NORMAL("NORMAL", 0, 0, "cobblestone", "normal"),
    MOSSY("MOSSY", 1, 1, "mossy_cobblestone", "mossy");
    private static final BlockWall.EnumType[] field_176666_c =
        new BlockWall.EnumType[values().length];
    private final int field_176663_d;
    private final String field_176664_e;
    private String field_176661_f;

    private static final BlockWall.EnumType[] $VALUES = new BlockWall.EnumType[] {NORMAL, MOSSY};
    private static final String __OBFID = "CL_00002048";

    private EnumType(
        String p_i45673_1_,
        int p_i45673_2_,
        int p_i45673_3_,
        String p_i45673_4_,
        String p_i45673_5_) {
      this.field_176663_d = p_i45673_3_;
      this.field_176664_e = p_i45673_4_;
      this.field_176661_f = p_i45673_5_;
    }

    public int func_176657_a() {
      return this.field_176663_d;
    }

    public String toString() {
      return this.field_176664_e;
    }

    public static BlockWall.EnumType func_176660_a(int p_176660_0_) {
      if (p_176660_0_ < 0 || p_176660_0_ >= field_176666_c.length) {
        p_176660_0_ = 0;
      }

      return field_176666_c[p_176660_0_];
    }

    public String getName() {
      return this.field_176664_e;
    }

    public String func_176659_c() {
      return this.field_176661_f;
    }

    static {
      BlockWall.EnumType[] var0 = values();
      int var1 = var0.length;

      for (int var2 = 0; var2 < var1; ++var2) {
        BlockWall.EnumType var3 = var0[var2];
        field_176666_c[var3.func_176657_a()] = var3;
      }
    }
  }
}
示例#11
0
public class BlockScreen extends BlockAdvanced
    implements IShiftDescription, IPartialSealableBlock, ITileEntityProvider, ISortableBlock {
  /*private IIcon iconFront;
  private IIcon iconSide;*/

  public static final PropertyDirection FACING = PropertyDirection.create("facing");
  public static final PropertyBool LEFT = PropertyBool.create("left");
  public static final PropertyBool RIGHT = PropertyBool.create("right");
  public static final PropertyBool UP = PropertyBool.create("up");
  public static final PropertyBool DOWN = PropertyBool.create("down");

  // Metadata: 0-5 = direction of screen back;  bit 3 = reserved for future use
  protected BlockScreen(String assetName) {
    super(Material.circuits);
    this.setDefaultState(
        this.blockState
            .getBaseState()
            .withProperty(FACING, EnumFacing.NORTH)
            .withProperty(LEFT, false)
            .withProperty(RIGHT, false)
            .withProperty(UP, false)
            .withProperty(DOWN, false));
    this.setHardness(0.1F);
    this.setStepSound(Block.soundTypeGlass);
    // this.setBlockTextureName("glass");
    this.setUnlocalizedName(assetName);
  }

  @Override
  public boolean isSideSolid(IBlockAccess world, BlockPos pos, EnumFacing direction) {
    return direction.ordinal() != getMetaFromState(world.getBlockState(pos));
  }

  @Override
  public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    ((TileEntityScreen) worldIn.getTileEntity(pos)).breakScreen(state);
    super.breakBlock(worldIn, pos, state);
  }

  @Override
  public boolean isOpaqueCube() {
    return false;
  }

  @Override
  public boolean isFullCube() {
    return false;
  }

  @Override
  public int getRenderType() {
    return GalacticraftCore.proxy.getBlockRender(this);
  }

  /*@Override
  @SideOnly(Side.CLIENT)
  public void registerBlockIcons(IIconRegister par1IconRegister)
  {
      this.iconFront = par1IconRegister.registerIcon(GalacticraftCore.TEXTURE_PREFIX + "screenFront");
      this.iconSide = par1IconRegister.registerIcon(GalacticraftCore.TEXTURE_PREFIX + "screenSide");
  }

  @Override
  public IIcon getIcon(int side, int metadata)
  {
      if (side == (metadata & 7))
      {
          return this.iconSide;
      }

      return this.iconFront;
  }*/

  @Override
  public void onBlockPlacedBy(
      World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    final int angle = MathHelper.floor_double(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
    int change = EnumFacing.getHorizontal(angle).getOpposite().getIndex();
    worldIn.setBlockState(pos, getStateFromMeta(change), 3);
  }

  @Override
  public boolean onUseWrench(
      World world,
      BlockPos pos,
      EntityPlayer entityPlayer,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    int change = world.getBlockState(pos).getValue(FACING).rotateY().getIndex();
    world.setBlockState(pos, this.getStateFromMeta(change), 3);
    return true;
  }

  @Override
  public TileEntity createNewTileEntity(World world, int meta) {
    return new TileEntityScreen();
  }

  @Override
  public CreativeTabs getCreativeTabToDisplayOn() {
    return GalacticraftCore.galacticraftBlocksTab;
  }

  @Override
  public boolean onMachineActivated(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer entityPlayer,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TileEntityScreen) {
      ((TileEntityScreen) tile).changeChannel();
      return true;
    }
    return false;
  }

  @Override
  public void onNeighborBlockChange(
      World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile instanceof TileEntityScreen) {
      ((TileEntityScreen) tile).refreshConnections(true);
    }
  }

  @Override
  public String getShiftDescription(int meta) {
    return GCCoreUtil.translate(this.getUnlocalizedName() + ".description");
  }

  @Override
  public boolean showDescription(int meta) {
    return true;
  }

  @Override
  public boolean isSealed(World worldIn, BlockPos pos, EnumFacing direction) {
    return true;
  }

  @Override
  public MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end) {
    final int metadata = getMetaFromState(worldIn.getBlockState(pos)) & 7;
    float boundsFront = 0.094F;
    float boundsBack = 1.0F - boundsFront;

    switch (metadata) {
      case 0:
        this.setBlockBounds(0F, 0F, 0F, 1.0F, boundsBack, 1.0F);
        break;
      case 1:
        this.setBlockBounds(0F, boundsFront, 0F, 1.0F, 1.0F, 1.0F);
        break;
      case 2:
        this.setBlockBounds(0F, 0F, boundsFront, 1.0F, 1.0F, 1.0F);
        break;
      case 3:
        this.setBlockBounds(0F, 0F, 0F, 1.0F, 1.0F, boundsBack);
        break;
      case 4:
        this.setBlockBounds(boundsFront, 0F, 0F, 1.0F, 1.0F, 1.0F);
        break;
      case 5:
        this.setBlockBounds(0F, 0F, 0F, boundsBack, 1.0F, 1.0F);
        break;
    }

    return super.collisionRayTrace(worldIn, pos, start, end);
  }

  @Override
  public IBlockState getStateFromMeta(int meta) {
    EnumFacing enumfacing = EnumFacing.getFront(meta);
    return this.getDefaultState().withProperty(FACING, enumfacing);
  }

  @Override
  public int getMetaFromState(IBlockState state) {
    return (state.getValue(FACING)).getIndex();
  }

  @Override
  protected BlockState createBlockState() {
    return new BlockState(this, FACING, LEFT, RIGHT, UP, DOWN);
  }

  @Override
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    TileEntityScreen screen = (TileEntityScreen) worldIn.getTileEntity(pos);
    return state
        .withProperty(LEFT, screen.connectedLeft)
        .withProperty(RIGHT, screen.connectedRight)
        .withProperty(UP, screen.connectedUp)
        .withProperty(DOWN, screen.connectedDown);
  }

  @Override
  public EnumSortCategoryBlock getCategory(int meta) {
    return EnumSortCategoryBlock.MACHINE;
  }
}
public class BlockDispenser extends Block implements BlockContainer {
  public static final PropertyDirection FACING = PropertyDirection.create("facing");
  public static final PropertyBool TRIGGERED = PropertyBool.create("triggered");

  /** Registry for all dispense behaviors. */
  public static final RegistryDefaulted<Item, IBehaviorDispenseItem> dispenseBehaviorRegistry =
      new RegistryDefaulted<>(new BehaviorDefaultDispenseItem());

  protected Random rand = new Random();

  /* BlockState methods */
  public BlockState createBlockState() {
    return new BlockState(this, FACING, TRIGGERED);
  }

  public IBlockState getDefaultState() {
    return this.getBaseState()
        .withProperty(FACING, EnumDirection.NORTH)
        .withProperty(TRIGGERED, false);
  }

  public int getMetaFromState(IBlockState state) {
    return state.getValue(FACING).getIndex() | (state.getValue(TRIGGERED) ? 8 : 0);
  }

  public IBlockState getStateFromMeta(int data) {
    return this.getDefaultState()
        .withProperty(FACING, getFacing(data))
        .withProperty(TRIGGERED, (data & 8) > 0);
  }

  public IBlockState getStateForEntityRender(IBlockState state) {
    return this.getDefaultState().withProperty(FACING, EnumDirection.SOUTH);
  }

  /* Event hooks */
  public void didPlaceBlock(World world, BlockPos pos, IBlockState state) {
    super.didPlaceBlock(world, pos, state);
    this.setDefaultDirection(world, pos, state);
  }

  private void setDefaultDirection(World world, BlockPos pos, IBlockState state) {
    if (!world.isRemote) {
      EnumDirection var4 = state.getValue(FACING);
      boolean var5 = world.getBlockState(pos.offsetNorth()).getBlock().isFullBlock();
      boolean var6 = world.getBlockState(pos.offsetSouth()).getBlock().isFullBlock();

      if (var4 == EnumDirection.NORTH && var5 && !var6) {
        var4 = EnumDirection.SOUTH;
      } else if (var4 == EnumDirection.SOUTH && var6 && !var5) {
        var4 = EnumDirection.NORTH;
      } else {
        boolean var7 = world.getBlockState(pos.offsetWest()).getBlock().isFullBlock();
        boolean var8 = world.getBlockState(pos.offsetEast()).getBlock().isFullBlock();

        if (var4 == EnumDirection.WEST && var7 && !var8) {
          var4 = EnumDirection.EAST;
        } else if (var4 == EnumDirection.EAST && var8 && !var7) {
          var4 = EnumDirection.WEST;
        }
      }

      world.setBlockState(pos, state.withProperty(FACING, var4).withProperty(TRIGGERED, false), 2);
    }
  }

  public boolean didActivateBlock(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumDirection side,
      float hitX,
      float hitY,
      float hitZ) {
    if (!world.isRemote) {
      world.withTileEntity(pos, TileEntityDispenser.class, player::displayGUIChest);
    }

    return true;
  }

  protected void dispenseItem(World world, BlockPos pos) {
    world.withTileEntity(
        pos,
        TileEntityDispenser.class,
        var4 -> {
          int var5 = var4.func_146017_i();

          if (var5 < 0) {
            world.playSound(1001, pos, 0);
          } else {
            ItemStack var6 = var4.get(var5);
            IBehaviorDispenseItem var7 = this.getDispenserLogic(var6);

            if (var7 != IBehaviorDispenseItem.itemDispenseBehaviorProvider) {
              ItemStack var8 = var7.dispense(new BlockSource(world, pos), var6);
              var4.set(var5, var8.stackSize == 0 ? null : var8);
            }
          }
        });
  }

  protected IBehaviorDispenseItem getDispenserLogic(ItemStack stack) {
    return dispenseBehaviorRegistry.get(stack == null ? null : stack.getItem());
  }

  public void neighborDidChange(
      World world, BlockPos pos, IBlockState state, IBlock neighborBlock) {
    boolean var5 = world.isBlockBeingPowered(pos) || world.isBlockBeingPowered(pos.offsetUp());
    boolean var6 = state.getValue(TRIGGERED);

    if (var5 && !var6) {
      world.scheduleUpdate(pos, this, this.tickRate(world));
      world.setBlockState(pos, state.withProperty(TRIGGERED, true), 4);
    } else if (!var5 && var6) {
      world.setBlockState(pos, state.withProperty(TRIGGERED, false), 4);
    }
  }

  public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
    if (!world.isRemote) {
      this.dispenseItem(world, pos);
    }
  }

  /** Returns a new instance of a block's tile entity class. Called on placing the block. */
  public TileEntity createTileEntity(World world, int meta) {
    return new TileEntityDispenser();
  }

  public IBlockState didPlaceBlock(
      World world,
      BlockPos pos,
      EnumDirection facing,
      float hitX,
      float hitY,
      float hitZ,
      int meta,
      EntityLivingBase player) {
    return this.getDefaultState()
        .withProperty(FACING, BlockPistonBase.func_180695_a(world, pos, player))
        .withProperty(TRIGGERED, false);
  }

  public void didPlaceBlock(
      World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
    world.setBlockState(
        pos, state.withProperty(FACING, BlockPistonBase.func_180695_a(world, pos, player)), 2);
    world.withTileEntity(
        pos, TileEntityDispenser.class, t -> stack.withDisplayName(t::setCustomName));
  }

  public void didBreakBlock(World world, BlockPos pos, IBlockState state) {
    world.withTileEntity(
        pos,
        TileEntityDispenser.class,
        t -> {
          InventoryHelper.dropInventoryItems(world, pos, t);
          world.updateComparatorOutputLevel(pos, this);
        });

    super.didBreakBlock(world, pos, state);
  }

  /** Get the position where the dispenser at the given Coordinates should dispense to. */
  public static IPosition getDispensePosition(IBlockSource coords) {
    EnumDirection var1 = getFacing(coords.getBlockMetadata());
    double var2 = coords.getX() + 0.7D * var1.getOffsetX();
    double var4 = coords.getY() + 0.7D * var1.getOffsetY();
    double var6 = coords.getZ() + 0.7D * var1.getOffsetZ();
    return new PositionImpl(var2, var4, var6);
  }

  /** Get the facing of a dispenser with the given metadata */
  public static EnumDirection getFacing(int meta) {
    return EnumDirection.fromIndex(meta & 7);
  }

  public boolean hasComparatorInputOverride() {
    return true;
  }

  public int getComparatorInputOverride(World world, BlockPos pos) {
    return Container.getRedstonePower(world.getTileEntity(pos));
  }

  /** The type of render function that is called for this block */
  public int getRenderType() {
    return 3;
  }

  /* Ticking methods */
  public int tickRate(World world) {
    return 4;
  }

  /* Property methods */
  public String getBlockName() {
    return "dispenser";
  }

  public CreativeTab getCreativeTab() {
    return CreativeTab.tabRedstone;
  }

  public SoundType getStepSound() {
    return soundTypePiston;
  }

  public float getHardness() {
    return 3.5F;
  }

  public Material getMaterial() {
    return Material.rock;
  }
}
示例#13
0
public class BlockMycelium extends Block {
  public static final PropertyBool SNOWY = PropertyBool.create("snowy");

  /* BlockState methods */
  public BlockState createBlockState() {
    return new BlockState(this, SNOWY);
  }

  public IBlockState getDefaultState() {
    return this.getBaseState().withProperty(SNOWY, false);
  }

  public IBlockState getActualState(IBlockAccess world, BlockPos pos, IBlockState state) {
    return state.withProperty(SNOWY, pos.offsetUp().blockIs(world, Blocks.snow, Blocks.snow_layer));
  }

  /* Item methods */
  public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    return Blocks.dirt.getItemDropped(rand, fortune);
  }

  /* Ticking methods */
  public boolean needsRandomTick() {
    return true;
  }

  public void randomDisplayTick(World world, BlockPos pos, IBlockState state, Random rand) {
    super.randomDisplayTick(world, pos, state, rand);

    if (rand.nextInt(10) == 0) {
      world.spawnParticle(
          EnumParticleType.TOWN_AURA,
          ((float) pos.x + rand.nextFloat()),
          ((float) pos.y + 1.1F),
          ((float) pos.z + rand.nextFloat()),
          0.0D,
          0.0D,
          0.0D,
          new int[0]);
    }
  }

  public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
    if (!world.isRemote) {
      if (world.getLightFromNeighbors(pos.offsetUp()) < 4
          && world.getBlockState(pos.offsetUp()).getBlock().getLightOpacity() > 2) {
        world.setBlockState(
            pos,
            Blocks.dirt
                .getDefaultState()
                .withProperty(BlockDirt.VARIANT, BlockDirt.EnumDirtType.DIRT));
      } else if (world.getLightFromNeighbors(pos.offsetUp()) >= 9) {
        for (int i = 0; i < 4; i++) {
          BlockPos target = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
          if (pos.blockIs(world, Blocks.dirt)
              && target.getBlockProperty(world, BlockDirt.VARIANT) == BlockDirt.EnumDirtType.DIRT
              && world.getLightFromNeighbors(target.offsetUp()) >= 4
              && pos.offsetUp().getBlock(world).getLightOpacity() <= 2) {
            world.setBlockState(target, this.getDefaultState());
          }
        }
      }
    }
  }

  /* Property methods */
  public String getBlockName() {
    return "mycel";
  }

  public CreativeTab getCreativeTab() {
    return CreativeTab.tabBlock;
  }

  public SoundType getStepSound() {
    return soundTypeGrass;
  }

  public float getHardness() {
    return 0.6F;
  }

  public Material getMaterial() {
    return Material.grass;
  }
}
/** Created by Ratismal on 2016-01-13. */
public class BaseBlockSemiEthereal extends BaseBlock {
  // Blocks that can be walked through when not wearing the Transient Eye

  // public static final PropertyBool ENABLED = PropertyBool.create("enabled");
  public static final PropertyBool VISIBLE = PropertyBool.create("visible");

  public BaseBlockSemiEthereal(String name) {
    super(name);
    setHardness(3f);
    setBlockUnbreakable();
  }

  @SideOnly(Side.CLIENT)
  @Override
  public EnumWorldBlockLayer getBlockLayer() {
    //    if (TriggersMod.ClientProxy.getThePlayer().inventory.armorItemInSlot(3) != null &&
    //         TriggersMod.ClientProxy.getThePlayer().inventory.armorItemInSlot(3).getItem()
    // instanceof ItemEyeTransient) {
    return EnumWorldBlockLayer.TRANSLUCENT;
    // } else {
    //      return EnumWorldBlockLayer.CUTOUT;
    // }
  }

  @Override
  public boolean isOpaqueCube() {
    return false;
  }

  @Override
  public boolean isFullCube() {
    return false;
  }

  @Override
  public boolean isNormalCube() {
    return false;
  }

  @Override
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    if (isNoCol()) {
      return state.withProperty(VISIBLE, true);
    }
    return state.withProperty(VISIBLE, false);
  }

  public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
    return null;
  }

  @Override
  public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
    if (isNoCol()) {
      // TriggersMod.logger.info("meow");
      this.setBlockBounds(0, 0, 0, 1, 1, 1);
      // return AxisAlignedBB.getAABBPool().getAABB((double)par2, (double)par3, (double)par4,
      // (double)par2, (double)par3, (double)par4);
    } else {
      this.setBlockBounds(0, 0, 0, 0, 0, 0);
    }
  }

  @Override
  public void addCollisionBoxesToList(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      AxisAlignedBB mask,
      List<AxisAlignedBB> list,
      Entity collidingEntity) {
    // AxisAlignedBB axisalignedbb = this.getCollisionBoundingBox(worldIn, pos, state);
    // TileSemiEthereal te = getTileEntity(worldIn, pos);
    // toggleTexture(worldIn, pos, state);
    /*
    if (te != null && te.is(collidingEntity)) {
        AxisAlignedBB aabb = AxisAlignedBB.fromBounds(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1);
        if (aabb != null && aabb.intersectsWith(mask)) list.add(aabb);
        // TriggersMod.logger.info("Adding collision box");
        //list.add(mask);
        //toggleTexture(worldIn, pos, state, true);
    }
    */
    // toggleTexture(worldIn, pos, state, false);
  }

  public TileSemiEthereal getTileEntity(World world, BlockPos pos) {
    //  TriggersMod.logger.info("Getting tile entity");
    return (TileSemiEthereal) world.getTileEntity(pos);
  }

  // @SideOnly(Side.CLIENT)
  @Override
  public IBlockState getStateFromMeta(int meta) {
    return getDefaultState().withProperty(VISIBLE, (meta & 8) != 0);
  }

  // @SideOnly(Side.CLIENT)
  @Override
  public int getMetaFromState(IBlockState state) {
    return (state.getValue(VISIBLE) ? 8 : 0);
  }

  // @SideOnly(Side.CLIENT)
  @Override
  protected BlockState createBlockState() {
    return new BlockState(this, VISIBLE);
  }

  /**
   * Checks if the player is wearing an active ItemEyeTransient
   *
   * @param player player
   * @return true/false
   */
  public boolean is(EntityPlayer player) {
    // if (what == Property.SOLID) return true;

    ItemStack helmet = player.inventory.armorItemInSlot(3);

    if (helmet == null) return false;

    Item item = helmet.getItem();

    if (item instanceof ItemEyeTransient) {
      return ((ItemEyeTransient) item).checkBlock(helmet);
    }

    return false;
  }

  /**
   * is(), but without caring if the ItemEyeTransient is active or not
   *
   * @param player player
   * @return true/false
   */
  public boolean isNoCol(EntityPlayer player) {
    // if (what == Property.SOLID) return true;

    ItemStack helmet = player.inventory.armorItemInSlot(3);

    if (helmet == null) return false;

    Item item = helmet.getItem();

    if (item instanceof ItemEyeTransient) {
      return true;
    }

    return false;
  }

  public boolean is(Entity e) {
    return (e instanceof EntityPlayer) && is((EntityPlayer) e);
  }

  public boolean is() {
    EntityPlayer player = TriggersMod.ClientProxy.getThePlayer();
    return player != null && is(player);
  }

  public boolean isNoCol() {
    EntityPlayer player = TriggersMod.ClientProxy.getThePlayer();
    return player != null && isNoCol(player);
  }
}
示例#15
0
public class BlockBrewingStand extends BlockContainer {
  public static final PropertyBool[] HAS_BOTTLE =
      new PropertyBool[] {
        PropertyBool.create("has_bottle_0"),
        PropertyBool.create("has_bottle_1"),
        PropertyBool.create("has_bottle_2")
      };

  public BlockBrewingStand() {
    super(Material.iron);
    this.setDefaultState(
        this.blockState
            .getBaseState()
            .withProperty(HAS_BOTTLE[0], Boolean.valueOf(false))
            .withProperty(HAS_BOTTLE[1], Boolean.valueOf(false))
            .withProperty(HAS_BOTTLE[2], Boolean.valueOf(false)));
  }

  /** Gets the localized name of this block. Used for the statistics page. */
  public String getLocalizedName() {
    return StatCollector.translateToLocal("item.brewingStand.name");
  }

  /** Used to determine ambient occlusion and culling when rebuilding chunks for render */
  public boolean isOpaqueCube() {
    return false;
  }

  /**
   * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids,
   * -1 is no render
   */
  public int getRenderType() {
    return 3;
  }

  /** Returns a new instance of a block's tile entity class. Called on placing the block. */
  public TileEntity createNewTileEntity(World worldIn, int meta) {
    return new TileEntityBrewingStand();
  }

  public boolean isFullCube() {
    return false;
  }

  /** Add all collision boxes of this Block to the list that intersect with the given mask. */
  public void addCollisionBoxesToList(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      AxisAlignedBB mask,
      List<AxisAlignedBB> list,
      Entity collidingEntity) {
    this.setBlockBounds(0.4375F, 0.0F, 0.4375F, 0.5625F, 0.875F, 0.5625F);
    super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
    this.setBlockBoundsForItemRender();
    super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
  }

  /** Sets the block's bounds for rendering it as an item */
  public void setBlockBoundsForItemRender() {
    this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
  }

  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (worldIn.isRemote) {
      return true;
    } else {
      TileEntity tileentity = worldIn.getTileEntity(pos);

      if (tileentity instanceof TileEntityBrewingStand) {
        playerIn.displayGUIChest((TileEntityBrewingStand) tileentity);
        playerIn.triggerAchievement(StatList.field_181729_M);
      }

      return true;
    }
  }

  /** Called by ItemBlocks after a block is set in the world, to allow post-place logic */
  public void onBlockPlacedBy(
      World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    if (stack.hasDisplayName()) {
      TileEntity tileentity = worldIn.getTileEntity(pos);

      if (tileentity instanceof TileEntityBrewingStand) {
        ((TileEntityBrewingStand) tileentity).setName(stack.getDisplayName());
      }
    }
  }

  @SideOnly(Side.CLIENT)
  public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    double d0 = (double) ((float) pos.getX() + 0.4F + rand.nextFloat() * 0.2F);
    double d1 = (double) ((float) pos.getY() + 0.7F + rand.nextFloat() * 0.3F);
    double d2 = (double) ((float) pos.getZ() + 0.4F + rand.nextFloat() * 0.2F);
    worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
  }

  public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (tileentity instanceof TileEntityBrewingStand) {
      InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityBrewingStand) tileentity);
    }

    super.breakBlock(worldIn, pos, state);
  }

  /** Get the Item that this Block should drop when harvested. */
  public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    return Items.brewing_stand;
  }

  @SideOnly(Side.CLIENT)
  public Item getItem(World worldIn, BlockPos pos) {
    return Items.brewing_stand;
  }

  public boolean hasComparatorInputOverride() {
    return true;
  }

  public int getComparatorInputOverride(World worldIn, BlockPos pos) {
    return Container.calcRedstone(worldIn.getTileEntity(pos));
  }

  @SideOnly(Side.CLIENT)
  public EnumWorldBlockLayer getBlockLayer() {
    return EnumWorldBlockLayer.CUTOUT;
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    IBlockState iblockstate = this.getDefaultState();

    for (int i = 0; i < 3; ++i) {
      iblockstate = iblockstate.withProperty(HAS_BOTTLE[i], Boolean.valueOf((meta & 1 << i) > 0));
    }

    return iblockstate;
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;

    for (int j = 0; j < 3; ++j) {
      if (((Boolean) state.getValue(HAS_BOTTLE[j])).booleanValue()) {
        i |= 1 << j;
      }
    }

    return i;
  }

  protected BlockState createBlockState() {
    return new BlockState(this, new IProperty[] {HAS_BOTTLE[0], HAS_BOTTLE[1], HAS_BOTTLE[2]});
  }
}
示例#16
0
public class BlockFenceGate extends BlockHorizontal {
  public static final PropertyBool OPEN = PropertyBool.create("open");
  public static final PropertyBool POWERED = PropertyBool.create("powered");
  public static final PropertyBool IN_WALL = PropertyBool.create("in_wall");
  protected static final AxisAlignedBB AABB_COLLIDE_ZAXIS =
      new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D);
  protected static final AxisAlignedBB AABB_COLLIDE_XAXIS =
      new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D);
  protected static final AxisAlignedBB AABB_COLLIDE_ZAXIS_INWALL =
      new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 0.8125D, 0.625D);
  protected static final AxisAlignedBB AABB_COLLIDE_XAXIS_INWALL =
      new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 0.8125D, 1.0D);
  protected static final AxisAlignedBB AABB_CLOSED_SELECTED_ZAXIS =
      new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.5D, 0.625D);
  protected static final AxisAlignedBB AABB_CLOSED_SELECTED_XAXIS =
      new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.5D, 1.0D);

  public BlockFenceGate(BlockPlanks.EnumType p_i46394_1_) {
    super(Material.WOOD, p_i46394_1_.getMapColor());
    this.setDefaultState(
        this.blockState
            .getBaseState()
            .withProperty(OPEN, Boolean.valueOf(false))
            .withProperty(POWERED, Boolean.valueOf(false))
            .withProperty(IN_WALL, Boolean.valueOf(false)));
    this.setCreativeTab(CreativeTabs.REDSTONE);
  }

  public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
    state = this.getActualState(state, source, pos);
    return ((Boolean) state.getValue(IN_WALL)).booleanValue()
        ? (((EnumFacing) state.getValue(FACING)).getAxis() == EnumFacing.Axis.X
            ? AABB_COLLIDE_XAXIS_INWALL
            : AABB_COLLIDE_ZAXIS_INWALL)
        : (((EnumFacing) state.getValue(FACING)).getAxis() == EnumFacing.Axis.X
            ? AABB_COLLIDE_XAXIS
            : AABB_COLLIDE_ZAXIS);
  }

  /**
   * Get the actual Block state of this Block at the given position. This applies properties not
   * visible in the metadata, such as fence connections.
   */
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    EnumFacing.Axis enumfacing$axis = ((EnumFacing) state.getValue(FACING)).getAxis();

    if (enumfacing$axis == EnumFacing.Axis.Z
            && (worldIn.getBlockState(pos.west()).getBlock() == Blocks.COBBLESTONE_WALL
                || worldIn.getBlockState(pos.east()).getBlock() == Blocks.COBBLESTONE_WALL)
        || enumfacing$axis == EnumFacing.Axis.X
            && (worldIn.getBlockState(pos.north()).getBlock() == Blocks.COBBLESTONE_WALL
                || worldIn.getBlockState(pos.south()).getBlock() == Blocks.COBBLESTONE_WALL)) {
      state = state.withProperty(IN_WALL, Boolean.valueOf(true));
    }

    return state;
  }

  /**
   * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable,
   * returns the passed blockstate.
   */
  public IBlockState withRotation(IBlockState state, Rotation rot) {
    return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
  }

  /**
   * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns
   * the passed blockstate.
   */
  public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
    return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING)));
  }

  public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
    return worldIn.getBlockState(pos.down()).getMaterial().isSolid()
        ? super.canPlaceBlockAt(worldIn, pos)
        : false;
  }

  @Nullable
  public AxisAlignedBB getCollisionBoundingBox(
      IBlockState blockState, World worldIn, BlockPos pos) {
    return ((Boolean) blockState.getValue(OPEN)).booleanValue()
        ? NULL_AABB
        : (((EnumFacing) blockState.getValue(FACING)).getAxis() == EnumFacing.Axis.Z
            ? AABB_CLOSED_SELECTED_ZAXIS
            : AABB_CLOSED_SELECTED_XAXIS);
  }

  /** Used to determine ambient occlusion and culling when rebuilding chunks for render */
  public boolean isOpaqueCube(IBlockState state) {
    return false;
  }

  public boolean isFullCube(IBlockState state) {
    return false;
  }

  public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
    return ((Boolean) worldIn.getBlockState(pos).getValue(OPEN)).booleanValue();
  }

  /**
   * Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments
   * to the IBlockstate
   */
  public IBlockState onBlockPlaced(
      World worldIn,
      BlockPos pos,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ,
      int meta,
      EntityLivingBase placer) {
    return this.getDefaultState()
        .withProperty(FACING, placer.getHorizontalFacing())
        .withProperty(OPEN, Boolean.valueOf(false))
        .withProperty(POWERED, Boolean.valueOf(false))
        .withProperty(IN_WALL, Boolean.valueOf(false));
  }

  public boolean onBlockActivated(
      World worldIn,
      BlockPos pos,
      IBlockState state,
      EntityPlayer playerIn,
      EnumHand hand,
      @Nullable ItemStack heldItem,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (((Boolean) state.getValue(OPEN)).booleanValue()) {
      state = state.withProperty(OPEN, Boolean.valueOf(false));
      worldIn.setBlockState(pos, state, 10);
    } else {
      EnumFacing enumfacing = EnumFacing.fromAngle((double) playerIn.rotationYaw);

      if (state.getValue(FACING) == enumfacing.getOpposite()) {
        state = state.withProperty(FACING, enumfacing);
      }

      state = state.withProperty(OPEN, Boolean.valueOf(true));
      worldIn.setBlockState(pos, state, 10);
    }

    worldIn.playEvent(
        playerIn, ((Boolean) state.getValue(OPEN)).booleanValue() ? 1008 : 1014, pos, 0);
    return true;
  }

  /**
   * Called when a neighboring block was changed and marks that this state should perform any checks
   * during a neighbor change. Cases may include when redstone power is updated, cactus blocks
   * popping off due to a neighboring solid block, etc.
   */
  public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
    if (!worldIn.isRemote) {
      boolean flag = worldIn.isBlockPowered(pos);

      if (flag || blockIn.getDefaultState().canProvidePower()) {
        if (flag
            && !((Boolean) state.getValue(OPEN)).booleanValue()
            && !((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(
              pos,
              state
                  .withProperty(OPEN, Boolean.valueOf(true))
                  .withProperty(POWERED, Boolean.valueOf(true)),
              2);
          worldIn.playEvent((EntityPlayer) null, 1008, pos, 0);
        } else if (!flag
            && ((Boolean) state.getValue(OPEN)).booleanValue()
            && ((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(
              pos,
              state
                  .withProperty(OPEN, Boolean.valueOf(false))
                  .withProperty(POWERED, Boolean.valueOf(false)),
              2);
          worldIn.playEvent((EntityPlayer) null, 1014, pos, 0);
        } else if (flag != ((Boolean) state.getValue(POWERED)).booleanValue()) {
          worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)), 2);
        }
      }
    }
  }

  @SideOnly(Side.CLIENT)
  public boolean shouldSideBeRendered(
      IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
    return true;
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    return this.getDefaultState()
        .withProperty(FACING, EnumFacing.getHorizontal(meta))
        .withProperty(OPEN, Boolean.valueOf((meta & 4) != 0))
        .withProperty(POWERED, Boolean.valueOf((meta & 8) != 0));
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;
    i = i | ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();

    if (((Boolean) state.getValue(POWERED)).booleanValue()) {
      i |= 8;
    }

    if (((Boolean) state.getValue(OPEN)).booleanValue()) {
      i |= 4;
    }

    return i;
  }

  protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] {FACING, OPEN, POWERED, IN_WALL});
  }
}
示例#17
0
// Draconium slab/double slab main class.
public abstract class EABlockSlabDraconium extends BlockSlab {
  public static final PropertyBool SEAMLESS = PropertyBool.create("seamless");
  public static final PropertyEnum<EABlockSlabDraconium.EnumType> VARIANT =
      PropertyEnum.<EABlockSlabDraconium.EnumType>create(
          "variant", EABlockSlabDraconium.EnumType.class);

  public EABlockSlabDraconium() {
    super(Material.ROCK);
    this.useNeighborBrightness = !this.isDouble();
    this.setHarvestLevel("pickaxe", 2);
    this.setHardness(5.0F);
    this.setSoundType(SoundType.STONE);

    IBlockState iblockstate = this.blockState.getBaseState();

    if (this.isDouble()) {
      iblockstate = iblockstate.withProperty(SEAMLESS, Boolean.valueOf(false));
    } else {
      iblockstate = iblockstate.withProperty(HALF, EABlockSlabDraconium.EnumBlockHalf.BOTTOM);
    }

    this.setDefaultState(iblockstate.withProperty(VARIANT, EABlockSlabDraconium.EnumType.STONE));
    this.setCreativeTab(EbonArtsMod.tabEbonArtsBlocks);
  }

  /** Get the Item that this Block should drop when harvested. */
  public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    return Item.getItemFromBlock(InitBlocksEA.draconium_slab);
  }

  public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
    return new ItemStack(
        InitBlocksEA.draconium_slab,
        1,
        ((EABlockSlabDraconium.EnumType) state.getValue(VARIANT)).getMetadata());
  }

  /** Returns the slab block name with the type associated with it */
  public String getUnlocalizedName(int meta) {
    return this.getUnlocalizedName();
  }

  public IProperty<?> getVariantProperty() {
    return VARIANT;
  }

  public Comparable<?> getTypeForItem(ItemStack stack) {
    return EABlockSlabDraconium.EnumType.byMetadata(
        stack.getMetadata()
            &
            // 7
            0);
  }

  /** returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */
  @SideOnly(Side.CLIENT)
  public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
    if (itemIn != Item.getItemFromBlock(InitBlocksEA.double_draconium_slab)) {
      for (EABlockSlabDraconium.EnumType EABlockSlabDraconium$enumtype :
          EABlockSlabDraconium.EnumType.values()) {

        list.add(new ItemStack(itemIn, 1, EABlockSlabDraconium$enumtype.getMetadata()));
      }
    }
  }

  /** Convert the given metadata into a BlockState for this Block */
  public IBlockState getStateFromMeta(int meta) {
    IBlockState iblockstate =
        this.getDefaultState()
            .withProperty(
                VARIANT,
                EABlockSlabDraconium.EnumType.byMetadata(
                    meta
                        &
                        // 7
                        0));

    if (this.isDouble()) {
      iblockstate = iblockstate.withProperty(SEAMLESS, Boolean.valueOf((meta & 8) != 0));
    } else {
      iblockstate =
          iblockstate.withProperty(
              HALF,
              (meta & 8) == 0
                  ? EABlockSlabDraconium.EnumBlockHalf.BOTTOM
                  : EABlockSlabDraconium.EnumBlockHalf.TOP);
    }

    return iblockstate;
  }

  /** Convert the BlockState into the correct metadata value */
  public int getMetaFromState(IBlockState state) {
    int i = 0;
    i = i | ((EABlockSlabDraconium.EnumType) state.getValue(VARIANT)).getMetadata();

    if (this.isDouble()) {
      if (((Boolean) state.getValue(SEAMLESS)).booleanValue()) {
        i |= 8;
      }
    } else if (state.getValue(HALF) == EABlockSlabDraconium.EnumBlockHalf.TOP) {
      i |= 8;
    }

    return i;
  }

  protected BlockStateContainer createBlockState() {
    return this.isDouble()
        ? new BlockStateContainer(this, new IProperty[] {SEAMLESS, VARIANT})
        : new BlockStateContainer(this, new IProperty[] {HALF, VARIANT});
  }

  /**
   * Gets the metadata of the item this Block can drop. This method is called when the block gets
   * destroyed. It returns the metadata of the dropped item based on the old metadata of the block.
   */
  public int damageDropped(IBlockState state) {
    return ((EABlockSlabDraconium.EnumType) state.getValue(VARIANT)).getMetadata();
  }

  /// **
  // * Get the MapColor for this Block and the given BlockState
  // */
  // public MapColor getMapColor(IBlockState state)
  // {
  //    return ((EABlockSlabDraconium.EnumType)state.getValue(VARIANT)).func_181074_c();
  // }

  public static enum EnumType implements IStringSerializable {
    STONE(
        0,
        null,
        // MapColor.stoneColor,
        "stone");
    // ,
    // SAND(1, MapColor.sandColor, "sandstone", "sand"),
    // WOOD(2, MapColor.woodColor, "wood_old", "wood"),
    // COBBLESTONE(3, MapColor.stoneColor, "cobblestone", "cobble"),
    // BRICK(4, MapColor.redColor, "brick"),
    // SMOOTHBRICK(5, MapColor.stoneColor, "stone_brick", "smoothStoneBrick"),
    // NETHERBRICK(6, MapColor.netherrackColor, "nether_brick", "netherBrick"),
    // QUARTZ(7, MapColor.quartzColor, "quartz");

    private static final EABlockSlabDraconium.EnumType[] META_LOOKUP =
        new EABlockSlabDraconium.EnumType[values().length];
    private final int meta;
    private final MapColor mapColorIn;
    private final String name;
    private final String unlocalizedName;

    private EnumType(int p_i46381_3_, MapColor p_i46381_4_, String p_i46381_5_) {
      this(p_i46381_3_, p_i46381_4_, p_i46381_5_, p_i46381_5_);
    }

    private EnumType(
        int p_i46382_3_, MapColor p_i46382_4_, String p_i46382_5_, String p_i46382_6_) {
      this.meta = p_i46382_3_;
      this.mapColorIn = p_i46382_4_;
      this.name = p_i46382_5_;
      this.unlocalizedName = p_i46382_6_;
    }

    public int getMetadata() {
      return this.meta;
    }

    public MapColor func_181074_c() {
      return this.mapColorIn;
    }

    public String toString() {
      return this.name;
    }

    public static EABlockSlabDraconium.EnumType byMetadata(int meta) {
      if (meta < 0 || meta >= META_LOOKUP.length) {
        meta = 0;
      }

      return META_LOOKUP[meta];
    }

    public String getName() {
      return this.name;
    }

    public String getUnlocalizedName() {
      return this.unlocalizedName;
    }

    static {
      for (EABlockSlabDraconium.EnumType EABlockSlabDraconium$enumtype : values()) {
        META_LOOKUP[EABlockSlabDraconium$enumtype.getMetadata()] = EABlockSlabDraconium$enumtype;
      }
    }
  }
}
示例#18
0
/** Represents a Carvable (aka Chisilable) block */
public class BlockCarvable extends Block {

  /** The Property for the variation of this block */
  public PropertyVariation VARIATION;

  /** X Y and Z modules for coordinate variation */
  public static final IUnlistedProperty XMODULES =
      Properties.toUnlisted(PropertyInteger.create("X Modules", 0, 4));

  public static final IUnlistedProperty YMODULES =
      Properties.toUnlisted(PropertyInteger.create("V Section", 0, 4));
  public static final IUnlistedProperty ZMODULES =
      Properties.toUnlisted(PropertyInteger.create("Z Section", 0, 4));

  /** These are used for connected textures */
  public static final IUnlistedProperty CONNECTED_DOWN =
      Properties.toUnlisted(PropertyBool.create("Connected Down"));

  public static final IUnlistedProperty CONNECTED_UP =
      Properties.toUnlisted(PropertyBool.create("Connected Up"));
  public static final IUnlistedProperty CONNECTED_NORTH =
      Properties.toUnlisted(PropertyBool.create("Connected North"));
  public static final IUnlistedProperty CONNECTED_SOUTH =
      Properties.toUnlisted(PropertyBool.create("Connected South"));
  public static final IUnlistedProperty CONNECTED_EAST =
      Properties.toUnlisted(PropertyBool.create("Connected East"));
  public static final IUnlistedProperty CONNECTED_WEST =
      Properties.toUnlisted(PropertyBool.create("Connected West"));
  /** For connected textures corners 12 */
  public static final IUnlistedProperty CONNECTED_NORTH_EAST =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));

  public static final IUnlistedProperty CONNECTED_NORTH_WEST =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_NORTH_UP =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_NORTH_DOWN =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_SOUTH_EAST =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_SOUTH_WEST =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_SOUTH_UP =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_SOUTH_DOWN =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_EAST_UP =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_EAST_DOWN =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_WEST_UP =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));
  public static final IUnlistedProperty CONNECTED_WEST_DOWN =
      Properties.toUnlisted(PropertyBool.create("Connected North East"));

  private CarvableBlocks type;

  /** Array of all the block resources, each one represents a sub block */
  private ISubBlock[] subBlocks;

  private int index;

  private boolean isBeaconBase;

  public BlockCarvable(
      CarvableBlocks type,
      int subBlocksAmount,
      int index,
      PropertyVariation p,
      boolean isBeaconBase) {
    this(Material.rock, type, subBlocksAmount, index, p, isBeaconBase);
  }

  public BlockCarvable(
      Material material,
      CarvableBlocks type,
      int subBlocksAmount,
      int index,
      PropertyVariation p,
      boolean isBeaconBase) {
    super(material);
    this.isBeaconBase = isBeaconBase;
    subBlocks = new ISubBlock[subBlocksAmount];
    this.type = type;
    this.index = index;
    this.VARIATION = p;
    this.fullBlock = isOpaqueCube();
    this.blockState = createRealBlockState(p);
    setupStates();
    setResistance(10.0F);
    setHardness(2.0F);
    setCreativeTab(ChiselTabs.tab);
    setUnlocalizedName(type.getName());
  }

  public int getIndex() {
    return this.index;
  }

  private BlockState createRealBlockState(PropertyVariation p) {
    ExtendedBlockState state =
        new ExtendedBlockState(
            this,
            new IProperty[] {p},
            new IUnlistedProperty[] {
              CONNECTED_DOWN,
              CONNECTED_UP,
              CONNECTED_NORTH,
              CONNECTED_SOUTH,
              CONNECTED_WEST,
              CONNECTED_EAST,
              CONNECTED_NORTH_EAST,
              CONNECTED_NORTH_WEST,
              CONNECTED_NORTH_UP,
              CONNECTED_NORTH_DOWN,
              CONNECTED_SOUTH_EAST,
              CONNECTED_SOUTH_WEST,
              CONNECTED_SOUTH_UP,
              CONNECTED_SOUTH_DOWN,
              CONNECTED_EAST_UP,
              CONNECTED_EAST_DOWN,
              CONNECTED_WEST_UP,
              CONNECTED_WEST_DOWN,
              XMODULES,
              YMODULES,
              ZMODULES
            });
    return state;
  }

  @Override
  public BlockState createBlockState() {
    return Blocks.air.getBlockState();
  }

  private void setupStates() {
    Variation v = type.getVariants()[getIndex() * 16];
    this.setDefaultState(
        getExtendedBlockState()
            .withProperty(CONNECTED_DOWN, false)
            .withProperty(CONNECTED_UP, false)
            .withProperty(CONNECTED_NORTH, false)
            .withProperty(CONNECTED_SOUTH, false)
            .withProperty(CONNECTED_EAST, false)
            .withProperty(CONNECTED_WEST, false)
            .withProperty(CONNECTED_NORTH_EAST, false)
            .withProperty(CONNECTED_NORTH_WEST, false)
            .withProperty(CONNECTED_NORTH_UP, false)
            .withProperty(CONNECTED_NORTH_DOWN, false)
            .withProperty(CONNECTED_SOUTH_EAST, false)
            .withProperty(CONNECTED_SOUTH_WEST, false)
            .withProperty(CONNECTED_SOUTH_UP, false)
            .withProperty(CONNECTED_SOUTH_DOWN, false)
            .withProperty(CONNECTED_EAST_UP, false)
            .withProperty(CONNECTED_EAST_DOWN, false)
            .withProperty(CONNECTED_WEST_UP, false)
            .withProperty(CONNECTED_WEST_DOWN, false)
            .withProperty(XMODULES, 0)
            .withProperty(YMODULES, 0)
            .withProperty(ZMODULES, 0)
            .withProperty(VARIATION, v));
  }

  public ExtendedBlockState getBaseExtendedState() {
    return (ExtendedBlockState) this.getBlockState();
  }

  public IExtendedBlockState getExtendedBlockState() {
    return (IExtendedBlockState) this.getBaseExtendedState().getBaseState();
  }

  @Override
  public int damageDropped(IBlockState state) {
    return getMetaFromState(state);
  }

  @Override
  public IBlockState getStateFromMeta(int meta) {
    Variation v = Variation.fromMeta(type, meta, getIndex());
    return getBlockState().getBaseState().withProperty(VARIATION, v);
  }

  //    @Override
  //    public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX,
  // float hitY, float hitZ, int meta, EntityLivingBase placer){
  //        IBlockState state = getStateFromMeta(meta);
  //        Variation v = ((BlockCarvable)
  // state.getBlock()).getType().getVariants()[state.getBlock().getMetaFromState(state)];
  //        state.withProperty(VARIATION, v);
  //        Chisel.logger.info("Setting variation for "+((BlockCarvable)
  // state.getBlock()).getName()+" to "+v+ " placed");
  //        Chisel.logger.info("Variation is "+state.getValue(VARIATION));
  //        return state;
  //    }

  @Override
  public int getMetaFromState(IBlockState state) {
    //        if (state.getBlock() instanceof BlockCarvable){
    //            BlockCarvable b = (BlockCarvable)state.getBlock();
    //            return Variation.metaFromVariation(b.getType(), (Variation)
    // state.getValue(VARIATION));
    //        }
    return Variation.metaFromVariation(type, (Variation) state.getValue(VARIATION));
  }

  /**
   * Add a sub block
   *
   * @param subBlock
   */
  public void addSubBlock(ISubBlock subBlock) {
    if (!hasSubBlock(subBlock)) {
      for (int i = 0; i < subBlocks.length; i++) {
        if (subBlocks[i] == null) {
          subBlocks[i] = subBlock;
          // Chisel.logger.info("Adding Sub Block "+subBlock.getName()+" to "+this.getName());
          return;
        }
      }
    }
  }

  private boolean hasSubBlock(ISubBlock subBlock) {
    if (subBlock == null) {
      return true;
    }
    for (ISubBlock block : subBlocks) {
      if (block == null) {
        continue;
      }
      if (block.equals(subBlock)) {
        return true;
      }
    }
    return false;
  }

  @Override
  public boolean equals(Object object) {
    if (object instanceof BlockCarvable) {
      BlockCarvable carv = (BlockCarvable) object;
      return carv.getUnlocalizedName().equals(this.getUnlocalizedName());
    }
    return false;
  }

  /**
   * Get the sub block from the variation
   *
   * @param v the variation
   * @return The sub block
   */
  public ISubBlock getSubBlock(Variation v) {
    // Chisel.logger.info("meta: "+Variation.metaFromVariation(type, v));
    ISubBlock block = subBlocks[Variation.metaFromVariation(type, v)];
    // Chisel.logger.info("Returning sub block "+block.getName());
    return block;
  }

  public ISubBlock[] allSubBlocks() {
    return this.subBlocks;
  }

  /**
   * Name used for texture path
   *
   * @return The Name
   */
  public String getName() {
    return this.type.getName();
  }

  /**
   * Gets the type of block this is
   *
   * @return The Type
   */
  public CarvableBlocks getType() {
    return this.type;
  }

  //    @Override
  //    public IBlockState getActualState(IBlockState state, IBlockAccess w, BlockPos pos){
  //        if (state.getBlock() instanceof BlockCarvable){
  //            Variation v = ((BlockCarvable)
  // state.getBlock()).getType().getVariants()[state.getBlock().getMetaFromState(state)];
  //            state.withProperty(VARIATION, v);
  //            Chisel.logger.info("Setting variation for "+((BlockCarvable)
  // state.getBlock()).getName()+" to "+v+ " basic");
  //        }
  //        return state;
  //    }

  @Override
  public IBlockState getExtendedState(IBlockState stateIn, IBlockAccess w, BlockPos pos) {
    if (stateIn.getBlock() == null || stateIn.getBlock().getMaterial() == Material.air) {
      return stateIn;
    }
    IExtendedBlockState state = (IExtendedBlockState) stateIn;
    Variation v =
        ((BlockCarvable) state.getBlock())
            .getType()
            .getVariants()[state.getBlock().getMetaFromState(state)];
    IBlockResources res = SubBlockUtil.getResources(state.getBlock(), v);
    if (res.getType() == IBlockResources.V4 || res.getType() == IBlockResources.V9) {
      int variationSize = BlockResources.getVariationWidth(res.getType());
      int xModulus = Math.abs(pos.getX() % variationSize);
      int zModulus = Math.abs(pos.getZ() % variationSize);
      int yModules = Math.abs(pos.getY() % variationSize);
      return state
          .withProperty(XMODULES, xModulus)
          .withProperty(YMODULES, yModules)
          .withProperty(ZMODULES, zModulus);
    } else if (res.getType() == IBlockResources.NORMAL
        || res.getType() == IBlockResources.R9
        || res.getType() == IBlockResources.R4
        || res.getType() == IBlockResources.R16) {
      return stateIn;
    }

    boolean up = false;
    boolean down = false;
    boolean north = false;
    boolean south = false;
    boolean east = false;
    boolean west = false;
    boolean north_east = false;
    boolean north_west = false;
    boolean north_up = false;
    boolean north_down = false;
    boolean south_east = false;
    boolean south_west = false;
    boolean south_up = false;
    boolean south_down = false;
    boolean east_up = false;
    boolean east_down = false;
    boolean west_up = false;
    boolean west_down = false;

    if (areBlocksEqual(state, w.getBlockState(pos.up()))) {
      up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.down()))) {
      down = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.north()))) {
      north = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south()))) {
      south = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.east()))) {
      east = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.west()))) {
      west = true;
    }

    if (areBlocksEqual(state, w.getBlockState(pos.north().east()))) {
      north_east = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.north().west()))) {
      north_west = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.north().up()))) {
      north_up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.north().down()))) {
      north_down = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south().east()))) {
      south_east = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south().west()))) {
      south_west = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south().up()))) {
      south_up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.south().down()))) {
      south_down = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.east().up()))) {
      east_up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.east().down()))) {
      east_down = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.west().up()))) {
      west_up = true;
    }
    if (areBlocksEqual(state, w.getBlockState(pos.west().down()))) {
      west_down = true;
    }

    return state
        .withProperty(CONNECTED_UP, up)
        .withProperty(CONNECTED_DOWN, down)
        .withProperty(CONNECTED_NORTH, north)
        .withProperty(CONNECTED_SOUTH, south)
        .withProperty(CONNECTED_EAST, east)
        .withProperty(CONNECTED_WEST, west)
        .withProperty(CONNECTED_NORTH_EAST, north_east)
        .withProperty(CONNECTED_NORTH_WEST, north_west)
        .withProperty(CONNECTED_NORTH_UP, north_up)
        .withProperty(CONNECTED_NORTH_DOWN, north_down)
        .withProperty(CONNECTED_SOUTH_EAST, south_east)
        .withProperty(CONNECTED_SOUTH_WEST, south_west)
        .withProperty(CONNECTED_SOUTH_UP, south_up)
        .withProperty(CONNECTED_SOUTH_DOWN, south_down)
        .withProperty(CONNECTED_EAST_UP, east_up)
        .withProperty(CONNECTED_EAST_DOWN, east_down)
        .withProperty(CONNECTED_WEST_UP, west_up)
        .withProperty(CONNECTED_WEST_DOWN, west_down);
  }

  /**
   * Whether it is connected on the specified side
   *
   * @param world The World
   * @param pos The Block pos
   * @param facing The Side
   * @return Whether it is connected
   */
  public static boolean isConnected(IBlockAccess world, BlockPos pos, EnumFacing facing) {
    return blockStatesEqual(
        getBlockOrFacade(world, pos, facing),
        getBlockOrFacade(
            world,
            pos(
                pos.getX() + facing.getFrontOffsetX(),
                pos.getY() + facing.getFrontOffsetY(),
                pos.getZ() + facing.getFrontOffsetZ()),
            facing));
  }

  /**
   * Whether it is connected on the specified side
   *
   * @param world The World
   * @param x The Block x position
   * @param y The Block y position
   * @param z The Block z position
   * @param facing The Side
   * @return Whether it is connected
   */
  public static boolean isConnected(IBlockAccess world, int x, int y, int z, EnumFacing facing) {
    return isConnected(world, pos(x, y, z), facing);
  }

  public static IBlockState getBlockOrFacade(IBlockAccess world, BlockPos pos, EnumFacing side) {
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() instanceof IFacade) {
      return ((IFacade) state.getBlock()).getFacade(world, pos, side);
    }
    return state;
  }

  public static BlockPos pos(int x, int y, int z) {
    return new BlockPos(x, y, z);
  }

  /**
   * Returns whether the two block states are equal to each other
   *
   * @param state1 The First Block State
   * @param state2 The Second Block State
   * @return Whether they are equal
   */
  public static boolean blockStatesEqual(IBlockState state1, IBlockState state2) {
    for (IProperty p : (ImmutableSet<IProperty>) state1.getProperties().keySet()) {
      if (!state2.getProperties().containsKey(p)) {
        return false;
      }
      if (state1.getValue(p) != state2.getValue(p)) {
        return false;
      }
    }
    return state1.getBlock() == state2.getBlock();
  }

  /**
   * Returns whether the two blocks are equal ctm blocks
   *
   * @param state1 First state
   * @param state2 Second state
   * @return Whether they are the same block
   */
  public boolean areBlocksEqual(IBlockState state1, IBlockState state2) {
    return (state1.getBlock() == state2.getBlock()
        && ((Variation) state1.getValue(VARIATION)).equals((Variation) state2.getValue(VARIATION)));
  }

  /**
   * Whether the two positions
   *
   * @param w
   * @param pos1
   * @param pos2
   * @return
   */
  public boolean isConnected(World w, BlockPos pos1, BlockPos pos2) {
    return areBlocksEqual(w.getBlockState(pos1), w.getBlockState(pos2));
  }

  @Override
  @SideOnly(Side.CLIENT)
  public int getMixedBrightnessForBlock(IBlockAccess worldIn, BlockPos pos) {
    return 0xf << 20;
  }

  @Override
  @SideOnly(Side.CLIENT)
  public void getSubBlocks(Item item, CreativeTabs tab, List list) {
    int curIndex = 0;
    for (ISubBlock sub : subBlocks) {
      if (sub == null) {
        continue;
      }
      ItemStack stack = new ItemStack(item, 1, curIndex);
      curIndex++;
      // CTMBlockResources r = SubBlockUtil.getResources(sub);
      // setLore(stack, r.getLore());
      list.add(stack);
    }
  }

  @Override
  public int getRenderType() {
    return 3;
  }

  @Override
  public boolean isOpaqueCube() {
    if (type == null) {
      return true;
    }
    return type.isOpaqueCube();
  }

  @Override
  public boolean isFullCube() {
    return false;
  }

  @Override
  public boolean isVisuallyOpaque() {
    return false;
  }

  @Override
  public boolean isBeaconBase(IBlockAccess worldObj, BlockPos pos, BlockPos beacon) {
    return this.isBeaconBase;
  }

  @Override
  public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
    AxisAlignedBB axis = type.getCollisionBoundingBox(worldIn, pos, state);
    if (axis != null) {
      return axis;
    }
    return super.getCollisionBoundingBox(worldIn, pos, state);
  }

  @Override
  public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, Entity entityIn) {
    type.onEntityCollidedWithBlock(worldIn, pos, entityIn);
  }
}
public class BlockRedstoneComparator extends BlockRedstoneDiode implements ITileEntityProvider {
  public static final PropertyBool POWERED = PropertyBool.create("powered");
  public static final PropertyEnum<Mode> MODE = PropertyEnum.create("mode", Mode.class);

  public BlockRedstoneComparator(boolean powered) {
    super(powered);
  }

  /* BlockState methods */
  public TileEntity createTileEntity(World world, int meta) {
    return new TileEntityComparator();
  }

  public BlockState createBlockState() {
    return new BlockState(this, DIRECTION, MODE, POWERED);
  }

  public IBlockState getDefaultState() {
    return super.getDefaultState()
        .withProperty(POWERED, false)
        .withProperty(MODE, BlockRedstoneComparator.Mode.COMPARE);
  }

  public int getMetaFromState(IBlockState state) {
    return super.getMetaFromState(state)
        | (state.getValue(POWERED) ? 8 : 0)
        | (state.getValue(MODE) == Mode.SUBTRACT ? 4 : 0);
  }

  public IBlockState getStateFromMeta(int data) {
    return super.getStateFromMeta(data)
        .withProperty(POWERED, (data & 8) > 0)
        .withProperty(
            MODE,
            (data & 4) > 0
                ? BlockRedstoneComparator.Mode.SUBTRACT
                : BlockRedstoneComparator.Mode.COMPARE);
  }

  /* Item methods */
  public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    return Items.comparator;
  }

  public Item getItem(World world, BlockPos pos) {
    return Items.comparator;
  }

  protected int func_176403_d(IBlockState state) {
    return 2;
  }

  protected IBlockState getPoweredState(IBlockState state) {
    return Blocks.powered_comparator
        .getDefaultState()
        .withProperty(DIRECTION, state.getValue(DIRECTION))
        .withProperty(POWERED, state.getValue(POWERED))
        .withProperty(MODE, state.getValue(MODE));
  }

  protected IBlockState getUnpoweredState(IBlockState state) {
    return Blocks.unpowered_comparator
        .getDefaultState()
        .withProperty(DIRECTION, state.getValue(DIRECTION))
        .withProperty(POWERED, state.getValue(POWERED))
        .withProperty(MODE, state.getValue(MODE));
  }

  protected int func_176408_a(IBlockAccess world, BlockPos pos, IBlockState state) {
    return F.let(
        world.getTileEntity(pos, TileEntityComparator.class),
        t -> t == null ? 0 : t.getOutputSignal());
  }

  private int func_176460_j(World world, BlockPos pos, IBlockState state) {
    return state.getValue(MODE) == BlockRedstoneComparator.Mode.SUBTRACT
        ? Math.max(
            this.getRedstonePower(world, pos, state) - this.func_176407_c(world, pos, state), 0)
        : this.getRedstonePower(world, pos, state);
  }

  protected boolean isPowered(IBlockState state) {
    return this.powered || state.getValue(POWERED);
  }

  protected boolean isPowered(World world, BlockPos pos, IBlockState state) {
    int var4 = this.getRedstonePower(world, pos, state);

    if (var4 >= 15) {
      return true;
    } else if (var4 == 0) {
      return false;
    } else {
      int var5 = this.func_176407_c(world, pos, state);
      return var5 == 0 || var4 >= var5;
    }
  }

  protected int getRedstonePower(World world, BlockPos pos, IBlockState state) {
    int var4 = super.getRedstonePower(world, pos, state);
    EnumDirection var5 = state.getValue(DIRECTION);
    BlockPos var6 = pos.offset(var5);
    IBlock var7 = world.getBlockState(var6).getBlock();

    if (var7.hasComparatorInputOverride()) {
      var4 = var7.getComparatorInputOverride(world, var6);
    } else if (var4 < 15 && var7.isNormalCube()) {
      var6 = var6.offset(var5);
      var7 = world.getBlockState(var6).getBlock();

      if (var7.hasComparatorInputOverride()) {
        var4 = var7.getComparatorInputOverride(world, var6);
      } else if (var7.getMaterial() == Material.air) {
        EntityItemFrame var8 = this.func_176461_a(world, var5, var6);

        if (var8 != null) {
          var4 = var8.func_174866_q();
        }
      }
    }

    return var4;
  }

  private EntityItemFrame func_176461_a(World world, EnumDirection direction, BlockPos pos) {
    List var4 =
        world.getEntitiesWithinAABB(
            EntityItemFrame.class,
            AxisAlignedBB.newBlock(pos),
            e -> e != null && e.getFacing() == direction);
    return var4.size() == 1 ? (EntityItemFrame) var4.get(0) : null;
  }

  protected void func_176398_g(World world, BlockPos pos, IBlockState state) {
    if (!world.isBlockTickPending(pos, this)) {
      int var4 = this.func_176460_j(world, pos, state);
      int var6 =
          F.or(
              world.bindTileEntity(
                  pos, TileEntityComparator.class, TileEntityComparator::getOutputSignal),
              0);

      if (var4 != var6 || this.isPowered(state) != this.isPowered(world, pos, state)) {
        if (this.func_176402_i(world, pos, state)) {
          world.scheduleUpdate(pos, this, 2, -1);
        } else {
          world.scheduleUpdate(pos, this, 2, 0);
        }
      }
    }
  }

  private void func_176462_k(World world, BlockPos pos, IBlockState state) {
    int newStrength = this.func_176460_j(world, pos, state);
    int oldStrength =
        F.or(
            world.bindTileEntity(
                pos,
                TileEntityComparator.class,
                t -> {
                  int old = t.getOutputSignal();
                  t.setOutputSignal(newStrength);
                  return old;
                }),
            0);

    if (oldStrength != newStrength
        || state.getValue(MODE) == BlockRedstoneComparator.Mode.COMPARE) {
      boolean var9 = this.isPowered(world, pos, state);
      boolean var8 = this.isPowered(state);

      if (var8 && !var9) {
        world.setBlockState(pos, state.withProperty(POWERED, false), 2);
      } else if (!var8 && var9) {
        world.setBlockState(pos, state.withProperty(POWERED, true), 2);
      }

      this.updateRedstoneState(world, pos, state);
    }
  }

  /* Event hooks */
  public boolean didActivateBlock(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumDirection side,
      float hitX,
      float hitY,
      float hitZ) {
    if (player.capabilities.allowEdit) {
      state = state.cycleProperty(MODE);
      world.playSoundAtLocation(
          pos.getCenter(),
          "random.click",
          0.3F,
          state.getValue(MODE) == BlockRedstoneComparator.Mode.SUBTRACT ? 0.55F : 0.5F);
      world.setBlockState(pos, state, 2);
      this.func_176462_k(world, pos, state);
      return true;
    } else {
      return false;
    }
  }

  public void didPlaceBlock(World world, BlockPos pos, IBlockState state) {
    super.didPlaceBlock(world, pos, state);
    world.setTileEntity(pos, this.createTileEntity(world, 0));
  }

  public IBlockState didPlaceBlock(
      World world,
      BlockPos pos,
      EnumDirection facing,
      float hitX,
      float hitY,
      float hitZ,
      int meta,
      EntityLivingBase player) {
    return this.getDefaultState()
        .withProperty(DIRECTION, player.getFacing().getOpposite())
        .withProperty(POWERED, false)
        .withProperty(MODE, BlockRedstoneComparator.Mode.COMPARE);
  }

  public void didBreakBlock(World world, BlockPos pos, IBlockState state) {
    super.didBreakBlock(world, pos, state);
    world.removeTileEntity(pos);
    this.updateRedstoneState(world, pos, state);
  }

  public boolean didReceiveBlockEvent(
      World world, BlockPos pos, IBlockState state, int eventID, int eventParam) {
    super.didReceiveBlockEvent(world, pos, state, eventID, eventParam);
    TileEntity tileEntity = world.getTileEntity(pos);
    return tileEntity != null && tileEntity.receiveClientEvent(eventID, eventParam);
  }

  /* Ticking methods */
  public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
    if (this.powered) {
      world.setBlockState(pos, this.getUnpoweredState(state).withProperty(POWERED, true), 4);
    }

    this.func_176462_k(world, pos, state);
  }

  /* Property methods */
  public String getBlockName() {
    return "comparator";
  }

  public SoundType getStepSound() {
    return soundTypeWood;
  }

  public boolean getEnableStats() {
    return false;
  }

  public boolean hasTileEntity() {
    return true;
  }

  public int getLightLevel() {
    return this.powered ? 10 : 0;
  }

  public float getHardness() {
    return 0.0F;
  }

  /** Internal comparator mode enum */
  public enum Mode implements IStringSerializable {
    COMPARE,
    SUBTRACT
  }
}