Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix colony map #10171

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,14 @@
{
"item": "minecraft:fern"
},
{
"checkednbtkeys": [
"minecraft:map_color",
"minecraft:map_decorations",
"minecraft:map_id"
],
"item": "minecraft:filled_map"
},
{
"item": "minecraft:fire_charge"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import com.minecolonies.api.colony.buildings.views.IBuildingView;
import com.minecolonies.api.colony.colonyEvents.descriptions.IColonyEventDescription;
import com.minecolonies.api.colony.permissions.PermissionEvent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.level.saveddata.maps.MapId;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;

import java.util.List;

Expand All @@ -28,4 +33,20 @@ public interface ITownHallView extends IBuildingView
* @return true if so.
*/
boolean canPlayerUseTP();

/**
* Getter for the mapdata.
* @return the original list.
*/
List<MapEntry> getMapDataList();

public record MapEntry(MapId mapId, MapItemSavedData mapData)
{
public static final StreamCodec<RegistryFriendlyByteBuf, MapEntry> STREAM_CODEC =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a custom codec for vanilla maps? shouldnt we be able to use the vanilla codec for them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first is item dataComp and has both codecs, the second is level savedData which doesnt have any codec

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then I dont see why we dont simply sent the int and nbt via buffer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because in first comment you want to me to use vanilla codec? (for mapid)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just do:
buf.writeNbt(data.save(new CompoundTag(), buf.registryAccess()))

  • Use the mapId codec from vanilla?

I think that was what Sam meant

StreamCodec.composite(MapId.STREAM_CODEC,
MapEntry::mapId,
StreamCodec.of((buf, data) -> buf.writeNbt(data.save(new CompoundTag(), buf.registryAccess())), buf -> MapItemSavedData.load(buf.readNbt(), buf.registryAccess())),
MapEntry::mapData,
MapEntry::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import com.ldtteam.blockui.BOGuiGraphics;
import com.ldtteam.blockui.Pane;
import com.ldtteam.blockui.PaneParams;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.client.Minecraft;
import net.minecraft.world.level.saveddata.maps.MapId;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;

/**
* Simple minecraft map element.
*/
public class MinecraftMap extends Pane implements AutoCloseable
public class MinecraftMap extends Pane
{
private DynamicTexture texture;
private ResourceLocation textureResLoc;
public static final int MAP_SIZE = 128;
public static final int MAP_CENTER = 64;

private MapItemSavedData mapData;
private MapId mapId;

/**
* Default Constructor.
Expand All @@ -38,25 +40,10 @@ public MinecraftMap(final PaneParams params)
* Set the fitting map data.
* @param mapData the mapData to set.
*/
public void setMapData(final MapItemSavedData mapData)
public void setMapData(final MapId mapId, final MapItemSavedData mapData)
{
if (texture != null)
{
freeTexture();
}

texture = new DynamicTexture(128, 128, false);

for (int y = 0; y < 128; ++y)
{
for (int x = 0; x < 128; ++x)
{
texture.getPixels().setPixelRGBA(x, y, MapColor.getColorFromPackedId(mapData.colors[x + y * 128]));
}
}

texture.upload();
textureResLoc = mc.getTextureManager().register("minecolonies_map/" + id, texture);
this.mapId = mapId;
this.mapData = mapData;
}

/**
Expand All @@ -68,27 +55,17 @@ public void setMapData(final MapItemSavedData mapData)
@Override
public void drawSelf(final BOGuiGraphics ms, final double mx, final double my)
{
if (textureResLoc != null)
if (mapData != null)
{
blit(ms.pose(), textureResLoc, x, y, width, height);
}
}
ms.pose().pushPose();
ms.pose().translate(x, y, 0.01f);
ms.pose().scale(getWidth() / MAP_SIZE, getHeight() / MAP_SIZE, 1);

private void freeTexture()
{
if (textureResLoc != null)
{
texture.close();
mc.getTextureManager().release(textureResLoc);
// if fifth bool == false => enable all map decos
Minecraft.getInstance().gameRenderer.getMapRenderer().render(ms.pose(), ms.bufferSource(), mapId, mapData, true, 15728880);

texture = null;
textureResLoc = null;
ms.flush();
ms.pose().popPose();
}
}

@Override
public void close()
{
freeTexture();
}
}
Loading