net.minecraft.world.storage.MapData Java Examples

The following examples show how to use net.minecraft.world.storage.MapData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapDownloader.java    From ForgeHax with MIT License 6 votes vote down vote up
private void downloadMap(MapData data, String fileName, Integer scaledRes) {
  if (fileName == null) {
    fileName = data.mapName;
  }

  ResourceLocation location = findResourceLocation(data.mapName);
  if (location == null) {
    Helper.printMessage("Failed to find ResourceLocation");
    return;
  }

  DynamicTexture texture = (DynamicTexture) MC.getTextureManager().getTexture(location);
  BufferedImage image = dynamicToImage(texture);
  if (scaledRes != null) {
    image = createResizedCopy(image, scaledRes, scaledRes, true);
  }

  saveImage(fileName, image);
}
 
Example #2
Source File: RenderCyberlimbHand.java    From Cyberware with MIT License 5 votes vote down vote up
private void renderMapFirstPerson(ItemStack stack)
{
	GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
	GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
	GlStateManager.scale(0.38F, 0.38F, 0.38F);
	GlStateManager.disableLighting();
	this.mc.getTextureManager().bindTexture(RES_MAP_BACKGROUND);
	Tessellator tessellator = Tessellator.getInstance();
	VertexBuffer vertexbuffer = tessellator.getBuffer();
	GlStateManager.translate(-0.5F, -0.5F, 0.0F);
	GlStateManager.scale(0.0078125F, 0.0078125F, 0.0078125F);
	vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
	vertexbuffer.pos(-7.0D, 135.0D, 0.0D).tex(0.0D, 1.0D).endVertex();
	vertexbuffer.pos(135.0D, 135.0D, 0.0D).tex(1.0D, 1.0D).endVertex();
	vertexbuffer.pos(135.0D, -7.0D, 0.0D).tex(1.0D, 0.0D).endVertex();
	vertexbuffer.pos(-7.0D, -7.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
	tessellator.draw();
	
	if (stack != null)
	{
		MapData mapdata = Items.FILLED_MAP.getMapData(stack, Minecraft.getMinecraft().theWorld);

		if (mapdata != null)
		{
			this.mc.entityRenderer.getMapItemRenderer().renderMap(mapdata, false);
		}
	}

	GlStateManager.enableLighting();
}
 
Example #3
Source File: ItemEmptyWirelessMap.java    From WirelessRedstone with MIT License 5 votes vote down vote up
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
{
    ItemStack itemstack1 = new ItemStack(WirelessRedstoneAddons.wirelessMap, 1, p_77659_2_.getUniqueDataId("map"));
    String s = "map_" + itemstack1.getItemDamage();
    MapData mapdata = new MapData(s);
    p_77659_2_.setItemData(s, mapdata);
    mapdata.scale = 0;
    int i = 128 * (1 << mapdata.scale);
    mapdata.xCenter = (int)(Math.round(p_77659_3_.posX / (double)i) * (long)i);
    mapdata.zCenter = (int)(Math.round(p_77659_3_.posZ / (double)i) * (long)i);
    mapdata.dimension = p_77659_2_.provider.dimensionId;
    mapdata.markDirty();
    --p_77659_1_.stackSize;

    if (p_77659_1_.stackSize <= 0)
    {
        return itemstack1;
    }
    else
    {
        if (!p_77659_3_.inventory.addItemStackToInventory(itemstack1.copy()))
        {
            p_77659_3_.dropPlayerItemWithRandomChoice(itemstack1, false);
        }

        return p_77659_1_;
    }
}
 
Example #4
Source File: WRAddonSPH.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void sendMapInfoTo(EntityPlayer player, int mapno, MapData mapdata) {
    PacketCustom packet = new PacketCustom(WirelessRedstoneCore.channel, 56);
    packet.writeShort((short) mapno);
    packet.writeInt(mapdata.xCenter);
    packet.writeInt(mapdata.zCenter);
    packet.writeByte(mapdata.scale);

    packet.sendToPlayer(player);
}
 
Example #5
Source File: RedstoneEtherServerAddons.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public void updateSMPMapInfo(World world, EntityPlayer player, MapData mapdata, int mapno) {
    AddonPlayerInfo info = getPlayerInfo(player);
    if (!info.mapInfoSet.contains(Integer.valueOf(mapno))) {
        WRAddonSPH.sendMapInfoTo(player, mapno, mapdata);
        info.mapInfoSet.add(mapno);
    }
}
 
Example #6
Source File: RedstoneEtherServerAddons.java    From WirelessRedstone with MIT License 5 votes vote down vote up
private void updatePlayerMapData(EntityPlayer player, World world, MapData mapdata, Map<BlockCoord, TXNodeInfo> txnodes, Set<WirelessTransmittingDevice> devices) {
    TreeSet<FreqCoord> mnodes = new TreeSet<FreqCoord>();
    TreeSet<FreqCoord> mdevices = new TreeSet<FreqCoord>();

    int blockwidth = 1 << mapdata.scale;
    int minx = mapdata.xCenter - blockwidth * 64;
    int minz = mapdata.zCenter - blockwidth * 64;
    int maxx = mapdata.xCenter + blockwidth * 64;
    int maxz = mapdata.zCenter + blockwidth * 64;

    for (Entry<BlockCoord, TXNodeInfo> entry : txnodes.entrySet()) {
        BlockCoord node = entry.getKey();
        TXNodeInfo info = entry.getValue();
        if (info.on && node.x > minx && node.x < maxx && node.z > minz && node.z < maxz && RedstoneEther.server().canBroadcastOnFrequency(player, info.freq)) {
            mnodes.add(new FreqCoord(node.x - mapdata.xCenter, node.y, node.z - mapdata.zCenter, info.freq));
        }
    }

    for (Iterator<WirelessTransmittingDevice> iterator = devices.iterator(); iterator.hasNext(); ) {
        WirelessTransmittingDevice device = iterator.next();
        Vector3 pos = device.getPosition();
        if (pos.x > minx && pos.x < maxx && pos.z > minz && pos.z < maxz && RedstoneEther.server().canBroadcastOnFrequency(player, device.getFreq())) {
            mdevices.add(new FreqCoord((int) pos.x, (int) pos.y, (int) pos.z, device.getFreq()));
        }
    }

    WirelessMapNodeStorage mapnodes = getMapNodes(player);

    mapnodes.nodes = mnodes;
    mapnodes.devices = mdevices;
}
 
Example #7
Source File: WirelessMapRenderer.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public void renderMap(EntityPlayer player, MapData mapData, boolean inFrame) {
    Minecraft.getMinecraft().entityRenderer.getMapItemRenderer().func_148250_a(mapData, inFrame);

    WirelessMapNodeStorage mapstorage = RedstoneEtherAddons.client().getMapNodes();
    Tessellator tessellator = Tessellator.instance;
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
    float light = 1;
    long worldTime = player.worldObj.getTotalWorldTime();

    ItemStack currentitem = player.inventory.getCurrentItem();
    if (currentitem == null || currentitem.getItem() != WirelessRedstoneAddons.wirelessMap)
        return;

    ClientMapInfo mapinfo = RedstoneEtherAddons.client().getMPMapInfo((short) currentitem.getItemDamage());
    if (mapinfo == null)
        return;

    int xCenter = mapinfo.xCenter;
    int zCenter = mapinfo.zCenter;
    int scale = mapinfo.scale;

    tessellator.startDrawingQuads();
    renderPass(xCenter, zCenter, scale, mapstorage, worldTime, 0.75F, 1F, light * 0.5F);
    renderPass(xCenter, zCenter, scale, mapstorage, worldTime, 0.6F, 1F, light);
    tessellator.draw();

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
 
Example #8
Source File: MapMod.java    From ForgeHax with MIT License 5 votes vote down vote up
private void updateHeldMapTexture(String url) {
  if (MC.player == null || !(MC.player.getHeldItemMainhand().getItem() instanceof ItemMap)) {
    return;
  }
  
  MC.addScheduledTask(
      () -> { // allows DynamicTexture to work
        ItemMap map = (ItemMap) MC.player.getHeldItemMainhand().getItem();
        MapData heldMapData = map.getMapData(MC.player.getHeldItemMainhand(), MC.world);
        
        try {
          BufferedImage image = getImageFromUrl(url);
          
          DynamicTexture dynamicTexture = new DynamicTexture(image);
          dynamicTexture.loadTexture(MC.getResourceManager());
          
          Map<ResourceLocation, ITextureObject> mapTextureObjects =
              FastReflection.Fields.TextureManager_mapTextureObjects.get(MC.getTextureManager());
          
          ResourceLocation textureLocation =
              mapTextureObjects
                  .keySet()
                  .stream()
                  .filter(k -> k.getResourcePath().contains(heldMapData.mapName))
                  .findFirst()
                  .orElse(null);
          
          mapTextureObjects.put(
              textureLocation, dynamicTexture); // overwrite old texture with our custom one
          
        } catch (Exception e) {
          e.printStackTrace();
        }
      });
}
 
Example #9
Source File: MapDownloader.java    From ForgeHax with MIT License 5 votes vote down vote up
@Override
public void onLoad() {
  getCommandStub()
      .builders()
      .newCommandBuilder()
      .name("Download")
      .description("Download the held map as an image")
      .processor(
          data -> {
            if (MC.player == null || !(MC.player.getHeldItemMainhand().getItem() instanceof ItemMap)) {
              Helper.printError("You're not holding a map.");
              return;
            }

            ItemMap map = (ItemMap) MC.player.getHeldItemMainhand().getItem();
            MapData mapData = map.getMapData(MC.player.getHeldItemMainhand(), MC.world);

            String fileName = data.getArgument(0);
            Integer scaledRes = null;
            try {
              if (data.getArgument(1) != null) {
                scaledRes = Integer.valueOf(data.getArgument(1));
              }
            } catch (NumberFormatException e) {
              Helper.printMessage("Failed to parse resolution");
            }

            downloadMap(mapData, fileName, scaledRes);
          })
      .build();
}
 
Example #10
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CraftMapView createMap(World world) {
    Validate.notNull(world, "World cannot be null");

    net.minecraft.item.ItemStack stack = new net.minecraft.item.ItemStack(Items.MAP, 1, -1);
    MapData worldmap = Items.FILLED_MAP.getMapData(stack, ((CraftWorld) world).getHandle());
    return worldmap.mapView;
}
 
Example #11
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Deprecated
public CraftMapView getMap(short id) {
    MapStorage collection = console.worlds[0].mapStorage;
    MapData worldmap = (MapData) collection.getOrLoadData(MapData.class, "map_" + id);
    if (worldmap == null) {
        return null;
    }
    return worldmap.mapView;
}
 
Example #12
Source File: CraftMapRenderer.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftMapRenderer(CraftMapView mapView, MapData worldMap) {
    super(false);
    this.worldMap = worldMap;
}
 
Example #13
Source File: RedstoneEtherClientAddons.java    From WirelessRedstone with MIT License 4 votes vote down vote up
public void updateSSPMap(World world, EntityPlayer player, MapData mapdata) {
    if (RedstoneEther.get(true).isPlayerJammed(player) || mapdata.dimension != player.dimension) {
        clearMapNodes(player);
        return;
    }
}
 
Example #14
Source File: MapMod.java    From ForgeHax with MIT License 4 votes vote down vote up
private void updateHeldMap(String url) {
  if (MC.player == null || !(MC.player.getHeldItemMainhand().getItem() instanceof ItemMap)) {
    return;
  }
  
  BufferedImage image = getImageFromUrl(url);
  if (image == null) {
    Helper.printMessage("Failed to download image");
    return;
  }
  
  image = createResizedCopy(image, 128, 128, false);
  int[][] imageColors = imageToArray(image); // convert image into a 2d array of rgba integers
  
  byte[] convertedMapColors =
      new byte
          [128
          * 128]; // create a 1d array 128^2 in length that will be used to hold the final map
  // data
  
  int count = 0;
  for (int x = 0; x < 128; x++) { // iterate vertically
    for (int y = 0; y < 128; y++) { // iterate through row of pixels
      imageColors[y][x] =
          closest_color_RGB(
              imageColors[y][
                  x]); // each color in the image data now a color in COLOR_LIST that is the
      // closest match
      convertedMapColors[count] =
          (byte) imageColors[y][x]; // convert the 2d array into a 1d array
      count++;
    } // normally would do [x][y] but that appears to cause a rotation problem that is fixed by
    // doing [j][i]
  }
  
  ItemMap map = (ItemMap) MC.player.getHeldItemMainhand().getItem();
  
  MapData heldMapData = map.getMapData(MC.player.getHeldItemMainhand(), MC.world);
  
  heldMapData.colors = convertedMapColors; // set the colors of the map to the colors of the image
}
 
Example #15
Source File: WirelessMapRenderer.java    From WirelessRedstone with MIT License 4 votes vote down vote up
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    renderMap((EntityPlayer) data[0], (MapData) data[2], false);
}
 
Example #16
Source File: RedstoneEtherServerAddons.java    From WirelessRedstone with MIT License 4 votes vote down vote up
public void processSMPMaps(World world) {
    RedstoneEther.loadServerWorld(world);
    int dimension = CommonUtils.getDimension(world);
    ArrayList<EntityPlayer> players = ServerUtils.getPlayersInDimension(dimension);

    Map<BlockCoord, TXNodeInfo> txnodes = RedstoneEther.server().getTransmittersInDimension(dimension);
    Set<WirelessTransmittingDevice> devices = RedstoneEther.server().getTransmittingDevicesInDimension(dimension);

    for (EntityPlayer player : players) {
        ItemStack helditem = player.getCurrentEquippedItem();

        if (helditem == null || helditem.getItem() != WirelessRedstoneAddons.wirelessMap || RedstoneEther.server().isPlayerJammed(player)) {
            continue;
        }

        ItemWirelessMap map = (ItemWirelessMap) helditem.getItem();
        MapData mapdata = map.getMapData(helditem, world);

        if (mapdata.dimension != player.dimension) {
            continue;
        }

        WirelessMapNodeStorage mapnodes = getMapNodes(player);
        TreeSet<FreqCoord> oldnodes = mapnodes.nodes;
        int lastdevices = mapnodes.devices.size();

        updatePlayerMapData(player, world, mapdata, txnodes, devices);

        TreeSet<FreqCoord> addednodes = new TreeSet<FreqCoord>(mapnodes.nodes);
        TreeSet<FreqCoord> removednodes = new TreeSet<FreqCoord>();

        if (oldnodes.size() != 0) {
            for (Iterator<FreqCoord> nodeiterator = oldnodes.iterator(); nodeiterator.hasNext(); ) {
                FreqCoord node = nodeiterator.next();
                if (!addednodes.remove(node))//remove returns false if the item was not in the set
                {
                    removednodes.add(node);
                }
            }
        }

        if (addednodes.size() != 0 || removednodes.size() != 0 || devices.size() != 0 || lastdevices > 0) {
            WRAddonSPH.sendMapUpdatePacketTo(player, helditem.getItemDamage(), mapdata, addednodes, removednodes, mapnodes.devices);
        }
    }
}
 
Example #17
Source File: CraftMapView.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftMapView(MapData worldMap) {
    this.worldMap = worldMap;
    addRenderer(new CraftMapRenderer(this, worldMap));
}