Exemplo n.º 1
0
 @Override
 public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) throws IOException {
   ByteBufInputStream bis = new ByteBufInputStream(buffer);
   x = bis.readInt();
   y = bis.readInt();
   z = bis.readInt();
   DataInputStream dis = new DataInputStream(bis);
   tag = NBTHelper.nbtRead(dis);
 }
  @SubscribeEvent
  public void onClientPacket(ClientCustomPacketEvent event) {

    EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
    ByteBufInputStream bbis = new ByteBufInputStream(event.packet.payload());
    byte packetType;
    int dimension;
    byte packetID;
    try {
      packetType = bbis.readByte();
      dimension = bbis.readInt();
      World world = DimensionManager.getWorld(dimension);
      if (packetType == 2) {
        this.handleRocketJumpHackyPacket(bbis, world);
      }
      if (packetType == 3) {
        this.handleExplodePacket(bbis, world);
      }
      //        	for (int i = 0; i < 3; i++){
      //        		player.worldObj.spawnParticle("smoke", x, y, z, -0.005D+(Math.random()*0.01D),
      // 0.025D, -0.005D+(Math.random()*0.01D));
      //        	}

      bbis.close();
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
  }
  private void handleRocketJumpHackyPacket(ByteBufInputStream dat, World world) {
    try {
      int id = dat.readInt();
      EntityPlayer player = (EntityPlayer) world.getEntityByID(id);
      if (player != null) {
        double motionX = dat.readDouble();
        double motionY = dat.readDouble();
        double motionZ = dat.readDouble();

        Minecraft.getMinecraft().thePlayer.motionX += motionX;
        Minecraft.getMinecraft().thePlayer.motionY += motionY;
        Minecraft.getMinecraft().thePlayer.motionZ += motionZ;
      }
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
  }
  @Override
  public void processData(EntityPlayer entityPlayer, ByteBufInputStream bbis) throws IOException {
    super.processData(entityPlayer, bbis);

    ItemStack itemStack = entityPlayer.getHeldItem();
    side = bbis.readInt();

    boolean result =
        entityPlayer
            .worldObj
            .getBlock(x, y, z)
            .onBlockActivated(entityPlayer.worldObj, x, y, z, entityPlayer, side, 1.0F, 1.0F, 1.0F);

    if (!result) {
      if (itemStack != null && itemStack.getItem() instanceof ItemBlock) {
        itemStack.tryPlaceItemIntoWorld(
            entityPlayer, entityPlayer.worldObj, x, y, z, side, 1.0F, 1.0F, 1.0F);
        if (!entityPlayer.capabilities.isCreativeMode && --itemStack.stackSize <= 0) {
          entityPlayer.inventory.setInventorySlotContents(
              entityPlayer.inventory.currentItem, (ItemStack) null);
        }
      }
    }
  }
Exemplo n.º 5
0
  @SubscribeEvent
  public void onServerPacket(ServerCustomPacketEvent event) {

    if (!event.packet.channel().equals(Telepads.channelName)) return;

    EntityPlayerMP p = ((NetHandlerPlayServer) event.handler).playerEntity;
    ByteBufInputStream dis = new ByteBufInputStream(event.packet.payload());
    ByteBuf buf = event.packet.payload();

    World world = p.worldObj;

    int x = (int) p.posX;
    int y = (int) p.posY;
    int z = (int) p.posZ;

    try {

      int packetID = dis.readInt();

      int x2 = dis.readInt();
      int y2 = dis.readInt();
      int z2 = dis.readInt();

      TETelepad pad = (TETelepad) p.worldObj.getTileEntity(x2, y2, z2);

      switch (packetID) {
        case IDENTIFIER_GUI:
          int id = dis.readInt();
          p.openGui(Telepads.instance, id, world, x2, y2, z2);
          break;

        case IDENTIFIER_NAMEPAD:
          String name = dis.readUTF();
          String channel = dis.readUTF();

          pad.telepadname = name;
          pad.TELEPORTCHANNEL = channel;

          TelepadWorldData.get(world).addPad(pad);
          pad.markDirty();
          TelepadWorldData.get(world).markDirty();

          ByteBuf buff = Unpooled.buffer();
          ByteBufOutputStream out = new ByteBufOutputStream(buff);
          try {

            out.writeInt(ServerPacketHandler.IDENTIFIER_NAMEPAD);
            out.writeInt(x2);
            out.writeInt(y2);
            out.writeInt(z2);
            out.writeUTF(name);
            out.writeUTF(channel);
            out.close();

            if (!p.worldObj.isRemote)
              Telepads.Channel.sendTo(new FMLProxyPacket(buf, Telepads.channelName), p);

          } catch (IOException e) {
            e.printStackTrace();
          }
          break;

        case IDENTIFIER_TELEPORTER:
          if (dis.readInt() == GuiTeleport.EXIT_BUTTON) {
            pad.resetTE();
            pad.getDescriptionPacket();
            break;
          } else {
            // reset pad BEFORE the player gets teleported, or else it might be out of range and
            // can't be reset
            pad.resetTE();
            pad.getDescriptionPacket();

            int otherPadX = dis.readInt();
            int otherPadY = dis.readInt();
            int otherPadZ = dis.readInt();

            int dimID = dis.readInt();

            // if the dimension id = the End, play endscreen and teleport to spawn point.
            // this is needed or game will act funny if you don't.
            if (dimID != p.worldObj.provider.dimensionId) {
              if (p.worldObj.provider.dimensionId == 1) {
                p.travelToDimension(1);
              } else {
                p.travelToDimension(dimID);
                p.setPositionAndUpdate(otherPadX + 2, otherPadY + 0.5d, otherPadZ);
              }

            } else {
              p.setPositionAndUpdate(otherPadX + 2, otherPadY + 0.5d, otherPadZ);
            }
          }

          break;

        case IDENTIFIER_PLATFORM:
          boolean b = dis.readBoolean();

          pad.isStandingOnPlatform = b;

          if (b == false) {
            pad.resetTE();
            pad.playerStandingOnPad = null;
          }

          break;

        case IDENTIFIER_RESETnNOTIFY:
          p.addChatMessage(new ChatComponentText(dis.readUTF()));
          pad.resetTE();
          break;
      }

      dis.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }