Ejemplo n.º 1
0
 @Override
 public void writeToNBT(NBTTagCompound tagCompound) {
   super.writeToNBT(tagCompound);
   if (link != null) {
     NBTTagCompound linkTag = new NBTTagCompound();
     link.writeToNBT(linkTag);
     tagCompound.setTag("link", linkTag);
   }
   tagCompound.setBoolean("noEnergy", noEnergy);
   storage.writeToNBT(tagCompound);
 }
Ejemplo n.º 2
0
  public void onStepped(Entity stepper) {
    if (worldObj.isRemote || link == null) return;

    if (here == null) here = Vector3.getNewVector().set(this);
    if (linkPos == null) {
      linkPos = Vector3.getNewVector().set(link.x, link.y, link.z);
    }

    double distSq = 0;
    long time = worldObj.getTotalWorldTime();
    long lastStepped = stepper.getEntityData().getLong("lastWarpPadUse");
    boolean tele =
        link != null
            && !link.isEmpty()
            && lastStepped + COOLDOWN <= time
            && (MAXRANGE < 0 || (distSq = here.distToSq(linkPos)) < MAXRANGE * MAXRANGE);
    if (tele && Config.instance.warpPadEnergy && !noEnergy) {
      int energy = (int) (distSq);
      tele = storage.extractEnergy(energy, false) == energy;

      if (!tele) {
        worldObj.playSoundEffect(
            getPos().getX(), getPos().getY(), getPos().getZ(), "note.bd", 1.0F, 1.0F);
        stepper.getEntityData().setLong("lastWarpPadUse", time);
      }
    }

    if (tele) {
      worldObj.playSoundEffect(
          getPos().getX(), getPos().getY(), getPos().getZ(), "mob.endermen.portal", 1.0F, 1.0F);
      PacketBuffer buff = new PacketBuffer(Unpooled.buffer());
      buff.writeByte(9);
      here.writeToBuff(buff);
      MessageClient packet = new MessageClient(buff);
      PokecubePacketHandler.sendToAllNear(packet, here, stepper.dimension, 20);
      stepper.getEntityData().setLong("lastWarpPadUse", time);
      TeleDest d = new TeleDest(link);
      Vector3 loc = d.getLoc();
      int dim = d.getDim();
      if (stepper instanceof EntityPlayer) {
        Transporter.teleportEntity(stepper, loc, dim, false);
      } else if (dim == d.getDim()) {
        stepper.setPositionAndUpdate(loc.x, loc.y, loc.z);
      } else {
        return;
      }
      worldObj.playSoundEffect(loc.x, loc.y, loc.z, "mob.endermen.portal", 1.0F, 1.0F);
      buff = new PacketBuffer(Unpooled.buffer());
      buff.writeByte(9);
      linkPos.writeToBuff(buff);
      packet = new MessageClient(buff);
      PokecubePacketHandler.sendToAllNear(packet, linkPos, stepper.dimension, 20);
    }
  }
Ejemplo n.º 3
0
 @Callback(
     doc =
         "function(x:number, y:number, z:number, w:number) - Sets the 4-vector destination, w is the dimension")
 @Optional.Method(modid = "OpenComputers")
 public Object[] setDestination(Context context, Arguments args) throws Exception {
   if (args.isDouble(0) && args.isDouble(1) && args.isDouble(2) && args.isDouble(3)) {
     float x = (float) args.checkDouble(0);
     float y = (float) args.checkDouble(1);
     float z = (float) args.checkDouble(2);
     float w = (float) args.checkDouble(3);
     if (link == null) {
       link = new Vector4(x, y, z, w);
     } else {
       link.set(x, y, z, w);
     }
     return new Object[] {link.x, link.y, link.z, link.w};
   }
   throw new Exception("invalid arguments, expected number,number,number,number");
 }