Refactor map station marker mixins

- Map update packet now sends station indices instead of guessing that
certain decorations are stations
- Do not use MapDecoration.Type.MANSION for stations to allow map
extending
- Create CustomRenderedMapDecoration
- Change how custom MapDecorations are rendered
- Fix some code in MapItemSavedDataMixin
This commit is contained in:
PepperCode1 2022-11-05 21:13:35 -07:00
parent 0c5ccf38ee
commit b77388a8e4
8 changed files with 253 additions and 175 deletions

View file

@ -9,6 +9,7 @@ import com.mojang.math.Matrix4f;
import com.simibubi.create.AllTileEntities; import com.simibubi.create.AllTileEntities;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.content.logistics.trains.management.edgePoint.TrackTargetingBehaviour; import com.simibubi.create.content.logistics.trains.management.edgePoint.TrackTargetingBehaviour;
import com.simibubi.create.foundation.map.CustomRenderedMapDecoration;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Components;
@ -25,15 +26,19 @@ import net.minecraft.world.level.saveddata.maps.MapDecoration;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData; import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
public class StationMarker { public class StationMarker {
// Not MANSION or MONUMENT to allow map extending
public static final MapDecoration.Type TYPE = MapDecoration.Type.RED_MARKER;
private final BlockPos source; private final BlockPos source;
private final BlockPos target; private final BlockPos target;
private final Component name; private final Component name;
private final String id;
public StationMarker(BlockPos source, BlockPos target, Component name) { public StationMarker(BlockPos source, BlockPos target, Component name) {
this.source = source; this.source = source;
this.target = target; this.target = target;
this.name = name; this.name = name;
id = "create:station-" + target.getX() + "," + target.getY() + "," + target.getZ();
} }
public static StationMarker load(CompoundTag tag) { public static StationMarker load(CompoundTag tag) {
@ -59,13 +64,29 @@ public class StationMarker {
public CompoundTag save() { public CompoundTag save() {
CompoundTag tag = new CompoundTag(); CompoundTag tag = new CompoundTag();
tag.put("source", NbtUtils.writeBlockPos(this.source)); tag.put("source", NbtUtils.writeBlockPos(source));
tag.put("target", NbtUtils.writeBlockPos(this.target)); tag.put("target", NbtUtils.writeBlockPos(target));
tag.putString("name", Component.Serializer.toJson(this.name)); tag.putString("name", Component.Serializer.toJson(name));
return tag; return tag;
} }
public BlockPos getSource() {
return source;
}
public BlockPos getTarget() {
return target;
}
public Component getName() {
return name;
}
public String getId() {
return id;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -79,33 +100,18 @@ public class StationMarker {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(this.target, this.name); return Objects.hash(target, name);
} }
public BlockPos getTarget() { public static class Decoration extends MapDecoration implements CustomRenderedMapDecoration {
return this.target; private static final RenderType RENDER_TYPE = RenderType.text(Create.asResource("textures/gui/station_map_icon.png"));
}
public BlockPos getSource() { public Decoration(byte x, byte y, Component name) {
return this.source; super(TYPE, x, y, (byte) 0, name);
} }
public Component getName() { public static Decoration from(MapDecoration decoration) {
return name; return new StationMarker.Decoration(decoration.getX(), decoration.getY(), decoration.getName());
}
public MapDecoration.Type getType() {
return MapDecoration.Type.MANSION;
}
public String getId() {
return "create:station-" + this.target.getX() + "," + this.target.getY() + "," + this.target.getZ();
}
public static class Decoration extends MapDecoration {
public Decoration(byte pX, byte pY, Component pName) {
super(Type.MANSION, pX, pY, (byte) 0, pName);
} }
@Override @Override
@ -114,52 +120,48 @@ public class StationMarker {
} }
@Override @Override
public boolean render(int index) { public void render(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, MapItemSavedData mapData, int index) {
return true; poseStack.pushPose();
}
public boolean render(PoseStack ms, MultiBufferSource bufferSource, int mapId, MapItemSavedData mapData, boolean active, int packedLight, int index) { poseStack.translate(getX() / 2D + 64.0, getY() / 2D + 64.0, -0.02D);
ms.pushPose();
ms.translate(getX() / 2D + 64.0, getY() / 2D + 64.0, -0.02D); poseStack.pushPose();
ms.pushPose(); poseStack.translate(0.5f, 0f, 0);
poseStack.scale(4.5F, 4.5F, 3.0F);
ms.translate(0.5f, 0f, 0);
ms.scale(4.5F, 4.5F, 3.0F);
VertexConsumer buffer = bufferSource.getBuffer(RenderType.text(Create.asResource("textures/gui/station_map_icon.png")));
VertexConsumer buffer = bufferSource.getBuffer(RENDER_TYPE);
Matrix4f mat = poseStack.last().pose();
float zOffset = -0.001f; float zOffset = -0.001f;
float alpha = 1f; buffer.vertex(mat, -1, -1, zOffset * index).color(255, 255, 255, 255).uv(0.0f , 0.0f ).uv2(packedLight).endVertex();
buffer.vertex(mat, -1, 1, zOffset * index).color(255, 255, 255, 255).uv(0.0f , 0.0f + 1.0f).uv2(packedLight).endVertex();
buffer.vertex(mat, 1, 1, zOffset * index).color(255, 255, 255, 255).uv(0.0f + 1.0f, 0.0f + 1.0f).uv2(packedLight).endVertex();
buffer.vertex(mat, 1, -1, zOffset * index).color(255, 255, 255, 255).uv(0.0f + 1.0f, 0.0f ).uv2(packedLight).endVertex();
Matrix4f mat = ms.last().pose(); poseStack.popPose();
buffer.vertex(mat, -1, -1, zOffset * index).color(1f, 1f, 1f, alpha).uv(0.0f , 0.0f ).uv2(packedLight).endVertex();
buffer.vertex(mat, -1, 1, zOffset * index).color(1f, 1f, 1f, alpha).uv(0.0f , 0.0f + 1.0f).uv2(packedLight).endVertex();
buffer.vertex(mat, 1, 1, zOffset * index).color(1f, 1f, 1f, alpha).uv(0.0f + 1.0f, 0.0f + 1.0f).uv2(packedLight).endVertex();
buffer.vertex(mat, 1, -1, zOffset * index).color(1f, 1f, 1f, alpha).uv(0.0f + 1.0f, 0.0f ).uv2(packedLight).endVertex();
ms.popPose();
if (getName() != null) { if (getName() != null) {
Font font = Minecraft.getInstance().font; Font font = Minecraft.getInstance().font;
Component component = getName(); Component component = getName();
float f6 = (float)font.width(component); float f6 = (float)font.width(component);
// float f7 = Mth.clamp(25.0F / f6, 0.0F, 6.0F / 9.0F); // float f7 = Mth.clamp(25.0F / f6, 0.0F, 6.0F / 9.0F);
ms.pushPose(); poseStack.pushPose();
//ms.translate((double)(0.0F + (float)getX() / 2.0F + 64.0F / 2.0F), (double)(0.0F + (float)getY() / 2.0F + 64.0F + 4.0F), (double)-0.025F); // poseStack.translate((double)(0.0F + (float)getX() / 2.0F + 64.0F / 2.0F), (double)(0.0F + (float)getY() / 2.0F + 64.0F + 4.0F), (double)-0.025F);
ms.translate(0, 6.0D, -0.005F); poseStack.translate(0, 6.0D, -0.005F);
ms.scale(0.8f, 0.8f, 1.0F); poseStack.scale(0.8f, 0.8f, 1.0F);
ms.translate(-f6 / 2f + .5f, 0, 0); poseStack.translate(-f6 / 2f + .5f, 0, 0);
//ms.scale(f7, f7, 1.0F); // poseStack.scale(f7, f7, 1.0F);
font.drawInBatch(component, 0.0F, 0.0F, -1, false, ms.last().pose(), bufferSource, false, Integer.MIN_VALUE, 15728880); font.drawInBatch(component, 0.0F, 0.0F, -1, false, poseStack.last().pose(), bufferSource, false, Integer.MIN_VALUE, 15728880);
ms.popPose(); poseStack.popPose();
} }
ms.popPose(); poseStack.popPose();
}
return false; @Override
public boolean render(int index) {
return true;
} }
} }
} }

View file

@ -0,0 +1,10 @@
package com.simibubi.create.foundation.map;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
public interface CustomRenderedMapDecoration {
void render(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, MapItemSavedData mapData, int index);
}

View file

@ -0,0 +1,73 @@
package com.simibubi.create.foundation.mixin;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.simibubi.create.content.logistics.trains.management.edgePoint.station.StationMarker;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.game.ClientboundMapItemDataPacket;
import net.minecraft.world.level.saveddata.maps.MapDecoration;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
// random priority to prevent networking conflicts
@Mixin(value = ClientboundMapItemDataPacket.class, priority = 826)
public class ClientboundMapItemDataPacketMixin {
@Shadow
@Final
private List<MapDecoration> decorations;
@Unique
private int[] stationIndices;
@Inject(method = "<init>(IBZLjava/util/Collection;Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData$MapPatch;)V", at = @At("RETURN"))
private void onInit(int mapId, byte scale, boolean locked, @Nullable Collection<MapDecoration> decorations, @Nullable MapItemSavedData.MapPatch colorPatch, CallbackInfo ci) {
stationIndices = getStationIndices(this.decorations);
}
private static int[] getStationIndices(List<MapDecoration> decorations) {
if (decorations == null) {
return new int[0];
}
IntList indices = new IntArrayList();
for (int i = 0; i < decorations.size(); i++) {
MapDecoration decoration = decorations.get(i);
if (decoration instanceof StationMarker.Decoration) {
indices.add(i);
}
}
return indices.toIntArray();
}
@Inject(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
private void onInit(FriendlyByteBuf buf, CallbackInfo ci) {
stationIndices = buf.readVarIntArray();
if (decorations != null) {
for (int i : stationIndices) {
if (i >= 0 && i < decorations.size()) {
MapDecoration decoration = decorations.get(i);
decorations.set(i, StationMarker.Decoration.from(decoration));
}
}
}
}
@Inject(method = "write(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
private void onWrite(FriendlyByteBuf buf, CallbackInfo ci) {
buf.writeVarIntArray(stationIndices);
}
}

View file

@ -1,11 +1,14 @@
package com.simibubi.create.foundation.mixin; package com.simibubi.create.foundation.mixin;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -19,6 +22,7 @@ import com.simibubi.create.content.logistics.trains.management.edgePoint.station
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.saveddata.maps.MapDecoration; import net.minecraft.world.level.saveddata.maps.MapDecoration;
@ -26,80 +30,101 @@ import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
@Mixin(MapItemSavedData.class) @Mixin(MapItemSavedData.class)
public class MapItemSavedDataMixin implements StationMapData { public class MapItemSavedDataMixin implements StationMapData {
@Unique
private static final String STATION_MARKERS_KEY = "create:stations";
@Final
@Shadow @Shadow
@Final
public int x; public int x;
@Final
@Shadow @Shadow
@Final
public int z; public int z;
@Final
@Shadow @Shadow
@Final
public byte scale; public byte scale;
@Final
@Shadow @Shadow
@Final
Map<String, MapDecoration> decorations; Map<String, MapDecoration> decorations;
private final Map<String, StationMarker> stationMarkers = Maps.newLinkedHashMap(); @Shadow
private int trackedDecorationCount;
@Inject( @Unique
method = "save(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/nbt/CompoundTag;", private final Map<String, StationMarker> stationMarkers = Maps.newHashMap();
at = @At("RETURN")
)
public void save(CompoundTag compound, CallbackInfoReturnable<CompoundTag> cir) {
ListTag listTag = new ListTag();
for (StationMarker stationMarker : this.stationMarkers.values()) {
listTag.add(stationMarker.save());
}
cir.getReturnValue().put("create:stations", listTag);
}
@Inject( @Inject(
method = "load(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;", method = "load(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;",
at = @At("RETURN") at = @At("RETURN")
) )
private static void load(CompoundTag compound, CallbackInfoReturnable<MapItemSavedData> cir) { private static void onLoad(CompoundTag compound, CallbackInfoReturnable<MapItemSavedData> cir) {
MapItemSavedData mapData = cir.getReturnValue(); MapItemSavedData mapData = cir.getReturnValue();
StationMapData stationMapData = (StationMapData) mapData; StationMapData stationMapData = (StationMapData) mapData;
ListTag listTag = compound.getList("create:stations", 10); ListTag listTag = compound.getList(STATION_MARKERS_KEY, Tag.TAG_COMPOUND);
for (int k = 0; k < listTag.size(); ++k) { for (int i = 0; i < listTag.size(); ++i) {
StationMarker stationMarker = StationMarker.load(listTag.getCompound(k)); StationMarker stationMarker = StationMarker.load(listTag.getCompound(i));
stationMapData.addStationMarker(stationMarker); stationMapData.addStationMarker(stationMarker);
} }
} }
@Inject(
method = "save(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/nbt/CompoundTag;",
at = @At("RETURN")
)
public void onSave(CompoundTag compound, CallbackInfoReturnable<CompoundTag> cir) {
ListTag listTag = new ListTag();
for (StationMarker stationMarker : stationMarkers.values()) {
listTag.add(stationMarker.save());
}
compound.put(STATION_MARKERS_KEY, listTag);
}
@Override @Override
public void addStationMarker(StationMarker marker) { public void addStationMarker(StationMarker marker) {
stationMarkers.put(marker.getId(), marker); stationMarkers.put(marker.getId(), marker);
int scaleMultiplier = 1 << this.scale; int scaleMultiplier = 1 << scale;
float localX = (marker.getTarget().getX() - x) / (float) scaleMultiplier;
float localZ = (marker.getTarget().getZ() - z) / (float) scaleMultiplier;
double localX = ((double) marker.getTarget().getX() - (double) this.x) / (double) scaleMultiplier; if (localX < -63.0F || localX > 63.0F || localZ < -63.0F || localZ > 63.0F) {
double localZ = ((double) marker.getTarget().getZ() - (double) this.z) / (double) scaleMultiplier; removeDecoration(marker.getId());
if (localX < -63.0D || localX > 63.0D || localZ < -63.0D || localZ > 63.0D)
return; return;
}
byte localXByte = (byte) (int) (localX * 2.0F + 0.5D); byte localXByte = (byte) (int) (localX * 2.0F + 0.5F);
byte localZByte = (byte) (int) (localZ * 2.0F + 0.5D); byte localZByte = (byte) (int) (localZ * 2.0F + 0.5F);
MapDecoration decoration = new StationMarker.Decoration(localXByte, localZByte, marker.getName()); MapDecoration decoration = new StationMarker.Decoration(localXByte, localZByte, marker.getName());
this.decorations.put(marker.getId(), decoration); MapDecoration oldDecoration = decorations.put(marker.getId(), decoration);
if (!decoration.equals(oldDecoration)) {
if (oldDecoration != null && oldDecoration.getType().shouldTrackCount()) {
--trackedDecorationCount;
}
if (decoration.getType().shouldTrackCount()) {
++trackedDecorationCount;
}
setDecorationsDirty();
}
} }
@Shadow @Shadow
private void removeDecoration(String pIdentifier) { private void removeDecoration(String identifier) {
throw new AssertionError(); throw new AssertionError();
} }
@Shadow @Shadow
public boolean isTrackedCountOverLimit(int pTrackedCount) { private void setDecorationsDirty() {
throw new AssertionError();
}
@Shadow
public boolean isTrackedCountOverLimit(int trackedCount) {
throw new AssertionError(); throw new AssertionError();
} }
@ -107,10 +132,10 @@ public class MapItemSavedDataMixin implements StationMapData {
public boolean toggleStation(LevelAccessor level, BlockPos pos, StationTileEntity stationTileEntity) { public boolean toggleStation(LevelAccessor level, BlockPos pos, StationTileEntity stationTileEntity) {
double xCenter = pos.getX() + 0.5D; double xCenter = pos.getX() + 0.5D;
double zCenter = pos.getZ() + 0.5D; double zCenter = pos.getZ() + 0.5D;
int scaleMultiplier = 1 << this.scale; int scaleMultiplier = 1 << scale;
double localX = (xCenter - (double) this.x) / (double) scaleMultiplier; double localX = (xCenter - (double) x) / (double) scaleMultiplier;
double localZ = (zCenter - (double) this.z) / (double) scaleMultiplier; double localZ = (zCenter - (double) z) / (double) scaleMultiplier;
if (localX < -63.0D || localX > 63.0D || localZ < -63.0D || localZ > 63.0D) if (localX < -63.0D || localX > 63.0D || localZ < -63.0D || localZ > 63.0D)
return false; return false;
@ -119,13 +144,14 @@ public class MapItemSavedDataMixin implements StationMapData {
if (marker == null) if (marker == null)
return false; return false;
if (this.stationMarkers.remove(marker.getId(), marker)) { if (stationMarkers.remove(marker.getId(), marker)) {
this.removeDecoration(marker.getId()); removeDecoration(marker.getId());
return true; return true;
} }
if (!this.isTrackedCountOverLimit(256)) { if (!isTrackedCountOverLimit(256)) {
addStationMarker(marker); addStationMarker(marker);
return true;
} }
return false; return false;
@ -135,26 +161,31 @@ public class MapItemSavedDataMixin implements StationMapData {
method = "checkBanners(Lnet/minecraft/world/level/BlockGetter;II)V", method = "checkBanners(Lnet/minecraft/world/level/BlockGetter;II)V",
at = @At("RETURN") at = @At("RETURN")
) )
public void checkBanners(BlockGetter pReader, int pX, int pZ, CallbackInfo ci) { public void checkBanners(BlockGetter blockGetter, int x, int z, CallbackInfo ci) {
checkStations(pReader, pX, pZ); checkStations(blockGetter, x, z);
} }
private void checkStations(BlockGetter pReader, int pX, int pZ) { private void checkStations(BlockGetter blockGetter, int x, int z) {
Iterator<StationMarker> iterator = this.stationMarkers.values().iterator(); Iterator<StationMarker> iterator = stationMarkers.values().iterator();
List<StationMarker> newMarkers = new ArrayList<>();
while (iterator.hasNext()) { while (iterator.hasNext()) {
StationMarker marker = iterator.next(); StationMarker marker = iterator.next();
if (marker.getTarget().getX() == pX && marker.getTarget().getZ() == pZ) { if (marker.getTarget().getX() == x && marker.getTarget().getZ() == z) {
StationMarker other = StationMarker.fromWorld(pReader, marker.getSource()); StationMarker other = StationMarker.fromWorld(blockGetter, marker.getSource());
if (!marker.equals(other)) { if (!marker.equals(other)) {
iterator.remove(); iterator.remove();
this.removeDecoration(marker.getId()); removeDecoration(marker.getId());
if (other != null && marker.getTarget().equals(other.getTarget())) { if (other != null && marker.getTarget().equals(other.getTarget())) {
addStationMarker(other); newMarkers.add(other);
} }
} }
} }
} }
for (StationMarker marker : newMarkers) {
addStationMarker(marker);
}
} }
} }

View file

@ -1,31 +0,0 @@
package com.simibubi.create.foundation.mixin;
import java.util.List;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.simibubi.create.content.logistics.trains.management.edgePoint.station.StationMarker;
import net.minecraft.world.level.saveddata.maps.MapDecoration;
import net.minecraft.world.level.saveddata.maps.MapDecoration.Type;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
@Mixin(MapItemSavedData.class)
public class MapItemSavedDataMixinClient {
@Inject(method = "addClientSideDecorations(Ljava/util/List;)V", at = @At("HEAD"))
private void addClientSideDecorations(List<MapDecoration> pDecorations, CallbackInfo ci) {
for (int i = 0; i < pDecorations.size(); i++) {
MapDecoration deco = pDecorations.get(i);
if (deco.getType() != Type.MANSION)
continue;
if (deco.getName() == null)
continue;
pDecorations.set(i, new StationMarker.Decoration(deco.getX(), deco.getY(), deco.getName()));
}
}
}

View file

@ -0,0 +1,32 @@
package com.simibubi.create.foundation.mixin;
import java.util.Iterator;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix4f;
import com.simibubi.create.foundation.map.CustomRenderedMapDecoration;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.level.saveddata.maps.MapDecoration;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
@Mixin(targets = "net.minecraft.client.gui.MapRenderer$MapInstance")
public class MapRendererMapInstanceMixin {
@Shadow
private MapItemSavedData data;
@Inject(method = "draw(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ZI)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/saveddata/maps/MapDecoration;render(I)Z", remap = false), locals = LocalCapture.CAPTURE_FAILHARD)
private void onDraw(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, CallbackInfo ci, int i, int j, float f, Matrix4f matrix4f, VertexConsumer vertexConsumer, int index, Iterator<MapDecoration> iterator, MapDecoration decoration) {
if (decoration instanceof CustomRenderedMapDecoration renderer) {
renderer.render(poseStack, bufferSource, active, packedLight, data, index);
}
}
}

View file

@ -1,40 +0,0 @@
package com.simibubi.create.foundation.mixin;
import java.util.Collection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.content.logistics.trains.management.edgePoint.station.StationMarker;
import net.minecraft.client.gui.MapRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.level.saveddata.maps.MapDecoration;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
@Mixin(MapRenderer.class)
public class MapRendererMixin {
@Inject(
method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/level/saveddata/maps/MapItemSavedData;ZI)V",
at = @At("TAIL")
)
public void render(PoseStack ms, MultiBufferSource buffer, int mapId, MapItemSavedData mapData, boolean active, int packedLight, CallbackInfo ci) {
Iterable<MapDecoration> decorations = mapData.getDecorations();
int index = 32;
if (decorations instanceof Collection) {
index = ((Collection<?>) decorations).size();
}
for (MapDecoration deco : decorations) {
if (!(deco instanceof StationMarker.Decoration stationDeco))
continue;
stationDeco.render(ms, buffer, mapId, mapData, active, packedLight, index++);
}
}
}

View file

@ -5,6 +5,8 @@
"compatibilityLevel": "JAVA_16", "compatibilityLevel": "JAVA_16",
"refmap": "create.refmap.json", "refmap": "create.refmap.json",
"mixins": [ "mixins": [
"ClientboundMapItemDataPacketMixin",
"ContraptionDriverInteractMixin",
"CustomItemUseEffectsMixin", "CustomItemUseEffectsMixin",
"MapItemSavedDataMixin", "MapItemSavedDataMixin",
"ContraptionDriverInteractMixin", "ContraptionDriverInteractMixin",
@ -15,14 +17,13 @@
"accessor.ServerLevelAccessor" "accessor.ServerLevelAccessor"
], ],
"client": [ "client": [
"MapItemSavedDataMixinClient",
"CameraMixin", "CameraMixin",
"DestroyProgressMixin", "DestroyProgressMixin",
"EntityContraptionInteractionMixin", "EntityContraptionInteractionMixin",
"FixNormalScalingMixin", "FixNormalScalingMixin",
"GameRendererMixin", "GameRendererMixin",
"HeavyBootsOnPlayerMixin", "HeavyBootsOnPlayerMixin",
"MapRendererMixin", "MapRendererMapInstanceMixin",
"ModelDataRefreshMixin", "ModelDataRefreshMixin",
"WindowResizeMixin", "WindowResizeMixin",
"accessor.AgeableListModelAccessor", "accessor.AgeableListModelAccessor",