@Inject(method = "<init>", at = @At("RETURN"))
 public void onConstructed(
     List<net.minecraftforge.common.util.BlockSnapshot> blockSnapshots,
     IBlockState placedAgainst,
     EntityPlayer player,
     CallbackInfo ci) {
   ImmutableList.Builder<Transaction<BlockSnapshot>> builder =
       new ImmutableList.Builder<Transaction<BlockSnapshot>>();
   for (net.minecraftforge.common.util.BlockSnapshot blockSnapshot : blockSnapshots) {
     BlockSnapshot spongeOriginalBlockSnapshot =
         ((IMixinBlockSnapshot) blockSnapshot).createSpongeBlockSnapshot();
     BlockSnapshot replacementSnapshot =
         ((IMixinBlockSnapshot)
                 net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(
                     blockSnapshot.world, blockSnapshot.pos))
             .createSpongeBlockSnapshot();
     builder.add(new Transaction<BlockSnapshot>(spongeOriginalBlockSnapshot, replacementSnapshot));
   }
   this.blockTransactions = builder.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
  public boolean place(Block block, int meta) {
    if (!world.blockExists(x, y, z)) return false;

    if (spawnProtection) {
      if (!world.canMineBlock(player, x, y, z)) return false;
    }

    final BlockSnapshot snapshot =
        net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(world, x, y, z);

    if (!world.setBlock(x, y, z, block, meta, blockPlaceFlags)) return false;

    if (ForgeEventFactory.onPlayerBlockPlace(
            player, snapshot, net.minecraftforge.common.util.ForgeDirection.UNKNOWN)
        .isCanceled()) {
      world.restoringBlockSnapshots = true;
      snapshot.restore(true, false);
      world.restoringBlockSnapshots = false;
      return false;
    }

    return true;
  }