@Inject(method = "<init>", at = @At("RETURN"))
 public void onConstructed(
     net.minecraft.world.World world,
     BlockPos pos,
     IBlockState state,
     EntityPlayer player,
     CallbackInfo ci) {
   this.blockOriginal = ((World) world).createSnapshot(pos.getX(), pos.getY(), pos.getZ());
   this.blockReplacement =
       BlockTypes.AIR
           .getDefaultState()
           .snapshotFor(new Location<World>((World) world, VecHelper.toVector(pos)));
   this.blockTransactions =
       new ImmutableList.Builder<BlockTransaction>()
           .add(new BlockTransaction(this.blockOriginal, this.blockReplacement))
           .build();
 }
 @SuppressWarnings("unchecked")
 public void createSpongeData() {
   List<BlockPos> affectedPositions = this.explosion.func_180343_e();
   ImmutableList.Builder<BlockTransaction> builder =
       new ImmutableList.Builder<BlockTransaction>();
   for (BlockPos pos : affectedPositions) {
     Location<World> location = new Location<World>((World) this.world, VecHelper.toVector(pos));
     BlockSnapshot originalSnapshot =
         ((IMixinBlockSnapshot)
                 net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(this.world, pos))
             .createSpongeBlockSnapshot();
     final SpongeBlockSnapshotBuilder replacementBuilder =
         new SpongeBlockSnapshotBuilder()
             .blockState(BlockTypes.AIR.getDefaultState())
             .position(location.getBlockPosition())
             .worldId(location.getExtent().getUniqueId());
     BlockSnapshot replacementSnapshot = replacementBuilder.build();
     builder.add(new BlockTransaction(originalSnapshot, replacementSnapshot)).build();
   }
   this.blockTransactions = builder.build();
 }
Ejemplo n.º 3
0
  @Override
  public boolean triggerMechanic(Location block, Sign sign, Human human, Boolean forceState) {

    if (!SignUtil.getTextRaw(sign, 1).equals("[Door]")) {

      Direction back =
          SignUtil.getTextRaw(sign, 1).equals("[Door Up]") ? Direction.UP : Direction.DOWN;

      Location baseBlock = block.getRelative(back);

      Location otherSide = getOtherEnd(block, back, maximumLength);
      if (otherSide == null) {
        if (human instanceof CommandSource)
          ((CommandSource) human).sendMessage(Texts.builder("Missing other end!").build());
        return true;
      }

      Location otherBase = otherSide.getRelative(back.getOpposite());

      if (!baseBlock.getBlock().equals(otherBase.getBlock())) {
        if (human instanceof CommandSource)
          ((CommandSource) human)
              .sendMessage(Texts.builder("Both ends must be the same material!").build());
        return true;
      }

      int leftBlocks = 0, rightBlocks = 0; // Default to 0. Single width bridge is the default.

      Location left = baseBlock.getRelative(SignUtil.getLeft(block));
      Location right = baseBlock.getRelative(SignUtil.getRight(block));

      // Calculate left distance
      Location otherLeft = otherBase.getRelative(SignUtil.getLeft(block));

      while (true) {
        if (leftBlocks >= maximumWidth) break;
        if (left.getBlock().equals(baseBlock.getBlock())
            && otherLeft.getBlock().equals(baseBlock.getBlock())) {
          leftBlocks++;
          left = left.getRelative(SignUtil.getLeft(block));
          otherLeft = otherLeft.getRelative(SignUtil.getLeft(block));
        } else {
          break;
        }
      }

      // Calculate right distance
      Location otherRight = otherBase.getRelative(SignUtil.getRight(block));

      while (true) {
        if (rightBlocks >= maximumWidth) break;
        if (right.getBlock().equals(baseBlock.getBlock())
            && otherRight.getBlock().equals(baseBlock.getBlock())) {
          rightBlocks++;
          right = right.getRelative(SignUtil.getRight(block));
          otherRight = otherRight.getRelative(SignUtil.getRight(block));
        } else {
          break;
        }
      }

      baseBlock = baseBlock.getRelative(back);

      BlockState type = block.getRelative(back).getBlock();
      if (baseBlock.getBlock().equals(type) && (forceState == null || !forceState))
        type = BlockTypes.AIR.getDefaultState();

      while (baseBlock.getBlockY() != otherSide.getBlockY() + (back == Direction.UP ? -1 : 1)) {

        baseBlock.setBlock(type);

        left = baseBlock.getRelative(SignUtil.getLeft(block));

        for (int i = 0; i < leftBlocks; i++) {
          left.setBlock(type);
          left = left.getRelative(SignUtil.getLeft(block));
        }

        right = baseBlock.getRelative(SignUtil.getRight(block));

        for (int i = 0; i < rightBlocks; i++) {
          right.setBlock(type);
          right = right.getRelative(SignUtil.getRight(block));
        }

        baseBlock = baseBlock.getRelative(back);
      }
    } else {
      if (human instanceof CommandSource)
        ((CommandSource) human)
            .sendMessage(Texts.builder("Door not activatable from here!").build());
      return false;
    }

    return true;
  }