Exemplo n.º 1
0
  @Override
  public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
    if (!world.blockExists(x, y, z)) {
      return null;
    }

    TileEntity tile = world.getTileEntity(x, y, z);

    switch (id) {
      case 0:
        if (!(tile instanceof TileAssemblyTable)) {
          return null;
        } else {
          return new ContainerAssemblyTable(player.inventory, (TileAssemblyTable) tile);
        }

      case 1:
        if (!(tile instanceof TileAdvancedCraftingTable)) {
          return null;
        } else {
          return new ContainerAdvancedCraftingTable(
              player.inventory, (TileAdvancedCraftingTable) tile);
        }

      case 2:
        if (!(tile instanceof TileIntegrationTable)) {
          return null;
        } else {
          return new ContainerIntegrationTable(player.inventory, (TileIntegrationTable) tile);
        }

      default:
        return null;
    }
  }
Exemplo n.º 2
0
  public void handlePacket(Packet250CustomPayload packet) throws IOException {

    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet.data));

    byte type = dis.readByte();

    World world = net.minecraft.client.Minecraft.getMinecraft().theWorld;

    ISyncHandler handler = null;

    if (type == TYPE_TILE) {
      int x = dis.readInt();
      int y = dis.readInt();
      int z = dis.readInt();
      if (world != null) {
        if (world.blockExists(x, y, z)) {
          TileEntity tile = world.getBlockTileEntity(x, y, z);
          if (tile instanceof ISyncHandler) {
            handler = (ISyncHandler) tile;
          }
        }
      }
    } else if (type == TYPE_ENTITY) {
      int entityId = dis.readInt();
      Entity entity = world.getEntityByID(entityId);
      if (entity != null && entity instanceof ISyncHandler) {
        handler = (ISyncHandler) entity;
      }
    }
    if (handler != null) {
      List<ISyncableObject> changes = handler.getSyncMap().readFromStream(dis);
      handler.onSynced(changes);
    }
    dis.close();
  }
Exemplo n.º 3
0
  public boolean generate(World world, Random random, int x, int y, int z) {

    if (!world.blockExists(x, y, z)) {
      return false;
    }

    int i = y;
    while (world.getBlock(x, i, z) != Blocks.stone) {
      if (i > 96) return false; // Don't generate marble over y96
      i++;
      addBlock(x, i, z, 6);
    }
    while ((this.marbleVein.size() > 0) && (this.numberOfBlocks > 0)) {
      List blocksToGenerate = (List) this.marbleVein.removeFirst();
      Integer[] blockToSet = (Integer[]) blocksToGenerate.toArray();
      if (world.getBlock(blockToSet[0], blockToSet[1], blockToSet[2]) == Blocks.stone) {
        world.setBlock(blockToSet[0], blockToSet[1], blockToSet[2], this.block);
        if (blockToSet[3] > 0) {
          searchBlock(world, blockToSet[0], blockToSet[1], blockToSet[2], blockToSet[3] - 1);
        }
        this.numberOfBlocks -= 1;
      }
    }
    return true;
  }
 public static void unpath(World world, int i, int j, int k) {
   List<ChunkCoordinates> blocks = Lists.newLinkedList();
   List<ChunkCoordinates> notify = Lists.newLinkedList();
   blocks.add(new ChunkCoordinates(i, j, k));
   while (blocks.size() > 0) {
     ChunkCoordinates coords = blocks.remove(0);
     depolarize(world, coords.posX + 1, coords.posY, coords.posZ, blocks);
     depolarize(world, coords.posX, coords.posY + 1, coords.posZ, blocks);
     depolarize(world, coords.posX, coords.posY, coords.posZ + 1, blocks);
     depolarize(world, coords.posX - 1, coords.posY, coords.posZ, blocks);
     depolarize(world, coords.posX, coords.posY - 1, coords.posZ, blocks);
     depolarize(world, coords.posX, coords.posY, coords.posZ - 1, blocks);
     notify.add(coords);
   }
   for (ChunkCoordinates coords : notify) {
     if (world.blockExists(coords.posX, coords.posY, coords.posZ)) {
       world.markBlockForUpdate(coords.posX, coords.posY, coords.posZ);
       world.notifyBlocksOfNeighborChange(
           coords.posX,
           coords.posY,
           coords.posZ,
           world.getBlock(coords.posX, coords.posY, coords.posZ));
     }
   }
 }
