mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 15:36:43 +01:00
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:
parent
8d68dff7a5
commit
ce03a91983
8 changed files with 252 additions and 175 deletions
|
@ -9,6 +9,7 @@ import com.mojang.math.Matrix4f;
|
|||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.Create;
|
||||
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.utility.Components;
|
||||
|
||||
|
@ -25,15 +26,19 @@ import net.minecraft.world.level.saveddata.maps.MapDecoration;
|
|||
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
||||
|
||||
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 target;
|
||||
private final Component name;
|
||||
private final String id;
|
||||
|
||||
public StationMarker(BlockPos source, BlockPos target, Component name) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.name = name;
|
||||
id = "create:station-" + target.getX() + "," + target.getY() + "," + target.getZ();
|
||||
}
|
||||
|
||||
public static StationMarker load(CompoundTag tag) {
|
||||
|
@ -59,13 +64,29 @@ public class StationMarker {
|
|||
|
||||
public CompoundTag save() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("source", NbtUtils.writeBlockPos(this.source));
|
||||
tag.put("target", NbtUtils.writeBlockPos(this.target));
|
||||
tag.putString("name", Component.Serializer.toJson(this.name));
|
||||
tag.put("source", NbtUtils.writeBlockPos(source));
|
||||
tag.put("target", NbtUtils.writeBlockPos(target));
|
||||
tag.putString("name", Component.Serializer.toJson(name));
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public BlockPos getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public BlockPos getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -79,33 +100,18 @@ public class StationMarker {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.target, this.name);
|
||||
return Objects.hash(target, name);
|
||||
}
|
||||
|
||||
public BlockPos getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
public static class Decoration extends MapDecoration implements CustomRenderedMapDecoration {
|
||||
private static final RenderType RENDER_TYPE = RenderType.text(Create.asResource("textures/gui/station_map_icon.png"));
|
||||
|
||||
public BlockPos getSource() {
|
||||
return this.source;
|
||||
}
|
||||
public Decoration(byte x, byte y, Component name) {
|
||||
super(TYPE, x, y, (byte) 0, name);
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
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);
|
||||
public static Decoration from(MapDecoration decoration) {
|
||||
return new StationMarker.Decoration(decoration.getX(), decoration.getY(), decoration.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,52 +120,48 @@ public class StationMarker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean render(int index) {
|
||||
return true;
|
||||
}
|
||||
public void render(PoseStack poseStack, MultiBufferSource bufferSource, boolean active, int packedLight, MapItemSavedData mapData, int index) {
|
||||
poseStack.pushPose();
|
||||
|
||||
public boolean render(PoseStack ms, MultiBufferSource bufferSource, int mapId, MapItemSavedData mapData, boolean active, int packedLight, int index) {
|
||||
ms.pushPose();
|
||||
poseStack.translate(getX() / 2D + 64.0, getY() / 2D + 64.0, -0.02D);
|
||||
|
||||
ms.translate(getX() / 2D + 64.0, getY() / 2D + 64.0, -0.02D);
|
||||
poseStack.pushPose();
|
||||
|
||||
ms.pushPose();
|
||||
|
||||
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")));
|
||||
poseStack.translate(0.5f, 0f, 0);
|
||||
poseStack.scale(4.5F, 4.5F, 3.0F);
|
||||
|
||||
VertexConsumer buffer = bufferSource.getBuffer(RENDER_TYPE);
|
||||
Matrix4f mat = poseStack.last().pose();
|
||||
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();
|
||||
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();
|
||||
poseStack.popPose();
|
||||
|
||||
if (getName() != null) {
|
||||
Font font = Minecraft.getInstance().font;
|
||||
Component component = getName();
|
||||
float f6 = (float)font.width(component);
|
||||
// float f7 = Mth.clamp(25.0F / f6, 0.0F, 6.0F / 9.0F);
|
||||
ms.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);
|
||||
ms.translate(0, 6.0D, -0.005F);
|
||||
poseStack.pushPose();
|
||||
// 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);
|
||||
poseStack.translate(0, 6.0D, -0.005F);
|
||||
|
||||
ms.scale(0.8f, 0.8f, 1.0F);
|
||||
ms.translate(-f6 / 2f + .5f, 0, 0);
|
||||
//ms.scale(f7, f7, 1.0F);
|
||||
font.drawInBatch(component, 0.0F, 0.0F, -1, false, ms.last().pose(), bufferSource, false, Integer.MIN_VALUE, 15728880);
|
||||
ms.popPose();
|
||||
poseStack.scale(0.8f, 0.8f, 1.0F);
|
||||
poseStack.translate(-f6 / 2f + .5f, 0, 0);
|
||||
// poseStack.scale(f7, f7, 1.0F);
|
||||
font.drawInBatch(component, 0.0F, 0.0F, -1, false, poseStack.last().pose(), bufferSource, false, Integer.MIN_VALUE, 15728880);
|
||||
poseStack.popPose();
|
||||
}
|
||||
|
||||
ms.popPose();
|
||||
poseStack.popPose();
|
||||
}
|
||||
|
||||
return false;
|
||||
@Override
|
||||
public boolean render(int index) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,14 @@
|
|||
package com.simibubi.create.foundation.mixin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
|
@ -19,6 +22,7 @@ import com.simibubi.create.content.logistics.trains.management.edgePoint.station
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.saveddata.maps.MapDecoration;
|
||||
|
@ -26,80 +30,101 @@ import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
|||
|
||||
@Mixin(MapItemSavedData.class)
|
||||
public class MapItemSavedDataMixin implements StationMapData {
|
||||
@Unique
|
||||
private static final String STATION_MARKERS_KEY = "create:stations";
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
@Final
|
||||
public int x;
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
@Final
|
||||
public int z;
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
@Final
|
||||
public byte scale;
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
@Final
|
||||
Map<String, MapDecoration> decorations;
|
||||
|
||||
private final Map<String, StationMarker> stationMarkers = Maps.newLinkedHashMap();
|
||||
@Shadow
|
||||
private int trackedDecorationCount;
|
||||
|
||||
@Inject(
|
||||
method = "save(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/nbt/CompoundTag;",
|
||||
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);
|
||||
}
|
||||
@Unique
|
||||
private final Map<String, StationMarker> stationMarkers = Maps.newHashMap();
|
||||
|
||||
@Inject(
|
||||
method = "load(Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;",
|
||||
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();
|
||||
StationMapData stationMapData = (StationMapData) mapData;
|
||||
|
||||
ListTag listTag = compound.getList("create:stations", 10);
|
||||
for (int k = 0; k < listTag.size(); ++k) {
|
||||
StationMarker stationMarker = StationMarker.load(listTag.getCompound(k));
|
||||
ListTag listTag = compound.getList(STATION_MARKERS_KEY, Tag.TAG_COMPOUND);
|
||||
for (int i = 0; i < listTag.size(); ++i) {
|
||||
StationMarker stationMarker = StationMarker.load(listTag.getCompound(i));
|
||||
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
|
||||
public void addStationMarker(StationMarker 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;
|
||||
double localZ = ((double) marker.getTarget().getZ() - (double) this.z) / (double) scaleMultiplier;
|
||||
|
||||
if (localX < -63.0D || localX > 63.0D || localZ < -63.0D || localZ > 63.0D)
|
||||
if (localX < -63.0F || localX > 63.0F || localZ < -63.0F || localZ > 63.0F) {
|
||||
removeDecoration(marker.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
byte localXByte = (byte) (int) (localX * 2.0F + 0.5D);
|
||||
byte localZByte = (byte) (int) (localZ * 2.0F + 0.5D);
|
||||
byte localXByte = (byte) (int) (localX * 2.0F + 0.5F);
|
||||
byte localZByte = (byte) (int) (localZ * 2.0F + 0.5F);
|
||||
|
||||
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
|
||||
private void removeDecoration(String pIdentifier) {
|
||||
private void removeDecoration(String identifier) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Shadow
|
||||
public boolean isTrackedCountOverLimit(int pTrackedCount) {
|
||||
private void setDecorationsDirty() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Shadow
|
||||
public boolean isTrackedCountOverLimit(int trackedCount) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
@ -107,10 +132,10 @@ public class MapItemSavedDataMixin implements StationMapData {
|
|||
public boolean toggleStation(LevelAccessor level, BlockPos pos, StationTileEntity stationTileEntity) {
|
||||
double xCenter = pos.getX() + 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 localZ = (zCenter - (double) this.z) / (double) scaleMultiplier;
|
||||
double localX = (xCenter - (double) x) / (double) scaleMultiplier;
|
||||
double localZ = (zCenter - (double) z) / (double) scaleMultiplier;
|
||||
|
||||
if (localX < -63.0D || localX > 63.0D || localZ < -63.0D || localZ > 63.0D)
|
||||
return false;
|
||||
|
@ -119,13 +144,14 @@ public class MapItemSavedDataMixin implements StationMapData {
|
|||
if (marker == null)
|
||||
return false;
|
||||
|
||||
if (this.stationMarkers.remove(marker.getId(), marker)) {
|
||||
this.removeDecoration(marker.getId());
|
||||
if (stationMarkers.remove(marker.getId(), marker)) {
|
||||
removeDecoration(marker.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this.isTrackedCountOverLimit(256)) {
|
||||
if (!isTrackedCountOverLimit(256)) {
|
||||
addStationMarker(marker);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -135,26 +161,31 @@ public class MapItemSavedDataMixin implements StationMapData {
|
|||
method = "checkBanners(Lnet/minecraft/world/level/BlockGetter;II)V",
|
||||
at = @At("RETURN")
|
||||
)
|
||||
public void checkBanners(BlockGetter pReader, int pX, int pZ, CallbackInfo ci) {
|
||||
checkStations(pReader, pX, pZ);
|
||||
public void checkBanners(BlockGetter blockGetter, int x, int z, CallbackInfo ci) {
|
||||
checkStations(blockGetter, x, z);
|
||||
}
|
||||
|
||||
private void checkStations(BlockGetter pReader, int pX, int pZ) {
|
||||
Iterator<StationMarker> iterator = this.stationMarkers.values().iterator();
|
||||
private void checkStations(BlockGetter blockGetter, int x, int z) {
|
||||
Iterator<StationMarker> iterator = stationMarkers.values().iterator();
|
||||
List<StationMarker> newMarkers = new ArrayList<>();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
StationMarker marker = iterator.next();
|
||||
if (marker.getTarget().getX() == pX && marker.getTarget().getZ() == pZ) {
|
||||
StationMarker other = StationMarker.fromWorld(pReader, marker.getSource());
|
||||
if (marker.getTarget().getX() == x && marker.getTarget().getZ() == z) {
|
||||
StationMarker other = StationMarker.fromWorld(blockGetter, marker.getSource());
|
||||
if (!marker.equals(other)) {
|
||||
iterator.remove();
|
||||
this.removeDecoration(marker.getId());
|
||||
removeDecoration(marker.getId());
|
||||
|
||||
if (other != null && marker.getTarget().equals(other.getTarget())) {
|
||||
addStationMarker(other);
|
||||
newMarkers.add(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (StationMarker marker : newMarkers) {
|
||||
addStationMarker(marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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++);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
"compatibilityLevel": "JAVA_16",
|
||||
"refmap": "create.refmap.json",
|
||||
"mixins": [
|
||||
"ClientboundMapItemDataPacketMixin",
|
||||
"ContraptionDriverInteractMixin",
|
||||
"CustomItemUseEffectsMixin",
|
||||
"EnchantmentHelperMixin",
|
||||
|
@ -25,8 +26,7 @@
|
|||
"GameRendererMixin",
|
||||
"HeavyBootsOnPlayerMixin",
|
||||
"HumanoidArmorLayerMixin",
|
||||
"MapItemSavedDataMixinClient",
|
||||
"MapRendererMixin",
|
||||
"MapRendererMapInstanceMixin",
|
||||
"ModelDataRefreshMixin",
|
||||
"WindowResizeMixin",
|
||||
"accessor.AgeableListModelAccessor",
|
||||
|
|
Loading…
Reference in a new issue