示例#1
0
  public Schematic flip(final ISchematic schematic, final EnumFacing axis, boolean forced)
      throws FlipException {
    final Vec3i dimensionsFlipped =
        new Vec3i(schematic.getWidth(), schematic.getHeight(), schematic.getLength());
    final Schematic schematicFlipped =
        new Schematic(
            schematic.getIcon(),
            dimensionsFlipped.getX(),
            dimensionsFlipped.getY(),
            dimensionsFlipped.getZ());
    final MBlockPos tmp = new MBlockPos();

    for (final MBlockPos pos :
        BlockPosHelper.getAllInBox(
            0,
            0,
            0,
            schematic.getWidth() - 1,
            schematic.getHeight() - 1,
            schematic.getLength() - 1)) {
      final IBlockState blockState = schematic.getBlockState(pos);
      final IBlockState blockStateFlipped = flipBlock(blockState, axis, forced);
      schematicFlipped.setBlockState(flipPos(pos, axis, dimensionsFlipped, tmp), blockStateFlipped);
    }

    final List<TileEntity> tileEntities = schematic.getTileEntities();
    for (final TileEntity tileEntity : tileEntities) {
      final BlockPos pos = tileEntity.getPos();
      tileEntity.setPos(new BlockPos(flipPos(pos, axis, dimensionsFlipped, tmp)));
      schematicFlipped.setTileEntity(tileEntity.getPos(), tileEntity);
    }

    return schematicFlipped;
  }