Exemplo n.º 5
0
  /* Safe Tile Entity Retrieval */
  public static TileEntity getAdjacentTileEntity(
      World world, int x, int y, int z, ForgeDirection dir) {

    x += dir.offsetX;
    y += dir.offsetY;
    z += dir.offsetZ;
    return world == null || !world.blockExists(x, y, z) ? null : world.getTileEntity(x, y, z);
  }
 @Override
 public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int metaData) {
   if (!world.isRemote) {
     if (world.blockExists(x, y - 1, z)) {
       world.setBlock(x, y - 1, z, Blocks.air);
     }
   }
 }
 public void activate(Vector3f pos) {
   if (_world.blockExists((int) pos.getX(), (int) pos.getY(), (int) pos.getZ())) {
     Block blk =
         Block.blocksList[_world.getBlockId((int) pos.getX(), (int) pos.getY(), (int) pos.getZ())];
     blk.onBlockActivated(
         _world, (int) pos.getX(), (int) pos.getY(), (int) pos.getZ(), _player, 0, 0, 0, 0);
   }
 }
  private void setBlocks(World par1World, int x, int y, int z, boolean item, int blockid) {
    if (par1World.blockExists(x, y, z)) {
      if (par1World.getBlockId(x, y, z) != blockid) {
        par1World.destroyBlock(x, y, z, item);
      }

      par1World.setBlock(x, y, z, blockid);
    }
  }
  @Override
  public void processCommand(ICommandSender icommandsender, String[] astring) {

    ArrayList<ChunkCoordinates> ccListsb = new ArrayList<ChunkCoordinates>();
    ArrayList<ChunkCoordinates> ccListdb = new ArrayList<ChunkCoordinates>();
    boolean sameBiome;
    int offset = 1;
    ChunkCoordinates cc = icommandsender.getPlayerCoordinates();
    EntityPlayerMP player = getCommandSenderAsPlayer(icommandsender);

    World w = player.worldObj;
    BiomeGenBase bg = w.getBiomeGenForCoords(cc.posX, cc.posZ);

    sameBiome = true;

    int olddb, newdb;

    newdb = 0;

    while (sameBiome == true) {

      olddb = newdb;

      for (int i = -offset; i <= offset; i++) {
        for (int j = -offset; j <= offset; j++) {
          if (w.getBiomeGenForCoords(cc.posX + i, cc.posZ + j) == bg) {
            ccListsb.add(new ChunkCoordinates(cc.posX + i, 0, cc.posZ + j));
          } else {
            ccListdb.add(new ChunkCoordinates(cc.posX + i, 0, cc.posZ + j));
          }
        }
      }

      newdb = ccListdb.size();

      if ((newdb - olddb >= offset * 8 || offset == 512)) {
        System.out.println("" + ccListsb.size());
        sameBiome = false;
      } else {
        ccListdb.clear();
        ccListsb.clear();
      }

      offset++;
    }

    for (int j = 0; j < ccListsb.size(); j++) {
      for (int i = 0; i < 256; i++) {
        if (w.blockExists(ccListsb.get(j).posX, i, ccListsb.get(j).posZ))
          w.destroyBlock(ccListsb.get(j).posX, i, ccListsb.get(j).posZ, false);
      }
    }

    System.out.println("Done");
  }
