Skip to content

Commit

Permalink
1.21 Port XXX
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Aug 12, 2024
1 parent 762313e commit cbb758d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 61 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ dependencies {
runtimeOnly("mezz.jei:jei-${jei_minecraft_version}-neoforge:${jei_version}")

compileOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}+${curios_minecraft_version}:api")
runtimeOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}+${curios_minecraft_version}")
// Look into what to replace this with
//runtimeOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}+${curios_minecraft_version}")

if (cc_tweaked_enable.toBoolean()) {
compileOnly("cc.tweaked:cc-tweaked-${cc_tweaked_minecraft_version}-core-api:${cc_tweaked_version}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.ResourceLocationException;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
Expand All @@ -24,6 +25,11 @@

public class PotatoCannonProjectileType {

public static StreamCodec<FriendlyByteBuf, PotatoCannonProjectileType> STREAM_CODEC = StreamCodec.of(
PotatoCannonProjectileType::toBuffer,
PotatoCannonProjectileType::fromBuffer
);

private List<Supplier<Item>> items = new ArrayList<>();

private int reloadTicks = 10;
Expand Down Expand Up @@ -145,7 +151,7 @@ private static void parseJsonPrimitive(JsonObject object, String key, Predicate<
}
}

public static void toBuffer(PotatoCannonProjectileType type, FriendlyByteBuf buffer) {
public static void toBuffer(FriendlyByteBuf buffer, PotatoCannonProjectileType type) {
buffer.writeVarInt(type.items.size());
for (Supplier<Item> delegate : type.items) {
buffer.writeResourceLocation(RegisteredObjects.getKeyOrThrow(delegate.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -88,21 +89,10 @@ public static void toBuffer(FriendlyByteBuf buffer) {
buffer.writeVarInt(CUSTOM_TYPE_MAP.size());
for (Map.Entry<ResourceLocation, PotatoCannonProjectileType> entry : CUSTOM_TYPE_MAP.entrySet()) {
buffer.writeResourceLocation(entry.getKey());
PotatoCannonProjectileType.toBuffer(entry.getValue(), buffer);
PotatoCannonProjectileType.STREAM_CODEC.encode(buffer, entry.getValue());
}
}

public static void fromBuffer(FriendlyByteBuf buffer) {
clear();

int size = buffer.readVarInt();
for (int i = 0; i < size; i++) {
CUSTOM_TYPE_MAP.put(buffer.readResourceLocation(), PotatoCannonProjectileType.fromBuffer(buffer));
}

fillItemMap();
}

public static void syncTo(ServerPlayer player) {
PacketSender.sendToClient(player, new SyncPacket());
}
Expand Down Expand Up @@ -141,16 +131,18 @@ protected void apply(Map<ResourceLocation, JsonElement> map, ResourceManager res
}

public static class SyncPacket implements ClientboundPacketPayload {
public static final StreamCodec<FriendlyByteBuf, SyncPacket> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.map(HashMap::new, ResourceLocation.STREAM_CODEC, PotatoCannonProjectileType.STREAM_CODEC), (p) -> CUSTOM_TYPE_MAP,
SyncPacket::new
);

public static final StreamCodec<FriendlyByteBuf, SyncPacket> STREAM_CODEC = StreamCodec.of((b, v) -> v.write(b), SyncPacket::new);

private FriendlyByteBuf buffer;
Map<ResourceLocation, PotatoCannonProjectileType> map;

public SyncPacket() {
}

protected SyncPacket(FriendlyByteBuf buffer) {
this.buffer = buffer;
public SyncPacket(Map<ResourceLocation, PotatoCannonProjectileType> map) {
this.map = map;
}

protected void write(FriendlyByteBuf buffer) {
Expand All @@ -160,7 +152,11 @@ protected void write(FriendlyByteBuf buffer) {
@Override
@OnlyIn(Dist.CLIENT)
public void handle(LocalPlayer player, IPayloadContext ctx) {
fromBuffer(buffer);
clear();

CUSTOM_TYPE_MAP.putAll(map);

fillItemMap();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,12 +12,10 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.simibubi.create.content.trains.station.StationMarker;
import com.simibubi.create.foundation.map.StationMapDecoration;

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.MapId;
Expand All @@ -27,7 +26,7 @@
public class ClientboundMapItemDataPacketMixin {
@Shadow
@Final
private List<MapDecoration> decorations;
private Optional<List<MapDecoration>> decorations;

@Unique
private int[] create$stationIndices;
Expand All @@ -38,37 +37,38 @@ public class ClientboundMapItemDataPacketMixin {
}

@Unique
private static int[] create$getStationIndices(List<MapDecoration> decorations) {
if (decorations == null) {
private static int[] create$getStationIndices(Optional<List<MapDecoration>> decorations) {
if (decorations.isEmpty()) {
return new int[0];
}

IntList indices = new IntArrayList();
for (int i = 0; i < decorations.size(); i++) {
StationMapDecoration decoration = (StationMapDecoration) (Object) decorations.get(i);
for (int i = 0; i < decorations.get().size(); i++) {
StationMapDecoration decoration = (StationMapDecoration) (Object) decorations.get().get(i);
if (decoration != null && decoration.create$isStationMarker()) {
indices.add(i);
}
}
return indices.toIntArray();
}

@Inject(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
private void create$onInit(FriendlyByteBuf buf, CallbackInfo ci) {
create$stationIndices = buf.readVarIntArray();

if (decorations != null) {
for (int i : create$stationIndices) {
if (i >= 0 && i < decorations.size()) {
MapDecoration decoration = decorations.get(i);
decorations.set(i, StationMarker.createStationDecorationFrom(decoration));
}
}
}
}

@Inject(method = "write(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
private void create$onWrite(FriendlyByteBuf buf, CallbackInfo ci) {
buf.writeVarIntArray(create$stationIndices);
}
// FIXME 1.21: Rework this entirely
// @Inject(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
// private void create$onInit(FriendlyByteBuf buf, CallbackInfo ci) {
// create$stationIndices = buf.readVarIntArray();
//
// if (decorations != null) {
// for (int i : create$stationIndices) {
// if (i >= 0 && i < decorations.size()) {
// MapDecoration decoration = decorations.get(i);
// decorations.set(i, StationMarker.createStationDecorationFrom(decoration));
// }
// }
// }
// }
//
// @Inject(method = "write(Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN"))
// private void create$onWrite(FriendlyByteBuf buf, CallbackInfo ci) {
// buf.writeVarIntArray(create$stationIndices);
// }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.simibubi.create.foundation.mixin.client;

import java.util.Optional;

import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.simibubi.create.content.trains.station.StationMarker;
Expand All @@ -11,25 +18,15 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.saveddata.maps.MapDecoration;

import net.minecraft.world.level.saveddata.maps.MapItemSavedData;

import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

import org.joml.Matrix4f;
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 javax.annotation.Nullable;

@Mixin(MapDecoration.class)
public abstract class MapDecorationMixin implements StationMapDecoration {
@Shadow public abstract byte x();
@Shadow public abstract byte y();
@Shadow @Final @Nullable private Component name;
@Shadow public abstract Optional<Component> name();

@Unique private boolean create$isStationMarker = false;

Expand Down Expand Up @@ -65,9 +62,9 @@ public abstract class MapDecorationMixin implements StationMapDecoration {

poseStack.popPose();

if (name != null) {
if (name().isPresent()) {
Font font = Minecraft.getInstance().font;
Component component = name;
Component component = name().get();
float f6 = (float)font.width(component);
// float f7 = Mth.clamp(25.0F / f6, 0.0F, 6.0F / 9.0F);
poseStack.pushPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"uniforms": [
{ "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "IViewRotMat", "type": "matrix3x3", "count": 9, "values": [ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] },
{ "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] },
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ uniform sampler2D Sampler2;

uniform mat4 ModelViewMat;
uniform mat4 ProjMat;
uniform mat3 IViewRotMat;
uniform int FogShape;

out float vertexDistance;
Expand All @@ -27,7 +26,7 @@ out vec4 normal;
void main() {
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0);

vertexDistance = fog_distance(ModelViewMat, IViewRotMat * Position, FogShape);
vertexDistance = fog_distance(Position, FogShape);
vertexColor = Color;
lightMapColor = texelFetch(Sampler2, UV2 / 16, 0);
texCoord0 = UV0;
Expand Down

0 comments on commit cbb758d

Please sign in to comment.