mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-23 13:39:43 +00:00
Forge 1.19.3
Created a CreativeModeTabEvent to register creative mode tabs and populate entries per tab Moved datapack registries to DataPackRegistryEvent.NewRegistry event instead of tying them to ForgeRegistry Made it easier for mods to datagen datapack builtin entries with DatapackBuiltinEntriesProvider Provided access to lookupProvider for datagen Updated dependencies to match versions used by vanilla and update JarJar to 0.3.18 Added a test mod for the new CreativeModeTabEvent Throws better error message for Forge registries in tag datagen Deleted ForgeRegistryTagsProvider Updated ClientChatReceivedEvent and ServerChatEvent for Mojang changes Added patches for both sign related methods in ModelLayers Changed RegisterShadersEvent to use ResourceProvider Migrated old Mojang math types to JOML Co-authored-by: Marc Hermans <[email protected]> Co-authored-by: LexManos <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Co-authored-by: coehlrich <[email protected]>
This commit is contained in:
1 parent
617ecb7ad3
commit
8255d7aed3
726 files changed
+7615
-6653
No files matched your search
@@ -20,6 +20,12 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public class ConcatenatedListView<T> implements List<T>
|
||||
{
|
||||
@SafeVarargs
|
||||
public static <T> ConcatenatedListView<T> of(List<T>... lists)
|
||||
{
|
||||
return new ConcatenatedListView<>(List.of(lists));
|
||||
}
|
||||
|
||||
public static <T> List<T> of(List<? extends List<? extends T>> members)
|
||||
{
|
||||
return switch (members.size()) {
|
||||
|
||||
@@ -8,17 +8,21 @@ package net.minecraftforge.common.util;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.Set;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.PacketSendListener;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundAcceptTeleportationPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundBlockEntityTagQuery;
|
||||
import net.minecraft.network.protocol.game.ServerboundChangeDifficultyPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatAckPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundClientCommandPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundClientInformationPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket;
|
||||
@@ -66,7 +70,6 @@ import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -77,7 +80,7 @@ public class FakePlayer extends ServerPlayer
|
||||
{
|
||||
public FakePlayer(ServerLevel level, GameProfile name)
|
||||
{
|
||||
super(level.getServer(), level, name, null);
|
||||
super(level.getServer(), level, name);
|
||||
this.connection = new FakePlayerNetHandler(level.getServer(), this);
|
||||
}
|
||||
|
||||
@@ -150,5 +153,14 @@ public class FakePlayer extends ServerPlayer
|
||||
@Override public void handleCustomPayload(ServerboundCustomPayloadPacket packet) { }
|
||||
@Override public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { }
|
||||
@Override public void handleLockDifficulty(ServerboundLockDifficultyPacket packet) { }
|
||||
@Override public void dismount(double x, double y, double z, float yaw, float pitch) { }
|
||||
@Override public void teleport(double x, double y, double z, float yaw, float pitch, Set<ClientboundPlayerPositionPacket.RelativeArgument> relativeSet, boolean dismountVehicle) { }
|
||||
@Override public void ackBlockChangesUpTo(int sequence) { }
|
||||
@Override public void handleChatCommand(ServerboundChatCommandPacket packet) { }
|
||||
@Override public void handleChatAck(ServerboundChatAckPacket packet) { }
|
||||
@Override public void addPendingMessage(PlayerChatMessage message) { }
|
||||
@Override public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound boundChatType) { }
|
||||
@Override public void sendDisguisedChatMessage(Component content, ChatType.Bound boundChatType) { }
|
||||
@Override public void handleChatSessionUpdate(ServerboundChatSessionUpdatePacket packet) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenCustomHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStackLinkedSet;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemStackMap {
|
||||
|
||||
public static <V> Map<ItemStack, V> createTypeAndTagLinkedMap() {
|
||||
return new Object2ObjectLinkedOpenCustomHashMap<>(ItemStackLinkedSet.TYPE_AND_TAG);
|
||||
}
|
||||
|
||||
public static <V> Map<ItemStack, V> createTypeAndTagMap() {
|
||||
return new Object2ObjectOpenCustomHashMap<>(ItemStackLinkedSet.TYPE_AND_TAG);
|
||||
}
|
||||
}
|
||||
@@ -5,47 +5,58 @@
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.math.Axis;
|
||||
import com.mojang.math.Transformation;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
import com.mojang.math.Vector4f;
|
||||
import net.minecraftforge.client.model.generators.BlockModelBuilder.RootTransformBuilder.TransformOrigin;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Quaternionfc;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
public final class TransformationHelper
|
||||
{
|
||||
public static Quaternion quatFromXYZ(Vector3f xyz, boolean degrees)
|
||||
public static Quaternionf quatFromXYZ(Vector3f xyz, boolean degrees)
|
||||
{
|
||||
return new Quaternion(xyz.x(), xyz.y(), xyz.z(), degrees);
|
||||
return quatFromXYZ(xyz.x, xyz.y, xyz.z, degrees);
|
||||
}
|
||||
|
||||
public static Quaternion quatFromXYZ(float[] xyz, boolean degrees)
|
||||
public static Quaternionf quatFromXYZ(float[] xyz, boolean degrees)
|
||||
{
|
||||
return new Quaternion(xyz[0], xyz[1], xyz[2], degrees);
|
||||
return quatFromXYZ(xyz[0], xyz[1], xyz[2], degrees);
|
||||
}
|
||||
|
||||
public static Quaternion makeQuaternion(float[] values)
|
||||
public static Quaternionf quatFromXYZ(float x, float y, float z, boolean degrees)
|
||||
{
|
||||
return new Quaternion(values[0], values[1], values[2], values[3]);
|
||||
float conversionFactor = degrees ? (float) Math.PI / 180 : 1;
|
||||
return new Quaternionf().rotationXYZ(x * conversionFactor, y * conversionFactor, z * conversionFactor);
|
||||
}
|
||||
|
||||
public static Quaternionf makeQuaternion(float[] values)
|
||||
{
|
||||
return new Quaternionf(values[0], values[1], values[2], values[3]);
|
||||
}
|
||||
|
||||
public static Vector3f lerp(Vector3f from, Vector3f to, float progress)
|
||||
{
|
||||
Vector3f res = from.copy();
|
||||
Vector3f res = new Vector3f(from);
|
||||
res.lerp(to, progress);
|
||||
return res;
|
||||
}
|
||||
|
||||
private static final double THRESHOLD = 0.9995;
|
||||
public static Quaternion slerp(Quaternion v0, Quaternion v1, float t)
|
||||
public static Quaternionf slerp(Quaternionfc v0, Quaternionfc v1, float t)
|
||||
{
|
||||
// From https://en.wikipedia.org/w/index.php?title=Slerp&oldid=928959428
|
||||
// License: CC BY-SA 3.0 https://creativecommons.org/licenses/by-sa/3.0/
|
||||
@@ -55,20 +66,20 @@ public final class TransformationHelper
|
||||
// the shorter path. Note that v1 and -v1 are equivalent when
|
||||
// the negation is applied to all four components. Fix by
|
||||
// reversing one quaternion.
|
||||
float dot = v0.i() * v1.i() + v0.j() * v1.j() + v0.k() * v1.k() + v0.r() * v1.r();
|
||||
float dot = v0.x() * v1.x() + v0.y() * v1.y() + v0.z() * v1.z() + v0.w() * v1.w();
|
||||
if (dot < 0.0f) {
|
||||
v1 = new Quaternion(-v1.i(), -v1.j(), -v1.k(), -v1.r());
|
||||
v1 = new Quaternionf(-v1.x(), -v1.y(), -v1.z(), -v1.w());
|
||||
dot = -dot;
|
||||
}
|
||||
|
||||
// If the inputs are too close for comfort, linearly interpolate
|
||||
// and normalize the result.
|
||||
if (dot > THRESHOLD) {
|
||||
float x = Mth.lerp(t, v0.i(), v1.i());
|
||||
float y = Mth.lerp(t, v0.j(), v1.j());
|
||||
float z = Mth.lerp(t, v0.k(), v1.k());
|
||||
float w = Mth.lerp(t, v0.r(), v1.r());
|
||||
return new Quaternion(x,y,z,w);
|
||||
float x = Mth.lerp(t, v0.x(), v1.x());
|
||||
float y = Mth.lerp(t, v0.y(), v1.y());
|
||||
float z = Mth.lerp(t, v0.z(), v1.z());
|
||||
float w = Mth.lerp(t, v0.w(), v1.w());
|
||||
return new Quaternionf(x,y,z,w);
|
||||
}
|
||||
|
||||
// Since dot is in range [0, DOT_THRESHOLD], acos is safe
|
||||
@@ -81,11 +92,11 @@ public final class TransformationHelper
|
||||
float s1 = sin0t / sin01;
|
||||
float s0 = sin1t / sin01;
|
||||
|
||||
return new Quaternion(
|
||||
s0 * v0.i() + s1 * v1.i(),
|
||||
s0 * v0.j() + s1 * v1.j(),
|
||||
s0 * v0.k() + s1 * v1.k(),
|
||||
s0 * v0.r() + s1 * v1.r()
|
||||
return new Quaternionf(
|
||||
s0 * v0.x() + s1 * v1.x(),
|
||||
s0 * v0.y() + s1 * v1.y(),
|
||||
s0 * v0.z() + s1 * v1.z(),
|
||||
s0 * v0.w() + s1 * v1.w()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -143,9 +154,9 @@ public final class TransformationHelper
|
||||
return ret;
|
||||
}
|
||||
Vector3f translation = null;
|
||||
Quaternion leftRot = null;
|
||||
Quaternionf leftRot = null;
|
||||
Vector3f scale = null;
|
||||
Quaternion rightRot = null;
|
||||
Quaternionf rightRot = null;
|
||||
// TODO: Default origin is opposing corner, due to a mistake.
|
||||
// This should probably be replaced with center in future versions.
|
||||
Vector3f origin = TransformOrigin.OPPOSING_CORNER.getVector(); // TODO: Changing this to ORIGIN_CENTER breaks models, function content needs changing too -C
|
||||
@@ -206,7 +217,7 @@ public final class TransformationHelper
|
||||
// Use a different origin if needed.
|
||||
if (!TransformOrigin.CENTER.getVector().equals(origin))
|
||||
{
|
||||
Vector3f originFromCenter = origin.copy();
|
||||
Vector3f originFromCenter = new Vector3f(origin);
|
||||
originFromCenter.sub(TransformOrigin.CENTER.getVector());
|
||||
matrix = matrix.applyOrigin(originFromCenter);
|
||||
}
|
||||
@@ -244,25 +255,25 @@ public final class TransformationHelper
|
||||
if (!e.isJsonArray()) throw new JsonParseException("Matrix: expected an array, got: " + e);
|
||||
JsonArray m = e.getAsJsonArray();
|
||||
if (m.size() != 3) throw new JsonParseException("Matrix: expected an array of length 3, got: " + m.size());
|
||||
float[] values = new float[16];
|
||||
for (int i = 0; i < 3; i++)
|
||||
Matrix4f matrix = new Matrix4f().zero();
|
||||
for (int rowIdx = 0; rowIdx < 3; rowIdx++)
|
||||
{
|
||||
if (!m.get(i).isJsonArray()) throw new JsonParseException("Matrix row: expected an array, got: " + m.get(i));
|
||||
JsonArray r = m.get(i).getAsJsonArray();
|
||||
if (!m.get(rowIdx).isJsonArray()) throw new JsonParseException("Matrix row: expected an array, got: " + m.get(rowIdx));
|
||||
JsonArray r = m.get(rowIdx).getAsJsonArray();
|
||||
if (r.size() != 4) throw new JsonParseException("Matrix row: expected an array of length 4, got: " + r.size());
|
||||
for (int j = 0; j < 4; j++)
|
||||
for (int columnIdx = 0; columnIdx < 4; columnIdx++)
|
||||
{
|
||||
try
|
||||
{
|
||||
values[j*4+i] = r.get(j).getAsNumber().floatValue();
|
||||
matrix.set(columnIdx, rowIdx, r.get(columnIdx).getAsNumber().floatValue());
|
||||
}
|
||||
catch (ClassCastException ex)
|
||||
{
|
||||
throw new JsonParseException("Matrix element: expected number, got: " + r.get(j));
|
||||
throw new JsonParseException("Matrix element: expected number, got: " + r.get(columnIdx));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Matrix4f(values);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public static float[] parseFloatArray(JsonElement e, int length, String prefix)
|
||||
@@ -285,26 +296,26 @@ public final class TransformationHelper
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Quaternion parseAxisRotation(JsonElement e)
|
||||
public static Quaternionf parseAxisRotation(JsonElement e)
|
||||
{
|
||||
if (!e.isJsonObject()) throw new JsonParseException("Axis rotation: object expected, got: " + e);
|
||||
JsonObject obj = e.getAsJsonObject();
|
||||
if (obj.entrySet().size() != 1) throw new JsonParseException("Axis rotation: expected single axis object, got: " + e);
|
||||
Map.Entry<String, JsonElement> entry = obj.entrySet().iterator().next();
|
||||
Quaternion ret;
|
||||
Quaternionf ret;
|
||||
try
|
||||
{
|
||||
if (entry.getKey().equals("x"))
|
||||
{
|
||||
ret = Vector3f.XP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
|
||||
ret = Axis.XP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
|
||||
}
|
||||
else if (entry.getKey().equals("y"))
|
||||
{
|
||||
ret = Vector3f.YP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
|
||||
ret = Axis.YP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
|
||||
}
|
||||
else if (entry.getKey().equals("z"))
|
||||
{
|
||||
ret = Vector3f.ZP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
|
||||
ret = Axis.ZP.rotationDegrees(entry.getValue().getAsNumber().floatValue());
|
||||
}
|
||||
else throw new JsonParseException("Axis rotation: expected single axis key, got: " + entry.getKey());
|
||||
}
|
||||
@@ -315,13 +326,13 @@ public final class TransformationHelper
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Quaternion parseRotation(JsonElement e)
|
||||
public static Quaternionf parseRotation(JsonElement e)
|
||||
{
|
||||
if (e.isJsonArray())
|
||||
{
|
||||
if (e.getAsJsonArray().get(0).isJsonObject())
|
||||
{
|
||||
Quaternion ret = Quaternion.ONE.copy();
|
||||
Quaternionf ret = new Quaternionf();
|
||||
for (JsonElement a : e.getAsJsonArray())
|
||||
{
|
||||
ret.mul(parseAxisRotation(a));
|
||||
|
||||
Reference in new issue
Block a user