Exemplo n.º 10
0
 private static void pathto(World world, int i, int j, int k) {
   List<ChunkCoordinates> blocks = Lists.newLinkedList();
   List<ChunkCoordinates> portals = Lists.newLinkedList();
   List<ChunkCoordinates> repath = Lists.newLinkedList();
   List<ChunkCoordinates> redraw = Lists.newLinkedList();
   blocks.add(new ChunkCoordinates(i, j, k));
   while ((portals.size() > 0) || (blocks.size() > 0)) {
     while (blocks.size() > 0) {
       ChunkCoordinates coords = blocks.remove(0);
       directPortal(world, coords.posX + 1, coords.posY, coords.posZ, 5, blocks, portals);
       directPortal(world, coords.posX, coords.posY + 1, coords.posZ, 1, blocks, portals);
       directPortal(world, coords.posX, coords.posY, coords.posZ + 1, 3, blocks, portals);
       directPortal(world, coords.posX - 1, coords.posY, coords.posZ, 6, blocks, portals);
       directPortal(world, coords.posX, coords.posY - 1, coords.posZ, 2, blocks, portals);
       directPortal(world, coords.posX, coords.posY, coords.posZ - 1, 4, blocks, portals);
       redraw.add(coords);
     }
     if (portals.size() > 0) {
       ChunkCoordinates coords = portals.remove(0);
       directPortal(world, coords.posX + 1, coords.posY, coords.posZ, 5, blocks, portals);
       directPortal(world, coords.posX, coords.posY + 1, coords.posZ, 1, blocks, portals);
       directPortal(world, coords.posX, coords.posY, coords.posZ + 1, 3, blocks, portals);
       directPortal(world, coords.posX - 1, coords.posY, coords.posZ, 6, blocks, portals);
       directPortal(world, coords.posX, coords.posY - 1, coords.posZ, 2, blocks, portals);
       directPortal(world, coords.posX, coords.posY, coords.posZ - 1, 4, blocks, portals);
       if (world.getBlock(coords.posX, coords.posY, coords.posZ) == NailedBlocks.portal) {
         repath.add(coords);
       }
     }
   }
   while (repath.size() > 0) {
     ChunkCoordinates coords = repath.remove(0);
     if (world.getBlock(coords.posX, coords.posY, coords.posZ) == NailedBlocks.portal) {
       if (!BlockPortal.isValidPortal(world, coords.posX, coords.posY, coords.posZ)) {
         repathNeighbors(world, coords.posX, coords.posY, coords.posZ);
         world.setBlock(coords.posX, coords.posY, coords.posZ, Blocks.air, 0, 0);
         addSurrounding(repath, coords.posX, coords.posY, coords.posZ);
       } else {
         redraw.add(coords);
       }
     }
   }
   for (ChunkCoordinates coords : redraw) {
     if (world.blockExists(coords.posX, coords.posY, coords.posZ)) {
       world.markBlockForUpdate(coords.posX, coords.posY, coords.posZ);
       world.notifyBlocksOfNeighborChange(
           coords.posX,
           coords.posY,
           coords.posZ,
           world.getBlock(coords.posX, coords.posY, coords.posZ));
     }
   }
 }
 private void breakBlocks(World par1World, int x, int y, int z, boolean item) {
   if (par1World.blockExists(x, y, z)) {
     if (par1World.getBlockId(x, y, z) == SpacecraftBlocks.caravanModulePart.blockID
         || par1World.getBlockId(x, y, z) == GCCoreBlocks.glowstoneTorch.blockID
         || par1World.getBlockId(x, y, z) == Block.furnaceBurning.blockID
         || par1World.getBlockId(x, y, z) == Block.furnaceIdle.blockID
         || par1World.getBlockId(x, y, z) == Block.chest.blockID
         || par1World.getBlockId(x, y, z) == Block.workbench.blockID) {
       par1World.destroyBlock(x, y, z, item);
     }
   }
 }
 @Override
 public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
   switch (id) {
     case 0:
     case 1:
       break;
     case 2:
       return new GuiContainerBasic(new ContainerItemShield(player), prefix + "shield");
     case 3:
       return new GuiItemTeleporter(player);
     case 4:
       return new GuiItemFloater(player);
     case 5:
       return new GuiContainerBasic(new ContainerItemFilter(player), prefix + "filterItem");
     case 6:
       return new GuiItemFilterInstaller(player);
     case 7:
       return new GuiContainerBasic(new ContainerItemCollector(player), prefix + "collector");
   }
   if (!world.blockExists(x, y, z)) return null;
   TileEntity tileEntity = world.getTileEntity(x, y, z);
   if (tileEntity instanceof TileEntitySmeltingMachine)
     return new GuiSmeltingMachine(player, (TileEntitySmeltingMachine) tileEntity);
   if (tileEntity instanceof TileEntityRepairingMachine)
     return new GuiRepairingMachine(player, (TileEntityRepairingMachine) tileEntity);
   if (tileEntity instanceof TileEntityConvertingMachine)
     return new GuiConvertingMachine(player, (TileEntityConvertingMachine) tileEntity);
   if (tileEntity instanceof TileEntityFusingMachine)
     return new GuiFusingMachine(player, (TileEntityFusingMachine) tileEntity);
   if (tileEntity instanceof TileEntityTeleportingMarker)
     return new GuiTeleportingMarker(player, (TileEntityTeleportingMarker) tileEntity);
   if (tileEntity instanceof TileEntityPresentBox)
     return new GuiPresentBox(player, (TileEntityPresentBox) tileEntity);
   if (id == 1) {
     if (tileEntity instanceof TileEntityPlacer)
       return new GuiWorldEditorBase.GuiPlacer(player, (TileEntityPlacer) tileEntity);
     if (tileEntity instanceof TileEntityCollector)
       return new GuiWorldEditorBase.GuiCollector(player, (TileEntityCollector) tileEntity);
     if (tileEntity instanceof TileEntityWorldEditorBase)
       return new GuiWorldEditorBase(player, (TileEntityWorldEditorBase) tileEntity);
   } else if (id == 0) {
     if (tileEntity instanceof TileEntityWorldEditorBase)
       return new GuiSettingWorldEditorBase((TileEntityWorldEditorBase) tileEntity);
   }
   return null;
 }