示例#2
0
 public static void log(World world, TileEntity te, String message, Object... args) {
   if (doLogging) {
     long ticks = world.getTotalWorldTime();
     if (ticks != prevTicks) {
       prevTicks = ticks;
       getInstance().logger.log(Level.INFO, "=== Time " + ticks + " ===");
     }
     String id = te.getPos().getX() + "," + te.getPos().getY() + "," + te.getPos().getZ() + ": ";
     getInstance().logger.log(Level.INFO, id + String.format(message, args));
   }
 }
 private void runThroughNetwork(BlockPos pos) {
   for (EnumFacing facing : EnumFacing.values()) {
     BlockPos searchPos = pos.offset(facing);
     if (worldObj.getTileEntity(pos) instanceof INetworkPart
         && !((INetworkPart) worldObj.getTileEntity(pos)).getNeighborFaces().contains(facing))
       continue;
     if (worldObj.getTileEntity(searchPos) instanceof INetworkPart
         && !((INetworkPart) worldObj.getTileEntity(searchPos))
             .getNeighborFaces()
             .contains(facing.getOpposite())) continue;
     if (!getWorld().isAirBlock(searchPos)) {
       TileEntity tile = getWorld().getTileEntity(searchPos);
       if (tile != null) {
         if (tile instanceof TileNetworkCore && !tile.getPos().equals(this.pos)) {
           worldObj.setBlockToAir(searchPos);
           worldObj.playEvent(2001, searchPos, Block.getIdFromBlock(Registry.networkCore));
           StackHelper.spawnItemStack(worldObj, searchPos, new ItemStack(Registry.networkCore));
           markForNetworkInit();
         } else if (tile instanceof INetworkPart && !network.networkParts.contains(tile)) {
           network.addPart((INetworkPart) tile);
         } else if (InvHelper.hasItemHandler(tile, facing.getOpposite())
             && !network.networkParts.contains(
                 InvHelper.getItemHandler(tile, facing.getOpposite()))) {
           network.addPart(
               new InventoryNetworkPart(
                   tile.getWorld(),
                   searchPos,
                   InvHelper.getItemHandler(tile, facing.getOpposite())));
         } else continue;
         runThroughNetwork(searchPos);
       }
     }
   }
 }
 @Override
 protected IMessage handleMessage(
     DeviceChangeExposureMessage message, MessageContext ctx, TileEntity te) {
   if (te instanceof TileEntityBeefBase) {
     TileEntityBeefBase beefTe = (TileEntityBeefBase) te;
     if (message.increment) {
       beefTe.incrSide(message.side);
     } else {
       beefTe.decrSide(message.side);
     }
   } else {
     BRLog.warning(
         "Received SideChangeMessage for TE at %d, %d, %d, but it was not a TE with an iterable side exposure!",
         te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
   }
   return null;
 }
示例#5
0
 @Override
 public void recieveMana(int mana) {
   int tiles = validPools.size();
   if (tiles != 0) {
     int manaForEach = mana / tiles;
     for (IManaReceiver pool : validPools) {
       pool.recieveMana(manaForEach);
       TileEntity tile = (TileEntity) pool;
       VanillaPacketDispatcher.dispatchTEToNearbyPlayers(worldObj, tile.getPos());
     }
   }
 }
示例#6
0
  public static void DropItems(TileEntity tileEntity, int min, int max) {
    if (!(tileEntity instanceof IInventory)) {
      return;
    }

    IInventory inventory = (IInventory) tileEntity;
    World world = tileEntity.getWorld();
    BlockPos blockPos = tileEntity.getPos();

    for (int i = min; i <= max; i++) {
      ItemStack itemStack = inventory.getStackInSlot(i);

      if (itemStack != null && itemStack.stackSize > 0) {
        Random rand = new Random();

        float dX = rand.nextFloat() * 0.8F + 0.1F;
        float dY = rand.nextFloat() * 0.8F + 0.1F;
        float dZ = rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityItem =
            new EntityItem(
                world,
                blockPos.getX() + dX,
                blockPos.getY() + dY,
                blockPos.getZ() + dZ,
                itemStack.copy());

        if (itemStack.hasTagCompound()) {
          entityItem
              .getEntityItem()
              .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
        }

        float factor = 0.05F;
        entityItem.motionX = rand.nextGaussian() * factor;
        entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
        entityItem.motionZ = rand.nextGaussian() * factor;
        world.spawnEntityInWorld(entityItem);
        itemStack.stackSize = 0;
        inventory.setInventorySlotContents(i, null);
      }
    }

    inventory.markDirty();
  }
示例#7
0
 public static void notifyBlockUpdateAtTile(TileEntity te) {
   final IBlockState state = te.getWorld().getBlockState(te.getPos());
   te.getWorld().notifyBlockUpdate(te.getPos(), state, state, 3);
 }
示例#8
0
  @Override
  public void renderEntities(
      final Entity renderViewEntity, final ICamera camera, final float partialTicks) {
    final int entityPass = 0;

    this.profiler.startSection("prepare");
    TileEntityRendererDispatcher.instance.cacheActiveRenderInfo(
        this.world,
        this.mc.getTextureManager(),
        this.mc.fontRendererObj,
        renderViewEntity,
        partialTicks);
    this.renderManager.cacheActiveRenderInfo(
        this.world,
        this.mc.fontRendererObj,
        renderViewEntity,
        this.mc.pointedEntity,
        this.mc.gameSettings,
        partialTicks);

    this.countEntitiesTotal = 0;
    this.countEntitiesRendered = 0;

    this.countTileEntitiesTotal = 0;
    this.countTileEntitiesRendered = 0;

    final double x = PLAYER_POSITION_OFFSET.x;
    final double y = PLAYER_POSITION_OFFSET.y;
    final double z = PLAYER_POSITION_OFFSET.z;

    TileEntityRendererDispatcher.staticPlayerX = x;
    TileEntityRendererDispatcher.staticPlayerY = y;
    TileEntityRendererDispatcher.staticPlayerZ = z;

    TileEntityRendererDispatcher.instance.entityX = x;
    TileEntityRendererDispatcher.instance.entityY = y;
    TileEntityRendererDispatcher.instance.entityZ = z;

    this.renderManager.setRenderPosition(x, y, z);
    this.mc.entityRenderer.enableLightmap();

    this.profiler.endStartSection("blockentities");
    RenderHelper.enableStandardItemLighting();

    for (final ContainerLocalRenderInformation renderInfo : this.renderInfos) {
      for (final TileEntity tileEntity :
          (List<TileEntity>) renderInfo.renderChunk.getCompiledChunk().getTileEntities()) {
        final AxisAlignedBB renderBB = tileEntity.getRenderBoundingBox();

        this.countTileEntitiesTotal++;
        if (!tileEntity.shouldRenderInPass(entityPass)
            || !camera.isBoundingBoxInFrustum(renderBB)) {
          continue;
        }

        if (!this.mc.theWorld.isAirBlock(tileEntity.getPos().add(this.world.position))) {
          continue;
        }

        TileEntityRendererDispatcher.instance.renderTileEntity(tileEntity, partialTicks, -1);
        this.countTileEntitiesRendered++;
      }
    }

    this.mc.entityRenderer.disableLightmap();
    this.profiler.endSection();
  }
示例#9
0
  public void run() {
    try {
      if (general.dynamicTankEasterEgg) {
        pointer
            .getWorld()
            .playSound(
                null,
                pointer.getPos().getX(),
                pointer.getPos().getY(),
                pointer.getPos().getZ(),
                MekanismSounds.CJ_EASTER_EGG,
                SoundCategory.BLOCKS,
                1F,
                1F);
      }

      loop(pointer);
    } catch (Exception e) {
    }

    try {
      new Thread() {
        @Override
        public void run() {
          World world = pointer.getWorld();

          for (Coord4D coord : iteratedNodes) {
            for (int i = 0; i < 6; i++) {
              world.spawnParticle(
                  EnumParticleTypes.REDSTONE,
                  coord.xCoord + random.nextDouble(),
                  coord.yCoord + -.01,
                  coord.zCoord + random.nextDouble(),
                  0,
                  0,
                  0);
              world.spawnParticle(
                  EnumParticleTypes.REDSTONE,
                  coord.xCoord + random.nextDouble(),
                  coord.yCoord + 1.01,
                  coord.zCoord + random.nextDouble(),
                  0,
                  0,
                  0);
              world.spawnParticle(
                  EnumParticleTypes.REDSTONE,
                  coord.xCoord + random.nextDouble(),
                  coord.yCoord + random.nextDouble(),
                  coord.zCoord + -.01,
                  0,
                  0,
                  0);
              world.spawnParticle(
                  EnumParticleTypes.REDSTONE,
                  coord.xCoord + random.nextDouble(),
                  coord.yCoord + random.nextDouble(),
                  coord.zCoord + 1.01,
                  0,
                  0,
                  0);
              world.spawnParticle(
                  EnumParticleTypes.REDSTONE,
                  coord.xCoord + -.01,
                  coord.yCoord + random.nextDouble(),
                  coord.zCoord + random.nextDouble(),
                  0,
                  0,
                  0);
              world.spawnParticle(
                  EnumParticleTypes.REDSTONE,
                  coord.xCoord + 1.01,
                  coord.yCoord + random.nextDouble(),
                  coord.zCoord + random.nextDouble(),
                  0,
                  0,
                  0);
            }
          }
        }
      }.start();
    } catch (Exception e) {
    }
  }
  @Override
  public void renderTileEntityAt(
      TileEntity te, double x, double y, double z, float partialTick, int destroyStage) {
    TileEntityCampfire campfire = (TileEntityCampfire) te;
    World world = te.getWorld();
    BlockPos pos = te.getPos();
    IBlockState state = world.getBlockState(pos);

    GlStateManager.pushMatrix();
    // Translate to the proper coordinates.
    GlStateManager.translate(x, y, z);

    EnumAxis axis = (EnumAxis) state.getValue(BlockCampfire.FACING);

    // Clear all rotation on the model parts before setting new rotation angles.
    model.fire.resetState();
    model.stick.resetState();
    model.cookingPot.resetState();
    model.stickItem.resetState();
    model.cookingItem.resetState();
    model.fuel.resetState();

    // Construct the proper ModelResourceLocation from STICK_LOC and the variant string.
    String properties = ModelHelpers.getPropertyString(state.getProperties());
    ModelResourceLocation stickLoc = ModelHelpers.getLocationWithProperties(STICK, properties);
    model.stick.setModelLocation(stickLoc, world, pos);

    boolean hasCookingPot = campfire.hasCookingPot();

    float stickRot = campfire.prevRot + (campfire.rot - campfire.prevRot) * partialTick;
    model.stick.rotateAngleZ += stickRot;

    if (axis == EnumAxis.Z) {
      model.stick.rotateAngleY += 90;
    }

    boolean burning = campfire.isBurning();

    // Set fire model location.
    if (burning) {
      model.fire.setModelLocation(
          ModelHelpers.getLocationWithProperties(FIRE, "fire=uncovered"), world, pos);
    } else if (campfire.isWet()) {
      if (fireModels.contains("wet")) {
        model.fire.setModelLocation(
            ModelHelpers.getLocationWithProperties(FIRE, "fire=wet"), world, pos);
      }
    } else {
      if (fireModels.contains("none")) {
        model.fire.setModelLocation(
            ModelHelpers.getLocationWithProperties(FIRE, "fire=none"), world, pos);
      }
    }

    if (hasCookingPot) {
      // Show only the cooking pot model.
      model.stickItem.showModel = false;
      model.cookingPot.showModel = true;

      model.cookingPot.setModelLocation(
          ModelHelpers.getLocationWithProperties(COOKING_POT, properties), world, pos);
    } else {
      ItemStack input = campfire.getInput();

      if (input != null) {
        String itemID = getVariantNameForCookingItem(input);

        if (itemID != null) {
          // Change fire model to a "covered" version so that it doesn't clip through the cooking
          // item.
          if (burning) {
            model.fire.setModelLocation(
                ModelHelpers.getLocationWithProperties(FIRE, "fire=covered"), world, pos);
          }

          model.cookingItem.setModelLocation(
              ModelHelpers.getLocationWithProperties(COOKING_ITEM, "item=" + itemID), world, pos);
        } else {
          // Show only the impaled item.
          model.stickItem.showModel = true;
          model.cookingPot.showModel = false;

          // Set the stack to render on the stick.
          model.stickItem.setStack(input);
          // Reset item's transformations.
          model.stickItem.rotateAngleX += 90;

          if (ModelHelpers.isGeneratedItemModel(input)) {
            // Offset the item to prevent Z-fighting.
            model.stickItem.offsetX -= 0.0001F;

            // Scale the item to half size.
            model.stickItem.scaleX *= 0.5F;
            model.stickItem.scaleY *= 0.5F;
            model.stickItem.scaleZ *= 0.5F;

            // Scale the item to be thicker, and actually appear to be impaled.
            model.stickItem.scaleZ *= 3;
          }
        }
      }
    }

    // Render a fuel model in the campfire (with possibility for custom models for individual
    // items).
    // Will try to fall back to variant "item=generic_fuel" if no model definition is found.
    ItemStack fuel = campfire.getFuel();

    if (fuel != null) {
      String itemID = ModelHelpers.getStringIDInSetForStack(fuel, fuelModels, "generic_fuel");

      if (itemID != null) {
        model.fuel.setModelLocation(
            ModelHelpers.getLocationWithProperties(FUEL, "item=" + itemID), world, pos);
      }
    }

    // Render the model.
    model.renderAll();

    GlStateManager.popMatrix();
  }
  protected boolean setTarget(boolean doSet, int destFreq) {
    if (!GalacticraftCore.isPlanetsLoaded
        || FMLCommonHandler.instance().getMinecraftServerInstance() == null
        || FMLCommonHandler.instance().getMinecraftServerInstance().worldServers == null) {
      return false;
    }

    WorldServer[] servers = FMLCommonHandler.instance().getMinecraftServerInstance().worldServers;

    for (int i = 0; i < servers.length; i++) {
      WorldServer world = servers[i];

      try {
        Class<?> controllerClass =
            Class.forName(
                "micdoodle8.mods.galacticraft.planets.mars.tile.TileEntityLaunchController");

        for (TileEntity tile : new ArrayList<TileEntity>(world.loadedTileEntityList)) {
          if (tile != null) {
            tile = world.getTileEntity(tile.getPos());
            if (tile == null) continue;

            try {
              controllerClass.cast(tile);
            } catch (ClassCastException e) {
              continue;
            }

            int controllerFrequency = controllerClass.getField("frequency").getInt(tile);

            if (destFreq == controllerFrequency) {
              boolean targetSet = false;

              blockLoop:
              for (int x = -2; x <= 2; x++) {
                for (int z = -2; z <= 2; z++) {
                  BlockPos pos = new BlockPos(tile.getPos().add(x, 0, z));
                  Block block = world.getBlockState(pos).getBlock();

                  if (block instanceof BlockLandingPadFull) {
                    if (doSet) {
                      this.targetVec = pos;
                    }

                    targetSet = true;
                    break blockLoop;
                  }
                }
              }

              if (doSet) {
                this.targetDimension = tile.getWorld().provider.getDimensionId();
              }

              if (!targetSet) {
                if (doSet) {
                  this.targetVec = null;
                }

                return false;
              } else {
                return true;
              }
            }
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    return false;
  }
  public boolean setFrequency() {
    if (!GalacticraftCore.isPlanetsLoaded) {
      return false;
    }

    for (int x = MathHelper.floor_double(this.posX) - 1;
        x <= MathHelper.floor_double(this.posX) + 1;
        x++) {
      for (int y = MathHelper.floor_double(this.posY) - 3;
          y <= MathHelper.floor_double(this.posY) + 1;
          y++) {
        for (int z = MathHelper.floor_double(this.posZ) - 1;
            z <= MathHelper.floor_double(this.posZ) + 1;
            z++) {
          BlockPos pos = new BlockPos(x, y, z);
          TileEntity tile = this.worldObj.getTileEntity(pos);

          if (tile instanceof IFuelDock) {
            IFuelDock dock = (IFuelDock) tile;

            try {
              TileEntity launchController = null;
              Class<?> controllerClass =
                  Class.forName(
                      "micdoodle8.mods.galacticraft.planets.mars.tile.TileEntityLaunchController");

              for (ILandingPadAttachable connectedTile : dock.getConnectedTiles()) {
                try {
                  controllerClass.cast(connectedTile);
                } catch (ClassCastException e) {
                  continue;
                }

                launchController = (TileEntity) connectedTile;
                if (launchController != null) {
                  TileEntity tile2 =
                      launchController.getWorld().getTileEntity(launchController.getPos());

                  try {
                    controllerClass.cast(tile2);
                  } catch (ClassCastException e) {
                    launchController = null;
                    continue;
                  }

                  launchController = tile2;
                }

                if (launchController != null) {
                  break;
                }
              }

              if (launchController != null) {
                Boolean b =
                    (Boolean) controllerClass.getMethod("validFrequency").invoke(launchController);

                if (b != null && b) {
                  int controllerFrequency =
                      controllerClass.getField("destFrequency").getInt(launchController);
                  boolean foundPad = this.setTarget(false, controllerFrequency);

                  if (foundPad) {
                    this.destinationFrequency = controllerFrequency;
                    GCLog.debug(
                        "Rocket under launch control: going to target frequency "
                            + controllerFrequency);
                    return true;
                  }
                }
              }
            } catch (ClassCastException e) {
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      }
    }

    this.destinationFrequency = -1;
    return false;
  }