Exemplo n.º 13
0
  public void processPacket211(Packet211TileDesc var1, NetHandler var2) {
    if (var2 instanceof NetClientHandler) {
      NetClientHandler var3 = (NetClientHandler) var2;
      World var4 = var3.getPlayer().worldObj;

      if (var4.blockExists(var1.xCoord, var1.yCoord, var1.zCoord)) {
        TileEntity var5 = var4.getBlockTileEntity(var1.xCoord, var1.yCoord, var1.zCoord);

        if (var5 instanceof IHandlePackets) {
          ((IHandlePackets) var5).handlePacket(var1);
          return;
        }
      }
    } else {
      super.processPacket211(var1, var2);
    }
  }
Exemplo n.º 14
0
  @Override
  public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

    if (!world.blockExists(x, y, z)) return null;

    TileEntity tile = world.getBlockTileEntity(x, y, z);

    switch (ID) {
      case 0:
        if (!(tile instanceof TileAssemblyTable)) return null;
        return new GuiAssemblyTable(player.inventory, (TileAssemblyTable) tile);

      case 1:
        if (!(tile instanceof TileAdvancedCraftingTable)) return null;
        return new GuiAdvancedCraftingTable(player.inventory, (TileAdvancedCraftingTable) tile);
      default:
        return null;
    }
  }
Exemplo n.º 15
0
 public static IImmersiveConnectable toIIC(Object object, World world) {
   if (object instanceof IImmersiveConnectable) return (IImmersiveConnectable) object;
   else if (object instanceof ChunkCoordinates
       && world != null
       && world.blockExists(
           ((ChunkCoordinates) object).posX,
           ((ChunkCoordinates) object).posY,
           ((ChunkCoordinates) object).posZ)
       && world.getTileEntity(
               ((ChunkCoordinates) object).posX,
               ((ChunkCoordinates) object).posY,
               ((ChunkCoordinates) object).posZ)
           instanceof IImmersiveConnectable) {
     return (IImmersiveConnectable)
         world.getTileEntity(
             ((ChunkCoordinates) object).posX,
             ((ChunkCoordinates) object).posY,
             ((ChunkCoordinates) object).posZ);
   }
   return null;
 }
Exemplo n.º 16
0
  /** Refresh validity of each conductor in the network */
  public void refreshWithChecks() {
    int tierfound = 2;
    Iterator<IConductor> it = this.conductors.iterator();
    while (it.hasNext()) {
      IConductor conductor = it.next();

      if (conductor == null) {
        it.remove();
        continue;
      }

      TileEntity tile = (TileEntity) conductor;
      World world = tile.getWorldObj();
      // Remove any conductors in unloaded chunks
      if (tile.isInvalid()
          || world == null
          || !world.blockExists(tile.xCoord, tile.yCoord, tile.zCoord)) {
        it.remove();
        continue;
      }

      if (conductor != world.getTileEntity(tile.xCoord, tile.yCoord, tile.zCoord)) {
        it.remove();
        continue;
      }

      if (conductor.getTierGC() < 2) {
        tierfound = 1;
      }

      if (conductor.getNetwork() != this) {
        conductor.setNetwork(this);
        conductor.onNetworkChanged();
      }
    }

    // This will set the network tier to 2 if all the conductors are tier 2
    this.networkTierGC = tierfound;
  }
Exemplo n.º 17
0
  public boolean remove() {
    if (!world.blockExists(x, y, z)) return false;

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

    if (eventCheck) {
      final Block block = world.getBlock(x, y, z);
      final int meta = world.getBlockMetadata(x, y, z);
      BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, meta, player);
      event.setExpToDrop(0);

      MinecraftForge.EVENT_BUS.post(event);

      if (event.isCanceled()) return false;
    }

    if (silentTeRemove) world.removeTileEntity(x, y, z);

    return world.setBlockToAir(x, y, z);
  }
Exemplo n.º 18
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;
  }
  private void breakBlocksOther(World par1World, int x, int y, int z, boolean item) {
    if (par1World.blockExists(x, y, z)) {

      par1World.destroyBlock(x, y, z, item);
    }
  }
Exemplo n.º 20
0
  public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr) {
    if (par2ArrayOfStr.length >= 1) {
      String var3 = par2ArrayOfStr[0];
      double var4 = (double) par1ICommandSender.getCommandSenderPosition().posX + 0.5D;
      double var6 = (double) par1ICommandSender.getCommandSenderPosition().posY;
      double var8 = (double) par1ICommandSender.getCommandSenderPosition().posZ + 0.5D;

      if (par2ArrayOfStr.length >= 4) {
        var4 = func_110666_a(par1ICommandSender, var4, par2ArrayOfStr[1]);
        var6 = func_110666_a(par1ICommandSender, var6, par2ArrayOfStr[2]);
        var8 = func_110666_a(par1ICommandSender, var8, par2ArrayOfStr[3]);
      }

      World var10 = par1ICommandSender.getEntityWorld();

      if (!var10.blockExists((int) var4, (int) var6, (int) var8)) {
        notifyAdmins(par1ICommandSender, "commands.summon.outOfWorld", new Object[0]);
      } else {
        NBTTagCompound var11 = new NBTTagCompound();
        boolean var12 = false;

        if (par2ArrayOfStr.length >= 5) {
          IChatComponent var13 = func_147178_a(par1ICommandSender, par2ArrayOfStr, 4);

          try {
            NBTBase var14 = JsonToNBT.func_150315_a(var13.getUnformattedText());

            if (!(var14 instanceof NBTTagCompound)) {
              notifyAdmins(
                  par1ICommandSender, "commands.summon.tagError", new Object[] {"Not a valid tag"});
              return;
            }

            var11 = (NBTTagCompound) var14;
            var12 = true;
          } catch (NBTException var17) {
            notifyAdmins(
                par1ICommandSender, "commands.summon.tagError", new Object[] {var17.getMessage()});
            return;
          }
        }

        var11.setString("id", var3);
        Entity var18 = EntityList.createEntityFromNBT(var11, var10);

        if (var18 != null) {
          var18.setLocationAndAngles(var4, var6, var8, var18.rotationYaw, var18.rotationPitch);

          if (!var12 && var18 instanceof EntityLiving) {
            ((EntityLiving) var18).onSpawnWithEgg((IEntityLivingData) null);
          }

          var10.spawnEntityInWorld(var18);
          Entity var19 = var18;

          for (NBTTagCompound var15 = var11;
              var15.func_150297_b("Riding", 10);
              var15 = var15.getCompoundTag("Riding")) {
            Entity var16 = EntityList.createEntityFromNBT(var15.getCompoundTag("Riding"), var10);

            if (var16 != null) {
              var16.setLocationAndAngles(var4, var6, var8, var16.rotationYaw, var16.rotationPitch);
              var10.spawnEntityInWorld(var16);
              var19.mountEntity(var16);
            }

            var19 = var16;
          }

          notifyAdmins(par1ICommandSender, "commands.summon.success", new Object[0]);
        } else {
          notifyAdmins(par1ICommandSender, "commands.summon.failed", new Object[0]);
        }
      }
    } else {
      throw new WrongUsageException("commands.summon.usage", new Object[0]);
    }
  }