Compare commits

...

No commits in common. "master" and "2989347cc44a6453463d5e2573a7099fd835322b" have entirely different histories.

3584 changed files with 497866 additions and 125 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "enigma"]
path = enigma
url = https://github.com/DankParrot/Enigma.git

View File

@ -1,2 +0,0 @@
cd enigma
gradlew shadowJar

View File

@ -1 +0,0 @@
rm -rf src client.mappings client.jar client.txt

73229
client.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
# USAGE: bash create-branch.sh <version> <branch_flags>
gitcmd="git"
if uname -r | grep Microsoft > /dev/null; then
echo WSL Detected: Using git.exe
gitcmd="git.exe"
fi
# new branch
echo "Creating branch '$1'"
$gitcmd branch -D $1 || true
$gitcmd checkout $2 $1
$gitcmd reset
echo "Committing changes..."
$gitcmd add src
$gitcmd add client.txt
$gitcmd commit -m "Update to $1"
echo "Pushing to origin..."
$gitcmd push --force origin $1

View File

@ -1,12 +0,0 @@
#!/bin/bash
branch_flags=--orphan
cat versions.txt | while read line
do
./clean.sh
./setup-mappings.sh $line
./decompile-mc.sh
./create-branch.sh $line $branch_flags
branch_flags=-b
done

View File

@ -1,10 +0,0 @@
#!/usr/bin/env bash
# clear out current src directory
rm -rf src
mkdir src
echo "Decompiling client.jar..."
#procyon, cfr
./enigma.sh decompile cfr client.jar src client.mappings

1
enigma

@ -1 +0,0 @@
Subproject commit a36b2fca5f7293a17bb8fff87791fb7c6947400e

Binary file not shown.

View File

@ -1,31 +0,0 @@
# TODO: at what version does this start giving snowmans.
# TODO: does cfr decompiler also give snowmans
# TODO: -Xss100M -Xms11G -Xmx11G
java -jar enigma/enigma-cli/build/libs/enigma-cli-0.21+local-all.jar $@
# this one "works"
#java -cp enigma-0.14.3.146-all.jar cuchaz.enigma.CommandMain $@
#java -Xmx4G -cp enigma-0.14.3.149-all.jar cuchaz.enigma.CommandMain $@
# fails for no reason
#java -cp enigma-0.15.150-all.jar cuchaz.enigma.CommandMain $@
#java -cp enigma-0.15.1+build.164-all.jar cuchaz.enigma.CommandMain $@
# crashes with error 'null'
#java -cp enigma-0.15.153-all.jar cuchaz.enigma.CommandMain $@
#java -cp enigma-0.15.3+build.170-all.jar cuchaz.enigma.CommandMain $@
#java -cp enigma-0.16.1+build.177-all.jar cuchaz.enigma.CommandMain $@
#java -jar enigma-cli-0.19+build.194-all.jar $@
#java -jar enigma-cli-0.19+build.195-all.jar $@
# crashes with StackOverflowError
#java -jar enigma-cli-0.19+build.196-all.jar $@
#java -jar enigma-cli-0.19+build.198-all.jar $@
#java -jar enigma-cli-0.20+build.200-all.jar $@
# crashes with ArrayIndexOutOfBoundsException
#java -jar enigma-cli-0.20+build.204-all.jar $@
#java -jar enigma-cli-0.20+build.205-all.jar $@
#java -jar enigma-cli-0.20+build.206-all.jar $@

View File

@ -1,36 +0,0 @@
#!/usr/bin/env bash
# USAGE: bash setup-mappings.sh <version>
mc_version_manifest='https://launchermeta.mojang.com/mc/game/version_manifest.json'
# check dependencies. this script requires jq
if [ $(dpkg-query -W -f='${Status}' jq 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo "'jq' is not installed, run 'sudo apt-get install jq' to use this script"
exit
fi
# find our version.json file
echo 'Reading version_manifest.json...'
json_file=$(curl -s $mc_version_manifest | jq -r --arg version $1 '.versions[] | select(.id == $version).url')
# find jar and mappings url
echo "Reading $1.json..."
json_file_contents=$(curl -s $json_file)
client_jar=$(echo $json_file_contents | jq -r '.downloads.client.url')
client_mappings=$(echo $json_file_contents | jq -r '.downloads.client_mappings.url')
# download client.jar
echo "Downloading client.jar..."
curl -# -o client.jar $client_jar
# download client.txt
echo "Downloading ProGuard mappings: client.txt..."
curl -# -o client.txt $client_mappings
# delete old mappings
rm -rf client.mappings
echo "Converting ProGuard mappings to Engima mappings: client.mappings..."
./enigma.sh convert-mappings proguard client.txt enigma client.mappings

View File

@ -0,0 +1,14 @@
package com.mojang.blaze3d;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.system.MemoryUtil;
public class Blaze3D {
public static void youJustLostTheGame() {
MemoryUtil.memSet(0L, 0, 1L);
}
public static double getTime() {
return GLFW.glfwGetTime();
}
}

View File

@ -0,0 +1,175 @@
package com.mojang.blaze3d.audio;
import org.apache.logging.log4j.LogManager;
import java.nio.ByteBuffer;
import javax.sound.sampled.AudioFormat;
import net.minecraft.world.phys.Vec3;
import java.io.IOException;
import org.lwjgl.openal.AL10;
import javax.annotation.Nullable;
import net.minecraft.client.sounds.AudioStream;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.logging.log4j.Logger;
public class Channel {
private static final Logger LOGGER;
private final int source;
private final AtomicBoolean initialized;
private int streamingBufferSize;
@Nullable
private AudioStream stream;
@Nullable
static Channel create() {
final int[] arr1 = { 0 };
AL10.alGenSources(arr1);
if (OpenAlUtil.checkALError("Allocate new source")) {
return null;
}
return new Channel(arr1[0]);
}
private Channel(final int integer) {
this.initialized = new AtomicBoolean(true);
this.streamingBufferSize = 16384;
this.source = integer;
}
public void destroy() {
if (this.initialized.compareAndSet(true, false)) {
AL10.alSourceStop(this.source);
OpenAlUtil.checkALError("Stop");
if (this.stream != null) {
try {
this.stream.close();
}
catch (IOException iOException2) {
Channel.LOGGER.error("Failed to close audio stream", (Throwable)iOException2);
}
this.removeProcessedBuffers();
this.stream = null;
}
AL10.alDeleteSources(new int[] { this.source });
OpenAlUtil.checkALError("Cleanup");
}
}
public void play() {
AL10.alSourcePlay(this.source);
}
private int getState() {
if (!this.initialized.get()) {
return 4116;
}
return AL10.alGetSourcei(this.source, 4112);
}
public void pause() {
if (this.getState() == 4114) {
AL10.alSourcePause(this.source);
}
}
public void unpause() {
if (this.getState() == 4115) {
AL10.alSourcePlay(this.source);
}
}
public void stop() {
if (this.initialized.get()) {
AL10.alSourceStop(this.source);
OpenAlUtil.checkALError("Stop");
}
}
public boolean stopped() {
return this.getState() == 4116;
}
public void setSelfPosition(final Vec3 dem) {
AL10.alSourcefv(this.source, 4100, new float[] { (float)dem.x, (float)dem.y, (float)dem.z });
}
public void setPitch(final float float1) {
AL10.alSourcef(this.source, 4099, float1);
}
public void setLooping(final boolean boolean1) {
AL10.alSourcei(this.source, 4103, (int)(boolean1 ? 1 : 0));
}
public void setVolume(final float float1) {
AL10.alSourcef(this.source, 4106, float1);
}
public void disableAttenuation() {
AL10.alSourcei(this.source, 53248, 0);
}
public void linearAttenuation(final float float1) {
AL10.alSourcei(this.source, 53248, 53251);
AL10.alSourcef(this.source, 4131, float1);
AL10.alSourcef(this.source, 4129, 1.0f);
AL10.alSourcef(this.source, 4128, 0.0f);
}
public void setRelative(final boolean boolean1) {
AL10.alSourcei(this.source, 514, (int)(boolean1 ? 1 : 0));
}
public void attachStaticBuffer(final SoundBuffer dfy) {
dfy.getAlBuffer().ifPresent(integer -> AL10.alSourcei(this.source, 4105, integer));
}
public void attachBufferStream(final AudioStream epf) {
this.stream = epf;
final AudioFormat audioFormat3 = epf.getFormat();
this.streamingBufferSize = calculateBufferSize(audioFormat3, 1);
this.pumpBuffers(4);
}
private static int calculateBufferSize(final AudioFormat audioFormat, final int integer) {
return (int)(integer * audioFormat.getSampleSizeInBits() / 8.0f * audioFormat.getChannels() * audioFormat.getSampleRate());
}
private void pumpBuffers(final int integer) {
if (this.stream != null) {
try {
for (int integer2 = 0; integer2 < integer; ++integer2) {
final ByteBuffer byteBuffer4 = this.stream.read(this.streamingBufferSize);
if (byteBuffer4 != null) {
new SoundBuffer(byteBuffer4, this.stream.getFormat()).releaseAlBuffer().ifPresent(integer -> AL10.alSourceQueueBuffers(this.source, new int[] { integer }));
}
}
}
catch (IOException iOException3) {
Channel.LOGGER.error("Failed to read from audio stream", (Throwable)iOException3);
}
}
}
public void updateStream() {
if (this.stream != null) {
final int integer2 = this.removeProcessedBuffers();
this.pumpBuffers(integer2);
}
}
private int removeProcessedBuffers() {
final int integer2 = AL10.alGetSourcei(this.source, 4118);
if (integer2 > 0) {
final int[] arr3 = new int[integer2];
AL10.alSourceUnqueueBuffers(this.source, arr3);
OpenAlUtil.checkALError("Unqueue buffers");
AL10.alDeleteBuffers(arr3);
OpenAlUtil.checkALError("Remove processed buffers");
}
return integer2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,222 @@
package com.mojang.blaze3d.audio;
import com.google.common.collect.Sets;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import javax.annotation.Nullable;
import java.nio.ByteBuffer;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.openal.ALCapabilities;
import org.lwjgl.openal.ALCCapabilities;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.AL;
import net.minecraft.util.Mth;
import org.lwjgl.openal.ALC10;
import java.nio.IntBuffer;
import org.lwjgl.openal.ALC;
import org.apache.logging.log4j.Logger;
public class Library {
private static final Logger LOGGER;
private long device;
private long context;
private static final ChannelPool EMPTY;
private ChannelPool staticChannels;
private ChannelPool streamingChannels;
private final Listener listener;
public Library() {
this.staticChannels = Library.EMPTY;
this.streamingChannels = Library.EMPTY;
this.listener = new Listener();
}
public void init() {
this.device = tryOpenDevice();
final ALCCapabilities aLCCapabilities2 = ALC.createCapabilities(this.device);
if (OpenAlUtil.checkALCError(this.device, "Get capabilities")) {
throw new IllegalStateException("Failed to get OpenAL capabilities");
}
if (!aLCCapabilities2.OpenALC11) {
throw new IllegalStateException("OpenAL 1.1 not supported");
}
ALC10.alcMakeContextCurrent(this.context = ALC10.alcCreateContext(this.device, (IntBuffer)null));
final int integer3 = this.getChannelCount();
final int integer4 = Mth.clamp((int)Mth.sqrt((float)integer3), 2, 8);
final int integer5 = Mth.clamp(integer3 - integer4, 8, 255);
this.staticChannels = new CountingChannelPool(integer5);
this.streamingChannels = new CountingChannelPool(integer4);
final ALCapabilities aLCapabilities6 = AL.createCapabilities(aLCCapabilities2);
OpenAlUtil.checkALError("Initialization");
if (!aLCapabilities6.AL_EXT_source_distance_model) {
throw new IllegalStateException("AL_EXT_source_distance_model is not supported");
}
AL10.alEnable(512);
if (!aLCapabilities6.AL_EXT_LINEAR_DISTANCE) {
throw new IllegalStateException("AL_EXT_LINEAR_DISTANCE is not supported");
}
OpenAlUtil.checkALError("Enable per-source distance models");
Library.LOGGER.info("OpenAL initialized.");
}
private int getChannelCount() {
try (final MemoryStack memoryStack2 = MemoryStack.stackPush()) {
final int integer4 = ALC10.alcGetInteger(this.device, 4098);
if (OpenAlUtil.checkALCError(this.device, "Get attributes size")) {
throw new IllegalStateException("Failed to get OpenAL attributes");
}
final IntBuffer intBuffer5 = memoryStack2.mallocInt(integer4);
ALC10.alcGetIntegerv(this.device, 4099, intBuffer5);
if (OpenAlUtil.checkALCError(this.device, "Get attributes")) {
throw new IllegalStateException("Failed to get OpenAL attributes");
}
int integer5 = 0;
while (integer5 < integer4) {
final int integer6 = intBuffer5.get(integer5++);
if (integer6 == 0) {
break;
}
final int integer7 = intBuffer5.get(integer5++);
if (integer6 == 4112) {
return integer7;
}
}
}
return 30;
}
private static long tryOpenDevice() {
for (int integer1 = 0; integer1 < 3; ++integer1) {
final long long2 = ALC10.alcOpenDevice((ByteBuffer)null);
if (long2 != 0L && !OpenAlUtil.checkALCError(long2, "Open device")) {
return long2;
}
}
throw new IllegalStateException("Failed to open OpenAL device");
}
public void cleanup() {
this.staticChannels.cleanup();
this.streamingChannels.cleanup();
ALC10.alcDestroyContext(this.context);
if (this.device != 0L) {
ALC10.alcCloseDevice(this.device);
}
}
public Listener getListener() {
return this.listener;
}
@Nullable
public Channel acquireChannel(final Pool c) {
return ((c == Pool.STREAMING) ? this.streamingChannels : this.staticChannels).acquire();
}
public void releaseChannel(final Channel dft) {
if (!this.staticChannels.release(dft) && !this.streamingChannels.release(dft)) {
throw new IllegalStateException("Tried to release unknown channel");
}
}
public String getDebugString() {
return String.format("Sounds: %d/%d + %d/%d", this.staticChannels.getUsedCount(), this.staticChannels.getMaxCount(), this.streamingChannels.getUsedCount(), this.streamingChannels.getMaxCount());
}
static {
LOGGER = LogManager.getLogger();
EMPTY = new ChannelPool() {
@Nullable
@Override
public Channel acquire() {
return null;
}
@Override
public boolean release(final Channel dft) {
return false;
}
@Override
public void cleanup() {
}
@Override
public int getMaxCount() {
return 0;
}
@Override
public int getUsedCount() {
return 0;
}
};
}
public enum Pool {
STATIC,
STREAMING;
}
static class CountingChannelPool implements ChannelPool {
private final int limit;
private final Set<Channel> activeChannels;
public CountingChannelPool(final int integer) {
this.activeChannels = Sets.<Channel>newIdentityHashSet();
this.limit = integer;
}
@Nullable
@Override
public Channel acquire() {
if (this.activeChannels.size() >= this.limit) {
Library.LOGGER.warn("Maximum sound pool size {} reached", this.limit);
return null;
}
final Channel dft2 = Channel.create();
if (dft2 != null) {
this.activeChannels.add(dft2);
}
return dft2;
}
@Override
public boolean release(final Channel dft) {
if (!this.activeChannels.remove(dft)) {
return false;
}
dft.destroy();
return true;
}
@Override
public void cleanup() {
this.activeChannels.forEach(Channel::destroy);
this.activeChannels.clear();
}
@Override
public int getMaxCount() {
return this.limit;
}
@Override
public int getUsedCount() {
return this.activeChannels.size();
}
}
interface ChannelPool {
@Nullable
Channel acquire();
boolean release(final Channel dft);
void cleanup();
int getMaxCount();
int getUsedCount();
}
}

View File

@ -0,0 +1,42 @@
package com.mojang.blaze3d.audio;
import com.mojang.math.Vector3f;
import org.lwjgl.openal.AL10;
import net.minecraft.world.phys.Vec3;
public class Listener {
private float gain;
private Vec3 position;
public Listener() {
this.gain = 1.0f;
this.position = Vec3.ZERO;
}
public void setListenerPosition(final Vec3 dem) {
this.position = dem;
AL10.alListener3f(4100, (float)dem.x, (float)dem.y, (float)dem.z);
}
public Vec3 getListenerPosition() {
return this.position;
}
public void setListenerOrientation(final Vector3f g1, final Vector3f g2) {
AL10.alListenerfv(4111, new float[] { g1.x(), g1.y(), g1.z(), g2.x(), g2.y(), g2.z() });
}
public void setGain(final float float1) {
AL10.alListenerf(4106, float1);
this.gain = float1;
}
public float getGain() {
return this.gain;
}
public void reset() {
this.setListenerPosition(Vec3.ZERO);
this.setListenerOrientation(Vector3f.ZN, Vector3f.YP);
}
}

View File

@ -0,0 +1,220 @@
package com.mojang.blaze3d.audio;
import java.util.function.Consumer;
import net.minecraft.util.Mth;
import org.lwjgl.BufferUtils;
import com.google.common.collect.Lists;
import java.util.List;
import java.nio.FloatBuffer;
import org.lwjgl.PointerBuffer;
import java.nio.Buffer;
import java.nio.IntBuffer;
import org.lwjgl.stb.STBVorbisInfo;
import org.lwjgl.stb.STBVorbisAlloc;
import org.lwjgl.stb.STBVorbis;
import java.io.IOException;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import java.nio.ByteBuffer;
import java.io.InputStream;
import javax.sound.sampled.AudioFormat;
import net.minecraft.client.sounds.AudioStream;
public class OggAudioStream implements AudioStream {
private long handle;
private final AudioFormat audioFormat;
private final InputStream input;
private ByteBuffer buffer;
public OggAudioStream(final InputStream inputStream) throws IOException {
this.buffer = MemoryUtil.memAlloc(8192);
this.input = inputStream;
this.buffer.limit(0);
try (final MemoryStack memoryStack3 = MemoryStack.stackPush()) {
final IntBuffer intBuffer5 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer6 = memoryStack3.mallocInt(1);
while (this.handle == 0L) {
if (!this.refillFromStream()) {
throw new IOException("Failed to find Ogg header");
}
final int integer7 = this.buffer.position();
this.buffer.position(0);
this.handle = STBVorbis.stb_vorbis_open_pushdata(this.buffer, intBuffer5, intBuffer6, (STBVorbisAlloc)null);
this.buffer.position(integer7);
final int integer8 = intBuffer6.get(0);
if (integer8 == 1) {
this.forwardBuffer();
}
else {
if (integer8 != 0) {
throw new IOException("Failed to read Ogg file " + integer8);
}
continue;
}
}
this.buffer.position(this.buffer.position() + intBuffer5.get(0));
final STBVorbisInfo sTBVorbisInfo7 = STBVorbisInfo.mallocStack(memoryStack3);
STBVorbis.stb_vorbis_get_info(this.handle, sTBVorbisInfo7);
this.audioFormat = new AudioFormat((float)sTBVorbisInfo7.sample_rate(), 16, sTBVorbisInfo7.channels(), true, false);
}
}
private boolean refillFromStream() throws IOException {
final int integer2 = this.buffer.limit();
final int integer3 = this.buffer.capacity() - integer2;
if (integer3 == 0) {
return true;
}
final byte[] arr4 = new byte[integer3];
final int integer4 = this.input.read(arr4);
if (integer4 == -1) {
return false;
}
final int integer5 = this.buffer.position();
this.buffer.limit(integer2 + integer4);
this.buffer.position(integer2);
this.buffer.put(arr4, 0, integer4);
this.buffer.position(integer5);
return true;
}
private void forwardBuffer() {
final boolean boolean2 = this.buffer.position() == 0;
final boolean boolean3 = this.buffer.position() == this.buffer.limit();
if (boolean3 && !boolean2) {
this.buffer.position(0);
this.buffer.limit(0);
}
else {
final ByteBuffer byteBuffer4 = MemoryUtil.memAlloc(boolean2 ? (2 * this.buffer.capacity()) : this.buffer.capacity());
byteBuffer4.put(this.buffer);
MemoryUtil.memFree((Buffer)this.buffer);
byteBuffer4.flip();
this.buffer = byteBuffer4;
}
}
private boolean readFrame(final OutputConcat a) throws IOException {
if (this.handle == 0L) {
return false;
}
try (final MemoryStack memoryStack3 = MemoryStack.stackPush()) {
final PointerBuffer pointerBuffer5 = memoryStack3.mallocPointer(1);
final IntBuffer intBuffer6 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer7 = memoryStack3.mallocInt(1);
while (true) {
final int integer8 = STBVorbis.stb_vorbis_decode_frame_pushdata(this.handle, this.buffer, intBuffer6, pointerBuffer5, intBuffer7);
this.buffer.position(this.buffer.position() + integer8);
final int integer9 = STBVorbis.stb_vorbis_get_error(this.handle);
if (integer9 == 1) {
this.forwardBuffer();
if (!this.refillFromStream()) {
return false;
}
continue;
}
else {
if (integer9 != 0) {
throw new IOException("Failed to read Ogg file " + integer9);
}
final int integer10 = intBuffer7.get(0);
if (integer10 == 0) {
continue;
}
final int integer11 = intBuffer6.get(0);
final PointerBuffer pointerBuffer6 = pointerBuffer5.getPointerBuffer(integer11);
if (integer11 == 1) {
this.convertMono(pointerBuffer6.getFloatBuffer(0, integer10), a);
return true;
}
if (integer11 == 2) {
this.convertStereo(pointerBuffer6.getFloatBuffer(0, integer10), pointerBuffer6.getFloatBuffer(1, integer10), a);
return true;
}
throw new IllegalStateException("Invalid number of channels: " + integer11);
}
}
}
}
private void convertMono(final FloatBuffer floatBuffer, final OutputConcat a) {
while (floatBuffer.hasRemaining()) {
a.put(floatBuffer.get());
}
}
private void convertStereo(final FloatBuffer floatBuffer1, final FloatBuffer floatBuffer2, final OutputConcat a) {
while (floatBuffer1.hasRemaining() && floatBuffer2.hasRemaining()) {
a.put(floatBuffer1.get());
a.put(floatBuffer2.get());
}
}
@Override
public void close() throws IOException {
if (this.handle != 0L) {
STBVorbis.stb_vorbis_close(this.handle);
this.handle = 0L;
}
MemoryUtil.memFree((Buffer)this.buffer);
this.input.close();
}
@Override
public AudioFormat getFormat() {
return this.audioFormat;
}
@Override
public ByteBuffer read(final int integer) throws IOException {
final OutputConcat a3 = new OutputConcat(integer + 8192);
while (this.readFrame(a3) && a3.byteCount < integer) {}
return a3.get();
}
public ByteBuffer readAll() throws IOException {
final OutputConcat a2 = new OutputConcat(16384);
while (this.readFrame(a2)) {}
return a2.get();
}
static class OutputConcat {
private final List<ByteBuffer> buffers;
private final int bufferSize;
private int byteCount;
private ByteBuffer currentBuffer;
public OutputConcat(final int integer) {
this.buffers = Lists.newArrayList();
this.bufferSize = (integer + 1 & 0xFFFFFFFE);
this.createNewBuffer();
}
private void createNewBuffer() {
this.currentBuffer = BufferUtils.createByteBuffer(this.bufferSize);
}
public void put(final float float1) {
if (this.currentBuffer.remaining() == 0) {
this.currentBuffer.flip();
this.buffers.add(this.currentBuffer);
this.createNewBuffer();
}
final int integer3 = Mth.clamp((int)(float1 * 32767.5f - 0.5f), -32768, 32767);
this.currentBuffer.putShort((short)integer3);
this.byteCount += 2;
}
public ByteBuffer get() {
this.currentBuffer.flip();
if (this.buffers.isEmpty()) {
return this.currentBuffer;
}
final ByteBuffer byteBuffer2 = BufferUtils.createByteBuffer(this.byteCount);
this.buffers.forEach(byteBuffer2::put);
byteBuffer2.put(this.currentBuffer);
byteBuffer2.flip();
return byteBuffer2;
}
}
}

View File

@ -0,0 +1,104 @@
package com.mojang.blaze3d.audio;
import org.apache.logging.log4j.LogManager;
import javax.sound.sampled.AudioFormat;
import org.lwjgl.openal.ALC10;
import org.lwjgl.openal.AL10;
import org.apache.logging.log4j.Logger;
public class OpenAlUtil {
private static final Logger LOGGER;
private static String alErrorToString(final int integer) {
switch (integer) {
case 40961: {
return "Invalid name parameter.";
}
case 40962: {
return "Invalid enumerated parameter value.";
}
case 40963: {
return "Invalid parameter parameter value.";
}
case 40964: {
return "Invalid operation.";
}
case 40965: {
return "Unable to allocate memory.";
}
default: {
return "An unrecognized error occurred.";
}
}
}
static boolean checkALError(final String string) {
final int integer2 = AL10.alGetError();
if (integer2 != 0) {
OpenAlUtil.LOGGER.error("{}: {}", string, alErrorToString(integer2));
return true;
}
return false;
}
private static String alcErrorToString(final int integer) {
switch (integer) {
case 40961: {
return "Invalid device.";
}
case 40962: {
return "Invalid context.";
}
case 40964: {
return "Invalid value.";
}
case 40963: {
return "Illegal enum.";
}
case 40965: {
return "Unable to allocate memory.";
}
default: {
return "An unrecognized error occurred.";
}
}
}
static boolean checkALCError(final long long1, final String string) {
final int integer4 = ALC10.alcGetError(long1);
if (integer4 != 0) {
OpenAlUtil.LOGGER.error("{}{}: {}", string, long1, alcErrorToString(integer4));
return true;
}
return false;
}
static int audioFormatToOpenAl(final AudioFormat audioFormat) {
final AudioFormat.Encoding encoding2 = audioFormat.getEncoding();
final int integer3 = audioFormat.getChannels();
final int integer4 = audioFormat.getSampleSizeInBits();
if (encoding2.equals(AudioFormat.Encoding.PCM_UNSIGNED) || encoding2.equals(AudioFormat.Encoding.PCM_SIGNED)) {
if (integer3 == 1) {
if (integer4 == 8) {
return 4352;
}
if (integer4 == 16) {
return 4353;
}
}
else if (integer3 == 2) {
if (integer4 == 8) {
return 4354;
}
if (integer4 == 16) {
return 4355;
}
}
}
throw new IllegalArgumentException("Invalid audio format: " + audioFormat);
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,58 @@
package com.mojang.blaze3d.audio;
import org.lwjgl.openal.AL10;
import java.util.OptionalInt;
import javax.sound.sampled.AudioFormat;
import javax.annotation.Nullable;
import java.nio.ByteBuffer;
public class SoundBuffer {
@Nullable
private ByteBuffer data;
private final AudioFormat format;
private boolean hasAlBuffer;
private int alBuffer;
public SoundBuffer(final ByteBuffer byteBuffer, final AudioFormat audioFormat) {
this.data = byteBuffer;
this.format = audioFormat;
}
OptionalInt getAlBuffer() {
if (!this.hasAlBuffer) {
if (this.data == null) {
return OptionalInt.empty();
}
final int integer2 = OpenAlUtil.audioFormatToOpenAl(this.format);
final int[] arr3 = { 0 };
AL10.alGenBuffers(arr3);
if (OpenAlUtil.checkALError("Creating buffer")) {
return OptionalInt.empty();
}
AL10.alBufferData(arr3[0], integer2, this.data, (int)this.format.getSampleRate());
if (OpenAlUtil.checkALError("Assigning buffer data")) {
return OptionalInt.empty();
}
this.alBuffer = arr3[0];
this.hasAlBuffer = true;
this.data = null;
}
return OptionalInt.of(this.alBuffer);
}
public void discardAlBuffer() {
if (this.hasAlBuffer) {
AL10.alDeleteBuffers(new int[] { this.alBuffer });
if (OpenAlUtil.checkALError("Deleting stream buffers")) {
return;
}
}
this.hasAlBuffer = false;
}
public OptionalInt releaseAlBuffer() {
final OptionalInt optionalInt2 = this.getAlBuffer();
this.hasAlBuffer = false;
return optionalInt2;
}
}

View File

@ -0,0 +1,21 @@
package com.mojang.blaze3d.font;
public interface GlyphInfo {
float getAdvance();
default float getAdvance(final boolean boolean1) {
return this.getAdvance() + (boolean1 ? this.getBoldOffset() : 0.0f);
}
default float getBearingX() {
return 0.0f;
}
default float getBoldOffset() {
return 1.0f;
}
default float getShadowOffset() {
return 1.0f;
}
}

View File

@ -0,0 +1,17 @@
package com.mojang.blaze3d.font;
import it.unimi.dsi.fastutil.ints.IntSet;
import javax.annotation.Nullable;
import java.io.Closeable;
public interface GlyphProvider extends Closeable {
default void close() {
}
@Nullable
default RawGlyph getGlyph(final int integer) {
return null;
}
IntSet getSupportedGlyphs();
}

View File

@ -0,0 +1,33 @@
package com.mojang.blaze3d.font;
public interface RawGlyph extends GlyphInfo {
int getPixelWidth();
int getPixelHeight();
void upload(final int integer1, final int integer2);
boolean isColored();
float getOversample();
default float getLeft() {
return this.getBearingX();
}
default float getRight() {
return this.getLeft() + this.getPixelWidth() / this.getOversample();
}
default float getUp() {
return this.getBearingY();
}
default float getDown() {
return this.getUp() + this.getPixelHeight() / this.getOversample();
}
default float getBearingY() {
return 3.0f;
}
}

View File

@ -0,0 +1,145 @@
package com.mojang.blaze3d.font;
import com.mojang.blaze3d.platform.NativeImage;
import java.util.function.Supplier;
import it.unimi.dsi.fastutil.ints.IntCollection;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import java.util.stream.IntStream;
import java.nio.Buffer;
import org.lwjgl.system.MemoryUtil;
import javax.annotation.Nullable;
import java.nio.IntBuffer;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.stb.STBTruetype;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
import org.lwjgl.stb.STBTTFontinfo;
import java.nio.ByteBuffer;
public class TrueTypeGlyphProvider implements GlyphProvider {
private final ByteBuffer fontMemory;
private final STBTTFontinfo font;
private final float oversample;
private final IntSet skip;
private final float shiftX;
private final float shiftY;
private final float pointScale;
private final float ascent;
public TrueTypeGlyphProvider(final ByteBuffer byteBuffer, final STBTTFontinfo sTBTTFontinfo, final float float3, final float float4, final float float5, final float float6, final String string) {
this.skip = (IntSet)new IntArraySet();
this.fontMemory = byteBuffer;
this.font = sTBTTFontinfo;
this.oversample = float4;
string.codePoints().forEach(this.skip::add);
this.shiftX = float5 * float4;
this.shiftY = float6 * float4;
this.pointScale = STBTruetype.stbtt_ScaleForPixelHeight(sTBTTFontinfo, float3 * float4);
try (final MemoryStack memoryStack9 = MemoryStack.stackPush()) {
final IntBuffer intBuffer11 = memoryStack9.mallocInt(1);
final IntBuffer intBuffer12 = memoryStack9.mallocInt(1);
final IntBuffer intBuffer13 = memoryStack9.mallocInt(1);
STBTruetype.stbtt_GetFontVMetrics(sTBTTFontinfo, intBuffer11, intBuffer12, intBuffer13);
this.ascent = intBuffer11.get(0) * this.pointScale;
}
}
@Nullable
@Override
public Glyph getGlyph(final int integer) {
if (this.skip.contains(integer)) {
return null;
}
try (final MemoryStack memoryStack3 = MemoryStack.stackPush()) {
final IntBuffer intBuffer5 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer6 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer7 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer8 = memoryStack3.mallocInt(1);
final int integer2 = STBTruetype.stbtt_FindGlyphIndex(this.font, integer);
if (integer2 == 0) {
return null;
}
STBTruetype.stbtt_GetGlyphBitmapBoxSubpixel(this.font, integer2, this.pointScale, this.pointScale, this.shiftX, this.shiftY, intBuffer5, intBuffer6, intBuffer7, intBuffer8);
final int integer3 = intBuffer7.get(0) - intBuffer5.get(0);
final int integer4 = intBuffer8.get(0) - intBuffer6.get(0);
if (integer3 == 0 || integer4 == 0) {
return null;
}
final IntBuffer intBuffer9 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer10 = memoryStack3.mallocInt(1);
STBTruetype.stbtt_GetGlyphHMetrics(this.font, integer2, intBuffer9, intBuffer10);
return new Glyph(intBuffer5.get(0), intBuffer7.get(0), -intBuffer6.get(0), -intBuffer8.get(0), intBuffer9.get(0) * this.pointScale, intBuffer10.get(0) * this.pointScale, integer2);
}
}
@Override
public void close() {
this.font.free();
MemoryUtil.memFree((Buffer)this.fontMemory);
}
@Override
public IntSet getSupportedGlyphs() {
return IntStream.range(0, 65535).filter(integer -> !this.skip.contains(integer)).<IntSet>collect((Supplier<IntSet>)IntOpenHashSet::new, IntCollection::add, IntCollection::addAll);
}
class Glyph implements RawGlyph {
private final int width;
private final int height;
private final float bearingX;
private final float bearingY;
private final float advance;
private final int index;
private Glyph(final int integer2, final int integer3, final int integer4, final int integer5, final float float6, final float float7, final int integer8) {
this.width = integer3 - integer2;
this.height = integer4 - integer5;
this.advance = float6 / TrueTypeGlyphProvider.this.oversample;
this.bearingX = (float7 + integer2 + TrueTypeGlyphProvider.this.shiftX) / TrueTypeGlyphProvider.this.oversample;
this.bearingY = (TrueTypeGlyphProvider.this.ascent - integer4 + TrueTypeGlyphProvider.this.shiftY) / TrueTypeGlyphProvider.this.oversample;
this.index = integer8;
}
@Override
public int getPixelWidth() {
return this.width;
}
@Override
public int getPixelHeight() {
return this.height;
}
@Override
public float getOversample() {
return TrueTypeGlyphProvider.this.oversample;
}
@Override
public float getAdvance() {
return this.advance;
}
@Override
public float getBearingX() {
return this.bearingX;
}
@Override
public float getBearingY() {
return this.bearingY;
}
@Override
public void upload(final int integer1, final int integer2) {
final NativeImage dgs4 = new NativeImage(NativeImage.Format.LUMINANCE, this.width, this.height, false);
dgs4.copyFromFont(TrueTypeGlyphProvider.this.font, this.index, this.width, this.height, TrueTypeGlyphProvider.this.pointScale, TrueTypeGlyphProvider.this.pointScale, TrueTypeGlyphProvider.this.shiftX, TrueTypeGlyphProvider.this.shiftY, 0, 0);
dgs4.upload(0, integer1, integer2, 0, 0, this.width, this.height, false, true);
}
@Override
public boolean isColored() {
return false;
}
}
}

View File

@ -0,0 +1,5 @@
package com.mojang.blaze3d.pipeline;
public interface RenderCall {
void execute();
}

View File

@ -0,0 +1,19 @@
package com.mojang.blaze3d.pipeline;
import com.google.common.collect.ImmutableList;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.List;
public class RenderPipeline {
private final List<ConcurrentLinkedQueue<RenderCall>> renderCalls;
private volatile int recordingBuffer;
private volatile int processedBuffer;
private volatile int renderingBuffer;
public RenderPipeline() {
this.renderCalls = ImmutableList.of(new ConcurrentLinkedQueue(), new ConcurrentLinkedQueue(), new ConcurrentLinkedQueue(), new ConcurrentLinkedQueue());
final int n = this.renderingBuffer + 1;
this.processedBuffer = n;
this.recordingBuffer = n;
}
}

View File

@ -0,0 +1,265 @@
package com.mojang.blaze3d.pipeline;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import java.nio.IntBuffer;
import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.platform.GlConst;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
public class RenderTarget {
public int width;
public int height;
public int viewWidth;
public int viewHeight;
public final boolean useDepth;
public int frameBufferId;
public int colorTextureId;
public int depthBufferId;
public final float[] clearChannels;
public int filterMode;
public RenderTarget(final int integer1, final int integer2, final boolean boolean3, final boolean boolean4) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
this.useDepth = boolean3;
this.frameBufferId = -1;
this.colorTextureId = -1;
this.depthBufferId = -1;
(this.clearChannels = new float[4])[0] = 1.0f;
this.clearChannels[1] = 1.0f;
this.clearChannels[2] = 1.0f;
this.clearChannels[3] = 0.0f;
this.resize(integer1, integer2, boolean4);
}
public void resize(final int integer1, final int integer2, final boolean boolean3) {
if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(() -> this._resize(integer1, integer2, boolean3));
}
else {
this._resize(integer1, integer2, boolean3);
}
}
private void _resize(final int integer1, final int integer2, final boolean boolean3) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
GlStateManager._enableDepthTest();
if (this.frameBufferId >= 0) {
this.destroyBuffers();
}
this.createBuffers(integer1, integer2, boolean3);
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, 0);
}
public void destroyBuffers() {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
this.unbindRead();
this.unbindWrite();
if (this.depthBufferId > -1) {
TextureUtil.releaseTextureId(this.depthBufferId);
this.depthBufferId = -1;
}
if (this.colorTextureId > -1) {
TextureUtil.releaseTextureId(this.colorTextureId);
this.colorTextureId = -1;
}
if (this.frameBufferId > -1) {
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, 0);
GlStateManager._glDeleteFramebuffers(this.frameBufferId);
this.frameBufferId = -1;
}
}
public void copyDepthFrom(final RenderTarget dgf) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
if (GlStateManager.supportsFramebufferBlit()) {
GlStateManager._glBindFramebuffer(36008, dgf.frameBufferId);
GlStateManager._glBindFramebuffer(36009, this.frameBufferId);
GlStateManager._glBlitFrameBuffer(0, 0, dgf.width, dgf.height, 0, 0, this.width, this.height, 256, 9728);
}
else {
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, this.frameBufferId);
final int integer3 = GlStateManager.getFramebufferDepthTexture();
if (integer3 != 0) {
final int integer4 = GlStateManager.getActiveTextureName();
GlStateManager._bindTexture(integer3);
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, dgf.frameBufferId);
GlStateManager._glCopyTexSubImage2D(3553, 0, 0, 0, 0, 0, Math.min(this.width, dgf.width), Math.min(this.height, dgf.height));
GlStateManager._bindTexture(integer4);
}
}
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, 0);
}
public void createBuffers(final int integer1, final int integer2, final boolean boolean3) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
this.viewWidth = integer1;
this.viewHeight = integer2;
this.width = integer1;
this.height = integer2;
this.frameBufferId = GlStateManager.glGenFramebuffers();
this.colorTextureId = TextureUtil.generateTextureId();
if (this.useDepth) {
GlStateManager._bindTexture(this.depthBufferId = TextureUtil.generateTextureId());
GlStateManager._texParameter(3553, 10241, 9728);
GlStateManager._texParameter(3553, 10240, 9728);
GlStateManager._texParameter(3553, 10242, 10496);
GlStateManager._texParameter(3553, 10243, 10496);
GlStateManager._texParameter(3553, 34892, 0);
GlStateManager._texImage2D(3553, 0, 6402, this.width, this.height, 0, 6402, 5126, null);
}
this.setFilterMode(9728);
GlStateManager._bindTexture(this.colorTextureId);
GlStateManager._texImage2D(3553, 0, 32856, this.width, this.height, 0, 6408, 5121, null);
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, this.frameBufferId);
GlStateManager._glFramebufferTexture2D(GlConst.GL_FRAMEBUFFER, GlConst.GL_COLOR_ATTACHMENT0, 3553, this.colorTextureId, 0);
if (this.useDepth) {
GlStateManager._glFramebufferTexture2D(GlConst.GL_FRAMEBUFFER, GlConst.GL_DEPTH_ATTACHMENT, 3553, this.depthBufferId, 0);
}
this.checkStatus();
this.clear(boolean3);
this.unbindRead();
}
public void setFilterMode(final int integer) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
this.filterMode = integer;
GlStateManager._bindTexture(this.colorTextureId);
GlStateManager._texParameter(3553, 10241, integer);
GlStateManager._texParameter(3553, 10240, integer);
GlStateManager._texParameter(3553, 10242, 10496);
GlStateManager._texParameter(3553, 10243, 10496);
GlStateManager._bindTexture(0);
}
public void checkStatus() {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
final int integer2 = GlStateManager.glCheckFramebufferStatus(GlConst.GL_FRAMEBUFFER);
if (integer2 == GlConst.GL_FRAMEBUFFER_COMPLETE) {
return;
}
if (integer2 == GlConst.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
}
if (integer2 == GlConst.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
}
if (integer2 == GlConst.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER");
}
if (integer2 == GlConst.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER");
}
throw new RuntimeException("glCheckFramebufferStatus returned unknown status:" + integer2);
}
public void bindRead() {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
GlStateManager._bindTexture(this.colorTextureId);
}
public void unbindRead() {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
GlStateManager._bindTexture(0);
}
public void bindWrite(final boolean boolean1) {
if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(() -> this._bindWrite(boolean1));
}
else {
this._bindWrite(boolean1);
}
}
private void _bindWrite(final boolean boolean1) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, this.frameBufferId);
if (boolean1) {
GlStateManager._viewport(0, 0, this.viewWidth, this.viewHeight);
}
}
public void unbindWrite() {
if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(() -> GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, 0));
}
else {
GlStateManager._glBindFramebuffer(GlConst.GL_FRAMEBUFFER, 0);
}
}
public void setClearColor(final float float1, final float float2, final float float3, final float float4) {
this.clearChannels[0] = float1;
this.clearChannels[1] = float2;
this.clearChannels[2] = float3;
this.clearChannels[3] = float4;
}
public void blitToScreen(final int integer1, final int integer2) {
this.blitToScreen(integer1, integer2, true);
}
public void blitToScreen(final int integer1, final int integer2, final boolean boolean3) {
RenderSystem.assertThread(RenderSystem::isOnGameThreadOrInit);
if (!RenderSystem.isInInitPhase()) {
RenderSystem.recordRenderCall(() -> this._blitToScreen(integer1, integer2, boolean3));
}
else {
this._blitToScreen(integer1, integer2, boolean3);
}
}
private void _blitToScreen(final int integer1, final int integer2, final boolean boolean3) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
GlStateManager._colorMask(true, true, true, false);
GlStateManager._disableDepthTest();
GlStateManager._depthMask(false);
GlStateManager._matrixMode(5889);
GlStateManager._loadIdentity();
GlStateManager._ortho(0.0, integer1, integer2, 0.0, 1000.0, 3000.0);
GlStateManager._matrixMode(5888);
GlStateManager._loadIdentity();
GlStateManager._translatef(0.0f, 0.0f, -2000.0f);
GlStateManager._viewport(0, 0, integer1, integer2);
GlStateManager._enableTexture();
GlStateManager._disableLighting();
GlStateManager._disableAlphaTest();
if (boolean3) {
GlStateManager._disableBlend();
GlStateManager._enableColorMaterial();
}
GlStateManager._color4f(1.0f, 1.0f, 1.0f, 1.0f);
this.bindRead();
final float float5 = (float)integer1;
final float float6 = (float)integer2;
final float float7 = this.viewWidth / (float)this.width;
final float float8 = this.viewHeight / (float)this.height;
final Tesselator dhn9 = RenderSystem.renderThreadTesselator();
final BufferBuilder dhg10 = dhn9.getBuilder();
dhg10.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR);
dhg10.vertex(0.0, float6, 0.0).uv(0.0f, 0.0f).color(255, 255, 255, 255).endVertex();
dhg10.vertex(float5, float6, 0.0).uv(float7, 0.0f).color(255, 255, 255, 255).endVertex();
dhg10.vertex(float5, 0.0, 0.0).uv(float7, float8).color(255, 255, 255, 255).endVertex();
dhg10.vertex(0.0, 0.0, 0.0).uv(0.0f, float8).color(255, 255, 255, 255).endVertex();
dhn9.end();
this.unbindRead();
GlStateManager._depthMask(true);
GlStateManager._colorMask(true, true, true, true);
}
public void clear(final boolean boolean1) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
this.bindWrite(true);
GlStateManager._clearColor(this.clearChannels[0], this.clearChannels[1], this.clearChannels[2], this.clearChannels[3]);
int integer3 = 16384;
if (this.useDepth) {
GlStateManager._clearDepth(1.0);
integer3 |= 0x100;
}
GlStateManager._clear(integer3, boolean1);
this.unbindWrite();
}
}

View File

@ -0,0 +1,55 @@
package com.mojang.blaze3d.platform;
import java.nio.Buffer;
import org.lwjgl.system.MemoryUtil;
import com.google.common.base.Charsets;
import org.lwjgl.glfw.GLFWErrorCallback;
import net.minecraft.client.StringDecomposer;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import org.lwjgl.BufferUtils;
import java.nio.ByteBuffer;
public class ClipboardManager {
private final ByteBuffer clipboardScratchBuffer;
public ClipboardManager() {
this.clipboardScratchBuffer = BufferUtils.createByteBuffer(8192);
}
public String getClipboard(final long long1, final GLFWErrorCallbackI gLFWErrorCallbackI) {
final GLFWErrorCallback gLFWErrorCallback5 = GLFW.glfwSetErrorCallback(gLFWErrorCallbackI);
String string6 = GLFW.glfwGetClipboardString(long1);
string6 = ((string6 != null) ? StringDecomposer.filterBrokenSurrogates(string6) : "");
final GLFWErrorCallback gLFWErrorCallback6 = GLFW.glfwSetErrorCallback((GLFWErrorCallbackI)gLFWErrorCallback5);
if (gLFWErrorCallback6 != null) {
gLFWErrorCallback6.free();
}
return string6;
}
private static void pushClipboard(final long long1, final ByteBuffer byteBuffer, final byte[] arr) {
byteBuffer.clear();
byteBuffer.put(arr);
byteBuffer.put((byte)0);
byteBuffer.flip();
GLFW.glfwSetClipboardString(long1, byteBuffer);
}
public void setClipboard(final long long1, final String string) {
final byte[] arr5 = string.getBytes(Charsets.UTF_8);
final int integer6 = arr5.length + 1;
if (integer6 < this.clipboardScratchBuffer.capacity()) {
pushClipboard(long1, this.clipboardScratchBuffer, arr5);
}
else {
final ByteBuffer byteBuffer7 = MemoryUtil.memAlloc(integer6);
try {
pushClipboard(long1, byteBuffer7, arr5);
}
finally {
MemoryUtil.memFree((Buffer)byteBuffer7);
}
}
}
}

View File

@ -0,0 +1,66 @@
package com.mojang.blaze3d.platform;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.invoke.MethodHandles;
import org.lwjgl.system.Pointer;
import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
public class DebugMemoryUntracker {
@Nullable
private static final MethodHandle UNTRACK;
public static void untrack(final long long1) {
if (DebugMemoryUntracker.UNTRACK == null) {
return;
}
try {
DebugMemoryUntracker.UNTRACK.invoke(long1);
}
catch (Throwable throwable3) {
throw new RuntimeException(throwable3);
}
}
public static void untrack(final Pointer pointer) {
untrack(pointer.address());
}
static {
MethodHandles.Lookup lookup1;
Class<?> class2;
Method method3;
Field field4;
Object object5;
final ReflectiveOperationException ex;
ReflectiveOperationException reflectiveOperationException1;
UNTRACK = GLX.<MethodHandle>make(() -> {
try {
lookup1 = MethodHandles.lookup();
class2 = Class.forName("org.lwjgl.system.MemoryManage$DebugAllocator");
method3 = class2.getDeclaredMethod("untrack", Long.TYPE);
method3.setAccessible(true);
field4 = Class.forName("org.lwjgl.system.MemoryUtil$LazyInit").getDeclaredField("ALLOCATOR");
field4.setAccessible(true);
object5 = field4.get(null);
if (class2.isInstance(object5)) {
return lookup1.unreflect(method3);
}
else {
try {
return null;
}
catch (NoSuchMethodException | NoSuchFieldException ex2) {
reflectiveOperationException1 = ex;
throw new RuntimeException(reflectiveOperationException1);
}
}
}
catch (ClassNotFoundException ex3) {}
catch (NoSuchMethodException ex4) {}
catch (NoSuchFieldException ex5) {}
catch (IllegalAccessException ex6) {}
});
}
}

View File

@ -0,0 +1,19 @@
package com.mojang.blaze3d.platform;
import java.util.OptionalInt;
public class DisplayData {
public final int width;
public final int height;
public final OptionalInt fullscreenWidth;
public final OptionalInt fullscreenHeight;
public final boolean isFullscreen;
public DisplayData(final int integer1, final int integer2, final OptionalInt optionalInt3, final OptionalInt optionalInt4, final boolean boolean5) {
this.width = integer1;
this.height = integer2;
this.fullscreenWidth = optionalInt3;
this.fullscreenHeight = optionalInt4;
this.isFullscreen = boolean5;
}
}

View File

@ -0,0 +1,187 @@
package com.mojang.blaze3d.platform;
import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
import java.util.HashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import org.lwjgl.opengl.GL11;
import oshi.hardware.Processor;
import org.lwjgl.opengl.GLCapabilities;
import oshi.SystemInfo;
import org.lwjgl.opengl.GL;
import java.util.Iterator;
import org.lwjgl.glfw.GLFWErrorCallback;
import java.util.List;
import com.google.common.base.Joiner;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import com.google.common.collect.Lists;
import java.util.function.LongSupplier;
import org.lwjgl.Version;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.Map;
import org.apache.logging.log4j.Logger;
public class GLX {
private static final Logger LOGGER;
private static String capsString;
private static String cpuInfo;
private static final Map<Integer, String> LOOKUP_MAP;
public static String getOpenGLVersionString() {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
if (GLFW.glfwGetCurrentContext() == 0L) {
return "NO CONTEXT";
}
return GlStateManager._getString(7937) + " GL version " + GlStateManager._getString(7938) + ", " + GlStateManager._getString(7936);
}
public static int _getRefreshRate(final Window dgy) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
long long2 = GLFW.glfwGetWindowMonitor(dgy.getWindow());
if (long2 == 0L) {
long2 = GLFW.glfwGetPrimaryMonitor();
}
final GLFWVidMode gLFWVidMode4 = (long2 == 0L) ? null : GLFW.glfwGetVideoMode(long2);
return (gLFWVidMode4 == null) ? 0 : gLFWVidMode4.refreshRate();
}
public static String _getLWJGLVersion() {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
return Version.getVersion();
}
public static LongSupplier _initGlfw() {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
final IllegalStateException ex;
Window.checkGlfwError((integer, string) -> {
new IllegalStateException(String.format("GLFW error before init: [0x%X]%s", integer, string));
throw ex;
});
final List<String> list1 = Lists.newArrayList();
final GLFWErrorCallback gLFWErrorCallback2 = GLFW.glfwSetErrorCallback((integer, long3) -> list1.add(String.format("GLFW error during init: [0x%X]%s", integer, long3)));
if (GLFW.glfwInit()) {
final LongSupplier longSupplier3 = () -> (long)(GLFW.glfwGetTime() * 1.0E9);
for (final String string2 : list1) {
GLX.LOGGER.error("GLFW error collected during initialization: {}", string2);
}
RenderSystem.setErrorCallback((GLFWErrorCallbackI)gLFWErrorCallback2);
return longSupplier3;
}
throw new IllegalStateException("Failed to initialize GLFW, errors: " + Joiner.on(",").join(list1));
}
public static void _setGlfwErrorCallback(final GLFWErrorCallbackI gLFWErrorCallbackI) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
final GLFWErrorCallback gLFWErrorCallback2 = GLFW.glfwSetErrorCallback(gLFWErrorCallbackI);
if (gLFWErrorCallback2 != null) {
gLFWErrorCallback2.free();
}
}
public static boolean _shouldClose(final Window dgy) {
return GLFW.glfwWindowShouldClose(dgy.getWindow());
}
public static void _setupNvFogDistance() {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
if (GL.getCapabilities().GL_NV_fog_distance) {
GlStateManager._fogi(34138, 34139);
}
}
public static void _init(final int integer, final boolean boolean2) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
final GLCapabilities gLCapabilities3 = GL.getCapabilities();
GLX.capsString = "Using framebuffer using " + GlStateManager._init_fbo(gLCapabilities3);
try {
final Processor[] arr4 = new SystemInfo().getHardware().getProcessors();
GLX.cpuInfo = String.format("%dx %s", arr4.length, arr4[0]).replaceAll("\\s+", " ");
}
catch (Throwable t) {}
GlDebug.enableDebugCallback(integer, boolean2);
}
public static String _getCapsString() {
return GLX.capsString;
}
public static String _getCpuInfo() {
return (GLX.cpuInfo == null) ? "<unknown>" : GLX.cpuInfo;
}
public static void _renderCrosshair(final int integer, final boolean boolean2, final boolean boolean3, final boolean boolean4) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
GlStateManager._disableTexture();
GlStateManager._depthMask(false);
final Tesselator dhn5 = RenderSystem.renderThreadTesselator();
final BufferBuilder dhg6 = dhn5.getBuilder();
GL11.glLineWidth(4.0f);
dhg6.begin(1, DefaultVertexFormat.POSITION_COLOR);
if (boolean2) {
dhg6.vertex(0.0, 0.0, 0.0).color(0, 0, 0, 255).endVertex();
dhg6.vertex(integer, 0.0, 0.0).color(0, 0, 0, 255).endVertex();
}
if (boolean3) {
dhg6.vertex(0.0, 0.0, 0.0).color(0, 0, 0, 255).endVertex();
dhg6.vertex(0.0, integer, 0.0).color(0, 0, 0, 255).endVertex();
}
if (boolean4) {
dhg6.vertex(0.0, 0.0, 0.0).color(0, 0, 0, 255).endVertex();
dhg6.vertex(0.0, 0.0, integer).color(0, 0, 0, 255).endVertex();
}
dhn5.end();
GL11.glLineWidth(2.0f);
dhg6.begin(1, DefaultVertexFormat.POSITION_COLOR);
if (boolean2) {
dhg6.vertex(0.0, 0.0, 0.0).color(255, 0, 0, 255).endVertex();
dhg6.vertex(integer, 0.0, 0.0).color(255, 0, 0, 255).endVertex();
}
if (boolean3) {
dhg6.vertex(0.0, 0.0, 0.0).color(0, 255, 0, 255).endVertex();
dhg6.vertex(0.0, integer, 0.0).color(0, 255, 0, 255).endVertex();
}
if (boolean4) {
dhg6.vertex(0.0, 0.0, 0.0).color(127, 127, 255, 255).endVertex();
dhg6.vertex(0.0, 0.0, integer).color(127, 127, 255, 255).endVertex();
}
dhn5.end();
GL11.glLineWidth(1.0f);
GlStateManager._depthMask(true);
GlStateManager._enableTexture();
}
public static String getErrorString(final int integer) {
return GLX.LOOKUP_MAP.get(integer);
}
public static <T> T make(final Supplier<T> supplier) {
return supplier.get();
}
public static <T> T make(final T object, final Consumer<T> consumer) {
consumer.accept(object);
return object;
}
static {
LOGGER = LogManager.getLogger();
GLX.capsString = "";
LOOKUP_MAP = GLX.<Map<Integer, String>>make(Maps.newHashMap(), hashMap -> {
hashMap.put(0, "No error");
hashMap.put(1280, "Enum parameter is invalid for this function");
hashMap.put(1281, "Parameter is invalid for this function");
hashMap.put(1282, "Current state is invalid for this function");
hashMap.put(1283, "Stack overflow");
hashMap.put(1284, "Stack underflow");
hashMap.put(1285, "Out of memory");
hashMap.put(1286, "Operation on incomplete framebuffer");
hashMap.put(1286, "Operation on incomplete framebuffer");
});
}
}

View File

@ -0,0 +1,13 @@
package com.mojang.blaze3d.platform;
public class GlConst {
public static int GL_FRAMEBUFFER;
public static int GL_RENDERBUFFER;
public static int GL_COLOR_ATTACHMENT0;
public static int GL_DEPTH_ATTACHMENT;
public static int GL_FRAMEBUFFER_COMPLETE;
public static int GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
public static int GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
public static int GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER;
public static int GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER;
}

View File

@ -0,0 +1,886 @@
package com.mojang.blaze3d.platform;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.opengl.GLDebugMessageARBCallback;
import org.lwjgl.opengl.GLDebugMessageARBCallbackI;
import org.lwjgl.opengl.ARBDebugOutput;
import java.util.function.Consumer;
import org.lwjgl.opengl.GLDebugMessageCallbackI;
import org.lwjgl.opengl.KHRDebug;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL;
import com.mojang.blaze3d.systems.RenderSystem;
import org.lwjgl.opengl.GLDebugMessageCallback;
import java.util.List;
import java.util.Map;
import com.google.common.base.Joiner;
import java.nio.IntBuffer;
import java.nio.FloatBuffer;
import java.nio.ByteBuffer;
import org.apache.logging.log4j.Logger;
public class GlDebug {
private static final Logger LOGGER;
protected static final ByteBuffer BYTE_BUFFER;
protected static final FloatBuffer FLOAT_BUFFER;
protected static final IntBuffer INT_BUFFER;
private static final Joiner NEWLINE_JOINER;
private static final Joiner STATEMENT_JOINER;
private static final Map<Integer, String> BY_ID;
private static final List<Integer> DEBUG_LEVELS;
private static final List<Integer> DEBUG_LEVELS_ARB;
private static final Map<String, List<String>> SAVED_STATES;
private static String printUnknownToken(final int integer) {
return "Unknown (0x" + Integer.toHexString(integer).toUpperCase() + ")";
}
private static String sourceToString(final int integer) {
switch (integer) {
case 33350: {
return "API";
}
case 33351: {
return "WINDOW SYSTEM";
}
case 33352: {
return "SHADER COMPILER";
}
case 33353: {
return "THIRD PARTY";
}
case 33354: {
return "APPLICATION";
}
case 33355: {
return "OTHER";
}
default: {
return printUnknownToken(integer);
}
}
}
private static String typeToString(final int integer) {
switch (integer) {
case 33356: {
return "ERROR";
}
case 33357: {
return "DEPRECATED BEHAVIOR";
}
case 33358: {
return "UNDEFINED BEHAVIOR";
}
case 33359: {
return "PORTABILITY";
}
case 33360: {
return "PERFORMANCE";
}
case 33361: {
return "OTHER";
}
case 33384: {
return "MARKER";
}
default: {
return printUnknownToken(integer);
}
}
}
private static String severityToString(final int integer) {
switch (integer) {
case 37190: {
return "HIGH";
}
case 37191: {
return "MEDIUM";
}
case 37192: {
return "LOW";
}
case 33387: {
return "NOTIFICATION";
}
default: {
return printUnknownToken(integer);
}
}
}
private static void printDebugLog(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final long long6, final long long7) {
GlDebug.LOGGER.info("OpenGL debug message, id={}, source={}, type={}, severity={}, message={}", integer3, sourceToString(integer1), typeToString(integer2), severityToString(integer4), GLDebugMessageCallback.getMessage(integer5, long6));
}
private static void setup(final int integer, final String string) {
GlDebug.BY_ID.merge(integer, string, (string1, string2) -> string1 + "/" + string2);
}
public static void enableDebugCallback(final int integer, final boolean boolean2) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
if (integer <= 0) {
return;
}
final GLCapabilities gLCapabilities3 = GL.getCapabilities();
if (gLCapabilities3.GL_KHR_debug) {
GL11.glEnable(37600);
if (boolean2) {
GL11.glEnable(33346);
}
for (int integer2 = 0; integer2 < GlDebug.DEBUG_LEVELS.size(); ++integer2) {
final boolean boolean3 = integer2 < integer;
KHRDebug.glDebugMessageControl(4352, 4352, (int)GlDebug.DEBUG_LEVELS.get(integer2), (int[])null, boolean3);
}
KHRDebug.glDebugMessageCallback((GLDebugMessageCallbackI)GLX.<GLDebugMessageCallbackI>make((GLDebugMessageCallbackI)GLDebugMessageCallback.create(GlDebug::printDebugLog), (Consumer<GLDebugMessageCallbackI>)DebugMemoryUntracker::untrack), 0L);
}
else if (gLCapabilities3.GL_ARB_debug_output) {
if (boolean2) {
GL11.glEnable(33346);
}
for (int integer2 = 0; integer2 < GlDebug.DEBUG_LEVELS_ARB.size(); ++integer2) {
final boolean boolean3 = integer2 < integer;
ARBDebugOutput.glDebugMessageControlARB(4352, 4352, (int)GlDebug.DEBUG_LEVELS_ARB.get(integer2), (int[])null, boolean3);
}
ARBDebugOutput.glDebugMessageCallbackARB((GLDebugMessageARBCallbackI)GLX.<GLDebugMessageARBCallbackI>make((GLDebugMessageARBCallbackI)GLDebugMessageARBCallback.create(GlDebug::printDebugLog), (Consumer<GLDebugMessageARBCallbackI>)DebugMemoryUntracker::untrack), 0L);
}
}
static {
LOGGER = LogManager.getLogger();
BYTE_BUFFER = MemoryTracker.createByteBuffer(64);
FLOAT_BUFFER = GlDebug.BYTE_BUFFER.asFloatBuffer();
INT_BUFFER = GlDebug.BYTE_BUFFER.asIntBuffer();
NEWLINE_JOINER = Joiner.on('\n');
STATEMENT_JOINER = Joiner.on("; ");
BY_ID = Maps.newHashMap();
DEBUG_LEVELS = ImmutableList.<Integer>of(37190, 37191, 37192, 33387);
DEBUG_LEVELS_ARB = ImmutableList.<Integer>of(37190, 37191, 37192);
setup(256, "GL11.GL_ACCUM");
setup(257, "GL11.GL_LOAD");
setup(258, "GL11.GL_RETURN");
setup(259, "GL11.GL_MULT");
setup(260, "GL11.GL_ADD");
setup(512, "GL11.GL_NEVER");
setup(513, "GL11.GL_LESS");
setup(514, "GL11.GL_EQUAL");
setup(515, "GL11.GL_LEQUAL");
setup(516, "GL11.GL_GREATER");
setup(517, "GL11.GL_NOTEQUAL");
setup(518, "GL11.GL_GEQUAL");
setup(519, "GL11.GL_ALWAYS");
setup(0, "GL11.GL_POINTS");
setup(1, "GL11.GL_LINES");
setup(2, "GL11.GL_LINE_LOOP");
setup(3, "GL11.GL_LINE_STRIP");
setup(4, "GL11.GL_TRIANGLES");
setup(5, "GL11.GL_TRIANGLE_STRIP");
setup(6, "GL11.GL_TRIANGLE_FAN");
setup(7, "GL11.GL_QUADS");
setup(8, "GL11.GL_QUAD_STRIP");
setup(9, "GL11.GL_POLYGON");
setup(0, "GL11.GL_ZERO");
setup(1, "GL11.GL_ONE");
setup(768, "GL11.GL_SRC_COLOR");
setup(769, "GL11.GL_ONE_MINUS_SRC_COLOR");
setup(770, "GL11.GL_SRC_ALPHA");
setup(771, "GL11.GL_ONE_MINUS_SRC_ALPHA");
setup(772, "GL11.GL_DST_ALPHA");
setup(773, "GL11.GL_ONE_MINUS_DST_ALPHA");
setup(774, "GL11.GL_DST_COLOR");
setup(775, "GL11.GL_ONE_MINUS_DST_COLOR");
setup(776, "GL11.GL_SRC_ALPHA_SATURATE");
setup(32769, "GL14.GL_CONSTANT_COLOR");
setup(32770, "GL14.GL_ONE_MINUS_CONSTANT_COLOR");
setup(32771, "GL14.GL_CONSTANT_ALPHA");
setup(32772, "GL14.GL_ONE_MINUS_CONSTANT_ALPHA");
setup(1, "GL11.GL_TRUE");
setup(0, "GL11.GL_FALSE");
setup(12288, "GL11.GL_CLIP_PLANE0");
setup(12289, "GL11.GL_CLIP_PLANE1");
setup(12290, "GL11.GL_CLIP_PLANE2");
setup(12291, "GL11.GL_CLIP_PLANE3");
setup(12292, "GL11.GL_CLIP_PLANE4");
setup(12293, "GL11.GL_CLIP_PLANE5");
setup(5120, "GL11.GL_BYTE");
setup(5121, "GL11.GL_UNSIGNED_BYTE");
setup(5122, "GL11.GL_SHORT");
setup(5123, "GL11.GL_UNSIGNED_SHORT");
setup(5124, "GL11.GL_INT");
setup(5125, "GL11.GL_UNSIGNED_INT");
setup(5126, "GL11.GL_FLOAT");
setup(5127, "GL11.GL_2_BYTES");
setup(5128, "GL11.GL_3_BYTES");
setup(5129, "GL11.GL_4_BYTES");
setup(5130, "GL11.GL_DOUBLE");
setup(0, "GL11.GL_NONE");
setup(1024, "GL11.GL_FRONT_LEFT");
setup(1025, "GL11.GL_FRONT_RIGHT");
setup(1026, "GL11.GL_BACK_LEFT");
setup(1027, "GL11.GL_BACK_RIGHT");
setup(1028, "GL11.GL_FRONT");
setup(1029, "GL11.GL_BACK");
setup(1030, "GL11.GL_LEFT");
setup(1031, "GL11.GL_RIGHT");
setup(1032, "GL11.GL_FRONT_AND_BACK");
setup(1033, "GL11.GL_AUX0");
setup(1034, "GL11.GL_AUX1");
setup(1035, "GL11.GL_AUX2");
setup(1036, "GL11.GL_AUX3");
setup(0, "GL11.GL_NO_ERROR");
setup(1280, "GL11.GL_INVALID_ENUM");
setup(1281, "GL11.GL_INVALID_VALUE");
setup(1282, "GL11.GL_INVALID_OPERATION");
setup(1283, "GL11.GL_STACK_OVERFLOW");
setup(1284, "GL11.GL_STACK_UNDERFLOW");
setup(1285, "GL11.GL_OUT_OF_MEMORY");
setup(1536, "GL11.GL_2D");
setup(1537, "GL11.GL_3D");
setup(1538, "GL11.GL_3D_COLOR");
setup(1539, "GL11.GL_3D_COLOR_TEXTURE");
setup(1540, "GL11.GL_4D_COLOR_TEXTURE");
setup(1792, "GL11.GL_PASS_THROUGH_TOKEN");
setup(1793, "GL11.GL_POINT_TOKEN");
setup(1794, "GL11.GL_LINE_TOKEN");
setup(1795, "GL11.GL_POLYGON_TOKEN");
setup(1796, "GL11.GL_BITMAP_TOKEN");
setup(1797, "GL11.GL_DRAW_PIXEL_TOKEN");
setup(1798, "GL11.GL_COPY_PIXEL_TOKEN");
setup(1799, "GL11.GL_LINE_RESET_TOKEN");
setup(2048, "GL11.GL_EXP");
setup(2049, "GL11.GL_EXP2");
setup(2304, "GL11.GL_CW");
setup(2305, "GL11.GL_CCW");
setup(2560, "GL11.GL_COEFF");
setup(2561, "GL11.GL_ORDER");
setup(2562, "GL11.GL_DOMAIN");
setup(2816, "GL11.GL_CURRENT_COLOR");
setup(2817, "GL11.GL_CURRENT_INDEX");
setup(2818, "GL11.GL_CURRENT_NORMAL");
setup(2819, "GL11.GL_CURRENT_TEXTURE_COORDS");
setup(2820, "GL11.GL_CURRENT_RASTER_COLOR");
setup(2821, "GL11.GL_CURRENT_RASTER_INDEX");
setup(2822, "GL11.GL_CURRENT_RASTER_TEXTURE_COORDS");
setup(2823, "GL11.GL_CURRENT_RASTER_POSITION");
setup(2824, "GL11.GL_CURRENT_RASTER_POSITION_VALID");
setup(2825, "GL11.GL_CURRENT_RASTER_DISTANCE");
setup(2832, "GL11.GL_POINT_SMOOTH");
setup(2833, "GL11.GL_POINT_SIZE");
setup(2834, "GL11.GL_POINT_SIZE_RANGE");
setup(2835, "GL11.GL_POINT_SIZE_GRANULARITY");
setup(2848, "GL11.GL_LINE_SMOOTH");
setup(2849, "GL11.GL_LINE_WIDTH");
setup(2850, "GL11.GL_LINE_WIDTH_RANGE");
setup(2851, "GL11.GL_LINE_WIDTH_GRANULARITY");
setup(2852, "GL11.GL_LINE_STIPPLE");
setup(2853, "GL11.GL_LINE_STIPPLE_PATTERN");
setup(2854, "GL11.GL_LINE_STIPPLE_REPEAT");
setup(2864, "GL11.GL_LIST_MODE");
setup(2865, "GL11.GL_MAX_LIST_NESTING");
setup(2866, "GL11.GL_LIST_BASE");
setup(2867, "GL11.GL_LIST_INDEX");
setup(2880, "GL11.GL_POLYGON_MODE");
setup(2881, "GL11.GL_POLYGON_SMOOTH");
setup(2882, "GL11.GL_POLYGON_STIPPLE");
setup(2883, "GL11.GL_EDGE_FLAG");
setup(2884, "GL11.GL_CULL_FACE");
setup(2885, "GL11.GL_CULL_FACE_MODE");
setup(2886, "GL11.GL_FRONT_FACE");
setup(2896, "GL11.GL_LIGHTING");
setup(2897, "GL11.GL_LIGHT_MODEL_LOCAL_VIEWER");
setup(2898, "GL11.GL_LIGHT_MODEL_TWO_SIDE");
setup(2899, "GL11.GL_LIGHT_MODEL_AMBIENT");
setup(2900, "GL11.GL_SHADE_MODEL");
setup(2901, "GL11.GL_COLOR_MATERIAL_FACE");
setup(2902, "GL11.GL_COLOR_MATERIAL_PARAMETER");
setup(2903, "GL11.GL_COLOR_MATERIAL");
setup(2912, "GL11.GL_FOG");
setup(2913, "GL11.GL_FOG_INDEX");
setup(2914, "GL11.GL_FOG_DENSITY");
setup(2915, "GL11.GL_FOG_START");
setup(2916, "GL11.GL_FOG_END");
setup(2917, "GL11.GL_FOG_MODE");
setup(2918, "GL11.GL_FOG_COLOR");
setup(2928, "GL11.GL_DEPTH_RANGE");
setup(2929, "GL11.GL_DEPTH_TEST");
setup(2930, "GL11.GL_DEPTH_WRITEMASK");
setup(2931, "GL11.GL_DEPTH_CLEAR_VALUE");
setup(2932, "GL11.GL_DEPTH_FUNC");
setup(2944, "GL11.GL_ACCUM_CLEAR_VALUE");
setup(2960, "GL11.GL_STENCIL_TEST");
setup(2961, "GL11.GL_STENCIL_CLEAR_VALUE");
setup(2962, "GL11.GL_STENCIL_FUNC");
setup(2963, "GL11.GL_STENCIL_VALUE_MASK");
setup(2964, "GL11.GL_STENCIL_FAIL");
setup(2965, "GL11.GL_STENCIL_PASS_DEPTH_FAIL");
setup(2966, "GL11.GL_STENCIL_PASS_DEPTH_PASS");
setup(2967, "GL11.GL_STENCIL_REF");
setup(2968, "GL11.GL_STENCIL_WRITEMASK");
setup(2976, "GL11.GL_MATRIX_MODE");
setup(2977, "GL11.GL_NORMALIZE");
setup(2978, "GL11.GL_VIEWPORT");
setup(2979, "GL11.GL_MODELVIEW_STACK_DEPTH");
setup(2980, "GL11.GL_PROJECTION_STACK_DEPTH");
setup(2981, "GL11.GL_TEXTURE_STACK_DEPTH");
setup(2982, "GL11.GL_MODELVIEW_MATRIX");
setup(2983, "GL11.GL_PROJECTION_MATRIX");
setup(2984, "GL11.GL_TEXTURE_MATRIX");
setup(2992, "GL11.GL_ATTRIB_STACK_DEPTH");
setup(2993, "GL11.GL_CLIENT_ATTRIB_STACK_DEPTH");
setup(3008, "GL11.GL_ALPHA_TEST");
setup(3009, "GL11.GL_ALPHA_TEST_FUNC");
setup(3010, "GL11.GL_ALPHA_TEST_REF");
setup(3024, "GL11.GL_DITHER");
setup(3040, "GL11.GL_BLEND_DST");
setup(3041, "GL11.GL_BLEND_SRC");
setup(3042, "GL11.GL_BLEND");
setup(3056, "GL11.GL_LOGIC_OP_MODE");
setup(3057, "GL11.GL_INDEX_LOGIC_OP");
setup(3058, "GL11.GL_COLOR_LOGIC_OP");
setup(3072, "GL11.GL_AUX_BUFFERS");
setup(3073, "GL11.GL_DRAW_BUFFER");
setup(3074, "GL11.GL_READ_BUFFER");
setup(3088, "GL11.GL_SCISSOR_BOX");
setup(3089, "GL11.GL_SCISSOR_TEST");
setup(3104, "GL11.GL_INDEX_CLEAR_VALUE");
setup(3105, "GL11.GL_INDEX_WRITEMASK");
setup(3106, "GL11.GL_COLOR_CLEAR_VALUE");
setup(3107, "GL11.GL_COLOR_WRITEMASK");
setup(3120, "GL11.GL_INDEX_MODE");
setup(3121, "GL11.GL_RGBA_MODE");
setup(3122, "GL11.GL_DOUBLEBUFFER");
setup(3123, "GL11.GL_STEREO");
setup(3136, "GL11.GL_RENDER_MODE");
setup(3152, "GL11.GL_PERSPECTIVE_CORRECTION_HINT");
setup(3153, "GL11.GL_POINT_SMOOTH_HINT");
setup(3154, "GL11.GL_LINE_SMOOTH_HINT");
setup(3155, "GL11.GL_POLYGON_SMOOTH_HINT");
setup(3156, "GL11.GL_FOG_HINT");
setup(3168, "GL11.GL_TEXTURE_GEN_S");
setup(3169, "GL11.GL_TEXTURE_GEN_T");
setup(3170, "GL11.GL_TEXTURE_GEN_R");
setup(3171, "GL11.GL_TEXTURE_GEN_Q");
setup(3184, "GL11.GL_PIXEL_MAP_I_TO_I");
setup(3185, "GL11.GL_PIXEL_MAP_S_TO_S");
setup(3186, "GL11.GL_PIXEL_MAP_I_TO_R");
setup(3187, "GL11.GL_PIXEL_MAP_I_TO_G");
setup(3188, "GL11.GL_PIXEL_MAP_I_TO_B");
setup(3189, "GL11.GL_PIXEL_MAP_I_TO_A");
setup(3190, "GL11.GL_PIXEL_MAP_R_TO_R");
setup(3191, "GL11.GL_PIXEL_MAP_G_TO_G");
setup(3192, "GL11.GL_PIXEL_MAP_B_TO_B");
setup(3193, "GL11.GL_PIXEL_MAP_A_TO_A");
setup(3248, "GL11.GL_PIXEL_MAP_I_TO_I_SIZE");
setup(3249, "GL11.GL_PIXEL_MAP_S_TO_S_SIZE");
setup(3250, "GL11.GL_PIXEL_MAP_I_TO_R_SIZE");
setup(3251, "GL11.GL_PIXEL_MAP_I_TO_G_SIZE");
setup(3252, "GL11.GL_PIXEL_MAP_I_TO_B_SIZE");
setup(3253, "GL11.GL_PIXEL_MAP_I_TO_A_SIZE");
setup(3254, "GL11.GL_PIXEL_MAP_R_TO_R_SIZE");
setup(3255, "GL11.GL_PIXEL_MAP_G_TO_G_SIZE");
setup(3256, "GL11.GL_PIXEL_MAP_B_TO_B_SIZE");
setup(3257, "GL11.GL_PIXEL_MAP_A_TO_A_SIZE");
setup(3312, "GL11.GL_UNPACK_SWAP_BYTES");
setup(3313, "GL11.GL_UNPACK_LSB_FIRST");
setup(3314, "GL11.GL_UNPACK_ROW_LENGTH");
setup(3315, "GL11.GL_UNPACK_SKIP_ROWS");
setup(3316, "GL11.GL_UNPACK_SKIP_PIXELS");
setup(3317, "GL11.GL_UNPACK_ALIGNMENT");
setup(3328, "GL11.GL_PACK_SWAP_BYTES");
setup(3329, "GL11.GL_PACK_LSB_FIRST");
setup(3330, "GL11.GL_PACK_ROW_LENGTH");
setup(3331, "GL11.GL_PACK_SKIP_ROWS");
setup(3332, "GL11.GL_PACK_SKIP_PIXELS");
setup(3333, "GL11.GL_PACK_ALIGNMENT");
setup(3344, "GL11.GL_MAP_COLOR");
setup(3345, "GL11.GL_MAP_STENCIL");
setup(3346, "GL11.GL_INDEX_SHIFT");
setup(3347, "GL11.GL_INDEX_OFFSET");
setup(3348, "GL11.GL_RED_SCALE");
setup(3349, "GL11.GL_RED_BIAS");
setup(3350, "GL11.GL_ZOOM_X");
setup(3351, "GL11.GL_ZOOM_Y");
setup(3352, "GL11.GL_GREEN_SCALE");
setup(3353, "GL11.GL_GREEN_BIAS");
setup(3354, "GL11.GL_BLUE_SCALE");
setup(3355, "GL11.GL_BLUE_BIAS");
setup(3356, "GL11.GL_ALPHA_SCALE");
setup(3357, "GL11.GL_ALPHA_BIAS");
setup(3358, "GL11.GL_DEPTH_SCALE");
setup(3359, "GL11.GL_DEPTH_BIAS");
setup(3376, "GL11.GL_MAX_EVAL_ORDER");
setup(3377, "GL11.GL_MAX_LIGHTS");
setup(3378, "GL11.GL_MAX_CLIP_PLANES");
setup(3379, "GL11.GL_MAX_TEXTURE_SIZE");
setup(3380, "GL11.GL_MAX_PIXEL_MAP_TABLE");
setup(3381, "GL11.GL_MAX_ATTRIB_STACK_DEPTH");
setup(3382, "GL11.GL_MAX_MODELVIEW_STACK_DEPTH");
setup(3383, "GL11.GL_MAX_NAME_STACK_DEPTH");
setup(3384, "GL11.GL_MAX_PROJECTION_STACK_DEPTH");
setup(3385, "GL11.GL_MAX_TEXTURE_STACK_DEPTH");
setup(3386, "GL11.GL_MAX_VIEWPORT_DIMS");
setup(3387, "GL11.GL_MAX_CLIENT_ATTRIB_STACK_DEPTH");
setup(3408, "GL11.GL_SUBPIXEL_BITS");
setup(3409, "GL11.GL_INDEX_BITS");
setup(3410, "GL11.GL_RED_BITS");
setup(3411, "GL11.GL_GREEN_BITS");
setup(3412, "GL11.GL_BLUE_BITS");
setup(3413, "GL11.GL_ALPHA_BITS");
setup(3414, "GL11.GL_DEPTH_BITS");
setup(3415, "GL11.GL_STENCIL_BITS");
setup(3416, "GL11.GL_ACCUM_RED_BITS");
setup(3417, "GL11.GL_ACCUM_GREEN_BITS");
setup(3418, "GL11.GL_ACCUM_BLUE_BITS");
setup(3419, "GL11.GL_ACCUM_ALPHA_BITS");
setup(3440, "GL11.GL_NAME_STACK_DEPTH");
setup(3456, "GL11.GL_AUTO_NORMAL");
setup(3472, "GL11.GL_MAP1_COLOR_4");
setup(3473, "GL11.GL_MAP1_INDEX");
setup(3474, "GL11.GL_MAP1_NORMAL");
setup(3475, "GL11.GL_MAP1_TEXTURE_COORD_1");
setup(3476, "GL11.GL_MAP1_TEXTURE_COORD_2");
setup(3477, "GL11.GL_MAP1_TEXTURE_COORD_3");
setup(3478, "GL11.GL_MAP1_TEXTURE_COORD_4");
setup(3479, "GL11.GL_MAP1_VERTEX_3");
setup(3480, "GL11.GL_MAP1_VERTEX_4");
setup(3504, "GL11.GL_MAP2_COLOR_4");
setup(3505, "GL11.GL_MAP2_INDEX");
setup(3506, "GL11.GL_MAP2_NORMAL");
setup(3507, "GL11.GL_MAP2_TEXTURE_COORD_1");
setup(3508, "GL11.GL_MAP2_TEXTURE_COORD_2");
setup(3509, "GL11.GL_MAP2_TEXTURE_COORD_3");
setup(3510, "GL11.GL_MAP2_TEXTURE_COORD_4");
setup(3511, "GL11.GL_MAP2_VERTEX_3");
setup(3512, "GL11.GL_MAP2_VERTEX_4");
setup(3536, "GL11.GL_MAP1_GRID_DOMAIN");
setup(3537, "GL11.GL_MAP1_GRID_SEGMENTS");
setup(3538, "GL11.GL_MAP2_GRID_DOMAIN");
setup(3539, "GL11.GL_MAP2_GRID_SEGMENTS");
setup(3552, "GL11.GL_TEXTURE_1D");
setup(3553, "GL11.GL_TEXTURE_2D");
setup(3568, "GL11.GL_FEEDBACK_BUFFER_POINTER");
setup(3569, "GL11.GL_FEEDBACK_BUFFER_SIZE");
setup(3570, "GL11.GL_FEEDBACK_BUFFER_TYPE");
setup(3571, "GL11.GL_SELECTION_BUFFER_POINTER");
setup(3572, "GL11.GL_SELECTION_BUFFER_SIZE");
setup(4096, "GL11.GL_TEXTURE_WIDTH");
setup(4097, "GL11.GL_TEXTURE_HEIGHT");
setup(4099, "GL11.GL_TEXTURE_INTERNAL_FORMAT");
setup(4100, "GL11.GL_TEXTURE_BORDER_COLOR");
setup(4101, "GL11.GL_TEXTURE_BORDER");
setup(4352, "GL11.GL_DONT_CARE");
setup(4353, "GL11.GL_FASTEST");
setup(4354, "GL11.GL_NICEST");
setup(16384, "GL11.GL_LIGHT0");
setup(16385, "GL11.GL_LIGHT1");
setup(16386, "GL11.GL_LIGHT2");
setup(16387, "GL11.GL_LIGHT3");
setup(16388, "GL11.GL_LIGHT4");
setup(16389, "GL11.GL_LIGHT5");
setup(16390, "GL11.GL_LIGHT6");
setup(16391, "GL11.GL_LIGHT7");
setup(4608, "GL11.GL_AMBIENT");
setup(4609, "GL11.GL_DIFFUSE");
setup(4610, "GL11.GL_SPECULAR");
setup(4611, "GL11.GL_POSITION");
setup(4612, "GL11.GL_SPOT_DIRECTION");
setup(4613, "GL11.GL_SPOT_EXPONENT");
setup(4614, "GL11.GL_SPOT_CUTOFF");
setup(4615, "GL11.GL_CONSTANT_ATTENUATION");
setup(4616, "GL11.GL_LINEAR_ATTENUATION");
setup(4617, "GL11.GL_QUADRATIC_ATTENUATION");
setup(4864, "GL11.GL_COMPILE");
setup(4865, "GL11.GL_COMPILE_AND_EXECUTE");
setup(5376, "GL11.GL_CLEAR");
setup(5377, "GL11.GL_AND");
setup(5378, "GL11.GL_AND_REVERSE");
setup(5379, "GL11.GL_COPY");
setup(5380, "GL11.GL_AND_INVERTED");
setup(5381, "GL11.GL_NOOP");
setup(5382, "GL11.GL_XOR");
setup(5383, "GL11.GL_OR");
setup(5384, "GL11.GL_NOR");
setup(5385, "GL11.GL_EQUIV");
setup(5386, "GL11.GL_INVERT");
setup(5387, "GL11.GL_OR_REVERSE");
setup(5388, "GL11.GL_COPY_INVERTED");
setup(5389, "GL11.GL_OR_INVERTED");
setup(5390, "GL11.GL_NAND");
setup(5391, "GL11.GL_SET");
setup(5632, "GL11.GL_EMISSION");
setup(5633, "GL11.GL_SHININESS");
setup(5634, "GL11.GL_AMBIENT_AND_DIFFUSE");
setup(5635, "GL11.GL_COLOR_INDEXES");
setup(5888, "GL11.GL_MODELVIEW");
setup(5889, "GL11.GL_PROJECTION");
setup(5890, "GL11.GL_TEXTURE");
setup(6144, "GL11.GL_COLOR");
setup(6145, "GL11.GL_DEPTH");
setup(6146, "GL11.GL_STENCIL");
setup(6400, "GL11.GL_COLOR_INDEX");
setup(6401, "GL11.GL_STENCIL_INDEX");
setup(6402, "GL11.GL_DEPTH_COMPONENT");
setup(6403, "GL11.GL_RED");
setup(6404, "GL11.GL_GREEN");
setup(6405, "GL11.GL_BLUE");
setup(6406, "GL11.GL_ALPHA");
setup(6407, "GL11.GL_RGB");
setup(6408, "GL11.GL_RGBA");
setup(6409, "GL11.GL_LUMINANCE");
setup(6410, "GL11.GL_LUMINANCE_ALPHA");
setup(6656, "GL11.GL_BITMAP");
setup(6912, "GL11.GL_POINT");
setup(6913, "GL11.GL_LINE");
setup(6914, "GL11.GL_FILL");
setup(7168, "GL11.GL_RENDER");
setup(7169, "GL11.GL_FEEDBACK");
setup(7170, "GL11.GL_SELECT");
setup(7424, "GL11.GL_FLAT");
setup(7425, "GL11.GL_SMOOTH");
setup(7680, "GL11.GL_KEEP");
setup(7681, "GL11.GL_REPLACE");
setup(7682, "GL11.GL_INCR");
setup(7683, "GL11.GL_DECR");
setup(7936, "GL11.GL_VENDOR");
setup(7937, "GL11.GL_RENDERER");
setup(7938, "GL11.GL_VERSION");
setup(7939, "GL11.GL_EXTENSIONS");
setup(8192, "GL11.GL_S");
setup(8193, "GL11.GL_T");
setup(8194, "GL11.GL_R");
setup(8195, "GL11.GL_Q");
setup(8448, "GL11.GL_MODULATE");
setup(8449, "GL11.GL_DECAL");
setup(8704, "GL11.GL_TEXTURE_ENV_MODE");
setup(8705, "GL11.GL_TEXTURE_ENV_COLOR");
setup(8960, "GL11.GL_TEXTURE_ENV");
setup(9216, "GL11.GL_EYE_LINEAR");
setup(9217, "GL11.GL_OBJECT_LINEAR");
setup(9218, "GL11.GL_SPHERE_MAP");
setup(9472, "GL11.GL_TEXTURE_GEN_MODE");
setup(9473, "GL11.GL_OBJECT_PLANE");
setup(9474, "GL11.GL_EYE_PLANE");
setup(9728, "GL11.GL_NEAREST");
setup(9729, "GL11.GL_LINEAR");
setup(9984, "GL11.GL_NEAREST_MIPMAP_NEAREST");
setup(9985, "GL11.GL_LINEAR_MIPMAP_NEAREST");
setup(9986, "GL11.GL_NEAREST_MIPMAP_LINEAR");
setup(9987, "GL11.GL_LINEAR_MIPMAP_LINEAR");
setup(10240, "GL11.GL_TEXTURE_MAG_FILTER");
setup(10241, "GL11.GL_TEXTURE_MIN_FILTER");
setup(10242, "GL11.GL_TEXTURE_WRAP_S");
setup(10243, "GL11.GL_TEXTURE_WRAP_T");
setup(10496, "GL11.GL_CLAMP");
setup(10497, "GL11.GL_REPEAT");
setup(-1, "GL11.GL_ALL_CLIENT_ATTRIB_BITS");
setup(32824, "GL11.GL_POLYGON_OFFSET_FACTOR");
setup(10752, "GL11.GL_POLYGON_OFFSET_UNITS");
setup(10753, "GL11.GL_POLYGON_OFFSET_POINT");
setup(10754, "GL11.GL_POLYGON_OFFSET_LINE");
setup(32823, "GL11.GL_POLYGON_OFFSET_FILL");
setup(32827, "GL11.GL_ALPHA4");
setup(32828, "GL11.GL_ALPHA8");
setup(32829, "GL11.GL_ALPHA12");
setup(32830, "GL11.GL_ALPHA16");
setup(32831, "GL11.GL_LUMINANCE4");
setup(32832, "GL11.GL_LUMINANCE8");
setup(32833, "GL11.GL_LUMINANCE12");
setup(32834, "GL11.GL_LUMINANCE16");
setup(32835, "GL11.GL_LUMINANCE4_ALPHA4");
setup(32836, "GL11.GL_LUMINANCE6_ALPHA2");
setup(32837, "GL11.GL_LUMINANCE8_ALPHA8");
setup(32838, "GL11.GL_LUMINANCE12_ALPHA4");
setup(32839, "GL11.GL_LUMINANCE12_ALPHA12");
setup(32840, "GL11.GL_LUMINANCE16_ALPHA16");
setup(32841, "GL11.GL_INTENSITY");
setup(32842, "GL11.GL_INTENSITY4");
setup(32843, "GL11.GL_INTENSITY8");
setup(32844, "GL11.GL_INTENSITY12");
setup(32845, "GL11.GL_INTENSITY16");
setup(10768, "GL11.GL_R3_G3_B2");
setup(32847, "GL11.GL_RGB4");
setup(32848, "GL11.GL_RGB5");
setup(32849, "GL11.GL_RGB8");
setup(32850, "GL11.GL_RGB10");
setup(32851, "GL11.GL_RGB12");
setup(32852, "GL11.GL_RGB16");
setup(32853, "GL11.GL_RGBA2");
setup(32854, "GL11.GL_RGBA4");
setup(32855, "GL11.GL_RGB5_A1");
setup(32856, "GL11.GL_RGBA8");
setup(32857, "GL11.GL_RGB10_A2");
setup(32858, "GL11.GL_RGBA12");
setup(32859, "GL11.GL_RGBA16");
setup(32860, "GL11.GL_TEXTURE_RED_SIZE");
setup(32861, "GL11.GL_TEXTURE_GREEN_SIZE");
setup(32862, "GL11.GL_TEXTURE_BLUE_SIZE");
setup(32863, "GL11.GL_TEXTURE_ALPHA_SIZE");
setup(32864, "GL11.GL_TEXTURE_LUMINANCE_SIZE");
setup(32865, "GL11.GL_TEXTURE_INTENSITY_SIZE");
setup(32867, "GL11.GL_PROXY_TEXTURE_1D");
setup(32868, "GL11.GL_PROXY_TEXTURE_2D");
setup(32870, "GL11.GL_TEXTURE_PRIORITY");
setup(32871, "GL11.GL_TEXTURE_RESIDENT");
setup(32872, "GL11.GL_TEXTURE_BINDING_1D");
setup(32873, "GL11.GL_TEXTURE_BINDING_2D");
setup(32884, "GL11.GL_VERTEX_ARRAY");
setup(32885, "GL11.GL_NORMAL_ARRAY");
setup(32886, "GL11.GL_COLOR_ARRAY");
setup(32887, "GL11.GL_INDEX_ARRAY");
setup(32888, "GL11.GL_TEXTURE_COORD_ARRAY");
setup(32889, "GL11.GL_EDGE_FLAG_ARRAY");
setup(32890, "GL11.GL_VERTEX_ARRAY_SIZE");
setup(32891, "GL11.GL_VERTEX_ARRAY_TYPE");
setup(32892, "GL11.GL_VERTEX_ARRAY_STRIDE");
setup(32894, "GL11.GL_NORMAL_ARRAY_TYPE");
setup(32895, "GL11.GL_NORMAL_ARRAY_STRIDE");
setup(32897, "GL11.GL_COLOR_ARRAY_SIZE");
setup(32898, "GL11.GL_COLOR_ARRAY_TYPE");
setup(32899, "GL11.GL_COLOR_ARRAY_STRIDE");
setup(32901, "GL11.GL_INDEX_ARRAY_TYPE");
setup(32902, "GL11.GL_INDEX_ARRAY_STRIDE");
setup(32904, "GL11.GL_TEXTURE_COORD_ARRAY_SIZE");
setup(32905, "GL11.GL_TEXTURE_COORD_ARRAY_TYPE");
setup(32906, "GL11.GL_TEXTURE_COORD_ARRAY_STRIDE");
setup(32908, "GL11.GL_EDGE_FLAG_ARRAY_STRIDE");
setup(32910, "GL11.GL_VERTEX_ARRAY_POINTER");
setup(32911, "GL11.GL_NORMAL_ARRAY_POINTER");
setup(32912, "GL11.GL_COLOR_ARRAY_POINTER");
setup(32913, "GL11.GL_INDEX_ARRAY_POINTER");
setup(32914, "GL11.GL_TEXTURE_COORD_ARRAY_POINTER");
setup(32915, "GL11.GL_EDGE_FLAG_ARRAY_POINTER");
setup(10784, "GL11.GL_V2F");
setup(10785, "GL11.GL_V3F");
setup(10786, "GL11.GL_C4UB_V2F");
setup(10787, "GL11.GL_C4UB_V3F");
setup(10788, "GL11.GL_C3F_V3F");
setup(10789, "GL11.GL_N3F_V3F");
setup(10790, "GL11.GL_C4F_N3F_V3F");
setup(10791, "GL11.GL_T2F_V3F");
setup(10792, "GL11.GL_T4F_V4F");
setup(10793, "GL11.GL_T2F_C4UB_V3F");
setup(10794, "GL11.GL_T2F_C3F_V3F");
setup(10795, "GL11.GL_T2F_N3F_V3F");
setup(10796, "GL11.GL_T2F_C4F_N3F_V3F");
setup(10797, "GL11.GL_T4F_C4F_N3F_V4F");
setup(3057, "GL11.GL_LOGIC_OP");
setup(4099, "GL11.GL_TEXTURE_COMPONENTS");
setup(32874, "GL12.GL_TEXTURE_BINDING_3D");
setup(32875, "GL12.GL_PACK_SKIP_IMAGES");
setup(32876, "GL12.GL_PACK_IMAGE_HEIGHT");
setup(32877, "GL12.GL_UNPACK_SKIP_IMAGES");
setup(32878, "GL12.GL_UNPACK_IMAGE_HEIGHT");
setup(32879, "GL12.GL_TEXTURE_3D");
setup(32880, "GL12.GL_PROXY_TEXTURE_3D");
setup(32881, "GL12.GL_TEXTURE_DEPTH");
setup(32882, "GL12.GL_TEXTURE_WRAP_R");
setup(32883, "GL12.GL_MAX_3D_TEXTURE_SIZE");
setup(32992, "GL12.GL_BGR");
setup(32993, "GL12.GL_BGRA");
setup(32818, "GL12.GL_UNSIGNED_BYTE_3_3_2");
setup(33634, "GL12.GL_UNSIGNED_BYTE_2_3_3_REV");
setup(33635, "GL12.GL_UNSIGNED_SHORT_5_6_5");
setup(33636, "GL12.GL_UNSIGNED_SHORT_5_6_5_REV");
setup(32819, "GL12.GL_UNSIGNED_SHORT_4_4_4_4");
setup(33637, "GL12.GL_UNSIGNED_SHORT_4_4_4_4_REV");
setup(32820, "GL12.GL_UNSIGNED_SHORT_5_5_5_1");
setup(33638, "GL12.GL_UNSIGNED_SHORT_1_5_5_5_REV");
setup(32821, "GL12.GL_UNSIGNED_INT_8_8_8_8");
setup(33639, "GL12.GL_UNSIGNED_INT_8_8_8_8_REV");
setup(32822, "GL12.GL_UNSIGNED_INT_10_10_10_2");
setup(33640, "GL12.GL_UNSIGNED_INT_2_10_10_10_REV");
setup(32826, "GL12.GL_RESCALE_NORMAL");
setup(33272, "GL12.GL_LIGHT_MODEL_COLOR_CONTROL");
setup(33273, "GL12.GL_SINGLE_COLOR");
setup(33274, "GL12.GL_SEPARATE_SPECULAR_COLOR");
setup(33071, "GL12.GL_CLAMP_TO_EDGE");
setup(33082, "GL12.GL_TEXTURE_MIN_LOD");
setup(33083, "GL12.GL_TEXTURE_MAX_LOD");
setup(33084, "GL12.GL_TEXTURE_BASE_LEVEL");
setup(33085, "GL12.GL_TEXTURE_MAX_LEVEL");
setup(33000, "GL12.GL_MAX_ELEMENTS_VERTICES");
setup(33001, "GL12.GL_MAX_ELEMENTS_INDICES");
setup(33901, "GL12.GL_ALIASED_POINT_SIZE_RANGE");
setup(33902, "GL12.GL_ALIASED_LINE_WIDTH_RANGE");
setup(33984, "GL13.GL_TEXTURE0");
setup(33985, "GL13.GL_TEXTURE1");
setup(33986, "GL13.GL_TEXTURE2");
setup(33987, "GL13.GL_TEXTURE3");
setup(33988, "GL13.GL_TEXTURE4");
setup(33989, "GL13.GL_TEXTURE5");
setup(33990, "GL13.GL_TEXTURE6");
setup(33991, "GL13.GL_TEXTURE7");
setup(33992, "GL13.GL_TEXTURE8");
setup(33993, "GL13.GL_TEXTURE9");
setup(33994, "GL13.GL_TEXTURE10");
setup(33995, "GL13.GL_TEXTURE11");
setup(33996, "GL13.GL_TEXTURE12");
setup(33997, "GL13.GL_TEXTURE13");
setup(33998, "GL13.GL_TEXTURE14");
setup(33999, "GL13.GL_TEXTURE15");
setup(34000, "GL13.GL_TEXTURE16");
setup(34001, "GL13.GL_TEXTURE17");
setup(34002, "GL13.GL_TEXTURE18");
setup(34003, "GL13.GL_TEXTURE19");
setup(34004, "GL13.GL_TEXTURE20");
setup(34005, "GL13.GL_TEXTURE21");
setup(34006, "GL13.GL_TEXTURE22");
setup(34007, "GL13.GL_TEXTURE23");
setup(34008, "GL13.GL_TEXTURE24");
setup(34009, "GL13.GL_TEXTURE25");
setup(34010, "GL13.GL_TEXTURE26");
setup(34011, "GL13.GL_TEXTURE27");
setup(34012, "GL13.GL_TEXTURE28");
setup(34013, "GL13.GL_TEXTURE29");
setup(34014, "GL13.GL_TEXTURE30");
setup(34015, "GL13.GL_TEXTURE31");
setup(34016, "GL13.GL_ACTIVE_TEXTURE");
setup(34017, "GL13.GL_CLIENT_ACTIVE_TEXTURE");
setup(34018, "GL13.GL_MAX_TEXTURE_UNITS");
setup(34065, "GL13.GL_NORMAL_MAP");
setup(34066, "GL13.GL_REFLECTION_MAP");
setup(34067, "GL13.GL_TEXTURE_CUBE_MAP");
setup(34068, "GL13.GL_TEXTURE_BINDING_CUBE_MAP");
setup(34069, "GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X");
setup(34070, "GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_X");
setup(34071, "GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Y");
setup(34072, "GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y");
setup(34073, "GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Z");
setup(34074, "GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z");
setup(34075, "GL13.GL_PROXY_TEXTURE_CUBE_MAP");
setup(34076, "GL13.GL_MAX_CUBE_MAP_TEXTURE_SIZE");
setup(34025, "GL13.GL_COMPRESSED_ALPHA");
setup(34026, "GL13.GL_COMPRESSED_LUMINANCE");
setup(34027, "GL13.GL_COMPRESSED_LUMINANCE_ALPHA");
setup(34028, "GL13.GL_COMPRESSED_INTENSITY");
setup(34029, "GL13.GL_COMPRESSED_RGB");
setup(34030, "GL13.GL_COMPRESSED_RGBA");
setup(34031, "GL13.GL_TEXTURE_COMPRESSION_HINT");
setup(34464, "GL13.GL_TEXTURE_COMPRESSED_IMAGE_SIZE");
setup(34465, "GL13.GL_TEXTURE_COMPRESSED");
setup(34466, "GL13.GL_NUM_COMPRESSED_TEXTURE_FORMATS");
setup(34467, "GL13.GL_COMPRESSED_TEXTURE_FORMATS");
setup(32925, "GL13.GL_MULTISAMPLE");
setup(32926, "GL13.GL_SAMPLE_ALPHA_TO_COVERAGE");
setup(32927, "GL13.GL_SAMPLE_ALPHA_TO_ONE");
setup(32928, "GL13.GL_SAMPLE_COVERAGE");
setup(32936, "GL13.GL_SAMPLE_BUFFERS");
setup(32937, "GL13.GL_SAMPLES");
setup(32938, "GL13.GL_SAMPLE_COVERAGE_VALUE");
setup(32939, "GL13.GL_SAMPLE_COVERAGE_INVERT");
setup(34019, "GL13.GL_TRANSPOSE_MODELVIEW_MATRIX");
setup(34020, "GL13.GL_TRANSPOSE_PROJECTION_MATRIX");
setup(34021, "GL13.GL_TRANSPOSE_TEXTURE_MATRIX");
setup(34022, "GL13.GL_TRANSPOSE_COLOR_MATRIX");
setup(34160, "GL13.GL_COMBINE");
setup(34161, "GL13.GL_COMBINE_RGB");
setup(34162, "GL13.GL_COMBINE_ALPHA");
setup(34176, "GL13.GL_SOURCE0_RGB");
setup(34177, "GL13.GL_SOURCE1_RGB");
setup(34178, "GL13.GL_SOURCE2_RGB");
setup(34184, "GL13.GL_SOURCE0_ALPHA");
setup(34185, "GL13.GL_SOURCE1_ALPHA");
setup(34186, "GL13.GL_SOURCE2_ALPHA");
setup(34192, "GL13.GL_OPERAND0_RGB");
setup(34193, "GL13.GL_OPERAND1_RGB");
setup(34194, "GL13.GL_OPERAND2_RGB");
setup(34200, "GL13.GL_OPERAND0_ALPHA");
setup(34201, "GL13.GL_OPERAND1_ALPHA");
setup(34202, "GL13.GL_OPERAND2_ALPHA");
setup(34163, "GL13.GL_RGB_SCALE");
setup(34164, "GL13.GL_ADD_SIGNED");
setup(34165, "GL13.GL_INTERPOLATE");
setup(34023, "GL13.GL_SUBTRACT");
setup(34166, "GL13.GL_CONSTANT");
setup(34167, "GL13.GL_PRIMARY_COLOR");
setup(34168, "GL13.GL_PREVIOUS");
setup(34478, "GL13.GL_DOT3_RGB");
setup(34479, "GL13.GL_DOT3_RGBA");
setup(33069, "GL13.GL_CLAMP_TO_BORDER");
setup(33169, "GL14.GL_GENERATE_MIPMAP");
setup(33170, "GL14.GL_GENERATE_MIPMAP_HINT");
setup(33189, "GL14.GL_DEPTH_COMPONENT16");
setup(33190, "GL14.GL_DEPTH_COMPONENT24");
setup(33191, "GL14.GL_DEPTH_COMPONENT32");
setup(34890, "GL14.GL_TEXTURE_DEPTH_SIZE");
setup(34891, "GL14.GL_DEPTH_TEXTURE_MODE");
setup(34892, "GL14.GL_TEXTURE_COMPARE_MODE");
setup(34893, "GL14.GL_TEXTURE_COMPARE_FUNC");
setup(34894, "GL14.GL_COMPARE_R_TO_TEXTURE");
setup(33872, "GL14.GL_FOG_COORDINATE_SOURCE");
setup(33873, "GL14.GL_FOG_COORDINATE");
setup(33874, "GL14.GL_FRAGMENT_DEPTH");
setup(33875, "GL14.GL_CURRENT_FOG_COORDINATE");
setup(33876, "GL14.GL_FOG_COORDINATE_ARRAY_TYPE");
setup(33877, "GL14.GL_FOG_COORDINATE_ARRAY_STRIDE");
setup(33878, "GL14.GL_FOG_COORDINATE_ARRAY_POINTER");
setup(33879, "GL14.GL_FOG_COORDINATE_ARRAY");
setup(33062, "GL14.GL_POINT_SIZE_MIN");
setup(33063, "GL14.GL_POINT_SIZE_MAX");
setup(33064, "GL14.GL_POINT_FADE_THRESHOLD_SIZE");
setup(33065, "GL14.GL_POINT_DISTANCE_ATTENUATION");
setup(33880, "GL14.GL_COLOR_SUM");
setup(33881, "GL14.GL_CURRENT_SECONDARY_COLOR");
setup(33882, "GL14.GL_SECONDARY_COLOR_ARRAY_SIZE");
setup(33883, "GL14.GL_SECONDARY_COLOR_ARRAY_TYPE");
setup(33884, "GL14.GL_SECONDARY_COLOR_ARRAY_STRIDE");
setup(33885, "GL14.GL_SECONDARY_COLOR_ARRAY_POINTER");
setup(33886, "GL14.GL_SECONDARY_COLOR_ARRAY");
setup(32968, "GL14.GL_BLEND_DST_RGB");
setup(32969, "GL14.GL_BLEND_SRC_RGB");
setup(32970, "GL14.GL_BLEND_DST_ALPHA");
setup(32971, "GL14.GL_BLEND_SRC_ALPHA");
setup(34055, "GL14.GL_INCR_WRAP");
setup(34056, "GL14.GL_DECR_WRAP");
setup(34048, "GL14.GL_TEXTURE_FILTER_CONTROL");
setup(34049, "GL14.GL_TEXTURE_LOD_BIAS");
setup(34045, "GL14.GL_MAX_TEXTURE_LOD_BIAS");
setup(33648, "GL14.GL_MIRRORED_REPEAT");
setup(32773, "ARBImaging.GL_BLEND_COLOR");
setup(32777, "ARBImaging.GL_BLEND_EQUATION");
setup(32774, "GL14.GL_FUNC_ADD");
setup(32778, "GL14.GL_FUNC_SUBTRACT");
setup(32779, "GL14.GL_FUNC_REVERSE_SUBTRACT");
setup(32775, "GL14.GL_MIN");
setup(32776, "GL14.GL_MAX");
setup(34962, "GL15.GL_ARRAY_BUFFER");
setup(34963, "GL15.GL_ELEMENT_ARRAY_BUFFER");
setup(34964, "GL15.GL_ARRAY_BUFFER_BINDING");
setup(34965, "GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING");
setup(34966, "GL15.GL_VERTEX_ARRAY_BUFFER_BINDING");
setup(34967, "GL15.GL_NORMAL_ARRAY_BUFFER_BINDING");
setup(34968, "GL15.GL_COLOR_ARRAY_BUFFER_BINDING");
setup(34969, "GL15.GL_INDEX_ARRAY_BUFFER_BINDING");
setup(34970, "GL15.GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING");
setup(34971, "GL15.GL_EDGE_FLAG_ARRAY_BUFFER_BINDING");
setup(34972, "GL15.GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING");
setup(34973, "GL15.GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING");
setup(34974, "GL15.GL_WEIGHT_ARRAY_BUFFER_BINDING");
setup(34975, "GL15.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING");
setup(35040, "GL15.GL_STREAM_DRAW");
setup(35041, "GL15.GL_STREAM_READ");
setup(35042, "GL15.GL_STREAM_COPY");
setup(35044, "GL15.GL_STATIC_DRAW");
setup(35045, "GL15.GL_STATIC_READ");
setup(35046, "GL15.GL_STATIC_COPY");
setup(35048, "GL15.GL_DYNAMIC_DRAW");
setup(35049, "GL15.GL_DYNAMIC_READ");
setup(35050, "GL15.GL_DYNAMIC_COPY");
setup(35000, "GL15.GL_READ_ONLY");
setup(35001, "GL15.GL_WRITE_ONLY");
setup(35002, "GL15.GL_READ_WRITE");
setup(34660, "GL15.GL_BUFFER_SIZE");
setup(34661, "GL15.GL_BUFFER_USAGE");
setup(35003, "GL15.GL_BUFFER_ACCESS");
setup(35004, "GL15.GL_BUFFER_MAPPED");
setup(35005, "GL15.GL_BUFFER_MAP_POINTER");
setup(34138, "NVFogDistance.GL_FOG_DISTANCE_MODE_NV");
setup(34139, "NVFogDistance.GL_EYE_RADIAL_NV");
setup(34140, "NVFogDistance.GL_EYE_PLANE_ABSOLUTE_NV");
SAVED_STATES = Maps.newHashMap();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,19 @@
package com.mojang.blaze3d.platform;
public class GlUtil {
public static String getVendor() {
return GlStateManager._getString(7936);
}
public static String getCpuInfo() {
return GLX._getCpuInfo();
}
public static String getRenderer() {
return GlStateManager._getString(7937);
}
public static String getOpenGLVersion() {
return GlStateManager._getString(7938);
}
}

View File

@ -0,0 +1,373 @@
package com.mojang.blaze3d.platform;
import com.google.common.collect.Maps;
import java.util.Objects;
import java.util.OptionalInt;
import java.util.Map;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.locale.Language;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.network.chat.Component;
import java.util.function.BiFunction;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import java.lang.invoke.MethodType;
import java.lang.invoke.MethodHandles;
import org.lwjgl.glfw.GLFWDropCallbackI;
import org.lwjgl.glfw.GLFWScrollCallbackI;
import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
import org.lwjgl.glfw.GLFWCursorPosCallbackI;
import org.lwjgl.glfw.GLFWCharModsCallbackI;
import org.lwjgl.glfw.GLFWKeyCallbackI;
import org.lwjgl.glfw.GLFW;
import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
public class InputConstants {
@Nullable
private static final MethodHandle glfwRawMouseMotionSupported;
private static final int GLFW_RAW_MOUSE_MOTION;
public static final Key UNKNOWN;
public static Key getKey(final int integer1, final int integer2) {
if (integer1 == -1) {
return Type.SCANCODE.getOrCreate(integer2);
}
return Type.KEYSYM.getOrCreate(integer1);
}
public static Key getKey(final String string) {
if (Key.NAME_MAP.containsKey(string)) {
return Key.NAME_MAP.get(string);
}
for (final Type b5 : Type.values()) {
if (string.startsWith(b5.defaultPrefix)) {
final String string2 = string.substring(b5.defaultPrefix.length() + 1);
return b5.getOrCreate(Integer.parseInt(string2));
}
}
throw new IllegalArgumentException("Unknown key name: " + string);
}
public static boolean isKeyDown(final long long1, final int integer) {
return GLFW.glfwGetKey(long1, integer) == 1;
}
public static void setupKeyboardCallbacks(final long long1, final GLFWKeyCallbackI gLFWKeyCallbackI, final GLFWCharModsCallbackI gLFWCharModsCallbackI) {
GLFW.glfwSetKeyCallback(long1, gLFWKeyCallbackI);
GLFW.glfwSetCharModsCallback(long1, gLFWCharModsCallbackI);
}
public static void setupMouseCallbacks(final long long1, final GLFWCursorPosCallbackI gLFWCursorPosCallbackI, final GLFWMouseButtonCallbackI gLFWMouseButtonCallbackI, final GLFWScrollCallbackI gLFWScrollCallbackI, final GLFWDropCallbackI gLFWDropCallbackI) {
GLFW.glfwSetCursorPosCallback(long1, gLFWCursorPosCallbackI);
GLFW.glfwSetMouseButtonCallback(long1, gLFWMouseButtonCallbackI);
GLFW.glfwSetScrollCallback(long1, gLFWScrollCallbackI);
GLFW.glfwSetDropCallback(long1, gLFWDropCallbackI);
}
public static void grabOrReleaseMouse(final long long1, final int integer, final double double3, final double double4) {
GLFW.glfwSetCursorPos(long1, double3, double4);
GLFW.glfwSetInputMode(long1, 208897, integer);
}
public static boolean isRawMouseInputSupported() {
try {
return InputConstants.glfwRawMouseMotionSupported != null && InputConstants.glfwRawMouseMotionSupported.invokeExact();
}
catch (Throwable throwable1) {
throw new RuntimeException(throwable1);
}
}
public static void updateRawMouseInput(final long long1, final boolean boolean2) {
if (isRawMouseInputSupported()) {
GLFW.glfwSetInputMode(long1, InputConstants.GLFW_RAW_MOUSE_MOTION, (int)(boolean2 ? 1 : 0));
}
}
static {
final MethodHandles.Lookup lookup1 = MethodHandles.lookup();
final MethodType methodType2 = MethodType.methodType(Boolean.TYPE);
MethodHandle methodHandle3 = null;
int integer4 = 0;
try {
methodHandle3 = lookup1.findStatic(GLFW.class, "glfwRawMouseMotionSupported", methodType2);
final MethodHandle methodHandle4 = lookup1.findStaticGetter(GLFW.class, "GLFW_RAW_MOUSE_MOTION", Integer.TYPE);
integer4 = methodHandle4.invokeExact();
}
catch (NoSuchMethodException | NoSuchFieldException ex) {}
catch (Throwable throwable5) {
throw new RuntimeException(throwable5);
}
glfwRawMouseMotionSupported = methodHandle3;
GLFW_RAW_MOUSE_MOTION = integer4;
UNKNOWN = Type.KEYSYM.getOrCreate(-1);
}
public enum Type {
KEYSYM("key.keyboard", (integer, string) -> {
string2 = GLFW.glfwGetKeyName((int)integer, -1);
if (string2 != null) {
// new(net.minecraft.network.chat.TextComponent.class)
new TextComponent(string2);
}
else {
// new(net.minecraft.network.chat.TranslatableComponent.class)
new TranslatableComponent(string);
}
return o3;
}),
SCANCODE("scancode", (integer, string) -> {
string3 = GLFW.glfwGetKeyName(-1, (int)integer);
if (string3 != null) {
// new(net.minecraft.network.chat.TextComponent.class)
new TextComponent(string3);
}
else {
// new(net.minecraft.network.chat.TranslatableComponent.class)
new TranslatableComponent(string);
}
return o6;
}),
MOUSE("key.mouse", (integer, string) -> {
if (Language.getInstance().has(string)) {
// new(net.minecraft.network.chat.TranslatableComponent.class)
new TranslatableComponent(string);
}
else {
// new(net.minecraft.network.chat.TranslatableComponent.class)
new TranslatableComponent("key.mouse", new Object[] { integer + 1 });
}
return o9;
});
private final Int2ObjectMap<Key> map;
private final String defaultPrefix;
private final BiFunction<Integer, String, Component> displayTextSupplier;
private static void addKey(final Type b, final String string, final int integer) {
final Key a4 = new Key(string, b, integer);
b.map.put(integer, a4);
}
private Type(final String string3, final BiFunction<Integer, String, Component> biFunction) {
this.map = (Int2ObjectMap<Key>)new Int2ObjectOpenHashMap();
this.defaultPrefix = string3;
this.displayTextSupplier = biFunction;
}
public Key getOrCreate(final int integer) {
int integer2;
final String string4;
return (Key)this.map.computeIfAbsent(integer, integer -> {
integer2 = integer;
if (this == Type.MOUSE) {
++integer2;
}
string4 = this.defaultPrefix + "." + integer2;
return new Key(string4, this, integer);
});
}
static {
addKey(Type.KEYSYM, "key.keyboard.unknown", -1);
addKey(Type.MOUSE, "key.mouse.left", 0);
addKey(Type.MOUSE, "key.mouse.right", 1);
addKey(Type.MOUSE, "key.mouse.middle", 2);
addKey(Type.MOUSE, "key.mouse.4", 3);
addKey(Type.MOUSE, "key.mouse.5", 4);
addKey(Type.MOUSE, "key.mouse.6", 5);
addKey(Type.MOUSE, "key.mouse.7", 6);
addKey(Type.MOUSE, "key.mouse.8", 7);
addKey(Type.KEYSYM, "key.keyboard.0", 48);
addKey(Type.KEYSYM, "key.keyboard.1", 49);
addKey(Type.KEYSYM, "key.keyboard.2", 50);
addKey(Type.KEYSYM, "key.keyboard.3", 51);
addKey(Type.KEYSYM, "key.keyboard.4", 52);
addKey(Type.KEYSYM, "key.keyboard.5", 53);
addKey(Type.KEYSYM, "key.keyboard.6", 54);
addKey(Type.KEYSYM, "key.keyboard.7", 55);
addKey(Type.KEYSYM, "key.keyboard.8", 56);
addKey(Type.KEYSYM, "key.keyboard.9", 57);
addKey(Type.KEYSYM, "key.keyboard.a", 65);
addKey(Type.KEYSYM, "key.keyboard.b", 66);
addKey(Type.KEYSYM, "key.keyboard.c", 67);
addKey(Type.KEYSYM, "key.keyboard.d", 68);
addKey(Type.KEYSYM, "key.keyboard.e", 69);
addKey(Type.KEYSYM, "key.keyboard.f", 70);
addKey(Type.KEYSYM, "key.keyboard.g", 71);
addKey(Type.KEYSYM, "key.keyboard.h", 72);
addKey(Type.KEYSYM, "key.keyboard.i", 73);
addKey(Type.KEYSYM, "key.keyboard.j", 74);
addKey(Type.KEYSYM, "key.keyboard.k", 75);
addKey(Type.KEYSYM, "key.keyboard.l", 76);
addKey(Type.KEYSYM, "key.keyboard.m", 77);
addKey(Type.KEYSYM, "key.keyboard.n", 78);
addKey(Type.KEYSYM, "key.keyboard.o", 79);
addKey(Type.KEYSYM, "key.keyboard.p", 80);
addKey(Type.KEYSYM, "key.keyboard.q", 81);
addKey(Type.KEYSYM, "key.keyboard.r", 82);
addKey(Type.KEYSYM, "key.keyboard.s", 83);
addKey(Type.KEYSYM, "key.keyboard.t", 84);
addKey(Type.KEYSYM, "key.keyboard.u", 85);
addKey(Type.KEYSYM, "key.keyboard.v", 86);
addKey(Type.KEYSYM, "key.keyboard.w", 87);
addKey(Type.KEYSYM, "key.keyboard.x", 88);
addKey(Type.KEYSYM, "key.keyboard.y", 89);
addKey(Type.KEYSYM, "key.keyboard.z", 90);
addKey(Type.KEYSYM, "key.keyboard.f1", 290);
addKey(Type.KEYSYM, "key.keyboard.f2", 291);
addKey(Type.KEYSYM, "key.keyboard.f3", 292);
addKey(Type.KEYSYM, "key.keyboard.f4", 293);
addKey(Type.KEYSYM, "key.keyboard.f5", 294);
addKey(Type.KEYSYM, "key.keyboard.f6", 295);
addKey(Type.KEYSYM, "key.keyboard.f7", 296);
addKey(Type.KEYSYM, "key.keyboard.f8", 297);
addKey(Type.KEYSYM, "key.keyboard.f9", 298);
addKey(Type.KEYSYM, "key.keyboard.f10", 299);
addKey(Type.KEYSYM, "key.keyboard.f11", 300);
addKey(Type.KEYSYM, "key.keyboard.f12", 301);
addKey(Type.KEYSYM, "key.keyboard.f13", 302);
addKey(Type.KEYSYM, "key.keyboard.f14", 303);
addKey(Type.KEYSYM, "key.keyboard.f15", 304);
addKey(Type.KEYSYM, "key.keyboard.f16", 305);
addKey(Type.KEYSYM, "key.keyboard.f17", 306);
addKey(Type.KEYSYM, "key.keyboard.f18", 307);
addKey(Type.KEYSYM, "key.keyboard.f19", 308);
addKey(Type.KEYSYM, "key.keyboard.f20", 309);
addKey(Type.KEYSYM, "key.keyboard.f21", 310);
addKey(Type.KEYSYM, "key.keyboard.f22", 311);
addKey(Type.KEYSYM, "key.keyboard.f23", 312);
addKey(Type.KEYSYM, "key.keyboard.f24", 313);
addKey(Type.KEYSYM, "key.keyboard.f25", 314);
addKey(Type.KEYSYM, "key.keyboard.num.lock", 282);
addKey(Type.KEYSYM, "key.keyboard.keypad.0", 320);
addKey(Type.KEYSYM, "key.keyboard.keypad.1", 321);
addKey(Type.KEYSYM, "key.keyboard.keypad.2", 322);
addKey(Type.KEYSYM, "key.keyboard.keypad.3", 323);
addKey(Type.KEYSYM, "key.keyboard.keypad.4", 324);
addKey(Type.KEYSYM, "key.keyboard.keypad.5", 325);
addKey(Type.KEYSYM, "key.keyboard.keypad.6", 326);
addKey(Type.KEYSYM, "key.keyboard.keypad.7", 327);
addKey(Type.KEYSYM, "key.keyboard.keypad.8", 328);
addKey(Type.KEYSYM, "key.keyboard.keypad.9", 329);
addKey(Type.KEYSYM, "key.keyboard.keypad.add", 334);
addKey(Type.KEYSYM, "key.keyboard.keypad.decimal", 330);
addKey(Type.KEYSYM, "key.keyboard.keypad.enter", 335);
addKey(Type.KEYSYM, "key.keyboard.keypad.equal", 336);
addKey(Type.KEYSYM, "key.keyboard.keypad.multiply", 332);
addKey(Type.KEYSYM, "key.keyboard.keypad.divide", 331);
addKey(Type.KEYSYM, "key.keyboard.keypad.subtract", 333);
addKey(Type.KEYSYM, "key.keyboard.down", 264);
addKey(Type.KEYSYM, "key.keyboard.left", 263);
addKey(Type.KEYSYM, "key.keyboard.right", 262);
addKey(Type.KEYSYM, "key.keyboard.up", 265);
addKey(Type.KEYSYM, "key.keyboard.apostrophe", 39);
addKey(Type.KEYSYM, "key.keyboard.backslash", 92);
addKey(Type.KEYSYM, "key.keyboard.comma", 44);
addKey(Type.KEYSYM, "key.keyboard.equal", 61);
addKey(Type.KEYSYM, "key.keyboard.grave.accent", 96);
addKey(Type.KEYSYM, "key.keyboard.left.bracket", 91);
addKey(Type.KEYSYM, "key.keyboard.minus", 45);
addKey(Type.KEYSYM, "key.keyboard.period", 46);
addKey(Type.KEYSYM, "key.keyboard.right.bracket", 93);
addKey(Type.KEYSYM, "key.keyboard.semicolon", 59);
addKey(Type.KEYSYM, "key.keyboard.slash", 47);
addKey(Type.KEYSYM, "key.keyboard.space", 32);
addKey(Type.KEYSYM, "key.keyboard.tab", 258);
addKey(Type.KEYSYM, "key.keyboard.left.alt", 342);
addKey(Type.KEYSYM, "key.keyboard.left.control", 341);
addKey(Type.KEYSYM, "key.keyboard.left.shift", 340);
addKey(Type.KEYSYM, "key.keyboard.left.win", 343);
addKey(Type.KEYSYM, "key.keyboard.right.alt", 346);
addKey(Type.KEYSYM, "key.keyboard.right.control", 345);
addKey(Type.KEYSYM, "key.keyboard.right.shift", 344);
addKey(Type.KEYSYM, "key.keyboard.right.win", 347);
addKey(Type.KEYSYM, "key.keyboard.enter", 257);
addKey(Type.KEYSYM, "key.keyboard.escape", 256);
addKey(Type.KEYSYM, "key.keyboard.backspace", 259);
addKey(Type.KEYSYM, "key.keyboard.delete", 261);
addKey(Type.KEYSYM, "key.keyboard.end", 269);
addKey(Type.KEYSYM, "key.keyboard.home", 268);
addKey(Type.KEYSYM, "key.keyboard.insert", 260);
addKey(Type.KEYSYM, "key.keyboard.page.down", 267);
addKey(Type.KEYSYM, "key.keyboard.page.up", 266);
addKey(Type.KEYSYM, "key.keyboard.caps.lock", 280);
addKey(Type.KEYSYM, "key.keyboard.pause", 284);
addKey(Type.KEYSYM, "key.keyboard.scroll.lock", 281);
addKey(Type.KEYSYM, "key.keyboard.menu", 348);
addKey(Type.KEYSYM, "key.keyboard.print.screen", 283);
addKey(Type.KEYSYM, "key.keyboard.world.1", 161);
addKey(Type.KEYSYM, "key.keyboard.world.2", 162);
}
}
public static final class Key {
private final String name;
private final Type type;
private final int value;
private final LazyLoadedValue<Component> displayName;
private static final Map<String, Key> NAME_MAP;
private Key(final String string, final Type b, final int integer) {
this.name = string;
this.type = b;
this.value = integer;
this.displayName = new LazyLoadedValue<Component>(() -> b.displayTextSupplier.apply(integer, string));
Key.NAME_MAP.put(string, this);
}
public Type getType() {
return this.type;
}
public int getValue() {
return this.value;
}
public String getName() {
return this.name;
}
public Component getDisplayName() {
return this.displayName.get();
}
public OptionalInt getNumericKeyValue() {
if (this.value >= 48 && this.value <= 57) {
return OptionalInt.of(this.value - 48);
}
if (this.value >= 320 && this.value <= 329) {
return OptionalInt.of(this.value - 320);
}
return OptionalInt.empty();
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Key a3 = (Key)object;
return this.value == a3.value && this.type == a3.type;
}
@Override
public int hashCode() {
return Objects.hash(this.type, this.value);
}
@Override
public String toString() {
return this.name;
}
static {
NAME_MAP = Maps.newHashMap();
}
}
}

View File

@ -0,0 +1,47 @@
package com.mojang.blaze3d.platform;
import net.minecraft.Util;
import com.mojang.math.Matrix4f;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.math.Vector3f;
public class Lighting {
private static final Vector3f DIFFUSE_LIGHT_0;
private static final Vector3f DIFFUSE_LIGHT_1;
private static final Vector3f NETHER_DIFFUSE_LIGHT_0;
private static final Vector3f NETHER_DIFFUSE_LIGHT_1;
public static void turnBackOn() {
RenderSystem.enableLighting();
RenderSystem.enableColorMaterial();
RenderSystem.colorMaterial(1032, 5634);
}
public static void turnOff() {
RenderSystem.disableLighting();
RenderSystem.disableColorMaterial();
}
public static void setupNetherLevel(final Matrix4f b) {
RenderSystem.setupLevelDiffuseLighting(Lighting.NETHER_DIFFUSE_LIGHT_0, Lighting.NETHER_DIFFUSE_LIGHT_1, b);
}
public static void setupLevel(final Matrix4f b) {
RenderSystem.setupLevelDiffuseLighting(Lighting.DIFFUSE_LIGHT_0, Lighting.DIFFUSE_LIGHT_1, b);
}
public static void setupForFlatItems() {
RenderSystem.setupGuiFlatDiffuseLighting(Lighting.DIFFUSE_LIGHT_0, Lighting.DIFFUSE_LIGHT_1);
}
public static void setupFor3DItems() {
RenderSystem.setupGui3DDiffuseLighting(Lighting.DIFFUSE_LIGHT_0, Lighting.DIFFUSE_LIGHT_1);
}
static {
DIFFUSE_LIGHT_0 = Util.<Vector3f>make(new Vector3f(0.2f, 1.0f, -0.7f), Vector3f::normalize);
DIFFUSE_LIGHT_1 = Util.<Vector3f>make(new Vector3f(-0.2f, 1.0f, 0.7f), Vector3f::normalize);
NETHER_DIFFUSE_LIGHT_0 = Util.<Vector3f>make(new Vector3f(0.2f, 1.0f, -0.7f), Vector3f::normalize);
NETHER_DIFFUSE_LIGHT_1 = Util.<Vector3f>make(new Vector3f(-0.2f, -1.0f, 0.7f), Vector3f::normalize);
}
}

View File

@ -0,0 +1,15 @@
package com.mojang.blaze3d.platform;
import java.nio.FloatBuffer;
import java.nio.ByteOrder;
import java.nio.ByteBuffer;
public class MemoryTracker {
public static synchronized ByteBuffer createByteBuffer(final int integer) {
return ByteBuffer.allocateDirect(integer).order(ByteOrder.nativeOrder());
}
public static FloatBuffer createFloatBuffer(final int integer) {
return createByteBuffer(integer << 2).asFloatBuffer();
}
}

View File

@ -0,0 +1,90 @@
package com.mojang.blaze3d.platform;
import java.util.Iterator;
import java.util.Optional;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.systems.RenderSystem;
import com.google.common.collect.Lists;
import java.util.List;
public final class Monitor {
private final long monitor;
private final List<VideoMode> videoModes;
private VideoMode currentMode;
private int x;
private int y;
public Monitor(final long long1) {
this.monitor = long1;
this.videoModes = Lists.newArrayList();
this.refreshVideoModes();
}
public void refreshVideoModes() {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
this.videoModes.clear();
final GLFWVidMode.Buffer buffer2 = GLFW.glfwGetVideoModes(this.monitor);
for (int integer3 = buffer2.limit() - 1; integer3 >= 0; --integer3) {
buffer2.position(integer3);
final VideoMode dgx4 = new VideoMode(buffer2);
if (dgx4.getRedBits() >= 8 && dgx4.getGreenBits() >= 8 && dgx4.getBlueBits() >= 8) {
this.videoModes.add(dgx4);
}
}
final int[] arr3 = { 0 };
final int[] arr4 = { 0 };
GLFW.glfwGetMonitorPos(this.monitor, arr3, arr4);
this.x = arr3[0];
this.y = arr4[0];
final GLFWVidMode gLFWVidMode5 = GLFW.glfwGetVideoMode(this.monitor);
this.currentMode = new VideoMode(gLFWVidMode5);
}
public VideoMode getPreferredVidMode(final Optional<VideoMode> optional) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
if (optional.isPresent()) {
final VideoMode dgx3 = optional.get();
for (final VideoMode dgx4 : this.videoModes) {
if (dgx4.equals(dgx3)) {
return dgx4;
}
}
}
return this.getCurrentMode();
}
public int getVideoModeIndex(final VideoMode dgx) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
return this.videoModes.indexOf(dgx);
}
public VideoMode getCurrentMode() {
return this.currentMode;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public VideoMode getMode(final int integer) {
return this.videoModes.get(integer);
}
public int getModeCount() {
return this.videoModes.size();
}
public long getMonitor() {
return this.monitor;
}
@Override
public String toString() {
return String.format("Monitor[%s %sx%s %s]", this.monitor, this.x, this.y, this.currentMode);
}
}

View File

@ -0,0 +1,5 @@
package com.mojang.blaze3d.platform;
public interface MonitorCreator {
Monitor createMonitor(final long long1);
}

View File

@ -0,0 +1,572 @@
package com.mojang.blaze3d.platform;
import org.lwjgl.stb.STBIWriteCallback;
import java.util.EnumSet;
import org.apache.logging.log4j.LogManager;
import com.google.common.base.Charsets;
import java.util.Base64;
import org.lwjgl.stb.STBImageResize;
import org.lwjgl.stb.STBImageWrite;
import java.io.OutputStream;
import java.nio.channels.Channels;
import java.io.ByteArrayOutputStream;
import java.nio.channels.WritableByteChannel;
import java.nio.file.OpenOption;
import java.nio.file.Files;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.Path;
import org.lwjgl.stb.STBTruetype;
import org.lwjgl.stb.STBTTFontinfo;
import java.io.File;
import com.mojang.blaze3d.systems.RenderSystem;
import java.nio.IntBuffer;
import org.lwjgl.stb.STBImage;
import org.lwjgl.system.MemoryStack;
import java.nio.ByteBuffer;
import org.apache.commons.io.IOUtils;
import java.nio.Buffer;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import org.lwjgl.system.MemoryUtil;
import java.nio.file.StandardOpenOption;
import java.util.Set;
import org.apache.logging.log4j.Logger;
public final class NativeImage implements AutoCloseable {
private static final Logger LOGGER;
private static final Set<StandardOpenOption> OPEN_OPTIONS;
private final Format format;
private final int width;
private final int height;
private final boolean useStbFree;
private long pixels;
private final long size;
public NativeImage(final int integer1, final int integer2, final boolean boolean3) {
this(Format.RGBA, integer1, integer2, boolean3);
}
public NativeImage(final Format a, final int integer2, final int integer3, final boolean boolean4) {
this.format = a;
this.width = integer2;
this.height = integer3;
this.size = integer2 * (long)integer3 * a.components();
this.useStbFree = false;
if (boolean4) {
this.pixels = MemoryUtil.nmemCalloc(1L, this.size);
}
else {
this.pixels = MemoryUtil.nmemAlloc(this.size);
}
}
private NativeImage(final Format a, final int integer2, final int integer3, final boolean boolean4, final long long5) {
this.format = a;
this.width = integer2;
this.height = integer3;
this.useStbFree = boolean4;
this.pixels = long5;
this.size = integer2 * integer3 * a.components();
}
@Override
public String toString() {
return "NativeImage[" + this.format + " " + this.width + "x" + this.height + "@" + this.pixels + (this.useStbFree ? "S" : "N") + "]";
}
public static NativeImage read(final InputStream inputStream) throws IOException {
return read(Format.RGBA, inputStream);
}
public static NativeImage read(@Nullable final Format a, final InputStream inputStream) throws IOException {
ByteBuffer byteBuffer3 = null;
try {
byteBuffer3 = TextureUtil.readResource(inputStream);
byteBuffer3.rewind();
return read(a, byteBuffer3);
}
finally {
MemoryUtil.memFree((Buffer)byteBuffer3);
IOUtils.closeQuietly(inputStream);
}
}
public static NativeImage read(final ByteBuffer byteBuffer) throws IOException {
return read(Format.RGBA, byteBuffer);
}
public static NativeImage read(@Nullable final Format a, final ByteBuffer byteBuffer) throws IOException {
if (a != null && !a.supportedByStb()) {
throw new UnsupportedOperationException("Don't know how to read format " + a);
}
if (MemoryUtil.memAddress(byteBuffer) == 0L) {
throw new IllegalArgumentException("Invalid buffer");
}
try (final MemoryStack memoryStack3 = MemoryStack.stackPush()) {
final IntBuffer intBuffer5 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer6 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer7 = memoryStack3.mallocInt(1);
final ByteBuffer byteBuffer2 = STBImage.stbi_load_from_memory(byteBuffer, intBuffer5, intBuffer6, intBuffer7, (a == null) ? 0 : a.components);
if (byteBuffer2 == null) {
throw new IOException("Could not load image: " + STBImage.stbi_failure_reason());
}
return new NativeImage((a == null) ? getStbFormat(intBuffer7.get(0)) : a, intBuffer5.get(0), intBuffer6.get(0), true, MemoryUtil.memAddress(byteBuffer2));
}
}
private static void setClamp(final boolean boolean1) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
if (boolean1) {
GlStateManager._texParameter(3553, 10242, 10496);
GlStateManager._texParameter(3553, 10243, 10496);
}
else {
GlStateManager._texParameter(3553, 10242, 10497);
GlStateManager._texParameter(3553, 10243, 10497);
}
}
private static void setFilter(final boolean boolean1, final boolean boolean2) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
if (boolean1) {
GlStateManager._texParameter(3553, 10241, boolean2 ? 9987 : 9729);
GlStateManager._texParameter(3553, 10240, 9729);
}
else {
GlStateManager._texParameter(3553, 10241, boolean2 ? 9986 : 9728);
GlStateManager._texParameter(3553, 10240, 9728);
}
}
private void checkAllocated() {
if (this.pixels == 0L) {
throw new IllegalStateException("Image is not allocated.");
}
}
@Override
public void close() {
if (this.pixels != 0L) {
if (this.useStbFree) {
STBImage.nstbi_image_free(this.pixels);
}
else {
MemoryUtil.nmemFree(this.pixels);
}
}
this.pixels = 0L;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public Format format() {
return this.format;
}
public int getPixelRGBA(final int integer1, final int integer2) {
if (this.format != Format.RGBA) {
throw new IllegalArgumentException(String.format("getPixelRGBA only works on RGBA images; have %s", this.format));
}
if (integer1 > this.width || integer2 > this.height) {
throw new IllegalArgumentException(String.format("(%s, %s) outside of image bounds (%s, %s)", integer1, integer2, this.width, this.height));
}
this.checkAllocated();
final long long4 = (integer1 + integer2 * this.width) * 4;
return MemoryUtil.memGetInt(this.pixels + long4);
}
public void setPixelRGBA(final int integer1, final int integer2, final int integer3) {
if (this.format != Format.RGBA) {
throw new IllegalArgumentException(String.format("getPixelRGBA only works on RGBA images; have %s", this.format));
}
if (integer1 > this.width || integer2 > this.height) {
throw new IllegalArgumentException(String.format("(%s, %s) outside of image bounds (%s, %s)", integer1, integer2, this.width, this.height));
}
this.checkAllocated();
final long long5 = (integer1 + integer2 * this.width) * 4;
MemoryUtil.memPutInt(this.pixels + long5, integer3);
}
public byte getLuminanceOrAlpha(final int integer1, final int integer2) {
if (!this.format.hasLuminanceOrAlpha()) {
throw new IllegalArgumentException(String.format("no luminance or alpha in %s", this.format));
}
if (integer1 > this.width || integer2 > this.height) {
throw new IllegalArgumentException(String.format("(%s, %s) outside of image bounds (%s, %s)", integer1, integer2, this.width, this.height));
}
final int integer3 = (integer1 + integer2 * this.width) * this.format.components() + this.format.luminanceOrAlphaOffset() / 8;
return MemoryUtil.memGetByte(this.pixels + integer3);
}
@Deprecated
public int[] makePixelArray() {
if (this.format != Format.RGBA) {
throw new UnsupportedOperationException("can only call makePixelArray for RGBA images.");
}
this.checkAllocated();
final int[] arr2 = new int[this.getWidth() * this.getHeight()];
for (int integer3 = 0; integer3 < this.getHeight(); ++integer3) {
for (int integer4 = 0; integer4 < this.getWidth(); ++integer4) {
final int integer5 = this.getPixelRGBA(integer4, integer3);
final int integer6 = getA(integer5);
final int integer7 = getB(integer5);
final int integer8 = getG(integer5);
final int integer9 = getR(integer5);
final int integer10 = integer6 << 24 | integer9 << 16 | integer8 << 8 | integer7;
arr2[integer4 + integer3 * this.getWidth()] = integer10;
}
}
return arr2;
}
public void upload(final int integer1, final int integer2, final int integer3, final boolean boolean4) {
this.upload(integer1, integer2, integer3, 0, 0, this.width, this.height, false, boolean4);
}
public void upload(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6, final int integer7, final boolean boolean8, final boolean boolean9) {
this.upload(integer1, integer2, integer3, integer4, integer5, integer6, integer7, false, false, boolean8, boolean9);
}
public void upload(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6, final int integer7, final boolean boolean8, final boolean boolean9, final boolean boolean10, final boolean boolean11) {
if (!RenderSystem.isOnRenderThreadOrInit()) {
RenderSystem.recordRenderCall(() -> this._upload(integer1, integer2, integer3, integer4, integer5, integer6, integer7, boolean8, boolean9, boolean10, boolean11));
}
else {
this._upload(integer1, integer2, integer3, integer4, integer5, integer6, integer7, boolean8, boolean9, boolean10, boolean11);
}
}
private void _upload(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6, final int integer7, final boolean boolean8, final boolean boolean9, final boolean boolean10, final boolean boolean11) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
this.checkAllocated();
setFilter(boolean8, boolean10);
setClamp(boolean9);
if (integer6 == this.getWidth()) {
GlStateManager._pixelStore(3314, 0);
}
else {
GlStateManager._pixelStore(3314, this.getWidth());
}
GlStateManager._pixelStore(3316, integer4);
GlStateManager._pixelStore(3315, integer5);
this.format.setUnpackPixelStoreState();
GlStateManager._texSubImage2D(3553, integer1, integer2, integer3, integer6, integer7, this.format.glFormat(), 5121, this.pixels);
if (boolean11) {
this.close();
}
}
public void downloadTexture(final int integer, final boolean boolean2) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
this.checkAllocated();
this.format.setPackPixelStoreState();
GlStateManager._getTexImage(3553, integer, this.format.glFormat(), 5121, this.pixels);
if (boolean2 && this.format.hasAlpha()) {
for (int integer2 = 0; integer2 < this.getHeight(); ++integer2) {
for (int integer3 = 0; integer3 < this.getWidth(); ++integer3) {
this.setPixelRGBA(integer3, integer2, this.getPixelRGBA(integer3, integer2) | 255 << this.format.alphaOffset());
}
}
}
}
public void writeToFile(final File file) throws IOException {
this.writeToFile(file.toPath());
}
public void copyFromFont(final STBTTFontinfo sTBTTFontinfo, final int integer2, final int integer3, final int integer4, final float float5, final float float6, final float float7, final float float8, final int integer9, final int integer10) {
if (integer9 < 0 || integer9 + integer3 > this.getWidth() || integer10 < 0 || integer10 + integer4 > this.getHeight()) {
throw new IllegalArgumentException(String.format("Out of bounds: start: (%s, %s) (size: %sx%s); size: %sx%s", integer9, integer10, integer3, integer4, this.getWidth(), this.getHeight()));
}
if (this.format.components() != 1) {
throw new IllegalArgumentException("Can only write fonts into 1-component images.");
}
STBTruetype.nstbtt_MakeGlyphBitmapSubpixel(sTBTTFontinfo.address(), this.pixels + integer9 + integer10 * this.getWidth(), integer3, integer4, this.getWidth(), float5, float6, float7, float8, integer2);
}
public void writeToFile(final Path path) throws IOException {
if (!this.format.supportedByStb()) {
throw new UnsupportedOperationException("Don't know how to write format " + this.format);
}
this.checkAllocated();
try (final WritableByteChannel writableByteChannel3 = Files.newByteChannel(path, NativeImage.OPEN_OPTIONS, new FileAttribute[0])) {
if (!this.writeToChannel(writableByteChannel3)) {
throw new IOException("Could not write image to the PNG file \"" + path.toAbsolutePath() + "\": " + STBImage.stbi_failure_reason());
}
}
}
public byte[] asByteArray() throws IOException {
try (final ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
final WritableByteChannel writableByteChannel4 = Channels.newChannel(byteArrayOutputStream2)) {
if (!this.writeToChannel(writableByteChannel4)) {
throw new IOException("Could not write image to byte array: " + STBImage.stbi_failure_reason());
}
return byteArrayOutputStream2.toByteArray();
}
}
private boolean writeToChannel(final WritableByteChannel writableByteChannel) throws IOException {
final WriteCallback c3 = new WriteCallback(writableByteChannel);
try {
final int integer4 = Math.min(this.getHeight(), Integer.MAX_VALUE / this.getWidth() / this.format.components());
if (integer4 < this.getHeight()) {
NativeImage.LOGGER.warn("Dropping image height from {} to {} to fit the size into 32-bit signed int", this.getHeight(), integer4);
}
if (STBImageWrite.nstbi_write_png_to_func(c3.address(), 0L, this.getWidth(), integer4, this.format.components(), this.pixels, 0) == 0) {
return false;
}
c3.throwIfException();
return true;
}
finally {
c3.free();
}
}
public void copyFrom(final NativeImage dgs) {
if (dgs.format() != this.format) {
throw new UnsupportedOperationException("Image formats don't match.");
}
final int integer3 = this.format.components();
this.checkAllocated();
dgs.checkAllocated();
if (this.width == dgs.width) {
MemoryUtil.memCopy(dgs.pixels, this.pixels, Math.min(this.size, dgs.size));
}
else {
final int integer4 = Math.min(this.getWidth(), dgs.getWidth());
for (int integer5 = Math.min(this.getHeight(), dgs.getHeight()), integer6 = 0; integer6 < integer5; ++integer6) {
final int integer7 = integer6 * dgs.getWidth() * integer3;
final int integer8 = integer6 * this.getWidth() * integer3;
MemoryUtil.memCopy(dgs.pixels + integer7, this.pixels + integer8, (long)integer4);
}
}
}
public void fillRect(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5) {
for (int integer6 = integer2; integer6 < integer2 + integer4; ++integer6) {
for (int integer7 = integer1; integer7 < integer1 + integer3; ++integer7) {
this.setPixelRGBA(integer7, integer6, integer5);
}
}
}
public void copyRect(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6, final boolean boolean7, final boolean boolean8) {
for (int integer7 = 0; integer7 < integer6; ++integer7) {
for (int integer8 = 0; integer8 < integer5; ++integer8) {
final int integer9 = boolean7 ? (integer5 - 1 - integer8) : integer8;
final int integer10 = boolean8 ? (integer6 - 1 - integer7) : integer7;
final int integer11 = this.getPixelRGBA(integer1 + integer8, integer2 + integer7);
this.setPixelRGBA(integer1 + integer3 + integer9, integer2 + integer4 + integer10, integer11);
}
}
}
public void flipY() {
this.checkAllocated();
try (final MemoryStack memoryStack2 = MemoryStack.stackPush()) {
final int integer4 = this.format.components();
final int integer5 = this.getWidth() * integer4;
final long long6 = memoryStack2.nmalloc(integer5);
for (int integer6 = 0; integer6 < this.getHeight() / 2; ++integer6) {
final int integer7 = integer6 * this.getWidth() * integer4;
final int integer8 = (this.getHeight() - 1 - integer6) * this.getWidth() * integer4;
MemoryUtil.memCopy(this.pixels + integer7, long6, (long)integer5);
MemoryUtil.memCopy(this.pixels + integer8, this.pixels + integer7, (long)integer5);
MemoryUtil.memCopy(long6, this.pixels + integer8, (long)integer5);
}
}
}
public void resizeSubRectTo(final int integer1, final int integer2, final int integer3, final int integer4, final NativeImage dgs) {
this.checkAllocated();
if (dgs.format() != this.format) {
throw new UnsupportedOperationException("resizeSubRectTo only works for images of the same format.");
}
final int integer5 = this.format.components();
STBImageResize.nstbir_resize_uint8(this.pixels + (integer1 + integer2 * this.getWidth()) * integer5, integer3, integer4, this.getWidth() * integer5, dgs.pixels, dgs.getWidth(), dgs.getHeight(), 0, integer5);
}
public void untrack() {
DebugMemoryUntracker.untrack(this.pixels);
}
public static NativeImage fromBase64(final String string) throws IOException {
final byte[] arr2 = Base64.getDecoder().decode(string.replaceAll("\n", "").getBytes(Charsets.UTF_8));
try (final MemoryStack memoryStack3 = MemoryStack.stackPush()) {
final ByteBuffer byteBuffer5 = memoryStack3.malloc(arr2.length);
byteBuffer5.put(arr2);
byteBuffer5.rewind();
return read(byteBuffer5);
}
}
public static int getA(final int integer) {
return integer >> 24 & 0xFF;
}
public static int getR(final int integer) {
return integer >> 0 & 0xFF;
}
public static int getG(final int integer) {
return integer >> 8 & 0xFF;
}
public static int getB(final int integer) {
return integer >> 16 & 0xFF;
}
public static int combine(final int integer1, final int integer2, final int integer3, final int integer4) {
return (integer1 & 0xFF) << 24 | (integer2 & 0xFF) << 16 | (integer3 & 0xFF) << 8 | (integer4 & 0xFF) << 0;
}
static {
LOGGER = LogManager.getLogger();
OPEN_OPTIONS = EnumSet.<StandardOpenOption>of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}
static class WriteCallback extends STBIWriteCallback {
private final WritableByteChannel output;
@Nullable
private IOException exception;
private WriteCallback(final WritableByteChannel writableByteChannel) {
this.output = writableByteChannel;
}
public void invoke(final long long1, final long long2, final int integer) {
final ByteBuffer byteBuffer7 = getData(long2, integer);
try {
this.output.write(byteBuffer7);
}
catch (IOException iOException8) {
this.exception = iOException8;
}
}
public void throwIfException() throws IOException {
if (this.exception != null) {
throw this.exception;
}
}
}
public enum InternalGlFormat {
RGBA(6408),
RGB(6407),
LUMINANCE_ALPHA(6410),
LUMINANCE(6409),
INTENSITY(32841);
private final int glFormat;
private InternalGlFormat(final int integer3) {
this.glFormat = integer3;
}
int glFormat() {
return this.glFormat;
}
}
public enum Format {
RGBA(4, 6408, true, true, true, false, true, 0, 8, 16, 255, 24, true),
RGB(3, 6407, true, true, true, false, false, 0, 8, 16, 255, 255, true),
LUMINANCE_ALPHA(2, 6410, false, false, false, true, true, 255, 255, 255, 0, 8, true),
LUMINANCE(1, 6409, false, false, false, true, false, 0, 0, 0, 0, 255, true);
private final int components;
private final int glFormat;
private final boolean hasRed;
private final boolean hasGreen;
private final boolean hasBlue;
private final boolean hasLuminance;
private final boolean hasAlpha;
private final int redOffset;
private final int greenOffset;
private final int blueOffset;
private final int luminanceOffset;
private final int alphaOffset;
private final boolean supportedByStb;
private Format(final int integer3, final int integer4, final boolean boolean5, final boolean boolean6, final boolean boolean7, final boolean boolean8, final boolean boolean9, final int integer10, final int integer11, final int integer12, final int integer13, final int integer14, final boolean boolean15) {
this.components = integer3;
this.glFormat = integer4;
this.hasRed = boolean5;
this.hasGreen = boolean6;
this.hasBlue = boolean7;
this.hasLuminance = boolean8;
this.hasAlpha = boolean9;
this.redOffset = integer10;
this.greenOffset = integer11;
this.blueOffset = integer12;
this.luminanceOffset = integer13;
this.alphaOffset = integer14;
this.supportedByStb = boolean15;
}
public int components() {
return this.components;
}
public void setPackPixelStoreState() {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
GlStateManager._pixelStore(3333, this.components());
}
public void setUnpackPixelStoreState() {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
GlStateManager._pixelStore(3317, this.components());
}
public int glFormat() {
return this.glFormat;
}
public boolean hasAlpha() {
return this.hasAlpha;
}
public int alphaOffset() {
return this.alphaOffset;
}
public boolean hasLuminanceOrAlpha() {
return this.hasLuminance || this.hasAlpha;
}
public int luminanceOrAlphaOffset() {
return this.hasLuminance ? this.luminanceOffset : this.alphaOffset;
}
public boolean supportedByStb() {
return this.supportedByStb;
}
private static Format getStbFormat(final int integer) {
switch (integer) {
case 1: {
return Format.LUMINANCE;
}
case 2: {
return Format.LUMINANCE_ALPHA;
}
case 3: {
return Format.RGB;
}
default: {
return Format.RGBA;
}
}
}
}
}

View File

@ -0,0 +1,182 @@
package com.mojang.blaze3d.platform;
import java.io.EOFException;
import java.nio.channels.ReadableByteChannel;
import java.nio.ByteBuffer;
import org.lwjgl.system.MemoryUtil;
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
import java.io.FileInputStream;
import java.nio.IntBuffer;
import java.io.IOException;
import org.lwjgl.stb.STBImage;
import org.lwjgl.stb.STBIEOFCallbackI;
import org.lwjgl.stb.STBISkipCallbackI;
import org.lwjgl.stb.STBIReadCallbackI;
import org.lwjgl.stb.STBIIOCallbacks;
import org.lwjgl.stb.STBIEOFCallback;
import org.lwjgl.stb.STBISkipCallback;
import org.lwjgl.stb.STBIReadCallback;
import org.lwjgl.system.MemoryStack;
import java.io.InputStream;
public class PngInfo {
public final int width;
public final int height;
public PngInfo(final String string, final InputStream inputStream) throws IOException {
try (final MemoryStack memoryStack4 = MemoryStack.stackPush();
final StbReader a6 = createCallbacks(inputStream);
final STBIReadCallback sTBIReadCallback8 = STBIReadCallback.create(a6::read);
final STBISkipCallback sTBISkipCallback10 = STBISkipCallback.create(a6::skip);
final STBIEOFCallback sTBIEOFCallback12 = STBIEOFCallback.create(a6::eof)) {
final STBIIOCallbacks sTBIIOCallbacks14 = STBIIOCallbacks.mallocStack(memoryStack4);
sTBIIOCallbacks14.read((STBIReadCallbackI)sTBIReadCallback8);
sTBIIOCallbacks14.skip((STBISkipCallbackI)sTBISkipCallback10);
sTBIIOCallbacks14.eof((STBIEOFCallbackI)sTBIEOFCallback12);
final IntBuffer intBuffer15 = memoryStack4.mallocInt(1);
final IntBuffer intBuffer16 = memoryStack4.mallocInt(1);
final IntBuffer intBuffer17 = memoryStack4.mallocInt(1);
if (!STBImage.stbi_info_from_callbacks(sTBIIOCallbacks14, 0L, intBuffer15, intBuffer16, intBuffer17)) {
throw new IOException("Could not read info from the PNG file " + string + " " + STBImage.stbi_failure_reason());
}
this.width = intBuffer15.get(0);
this.height = intBuffer16.get(0);
}
}
private static StbReader createCallbacks(final InputStream inputStream) {
if (inputStream instanceof FileInputStream) {
return new StbReaderSeekableByteChannel((SeekableByteChannel)((FileInputStream)inputStream).getChannel());
}
return new StbReaderBufferedChannel(Channels.newChannel(inputStream));
}
abstract static class StbReader implements AutoCloseable {
protected boolean closed;
private StbReader() {
}
int read(final long long1, final long long2, final int integer) {
try {
return this.read(long2, integer);
}
catch (IOException iOException7) {
this.closed = true;
return 0;
}
}
void skip(final long long1, final int integer) {
try {
this.skip(integer);
}
catch (IOException iOException5) {
this.closed = true;
}
}
int eof(final long long1) {
return this.closed ? 1 : 0;
}
protected abstract int read(final long long1, final int integer) throws IOException;
protected abstract void skip(final int integer) throws IOException;
@Override
public abstract void close() throws IOException;
}
static class StbReaderSeekableByteChannel extends StbReader {
private final SeekableByteChannel channel;
private StbReaderSeekableByteChannel(final SeekableByteChannel seekableByteChannel) {
this.channel = seekableByteChannel;
}
public int read(final long long1, final int integer) throws IOException {
final ByteBuffer byteBuffer5 = MemoryUtil.memByteBuffer(long1, integer);
return this.channel.read(byteBuffer5);
}
public void skip(final int integer) throws IOException {
this.channel.position(this.channel.position() + integer);
}
public int eof(final long long1) {
return (super.eof(long1) != 0 && this.channel.isOpen()) ? 1 : 0;
}
@Override
public void close() throws IOException {
this.channel.close();
}
}
static class StbReaderBufferedChannel extends StbReader {
private final ReadableByteChannel channel;
private long readBufferAddress;
private int bufferSize;
private int read;
private int consumed;
private StbReaderBufferedChannel(final ReadableByteChannel readableByteChannel) {
this.readBufferAddress = MemoryUtil.nmemAlloc(128L);
this.bufferSize = 128;
this.channel = readableByteChannel;
}
private void fillReadBuffer(final int integer) throws IOException {
ByteBuffer byteBuffer3 = MemoryUtil.memByteBuffer(this.readBufferAddress, this.bufferSize);
if (integer + this.consumed > this.bufferSize) {
this.bufferSize = integer + this.consumed;
byteBuffer3 = MemoryUtil.memRealloc(byteBuffer3, this.bufferSize);
this.readBufferAddress = MemoryUtil.memAddress(byteBuffer3);
}
byteBuffer3.position(this.read);
while (integer + this.consumed > this.read) {
try {
final int integer2 = this.channel.read(byteBuffer3);
if (integer2 == -1) {
break;
}
continue;
}
finally {
this.read = byteBuffer3.position();
}
}
}
public int read(final long long1, int integer) throws IOException {
this.fillReadBuffer(integer);
if (integer + this.consumed > this.read) {
integer = this.read - this.consumed;
}
MemoryUtil.memCopy(this.readBufferAddress + this.consumed, long1, (long)integer);
this.consumed += integer;
return integer;
}
public void skip(final int integer) throws IOException {
if (integer > 0) {
this.fillReadBuffer(integer);
if (integer + this.consumed > this.read) {
throw new EOFException("Can't skip past the EOF.");
}
}
if (this.consumed + integer < 0) {
throw new IOException("Can't seek before the beginning: " + (this.consumed + integer));
}
this.consumed += integer;
}
@Override
public void close() throws IOException {
MemoryUtil.nmemFree(this.readBufferAddress);
this.channel.close();
}
}
}

View File

@ -0,0 +1,96 @@
package com.mojang.blaze3d.platform;
import org.lwjgl.glfw.GLFWMonitorCallback;
import org.lwjgl.glfw.GLFWMonitorCallbackI;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import javax.annotation.Nullable;
import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.systems.RenderSystem;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
public class ScreenManager {
private final Long2ObjectMap<Monitor> monitors;
private final MonitorCreator monitorCreator;
public ScreenManager(final MonitorCreator dgr) {
this.monitors = (Long2ObjectMap<Monitor>)new Long2ObjectOpenHashMap();
RenderSystem.assertThread(RenderSystem::isInInitPhase);
this.monitorCreator = dgr;
GLFW.glfwSetMonitorCallback(this::onMonitorChange);
final PointerBuffer pointerBuffer3 = GLFW.glfwGetMonitors();
if (pointerBuffer3 != null) {
for (int integer4 = 0; integer4 < pointerBuffer3.limit(); ++integer4) {
final long long5 = pointerBuffer3.get(integer4);
this.monitors.put(long5, dgr.createMonitor(long5));
}
}
}
private void onMonitorChange(final long long1, final int integer) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
if (integer == 262145) {
this.monitors.put(long1, this.monitorCreator.createMonitor(long1));
}
else if (integer == 262146) {
this.monitors.remove(long1);
}
}
@Nullable
public Monitor getMonitor(final long long1) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
return (Monitor)this.monitors.get(long1);
}
@Nullable
public Monitor findBestMonitor(final Window dgy) {
final long long3 = GLFW.glfwGetWindowMonitor(dgy.getWindow());
if (long3 != 0L) {
return this.getMonitor(long3);
}
final int integer5 = dgy.getX();
final int integer6 = integer5 + dgy.getScreenWidth();
final int integer7 = dgy.getY();
final int integer8 = integer7 + dgy.getScreenHeight();
int integer9 = -1;
Monitor dgq10 = null;
for (final Monitor dgq11 : this.monitors.values()) {
final int integer10 = dgq11.getX();
final int integer11 = integer10 + dgq11.getCurrentMode().getWidth();
final int integer12 = dgq11.getY();
final int integer13 = integer12 + dgq11.getCurrentMode().getHeight();
final int integer14 = clamp(integer5, integer10, integer11);
final int integer15 = clamp(integer6, integer10, integer11);
final int integer16 = clamp(integer7, integer12, integer13);
final int integer17 = clamp(integer8, integer12, integer13);
final int integer18 = Math.max(0, integer15 - integer14);
final int integer19 = Math.max(0, integer17 - integer16);
final int integer20 = integer18 * integer19;
if (integer20 > integer9) {
dgq10 = dgq11;
integer9 = integer20;
}
}
return dgq10;
}
public static int clamp(final int integer1, final int integer2, final int integer3) {
if (integer1 < integer2) {
return integer2;
}
if (integer1 > integer3) {
return integer3;
}
return integer1;
}
public void shutdown() {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
final GLFWMonitorCallback gLFWMonitorCallback2 = GLFW.glfwSetMonitorCallback((GLFWMonitorCallbackI)null);
if (gLFWMonitorCallback2 != null) {
gLFWMonitorCallback2.free();
}
}
}

View File

@ -0,0 +1,115 @@
package com.mojang.blaze3d.platform;
import org.apache.logging.log4j.LogManager;
import org.lwjgl.opengl.GL11;
import java.nio.Buffer;
import java.io.IOException;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.FileChannel;
import java.nio.channels.Channels;
import org.lwjgl.system.MemoryUtil;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.io.InputStream;
import java.nio.IntBuffer;
import com.mojang.blaze3d.systems.RenderSystem;
import org.apache.logging.log4j.Logger;
public class TextureUtil {
private static final Logger LOGGER;
public static int generateTextureId() {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
return GlStateManager._genTexture();
}
public static void releaseTextureId(final int integer) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
GlStateManager._deleteTexture(integer);
}
public static void prepareImage(final int integer1, final int integer2, final int integer3) {
prepareImage(NativeImage.InternalGlFormat.RGBA, integer1, 0, integer2, integer3);
}
public static void prepareImage(final NativeImage.InternalGlFormat b, final int integer2, final int integer3, final int integer4) {
prepareImage(b, integer2, 0, integer3, integer4);
}
public static void prepareImage(final int integer1, final int integer2, final int integer3, final int integer4) {
prepareImage(NativeImage.InternalGlFormat.RGBA, integer1, integer2, integer3, integer4);
}
public static void prepareImage(final NativeImage.InternalGlFormat b, final int integer2, final int integer3, final int integer4, final int integer5) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
bind(integer2);
if (integer3 >= 0) {
GlStateManager._texParameter(3553, 33085, integer3);
GlStateManager._texParameter(3553, 33082, 0);
GlStateManager._texParameter(3553, 33083, integer3);
GlStateManager._texParameter(3553, 34049, 0.0f);
}
for (int integer6 = 0; integer6 <= integer3; ++integer6) {
GlStateManager._texImage2D(3553, integer6, b.glFormat(), integer4 >> integer6, integer5 >> integer6, 0, 6408, 5121, null);
}
}
private static void bind(final int integer) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
GlStateManager._bindTexture(integer);
}
public static ByteBuffer readResource(final InputStream inputStream) throws IOException {
ByteBuffer byteBuffer2;
if (inputStream instanceof FileInputStream) {
final FileInputStream fileInputStream3 = (FileInputStream)inputStream;
final FileChannel fileChannel4 = fileInputStream3.getChannel();
byteBuffer2 = MemoryUtil.memAlloc((int)fileChannel4.size() + 1);
while (fileChannel4.read(byteBuffer2) != -1) {}
}
else {
byteBuffer2 = MemoryUtil.memAlloc(8192);
for (ReadableByteChannel readableByteChannel3 = Channels.newChannel(inputStream); readableByteChannel3.read(byteBuffer2) != -1; byteBuffer2 = MemoryUtil.memRealloc(byteBuffer2, byteBuffer2.capacity() * 2)) {
if (byteBuffer2.remaining() == 0) {}
}
}
return byteBuffer2;
}
public static String readResourceAsString(final InputStream inputStream) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
ByteBuffer byteBuffer2 = null;
try {
byteBuffer2 = readResource(inputStream);
final int integer3 = byteBuffer2.position();
byteBuffer2.rewind();
return MemoryUtil.memASCII(byteBuffer2, integer3);
}
catch (IOException ex) {}
finally {
if (byteBuffer2 != null) {
MemoryUtil.memFree((Buffer)byteBuffer2);
}
}
return null;
}
public static void initTexture(final IntBuffer intBuffer, final int integer2, final int integer3) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
GL11.glPixelStorei(3312, 0);
GL11.glPixelStorei(3313, 0);
GL11.glPixelStorei(3314, 0);
GL11.glPixelStorei(3315, 0);
GL11.glPixelStorei(3316, 0);
GL11.glPixelStorei(3317, 4);
GL11.glTexImage2D(3553, 0, 6408, integer2, integer3, 0, 32993, 33639, intBuffer);
GL11.glTexParameteri(3553, 10242, 10497);
GL11.glTexParameteri(3553, 10243, 10497);
GL11.glTexParameteri(3553, 10240, 9728);
GL11.glTexParameteri(3553, 10241, 9729);
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,132 @@
package com.mojang.blaze3d.platform;
import java.util.regex.Matcher;
import java.util.Optional;
import javax.annotation.Nullable;
import java.util.Objects;
import org.lwjgl.glfw.GLFWVidMode;
import java.util.regex.Pattern;
public final class VideoMode {
private final int width;
private final int height;
private final int redBits;
private final int greenBits;
private final int blueBits;
private final int refreshRate;
private static final Pattern PATTERN;
public VideoMode(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6) {
this.width = integer1;
this.height = integer2;
this.redBits = integer3;
this.greenBits = integer4;
this.blueBits = integer5;
this.refreshRate = integer6;
}
public VideoMode(final GLFWVidMode.Buffer buffer) {
this.width = buffer.width();
this.height = buffer.height();
this.redBits = buffer.redBits();
this.greenBits = buffer.greenBits();
this.blueBits = buffer.blueBits();
this.refreshRate = buffer.refreshRate();
}
public VideoMode(final GLFWVidMode gLFWVidMode) {
this.width = gLFWVidMode.width();
this.height = gLFWVidMode.height();
this.redBits = gLFWVidMode.redBits();
this.greenBits = gLFWVidMode.greenBits();
this.blueBits = gLFWVidMode.blueBits();
this.refreshRate = gLFWVidMode.refreshRate();
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public int getRedBits() {
return this.redBits;
}
public int getGreenBits() {
return this.greenBits;
}
public int getBlueBits() {
return this.blueBits;
}
public int getRefreshRate() {
return this.refreshRate;
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final VideoMode dgx3 = (VideoMode)object;
return this.width == dgx3.width && this.height == dgx3.height && this.redBits == dgx3.redBits && this.greenBits == dgx3.greenBits && this.blueBits == dgx3.blueBits && this.refreshRate == dgx3.refreshRate;
}
@Override
public int hashCode() {
return Objects.hash(this.width, this.height, this.redBits, this.greenBits, this.blueBits, this.refreshRate);
}
@Override
public String toString() {
return String.format("%sx%s@%s (%sbit)", this.width, this.height, this.refreshRate, this.redBits + this.greenBits + this.blueBits);
}
public static Optional<VideoMode> read(@Nullable final String string) {
if (string == null) {
return Optional.<VideoMode>empty();
}
try {
final Matcher matcher2 = VideoMode.PATTERN.matcher(string);
if (matcher2.matches()) {
final int integer3 = Integer.parseInt(matcher2.group(1));
final int integer4 = Integer.parseInt(matcher2.group(2));
final String string2 = matcher2.group(3);
int integer5;
if (string2 == null) {
integer5 = 60;
}
else {
integer5 = Integer.parseInt(string2);
}
final String string3 = matcher2.group(4);
int integer6;
if (string3 == null) {
integer6 = 24;
}
else {
integer6 = Integer.parseInt(string3);
}
final int integer7 = integer6 / 3;
return Optional.<VideoMode>of(new VideoMode(integer3, integer4, integer7, integer7, integer7, integer5));
}
}
catch (Exception ex) {}
return Optional.<VideoMode>empty();
}
public String write() {
return String.format("%sx%s@%s:%s", this.width, this.height, this.refreshRate, this.redBits + this.greenBits + this.blueBits);
}
static {
PATTERN = Pattern.compile("(\\d+)x(\\d+)(?:@(\\d+)(?::(\\d+))?)?");
}
}

View File

@ -0,0 +1,459 @@
package com.mojang.blaze3d.platform;
import net.minecraft.client.main.SilentInitException;
import org.apache.logging.log4j.LogManager;
import org.lwjgl.glfw.Callbacks;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import org.lwjgl.util.tinyfd.TinyFileDialogs;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.io.IOException;
import org.lwjgl.stb.STBImage;
import org.lwjgl.glfw.GLFWImage;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.MemoryStack;
import java.util.function.BiConsumer;
import org.lwjgl.opengl.GL;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.systems.RenderSystem;
import javax.annotation.Nullable;
import java.util.Optional;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.apache.logging.log4j.Logger;
public final class Window implements AutoCloseable {
private static final Logger LOGGER;
private final GLFWErrorCallback defaultErrorCallback;
private final WindowEventHandler eventHandler;
private final ScreenManager screenManager;
private final long window;
private int windowedX;
private int windowedY;
private int windowedWidth;
private int windowedHeight;
private Optional<VideoMode> preferredFullscreenVideoMode;
private boolean fullscreen;
private boolean actuallyFullscreen;
private int x;
private int y;
private int width;
private int height;
private int framebufferWidth;
private int framebufferHeight;
private int guiScaledWidth;
private int guiScaledHeight;
private double guiScale;
private String errorSection;
private boolean dirty;
private int framerateLimit;
private boolean vsync;
public Window(final WindowEventHandler dgz, final ScreenManager dgu, final DisplayData dgi, @Nullable final String string4, final String string5) {
this.defaultErrorCallback = GLFWErrorCallback.create(this::defaultErrorCallback);
this.errorSection = "";
RenderSystem.assertThread(RenderSystem::isInInitPhase);
this.screenManager = dgu;
this.setBootErrorCallback();
this.setErrorSection("Pre startup");
this.eventHandler = dgz;
final Optional<VideoMode> optional7 = VideoMode.read(string4);
if (optional7.isPresent()) {
this.preferredFullscreenVideoMode = optional7;
}
else if (dgi.fullscreenWidth.isPresent() && dgi.fullscreenHeight.isPresent()) {
this.preferredFullscreenVideoMode = Optional.<VideoMode>of(new VideoMode(dgi.fullscreenWidth.getAsInt(), dgi.fullscreenHeight.getAsInt(), 8, 8, 8, 60));
}
else {
this.preferredFullscreenVideoMode = Optional.<VideoMode>empty();
}
final boolean isFullscreen = dgi.isFullscreen;
this.fullscreen = isFullscreen;
this.actuallyFullscreen = isFullscreen;
final Monitor dgq8 = dgu.getMonitor(GLFW.glfwGetPrimaryMonitor());
final int n = (dgi.width > 0) ? dgi.width : 1;
this.width = n;
this.windowedWidth = n;
final int n2 = (dgi.height > 0) ? dgi.height : 1;
this.height = n2;
this.windowedHeight = n2;
GLFW.glfwDefaultWindowHints();
GLFW.glfwWindowHint(139265, 196609);
GLFW.glfwWindowHint(139275, 221185);
GLFW.glfwWindowHint(139266, 2);
GLFW.glfwWindowHint(139267, 0);
GLFW.glfwWindowHint(139272, 0);
this.window = GLFW.glfwCreateWindow(this.width, this.height, (CharSequence)string5, (this.fullscreen && dgq8 != null) ? dgq8.getMonitor() : 0L, 0L);
if (dgq8 != null) {
final VideoMode dgx9 = dgq8.getPreferredVidMode(this.fullscreen ? this.preferredFullscreenVideoMode : Optional.<VideoMode>empty());
final int n3 = dgq8.getX() + dgx9.getWidth() / 2 - this.width / 2;
this.x = n3;
this.windowedX = n3;
final int n4 = dgq8.getY() + dgx9.getHeight() / 2 - this.height / 2;
this.y = n4;
this.windowedY = n4;
}
else {
final int[] arr9 = { 0 };
final int[] arr10 = { 0 };
GLFW.glfwGetWindowPos(this.window, arr9, arr10);
final int n5 = arr9[0];
this.x = n5;
this.windowedX = n5;
final int n6 = arr10[0];
this.y = n6;
this.windowedY = n6;
}
GLFW.glfwMakeContextCurrent(this.window);
GL.createCapabilities();
this.setMode();
this.refreshFramebufferSize();
GLFW.glfwSetFramebufferSizeCallback(this.window, this::onFramebufferResize);
GLFW.glfwSetWindowPosCallback(this.window, this::onMove);
GLFW.glfwSetWindowSizeCallback(this.window, this::onResize);
GLFW.glfwSetWindowFocusCallback(this.window, this::onFocus);
GLFW.glfwSetCursorEnterCallback(this.window, this::onEnter);
}
public int getRefreshRate() {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
return GLX._getRefreshRate(this);
}
public boolean shouldClose() {
return GLX._shouldClose(this);
}
public static void checkGlfwError(final BiConsumer<Integer, String> biConsumer) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
try (final MemoryStack memoryStack2 = MemoryStack.stackPush()) {
final PointerBuffer pointerBuffer4 = memoryStack2.mallocPointer(1);
final int integer5 = GLFW.glfwGetError(pointerBuffer4);
if (integer5 != 0) {
final long long6 = pointerBuffer4.get();
final String string8 = (long6 == 0L) ? "" : MemoryUtil.memUTF8(long6);
biConsumer.accept(integer5, string8);
}
}
}
public void setIcon(final InputStream inputStream1, final InputStream inputStream2) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
try (final MemoryStack memoryStack4 = MemoryStack.stackPush()) {
if (inputStream1 == null) {
throw new FileNotFoundException("icons/icon_16x16.png");
}
if (inputStream2 == null) {
throw new FileNotFoundException("icons/icon_32x32.png");
}
final IntBuffer intBuffer6 = memoryStack4.mallocInt(1);
final IntBuffer intBuffer7 = memoryStack4.mallocInt(1);
final IntBuffer intBuffer8 = memoryStack4.mallocInt(1);
final GLFWImage.Buffer buffer9 = GLFWImage.mallocStack(2, memoryStack4);
final ByteBuffer byteBuffer10 = this.readIconPixels(inputStream1, intBuffer6, intBuffer7, intBuffer8);
if (byteBuffer10 == null) {
throw new IllegalStateException("Could not load icon: " + STBImage.stbi_failure_reason());
}
buffer9.position(0);
buffer9.width(intBuffer6.get(0));
buffer9.height(intBuffer7.get(0));
buffer9.pixels(byteBuffer10);
final ByteBuffer byteBuffer11 = this.readIconPixels(inputStream2, intBuffer6, intBuffer7, intBuffer8);
if (byteBuffer11 == null) {
throw new IllegalStateException("Could not load icon: " + STBImage.stbi_failure_reason());
}
buffer9.position(1);
buffer9.width(intBuffer6.get(0));
buffer9.height(intBuffer7.get(0));
buffer9.pixels(byteBuffer11);
buffer9.position(0);
GLFW.glfwSetWindowIcon(this.window, buffer9);
STBImage.stbi_image_free(byteBuffer10);
STBImage.stbi_image_free(byteBuffer11);
}
catch (IOException iOException4) {
Window.LOGGER.error("Couldn't set icon", (Throwable)iOException4);
}
}
@Nullable
private ByteBuffer readIconPixels(final InputStream inputStream, final IntBuffer intBuffer2, final IntBuffer intBuffer3, final IntBuffer intBuffer4) throws IOException {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
ByteBuffer byteBuffer6 = null;
try {
byteBuffer6 = TextureUtil.readResource(inputStream);
byteBuffer6.rewind();
return STBImage.stbi_load_from_memory(byteBuffer6, intBuffer2, intBuffer3, intBuffer4, 0);
}
finally {
if (byteBuffer6 != null) {
MemoryUtil.memFree((Buffer)byteBuffer6);
}
}
}
public void setErrorSection(final String string) {
this.errorSection = string;
}
private void setBootErrorCallback() {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
GLFW.glfwSetErrorCallback(Window::bootCrash);
}
private static void bootCrash(final int integer, final long long2) {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
final String string4 = "GLFW error " + integer + ": " + MemoryUtil.memUTF8(long2);
TinyFileDialogs.tinyfd_messageBox((CharSequence)"Minecraft", (CharSequence)(string4 + ".\n\nPlease make sure you have up-to-date drivers (see aka.ms/mcdriver for instructions)."), (CharSequence)"ok", (CharSequence)"error", false);
throw new WindowInitFailed(string4);
}
public void defaultErrorCallback(final int integer, final long long2) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
final String string5 = MemoryUtil.memUTF8(long2);
Window.LOGGER.error("########## GL ERROR ##########");
Window.LOGGER.error("@ {}", this.errorSection);
Window.LOGGER.error("{}: {}", integer, string5);
}
public void setDefaultErrorCallback() {
final GLFWErrorCallback gLFWErrorCallback2 = GLFW.glfwSetErrorCallback((GLFWErrorCallbackI)this.defaultErrorCallback);
if (gLFWErrorCallback2 != null) {
gLFWErrorCallback2.free();
}
}
public void updateVsync(final boolean boolean1) {
RenderSystem.assertThread(RenderSystem::isOnRenderThreadOrInit);
GLFW.glfwSwapInterval((int)((this.vsync = boolean1) ? 1 : 0));
}
@Override
public void close() {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
Callbacks.glfwFreeCallbacks(this.window);
this.defaultErrorCallback.close();
GLFW.glfwDestroyWindow(this.window);
GLFW.glfwTerminate();
}
private void onMove(final long long1, final int integer2, final int integer3) {
this.x = integer2;
this.y = integer3;
}
private void onFramebufferResize(final long long1, final int integer2, final int integer3) {
if (long1 != this.window) {
return;
}
final int integer4 = this.getWidth();
final int integer5 = this.getHeight();
if (integer2 == 0 || integer3 == 0) {
return;
}
this.framebufferWidth = integer2;
this.framebufferHeight = integer3;
if (this.getWidth() != integer4 || this.getHeight() != integer5) {
this.eventHandler.resizeDisplay();
}
}
private void refreshFramebufferSize() {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
final int[] arr2 = { 0 };
final int[] arr3 = { 0 };
GLFW.glfwGetFramebufferSize(this.window, arr2, arr3);
this.framebufferWidth = arr2[0];
this.framebufferHeight = arr3[0];
}
private void onResize(final long long1, final int integer2, final int integer3) {
this.width = integer2;
this.height = integer3;
}
private void onFocus(final long long1, final boolean boolean2) {
if (long1 == this.window) {
this.eventHandler.setWindowActive(boolean2);
}
}
private void onEnter(final long long1, final boolean boolean2) {
if (boolean2) {
this.eventHandler.cursorEntered();
}
}
public void setFramerateLimit(final int integer) {
this.framerateLimit = integer;
}
public int getFramerateLimit() {
return this.framerateLimit;
}
public void updateDisplay() {
RenderSystem.flipFrame(this.window);
if (this.fullscreen != this.actuallyFullscreen) {
this.actuallyFullscreen = this.fullscreen;
this.updateFullscreen(this.vsync);
}
}
public Optional<VideoMode> getPreferredFullscreenVideoMode() {
return this.preferredFullscreenVideoMode;
}
public void setPreferredFullscreenVideoMode(final Optional<VideoMode> optional) {
final boolean boolean3 = !optional.equals(this.preferredFullscreenVideoMode);
this.preferredFullscreenVideoMode = optional;
if (boolean3) {
this.dirty = true;
}
}
public void changeFullscreenVideoMode() {
if (this.fullscreen && this.dirty) {
this.dirty = false;
this.setMode();
this.eventHandler.resizeDisplay();
}
}
private void setMode() {
RenderSystem.assertThread(RenderSystem::isInInitPhase);
final boolean boolean2 = GLFW.glfwGetWindowMonitor(this.window) != 0L;
if (this.fullscreen) {
final Monitor dgq3 = this.screenManager.findBestMonitor(this);
if (dgq3 == null) {
Window.LOGGER.warn("Failed to find suitable monitor for fullscreen mode");
this.fullscreen = false;
}
else {
final VideoMode dgx4 = dgq3.getPreferredVidMode(this.preferredFullscreenVideoMode);
if (!boolean2) {
this.windowedX = this.x;
this.windowedY = this.y;
this.windowedWidth = this.width;
this.windowedHeight = this.height;
}
this.x = 0;
this.y = 0;
this.width = dgx4.getWidth();
this.height = dgx4.getHeight();
GLFW.glfwSetWindowMonitor(this.window, dgq3.getMonitor(), this.x, this.y, this.width, this.height, dgx4.getRefreshRate());
}
}
else {
this.x = this.windowedX;
this.y = this.windowedY;
this.width = this.windowedWidth;
this.height = this.windowedHeight;
GLFW.glfwSetWindowMonitor(this.window, 0L, this.x, this.y, this.width, this.height, -1);
}
}
public void toggleFullScreen() {
this.fullscreen = !this.fullscreen;
}
private void updateFullscreen(final boolean boolean1) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
try {
this.setMode();
this.eventHandler.resizeDisplay();
this.updateVsync(boolean1);
this.updateDisplay();
}
catch (Exception exception3) {
Window.LOGGER.error("Couldn't toggle fullscreen", (Throwable)exception3);
}
}
public int calculateScale(final int integer, final boolean boolean2) {
int integer2;
for (integer2 = 1; integer2 != integer && integer2 < this.framebufferWidth && integer2 < this.framebufferHeight && this.framebufferWidth / (integer2 + 1) >= 320 && this.framebufferHeight / (integer2 + 1) >= 240; ++integer2) {}
if (boolean2 && integer2 % 2 != 0) {
++integer2;
}
return integer2;
}
public void setGuiScale(final double double1) {
this.guiScale = double1;
final int integer4 = (int)(this.framebufferWidth / double1);
this.guiScaledWidth = ((this.framebufferWidth / double1 > integer4) ? (integer4 + 1) : integer4);
final int integer5 = (int)(this.framebufferHeight / double1);
this.guiScaledHeight = ((this.framebufferHeight / double1 > integer5) ? (integer5 + 1) : integer5);
}
public void setTitle(final String string) {
GLFW.glfwSetWindowTitle(this.window, (CharSequence)string);
}
public long getWindow() {
return this.window;
}
public boolean isFullscreen() {
return this.fullscreen;
}
public int getWidth() {
return this.framebufferWidth;
}
public int getHeight() {
return this.framebufferHeight;
}
public int getScreenWidth() {
return this.width;
}
public int getScreenHeight() {
return this.height;
}
public int getGuiScaledWidth() {
return this.guiScaledWidth;
}
public int getGuiScaledHeight() {
return this.guiScaledHeight;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public double getGuiScale() {
return this.guiScale;
}
@Nullable
public Monitor findBestMonitor() {
return this.screenManager.findBestMonitor(this);
}
public void updateRawMouseInput(final boolean boolean1) {
InputConstants.updateRawMouseInput(this.window, boolean1);
}
static {
LOGGER = LogManager.getLogger();
}
public static class WindowInitFailed extends SilentInitException {
private WindowInitFailed(final String string) {
super(string);
}
}
}

View File

@ -0,0 +1,9 @@
package com.mojang.blaze3d.platform;
public interface WindowEventHandler {
void setWindowActive(final boolean boolean1);
void resizeDisplay();
void cursorEntered();
}

View File

@ -0,0 +1,29 @@
package com.mojang.blaze3d.shaders;
import com.mojang.math.Matrix4f;
public class AbstractUniform {
public void set(final float float1) {
}
public void set(final float float1, final float float2) {
}
public void set(final float float1, final float float2, final float float3) {
}
public void set(final float float1, final float float2, final float float3, final float float4) {
}
public void setSafe(final float float1, final float float2, final float float3, final float float4) {
}
public void setSafe(final int integer1, final int integer2, final int integer3, final int integer4) {
}
public void set(final float[] arr) {
}
public void set(final Matrix4f b) {
}
}

View File

@ -0,0 +1,148 @@
package com.mojang.blaze3d.shaders;
import java.util.Locale;
import com.mojang.blaze3d.systems.RenderSystem;
public class BlendMode {
private static BlendMode lastApplied;
private final int srcColorFactor;
private final int srcAlphaFactor;
private final int dstColorFactor;
private final int dstAlphaFactor;
private final int blendFunc;
private final boolean separateBlend;
private final boolean opaque;
private BlendMode(final boolean boolean1, final boolean boolean2, final int integer3, final int integer4, final int integer5, final int integer6, final int integer7) {
this.separateBlend = boolean1;
this.srcColorFactor = integer3;
this.dstColorFactor = integer4;
this.srcAlphaFactor = integer5;
this.dstAlphaFactor = integer6;
this.opaque = boolean2;
this.blendFunc = integer7;
}
public BlendMode() {
this(false, true, 1, 0, 1, 0, 32774);
}
public BlendMode(final int integer1, final int integer2, final int integer3) {
this(false, false, integer1, integer2, integer1, integer2, integer3);
}
public BlendMode(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5) {
this(true, false, integer1, integer2, integer3, integer4, integer5);
}
public void apply() {
if (this.equals(BlendMode.lastApplied)) {
return;
}
if (BlendMode.lastApplied == null || this.opaque != BlendMode.lastApplied.isOpaque()) {
BlendMode.lastApplied = this;
if (this.opaque) {
RenderSystem.disableBlend();
return;
}
RenderSystem.enableBlend();
}
RenderSystem.blendEquation(this.blendFunc);
if (this.separateBlend) {
RenderSystem.blendFuncSeparate(this.srcColorFactor, this.dstColorFactor, this.srcAlphaFactor, this.dstAlphaFactor);
}
else {
RenderSystem.blendFunc(this.srcColorFactor, this.dstColorFactor);
}
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (!(object instanceof BlendMode)) {
return false;
}
final BlendMode dhb3 = (BlendMode)object;
return this.blendFunc == dhb3.blendFunc && this.dstAlphaFactor == dhb3.dstAlphaFactor && this.dstColorFactor == dhb3.dstColorFactor && this.opaque == dhb3.opaque && this.separateBlend == dhb3.separateBlend && this.srcAlphaFactor == dhb3.srcAlphaFactor && this.srcColorFactor == dhb3.srcColorFactor;
}
@Override
public int hashCode() {
int integer2 = this.srcColorFactor;
integer2 = 31 * integer2 + this.srcAlphaFactor;
integer2 = 31 * integer2 + this.dstColorFactor;
integer2 = 31 * integer2 + this.dstAlphaFactor;
integer2 = 31 * integer2 + this.blendFunc;
integer2 = 31 * integer2 + (this.separateBlend ? 1 : 0);
integer2 = 31 * integer2 + (this.opaque ? 1 : 0);
return integer2;
}
public boolean isOpaque() {
return this.opaque;
}
public static int stringToBlendFunc(final String string) {
final String string2 = string.trim().toLowerCase(Locale.ROOT);
if ("add".equals(string2)) {
return 32774;
}
if ("subtract".equals(string2)) {
return 32778;
}
if ("reversesubtract".equals(string2)) {
return 32779;
}
if ("reverse_subtract".equals(string2)) {
return 32779;
}
if ("min".equals(string2)) {
return 32775;
}
if ("max".equals(string2)) {
return 32776;
}
return 32774;
}
public static int stringToBlendFactor(final String string) {
String string2 = string.trim().toLowerCase(Locale.ROOT);
string2 = string2.replaceAll("_", "");
string2 = string2.replaceAll("one", "1");
string2 = string2.replaceAll("zero", "0");
string2 = string2.replaceAll("minus", "-");
if ("0".equals(string2)) {
return 0;
}
if ("1".equals(string2)) {
return 1;
}
if ("srccolor".equals(string2)) {
return 768;
}
if ("1-srccolor".equals(string2)) {
return 769;
}
if ("dstcolor".equals(string2)) {
return 774;
}
if ("1-dstcolor".equals(string2)) {
return 775;
}
if ("srcalpha".equals(string2)) {
return 770;
}
if ("1-srcalpha".equals(string2)) {
return 771;
}
if ("dstalpha".equals(string2)) {
return 772;
}
if ("1-dstalpha".equals(string2)) {
return 773;
}
return -1;
}
}

View File

@ -0,0 +1,11 @@
package com.mojang.blaze3d.shaders;
public interface Effect {
int getId();
void markDirty();
Program getVertexProgram();
Program getFragmentProgram();
}

View File

@ -0,0 +1,93 @@
package com.mojang.blaze3d.shaders;
import com.google.common.collect.Maps;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import com.mojang.blaze3d.platform.TextureUtil;
import java.io.InputStream;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
public class Program {
private final Type type;
private final String name;
private final int id;
private int references;
private Program(final Type a, final int integer, final String string) {
this.type = a;
this.id = integer;
this.name = string;
}
public void attachToEffect(final Effect dhc) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
++this.references;
GlStateManager.glAttachShader(dhc.getId(), this.id);
}
public void close() {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
--this.references;
if (this.references <= 0) {
GlStateManager.glDeleteShader(this.id);
this.type.getPrograms().remove(this.name);
}
}
public String getName() {
return this.name;
}
public static Program compileShader(final Type a, final String string, final InputStream inputStream) throws IOException {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
final String string2 = TextureUtil.readResourceAsString(inputStream);
if (string2 == null) {
throw new IOException("Could not load program " + a.getName());
}
final int integer5 = GlStateManager.glCreateShader(a.getGlType());
GlStateManager.glShaderSource(integer5, string2);
GlStateManager.glCompileShader(integer5);
if (GlStateManager.glGetShaderi(integer5, 35713) == 0) {
final String string3 = StringUtils.trim(GlStateManager.glGetShaderInfoLog(integer5, 32768));
throw new IOException("Couldn't compile " + a.getName() + " program: " + string3);
}
final Program dhd6 = new Program(a, integer5, string);
a.getPrograms().put(string, dhd6);
return dhd6;
}
public enum Type {
VERTEX("vertex", ".vsh", 35633),
FRAGMENT("fragment", ".fsh", 35632);
private final String name;
private final String extension;
private final int glType;
private final Map<String, Program> programs;
private Type(final String string3, final String string4, final int integer5) {
this.programs = Maps.newHashMap();
this.name = string3;
this.extension = string4;
this.glType = integer5;
}
public String getName() {
return this.name;
}
public String getExtension() {
return this.extension;
}
private int getGlType() {
return this.glType;
}
public Map<String, Program> getPrograms() {
return this.programs;
}
}
}

View File

@ -0,0 +1,48 @@
package com.mojang.blaze3d.shaders;
import org.apache.logging.log4j.LogManager;
import java.io.IOException;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import org.apache.logging.log4j.Logger;
public class ProgramManager {
private static final Logger LOGGER;
public static void glUseProgram(final int integer) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
GlStateManager._glUseProgram(integer);
}
public static void releaseProgram(final Effect dhc) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
dhc.getFragmentProgram().close();
dhc.getVertexProgram().close();
GlStateManager.glDeleteProgram(dhc.getId());
}
public static int createProgram() throws IOException {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
final int integer1 = GlStateManager.glCreateProgram();
if (integer1 <= 0) {
throw new IOException("Could not create shader program (returned program ID " + integer1 + ")");
}
return integer1;
}
public static void linkProgram(final Effect dhc) throws IOException {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
dhc.getFragmentProgram().attachToEffect(dhc);
dhc.getVertexProgram().attachToEffect(dhc);
GlStateManager.glLinkProgram(dhc.getId());
final int integer2 = GlStateManager.glGetProgrami(dhc.getId(), 35714);
if (integer2 == 0) {
ProgramManager.LOGGER.warn("Error encountered when linking program containing VS {} and FS {}. Log output:", dhc.getVertexProgram().getName(), dhc.getFragmentProgram().getName());
ProgramManager.LOGGER.warn(GlStateManager.glGetProgramInfoLog(dhc.getId(), 32768));
}
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,281 @@
package com.mojang.blaze3d.shaders;
import org.apache.logging.log4j.LogManager;
import com.mojang.math.Matrix4f;
import java.nio.Buffer;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.platform.GlStateManager;
import org.lwjgl.system.MemoryUtil;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.apache.logging.log4j.Logger;
public class Uniform extends AbstractUniform implements AutoCloseable {
private static final Logger LOGGER;
private int location;
private final int count;
private final int type;
private final IntBuffer intValues;
private final FloatBuffer floatValues;
private final String name;
private boolean dirty;
private final Effect parent;
public Uniform(final String string, final int integer2, final int integer3, final Effect dhc) {
this.name = string;
this.count = integer3;
this.type = integer2;
this.parent = dhc;
if (integer2 <= 3) {
this.intValues = MemoryUtil.memAllocInt(integer3);
this.floatValues = null;
}
else {
this.intValues = null;
this.floatValues = MemoryUtil.memAllocFloat(integer3);
}
this.location = -1;
this.markDirty();
}
public static int glGetUniformLocation(final int integer, final CharSequence charSequence) {
return GlStateManager._glGetUniformLocation(integer, charSequence);
}
public static void uploadInteger(final int integer1, final int integer2) {
RenderSystem.glUniform1i(integer1, integer2);
}
public static int glGetAttribLocation(final int integer, final CharSequence charSequence) {
return GlStateManager._glGetAttribLocation(integer, charSequence);
}
@Override
public void close() {
if (this.intValues != null) {
MemoryUtil.memFree((Buffer)this.intValues);
}
if (this.floatValues != null) {
MemoryUtil.memFree((Buffer)this.floatValues);
}
}
private void markDirty() {
this.dirty = true;
if (this.parent != null) {
this.parent.markDirty();
}
}
public static int getTypeFromString(final String string) {
int integer2 = -1;
if ("int".equals(string)) {
integer2 = 0;
}
else if ("float".equals(string)) {
integer2 = 4;
}
else if (string.startsWith("matrix")) {
if (string.endsWith("2x2")) {
integer2 = 8;
}
else if (string.endsWith("3x3")) {
integer2 = 9;
}
else if (string.endsWith("4x4")) {
integer2 = 10;
}
}
return integer2;
}
public void setLocation(final int integer) {
this.location = integer;
}
public String getName() {
return this.name;
}
@Override
public void set(final float float1) {
this.floatValues.position(0);
this.floatValues.put(0, float1);
this.markDirty();
}
@Override
public void set(final float float1, final float float2) {
this.floatValues.position(0);
this.floatValues.put(0, float1);
this.floatValues.put(1, float2);
this.markDirty();
}
@Override
public void set(final float float1, final float float2, final float float3) {
this.floatValues.position(0);
this.floatValues.put(0, float1);
this.floatValues.put(1, float2);
this.floatValues.put(2, float3);
this.markDirty();
}
@Override
public void set(final float float1, final float float2, final float float3, final float float4) {
this.floatValues.position(0);
this.floatValues.put(float1);
this.floatValues.put(float2);
this.floatValues.put(float3);
this.floatValues.put(float4);
this.floatValues.flip();
this.markDirty();
}
@Override
public void setSafe(final float float1, final float float2, final float float3, final float float4) {
this.floatValues.position(0);
if (this.type >= 4) {
this.floatValues.put(0, float1);
}
if (this.type >= 5) {
this.floatValues.put(1, float2);
}
if (this.type >= 6) {
this.floatValues.put(2, float3);
}
if (this.type >= 7) {
this.floatValues.put(3, float4);
}
this.markDirty();
}
@Override
public void setSafe(final int integer1, final int integer2, final int integer3, final int integer4) {
this.intValues.position(0);
if (this.type >= 0) {
this.intValues.put(0, integer1);
}
if (this.type >= 1) {
this.intValues.put(1, integer2);
}
if (this.type >= 2) {
this.intValues.put(2, integer3);
}
if (this.type >= 3) {
this.intValues.put(3, integer4);
}
this.markDirty();
}
@Override
public void set(final float[] arr) {
if (arr.length < this.count) {
Uniform.LOGGER.warn("Uniform.set called with a too-small value array (expected {}, got {}). Ignoring.", this.count, arr.length);
return;
}
this.floatValues.position(0);
this.floatValues.put(arr);
this.floatValues.position(0);
this.markDirty();
}
@Override
public void set(final Matrix4f b) {
this.floatValues.position(0);
b.store(this.floatValues);
this.markDirty();
}
public void upload() {
if (!this.dirty) {}
this.dirty = false;
if (this.type <= 3) {
this.uploadAsInteger();
}
else if (this.type <= 7) {
this.uploadAsFloat();
}
else {
if (this.type > 10) {
Uniform.LOGGER.warn("Uniform.upload called, but type value ({}) is not a valid type. Ignoring.", this.type);
return;
}
this.uploadAsMatrix();
}
}
private void uploadAsInteger() {
this.floatValues.clear();
switch (this.type) {
case 0: {
RenderSystem.glUniform1(this.location, this.intValues);
break;
}
case 1: {
RenderSystem.glUniform2(this.location, this.intValues);
break;
}
case 2: {
RenderSystem.glUniform3(this.location, this.intValues);
break;
}
case 3: {
RenderSystem.glUniform4(this.location, this.intValues);
break;
}
default: {
Uniform.LOGGER.warn("Uniform.upload called, but count value ({}) is not in the range of 1 to 4. Ignoring.", this.count);
break;
}
}
}
private void uploadAsFloat() {
this.floatValues.clear();
switch (this.type) {
case 4: {
RenderSystem.glUniform1(this.location, this.floatValues);
break;
}
case 5: {
RenderSystem.glUniform2(this.location, this.floatValues);
break;
}
case 6: {
RenderSystem.glUniform3(this.location, this.floatValues);
break;
}
case 7: {
RenderSystem.glUniform4(this.location, this.floatValues);
break;
}
default: {
Uniform.LOGGER.warn("Uniform.upload called, but count value ({}) is not in the range of 1 to 4. Ignoring.", this.count);
break;
}
}
}
private void uploadAsMatrix() {
this.floatValues.clear();
switch (this.type) {
case 8: {
RenderSystem.glUniformMatrix2(this.location, false, this.floatValues);
break;
}
case 9: {
RenderSystem.glUniformMatrix3(this.location, false, this.floatValues);
break;
}
case 10: {
RenderSystem.glUniformMatrix4(this.location, false, this.floatValues);
break;
}
}
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,814 @@
package com.mojang.blaze3d.systems;
import com.google.common.collect.Queues;
import org.apache.logging.log4j.LogManager;
import net.minecraft.client.Options;
import net.minecraft.client.GraphicsStatus;
import net.minecraft.client.Minecraft;
import com.mojang.math.Vector3f;
import java.util.function.IntSupplier;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import java.util.function.LongSupplier;
import com.mojang.blaze3d.platform.GLX;
import java.util.function.Consumer;
import java.nio.ByteBuffer;
import com.mojang.math.Matrix4f;
import com.mojang.blaze3d.platform.GlStateManager;
import org.lwjgl.glfw.GLFW;
import java.util.function.Supplier;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.pipeline.RenderCall;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.logging.log4j.Logger;
public class RenderSystem {
private static final Logger LOGGER;
private static final ConcurrentLinkedQueue<RenderCall> recordingQueue;
private static final Tesselator RENDER_THREAD_TESSELATOR;
public static final float DEFAULTALPHACUTOFF = 0.1f;
private static final int MINIMUM_ATLAS_TEXTURE_SIZE = 1024;
private static boolean isReplayingQueue;
private static Thread gameThread;
private static Thread renderThread;
private static int MAX_SUPPORTED_TEXTURE_SIZE;
private static boolean isInInit;
private static double lastDrawTime;
public static void initRenderThread() {
if (RenderSystem.renderThread != null || RenderSystem.gameThread == Thread.currentThread()) {
throw new IllegalStateException("Could not initialize render thread");
}
RenderSystem.renderThread = Thread.currentThread();
}
public static boolean isOnRenderThread() {
return Thread.currentThread() == RenderSystem.renderThread;
}
public static boolean isOnRenderThreadOrInit() {
return RenderSystem.isInInit || isOnRenderThread();
}
public static void initGameThread(final boolean boolean1) {
final boolean boolean2 = RenderSystem.renderThread == Thread.currentThread();
if (RenderSystem.gameThread != null || RenderSystem.renderThread == null || boolean2 == boolean1) {
throw new IllegalStateException("Could not initialize tick thread");
}
RenderSystem.gameThread = Thread.currentThread();
}
public static boolean isOnGameThread() {
return true;
}
public static boolean isOnGameThreadOrInit() {
return RenderSystem.isInInit || isOnGameThread();
}
public static void assertThread(final Supplier<Boolean> supplier) {
if (!supplier.get()) {
throw new IllegalStateException("Rendersystem called from wrong thread");
}
}
public static boolean isInInitPhase() {
return true;
}
public static void recordRenderCall(final RenderCall dgd) {
RenderSystem.recordingQueue.add(dgd);
}
public static void flipFrame(final long long1) {
GLFW.glfwPollEvents();
replayQueue();
Tesselator.getInstance().getBuilder().clear();
GLFW.glfwSwapBuffers(long1);
GLFW.glfwPollEvents();
}
public static void replayQueue() {
RenderSystem.isReplayingQueue = true;
while (!RenderSystem.recordingQueue.isEmpty()) {
final RenderCall dgd1 = RenderSystem.recordingQueue.poll();
dgd1.execute();
}
RenderSystem.isReplayingQueue = false;
}
public static void limitDisplayFPS(final int integer) {
double double2;
double double3;
for (double2 = RenderSystem.lastDrawTime + 1.0 / integer, double3 = GLFW.glfwGetTime(); double3 < double2; double3 = GLFW.glfwGetTime()) {
GLFW.glfwWaitEventsTimeout(double2 - double3);
}
RenderSystem.lastDrawTime = double3;
}
@Deprecated
public static void pushLightingAttributes() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._pushLightingAttributes();
}
@Deprecated
public static void pushTextureAttributes() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._pushTextureAttributes();
}
@Deprecated
public static void popAttributes() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._popAttributes();
}
@Deprecated
public static void disableAlphaTest() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableAlphaTest();
}
@Deprecated
public static void enableAlphaTest() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableAlphaTest();
}
@Deprecated
public static void alphaFunc(final int integer, final float float2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._alphaFunc(integer, float2);
}
@Deprecated
public static void enableLighting() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableLighting();
}
@Deprecated
public static void disableLighting() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableLighting();
}
@Deprecated
public static void enableColorMaterial() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableColorMaterial();
}
@Deprecated
public static void disableColorMaterial() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableColorMaterial();
}
@Deprecated
public static void colorMaterial(final int integer1, final int integer2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._colorMaterial(integer1, integer2);
}
@Deprecated
public static void normal3f(final float float1, final float float2, final float float3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._normal3f(float1, float2, float3);
}
public static void disableDepthTest() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableDepthTest();
}
public static void enableDepthTest() {
assertThread(RenderSystem::isOnGameThreadOrInit);
GlStateManager._enableDepthTest();
}
public static void depthFunc(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._depthFunc(integer);
}
public static void depthMask(final boolean boolean1) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._depthMask(boolean1);
}
public static void enableBlend() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableBlend();
}
public static void disableBlend() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableBlend();
}
public static void blendFunc(final GlStateManager.SourceFactor q, final GlStateManager.DestFactor j) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._blendFunc(q.value, j.value);
}
public static void blendFunc(final int integer1, final int integer2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._blendFunc(integer1, integer2);
}
public static void blendFuncSeparate(final GlStateManager.SourceFactor q1, final GlStateManager.DestFactor j2, final GlStateManager.SourceFactor q3, final GlStateManager.DestFactor j4) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._blendFuncSeparate(q1.value, j2.value, q3.value, j4.value);
}
public static void blendFuncSeparate(final int integer1, final int integer2, final int integer3, final int integer4) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._blendFuncSeparate(integer1, integer2, integer3, integer4);
}
public static void blendEquation(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._blendEquation(integer);
}
public static void blendColor(final float float1, final float float2, final float float3, final float float4) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._blendColor(float1, float2, float3, float4);
}
@Deprecated
public static void enableFog() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableFog();
}
@Deprecated
public static void disableFog() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableFog();
}
@Deprecated
public static void fogMode(final GlStateManager.FogMode m) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._fogMode(m.value);
}
@Deprecated
public static void fogMode(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._fogMode(integer);
}
@Deprecated
public static void fogDensity(final float float1) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._fogDensity(float1);
}
@Deprecated
public static void fogStart(final float float1) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._fogStart(float1);
}
@Deprecated
public static void fogEnd(final float float1) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._fogEnd(float1);
}
@Deprecated
public static void fog(final int integer, final float float2, final float float3, final float float4, final float float5) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._fog(integer, new float[] { float2, float3, float4, float5 });
}
@Deprecated
public static void fogi(final int integer1, final int integer2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._fogi(integer1, integer2);
}
public static void enableCull() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableCull();
}
public static void disableCull() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableCull();
}
public static void polygonMode(final int integer1, final int integer2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._polygonMode(integer1, integer2);
}
public static void enablePolygonOffset() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enablePolygonOffset();
}
public static void disablePolygonOffset() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disablePolygonOffset();
}
public static void enableLineOffset() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableLineOffset();
}
public static void disableLineOffset() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableLineOffset();
}
public static void polygonOffset(final float float1, final float float2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._polygonOffset(float1, float2);
}
public static void enableColorLogicOp() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableColorLogicOp();
}
public static void disableColorLogicOp() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableColorLogicOp();
}
public static void logicOp(final GlStateManager.LogicOp o) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._logicOp(o.value);
}
public static void activeTexture(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._activeTexture(integer);
}
public static void enableTexture() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableTexture();
}
public static void disableTexture() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableTexture();
}
public static void texParameter(final int integer1, final int integer2, final int integer3) {
GlStateManager._texParameter(integer1, integer2, integer3);
}
public static void deleteTexture(final int integer) {
assertThread(RenderSystem::isOnGameThreadOrInit);
GlStateManager._deleteTexture(integer);
}
public static void bindTexture(final int integer) {
GlStateManager._bindTexture(integer);
}
@Deprecated
public static void shadeModel(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._shadeModel(integer);
}
@Deprecated
public static void enableRescaleNormal() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._enableRescaleNormal();
}
@Deprecated
public static void disableRescaleNormal() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._disableRescaleNormal();
}
public static void viewport(final int integer1, final int integer2, final int integer3, final int integer4) {
assertThread(RenderSystem::isOnGameThreadOrInit);
GlStateManager._viewport(integer1, integer2, integer3, integer4);
}
public static void colorMask(final boolean boolean1, final boolean boolean2, final boolean boolean3, final boolean boolean4) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._colorMask(boolean1, boolean2, boolean3, boolean4);
}
public static void stencilFunc(final int integer1, final int integer2, final int integer3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._stencilFunc(integer1, integer2, integer3);
}
public static void stencilMask(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._stencilMask(integer);
}
public static void stencilOp(final int integer1, final int integer2, final int integer3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._stencilOp(integer1, integer2, integer3);
}
public static void clearDepth(final double double1) {
assertThread(RenderSystem::isOnGameThreadOrInit);
GlStateManager._clearDepth(double1);
}
public static void clearColor(final float float1, final float float2, final float float3, final float float4) {
assertThread(RenderSystem::isOnGameThreadOrInit);
GlStateManager._clearColor(float1, float2, float3, float4);
}
public static void clearStencil(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._clearStencil(integer);
}
public static void clear(final int integer, final boolean boolean2) {
assertThread(RenderSystem::isOnGameThreadOrInit);
GlStateManager._clear(integer, boolean2);
}
@Deprecated
public static void matrixMode(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._matrixMode(integer);
}
@Deprecated
public static void loadIdentity() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._loadIdentity();
}
@Deprecated
public static void pushMatrix() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._pushMatrix();
}
@Deprecated
public static void popMatrix() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._popMatrix();
}
@Deprecated
public static void ortho(final double double1, final double double2, final double double3, final double double4, final double double5, final double double6) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._ortho(double1, double2, double3, double4, double5, double6);
}
@Deprecated
public static void rotatef(final float float1, final float float2, final float float3, final float float4) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._rotatef(float1, float2, float3, float4);
}
@Deprecated
public static void scalef(final float float1, final float float2, final float float3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._scalef(float1, float2, float3);
}
@Deprecated
public static void scaled(final double double1, final double double2, final double double3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._scaled(double1, double2, double3);
}
@Deprecated
public static void translatef(final float float1, final float float2, final float float3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._translatef(float1, float2, float3);
}
@Deprecated
public static void translated(final double double1, final double double2, final double double3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._translated(double1, double2, double3);
}
@Deprecated
public static void multMatrix(final Matrix4f b) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._multMatrix(b);
}
@Deprecated
public static void color4f(final float float1, final float float2, final float float3, final float float4) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._color4f(float1, float2, float3, float4);
}
@Deprecated
public static void color3f(final float float1, final float float2, final float float3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._color4f(float1, float2, float3, 1.0f);
}
@Deprecated
public static void clearCurrentColor() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._clearCurrentColor();
}
public static void drawArrays(final int integer1, final int integer2, final int integer3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._drawArrays(integer1, integer2, integer3);
}
public static void lineWidth(final float float1) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._lineWidth(float1);
}
public static void pixelStore(final int integer1, final int integer2) {
assertThread(RenderSystem::isOnGameThreadOrInit);
GlStateManager._pixelStore(integer1, integer2);
}
public static void pixelTransfer(final int integer, final float float2) {
GlStateManager._pixelTransfer(integer, float2);
}
public static void readPixels(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6, final ByteBuffer byteBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._readPixels(integer1, integer2, integer3, integer4, integer5, integer6, byteBuffer);
}
public static void getString(final int integer, final Consumer<String> consumer) {
assertThread(RenderSystem::isOnGameThread);
consumer.accept(GlStateManager._getString(integer));
}
public static String getBackendDescription() {
assertThread(RenderSystem::isInInitPhase);
return String.format("LWJGL version %s", GLX._getLWJGLVersion());
}
public static String getApiDescription() {
assertThread(RenderSystem::isInInitPhase);
return GLX.getOpenGLVersionString();
}
public static LongSupplier initBackendSystem() {
assertThread(RenderSystem::isInInitPhase);
return GLX._initGlfw();
}
public static void initRenderer(final int integer, final boolean boolean2) {
assertThread(RenderSystem::isInInitPhase);
GLX._init(integer, boolean2);
}
public static void setErrorCallback(final GLFWErrorCallbackI gLFWErrorCallbackI) {
assertThread(RenderSystem::isInInitPhase);
GLX._setGlfwErrorCallback(gLFWErrorCallbackI);
}
public static void renderCrosshair(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GLX._renderCrosshair(integer, true, true, true);
}
public static void setupNvFogDistance() {
assertThread(RenderSystem::isOnGameThread);
GLX._setupNvFogDistance();
}
@Deprecated
public static void glMultiTexCoord2f(final int integer, final float float2, final float float3) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glMultiTexCoord2f(integer, float2, float3);
}
public static String getCapsString() {
assertThread(RenderSystem::isOnGameThread);
return GLX._getCapsString();
}
public static void setupDefaultState(final int integer1, final int integer2, final int integer3, final int integer4) {
assertThread(RenderSystem::isInInitPhase);
GlStateManager._enableTexture();
GlStateManager._shadeModel(7425);
GlStateManager._clearDepth(1.0);
GlStateManager._enableDepthTest();
GlStateManager._depthFunc(515);
GlStateManager._enableAlphaTest();
GlStateManager._alphaFunc(516, 0.1f);
GlStateManager._matrixMode(5889);
GlStateManager._loadIdentity();
GlStateManager._matrixMode(5888);
GlStateManager._viewport(integer1, integer2, integer3, integer4);
}
public static int maxSupportedTextureSize() {
assertThread(RenderSystem::isInInitPhase);
if (RenderSystem.MAX_SUPPORTED_TEXTURE_SIZE == -1) {
final int integer1 = GlStateManager._getInteger(3379);
for (int integer2 = Math.max(32768, integer1); integer2 >= 1024; integer2 >>= 1) {
GlStateManager._texImage2D(32868, 0, 6408, integer2, integer2, 0, 6408, 5121, null);
final int integer3 = GlStateManager._getTexLevelParameter(32868, 0, 4096);
if (integer3 != 0) {
return RenderSystem.MAX_SUPPORTED_TEXTURE_SIZE = integer2;
}
}
RenderSystem.MAX_SUPPORTED_TEXTURE_SIZE = Math.max(integer1, 1024);
RenderSystem.LOGGER.info("Failed to determine maximum texture size by probing, trying GL_MAX_TEXTURE_SIZE = {}", RenderSystem.MAX_SUPPORTED_TEXTURE_SIZE);
}
return RenderSystem.MAX_SUPPORTED_TEXTURE_SIZE;
}
public static void glBindBuffer(final int integer, final Supplier<Integer> supplier) {
GlStateManager._glBindBuffer(integer, supplier.get());
}
public static void glBufferData(final int integer1, final ByteBuffer byteBuffer, final int integer3) {
assertThread(RenderSystem::isOnRenderThreadOrInit);
GlStateManager._glBufferData(integer1, byteBuffer, integer3);
}
public static void glDeleteBuffers(final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glDeleteBuffers(integer);
}
public static void glUniform1i(final int integer1, final int integer2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform1i(integer1, integer2);
}
public static void glUniform1(final int integer, final IntBuffer intBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform1(integer, intBuffer);
}
public static void glUniform2(final int integer, final IntBuffer intBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform2(integer, intBuffer);
}
public static void glUniform3(final int integer, final IntBuffer intBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform3(integer, intBuffer);
}
public static void glUniform4(final int integer, final IntBuffer intBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform4(integer, intBuffer);
}
public static void glUniform1(final int integer, final FloatBuffer floatBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform1(integer, floatBuffer);
}
public static void glUniform2(final int integer, final FloatBuffer floatBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform2(integer, floatBuffer);
}
public static void glUniform3(final int integer, final FloatBuffer floatBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform3(integer, floatBuffer);
}
public static void glUniform4(final int integer, final FloatBuffer floatBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniform4(integer, floatBuffer);
}
public static void glUniformMatrix2(final int integer, final boolean boolean2, final FloatBuffer floatBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniformMatrix2(integer, boolean2, floatBuffer);
}
public static void glUniformMatrix3(final int integer, final boolean boolean2, final FloatBuffer floatBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniformMatrix3(integer, boolean2, floatBuffer);
}
public static void glUniformMatrix4(final int integer, final boolean boolean2, final FloatBuffer floatBuffer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager._glUniformMatrix4(integer, boolean2, floatBuffer);
}
public static void setupOutline() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.setupOutline();
}
public static void teardownOutline() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.teardownOutline();
}
public static void setupOverlayColor(final IntSupplier intSupplier, final int integer) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.setupOverlayColor(intSupplier.getAsInt(), integer);
}
public static void teardownOverlayColor() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.teardownOverlayColor();
}
public static void setupLevelDiffuseLighting(final Vector3f g1, final Vector3f g2, final Matrix4f b) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.setupLevelDiffuseLighting(g1, g2, b);
}
public static void setupGuiFlatDiffuseLighting(final Vector3f g1, final Vector3f g2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.setupGuiFlatDiffuseLighting(g1, g2);
}
public static void setupGui3DDiffuseLighting(final Vector3f g1, final Vector3f g2) {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.setupGui3DDiffuseLighting(g1, g2);
}
public static void mulTextureByProjModelView() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.mulTextureByProjModelView();
}
public static void setupEndPortalTexGen() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.setupEndPortalTexGen();
}
public static void clearTexGen() {
assertThread(RenderSystem::isOnGameThread);
GlStateManager.clearTexGen();
}
public static void beginInitialization() {
RenderSystem.isInInit = true;
}
public static void finishInitialization() {
RenderSystem.isInInit = false;
if (!RenderSystem.recordingQueue.isEmpty()) {
replayQueue();
}
if (!RenderSystem.recordingQueue.isEmpty()) {
throw new IllegalStateException("Recorded to render queue during initialization");
}
}
public static void glGenBuffers(final Consumer<Integer> consumer) {
if (!isOnRenderThread()) {
recordRenderCall(() -> consumer.accept(GlStateManager._glGenBuffers()));
}
else {
consumer.accept(GlStateManager._glGenBuffers());
}
}
public static Tesselator renderThreadTesselator() {
assertThread(RenderSystem::isOnRenderThread);
return RenderSystem.RENDER_THREAD_TESSELATOR;
}
public static void defaultBlendFunc() {
blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
}
public static void defaultAlphaFunc() {
alphaFunc(516, 0.1f);
}
@Deprecated
public static void runAsFancy(final Runnable runnable) {
final boolean boolean2 = Minecraft.useShaderTransparency();
if (!boolean2) {
runnable.run();
return;
}
final Options dmb3 = Minecraft.getInstance().options;
final GraphicsStatus dlr4 = dmb3.graphicsMode;
dmb3.graphicsMode = GraphicsStatus.FANCY;
runnable.run();
dmb3.graphicsMode = dlr4;
}
static {
LOGGER = LogManager.getLogger();
recordingQueue = Queues.<RenderCall>newConcurrentLinkedQueue();
RENDER_THREAD_TESSELATOR = new Tesselator();
RenderSystem.MAX_SUPPORTED_TEXTURE_SIZE = -1;
RenderSystem.lastDrawTime = Double.MIN_VALUE;
}
}

View File

@ -0,0 +1,356 @@
package com.mojang.blaze3d.vertex;
import org.apache.logging.log4j.LogManager;
import com.google.common.primitives.Floats;
import com.mojang.datafixers.util.Pair;
import com.google.common.collect.ImmutableList;
import java.nio.FloatBuffer;
import java.util.BitSet;
import it.unimi.dsi.fastutil.ints.IntArrays;
import com.mojang.blaze3d.platform.MemoryTracker;
import com.google.common.collect.Lists;
import javax.annotation.Nullable;
import java.util.List;
import java.nio.ByteBuffer;
import org.apache.logging.log4j.Logger;
public class BufferBuilder extends DefaultedVertexConsumer implements BufferVertexConsumer {
private static final Logger LOGGER;
private ByteBuffer buffer;
private final List<DrawState> vertexCounts;
private int lastRenderedCountIndex;
private int totalRenderedBytes;
private int nextElementByte;
private int totalUploadedBytes;
private int vertices;
@Nullable
private VertexFormatElement currentElement;
private int elementIndex;
private int mode;
private VertexFormat format;
private boolean fastFormat;
private boolean fullFormat;
private boolean building;
public BufferBuilder(final int integer) {
this.vertexCounts = Lists.newArrayList();
this.lastRenderedCountIndex = 0;
this.totalRenderedBytes = 0;
this.nextElementByte = 0;
this.totalUploadedBytes = 0;
this.buffer = MemoryTracker.createByteBuffer(integer * 4);
}
protected void ensureVertexCapacity() {
this.ensureCapacity(this.format.getVertexSize());
}
private void ensureCapacity(final int integer) {
if (this.nextElementByte + integer <= this.buffer.capacity()) {
return;
}
final int integer2 = this.buffer.capacity();
final int integer3 = integer2 + roundUp(integer);
BufferBuilder.LOGGER.debug("Needed to grow BufferBuilder buffer: Old size {} bytes, new size {} bytes.", integer2, integer3);
final ByteBuffer byteBuffer5 = MemoryTracker.createByteBuffer(integer3);
this.buffer.position(0);
byteBuffer5.put(this.buffer);
byteBuffer5.rewind();
this.buffer = byteBuffer5;
}
private static int roundUp(final int integer) {
int integer2 = 2097152;
if (integer == 0) {
return integer2;
}
if (integer < 0) {
integer2 *= -1;
}
final int integer3 = integer % integer2;
if (integer3 == 0) {
return integer;
}
return integer + integer2 - integer3;
}
public void sortQuads(final float float1, final float float2, final float float3) {
this.buffer.clear();
final FloatBuffer floatBuffer5 = this.buffer.asFloatBuffer();
final int integer6 = this.vertices / 4;
final float[] arr7 = new float[integer6];
for (int integer7 = 0; integer7 < integer6; ++integer7) {
arr7[integer7] = getQuadDistanceFromPlayer(floatBuffer5, float1, float2, float3, this.format.getIntegerSize(), this.totalRenderedBytes / 4 + integer7 * this.format.getVertexSize());
}
final int[] arr8 = new int[integer6];
for (int integer8 = 0; integer8 < arr8.length; ++integer8) {
arr8[integer8] = integer8;
}
IntArrays.mergeSort(arr8, (integer2, integer3) -> Floats.compare(arr7[integer3], arr7[integer2]));
final BitSet bitSet9 = new BitSet();
final FloatBuffer floatBuffer6 = MemoryTracker.createFloatBuffer(this.format.getIntegerSize() * 4);
for (int integer9 = bitSet9.nextClearBit(0); integer9 < arr8.length; integer9 = bitSet9.nextClearBit(integer9 + 1)) {
final int integer10 = arr8[integer9];
if (integer10 != integer9) {
this.limitToVertex(floatBuffer5, integer10);
floatBuffer6.clear();
floatBuffer6.put(floatBuffer5);
for (int integer11 = integer10, integer12 = arr8[integer11]; integer11 != integer9; integer11 = integer12, integer12 = arr8[integer11]) {
this.limitToVertex(floatBuffer5, integer12);
final FloatBuffer floatBuffer7 = floatBuffer5.slice();
this.limitToVertex(floatBuffer5, integer11);
floatBuffer5.put(floatBuffer7);
bitSet9.set(integer11);
}
this.limitToVertex(floatBuffer5, integer9);
floatBuffer6.flip();
floatBuffer5.put(floatBuffer6);
}
bitSet9.set(integer9);
}
}
private void limitToVertex(final FloatBuffer floatBuffer, final int integer) {
final int integer2 = this.format.getIntegerSize() * 4;
floatBuffer.limit(this.totalRenderedBytes / 4 + (integer + 1) * integer2);
floatBuffer.position(this.totalRenderedBytes / 4 + integer * integer2);
}
public State getState() {
this.buffer.limit(this.nextElementByte);
this.buffer.position(this.totalRenderedBytes);
final ByteBuffer byteBuffer2 = ByteBuffer.allocate(this.vertices * this.format.getVertexSize());
byteBuffer2.put(this.buffer);
this.buffer.clear();
return new State(byteBuffer2, this.format);
}
private static float getQuadDistanceFromPlayer(final FloatBuffer floatBuffer, final float float2, final float float3, final float float4, final int integer5, final int integer6) {
final float float5 = floatBuffer.get(integer6 + integer5 * 0 + 0);
final float float6 = floatBuffer.get(integer6 + integer5 * 0 + 1);
final float float7 = floatBuffer.get(integer6 + integer5 * 0 + 2);
final float float8 = floatBuffer.get(integer6 + integer5 * 1 + 0);
final float float9 = floatBuffer.get(integer6 + integer5 * 1 + 1);
final float float10 = floatBuffer.get(integer6 + integer5 * 1 + 2);
final float float11 = floatBuffer.get(integer6 + integer5 * 2 + 0);
final float float12 = floatBuffer.get(integer6 + integer5 * 2 + 1);
final float float13 = floatBuffer.get(integer6 + integer5 * 2 + 2);
final float float14 = floatBuffer.get(integer6 + integer5 * 3 + 0);
final float float15 = floatBuffer.get(integer6 + integer5 * 3 + 1);
final float float16 = floatBuffer.get(integer6 + integer5 * 3 + 2);
final float float17 = (float5 + float8 + float11 + float14) * 0.25f - float2;
final float float18 = (float6 + float9 + float12 + float15) * 0.25f - float3;
final float float19 = (float7 + float10 + float13 + float16) * 0.25f - float4;
return float17 * float17 + float18 * float18 + float19 * float19;
}
public void restoreState(final State b) {
b.data.clear();
final int integer3 = b.data.capacity();
this.ensureCapacity(integer3);
this.buffer.limit(this.buffer.capacity());
this.buffer.position(this.totalRenderedBytes);
this.buffer.put(b.data);
this.buffer.clear();
final VertexFormat dhq4 = b.format;
this.switchFormat(dhq4);
this.vertices = integer3 / dhq4.getVertexSize();
this.nextElementByte = this.totalRenderedBytes + this.vertices * dhq4.getVertexSize();
}
public void begin(final int integer, final VertexFormat dhq) {
if (this.building) {
throw new IllegalStateException("Already building!");
}
this.building = true;
this.mode = integer;
this.switchFormat(dhq);
this.currentElement = dhq.getElements().get(0);
this.elementIndex = 0;
this.buffer.clear();
}
private void switchFormat(final VertexFormat dhq) {
if (this.format == dhq) {
return;
}
this.format = dhq;
final boolean boolean3 = dhq == DefaultVertexFormat.NEW_ENTITY;
final boolean boolean4 = dhq == DefaultVertexFormat.BLOCK;
this.fastFormat = (boolean3 || boolean4);
this.fullFormat = boolean3;
}
public void end() {
if (!this.building) {
throw new IllegalStateException("Not building!");
}
this.building = false;
this.vertexCounts.add(new DrawState(this.format, this.vertices, this.mode));
this.totalRenderedBytes += this.vertices * this.format.getVertexSize();
this.vertices = 0;
this.currentElement = null;
this.elementIndex = 0;
}
@Override
public void putByte(final int integer, final byte byte2) {
this.buffer.put(this.nextElementByte + integer, byte2);
}
@Override
public void putShort(final int integer, final short short2) {
this.buffer.putShort(this.nextElementByte + integer, short2);
}
@Override
public void putFloat(final int integer, final float float2) {
this.buffer.putFloat(this.nextElementByte + integer, float2);
}
@Override
public void endVertex() {
if (this.elementIndex != 0) {
throw new IllegalStateException("Not filled all elements of the vertex");
}
++this.vertices;
this.ensureVertexCapacity();
}
@Override
public void nextElement() {
final ImmutableList<VertexFormatElement> immutableList2 = this.format.getElements();
this.elementIndex = (this.elementIndex + 1) % immutableList2.size();
this.nextElementByte += this.currentElement.getByteSize();
final VertexFormatElement dhr3 = immutableList2.get(this.elementIndex);
this.currentElement = dhr3;
if (dhr3.getUsage() == VertexFormatElement.Usage.PADDING) {
this.nextElement();
}
if (this.defaultColorSet && this.currentElement.getUsage() == VertexFormatElement.Usage.COLOR) {
super.color(this.defaultR, this.defaultG, this.defaultB, this.defaultA);
}
}
@Override
public VertexConsumer color(final int integer1, final int integer2, final int integer3, final int integer4) {
if (this.defaultColorSet) {
throw new IllegalStateException();
}
return super.color(integer1, integer2, integer3, integer4);
}
@Override
public void vertex(final float float1, final float float2, final float float3, final float float4, final float float5, final float float6, final float float7, final float float8, final float float9, final int integer10, final int integer11, final float float12, final float float13, final float float14) {
if (this.defaultColorSet) {
throw new IllegalStateException();
}
if (this.fastFormat) {
this.putFloat(0, float1);
this.putFloat(4, float2);
this.putFloat(8, float3);
this.putByte(12, (byte)(float4 * 255.0f));
this.putByte(13, (byte)(float5 * 255.0f));
this.putByte(14, (byte)(float6 * 255.0f));
this.putByte(15, (byte)(float7 * 255.0f));
this.putFloat(16, float8);
this.putFloat(20, float9);
int integer12;
if (this.fullFormat) {
this.putShort(24, (short)(integer10 & 0xFFFF));
this.putShort(26, (short)(integer10 >> 16 & 0xFFFF));
integer12 = 28;
}
else {
integer12 = 24;
}
this.putShort(integer12 + 0, (short)(integer11 & 0xFFFF));
this.putShort(integer12 + 2, (short)(integer11 >> 16 & 0xFFFF));
this.putByte(integer12 + 4, BufferVertexConsumer.normalIntValue(float12));
this.putByte(integer12 + 5, BufferVertexConsumer.normalIntValue(float13));
this.putByte(integer12 + 6, BufferVertexConsumer.normalIntValue(float14));
this.nextElementByte += integer12 + 8;
this.endVertex();
return;
}
super.vertex(float1, float2, float3, float4, float5, float6, float7, float8, float9, integer10, integer11, float12, float13, float14);
}
public Pair<DrawState, ByteBuffer> popNextBuffer() {
final DrawState a2 = this.vertexCounts.get(this.lastRenderedCountIndex++);
this.buffer.position(this.totalUploadedBytes);
this.totalUploadedBytes += a2.vertexCount() * a2.format().getVertexSize();
this.buffer.limit(this.totalUploadedBytes);
if (this.lastRenderedCountIndex == this.vertexCounts.size() && this.vertices == 0) {
this.clear();
}
final ByteBuffer byteBuffer3 = this.buffer.slice();
this.buffer.clear();
return (Pair<DrawState, ByteBuffer>)Pair.of(a2, byteBuffer3);
}
public void clear() {
if (this.totalRenderedBytes != this.totalUploadedBytes) {
BufferBuilder.LOGGER.warn("Bytes mismatch " + this.totalRenderedBytes + " " + this.totalUploadedBytes);
}
this.discard();
}
public void discard() {
this.totalRenderedBytes = 0;
this.totalUploadedBytes = 0;
this.nextElementByte = 0;
this.vertexCounts.clear();
this.lastRenderedCountIndex = 0;
}
@Override
public VertexFormatElement currentElement() {
if (this.currentElement == null) {
throw new IllegalStateException("BufferBuilder not started");
}
return this.currentElement;
}
public boolean building() {
return this.building;
}
static {
LOGGER = LogManager.getLogger();
}
public static class State {
private final ByteBuffer data;
private final VertexFormat format;
private State(final ByteBuffer byteBuffer, final VertexFormat dhq) {
this.data = byteBuffer;
this.format = dhq;
}
}
public static final class DrawState {
private final VertexFormat format;
private final int vertexCount;
private final int mode;
private DrawState(final VertexFormat dhq, final int integer2, final int integer3) {
this.format = dhq;
this.vertexCount = integer2;
this.mode = integer3;
}
public VertexFormat format() {
return this.format;
}
public int vertexCount() {
return this.vertexCount;
}
public int mode() {
return this.mode;
}
}
}

View File

@ -0,0 +1,37 @@
package com.mojang.blaze3d.vertex;
import com.mojang.blaze3d.platform.GlStateManager;
import org.lwjgl.system.MemoryUtil;
import com.mojang.datafixers.util.Pair;
import java.nio.ByteBuffer;
import com.mojang.blaze3d.systems.RenderSystem;
public class BufferUploader {
public static void end(final BufferBuilder dhg) {
if (!RenderSystem.isOnRenderThread()) {
final Pair<BufferBuilder.DrawState, ByteBuffer> pair2;
final BufferBuilder.DrawState a3;
RenderSystem.recordRenderCall(() -> {
pair2 = dhg.popNextBuffer();
a3 = (BufferBuilder.DrawState)pair2.getFirst();
_end((ByteBuffer)pair2.getSecond(), a3.mode(), a3.format(), a3.vertexCount());
});
}
else {
final Pair<BufferBuilder.DrawState, ByteBuffer> pair3 = dhg.popNextBuffer();
final BufferBuilder.DrawState a4 = (BufferBuilder.DrawState)pair3.getFirst();
_end((ByteBuffer)pair3.getSecond(), a4.mode(), a4.format(), a4.vertexCount());
}
}
private static void _end(final ByteBuffer byteBuffer, final int integer2, final VertexFormat dhq, final int integer4) {
RenderSystem.assertThread(RenderSystem::isOnRenderThread);
byteBuffer.clear();
if (integer4 <= 0) {
return;
}
dhq.setupBufferState(MemoryUtil.memAddress(byteBuffer));
GlStateManager._drawArrays(integer2, 0, integer4);
dhq.clearBufferState();
}
}

View File

@ -0,0 +1,97 @@
package com.mojang.blaze3d.vertex;
import net.minecraft.util.Mth;
public interface BufferVertexConsumer extends VertexConsumer {
VertexFormatElement currentElement();
void nextElement();
void putByte(final int integer, final byte byte2);
void putShort(final int integer, final short short2);
void putFloat(final int integer, final float float2);
default VertexConsumer vertex(final double double1, final double double2, final double double3) {
if (this.currentElement().getType() != VertexFormatElement.Type.FLOAT) {
throw new IllegalStateException();
}
this.putFloat(0, (float)double1);
this.putFloat(4, (float)double2);
this.putFloat(8, (float)double3);
this.nextElement();
return this;
}
default VertexConsumer color(final int integer1, final int integer2, final int integer3, final int integer4) {
final VertexFormatElement dhr6 = this.currentElement();
if (dhr6.getUsage() != VertexFormatElement.Usage.COLOR) {
return this;
}
if (dhr6.getType() != VertexFormatElement.Type.UBYTE) {
throw new IllegalStateException();
}
this.putByte(0, (byte)integer1);
this.putByte(1, (byte)integer2);
this.putByte(2, (byte)integer3);
this.putByte(3, (byte)integer4);
this.nextElement();
return this;
}
default VertexConsumer uv(final float float1, final float float2) {
final VertexFormatElement dhr4 = this.currentElement();
if (dhr4.getUsage() != VertexFormatElement.Usage.UV || dhr4.getIndex() != 0) {
return this;
}
if (dhr4.getType() != VertexFormatElement.Type.FLOAT) {
throw new IllegalStateException();
}
this.putFloat(0, float1);
this.putFloat(4, float2);
this.nextElement();
return this;
}
default VertexConsumer overlayCoords(final int integer1, final int integer2) {
return this.uvShort((short)integer1, (short)integer2, 1);
}
default VertexConsumer uv2(final int integer1, final int integer2) {
return this.uvShort((short)integer1, (short)integer2, 2);
}
default VertexConsumer uvShort(final short short1, final short short2, final int integer) {
final VertexFormatElement dhr5 = this.currentElement();
if (dhr5.getUsage() != VertexFormatElement.Usage.UV || dhr5.getIndex() != integer) {
return this;
}
if (dhr5.getType() != VertexFormatElement.Type.SHORT) {
throw new IllegalStateException();
}
this.putShort(0, short1);
this.putShort(2, short2);
this.nextElement();
return this;
}
default VertexConsumer normal(final float float1, final float float2, final float float3) {
final VertexFormatElement dhr5 = this.currentElement();
if (dhr5.getUsage() != VertexFormatElement.Usage.NORMAL) {
return this;
}
if (dhr5.getType() != VertexFormatElement.Type.BYTE) {
throw new IllegalStateException();
}
this.putByte(0, normalIntValue(float1));
this.putByte(1, normalIntValue(float2));
this.putByte(2, normalIntValue(float3));
this.nextElement();
return this;
}
default byte normalIntValue(final float float1) {
return (byte)((int)(Mth.clamp(float1, -1.0f, 1.0f) * 127.0f) & 0xFF);
}
}

View File

@ -0,0 +1,51 @@
package com.mojang.blaze3d.vertex;
import com.google.common.collect.ImmutableList;
public class DefaultVertexFormat {
public static final VertexFormatElement ELEMENT_POSITION;
public static final VertexFormatElement ELEMENT_COLOR;
public static final VertexFormatElement ELEMENT_UV0;
public static final VertexFormatElement ELEMENT_UV1;
public static final VertexFormatElement ELEMENT_UV2;
public static final VertexFormatElement ELEMENT_NORMAL;
public static final VertexFormatElement ELEMENT_PADDING;
public static final VertexFormat BLOCK;
public static final VertexFormat NEW_ENTITY;
@Deprecated
public static final VertexFormat PARTICLE;
public static final VertexFormat POSITION;
public static final VertexFormat POSITION_COLOR;
public static final VertexFormat POSITION_COLOR_LIGHTMAP;
public static final VertexFormat POSITION_TEX;
public static final VertexFormat POSITION_COLOR_TEX;
@Deprecated
public static final VertexFormat POSITION_TEX_COLOR;
public static final VertexFormat POSITION_COLOR_TEX_LIGHTMAP;
@Deprecated
public static final VertexFormat POSITION_TEX_LIGHTMAP_COLOR;
@Deprecated
public static final VertexFormat POSITION_TEX_COLOR_NORMAL;
static {
ELEMENT_POSITION = new VertexFormatElement(0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.POSITION, 3);
ELEMENT_COLOR = new VertexFormatElement(0, VertexFormatElement.Type.UBYTE, VertexFormatElement.Usage.COLOR, 4);
ELEMENT_UV0 = new VertexFormatElement(0, VertexFormatElement.Type.FLOAT, VertexFormatElement.Usage.UV, 2);
ELEMENT_UV1 = new VertexFormatElement(1, VertexFormatElement.Type.SHORT, VertexFormatElement.Usage.UV, 2);
ELEMENT_UV2 = new VertexFormatElement(2, VertexFormatElement.Type.SHORT, VertexFormatElement.Usage.UV, 2);
ELEMENT_NORMAL = new VertexFormatElement(0, VertexFormatElement.Type.BYTE, VertexFormatElement.Usage.NORMAL, 3);
ELEMENT_PADDING = new VertexFormatElement(0, VertexFormatElement.Type.BYTE, VertexFormatElement.Usage.PADDING, 1);
BLOCK = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_COLOR).add(DefaultVertexFormat.ELEMENT_UV0).add(DefaultVertexFormat.ELEMENT_UV2).add(DefaultVertexFormat.ELEMENT_NORMAL).add(DefaultVertexFormat.ELEMENT_PADDING).build());
NEW_ENTITY = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_COLOR).add(DefaultVertexFormat.ELEMENT_UV0).add(DefaultVertexFormat.ELEMENT_UV1).add(DefaultVertexFormat.ELEMENT_UV2).add(DefaultVertexFormat.ELEMENT_NORMAL).add(DefaultVertexFormat.ELEMENT_PADDING).build());
PARTICLE = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_UV0).add(DefaultVertexFormat.ELEMENT_COLOR).add(DefaultVertexFormat.ELEMENT_UV2).build());
POSITION = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).build());
POSITION_COLOR = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_COLOR).build());
POSITION_COLOR_LIGHTMAP = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_COLOR).add(DefaultVertexFormat.ELEMENT_UV2).build());
POSITION_TEX = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_UV0).build());
POSITION_COLOR_TEX = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_COLOR).add(DefaultVertexFormat.ELEMENT_UV0).build());
POSITION_TEX_COLOR = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_UV0).add(DefaultVertexFormat.ELEMENT_COLOR).build());
POSITION_COLOR_TEX_LIGHTMAP = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_COLOR).add(DefaultVertexFormat.ELEMENT_UV0).add(DefaultVertexFormat.ELEMENT_UV2).build());
POSITION_TEX_LIGHTMAP_COLOR = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_UV0).add(DefaultVertexFormat.ELEMENT_UV2).add(DefaultVertexFormat.ELEMENT_COLOR).build());
POSITION_TEX_COLOR_NORMAL = new VertexFormat(ImmutableList.<VertexFormatElement>builder().add(DefaultVertexFormat.ELEMENT_POSITION).add(DefaultVertexFormat.ELEMENT_UV0).add(DefaultVertexFormat.ELEMENT_COLOR).add(DefaultVertexFormat.ELEMENT_NORMAL).add(DefaultVertexFormat.ELEMENT_PADDING).build());
}
}

View File

@ -0,0 +1,25 @@
package com.mojang.blaze3d.vertex;
public abstract class DefaultedVertexConsumer implements VertexConsumer {
protected boolean defaultColorSet;
protected int defaultR;
protected int defaultG;
protected int defaultB;
protected int defaultA;
public DefaultedVertexConsumer() {
this.defaultColorSet = false;
this.defaultR = 255;
this.defaultG = 255;
this.defaultB = 255;
this.defaultA = 255;
}
public void defaultColor(final int integer1, final int integer2, final int integer3, final int integer4) {
this.defaultR = integer1;
this.defaultG = integer2;
this.defaultB = integer3;
this.defaultA = integer4;
this.defaultColorSet = true;
}
}

View File

@ -0,0 +1,88 @@
package com.mojang.blaze3d.vertex;
import java.util.ArrayDeque;
import com.mojang.math.Quaternion;
import net.minecraft.util.Mth;
import net.minecraft.Util;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import com.google.common.collect.Queues;
import java.util.Deque;
public class PoseStack {
private final Deque<Pose> poseStack;
public PoseStack() {
final Matrix4f b2;
final Matrix3f a3;
this.poseStack = Util.<Deque<Pose>>make(Queues.newArrayDeque(), arrayDeque -> {
b2 = new Matrix4f();
b2.setIdentity();
a3 = new Matrix3f();
a3.setIdentity();
arrayDeque.add(new Pose(b2, a3));
});
}
public void translate(final double double1, final double double2, final double double3) {
final Pose a8 = this.poseStack.getLast();
a8.pose.multiply(Matrix4f.createTranslateMatrix((float)double1, (float)double2, (float)double3));
}
public void scale(final float float1, final float float2, final float float3) {
final Pose a5 = this.poseStack.getLast();
a5.pose.multiply(Matrix4f.createScaleMatrix(float1, float2, float3));
if (float1 == float2 && float2 == float3) {
if (float1 > 0.0f) {
return;
}
a5.normal.mul(-1.0f);
}
final float float4 = 1.0f / float1;
final float float5 = 1.0f / float2;
final float float6 = 1.0f / float3;
final float float7 = Mth.fastInvCubeRoot(float4 * float5 * float6);
a5.normal.mul(Matrix3f.createScaleMatrix(float7 * float4, float7 * float5, float7 * float6));
}
public void mulPose(final Quaternion d) {
final Pose a3 = this.poseStack.getLast();
a3.pose.multiply(d);
a3.normal.mul(d);
}
public void pushPose() {
final Pose a2 = this.poseStack.getLast();
this.poseStack.addLast(new Pose(a2.pose.copy(), a2.normal.copy()));
}
public void popPose() {
this.poseStack.removeLast();
}
public Pose last() {
return this.poseStack.getLast();
}
public boolean clear() {
return this.poseStack.size() == 1;
}
public static final class Pose {
private final Matrix4f pose;
private final Matrix3f normal;
private Pose(final Matrix4f b, final Matrix3f a) {
this.pose = b;
this.normal = a;
}
public Matrix4f pose() {
return this.pose;
}
public Matrix3f normal() {
return this.normal;
}
}
}

View File

@ -0,0 +1,96 @@
package com.mojang.blaze3d.vertex;
import com.mojang.math.Vector4f;
import net.minecraft.core.Direction;
import com.mojang.math.Vector3f;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
public class SheetedDecalTextureGenerator extends DefaultedVertexConsumer {
private final VertexConsumer delegate;
private final Matrix4f cameraInversePose;
private final Matrix3f normalInversePose;
private float x;
private float y;
private float z;
private int overlayU;
private int overlayV;
private int lightCoords;
private float nx;
private float ny;
private float nz;
public SheetedDecalTextureGenerator(final VertexConsumer dhp, final Matrix4f b, final Matrix3f a) {
this.delegate = dhp;
(this.cameraInversePose = b.copy()).invert();
(this.normalInversePose = a.copy()).invert();
this.resetState();
}
private void resetState() {
this.x = 0.0f;
this.y = 0.0f;
this.z = 0.0f;
this.overlayU = 0;
this.overlayV = 10;
this.lightCoords = 15728880;
this.nx = 0.0f;
this.ny = 1.0f;
this.nz = 0.0f;
}
@Override
public void endVertex() {
final Vector3f g2 = new Vector3f(this.nx, this.ny, this.nz);
g2.transform(this.normalInversePose);
final Direction fz3 = Direction.getNearest(g2.x(), g2.y(), g2.z());
final Vector4f h4 = new Vector4f(this.x, this.y, this.z, 1.0f);
h4.transform(this.cameraInversePose);
h4.transform(Vector3f.YP.rotationDegrees(180.0f));
h4.transform(Vector3f.XP.rotationDegrees(-90.0f));
h4.transform(fz3.getRotation());
final float float5 = -h4.x();
final float float6 = -h4.y();
this.delegate.vertex(this.x, this.y, this.z).color(1.0f, 1.0f, 1.0f, 1.0f).uv(float5, float6).overlayCoords(this.overlayU, this.overlayV).uv2(this.lightCoords).normal(this.nx, this.ny, this.nz).endVertex();
this.resetState();
}
@Override
public VertexConsumer vertex(final double double1, final double double2, final double double3) {
this.x = (float)double1;
this.y = (float)double2;
this.z = (float)double3;
return this;
}
@Override
public VertexConsumer color(final int integer1, final int integer2, final int integer3, final int integer4) {
return this;
}
@Override
public VertexConsumer uv(final float float1, final float float2) {
return this;
}
@Override
public VertexConsumer overlayCoords(final int integer1, final int integer2) {
this.overlayU = integer1;
this.overlayV = integer2;
return this;
}
@Override
public VertexConsumer uv2(final int integer1, final int integer2) {
this.lightCoords = (integer1 | integer2 << 16);
return this;
}
@Override
public VertexConsumer normal(final float float1, final float float2, final float float3) {
this.nx = float1;
this.ny = float2;
this.nz = float3;
return this;
}
}

View File

@ -0,0 +1,34 @@
package com.mojang.blaze3d.vertex;
import com.mojang.blaze3d.systems.RenderSystem;
public class Tesselator {
private final BufferBuilder builder;
private static final Tesselator INSTANCE;
public static Tesselator getInstance() {
RenderSystem.assertThread(RenderSystem::isOnGameThreadOrInit);
return Tesselator.INSTANCE;
}
public Tesselator(final int integer) {
this.builder = new BufferBuilder(integer);
}
public Tesselator() {
this(2097152);
}
public void end() {
this.builder.end();
BufferUploader.end(this.builder);
}
public BufferBuilder getBuilder() {
return this.builder;
}
static {
INSTANCE = new Tesselator();
}
}

View File

@ -0,0 +1,71 @@
package com.mojang.blaze3d.vertex;
import com.mojang.math.Matrix4f;
import com.mojang.datafixers.util.Pair;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;
import com.mojang.blaze3d.systems.RenderSystem;
public class VertexBuffer implements AutoCloseable {
private int id;
private final VertexFormat format;
private int vertexCount;
public VertexBuffer(final VertexFormat dhq) {
this.format = dhq;
RenderSystem.glGenBuffers(integer -> this.id = integer);
}
public void bind() {
RenderSystem.glBindBuffer(34962, () -> this.id);
}
public void upload(final BufferBuilder dhg) {
if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(() -> this.upload_(dhg));
}
else {
this.upload_(dhg);
}
}
public CompletableFuture<Void> uploadLater(final BufferBuilder dhg) {
if (!RenderSystem.isOnRenderThread()) {
return CompletableFuture.runAsync(() -> this.upload_(dhg), runnable -> RenderSystem.recordRenderCall(runnable::run));
}
this.upload_(dhg);
return CompletableFuture.<Void>completedFuture((Void)null);
}
private void upload_(final BufferBuilder dhg) {
final Pair<BufferBuilder.DrawState, ByteBuffer> pair3 = dhg.popNextBuffer();
if (this.id == -1) {
return;
}
final ByteBuffer byteBuffer4 = (ByteBuffer)pair3.getSecond();
this.vertexCount = byteBuffer4.remaining() / this.format.getVertexSize();
this.bind();
RenderSystem.glBufferData(34962, byteBuffer4, 35044);
unbind();
}
public void draw(final Matrix4f b, final int integer) {
RenderSystem.pushMatrix();
RenderSystem.loadIdentity();
RenderSystem.multMatrix(b);
RenderSystem.drawArrays(integer, 0, this.vertexCount);
RenderSystem.popMatrix();
}
public static void unbind() {
RenderSystem.glBindBuffer(34962, () -> 0);
}
@Override
public void close() {
if (this.id >= 0) {
RenderSystem.glDeleteBuffers(this.id);
this.id = -1;
}
}
}

View File

@ -0,0 +1,112 @@
package com.mojang.blaze3d.vertex;
import org.apache.logging.log4j.LogManager;
import com.mojang.math.Matrix3f;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import com.mojang.math.Matrix4f;
import net.minecraft.core.Vec3i;
import com.mojang.math.Vector4f;
import org.lwjgl.system.MemoryStack;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.block.model.BakedQuad;
import org.apache.logging.log4j.Logger;
public interface VertexConsumer {
public static final Logger LOGGER = LogManager.getLogger();
VertexConsumer vertex(final double double1, final double double2, final double double3);
VertexConsumer color(final int integer1, final int integer2, final int integer3, final int integer4);
VertexConsumer uv(final float float1, final float float2);
VertexConsumer overlayCoords(final int integer1, final int integer2);
VertexConsumer uv2(final int integer1, final int integer2);
VertexConsumer normal(final float float1, final float float2, final float float3);
void endVertex();
default void vertex(final float float1, final float float2, final float float3, final float float4, final float float5, final float float6, final float float7, final float float8, final float float9, final int integer10, final int integer11, final float float12, final float float13, final float float14) {
this.vertex(float1, float2, float3);
this.color(float4, float5, float6, float7);
this.uv(float8, float9);
this.overlayCoords(integer10);
this.uv2(integer11);
this.normal(float12, float13, float14);
this.endVertex();
}
default VertexConsumer color(final float float1, final float float2, final float float3, final float float4) {
return this.color((int)(float1 * 255.0f), (int)(float2 * 255.0f), (int)(float3 * 255.0f), (int)(float4 * 255.0f));
}
default VertexConsumer uv2(final int integer) {
return this.uv2(integer & 0xFFFF, integer >> 16 & 0xFFFF);
}
default VertexConsumer overlayCoords(final int integer) {
return this.overlayCoords(integer & 0xFFFF, integer >> 16 & 0xFFFF);
}
default void putBulkData(final PoseStack.Pose a, final BakedQuad ect, final float float3, final float float4, final float float5, final int integer6, final int integer7) {
this.putBulkData(a, ect, new float[] { 1.0f, 1.0f, 1.0f, 1.0f }, float3, float4, float5, new int[] { integer6, integer6, integer6, integer6 }, integer7, false);
}
default void putBulkData(final PoseStack.Pose a, final BakedQuad ect, final float[] arr, final float float4, final float float5, final float float6, final int[] arr, final int integer, final boolean boolean9) {
final int[] arr2 = ect.getVertices();
final Vec3i gr12 = ect.getDirection().getNormal();
final Vector3f g13 = new Vector3f((float)gr12.getX(), (float)gr12.getY(), (float)gr12.getZ());
final Matrix4f b14 = a.pose();
g13.transform(a.normal());
final int integer2 = 8;
final int integer3 = arr2.length / 8;
try (final MemoryStack memoryStack17 = MemoryStack.stackPush()) {
final ByteBuffer byteBuffer19 = memoryStack17.malloc(DefaultVertexFormat.BLOCK.getVertexSize());
final IntBuffer intBuffer20 = byteBuffer19.asIntBuffer();
for (int integer4 = 0; integer4 < integer3; ++integer4) {
intBuffer20.clear();
intBuffer20.put(arr2, integer4 * 8, 8);
final float float7 = byteBuffer19.getFloat(0);
final float float8 = byteBuffer19.getFloat(4);
final float float9 = byteBuffer19.getFloat(8);
float float13;
float float14;
float float15;
if (boolean9) {
final float float10 = (byteBuffer19.get(12) & 0xFF) / 255.0f;
final float float11 = (byteBuffer19.get(13) & 0xFF) / 255.0f;
final float float12 = (byteBuffer19.get(14) & 0xFF) / 255.0f;
float13 = float10 * arr[integer4] * float4;
float14 = float11 * arr[integer4] * float5;
float15 = float12 * arr[integer4] * float6;
}
else {
float13 = arr[integer4] * float4;
float14 = arr[integer4] * float5;
float15 = arr[integer4] * float6;
}
final int integer5 = arr[integer4];
final float float11 = byteBuffer19.getFloat(16);
final float float12 = byteBuffer19.getFloat(20);
final Vector4f h31 = new Vector4f(float7, float8, float9, 1.0f);
h31.transform(b14);
this.vertex(h31.x(), h31.y(), h31.z(), float13, float14, float15, 1.0f, float11, float12, integer, integer5, g13.x(), g13.y(), g13.z());
}
}
}
default VertexConsumer vertex(final Matrix4f b, final float float2, final float float3, final float float4) {
final Vector4f h6 = new Vector4f(float2, float3, float4, 1.0f);
h6.transform(b);
return this.vertex(h6.x(), h6.y(), h6.z());
}
default VertexConsumer normal(final Matrix3f a, final float float2, final float float3, final float float4) {
final Vector3f g6 = new Vector3f(float2, float3, float4);
g6.transform(a);
return this.normal(g6.x(), g6.y(), g6.z());
}
}

View File

@ -0,0 +1,84 @@
package com.mojang.blaze3d.vertex;
import java.util.List;
import com.mojang.blaze3d.systems.RenderSystem;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.function.Function;
import com.google.common.collect.UnmodifiableIterator;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import com.google.common.collect.ImmutableList;
public class VertexFormat {
private final ImmutableList<VertexFormatElement> elements;
private final IntList offsets;
private final int vertexSize;
public VertexFormat(final ImmutableList<VertexFormatElement> immutableList) {
this.offsets = (IntList)new IntArrayList();
this.elements = immutableList;
int integer3 = 0;
for (final VertexFormatElement dhr5 : immutableList) {
this.offsets.add(integer3);
integer3 += dhr5.getByteSize();
}
this.vertexSize = integer3;
}
@Override
public String toString() {
return "format: " + this.elements.size() + " elements: " + this.elements.stream().map(Object::toString).collect(Collectors.joining(" "));
}
public int getIntegerSize() {
return this.getVertexSize() / 4;
}
public int getVertexSize() {
return this.vertexSize;
}
public ImmutableList<VertexFormatElement> getElements() {
return this.elements;
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final VertexFormat dhq3 = (VertexFormat)object;
return this.vertexSize == dhq3.vertexSize && this.elements.equals(dhq3.elements);
}
@Override
public int hashCode() {
return this.elements.hashCode();
}
public void setupBufferState(final long long1) {
if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(() -> this.setupBufferState(long1));
return;
}
final int integer4 = this.getVertexSize();
final List<VertexFormatElement> list5 = this.getElements();
for (int integer5 = 0; integer5 < list5.size(); ++integer5) {
list5.get(integer5).setupBufferState(long1 + this.offsets.getInt(integer5), integer4);
}
}
public void clearBufferState() {
if (!RenderSystem.isOnRenderThread()) {
RenderSystem.recordRenderCall(this::clearBufferState);
return;
}
for (final VertexFormatElement dhr3 : this.getElements()) {
dhr3.clearBufferState();
}
}
}

View File

@ -0,0 +1,185 @@
package com.mojang.blaze3d.vertex;
import com.mojang.blaze3d.platform.GlStateManager;
import java.util.function.IntConsumer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class VertexFormatElement {
private static final Logger LOGGER;
private final Type type;
private final Usage usage;
private final int index;
private final int count;
private final int byteSize;
public VertexFormatElement(final int integer1, final Type a, final Usage b, final int integer4) {
if (this.supportsUsage(integer1, b)) {
this.usage = b;
}
else {
VertexFormatElement.LOGGER.warn("Multiple vertex elements of the same type other than UVs are not supported. Forcing type to UV.");
this.usage = Usage.UV;
}
this.type = a;
this.index = integer1;
this.count = integer4;
this.byteSize = a.getSize() * this.count;
}
private boolean supportsUsage(final int integer, final Usage b) {
return integer == 0 || b == Usage.UV;
}
public final Type getType() {
return this.type;
}
public final Usage getUsage() {
return this.usage;
}
public final int getIndex() {
return this.index;
}
@Override
public String toString() {
return this.count + "," + this.usage.getName() + "," + this.type.getName();
}
public final int getByteSize() {
return this.byteSize;
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final VertexFormatElement dhr3 = (VertexFormatElement)object;
return this.count == dhr3.count && this.index == dhr3.index && this.type == dhr3.type && this.usage == dhr3.usage;
}
@Override
public int hashCode() {
int integer2 = this.type.hashCode();
integer2 = 31 * integer2 + this.usage.hashCode();
integer2 = 31 * integer2 + this.index;
integer2 = 31 * integer2 + this.count;
return integer2;
}
public void setupBufferState(final long long1, final int integer) {
this.usage.setupBufferState(this.count, this.type.getGlType(), integer, long1, this.index);
}
public void clearBufferState() {
this.usage.clearBufferState(this.index);
}
static {
LOGGER = LogManager.getLogger();
}
public enum Usage {
POSITION("Position", (integer1, integer2, integer3, long4, integer5) -> {
GlStateManager._vertexPointer(integer1, integer2, integer3, long4);
GlStateManager._enableClientState(32884);
return;
}, integer -> GlStateManager._disableClientState(32884)),
NORMAL("Normal", (integer1, integer2, integer3, long4, integer5) -> {
GlStateManager._normalPointer(integer2, integer3, long4);
GlStateManager._enableClientState(32885);
return;
}, integer -> GlStateManager._disableClientState(32885)),
COLOR("Vertex Color", (integer1, integer2, integer3, long4, integer5) -> {
GlStateManager._colorPointer(integer1, integer2, integer3, long4);
GlStateManager._enableClientState(32886);
return;
}, integer -> {
GlStateManager._disableClientState(32886);
GlStateManager._clearCurrentColor();
return;
}),
UV("UV", (integer1, integer2, integer3, long4, integer5) -> {
GlStateManager._glClientActiveTexture(33984 + integer5);
GlStateManager._texCoordPointer(integer1, integer2, integer3, long4);
GlStateManager._enableClientState(32888);
GlStateManager._glClientActiveTexture(33984);
return;
}, integer -> {
GlStateManager._glClientActiveTexture(33984 + integer);
GlStateManager._disableClientState(32888);
GlStateManager._glClientActiveTexture(33984);
return;
}),
PADDING("Padding", (integer1, integer2, integer3, long4, integer5) -> {}, integer -> {}),
GENERIC("Generic", (integer1, integer2, integer3, long4, integer5) -> {
GlStateManager._enableVertexAttribArray(integer5);
GlStateManager._vertexAttribPointer(integer5, integer1, integer2, false, integer3, long4);
return;
}, GlStateManager::_disableVertexAttribArray);
private final String name;
private final SetupState setupState;
private final IntConsumer clearState;
private Usage(final String string3, final SetupState a, final IntConsumer intConsumer) {
this.name = string3;
this.setupState = a;
this.clearState = intConsumer;
}
private void setupBufferState(final int integer1, final int integer2, final int integer3, final long long4, final int integer5) {
this.setupState.setupBufferState(integer1, integer2, integer3, long4, integer5);
}
public void clearBufferState(final int integer) {
this.clearState.accept(integer);
}
public String getName() {
return this.name;
}
interface SetupState {
void setupBufferState(final int integer1, final int integer2, final int integer3, final long long4, final int integer5);
}
}
public enum Type {
FLOAT(4, "Float", 5126),
UBYTE(1, "Unsigned Byte", 5121),
BYTE(1, "Byte", 5120),
USHORT(2, "Unsigned Short", 5123),
SHORT(2, "Short", 5122),
UINT(4, "Unsigned Int", 5125),
INT(4, "Int", 5124);
private final int size;
private final String name;
private final int glType;
private Type(final int integer3, final String string4, final int integer5) {
this.size = integer3;
this.name = string4;
this.glType = integer5;
}
public int getSize() {
return this.size;
}
public String getName() {
return this.name;
}
public int getGlType() {
return this.glType;
}
}
}

View File

@ -0,0 +1,74 @@
package com.mojang.blaze3d.vertex;
public class VertexMultiConsumer {
public static VertexConsumer create(final VertexConsumer dhp1, final VertexConsumer dhp2) {
return new Double(dhp1, dhp2);
}
static class Double implements VertexConsumer {
private final VertexConsumer first;
private final VertexConsumer second;
public Double(final VertexConsumer dhp1, final VertexConsumer dhp2) {
if (dhp1 == dhp2) {
throw new IllegalArgumentException("Duplicate delegates");
}
this.first = dhp1;
this.second = dhp2;
}
@Override
public VertexConsumer vertex(final double double1, final double double2, final double double3) {
this.first.vertex(double1, double2, double3);
this.second.vertex(double1, double2, double3);
return this;
}
@Override
public VertexConsumer color(final int integer1, final int integer2, final int integer3, final int integer4) {
this.first.color(integer1, integer2, integer3, integer4);
this.second.color(integer1, integer2, integer3, integer4);
return this;
}
@Override
public VertexConsumer uv(final float float1, final float float2) {
this.first.uv(float1, float2);
this.second.uv(float1, float2);
return this;
}
@Override
public VertexConsumer overlayCoords(final int integer1, final int integer2) {
this.first.overlayCoords(integer1, integer2);
this.second.overlayCoords(integer1, integer2);
return this;
}
@Override
public VertexConsumer uv2(final int integer1, final int integer2) {
this.first.uv2(integer1, integer2);
this.second.uv2(integer1, integer2);
return this;
}
@Override
public VertexConsumer normal(final float float1, final float float2, final float float3) {
this.first.normal(float1, float2, float3);
this.second.normal(float1, float2, float3);
return this;
}
@Override
public void vertex(final float float1, final float float2, final float float3, final float float4, final float float5, final float float6, final float float7, final float float8, final float float9, final int integer10, final int integer11, final float float12, final float float13, final float float14) {
this.first.vertex(float1, float2, float3, float4, float5, float6, float7, float8, float9, integer10, integer11, float12, float13, float14);
this.second.vertex(float1, float2, float3, float4, float5, float6, float7, float8, float9, integer10, integer11, float12, float13, float14);
}
@Override
public void endVertex() {
this.first.endVertex();
this.second.endVertex();
}
}
}

View File

@ -0,0 +1,443 @@
package com.mojang.math;
import org.apache.commons.lang3.tuple.Triple;
import net.minecraft.util.Mth;
import com.mojang.datafixers.util.Pair;
public final class Matrix3f {
private static final float G;
private static final float CS;
private static final float SS;
private static final float SQ2;
protected float m00;
protected float m01;
protected float m02;
protected float m10;
protected float m11;
protected float m12;
protected float m20;
protected float m21;
protected float m22;
public Matrix3f() {
}
public Matrix3f(final Quaternion d) {
final float float3 = d.i();
final float float4 = d.j();
final float float5 = d.k();
final float float6 = d.r();
final float float7 = 2.0f * float3 * float3;
final float float8 = 2.0f * float4 * float4;
final float float9 = 2.0f * float5 * float5;
this.m00 = 1.0f - float8 - float9;
this.m11 = 1.0f - float9 - float7;
this.m22 = 1.0f - float7 - float8;
final float float10 = float3 * float4;
final float float11 = float4 * float5;
final float float12 = float5 * float3;
final float float13 = float3 * float6;
final float float14 = float4 * float6;
final float float15 = float5 * float6;
this.m10 = 2.0f * (float10 + float15);
this.m01 = 2.0f * (float10 - float15);
this.m20 = 2.0f * (float12 - float14);
this.m02 = 2.0f * (float12 + float14);
this.m21 = 2.0f * (float11 + float13);
this.m12 = 2.0f * (float11 - float13);
}
public static Matrix3f createScaleMatrix(final float float1, final float float2, final float float3) {
final Matrix3f a4 = new Matrix3f();
a4.m00 = float1;
a4.m11 = float2;
a4.m22 = float3;
return a4;
}
public Matrix3f(final Matrix4f b) {
this.m00 = b.m00;
this.m01 = b.m01;
this.m02 = b.m02;
this.m10 = b.m10;
this.m11 = b.m11;
this.m12 = b.m12;
this.m20 = b.m20;
this.m21 = b.m21;
this.m22 = b.m22;
}
public Matrix3f(final Matrix3f a) {
this.m00 = a.m00;
this.m01 = a.m01;
this.m02 = a.m02;
this.m10 = a.m10;
this.m11 = a.m11;
this.m12 = a.m12;
this.m20 = a.m20;
this.m21 = a.m21;
this.m22 = a.m22;
}
private static Pair<Float, Float> approxGivensQuat(final float float1, final float float2, final float float3) {
final float float4 = 2.0f * (float1 - float3);
final float float5 = float2;
if (Matrix3f.G * float5 * float5 < float4 * float4) {
final float float6 = Mth.fastInvSqrt(float5 * float5 + float4 * float4);
return (Pair<Float, Float>)Pair.of((float6 * float5), (float6 * float4));
}
return (Pair<Float, Float>)Pair.of(Matrix3f.SS, Matrix3f.CS);
}
private static Pair<Float, Float> qrGivensQuat(final float float1, final float float2) {
final float float3 = (float)Math.hypot(float1, float2);
float float4 = (float3 > 1.0E-6f) ? float2 : 0.0f;
float float5 = Math.abs(float1) + Math.max(float3, 1.0E-6f);
if (float1 < 0.0f) {
final float float6 = float4;
float4 = float5;
float5 = float6;
}
final float float6 = Mth.fastInvSqrt(float5 * float5 + float4 * float4);
float5 *= float6;
float4 *= float6;
return (Pair<Float, Float>)Pair.of(float4, float5);
}
private static Quaternion stepJacobi(final Matrix3f a) {
final Matrix3f a2 = new Matrix3f();
final Quaternion d3 = Quaternion.ONE.copy();
if (a.m01 * a.m01 + a.m10 * a.m10 > 1.0E-6f) {
final Pair<Float, Float> pair4 = approxGivensQuat(a.m00, 0.5f * (a.m01 + a.m10), a.m11);
final Float float5 = (Float)pair4.getFirst();
final Float float6 = (Float)pair4.getSecond();
final Quaternion d4 = new Quaternion(0.0f, 0.0f, float5, float6);
final float float7 = float6 * float6 - float5 * float5;
final float float8 = -2.0f * float5 * float6;
final float float9 = float6 * float6 + float5 * float5;
d3.mul(d4);
a2.setIdentity();
a2.m00 = float7;
a2.m11 = float7;
a2.m10 = -float8;
a2.m01 = float8;
a2.m22 = float9;
a.mul(a2);
a2.transpose();
a2.mul(a);
a.load(a2);
}
if (a.m02 * a.m02 + a.m20 * a.m20 > 1.0E-6f) {
final Pair<Float, Float> pair4 = approxGivensQuat(a.m00, 0.5f * (a.m02 + a.m20), a.m22);
final float float10 = -(float)pair4.getFirst();
final Float float6 = (Float)pair4.getSecond();
final Quaternion d4 = new Quaternion(0.0f, float10, 0.0f, float6);
final float float7 = float6 * float6 - float10 * float10;
final float float8 = -2.0f * float10 * float6;
final float float9 = float6 * float6 + float10 * float10;
d3.mul(d4);
a2.setIdentity();
a2.m00 = float7;
a2.m22 = float7;
a2.m20 = float8;
a2.m02 = -float8;
a2.m11 = float9;
a.mul(a2);
a2.transpose();
a2.mul(a);
a.load(a2);
}
if (a.m12 * a.m12 + a.m21 * a.m21 > 1.0E-6f) {
final Pair<Float, Float> pair4 = approxGivensQuat(a.m11, 0.5f * (a.m12 + a.m21), a.m22);
final Float float5 = (Float)pair4.getFirst();
final Float float6 = (Float)pair4.getSecond();
final Quaternion d4 = new Quaternion(float5, 0.0f, 0.0f, float6);
final float float7 = float6 * float6 - float5 * float5;
final float float8 = -2.0f * float5 * float6;
final float float9 = float6 * float6 + float5 * float5;
d3.mul(d4);
a2.setIdentity();
a2.m11 = float7;
a2.m22 = float7;
a2.m21 = -float8;
a2.m12 = float8;
a2.m00 = float9;
a.mul(a2);
a2.transpose();
a2.mul(a);
a.load(a2);
}
return d3;
}
public void transpose() {
float float2 = this.m01;
this.m01 = this.m10;
this.m10 = float2;
float2 = this.m02;
this.m02 = this.m20;
this.m20 = float2;
float2 = this.m12;
this.m12 = this.m21;
this.m21 = float2;
}
public Triple<Quaternion, Vector3f, Quaternion> svdDecompose() {
final Quaternion d2 = Quaternion.ONE.copy();
final Quaternion d3 = Quaternion.ONE.copy();
final Matrix3f a4 = this.copy();
a4.transpose();
a4.mul(this);
for (int integer5 = 0; integer5 < 5; ++integer5) {
d3.mul(stepJacobi(a4));
}
d3.normalize();
final Matrix3f a5 = new Matrix3f(this);
a5.mul(new Matrix3f(d3));
float float7 = 1.0f;
Pair<Float, Float> pair6 = qrGivensQuat(a5.m00, a5.m10);
final Float float8 = (Float)pair6.getFirst();
final Float float9 = (Float)pair6.getSecond();
final float float10 = float9 * float9 - float8 * float8;
final float float11 = -2.0f * float8 * float9;
final float float12 = float9 * float9 + float8 * float8;
final Quaternion d4 = new Quaternion(0.0f, 0.0f, float8, float9);
d2.mul(d4);
final Matrix3f a6 = new Matrix3f();
a6.setIdentity();
a6.m00 = float10;
a6.m11 = float10;
a6.m10 = float11;
a6.m01 = -float11;
a6.m22 = float12;
float7 *= float12;
a6.mul(a5);
pair6 = qrGivensQuat(a6.m00, a6.m20);
final float float13 = -(float)pair6.getFirst();
final Float float14 = (Float)pair6.getSecond();
final float float15 = float14 * float14 - float13 * float13;
final float float16 = -2.0f * float13 * float14;
final float float17 = float14 * float14 + float13 * float13;
final Quaternion d5 = new Quaternion(0.0f, float13, 0.0f, float14);
d2.mul(d5);
final Matrix3f a7 = new Matrix3f();
a7.setIdentity();
a7.m00 = float15;
a7.m22 = float15;
a7.m20 = -float16;
a7.m02 = float16;
a7.m11 = float17;
float7 *= float17;
a7.mul(a6);
pair6 = qrGivensQuat(a7.m11, a7.m21);
final Float float18 = (Float)pair6.getFirst();
final Float float19 = (Float)pair6.getSecond();
final float float20 = float19 * float19 - float18 * float18;
final float float21 = -2.0f * float18 * float19;
final float float22 = float19 * float19 + float18 * float18;
final Quaternion d6 = new Quaternion(float18, 0.0f, 0.0f, float19);
d2.mul(d6);
final Matrix3f a8 = new Matrix3f();
a8.setIdentity();
a8.m11 = float20;
a8.m22 = float20;
a8.m21 = float21;
a8.m12 = -float21;
a8.m00 = float22;
float7 *= float22;
a8.mul(a7);
float7 = 1.0f / float7;
d2.mul((float)Math.sqrt(float7));
final Vector3f g29 = new Vector3f(a8.m00 * float7, a8.m11 * float7, a8.m22 * float7);
return (Triple<Quaternion, Vector3f, Quaternion>)Triple.of(d2, g29, d3);
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Matrix3f a3 = (Matrix3f)object;
return Float.compare(a3.m00, this.m00) == 0 && Float.compare(a3.m01, this.m01) == 0 && Float.compare(a3.m02, this.m02) == 0 && Float.compare(a3.m10, this.m10) == 0 && Float.compare(a3.m11, this.m11) == 0 && Float.compare(a3.m12, this.m12) == 0 && Float.compare(a3.m20, this.m20) == 0 && Float.compare(a3.m21, this.m21) == 0 && Float.compare(a3.m22, this.m22) == 0;
}
@Override
public int hashCode() {
int integer2 = (this.m00 != 0.0f) ? Float.floatToIntBits(this.m00) : 0;
integer2 = 31 * integer2 + ((this.m01 != 0.0f) ? Float.floatToIntBits(this.m01) : 0);
integer2 = 31 * integer2 + ((this.m02 != 0.0f) ? Float.floatToIntBits(this.m02) : 0);
integer2 = 31 * integer2 + ((this.m10 != 0.0f) ? Float.floatToIntBits(this.m10) : 0);
integer2 = 31 * integer2 + ((this.m11 != 0.0f) ? Float.floatToIntBits(this.m11) : 0);
integer2 = 31 * integer2 + ((this.m12 != 0.0f) ? Float.floatToIntBits(this.m12) : 0);
integer2 = 31 * integer2 + ((this.m20 != 0.0f) ? Float.floatToIntBits(this.m20) : 0);
integer2 = 31 * integer2 + ((this.m21 != 0.0f) ? Float.floatToIntBits(this.m21) : 0);
integer2 = 31 * integer2 + ((this.m22 != 0.0f) ? Float.floatToIntBits(this.m22) : 0);
return integer2;
}
public void load(final Matrix3f a) {
this.m00 = a.m00;
this.m01 = a.m01;
this.m02 = a.m02;
this.m10 = a.m10;
this.m11 = a.m11;
this.m12 = a.m12;
this.m20 = a.m20;
this.m21 = a.m21;
this.m22 = a.m22;
}
@Override
public String toString() {
final StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.append("Matrix3f:\n");
stringBuilder2.append(this.m00);
stringBuilder2.append(" ");
stringBuilder2.append(this.m01);
stringBuilder2.append(" ");
stringBuilder2.append(this.m02);
stringBuilder2.append("\n");
stringBuilder2.append(this.m10);
stringBuilder2.append(" ");
stringBuilder2.append(this.m11);
stringBuilder2.append(" ");
stringBuilder2.append(this.m12);
stringBuilder2.append("\n");
stringBuilder2.append(this.m20);
stringBuilder2.append(" ");
stringBuilder2.append(this.m21);
stringBuilder2.append(" ");
stringBuilder2.append(this.m22);
stringBuilder2.append("\n");
return stringBuilder2.toString();
}
public void setIdentity() {
this.m00 = 1.0f;
this.m01 = 0.0f;
this.m02 = 0.0f;
this.m10 = 0.0f;
this.m11 = 1.0f;
this.m12 = 0.0f;
this.m20 = 0.0f;
this.m21 = 0.0f;
this.m22 = 1.0f;
}
public float adjugateAndDet() {
final float float2 = this.m11 * this.m22 - this.m12 * this.m21;
final float float3 = -(this.m10 * this.m22 - this.m12 * this.m20);
final float float4 = this.m10 * this.m21 - this.m11 * this.m20;
final float float5 = -(this.m01 * this.m22 - this.m02 * this.m21);
final float float6 = this.m00 * this.m22 - this.m02 * this.m20;
final float float7 = -(this.m00 * this.m21 - this.m01 * this.m20);
final float float8 = this.m01 * this.m12 - this.m02 * this.m11;
final float float9 = -(this.m00 * this.m12 - this.m02 * this.m10);
final float float10 = this.m00 * this.m11 - this.m01 * this.m10;
final float float11 = this.m00 * float2 + this.m01 * float3 + this.m02 * float4;
this.m00 = float2;
this.m10 = float3;
this.m20 = float4;
this.m01 = float5;
this.m11 = float6;
this.m21 = float7;
this.m02 = float8;
this.m12 = float9;
this.m22 = float10;
return float11;
}
public boolean invert() {
final float float2 = this.adjugateAndDet();
if (Math.abs(float2) > 1.0E-6f) {
this.mul(float2);
return true;
}
return false;
}
public void set(final int integer1, final int integer2, final float float3) {
if (integer1 == 0) {
if (integer2 == 0) {
this.m00 = float3;
}
else if (integer2 == 1) {
this.m01 = float3;
}
else {
this.m02 = float3;
}
}
else if (integer1 == 1) {
if (integer2 == 0) {
this.m10 = float3;
}
else if (integer2 == 1) {
this.m11 = float3;
}
else {
this.m12 = float3;
}
}
else if (integer2 == 0) {
this.m20 = float3;
}
else if (integer2 == 1) {
this.m21 = float3;
}
else {
this.m22 = float3;
}
}
public void mul(final Matrix3f a) {
final float float3 = this.m00 * a.m00 + this.m01 * a.m10 + this.m02 * a.m20;
final float float4 = this.m00 * a.m01 + this.m01 * a.m11 + this.m02 * a.m21;
final float float5 = this.m00 * a.m02 + this.m01 * a.m12 + this.m02 * a.m22;
final float float6 = this.m10 * a.m00 + this.m11 * a.m10 + this.m12 * a.m20;
final float float7 = this.m10 * a.m01 + this.m11 * a.m11 + this.m12 * a.m21;
final float float8 = this.m10 * a.m02 + this.m11 * a.m12 + this.m12 * a.m22;
final float float9 = this.m20 * a.m00 + this.m21 * a.m10 + this.m22 * a.m20;
final float float10 = this.m20 * a.m01 + this.m21 * a.m11 + this.m22 * a.m21;
final float float11 = this.m20 * a.m02 + this.m21 * a.m12 + this.m22 * a.m22;
this.m00 = float3;
this.m01 = float4;
this.m02 = float5;
this.m10 = float6;
this.m11 = float7;
this.m12 = float8;
this.m20 = float9;
this.m21 = float10;
this.m22 = float11;
}
public void mul(final Quaternion d) {
this.mul(new Matrix3f(d));
}
public void mul(final float float1) {
this.m00 *= float1;
this.m01 *= float1;
this.m02 *= float1;
this.m10 *= float1;
this.m11 *= float1;
this.m12 *= float1;
this.m20 *= float1;
this.m21 *= float1;
this.m22 *= float1;
}
public Matrix3f copy() {
return new Matrix3f(this);
}
static {
G = 3.0f + 2.0f * (float)Math.sqrt(2.0);
CS = (float)Math.cos(0.39269908169872414);
SS = (float)Math.sin(0.39269908169872414);
SQ2 = 1.0f / (float)Math.sqrt(2.0);
}
}

View File

@ -0,0 +1,375 @@
package com.mojang.math;
import java.nio.FloatBuffer;
public final class Matrix4f {
protected float m00;
protected float m01;
protected float m02;
protected float m03;
protected float m10;
protected float m11;
protected float m12;
protected float m13;
protected float m20;
protected float m21;
protected float m22;
protected float m23;
protected float m30;
protected float m31;
protected float m32;
protected float m33;
public Matrix4f() {
}
public Matrix4f(final Matrix4f b) {
this.m00 = b.m00;
this.m01 = b.m01;
this.m02 = b.m02;
this.m03 = b.m03;
this.m10 = b.m10;
this.m11 = b.m11;
this.m12 = b.m12;
this.m13 = b.m13;
this.m20 = b.m20;
this.m21 = b.m21;
this.m22 = b.m22;
this.m23 = b.m23;
this.m30 = b.m30;
this.m31 = b.m31;
this.m32 = b.m32;
this.m33 = b.m33;
}
public Matrix4f(final Quaternion d) {
final float float3 = d.i();
final float float4 = d.j();
final float float5 = d.k();
final float float6 = d.r();
final float float7 = 2.0f * float3 * float3;
final float float8 = 2.0f * float4 * float4;
final float float9 = 2.0f * float5 * float5;
this.m00 = 1.0f - float8 - float9;
this.m11 = 1.0f - float9 - float7;
this.m22 = 1.0f - float7 - float8;
this.m33 = 1.0f;
final float float10 = float3 * float4;
final float float11 = float4 * float5;
final float float12 = float5 * float3;
final float float13 = float3 * float6;
final float float14 = float4 * float6;
final float float15 = float5 * float6;
this.m10 = 2.0f * (float10 + float15);
this.m01 = 2.0f * (float10 - float15);
this.m20 = 2.0f * (float12 - float14);
this.m02 = 2.0f * (float12 + float14);
this.m21 = 2.0f * (float11 + float13);
this.m12 = 2.0f * (float11 - float13);
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Matrix4f b3 = (Matrix4f)object;
return Float.compare(b3.m00, this.m00) == 0 && Float.compare(b3.m01, this.m01) == 0 && Float.compare(b3.m02, this.m02) == 0 && Float.compare(b3.m03, this.m03) == 0 && Float.compare(b3.m10, this.m10) == 0 && Float.compare(b3.m11, this.m11) == 0 && Float.compare(b3.m12, this.m12) == 0 && Float.compare(b3.m13, this.m13) == 0 && Float.compare(b3.m20, this.m20) == 0 && Float.compare(b3.m21, this.m21) == 0 && Float.compare(b3.m22, this.m22) == 0 && Float.compare(b3.m23, this.m23) == 0 && Float.compare(b3.m30, this.m30) == 0 && Float.compare(b3.m31, this.m31) == 0 && Float.compare(b3.m32, this.m32) == 0 && Float.compare(b3.m33, this.m33) == 0;
}
@Override
public int hashCode() {
int integer2 = (this.m00 != 0.0f) ? Float.floatToIntBits(this.m00) : 0;
integer2 = 31 * integer2 + ((this.m01 != 0.0f) ? Float.floatToIntBits(this.m01) : 0);
integer2 = 31 * integer2 + ((this.m02 != 0.0f) ? Float.floatToIntBits(this.m02) : 0);
integer2 = 31 * integer2 + ((this.m03 != 0.0f) ? Float.floatToIntBits(this.m03) : 0);
integer2 = 31 * integer2 + ((this.m10 != 0.0f) ? Float.floatToIntBits(this.m10) : 0);
integer2 = 31 * integer2 + ((this.m11 != 0.0f) ? Float.floatToIntBits(this.m11) : 0);
integer2 = 31 * integer2 + ((this.m12 != 0.0f) ? Float.floatToIntBits(this.m12) : 0);
integer2 = 31 * integer2 + ((this.m13 != 0.0f) ? Float.floatToIntBits(this.m13) : 0);
integer2 = 31 * integer2 + ((this.m20 != 0.0f) ? Float.floatToIntBits(this.m20) : 0);
integer2 = 31 * integer2 + ((this.m21 != 0.0f) ? Float.floatToIntBits(this.m21) : 0);
integer2 = 31 * integer2 + ((this.m22 != 0.0f) ? Float.floatToIntBits(this.m22) : 0);
integer2 = 31 * integer2 + ((this.m23 != 0.0f) ? Float.floatToIntBits(this.m23) : 0);
integer2 = 31 * integer2 + ((this.m30 != 0.0f) ? Float.floatToIntBits(this.m30) : 0);
integer2 = 31 * integer2 + ((this.m31 != 0.0f) ? Float.floatToIntBits(this.m31) : 0);
integer2 = 31 * integer2 + ((this.m32 != 0.0f) ? Float.floatToIntBits(this.m32) : 0);
integer2 = 31 * integer2 + ((this.m33 != 0.0f) ? Float.floatToIntBits(this.m33) : 0);
return integer2;
}
private static int bufferIndex(final int integer1, final int integer2) {
return integer2 * 4 + integer1;
}
@Override
public String toString() {
final StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.append("Matrix4f:\n");
stringBuilder2.append(this.m00);
stringBuilder2.append(" ");
stringBuilder2.append(this.m01);
stringBuilder2.append(" ");
stringBuilder2.append(this.m02);
stringBuilder2.append(" ");
stringBuilder2.append(this.m03);
stringBuilder2.append("\n");
stringBuilder2.append(this.m10);
stringBuilder2.append(" ");
stringBuilder2.append(this.m11);
stringBuilder2.append(" ");
stringBuilder2.append(this.m12);
stringBuilder2.append(" ");
stringBuilder2.append(this.m13);
stringBuilder2.append("\n");
stringBuilder2.append(this.m20);
stringBuilder2.append(" ");
stringBuilder2.append(this.m21);
stringBuilder2.append(" ");
stringBuilder2.append(this.m22);
stringBuilder2.append(" ");
stringBuilder2.append(this.m23);
stringBuilder2.append("\n");
stringBuilder2.append(this.m30);
stringBuilder2.append(" ");
stringBuilder2.append(this.m31);
stringBuilder2.append(" ");
stringBuilder2.append(this.m32);
stringBuilder2.append(" ");
stringBuilder2.append(this.m33);
stringBuilder2.append("\n");
return stringBuilder2.toString();
}
public void store(final FloatBuffer floatBuffer) {
floatBuffer.put(bufferIndex(0, 0), this.m00);
floatBuffer.put(bufferIndex(0, 1), this.m01);
floatBuffer.put(bufferIndex(0, 2), this.m02);
floatBuffer.put(bufferIndex(0, 3), this.m03);
floatBuffer.put(bufferIndex(1, 0), this.m10);
floatBuffer.put(bufferIndex(1, 1), this.m11);
floatBuffer.put(bufferIndex(1, 2), this.m12);
floatBuffer.put(bufferIndex(1, 3), this.m13);
floatBuffer.put(bufferIndex(2, 0), this.m20);
floatBuffer.put(bufferIndex(2, 1), this.m21);
floatBuffer.put(bufferIndex(2, 2), this.m22);
floatBuffer.put(bufferIndex(2, 3), this.m23);
floatBuffer.put(bufferIndex(3, 0), this.m30);
floatBuffer.put(bufferIndex(3, 1), this.m31);
floatBuffer.put(bufferIndex(3, 2), this.m32);
floatBuffer.put(bufferIndex(3, 3), this.m33);
}
public void setIdentity() {
this.m00 = 1.0f;
this.m01 = 0.0f;
this.m02 = 0.0f;
this.m03 = 0.0f;
this.m10 = 0.0f;
this.m11 = 1.0f;
this.m12 = 0.0f;
this.m13 = 0.0f;
this.m20 = 0.0f;
this.m21 = 0.0f;
this.m22 = 1.0f;
this.m23 = 0.0f;
this.m30 = 0.0f;
this.m31 = 0.0f;
this.m32 = 0.0f;
this.m33 = 1.0f;
}
public float adjugateAndDet() {
final float float2 = this.m00 * this.m11 - this.m01 * this.m10;
final float float3 = this.m00 * this.m12 - this.m02 * this.m10;
final float float4 = this.m00 * this.m13 - this.m03 * this.m10;
final float float5 = this.m01 * this.m12 - this.m02 * this.m11;
final float float6 = this.m01 * this.m13 - this.m03 * this.m11;
final float float7 = this.m02 * this.m13 - this.m03 * this.m12;
final float float8 = this.m20 * this.m31 - this.m21 * this.m30;
final float float9 = this.m20 * this.m32 - this.m22 * this.m30;
final float float10 = this.m20 * this.m33 - this.m23 * this.m30;
final float float11 = this.m21 * this.m32 - this.m22 * this.m31;
final float float12 = this.m21 * this.m33 - this.m23 * this.m31;
final float float13 = this.m22 * this.m33 - this.m23 * this.m32;
final float float14 = this.m11 * float13 - this.m12 * float12 + this.m13 * float11;
final float float15 = -this.m10 * float13 + this.m12 * float10 - this.m13 * float9;
final float float16 = this.m10 * float12 - this.m11 * float10 + this.m13 * float8;
final float float17 = -this.m10 * float11 + this.m11 * float9 - this.m12 * float8;
final float float18 = -this.m01 * float13 + this.m02 * float12 - this.m03 * float11;
final float float19 = this.m00 * float13 - this.m02 * float10 + this.m03 * float9;
final float float20 = -this.m00 * float12 + this.m01 * float10 - this.m03 * float8;
final float float21 = this.m00 * float11 - this.m01 * float9 + this.m02 * float8;
final float float22 = this.m31 * float7 - this.m32 * float6 + this.m33 * float5;
final float float23 = -this.m30 * float7 + this.m32 * float4 - this.m33 * float3;
final float float24 = this.m30 * float6 - this.m31 * float4 + this.m33 * float2;
final float float25 = -this.m30 * float5 + this.m31 * float3 - this.m32 * float2;
final float float26 = -this.m21 * float7 + this.m22 * float6 - this.m23 * float5;
final float float27 = this.m20 * float7 - this.m22 * float4 + this.m23 * float3;
final float float28 = -this.m20 * float6 + this.m21 * float4 - this.m23 * float2;
final float float29 = this.m20 * float5 - this.m21 * float3 + this.m22 * float2;
this.m00 = float14;
this.m10 = float15;
this.m20 = float16;
this.m30 = float17;
this.m01 = float18;
this.m11 = float19;
this.m21 = float20;
this.m31 = float21;
this.m02 = float22;
this.m12 = float23;
this.m22 = float24;
this.m32 = float25;
this.m03 = float26;
this.m13 = float27;
this.m23 = float28;
this.m33 = float29;
return float2 * float13 - float3 * float12 + float4 * float11 + float5 * float10 - float6 * float9 + float7 * float8;
}
public void transpose() {
float float2 = this.m10;
this.m10 = this.m01;
this.m01 = float2;
float2 = this.m20;
this.m20 = this.m02;
this.m02 = float2;
float2 = this.m21;
this.m21 = this.m12;
this.m12 = float2;
float2 = this.m30;
this.m30 = this.m03;
this.m03 = float2;
float2 = this.m31;
this.m31 = this.m13;
this.m13 = float2;
float2 = this.m32;
this.m32 = this.m23;
this.m23 = float2;
}
public boolean invert() {
final float float2 = this.adjugateAndDet();
if (Math.abs(float2) > 1.0E-6f) {
this.multiply(float2);
return true;
}
return false;
}
public void multiply(final Matrix4f b) {
final float float3 = this.m00 * b.m00 + this.m01 * b.m10 + this.m02 * b.m20 + this.m03 * b.m30;
final float float4 = this.m00 * b.m01 + this.m01 * b.m11 + this.m02 * b.m21 + this.m03 * b.m31;
final float float5 = this.m00 * b.m02 + this.m01 * b.m12 + this.m02 * b.m22 + this.m03 * b.m32;
final float float6 = this.m00 * b.m03 + this.m01 * b.m13 + this.m02 * b.m23 + this.m03 * b.m33;
final float float7 = this.m10 * b.m00 + this.m11 * b.m10 + this.m12 * b.m20 + this.m13 * b.m30;
final float float8 = this.m10 * b.m01 + this.m11 * b.m11 + this.m12 * b.m21 + this.m13 * b.m31;
final float float9 = this.m10 * b.m02 + this.m11 * b.m12 + this.m12 * b.m22 + this.m13 * b.m32;
final float float10 = this.m10 * b.m03 + this.m11 * b.m13 + this.m12 * b.m23 + this.m13 * b.m33;
final float float11 = this.m20 * b.m00 + this.m21 * b.m10 + this.m22 * b.m20 + this.m23 * b.m30;
final float float12 = this.m20 * b.m01 + this.m21 * b.m11 + this.m22 * b.m21 + this.m23 * b.m31;
final float float13 = this.m20 * b.m02 + this.m21 * b.m12 + this.m22 * b.m22 + this.m23 * b.m32;
final float float14 = this.m20 * b.m03 + this.m21 * b.m13 + this.m22 * b.m23 + this.m23 * b.m33;
final float float15 = this.m30 * b.m00 + this.m31 * b.m10 + this.m32 * b.m20 + this.m33 * b.m30;
final float float16 = this.m30 * b.m01 + this.m31 * b.m11 + this.m32 * b.m21 + this.m33 * b.m31;
final float float17 = this.m30 * b.m02 + this.m31 * b.m12 + this.m32 * b.m22 + this.m33 * b.m32;
final float float18 = this.m30 * b.m03 + this.m31 * b.m13 + this.m32 * b.m23 + this.m33 * b.m33;
this.m00 = float3;
this.m01 = float4;
this.m02 = float5;
this.m03 = float6;
this.m10 = float7;
this.m11 = float8;
this.m12 = float9;
this.m13 = float10;
this.m20 = float11;
this.m21 = float12;
this.m22 = float13;
this.m23 = float14;
this.m30 = float15;
this.m31 = float16;
this.m32 = float17;
this.m33 = float18;
}
public void multiply(final Quaternion d) {
this.multiply(new Matrix4f(d));
}
public void multiply(final float float1) {
this.m00 *= float1;
this.m01 *= float1;
this.m02 *= float1;
this.m03 *= float1;
this.m10 *= float1;
this.m11 *= float1;
this.m12 *= float1;
this.m13 *= float1;
this.m20 *= float1;
this.m21 *= float1;
this.m22 *= float1;
this.m23 *= float1;
this.m30 *= float1;
this.m31 *= float1;
this.m32 *= float1;
this.m33 *= float1;
}
public static Matrix4f perspective(final double double1, final float float2, final float float3, final float float4) {
final float float5 = (float)(1.0 / Math.tan(double1 * 0.01745329238474369 / 2.0));
final Matrix4f b7 = new Matrix4f();
b7.m00 = float5 / float2;
b7.m11 = float5;
b7.m22 = (float4 + float3) / (float3 - float4);
b7.m32 = -1.0f;
b7.m23 = 2.0f * float4 * float3 / (float3 - float4);
return b7;
}
public static Matrix4f orthographic(final float float1, final float float2, final float float3, final float float4) {
final Matrix4f b5 = new Matrix4f();
b5.m00 = 2.0f / float1;
b5.m11 = 2.0f / float2;
final float float5 = float4 - float3;
b5.m22 = -2.0f / float5;
b5.m33 = 1.0f;
b5.m03 = -1.0f;
b5.m13 = -1.0f;
b5.m23 = -(float4 + float3) / float5;
return b5;
}
public void translate(final Vector3f g) {
this.m03 += g.x();
this.m13 += g.y();
this.m23 += g.z();
}
public Matrix4f copy() {
return new Matrix4f(this);
}
public static Matrix4f createScaleMatrix(final float float1, final float float2, final float float3) {
final Matrix4f b4 = new Matrix4f();
b4.m00 = float1;
b4.m11 = float2;
b4.m22 = float3;
b4.m33 = 1.0f;
return b4;
}
public static Matrix4f createTranslateMatrix(final float float1, final float float2, final float float3) {
final Matrix4f b4 = new Matrix4f();
b4.m00 = 1.0f;
b4.m11 = 1.0f;
b4.m22 = 1.0f;
b4.m33 = 1.0f;
b4.m03 = float1;
b4.m13 = float2;
b4.m23 = float3;
return b4;
}
}

View File

@ -0,0 +1,178 @@
package com.mojang.math;
import net.minecraft.Util;
import java.util.stream.Collectors;
import com.mojang.datafixers.util.Pair;
import java.util.Arrays;
import net.minecraft.core.FrontAndTop;
import com.google.common.collect.Maps;
import it.unimi.dsi.fastutil.booleans.BooleanArrayList;
import it.unimi.dsi.fastutil.booleans.BooleanList;
import javax.annotation.Nullable;
import net.minecraft.core.Direction;
import java.util.Map;
import net.minecraft.util.StringRepresentable;
public enum OctahedralGroup implements StringRepresentable {
IDENTITY("identity", SymmetricGroup3.P123, false, false, false),
ROT_180_FACE_XY("rot_180_face_xy", SymmetricGroup3.P123, true, true, false),
ROT_180_FACE_XZ("rot_180_face_xz", SymmetricGroup3.P123, true, false, true),
ROT_180_FACE_YZ("rot_180_face_yz", SymmetricGroup3.P123, false, true, true),
ROT_120_NNN("rot_120_nnn", SymmetricGroup3.P231, false, false, false),
ROT_120_NNP("rot_120_nnp", SymmetricGroup3.P312, true, false, true),
ROT_120_NPN("rot_120_npn", SymmetricGroup3.P312, false, true, true),
ROT_120_NPP("rot_120_npp", SymmetricGroup3.P231, true, false, true),
ROT_120_PNN("rot_120_pnn", SymmetricGroup3.P312, true, true, false),
ROT_120_PNP("rot_120_pnp", SymmetricGroup3.P231, true, true, false),
ROT_120_PPN("rot_120_ppn", SymmetricGroup3.P231, false, true, true),
ROT_120_PPP("rot_120_ppp", SymmetricGroup3.P312, false, false, false),
ROT_180_EDGE_XY_NEG("rot_180_edge_xy_neg", SymmetricGroup3.P213, true, true, true),
ROT_180_EDGE_XY_POS("rot_180_edge_xy_pos", SymmetricGroup3.P213, false, false, true),
ROT_180_EDGE_XZ_NEG("rot_180_edge_xz_neg", SymmetricGroup3.P321, true, true, true),
ROT_180_EDGE_XZ_POS("rot_180_edge_xz_pos", SymmetricGroup3.P321, false, true, false),
ROT_180_EDGE_YZ_NEG("rot_180_edge_yz_neg", SymmetricGroup3.P132, true, true, true),
ROT_180_EDGE_YZ_POS("rot_180_edge_yz_pos", SymmetricGroup3.P132, true, false, false),
ROT_90_X_NEG("rot_90_x_neg", SymmetricGroup3.P132, false, false, true),
ROT_90_X_POS("rot_90_x_pos", SymmetricGroup3.P132, false, true, false),
ROT_90_Y_NEG("rot_90_y_neg", SymmetricGroup3.P321, true, false, false),
ROT_90_Y_POS("rot_90_y_pos", SymmetricGroup3.P321, false, false, true),
ROT_90_Z_NEG("rot_90_z_neg", SymmetricGroup3.P213, false, true, false),
ROT_90_Z_POS("rot_90_z_pos", SymmetricGroup3.P213, true, false, false),
INVERSION("inversion", SymmetricGroup3.P123, true, true, true),
INVERT_X("invert_x", SymmetricGroup3.P123, true, false, false),
INVERT_Y("invert_y", SymmetricGroup3.P123, false, true, false),
INVERT_Z("invert_z", SymmetricGroup3.P123, false, false, true),
ROT_60_REF_NNN("rot_60_ref_nnn", SymmetricGroup3.P312, true, true, true),
ROT_60_REF_NNP("rot_60_ref_nnp", SymmetricGroup3.P231, true, false, false),
ROT_60_REF_NPN("rot_60_ref_npn", SymmetricGroup3.P231, false, false, true),
ROT_60_REF_NPP("rot_60_ref_npp", SymmetricGroup3.P312, false, false, true),
ROT_60_REF_PNN("rot_60_ref_pnn", SymmetricGroup3.P231, false, true, false),
ROT_60_REF_PNP("rot_60_ref_pnp", SymmetricGroup3.P312, true, false, false),
ROT_60_REF_PPN("rot_60_ref_ppn", SymmetricGroup3.P312, false, true, false),
ROT_60_REF_PPP("rot_60_ref_ppp", SymmetricGroup3.P231, true, true, true),
SWAP_XY("swap_xy", SymmetricGroup3.P213, false, false, false),
SWAP_YZ("swap_yz", SymmetricGroup3.P132, false, false, false),
SWAP_XZ("swap_xz", SymmetricGroup3.P321, false, false, false),
SWAP_NEG_XY("swap_neg_xy", SymmetricGroup3.P213, true, true, false),
SWAP_NEG_YZ("swap_neg_yz", SymmetricGroup3.P132, false, true, true),
SWAP_NEG_XZ("swap_neg_xz", SymmetricGroup3.P321, true, false, true),
ROT_90_REF_X_NEG("rot_90_ref_x_neg", SymmetricGroup3.P132, true, false, true),
ROT_90_REF_X_POS("rot_90_ref_x_pos", SymmetricGroup3.P132, true, true, false),
ROT_90_REF_Y_NEG("rot_90_ref_y_neg", SymmetricGroup3.P321, true, true, false),
ROT_90_REF_Y_POS("rot_90_ref_y_pos", SymmetricGroup3.P321, false, true, true),
ROT_90_REF_Z_NEG("rot_90_ref_z_neg", SymmetricGroup3.P213, false, true, true),
ROT_90_REF_Z_POS("rot_90_ref_z_pos", SymmetricGroup3.P213, true, false, true);
private final Matrix3f transformation;
private final String name;
@Nullable
private Map<Direction, Direction> rotatedDirections;
private final boolean invertX;
private final boolean invertY;
private final boolean invertZ;
private final SymmetricGroup3 permutation;
private static final OctahedralGroup[][] cayleyTable;
private static final OctahedralGroup[] inverseTable;
private OctahedralGroup(final String string3, final SymmetricGroup3 e, final boolean boolean5, final boolean boolean6, final boolean boolean7) {
this.name = string3;
this.invertX = boolean5;
this.invertY = boolean6;
this.invertZ = boolean7;
this.permutation = e;
this.transformation = new Matrix3f();
this.transformation.m00 = (boolean5 ? -1.0f : 1.0f);
this.transformation.m11 = (boolean6 ? -1.0f : 1.0f);
this.transformation.m22 = (boolean7 ? -1.0f : 1.0f);
this.transformation.mul(e.transformation());
}
private BooleanList packInversions() {
return (BooleanList)new BooleanArrayList(new boolean[] { this.invertX, this.invertY, this.invertZ });
}
public OctahedralGroup compose(final OctahedralGroup c) {
return OctahedralGroup.cayleyTable[this.ordinal()][c.ordinal()];
}
@Override
public String toString() {
return this.name;
}
@Override
public String getSerializedName() {
return this.name;
}
public Direction rotate(final Direction fz) {
if (this.rotatedDirections == null) {
this.rotatedDirections = Maps.newEnumMap(Direction.class);
for (final Direction fz2 : Direction.values()) {
final Direction.Axis a7 = fz2.getAxis();
final Direction.AxisDirection b8 = fz2.getAxisDirection();
final Direction.Axis a8 = Direction.Axis.values()[this.permutation.permutation(a7.ordinal())];
final Direction.AxisDirection b9 = this.inverts(a8) ? b8.opposite() : b8;
final Direction fz3 = Direction.fromAxisAndDirection(a8, b9);
this.rotatedDirections.put(fz2, fz3);
}
}
return this.rotatedDirections.get(fz);
}
public boolean inverts(final Direction.Axis a) {
switch (a) {
case X: {
return this.invertX;
}
case Y: {
return this.invertY;
}
default: {
return this.invertZ;
}
}
}
public FrontAndTop rotate(final FrontAndTop gb) {
return FrontAndTop.fromFrontAndTop(this.rotate(gb.front()), this.rotate(gb.top()));
}
static {
final Map<Pair<SymmetricGroup3, BooleanList>, OctahedralGroup> map2;
final OctahedralGroup[] array;
int length;
int i = 0;
OctahedralGroup c3;
final OctahedralGroup[] array2;
int length2;
int j = 0;
OctahedralGroup c4;
BooleanList booleanList11;
BooleanList booleanList12;
SymmetricGroup3 e13;
BooleanArrayList booleanArrayList14;
int integer2;
cayleyTable = Util.<OctahedralGroup[][]>make(new OctahedralGroup[values().length][values().length], arr -> {
map2 = Arrays.<OctahedralGroup>stream(values()).collect(Collectors.toMap(c -> Pair.of(c.permutation, c.packInversions()), c -> c));
values();
for (length = array.length; i < length; ++i) {
c3 = array[i];
values();
for (length2 = array2.length; j < length2; ++j) {
c4 = array2[j];
booleanList11 = c3.packInversions();
booleanList12 = c4.packInversions();
e13 = c4.permutation.compose(c3.permutation);
booleanArrayList14 = new BooleanArrayList(3);
for (integer2 = 0; integer2 < 3; ++integer2) {
booleanArrayList14.add(booleanList11.getBoolean(integer2) ^ booleanList12.getBoolean(c3.permutation.permutation(integer2)));
}
arr[c3.ordinal()][c4.ordinal()] = map2.get(Pair.of(e13, booleanArrayList14));
}
}
return;
});
inverseTable = Arrays.<OctahedralGroup>stream(values()).map(c -> Arrays.<OctahedralGroup>stream(values()).filter(c2 -> c.compose(c2) == OctahedralGroup.IDENTITY).findAny().get()).<OctahedralGroup>toArray(OctahedralGroup[]::new);
}
}

View File

@ -0,0 +1,169 @@
package com.mojang.math;
import net.minecraft.util.Mth;
public final class Quaternion {
public static final Quaternion ONE;
private float i;
private float j;
private float k;
private float r;
public Quaternion(final float float1, final float float2, final float float3, final float float4) {
this.i = float1;
this.j = float2;
this.k = float3;
this.r = float4;
}
public Quaternion(final Vector3f g, float float2, final boolean boolean3) {
if (boolean3) {
float2 *= 0.017453292f;
}
final float float3 = sin(float2 / 2.0f);
this.i = g.x() * float3;
this.j = g.y() * float3;
this.k = g.z() * float3;
this.r = cos(float2 / 2.0f);
}
public Quaternion(float float1, float float2, float float3, final boolean boolean4) {
if (boolean4) {
float1 *= 0.017453292f;
float2 *= 0.017453292f;
float3 *= 0.017453292f;
}
final float float4 = sin(0.5f * float1);
final float float5 = cos(0.5f * float1);
final float float6 = sin(0.5f * float2);
final float float7 = cos(0.5f * float2);
final float float8 = sin(0.5f * float3);
final float float9 = cos(0.5f * float3);
this.i = float4 * float7 * float9 + float5 * float6 * float8;
this.j = float5 * float6 * float9 - float4 * float7 * float8;
this.k = float4 * float6 * float9 + float5 * float7 * float8;
this.r = float5 * float7 * float9 - float4 * float6 * float8;
}
public Quaternion(final Quaternion d) {
this.i = d.i;
this.j = d.j;
this.k = d.k;
this.r = d.r;
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Quaternion d3 = (Quaternion)object;
return Float.compare(d3.i, this.i) == 0 && Float.compare(d3.j, this.j) == 0 && Float.compare(d3.k, this.k) == 0 && Float.compare(d3.r, this.r) == 0;
}
@Override
public int hashCode() {
int integer2 = Float.floatToIntBits(this.i);
integer2 = 31 * integer2 + Float.floatToIntBits(this.j);
integer2 = 31 * integer2 + Float.floatToIntBits(this.k);
integer2 = 31 * integer2 + Float.floatToIntBits(this.r);
return integer2;
}
@Override
public String toString() {
final StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.append("Quaternion[").append(this.r()).append(" + ");
stringBuilder2.append(this.i()).append("i + ");
stringBuilder2.append(this.j()).append("j + ");
stringBuilder2.append(this.k()).append("k]");
return stringBuilder2.toString();
}
public float i() {
return this.i;
}
public float j() {
return this.j;
}
public float k() {
return this.k;
}
public float r() {
return this.r;
}
public void mul(final Quaternion d) {
final float float3 = this.i();
final float float4 = this.j();
final float float5 = this.k();
final float float6 = this.r();
final float float7 = d.i();
final float float8 = d.j();
final float float9 = d.k();
final float float10 = d.r();
this.i = float6 * float7 + float3 * float10 + float4 * float9 - float5 * float8;
this.j = float6 * float8 - float3 * float9 + float4 * float10 + float5 * float7;
this.k = float6 * float9 + float3 * float8 - float4 * float7 + float5 * float10;
this.r = float6 * float10 - float3 * float7 - float4 * float8 - float5 * float9;
}
public void mul(final float float1) {
this.i *= float1;
this.j *= float1;
this.k *= float1;
this.r *= float1;
}
public void conj() {
this.i = -this.i;
this.j = -this.j;
this.k = -this.k;
}
public void set(final float float1, final float float2, final float float3, final float float4) {
this.i = float1;
this.j = float2;
this.k = float3;
this.r = float4;
}
private static float cos(final float float1) {
return (float)Math.cos(float1);
}
private static float sin(final float float1) {
return (float)Math.sin(float1);
}
public void normalize() {
final float float2 = this.i() * this.i() + this.j() * this.j() + this.k() * this.k() + this.r() * this.r();
if (float2 > 1.0E-6f) {
final float float3 = Mth.fastInvSqrt(float2);
this.i *= float3;
this.j *= float3;
this.k *= float3;
this.r *= float3;
}
else {
this.i = 0.0f;
this.j = 0.0f;
this.k = 0.0f;
this.r = 0.0f;
}
}
public Quaternion copy() {
return new Quaternion(this);
}
static {
ONE = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
}
}

View File

@ -0,0 +1,66 @@
package com.mojang.math;
import net.minecraft.Util;
import java.util.Arrays;
public enum SymmetricGroup3 {
P123(0, 1, 2),
P213(1, 0, 2),
P132(0, 2, 1),
P231(1, 2, 0),
P312(2, 0, 1),
P321(2, 1, 0);
private final int[] permutation;
private final Matrix3f transformation;
private static final SymmetricGroup3[][] cayleyTable;
private SymmetricGroup3(final int integer3, final int integer4, final int integer5) {
this.permutation = new int[] { integer3, integer4, integer5 };
(this.transformation = new Matrix3f()).set(0, this.permutation(0), 1.0f);
this.transformation.set(1, this.permutation(1), 1.0f);
this.transformation.set(2, this.permutation(2), 1.0f);
}
public SymmetricGroup3 compose(final SymmetricGroup3 e) {
return SymmetricGroup3.cayleyTable[this.ordinal()][e.ordinal()];
}
public int permutation(final int integer) {
return this.permutation[integer];
}
public Matrix3f transformation() {
return this.transformation;
}
static {
final SymmetricGroup3[] array;
int length;
int i = 0;
SymmetricGroup3 e2;
final SymmetricGroup3[] array2;
int length2;
int j = 0;
SymmetricGroup3 e3;
int[] arr2;
int integer11;
SymmetricGroup3 e4;
cayleyTable = Util.<SymmetricGroup3[][]>make(new SymmetricGroup3[values().length][values().length], arr -> {
values();
for (length = array.length; i < length; ++i) {
e2 = array[i];
values();
for (length2 = array2.length; j < length2; ++j) {
e3 = array2[j];
arr2 = new int[3];
for (integer11 = 0; integer11 < 3; ++integer11) {
arr2[integer11] = e2.permutation[e3.permutation[integer11]];
}
e4 = Arrays.<SymmetricGroup3>stream(values()).filter(e -> Arrays.equals(e.permutation, arr2)).findFirst().get();
arr[e2.ordinal()][e3.ordinal()] = e4;
}
}
});
}
}

View File

@ -0,0 +1,138 @@
package com.mojang.math;
import net.minecraft.Util;
import java.util.Objects;
import org.apache.commons.lang3.tuple.Triple;
import com.mojang.datafixers.util.Pair;
import javax.annotation.Nullable;
public final class Transformation {
private final Matrix4f matrix;
private boolean decomposed;
@Nullable
private Vector3f translation;
@Nullable
private Quaternion leftRotation;
@Nullable
private Vector3f scale;
@Nullable
private Quaternion rightRotation;
private static final Transformation IDENTITY;
public Transformation(@Nullable final Matrix4f b) {
if (b == null) {
this.matrix = Transformation.IDENTITY.matrix;
}
else {
this.matrix = b;
}
}
public Transformation(@Nullable final Vector3f g1, @Nullable final Quaternion d2, @Nullable final Vector3f g3, @Nullable final Quaternion d4) {
this.matrix = compose(g1, d2, g3, d4);
this.translation = ((g1 != null) ? g1 : new Vector3f());
this.leftRotation = ((d2 != null) ? d2 : Quaternion.ONE.copy());
this.scale = ((g3 != null) ? g3 : new Vector3f(1.0f, 1.0f, 1.0f));
this.rightRotation = ((d4 != null) ? d4 : Quaternion.ONE.copy());
this.decomposed = true;
}
public static Transformation identity() {
return Transformation.IDENTITY;
}
public Transformation compose(final Transformation f) {
final Matrix4f b3 = this.getMatrix();
b3.multiply(f.getMatrix());
return new Transformation(b3);
}
@Nullable
public Transformation inverse() {
if (this == Transformation.IDENTITY) {
return this;
}
final Matrix4f b2 = this.getMatrix();
if (b2.invert()) {
return new Transformation(b2);
}
return null;
}
private void ensureDecomposed() {
if (!this.decomposed) {
final Pair<Matrix3f, Vector3f> pair2 = toAffine(this.matrix);
final Triple<Quaternion, Vector3f, Quaternion> triple3 = ((Matrix3f)pair2.getFirst()).svdDecompose();
this.translation = (Vector3f)pair2.getSecond();
this.leftRotation = (Quaternion)triple3.getLeft();
this.scale = (Vector3f)triple3.getMiddle();
this.rightRotation = (Quaternion)triple3.getRight();
this.decomposed = true;
}
}
private static Matrix4f compose(@Nullable final Vector3f g1, @Nullable final Quaternion d2, @Nullable final Vector3f g3, @Nullable final Quaternion d4) {
final Matrix4f b5 = new Matrix4f();
b5.setIdentity();
if (d2 != null) {
b5.multiply(new Matrix4f(d2));
}
if (g3 != null) {
b5.multiply(Matrix4f.createScaleMatrix(g3.x(), g3.y(), g3.z()));
}
if (d4 != null) {
b5.multiply(new Matrix4f(d4));
}
if (g1 != null) {
b5.m03 = g1.x();
b5.m13 = g1.y();
b5.m23 = g1.z();
}
return b5;
}
public static Pair<Matrix3f, Vector3f> toAffine(final Matrix4f b) {
b.multiply(1.0f / b.m33);
final Vector3f g2 = new Vector3f(b.m03, b.m13, b.m23);
final Matrix3f a3 = new Matrix3f(b);
return (Pair<Matrix3f, Vector3f>)Pair.of(a3, g2);
}
public Matrix4f getMatrix() {
return this.matrix.copy();
}
public Quaternion getLeftRotation() {
this.ensureDecomposed();
return this.leftRotation.copy();
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Transformation f3 = (Transformation)object;
return Objects.equals(this.matrix, f3.matrix);
}
@Override
public int hashCode() {
return Objects.hash(this.matrix);
}
static {
final Matrix4f b1;
final Transformation f2;
IDENTITY = Util.<Transformation>make(() -> {
b1 = new Matrix4f();
b1.setIdentity();
f2 = new Transformation(b1);
f2.getLeftRotation();
return f2;
});
}
}

View File

@ -0,0 +1,13 @@
package com.mojang.math;
public class Vector3d {
public double x;
public double y;
public double z;
public Vector3d(final double double1, final double double2, final double double3) {
this.x = double1;
this.y = double2;
this.z = double3;
}
}

View File

@ -0,0 +1,189 @@
package com.mojang.math;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
public final class Vector3f {
public static Vector3f XN;
public static Vector3f XP;
public static Vector3f YN;
public static Vector3f YP;
public static Vector3f ZN;
public static Vector3f ZP;
private float x;
private float y;
private float z;
public Vector3f() {
}
public Vector3f(final float float1, final float float2, final float float3) {
this.x = float1;
this.y = float2;
this.z = float3;
}
public Vector3f(final Vec3 dem) {
this((float)dem.x, (float)dem.y, (float)dem.z);
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Vector3f g3 = (Vector3f)object;
return Float.compare(g3.x, this.x) == 0 && Float.compare(g3.y, this.y) == 0 && Float.compare(g3.z, this.z) == 0;
}
@Override
public int hashCode() {
int integer2 = Float.floatToIntBits(this.x);
integer2 = 31 * integer2 + Float.floatToIntBits(this.y);
integer2 = 31 * integer2 + Float.floatToIntBits(this.z);
return integer2;
}
public float x() {
return this.x;
}
public float y() {
return this.y;
}
public float z() {
return this.z;
}
public void mul(final float float1) {
this.x *= float1;
this.y *= float1;
this.z *= float1;
}
public void mul(final float float1, final float float2, final float float3) {
this.x *= float1;
this.y *= float2;
this.z *= float3;
}
public void clamp(final float float1, final float float2) {
this.x = Mth.clamp(this.x, float1, float2);
this.y = Mth.clamp(this.y, float1, float2);
this.z = Mth.clamp(this.z, float1, float2);
}
public void set(final float float1, final float float2, final float float3) {
this.x = float1;
this.y = float2;
this.z = float3;
}
public void add(final float float1, final float float2, final float float3) {
this.x += float1;
this.y += float2;
this.z += float3;
}
public void add(final Vector3f g) {
this.x += g.x;
this.y += g.y;
this.z += g.z;
}
public void sub(final Vector3f g) {
this.x -= g.x;
this.y -= g.y;
this.z -= g.z;
}
public float dot(final Vector3f g) {
return this.x * g.x + this.y * g.y + this.z * g.z;
}
public boolean normalize() {
final float float2 = this.x * this.x + this.y * this.y + this.z * this.z;
if (float2 < 1.0E-5) {
return false;
}
final float float3 = Mth.fastInvSqrt(float2);
this.x *= float3;
this.y *= float3;
this.z *= float3;
return true;
}
public void cross(final Vector3f g) {
final float float3 = this.x;
final float float4 = this.y;
final float float5 = this.z;
final float float6 = g.x();
final float float7 = g.y();
final float float8 = g.z();
this.x = float4 * float8 - float5 * float7;
this.y = float5 * float6 - float3 * float8;
this.z = float3 * float7 - float4 * float6;
}
public void transform(final Matrix3f a) {
final float float3 = this.x;
final float float4 = this.y;
final float float5 = this.z;
this.x = a.m00 * float3 + a.m01 * float4 + a.m02 * float5;
this.y = a.m10 * float3 + a.m11 * float4 + a.m12 * float5;
this.z = a.m20 * float3 + a.m21 * float4 + a.m22 * float5;
}
public void transform(final Quaternion d) {
final Quaternion d2 = new Quaternion(d);
d2.mul(new Quaternion(this.x(), this.y(), this.z(), 0.0f));
final Quaternion d3 = new Quaternion(d);
d3.conj();
d2.mul(d3);
this.set(d2.i(), d2.j(), d2.k());
}
public void lerp(final Vector3f g, final float float2) {
final float float3 = 1.0f - float2;
this.x = this.x * float3 + g.x * float2;
this.y = this.y * float3 + g.y * float2;
this.z = this.z * float3 + g.z * float2;
}
public Quaternion rotation(final float float1) {
return new Quaternion(this, float1, false);
}
public Quaternion rotationDegrees(final float float1) {
return new Quaternion(this, float1, true);
}
public Vector3f copy() {
return new Vector3f(this.x, this.y, this.z);
}
public void map(final Float2FloatFunction float2FloatFunction) {
this.x = float2FloatFunction.get(this.x);
this.y = float2FloatFunction.get(this.y);
this.z = float2FloatFunction.get(this.z);
}
@Override
public String toString() {
return "[" + this.x + ", " + this.y + ", " + this.z + "]";
}
static {
Vector3f.XN = new Vector3f(-1.0f, 0.0f, 0.0f);
Vector3f.XP = new Vector3f(1.0f, 0.0f, 0.0f);
Vector3f.YN = new Vector3f(0.0f, -1.0f, 0.0f);
Vector3f.YP = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f.ZN = new Vector3f(0.0f, 0.0f, -1.0f);
Vector3f.ZP = new Vector3f(0.0f, 0.0f, 1.0f);
}
}

View File

@ -0,0 +1,123 @@
package com.mojang.math;
import net.minecraft.util.Mth;
public class Vector4f {
private float x;
private float y;
private float z;
private float w;
public Vector4f() {
}
public Vector4f(final float float1, final float float2, final float float3, final float float4) {
this.x = float1;
this.y = float2;
this.z = float3;
this.w = float4;
}
public Vector4f(final Vector3f g) {
this(g.x(), g.y(), g.z(), 1.0f);
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Vector4f h3 = (Vector4f)object;
return Float.compare(h3.x, this.x) == 0 && Float.compare(h3.y, this.y) == 0 && Float.compare(h3.z, this.z) == 0 && Float.compare(h3.w, this.w) == 0;
}
@Override
public int hashCode() {
int integer2 = Float.floatToIntBits(this.x);
integer2 = 31 * integer2 + Float.floatToIntBits(this.y);
integer2 = 31 * integer2 + Float.floatToIntBits(this.z);
integer2 = 31 * integer2 + Float.floatToIntBits(this.w);
return integer2;
}
public float x() {
return this.x;
}
public float y() {
return this.y;
}
public float z() {
return this.z;
}
public float w() {
return this.w;
}
public void mul(final Vector3f g) {
this.x *= g.x();
this.y *= g.y();
this.z *= g.z();
}
public void set(final float float1, final float float2, final float float3, final float float4) {
this.x = float1;
this.y = float2;
this.z = float3;
this.w = float4;
}
public float dot(final Vector4f h) {
return this.x * h.x + this.y * h.y + this.z * h.z + this.w * h.w;
}
public boolean normalize() {
final float float2 = this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
if (float2 < 1.0E-5) {
return false;
}
final float float3 = Mth.fastInvSqrt(float2);
this.x *= float3;
this.y *= float3;
this.z *= float3;
this.w *= float3;
return true;
}
public void transform(final Matrix4f b) {
final float float3 = this.x;
final float float4 = this.y;
final float float5 = this.z;
final float float6 = this.w;
this.x = b.m00 * float3 + b.m01 * float4 + b.m02 * float5 + b.m03 * float6;
this.y = b.m10 * float3 + b.m11 * float4 + b.m12 * float5 + b.m13 * float6;
this.z = b.m20 * float3 + b.m21 * float4 + b.m22 * float5 + b.m23 * float6;
this.w = b.m30 * float3 + b.m31 * float4 + b.m32 * float5 + b.m33 * float6;
}
public void transform(final Quaternion d) {
final Quaternion d2 = new Quaternion(d);
d2.mul(new Quaternion(this.x(), this.y(), this.z(), 0.0f));
final Quaternion d3 = new Quaternion(d);
d3.conj();
d2.mul(d3);
this.set(d2.i(), d2.j(), d2.k(), this.w());
}
public void perspectiveDivide() {
this.x /= this.w;
this.y /= this.w;
this.z /= this.w;
this.w = 1.0f;
}
@Override
public String toString() {
return "[" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + "]";
}
}

View File

@ -0,0 +1,40 @@
package com.mojang.realmsclient;
import java.util.Arrays;
public class KeyCombo {
private final char[] chars;
private int matchIndex;
private final Runnable onCompletion;
public KeyCombo(final char[] arr, final Runnable runnable) {
this.onCompletion = runnable;
if (arr.length < 1) {
throw new IllegalArgumentException("Must have at least one char");
}
this.chars = arr;
}
public boolean keyPressed(final char character) {
if (character == this.chars[this.matchIndex++]) {
if (this.matchIndex == this.chars.length) {
this.reset();
this.onCompletion.run();
return true;
}
}
else {
this.reset();
}
return false;
}
public void reset() {
this.matchIndex = 0;
}
@Override
public String toString() {
return "KeyCombo{chars=" + Arrays.toString(this.chars) + ", matchIndex=" + this.matchIndex + '}';
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
package com.mojang.realmsclient;
import java.util.Locale;
public enum Unit {
B,
KB,
MB,
GB;
public static Unit getLargest(final long long1) {
if (long1 < 1024L) {
return Unit.B;
}
try {
final int integer3 = (int)(Math.log((double)long1) / Math.log(1024.0));
final String string4 = String.valueOf("KMGTPE".charAt(integer3 - 1));
return valueOf(string4 + "B");
}
catch (Exception exception3) {
return Unit.GB;
}
}
public static double convertTo(final long long1, final Unit dhw) {
if (dhw == Unit.B) {
return (double)long1;
}
return long1 / Math.pow(1024.0, dhw.ordinal());
}
public static String humanReadable(final long long1) {
final int integer3 = 1024;
if (long1 < 1024L) {
return long1 + " B";
}
final int integer4 = (int)(Math.log((double)long1) / Math.log(1024.0));
final String string5 = "KMGTPE".charAt(integer4 - 1) + "";
return String.format(Locale.ROOT, "%.1f %sB", long1 / Math.pow(1024.0, integer4), string5);
}
public static String humanReadable(final long long1, final Unit dhw) {
return String.format("%." + ((dhw == Unit.GB) ? "1" : "0") + "f %s", convertTo(long1, dhw), dhw.name());
}
}

View File

@ -0,0 +1,456 @@
package com.mojang.realmsclient.client;
import org.apache.commons.io.output.CountingOutputStream;
import org.apache.commons.io.FileUtils;
import com.google.common.io.Files;
import com.google.common.hash.Hashing;
import java.awt.event.ActionEvent;
import org.apache.logging.log4j.LogManager;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import java.nio.file.Path;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import java.util.regex.Matcher;
import java.util.Iterator;
import net.minecraft.world.level.storage.LevelResource;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import net.minecraft.client.Minecraft;
import java.util.Locale;
import net.minecraft.world.level.storage.LevelSummary;
import org.apache.commons.lang3.StringUtils;
import net.minecraft.SharedConstants;
import java.util.regex.Pattern;
import org.apache.http.HttpResponse;
import com.mojang.realmsclient.exception.RealmsDefaultUncaughtExceptionHandler;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import net.minecraft.world.level.storage.LevelStorageSource;
import com.mojang.realmsclient.gui.screens.RealmsDownloadLatestWorldScreen;
import com.mojang.realmsclient.dto.WorldDownload;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.IOException;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import java.io.File;
import org.apache.logging.log4j.Logger;
public class FileDownload {
private static final Logger LOGGER;
private volatile boolean cancelled;
private volatile boolean finished;
private volatile boolean error;
private volatile boolean extracting;
private volatile File tempFile;
private volatile File resourcePackPath;
private volatile HttpGet request;
private Thread currentThread;
private final RequestConfig requestConfig;
private static final String[] INVALID_FILE_NAMES;
public FileDownload() {
this.requestConfig = RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();
}
public long contentLength(final String string) {
CloseableHttpClient closeableHttpClient3 = null;
HttpGet httpGet4 = null;
try {
httpGet4 = new HttpGet(string);
closeableHttpClient3 = HttpClientBuilder.create().setDefaultRequestConfig(this.requestConfig).build();
final CloseableHttpResponse closeableHttpResponse5 = closeableHttpClient3.execute((HttpUriRequest)httpGet4);
return Long.parseLong(closeableHttpResponse5.getFirstHeader("Content-Length").getValue());
}
catch (Throwable throwable5) {
FileDownload.LOGGER.error("Unable to get content length for download");
return 0L;
}
finally {
if (httpGet4 != null) {
httpGet4.releaseConnection();
}
if (closeableHttpClient3 != null) {
try {
closeableHttpClient3.close();
}
catch (IOException iOException10) {
FileDownload.LOGGER.error("Could not close http client", (Throwable)iOException10);
}
}
}
}
public void download(final WorldDownload djc, final String string, final RealmsDownloadLatestWorldScreen.DownloadStatus a, final LevelStorageSource dae) {
if (this.currentThread != null) {
return;
}
CloseableHttpClient closeableHttpClient6;
HttpResponse httpResponse7;
OutputStream outputStream8;
ProgressListener b9;
DownloadCountingOutputStream a2;
HttpResponse httpResponse8;
OutputStream outputStream9;
ResourcePackProgressListener c9;
DownloadCountingOutputStream a3;
HttpResponse httpResponse9;
OutputStream outputStream10;
ResourcePackProgressListener c10;
DownloadCountingOutputStream a4;
(this.currentThread = new Thread(() -> {
closeableHttpClient6 = null;
try {
this.tempFile = File.createTempFile("backup", ".tar.gz");
this.request = new HttpGet(djc.downloadLink);
closeableHttpClient6 = HttpClientBuilder.create().setDefaultRequestConfig(this.requestConfig).build();
httpResponse7 = (HttpResponse)closeableHttpClient6.execute((HttpUriRequest)this.request);
a.totalBytes = Long.parseLong(httpResponse7.getFirstHeader("Content-Length").getValue());
if (httpResponse7.getStatusLine().getStatusCode() != 200) {
this.error = true;
this.request.abort();
}
else {
outputStream8 = new FileOutputStream(this.tempFile);
b9 = new ProgressListener(string.trim(), this.tempFile, dae, a);
a2 = new DownloadCountingOutputStream(outputStream8);
a2.setListener(b9);
IOUtils.copy(httpResponse7.getEntity().getContent(), (OutputStream)a2);
}
}
catch (Exception exception7) {
FileDownload.LOGGER.error("Caught exception while downloading: " + exception7.getMessage());
this.error = true;
this.request.releaseConnection();
if (this.tempFile != null) {
this.tempFile.delete();
}
if (!this.error) {
if (!djc.resourcePackUrl.isEmpty() && !djc.resourcePackHash.isEmpty()) {
try {
this.tempFile = File.createTempFile("resources", ".tar.gz");
this.request = new HttpGet(djc.resourcePackUrl);
httpResponse8 = (HttpResponse)closeableHttpClient6.execute((HttpUriRequest)this.request);
a.totalBytes = Long.parseLong(httpResponse8.getFirstHeader("Content-Length").getValue());
if (httpResponse8.getStatusLine().getStatusCode() != 200) {
this.error = true;
this.request.abort();
return;
}
else {
outputStream9 = new FileOutputStream(this.tempFile);
c9 = new ResourcePackProgressListener(this.tempFile, a, djc);
a3 = new DownloadCountingOutputStream(outputStream9);
a3.setListener(c9);
IOUtils.copy(httpResponse8.getEntity().getContent(), (OutputStream)a3);
}
}
catch (Exception exception8) {
FileDownload.LOGGER.error("Caught exception while downloading: " + exception8.getMessage());
this.error = true;
}
finally {
this.request.releaseConnection();
if (this.tempFile != null) {
this.tempFile.delete();
}
}
}
else {
this.finished = true;
}
}
if (closeableHttpClient6 != null) {
try {
closeableHttpClient6.close();
}
catch (IOException iOException7) {
FileDownload.LOGGER.error("Failed to close Realms download client");
}
}
}
finally {
this.request.releaseConnection();
if (this.tempFile != null) {
this.tempFile.delete();
}
if (!this.error) {
if (!djc.resourcePackUrl.isEmpty() && !djc.resourcePackHash.isEmpty()) {
try {
this.tempFile = File.createTempFile("resources", ".tar.gz");
this.request = new HttpGet(djc.resourcePackUrl);
httpResponse9 = (HttpResponse)closeableHttpClient6.execute((HttpUriRequest)this.request);
a.totalBytes = Long.parseLong(httpResponse9.getFirstHeader("Content-Length").getValue());
if (httpResponse9.getStatusLine().getStatusCode() != 200) {
this.error = true;
this.request.abort();
return;
}
else {
outputStream10 = new FileOutputStream(this.tempFile);
c10 = new ResourcePackProgressListener(this.tempFile, a, djc);
a4 = new DownloadCountingOutputStream(outputStream10);
a4.setListener(c10);
IOUtils.copy(httpResponse9.getEntity().getContent(), (OutputStream)a4);
}
}
catch (Exception exception9) {
FileDownload.LOGGER.error("Caught exception while downloading: " + exception9.getMessage());
this.error = true;
this.request.releaseConnection();
if (this.tempFile != null) {
this.tempFile.delete();
}
}
finally {
this.request.releaseConnection();
if (this.tempFile != null) {
this.tempFile.delete();
}
}
}
else {
this.finished = true;
}
}
if (closeableHttpClient6 != null) {
try {
closeableHttpClient6.close();
}
catch (IOException iOException8) {
FileDownload.LOGGER.error("Failed to close Realms download client");
}
}
}
return;
})).setUncaughtExceptionHandler(new RealmsDefaultUncaughtExceptionHandler(FileDownload.LOGGER));
this.currentThread.start();
}
public void cancel() {
if (this.request != null) {
this.request.abort();
}
if (this.tempFile != null) {
this.tempFile.delete();
}
this.cancelled = true;
}
public boolean isFinished() {
return this.finished;
}
public boolean isError() {
return this.error;
}
public boolean isExtracting() {
return this.extracting;
}
public static String findAvailableFolderName(String string) {
string = string.replaceAll("[\\./\"]", "_");
for (final String string2 : FileDownload.INVALID_FILE_NAMES) {
if (string.equalsIgnoreCase(string2)) {
string = "_" + string + "_";
}
}
return string;
}
private void untarGzipArchive(String string, final File file, final LevelStorageSource dae) throws IOException {
final Pattern pattern5 = Pattern.compile(".*-([0-9]+)$");
int integer7 = 1;
for (final char character11 : SharedConstants.ILLEGAL_FILE_CHARACTERS) {
string = string.replace(character11, '_');
}
if (StringUtils.isEmpty((CharSequence)string)) {
string = "Realm";
}
string = findAvailableFolderName(string);
try {
for (final LevelSummary daf9 : dae.getLevelList()) {
if (daf9.getLevelId().toLowerCase(Locale.ROOT).startsWith(string.toLowerCase(Locale.ROOT))) {
final Matcher matcher10 = pattern5.matcher(daf9.getLevelId());
if (matcher10.matches()) {
if (Integer.valueOf(matcher10.group(1)) <= integer7) {
continue;
}
integer7 = Integer.valueOf(matcher10.group(1));
}
else {
++integer7;
}
}
}
}
catch (Exception exception8) {
FileDownload.LOGGER.error("Error getting level list", (Throwable)exception8);
this.error = true;
return;
}
String string2;
if (!dae.isNewLevelIdAcceptable(string) || integer7 > 1) {
string2 = string + ((integer7 == 1) ? "" : ("-" + integer7));
if (!dae.isNewLevelIdAcceptable(string2)) {
for (boolean boolean8 = false; !boolean8; boolean8 = true) {
++integer7;
string2 = string + ((integer7 == 1) ? "" : ("-" + integer7));
if (dae.isNewLevelIdAcceptable(string2)) {}
}
}
}
else {
string2 = string;
}
TarArchiveInputStream tarArchiveInputStream8 = null;
final File file2 = new File(Minecraft.getInstance().gameDirectory.getAbsolutePath(), "saves");
try {
file2.mkdir();
tarArchiveInputStream8 = new TarArchiveInputStream((InputStream)new GzipCompressorInputStream((InputStream)new BufferedInputStream(new FileInputStream(file))));
for (TarArchiveEntry tarArchiveEntry10 = tarArchiveInputStream8.getNextTarEntry(); tarArchiveEntry10 != null; tarArchiveEntry10 = tarArchiveInputStream8.getNextTarEntry()) {
final File file3 = new File(file2, tarArchiveEntry10.getName().replace("world", string2));
if (tarArchiveEntry10.isDirectory()) {
file3.mkdirs();
}
else {
file3.createNewFile();
try (final FileOutputStream fileOutputStream12 = new FileOutputStream(file3)) {
IOUtils.copy((InputStream)tarArchiveInputStream8, (OutputStream)fileOutputStream12);
}
}
}
}
catch (Exception exception9) {
FileDownload.LOGGER.error("Error extracting world", (Throwable)exception9);
this.error = true;
}
finally {
if (tarArchiveInputStream8 != null) {
tarArchiveInputStream8.close();
}
if (file != null) {
file.delete();
}
try (final LevelStorageSource.LevelStorageAccess a22 = dae.createAccess(string2)) {
a22.renameLevel(string2.trim());
final Path path24 = a22.getLevelPath(LevelResource.LEVEL_DATA_FILE);
deletePlayerTag(path24.toFile());
}
catch (IOException iOException22) {
FileDownload.LOGGER.error("Failed to rename unpacked realms level {}", string2, iOException22);
}
this.resourcePackPath = new File(file2, string2 + File.separator + "resources.zip");
}
}
private static void deletePlayerTag(final File file) {
if (file.exists()) {
try {
final CompoundTag le2 = NbtIo.readCompressed(new FileInputStream(file));
final CompoundTag le3 = le2.getCompound("Data");
le3.remove("Player");
NbtIo.writeCompressed(le2, new FileOutputStream(file));
}
catch (Exception exception2) {
exception2.printStackTrace();
}
}
}
static {
LOGGER = LogManager.getLogger();
INVALID_FILE_NAMES = new String[] { "CON", "COM", "PRN", "AUX", "CLOCK$", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };
}
class ProgressListener implements ActionListener {
private final String worldName;
private final File tempFile;
private final LevelStorageSource levelStorageSource;
private final RealmsDownloadLatestWorldScreen.DownloadStatus downloadStatus;
private ProgressListener(final String string, final File file, final LevelStorageSource dae, final RealmsDownloadLatestWorldScreen.DownloadStatus a) {
this.worldName = string;
this.tempFile = file;
this.levelStorageSource = dae;
this.downloadStatus = a;
}
@Override
public void actionPerformed(final ActionEvent actionEvent) {
this.downloadStatus.bytesWritten = ((DownloadCountingOutputStream)actionEvent.getSource()).getByteCount();
if (this.downloadStatus.bytesWritten >= this.downloadStatus.totalBytes && !FileDownload.this.cancelled && !FileDownload.this.error) {
try {
FileDownload.this.extracting = true;
FileDownload.this.untarGzipArchive(this.worldName, this.tempFile, this.levelStorageSource);
}
catch (IOException iOException3) {
FileDownload.LOGGER.error("Error extracting archive", (Throwable)iOException3);
FileDownload.this.error = true;
}
}
}
}
class ResourcePackProgressListener implements ActionListener {
private final File tempFile;
private final RealmsDownloadLatestWorldScreen.DownloadStatus downloadStatus;
private final WorldDownload worldDownload;
private ResourcePackProgressListener(final File file, final RealmsDownloadLatestWorldScreen.DownloadStatus a, final WorldDownload djc) {
this.tempFile = file;
this.downloadStatus = a;
this.worldDownload = djc;
}
@Override
public void actionPerformed(final ActionEvent actionEvent) {
this.downloadStatus.bytesWritten = ((DownloadCountingOutputStream)actionEvent.getSource()).getByteCount();
if (this.downloadStatus.bytesWritten >= this.downloadStatus.totalBytes && !FileDownload.this.cancelled) {
try {
final String string3 = Hashing.sha1().hashBytes(Files.toByteArray(this.tempFile)).toString();
if (string3.equals(this.worldDownload.resourcePackHash)) {
FileUtils.copyFile(this.tempFile, FileDownload.this.resourcePackPath);
FileDownload.this.finished = true;
}
else {
FileDownload.LOGGER.error("Resourcepack had wrong hash (expected " + this.worldDownload.resourcePackHash + ", found " + string3 + "). Deleting it.");
FileUtils.deleteQuietly(this.tempFile);
FileDownload.this.error = true;
}
}
catch (IOException iOException3) {
FileDownload.LOGGER.error("Error copying resourcepack file", iOException3.getMessage());
FileDownload.this.error = true;
}
}
}
}
class DownloadCountingOutputStream extends CountingOutputStream {
private ActionListener listener;
public DownloadCountingOutputStream(final OutputStream outputStream) {
super(outputStream);
}
public void setListener(final ActionListener actionListener) {
this.listener = actionListener;
}
protected void afterWrite(final int integer) throws IOException {
super.afterWrite(integer);
if (this.listener != null) {
this.listener.actionPerformed(new ActionEvent(this, 0, null));
}
}
}
}

View File

@ -0,0 +1,210 @@
package com.mojang.realmsclient.client;
import org.apache.http.util.Args;
import java.io.OutputStream;
import org.apache.http.entity.InputStreamEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.http.Header;
import java.time.Duration;
import java.util.function.Function;
import com.google.gson.JsonElement;
import java.util.Optional;
import com.google.gson.JsonParser;
import org.apache.http.util.EntityUtils;
import java.io.FileNotFoundException;
import org.apache.http.HttpEntity;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.client.methods.HttpPost;
import java.util.function.Consumer;
import java.util.concurrent.TimeUnit;
import net.minecraft.client.User;
import org.apache.http.client.config.RequestConfig;
import com.mojang.realmsclient.gui.screens.UploadResult;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import com.mojang.realmsclient.dto.UploadInfo;
import java.io.File;
import org.apache.logging.log4j.Logger;
public class FileUpload {
private static final Logger LOGGER;
private final File file;
private final long worldId;
private final int slotId;
private final UploadInfo uploadInfo;
private final String sessionId;
private final String username;
private final String clientVersion;
private final UploadStatus uploadStatus;
private final AtomicBoolean cancelled;
private CompletableFuture<UploadResult> uploadTask;
private final RequestConfig requestConfig;
public FileUpload(final File file, final long long2, final int integer, final UploadInfo dja, final User dml, final String string, final UploadStatus die) {
this.cancelled = new AtomicBoolean(false);
this.requestConfig = RequestConfig.custom().setSocketTimeout((int)TimeUnit.MINUTES.toMillis(10L)).setConnectTimeout((int)TimeUnit.SECONDS.toMillis(15L)).build();
this.file = file;
this.worldId = long2;
this.slotId = integer;
this.uploadInfo = dja;
this.sessionId = dml.getSessionId();
this.username = dml.getName();
this.clientVersion = string;
this.uploadStatus = die;
}
public void upload(final Consumer<UploadResult> consumer) {
if (this.uploadTask != null) {
return;
}
(this.uploadTask = CompletableFuture.<UploadResult>supplyAsync(() -> this.requestUpload(0))).thenAccept(consumer);
}
public void cancel() {
this.cancelled.set(true);
if (this.uploadTask != null) {
this.uploadTask.cancel(false);
this.uploadTask = null;
}
}
private UploadResult requestUpload(final int integer) {
final UploadResult.Builder a3 = new UploadResult.Builder();
if (this.cancelled.get()) {
return a3.build();
}
this.uploadStatus.totalBytes = this.file.length();
final HttpPost httpPost4 = new HttpPost("http://" + this.uploadInfo.getUploadEndpoint() + ":" + this.uploadInfo.getPort() + "/upload" + "/" + this.worldId + "/" + this.slotId);
final CloseableHttpClient closeableHttpClient5 = HttpClientBuilder.create().setDefaultRequestConfig(this.requestConfig).build();
try {
this.setupRequest(httpPost4);
final HttpResponse httpResponse6 = (HttpResponse)closeableHttpClient5.execute((HttpUriRequest)httpPost4);
final long long7 = this.getRetryDelaySeconds(httpResponse6);
if (this.shouldRetry(long7, integer)) {
return this.retryUploadAfter(long7, integer);
}
this.handleResponse(httpResponse6, a3);
}
catch (Exception exception6) {
if (!this.cancelled.get()) {
FileUpload.LOGGER.error("Caught exception while uploading: ", (Throwable)exception6);
}
}
finally {
this.cleanup(httpPost4, closeableHttpClient5);
}
return a3.build();
}
private void cleanup(final HttpPost httpPost, final CloseableHttpClient closeableHttpClient) {
httpPost.releaseConnection();
if (closeableHttpClient != null) {
try {
closeableHttpClient.close();
}
catch (IOException iOException4) {
FileUpload.LOGGER.error("Failed to close Realms upload client");
}
}
}
private void setupRequest(final HttpPost httpPost) throws FileNotFoundException {
httpPost.setHeader("Cookie", "sid=" + this.sessionId + ";token=" + this.uploadInfo.getToken() + ";user=" + this.username + ";version=" + this.clientVersion);
final CustomInputStreamEntity a3 = new CustomInputStreamEntity(new FileInputStream(this.file), this.file.length(), this.uploadStatus);
a3.setContentType("application/octet-stream");
httpPost.setEntity((HttpEntity)a3);
}
private void handleResponse(final HttpResponse httpResponse, final UploadResult.Builder a) throws IOException {
final int integer4 = httpResponse.getStatusLine().getStatusCode();
if (integer4 == 401) {
FileUpload.LOGGER.debug("Realms server returned 401: " + httpResponse.getFirstHeader("WWW-Authenticate"));
}
a.withStatusCode(integer4);
if (httpResponse.getEntity() != null) {
final String string5 = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
if (string5 != null) {
try {
final JsonParser jsonParser6 = new JsonParser();
final JsonElement jsonElement7 = jsonParser6.parse(string5).getAsJsonObject().get("errorMsg");
final Optional<String> optional8 = Optional.<JsonElement>ofNullable(jsonElement7).<String>map(JsonElement::getAsString);
a.withErrorMessage(optional8.orElse(null));
}
catch (Exception ex) {}
}
}
}
private boolean shouldRetry(final long long1, final int integer) {
return long1 > 0L && integer + 1 < 5;
}
private UploadResult retryUploadAfter(final long long1, final int integer) throws InterruptedException {
Thread.sleep(Duration.ofSeconds(long1).toMillis());
return this.requestUpload(integer + 1);
}
private long getRetryDelaySeconds(final HttpResponse httpResponse) {
return Optional.<Header>ofNullable(httpResponse.getFirstHeader("Retry-After")).map(Header::getValue).<Long>map(Long::valueOf).orElse(0L);
}
public boolean isFinished() {
return this.uploadTask.isDone() || this.uploadTask.isCancelled();
}
static {
LOGGER = LogManager.getLogger();
}
static class CustomInputStreamEntity extends InputStreamEntity {
private final long length;
private final InputStream content;
private final UploadStatus uploadStatus;
public CustomInputStreamEntity(final InputStream inputStream, final long long2, final UploadStatus die) {
super(inputStream);
this.content = inputStream;
this.length = long2;
this.uploadStatus = die;
}
public void writeTo(final OutputStream outputStream) throws IOException {
Args.notNull(outputStream, "Output stream");
final InputStream inputStream3 = this.content;
try {
final byte[] arr4 = new byte[4096];
if (this.length < 0L) {
int integer5;
while ((integer5 = inputStream3.read(arr4)) != -1) {
outputStream.write(arr4, 0, integer5);
final UploadStatus uploadStatus = this.uploadStatus;
uploadStatus.bytesWritten += (Long)integer5;
}
}
else {
long long6 = this.length;
while (long6 > 0L) {
final int integer5 = inputStream3.read(arr4, 0, (int)Math.min(4096L, long6));
if (integer5 == -1) {
break;
}
outputStream.write(arr4, 0, integer5);
final UploadStatus uploadStatus2 = this.uploadStatus;
uploadStatus2.bytesWritten += (Long)integer5;
long6 -= integer5;
outputStream.flush();
}
}
}
finally {
inputStream3.close();
}
}
}
}

View File

@ -0,0 +1,82 @@
package com.mojang.realmsclient.client;
import net.minecraft.Util;
import java.net.SocketAddress;
import java.net.Socket;
import java.net.InetSocketAddress;
import java.util.Comparator;
import com.google.common.collect.Lists;
import com.mojang.realmsclient.dto.RegionPingResult;
import java.util.List;
public class Ping {
public static List<RegionPingResult> ping(final Region... arr) {
for (final Region a5 : arr) {
ping(a5.endpoint);
}
final List<RegionPingResult> list2 = Lists.newArrayList();
for (final Region a6 : arr) {
list2.add(new RegionPingResult(a6.name, ping(a6.endpoint)));
}
list2.sort(Comparator.comparingInt(RegionPingResult::ping));
return list2;
}
private static int ping(final String string) {
final int integer2 = 700;
long long3 = 0L;
Socket socket5 = null;
for (int integer3 = 0; integer3 < 5; ++integer3) {
try {
final SocketAddress socketAddress7 = new InetSocketAddress(string, 80);
socket5 = new Socket();
final long long4 = now();
socket5.connect(socketAddress7, 700);
long3 += now() - long4;
}
catch (Exception exception7) {
long3 += 700L;
}
finally {
close(socket5);
}
}
return (int)(long3 / 5.0);
}
private static void close(final Socket socket) {
try {
if (socket != null) {
socket.close();
}
}
catch (Throwable t) {}
}
private static long now() {
return Util.getMillis();
}
public static List<RegionPingResult> pingAllRegions() {
return ping(Region.values());
}
enum Region {
US_EAST_1("us-east-1", "ec2.us-east-1.amazonaws.com"),
US_WEST_2("us-west-2", "ec2.us-west-2.amazonaws.com"),
US_WEST_1("us-west-1", "ec2.us-west-1.amazonaws.com"),
EU_WEST_1("eu-west-1", "ec2.eu-west-1.amazonaws.com"),
AP_SOUTHEAST_1("ap-southeast-1", "ec2.ap-southeast-1.amazonaws.com"),
AP_SOUTHEAST_2("ap-southeast-2", "ec2.ap-southeast-2.amazonaws.com"),
AP_NORTHEAST_1("ap-northeast-1", "ec2.ap-northeast-1.amazonaws.com"),
SA_EAST_1("sa-east-1", "ec2.sa-east-1.amazonaws.com");
private final String name;
private final String endpoint;
private Region(final String string3, final String string4) {
this.name = string3;
this.endpoint = string4;
}
}
}

View File

@ -0,0 +1,384 @@
package com.mojang.realmsclient.client;
import org.apache.logging.log4j.LogManager;
import com.mojang.realmsclient.exception.RealmsHttpException;
import com.mojang.realmsclient.exception.RetryCallException;
import net.minecraft.SharedConstants;
import java.net.URISyntaxException;
import java.net.URI;
import javax.annotation.Nullable;
import com.mojang.realmsclient.dto.PingResult;
import com.mojang.realmsclient.dto.RealmsNews;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mojang.realmsclient.dto.UploadInfo;
import com.mojang.realmsclient.dto.WorldDownload;
import com.mojang.realmsclient.dto.PendingInvitesList;
import com.mojang.realmsclient.dto.Subscription;
import com.mojang.realmsclient.dto.RealmsWorldResetDto;
import com.mojang.realmsclient.dto.Ops;
import com.mojang.realmsclient.dto.WorldTemplatePaginatedList;
import com.mojang.realmsclient.dto.RealmsWorldOptions;
import com.mojang.realmsclient.dto.BackupList;
import com.mojang.realmsclient.dto.PlayerInfo;
import com.mojang.realmsclient.dto.ReflectionBasedSerialization;
import com.mojang.realmsclient.dto.RealmsDescriptionDto;
import com.mojang.realmsclient.dto.RealmsServerAddress;
import com.mojang.realmsclient.dto.RealmsServerPlayerLists;
import com.mojang.realmsclient.dto.RealmsServer;
import com.mojang.realmsclient.exception.RealmsServiceException;
import com.mojang.realmsclient.dto.RealmsServerList;
import java.net.Proxy;
import net.minecraft.client.Minecraft;
import com.mojang.realmsclient.dto.GuardedSerializer;
import org.apache.logging.log4j.Logger;
public class RealmsClient {
public static Environment currentEnvironment;
private static boolean initialized;
private static final Logger LOGGER;
private final String sessionId;
private final String username;
private static final GuardedSerializer GSON;
public static RealmsClient create() {
final Minecraft dlx1 = Minecraft.getInstance();
final String string2 = dlx1.getUser().getName();
final String string3 = dlx1.getUser().getSessionId();
if (!RealmsClient.initialized) {
RealmsClient.initialized = true;
String string4 = System.getenv("realms.environment");
if (string4 == null) {
string4 = System.getProperty("realms.environment");
}
if (string4 != null) {
if ("LOCAL".equals(string4)) {
switchToLocal();
}
else if ("STAGE".equals(string4)) {
switchToStage();
}
}
}
return new RealmsClient(string3, string2, dlx1.getProxy());
}
public static void switchToStage() {
RealmsClient.currentEnvironment = Environment.STAGE;
}
public static void switchToProd() {
RealmsClient.currentEnvironment = Environment.PRODUCTION;
}
public static void switchToLocal() {
RealmsClient.currentEnvironment = Environment.LOCAL;
}
public RealmsClient(final String string1, final String string2, final Proxy proxy) {
this.sessionId = string1;
this.username = string2;
RealmsClientConfig.setProxy(proxy);
}
public RealmsServerList listWorlds() throws RealmsServiceException {
final String string2 = this.url("worlds");
final String string3 = this.execute(Request.get(string2));
return RealmsServerList.parse(string3);
}
public RealmsServer getOwnWorld(final long long1) throws RealmsServiceException {
final String string4 = this.url("worlds" + "/$ID".replace("$ID", String.valueOf(long1)));
final String string5 = this.execute(Request.get(string4));
return RealmsServer.parse(string5);
}
public RealmsServerPlayerLists getLiveStats() throws RealmsServiceException {
final String string2 = this.url("activities/liveplayerlist");
final String string3 = this.execute(Request.get(string2));
return RealmsServerPlayerLists.parse(string3);
}
public RealmsServerAddress join(final long long1) throws RealmsServiceException {
final String string4 = this.url("worlds" + "/v1/$ID/join/pc".replace("$ID", "" + long1));
final String string5 = this.execute(Request.get(string4, 5000, 30000));
return RealmsServerAddress.parse(string5);
}
public void initializeWorld(final long long1, final String string2, final String string3) throws RealmsServiceException {
final RealmsDescriptionDto din6 = new RealmsDescriptionDto(string2, string3);
final String string4 = this.url("worlds" + "/$WORLD_ID/initialize".replace("$WORLD_ID", String.valueOf(long1)));
final String string5 = RealmsClient.GSON.toJson(din6);
this.execute(Request.post(string4, string5, 5000, 10000));
}
public Boolean mcoEnabled() throws RealmsServiceException {
final String string2 = this.url("mco/available");
final String string3 = this.execute(Request.get(string2));
return Boolean.valueOf(string3);
}
public Boolean stageAvailable() throws RealmsServiceException {
final String string2 = this.url("mco/stageAvailable");
final String string3 = this.execute(Request.get(string2));
return Boolean.valueOf(string3);
}
public CompatibleVersionResponse clientCompatible() throws RealmsServiceException {
final String string2 = this.url("mco/client/compatible");
final String string3 = this.execute(Request.get(string2));
CompatibleVersionResponse a4;
try {
a4 = CompatibleVersionResponse.valueOf(string3);
}
catch (IllegalArgumentException illegalArgumentException5) {
throw new RealmsServiceException(500, "Could not check compatible version, got response: " + string3, -1, "");
}
return a4;
}
public void uninvite(final long long1, final String string) throws RealmsServiceException {
final String string2 = this.url("invites" + "/$WORLD_ID/invite/$UUID".replace("$WORLD_ID", String.valueOf(long1)).replace("$UUID", string));
this.execute(Request.delete(string2));
}
public void uninviteMyselfFrom(final long long1) throws RealmsServiceException {
final String string4 = this.url("invites" + "/$WORLD_ID".replace("$WORLD_ID", String.valueOf(long1)));
this.execute(Request.delete(string4));
}
public RealmsServer invite(final long long1, final String string) throws RealmsServiceException {
final PlayerInfo dim5 = new PlayerInfo();
dim5.setName(string);
final String string2 = this.url("invites" + "/$WORLD_ID".replace("$WORLD_ID", String.valueOf(long1)));
final String string3 = this.execute(Request.post(string2, RealmsClient.GSON.toJson(dim5)));
return RealmsServer.parse(string3);
}
public BackupList backupsFor(final long long1) throws RealmsServiceException {
final String string4 = this.url("worlds" + "/$WORLD_ID/backups".replace("$WORLD_ID", String.valueOf(long1)));
final String string5 = this.execute(Request.get(string4));
return BackupList.parse(string5);
}
public void update(final long long1, final String string2, final String string3) throws RealmsServiceException {
final RealmsDescriptionDto din6 = new RealmsDescriptionDto(string2, string3);
final String string4 = this.url("worlds" + "/$WORLD_ID".replace("$WORLD_ID", String.valueOf(long1)));
this.execute(Request.post(string4, RealmsClient.GSON.toJson(din6)));
}
public void updateSlot(final long long1, final int integer, final RealmsWorldOptions div) throws RealmsServiceException {
final String string6 = this.url("worlds" + "/$WORLD_ID/slot/$SLOT_ID".replace("$WORLD_ID", String.valueOf(long1)).replace("$SLOT_ID", String.valueOf(integer)));
final String string7 = div.toJson();
this.execute(Request.post(string6, string7));
}
public boolean switchSlot(final long long1, final int integer) throws RealmsServiceException {
final String string5 = this.url("worlds" + "/$WORLD_ID/slot/$SLOT_ID".replace("$WORLD_ID", String.valueOf(long1)).replace("$SLOT_ID", String.valueOf(integer)));
final String string6 = this.execute(Request.put(string5, ""));
return Boolean.valueOf(string6);
}
public void restoreWorld(final long long1, final String string) throws RealmsServiceException {
final String string2 = this.url("worlds" + "/$WORLD_ID/backups".replace("$WORLD_ID", String.valueOf(long1)), "backupId=" + string);
this.execute(Request.put(string2, "", 40000, 600000));
}
public WorldTemplatePaginatedList fetchWorldTemplates(final int integer1, final int integer2, final RealmsServer.WorldType c) throws RealmsServiceException {
final String string5 = this.url("worlds" + "/templates/$WORLD_TYPE".replace("$WORLD_TYPE", c.toString()), String.format("page=%d&pageSize=%d", integer1, integer2));
final String string6 = this.execute(Request.get(string5));
return WorldTemplatePaginatedList.parse(string6);
}
public Boolean putIntoMinigameMode(final long long1, final String string) throws RealmsServiceException {
final String string2 = "/minigames/$MINIGAME_ID/$WORLD_ID".replace("$MINIGAME_ID", string).replace("$WORLD_ID", String.valueOf(long1));
final String string3 = this.url("worlds" + string2);
return Boolean.valueOf(this.execute(Request.put(string3, "")));
}
public Ops op(final long long1, final String string) throws RealmsServiceException {
final String string2 = "/$WORLD_ID/$PROFILE_UUID".replace("$WORLD_ID", String.valueOf(long1)).replace("$PROFILE_UUID", string);
final String string3 = this.url("ops" + string2);
return Ops.parse(this.execute(Request.post(string3, "")));
}
public Ops deop(final long long1, final String string) throws RealmsServiceException {
final String string2 = "/$WORLD_ID/$PROFILE_UUID".replace("$WORLD_ID", String.valueOf(long1)).replace("$PROFILE_UUID", string);
final String string3 = this.url("ops" + string2);
return Ops.parse(this.execute(Request.delete(string3)));
}
public Boolean open(final long long1) throws RealmsServiceException {
final String string4 = this.url("worlds" + "/$WORLD_ID/open".replace("$WORLD_ID", String.valueOf(long1)));
final String string5 = this.execute(Request.put(string4, ""));
return Boolean.valueOf(string5);
}
public Boolean close(final long long1) throws RealmsServiceException {
final String string4 = this.url("worlds" + "/$WORLD_ID/close".replace("$WORLD_ID", String.valueOf(long1)));
final String string5 = this.execute(Request.put(string4, ""));
return Boolean.valueOf(string5);
}
public Boolean resetWorldWithSeed(final long long1, final String string, final Integer integer, final boolean boolean4) throws RealmsServiceException {
final RealmsWorldResetDto diw7 = new RealmsWorldResetDto(string, -1L, integer, boolean4);
final String string2 = this.url("worlds" + "/$WORLD_ID/reset".replace("$WORLD_ID", String.valueOf(long1)));
final String string3 = this.execute(Request.post(string2, RealmsClient.GSON.toJson(diw7), 30000, 80000));
return Boolean.valueOf(string3);
}
public Boolean resetWorldWithTemplate(final long long1, final String string) throws RealmsServiceException {
final RealmsWorldResetDto diw5 = new RealmsWorldResetDto(null, Long.valueOf(string), -1, false);
final String string2 = this.url("worlds" + "/$WORLD_ID/reset".replace("$WORLD_ID", String.valueOf(long1)));
final String string3 = this.execute(Request.post(string2, RealmsClient.GSON.toJson(diw5), 30000, 80000));
return Boolean.valueOf(string3);
}
public Subscription subscriptionFor(final long long1) throws RealmsServiceException {
final String string4 = this.url("subscriptions" + "/$WORLD_ID".replace("$WORLD_ID", String.valueOf(long1)));
final String string5 = this.execute(Request.get(string4));
return Subscription.parse(string5);
}
public int pendingInvitesCount() throws RealmsServiceException {
final String string2 = this.url("invites/count/pending");
final String string3 = this.execute(Request.get(string2));
return Integer.parseInt(string3);
}
public PendingInvitesList pendingInvites() throws RealmsServiceException {
final String string2 = this.url("invites/pending");
final String string3 = this.execute(Request.get(string2));
return PendingInvitesList.parse(string3);
}
public void acceptInvitation(final String string) throws RealmsServiceException {
final String string2 = this.url("invites" + "/accept/$INVITATION_ID".replace("$INVITATION_ID", string));
this.execute(Request.put(string2, ""));
}
public WorldDownload download(final long long1, final int integer) throws RealmsServiceException {
final String string5 = this.url("worlds" + "/$WORLD_ID/slot/$SLOT_ID/download".replace("$WORLD_ID", String.valueOf(long1)).replace("$SLOT_ID", String.valueOf(integer)));
final String string6 = this.execute(Request.get(string5));
return WorldDownload.parse(string6);
}
public UploadInfo upload(final long long1, final String string) throws RealmsServiceException {
final String string2 = this.url("worlds" + "/$WORLD_ID/backups/upload".replace("$WORLD_ID", String.valueOf(long1)));
final UploadInfo dja6 = new UploadInfo();
if (string != null) {
dja6.setToken(string);
}
final GsonBuilder gsonBuilder7 = new GsonBuilder();
gsonBuilder7.excludeFieldsWithoutExposeAnnotation();
final Gson gson8 = gsonBuilder7.create();
final String string3 = gson8.toJson(dja6);
return UploadInfo.parse(this.execute(Request.put(string2, string3)));
}
public void rejectInvitation(final String string) throws RealmsServiceException {
final String string2 = this.url("invites" + "/reject/$INVITATION_ID".replace("$INVITATION_ID", string));
this.execute(Request.put(string2, ""));
}
public void agreeToTos() throws RealmsServiceException {
final String string2 = this.url("mco/tos/agreed");
this.execute(Request.post(string2, ""));
}
public RealmsNews getNews() throws RealmsServiceException {
final String string2 = this.url("mco/v1/news");
final String string3 = this.execute(Request.get(string2, 5000, 10000));
return RealmsNews.parse(string3);
}
public void sendPingResults(final PingResult dil) throws RealmsServiceException {
final String string3 = this.url("regions/ping/stat");
this.execute(Request.post(string3, RealmsClient.GSON.toJson(dil)));
}
public Boolean trialAvailable() throws RealmsServiceException {
final String string2 = this.url("trial");
final String string3 = this.execute(Request.get(string2));
return Boolean.valueOf(string3);
}
public void deleteWorld(final long long1) throws RealmsServiceException {
final String string4 = this.url("worlds" + "/$WORLD_ID".replace("$WORLD_ID", String.valueOf(long1)));
this.execute(Request.delete(string4));
}
@Nullable
private String url(final String string) {
return this.url(string, null);
}
@Nullable
private String url(final String string1, @Nullable final String string2) {
try {
return new URI(RealmsClient.currentEnvironment.protocol, RealmsClient.currentEnvironment.baseUrl, "/" + string1, string2, null).toASCIIString();
}
catch (URISyntaxException uRISyntaxException4) {
uRISyntaxException4.printStackTrace();
return null;
}
}
private String execute(final Request<?> did) throws RealmsServiceException {
did.cookie("sid", this.sessionId);
did.cookie("user", this.username);
did.cookie("version", SharedConstants.getCurrentVersion().getName());
try {
final int integer3 = did.responseCode();
if (integer3 == 503) {
final int integer4 = did.getRetryAfterHeader();
throw new RetryCallException(integer4);
}
final String string4 = did.text();
if (integer3 >= 200 && integer3 < 300) {
return string4;
}
if (integer3 == 401) {
final String string5 = did.getHeader("WWW-Authenticate");
RealmsClient.LOGGER.info("Could not authorize you against Realms server: " + string5);
throw new RealmsServiceException(integer3, string5, -1, string5);
}
if (string4 == null || string4.length() == 0) {
RealmsClient.LOGGER.error("Realms error code: " + integer3 + " message: " + string4);
throw new RealmsServiceException(integer3, string4, integer3, "");
}
final RealmsError dic5 = RealmsError.create(string4);
RealmsClient.LOGGER.error("Realms http code: " + integer3 + " - error code: " + dic5.getErrorCode() + " - message: " + dic5.getErrorMessage() + " - raw body: " + string4);
throw new RealmsServiceException(integer3, string4, dic5);
}
catch (RealmsHttpException djg3) {
throw new RealmsServiceException(500, "Could not connect to Realms: " + djg3.getMessage(), -1, "");
}
}
static {
RealmsClient.currentEnvironment = Environment.PRODUCTION;
LOGGER = LogManager.getLogger();
GSON = new GuardedSerializer();
}
public enum Environment {
PRODUCTION("pc.realms.minecraft.net", "https"),
STAGE("pc-stage.realms.minecraft.net", "https"),
LOCAL("localhost:8080", "http");
public String baseUrl;
public String protocol;
private Environment(final String string3, final String string4) {
this.baseUrl = string3;
this.protocol = string4;
}
}
public enum CompatibleVersionResponse {
COMPATIBLE,
OUTDATED,
OTHER;
}
}

View File

@ -0,0 +1,17 @@
package com.mojang.realmsclient.client;
import java.net.Proxy;
public class RealmsClientConfig {
private static Proxy proxy;
public static Proxy getProxy() {
return RealmsClientConfig.proxy;
}
public static void setProxy(final Proxy proxy) {
if (RealmsClientConfig.proxy == null) {
RealmsClientConfig.proxy = proxy;
}
}
}

View File

@ -0,0 +1,45 @@
package com.mojang.realmsclient.client;
import org.apache.logging.log4j.LogManager;
import com.google.gson.JsonObject;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonParser;
import org.apache.logging.log4j.Logger;
public class RealmsError {
private static final Logger LOGGER;
private final String errorMessage;
private final int errorCode;
private RealmsError(final String string, final int integer) {
this.errorMessage = string;
this.errorCode = integer;
}
public static RealmsError create(final String string) {
try {
final JsonParser jsonParser2 = new JsonParser();
final JsonObject jsonObject3 = jsonParser2.parse(string).getAsJsonObject();
final String string2 = JsonUtils.getStringOr("errorMsg", jsonObject3, "");
final int integer5 = JsonUtils.getIntOr("errorCode", jsonObject3, -1);
return new RealmsError(string2, integer5);
}
catch (Exception exception2) {
RealmsError.LOGGER.error("Could not parse RealmsError: " + exception2.getMessage());
RealmsError.LOGGER.error("The error was: " + string);
return new RealmsError("Failed to parse response from server", -1);
}
}
public String getErrorMessage() {
return this.errorMessage;
}
public int getErrorCode() {
return this.errorCode;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,280 @@
package com.mojang.realmsclient.client;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.net.Proxy;
import java.io.IOException;
import java.net.MalformedURLException;
import com.mojang.realmsclient.exception.RealmsHttpException;
import java.net.URL;
import java.net.HttpURLConnection;
public abstract class Request<T extends Request<T>> {
protected HttpURLConnection connection;
private boolean connected;
protected String url;
public Request(final String string, final int integer2, final int integer3) {
try {
this.url = string;
final Proxy proxy5 = RealmsClientConfig.getProxy();
if (proxy5 != null) {
this.connection = (HttpURLConnection)new URL(string).openConnection(proxy5);
}
else {
this.connection = (HttpURLConnection)new URL(string).openConnection();
}
this.connection.setConnectTimeout(integer2);
this.connection.setReadTimeout(integer3);
}
catch (MalformedURLException malformedURLException5) {
throw new RealmsHttpException(malformedURLException5.getMessage(), malformedURLException5);
}
catch (IOException iOException5) {
throw new RealmsHttpException(iOException5.getMessage(), iOException5);
}
}
public void cookie(final String string1, final String string2) {
cookie(this.connection, string1, string2);
}
public static void cookie(final HttpURLConnection httpURLConnection, final String string2, final String string3) {
final String string4 = httpURLConnection.getRequestProperty("Cookie");
if (string4 == null) {
httpURLConnection.setRequestProperty("Cookie", string2 + "=" + string3);
}
else {
httpURLConnection.setRequestProperty("Cookie", string4 + ";" + string2 + "=" + string3);
}
}
public int getRetryAfterHeader() {
return getRetryAfterHeader(this.connection);
}
public static int getRetryAfterHeader(final HttpURLConnection httpURLConnection) {
final String string2 = httpURLConnection.getHeaderField("Retry-After");
try {
return Integer.valueOf(string2);
}
catch (Exception exception3) {
return 5;
}
}
public int responseCode() {
try {
this.connect();
return this.connection.getResponseCode();
}
catch (Exception exception2) {
throw new RealmsHttpException(exception2.getMessage(), exception2);
}
}
public String text() {
try {
this.connect();
String string2 = null;
if (this.responseCode() >= 400) {
string2 = this.read(this.connection.getErrorStream());
}
else {
string2 = this.read(this.connection.getInputStream());
}
this.dispose();
return string2;
}
catch (IOException iOException2) {
throw new RealmsHttpException(iOException2.getMessage(), iOException2);
}
}
private String read(final InputStream inputStream) throws IOException {
if (inputStream == null) {
return "";
}
final InputStreamReader inputStreamReader3 = new InputStreamReader(inputStream, "UTF-8");
final StringBuilder stringBuilder4 = new StringBuilder();
for (int integer5 = inputStreamReader3.read(); integer5 != -1; integer5 = inputStreamReader3.read()) {
stringBuilder4.append((char)integer5);
}
return stringBuilder4.toString();
}
private void dispose() {
final byte[] arr2 = new byte[1024];
try {
final InputStream inputStream3 = this.connection.getInputStream();
while (inputStream3.read(arr2) > 0) {}
inputStream3.close();
}
catch (Exception exception3) {
try {
final InputStream inputStream4 = this.connection.getErrorStream();
if (inputStream4 == null) {
return;
}
while (inputStream4.read(arr2) > 0) {}
inputStream4.close();
}
catch (IOException ex) {}
}
finally {
if (this.connection != null) {
this.connection.disconnect();
}
}
}
protected T connect() {
if (this.connected) {
return (T)this;
}
final T did2 = this.doConnect();
this.connected = true;
return did2;
}
protected abstract T doConnect();
public static Request<?> get(final String string) {
return new Get(string, 5000, 60000);
}
public static Request<?> get(final String string, final int integer2, final int integer3) {
return new Get(string, integer2, integer3);
}
public static Request<?> post(final String string1, final String string2) {
return new Post(string1, string2, 5000, 60000);
}
public static Request<?> post(final String string1, final String string2, final int integer3, final int integer4) {
return new Post(string1, string2, integer3, integer4);
}
public static Request<?> delete(final String string) {
return new Delete(string, 5000, 60000);
}
public static Request<?> put(final String string1, final String string2) {
return new Put(string1, string2, 5000, 60000);
}
public static Request<?> put(final String string1, final String string2, final int integer3, final int integer4) {
return new Put(string1, string2, integer3, integer4);
}
public String getHeader(final String string) {
return getHeader(this.connection, string);
}
public static String getHeader(final HttpURLConnection httpURLConnection, final String string) {
try {
return httpURLConnection.getHeaderField(string);
}
catch (Exception exception3) {
return "";
}
}
public static class Delete extends Request<Delete> {
public Delete(final String string, final int integer2, final int integer3) {
super(string, integer2, integer3);
}
public Delete doConnect() {
try {
this.connection.setDoOutput(true);
this.connection.setRequestMethod("DELETE");
this.connection.connect();
return this;
}
catch (Exception exception2) {
throw new RealmsHttpException(exception2.getMessage(), exception2);
}
}
}
public static class Get extends Request<Get> {
public Get(final String string, final int integer2, final int integer3) {
super(string, integer2, integer3);
}
public Get doConnect() {
try {
this.connection.setDoInput(true);
this.connection.setDoOutput(true);
this.connection.setUseCaches(false);
this.connection.setRequestMethod("GET");
return this;
}
catch (Exception exception2) {
throw new RealmsHttpException(exception2.getMessage(), exception2);
}
}
}
public static class Put extends Request<Put> {
private final String content;
public Put(final String string1, final String string2, final int integer3, final int integer4) {
super(string1, integer3, integer4);
this.content = string2;
}
public Put doConnect() {
try {
if (this.content != null) {
this.connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
}
this.connection.setDoOutput(true);
this.connection.setDoInput(true);
this.connection.setRequestMethod("PUT");
final OutputStream outputStream2 = this.connection.getOutputStream();
final OutputStreamWriter outputStreamWriter3 = new OutputStreamWriter(outputStream2, "UTF-8");
outputStreamWriter3.write(this.content);
outputStreamWriter3.close();
outputStream2.flush();
return this;
}
catch (Exception exception2) {
throw new RealmsHttpException(exception2.getMessage(), exception2);
}
}
}
public static class Post extends Request<Post> {
private final String content;
public Post(final String string1, final String string2, final int integer3, final int integer4) {
super(string1, integer3, integer4);
this.content = string2;
}
public Post doConnect() {
try {
if (this.content != null) {
this.connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
}
this.connection.setDoInput(true);
this.connection.setDoOutput(true);
this.connection.setUseCaches(false);
this.connection.setRequestMethod("POST");
final OutputStream outputStream2 = this.connection.getOutputStream();
final OutputStreamWriter outputStreamWriter3 = new OutputStreamWriter(outputStream2, "UTF-8");
outputStreamWriter3.write(this.content);
outputStreamWriter3.close();
outputStream2.flush();
return this;
}
catch (Exception exception2) {
throw new RealmsHttpException(exception2.getMessage(), exception2);
}
}
}
}

View File

@ -0,0 +1,11 @@
package com.mojang.realmsclient.client;
public class UploadStatus {
public volatile Long bytesWritten;
public volatile Long totalBytes;
public UploadStatus() {
this.bytesWritten = 0L;
this.totalBytes = 0L;
}
}

View File

@ -0,0 +1,79 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import java.util.Iterator;
import java.util.Set;
import com.google.gson.JsonObject;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonElement;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Date;
import org.apache.logging.log4j.Logger;
public class Backup extends ValueObject {
private static final Logger LOGGER;
public String backupId;
public Date lastModifiedDate;
public long size;
private boolean uploadedVersion;
public Map<String, String> metadata;
public Map<String, String> changeList;
public Backup() {
this.metadata = Maps.newHashMap();
this.changeList = Maps.newHashMap();
}
public static Backup parse(final JsonElement jsonElement) {
final JsonObject jsonObject2 = jsonElement.getAsJsonObject();
final Backup dif3 = new Backup();
try {
dif3.backupId = JsonUtils.getStringOr("backupId", jsonObject2, "");
dif3.lastModifiedDate = JsonUtils.getDateOr("lastModifiedDate", jsonObject2);
dif3.size = JsonUtils.getLongOr("size", jsonObject2, 0L);
if (jsonObject2.has("metadata")) {
final JsonObject jsonObject3 = jsonObject2.getAsJsonObject("metadata");
final Set<Map.Entry<String, JsonElement>> set5 = jsonObject3.entrySet();
for (final Map.Entry<String, JsonElement> entry7 : set5) {
if (!entry7.getValue().isJsonNull()) {
dif3.metadata.put(format(entry7.getKey()), entry7.getValue().getAsString());
}
}
}
}
catch (Exception exception4) {
Backup.LOGGER.error("Could not parse Backup: " + exception4.getMessage());
}
return dif3;
}
private static String format(final String string) {
final String[] arr2 = string.split("_");
final StringBuilder stringBuilder3 = new StringBuilder();
for (final String string2 : arr2) {
if (string2 != null && string2.length() >= 1) {
if ("of".equals(string2)) {
stringBuilder3.append(string2).append(" ");
}
else {
final char character8 = Character.toUpperCase(string2.charAt(0));
stringBuilder3.append(character8).append(string2.substring(1)).append(" ");
}
}
}
return stringBuilder3.toString();
}
public boolean isUploadedVersion() {
return this.uploadedVersion;
}
public void setUploadedVersion(final boolean boolean1) {
this.uploadedVersion = boolean1;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,37 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import java.util.Iterator;
import com.google.gson.JsonElement;
import com.google.common.collect.Lists;
import com.google.gson.JsonParser;
import java.util.List;
import org.apache.logging.log4j.Logger;
public class BackupList extends ValueObject {
private static final Logger LOGGER;
public List<Backup> backups;
public static BackupList parse(final String string) {
final JsonParser jsonParser2 = new JsonParser();
final BackupList dig3 = new BackupList();
dig3.backups = Lists.newArrayList();
try {
final JsonElement jsonElement4 = jsonParser2.parse(string).getAsJsonObject().get("backups");
if (jsonElement4.isJsonArray()) {
final Iterator<JsonElement> iterator5 = jsonElement4.getAsJsonArray().iterator();
while (iterator5.hasNext()) {
dig3.backups.add(Backup.parse(iterator5.next()));
}
}
}
catch (Exception exception4) {
BackupList.LOGGER.error("Could not parse BackupList: " + exception4.getMessage());
}
return dig3;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,19 @@
package com.mojang.realmsclient.dto;
import com.google.gson.Gson;
public class GuardedSerializer {
private final Gson gson;
public GuardedSerializer() {
this.gson = new Gson();
}
public String toJson(final ReflectionBasedSerialization dix) {
return this.gson.toJson(dix);
}
public <T extends ReflectionBasedSerialization> T fromJson(final String string, final Class<T> class2) {
return this.gson.<T>fromJson(string, class2);
}
}

View File

@ -0,0 +1,33 @@
package com.mojang.realmsclient.dto;
import java.util.Iterator;
import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.common.collect.Sets;
import java.util.Set;
public class Ops extends ValueObject {
public Set<String> ops;
public Ops() {
this.ops = Sets.newHashSet();
}
public static Ops parse(final String string) {
final Ops dii2 = new Ops();
final JsonParser jsonParser3 = new JsonParser();
try {
final JsonElement jsonElement4 = jsonParser3.parse(string);
final JsonObject jsonObject5 = jsonElement4.getAsJsonObject();
final JsonElement jsonElement5 = jsonObject5.get("ops");
if (jsonElement5.isJsonArray()) {
for (final JsonElement jsonElement6 : jsonElement5.getAsJsonArray()) {
dii2.ops.add(jsonElement6.getAsString());
}
}
}
catch (Exception ex) {}
return dii2;
}
}

View File

@ -0,0 +1,35 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonObject;
import java.util.Date;
import org.apache.logging.log4j.Logger;
public class PendingInvite extends ValueObject {
private static final Logger LOGGER;
public String invitationId;
public String worldName;
public String worldOwnerName;
public String worldOwnerUuid;
public Date date;
public static PendingInvite parse(final JsonObject jsonObject) {
final PendingInvite dij2 = new PendingInvite();
try {
dij2.invitationId = JsonUtils.getStringOr("invitationId", jsonObject, "");
dij2.worldName = JsonUtils.getStringOr("worldName", jsonObject, "");
dij2.worldOwnerName = JsonUtils.getStringOr("worldOwnerName", jsonObject, "");
dij2.worldOwnerUuid = JsonUtils.getStringOr("worldOwnerUuid", jsonObject, "");
dij2.date = JsonUtils.getDateOr("date", jsonObject);
}
catch (Exception exception3) {
PendingInvite.LOGGER.error("Could not parse PendingInvite: " + exception3.getMessage());
}
return dij2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,41 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import java.util.Iterator;
import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.common.collect.Lists;
import java.util.List;
import org.apache.logging.log4j.Logger;
public class PendingInvitesList extends ValueObject {
private static final Logger LOGGER;
public List<PendingInvite> pendingInvites;
public PendingInvitesList() {
this.pendingInvites = Lists.newArrayList();
}
public static PendingInvitesList parse(final String string) {
final PendingInvitesList dik2 = new PendingInvitesList();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
if (jsonObject4.get("invites").isJsonArray()) {
final Iterator<JsonElement> iterator5 = jsonObject4.get("invites").getAsJsonArray().iterator();
while (iterator5.hasNext()) {
dik2.pendingInvites.add(PendingInvite.parse(iterator5.next().getAsJsonObject()));
}
}
}
catch (Exception exception3) {
PendingInvitesList.LOGGER.error("Could not parse PendingInvitesList: " + exception3.getMessage());
}
return dik2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,17 @@
package com.mojang.realmsclient.dto;
import com.google.common.collect.Lists;
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class PingResult extends ValueObject implements ReflectionBasedSerialization {
@SerializedName("pingResults")
public List<RegionPingResult> pingResults;
@SerializedName("worldIds")
public List<Long> worldIds;
public PingResult() {
this.pingResults = Lists.newArrayList();
this.worldIds = Lists.newArrayList();
}
}

View File

@ -0,0 +1,56 @@
package com.mojang.realmsclient.dto;
import com.google.gson.annotations.SerializedName;
public class PlayerInfo extends ValueObject implements ReflectionBasedSerialization {
@SerializedName("name")
private String name;
@SerializedName("uuid")
private String uuid;
@SerializedName("operator")
private boolean operator;
@SerializedName("accepted")
private boolean accepted;
@SerializedName("online")
private boolean online;
public String getName() {
return this.name;
}
public void setName(final String string) {
this.name = string;
}
public String getUuid() {
return this.uuid;
}
public void setUuid(final String string) {
this.uuid = string;
}
public boolean isOperator() {
return this.operator;
}
public void setOperator(final boolean boolean1) {
this.operator = boolean1;
}
public boolean getAccepted() {
return this.accepted;
}
public void setAccepted(final boolean boolean1) {
this.accepted = boolean1;
}
public boolean getOnline() {
return this.online;
}
public void setOnline(final boolean boolean1) {
this.online = boolean1;
}
}

View File

@ -0,0 +1,15 @@
package com.mojang.realmsclient.dto;
import com.google.gson.annotations.SerializedName;
public class RealmsDescriptionDto extends ValueObject implements ReflectionBasedSerialization {
@SerializedName("name")
public String name;
@SerializedName("description")
public String description;
public RealmsDescriptionDto(final String string1, final String string2) {
this.name = string1;
this.description = string2;
}
}

View File

@ -0,0 +1,29 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import com.google.gson.JsonObject;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonParser;
import org.apache.logging.log4j.Logger;
public class RealmsNews extends ValueObject {
private static final Logger LOGGER;
public String newsLink;
public static RealmsNews parse(final String string) {
final RealmsNews dio2 = new RealmsNews();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
dio2.newsLink = JsonUtils.getStringOr("newsLink", jsonObject4, null);
}
catch (Exception exception3) {
RealmsNews.LOGGER.error("Could not parse RealmsNews: " + exception3.getMessage());
}
return dio2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,301 @@
package com.mojang.realmsclient.dto;
import java.util.Comparator;
import org.apache.logging.log4j.LogManager;
import org.apache.commons.lang3.builder.EqualsBuilder;
import java.util.Objects;
import com.google.gson.JsonParser;
import com.google.common.collect.Maps;
import com.google.gson.JsonElement;
import com.google.gson.JsonArray;
import java.util.Locale;
import com.google.common.collect.ComparisonChain;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonObject;
import java.util.Iterator;
import com.google.common.base.Joiner;
import com.mojang.realmsclient.util.RealmsUtil;
import net.minecraft.client.Minecraft;
import com.google.common.collect.Lists;
import java.util.Map;
import java.util.List;
import org.apache.logging.log4j.Logger;
public class RealmsServer extends ValueObject {
private static final Logger LOGGER;
public long id;
public String remoteSubscriptionId;
public String name;
public String motd;
public State state;
public String owner;
public String ownerUUID;
public List<PlayerInfo> players;
public Map<Integer, RealmsWorldOptions> slots;
public boolean expired;
public boolean expiredTrial;
public int daysLeft;
public WorldType worldType;
public int activeSlot;
public String minigameName;
public int minigameId;
public String minigameImage;
public RealmsServerPing serverPing;
public RealmsServer() {
this.serverPing = new RealmsServerPing();
}
public String getDescription() {
return this.motd;
}
public String getName() {
return this.name;
}
public String getMinigameName() {
return this.minigameName;
}
public void setName(final String string) {
this.name = string;
}
public void setDescription(final String string) {
this.motd = string;
}
public void updateServerPing(final RealmsServerPlayerList dit) {
final List<String> list3 = Lists.newArrayList();
int integer4 = 0;
for (final String string6 : dit.players) {
if (string6.equals(Minecraft.getInstance().getUser().getUuid())) {
continue;
}
String string7 = "";
try {
string7 = RealmsUtil.uuidToName(string6);
}
catch (Exception exception8) {
RealmsServer.LOGGER.error("Could not get name for " + string6, (Throwable)exception8);
continue;
}
list3.add(string7);
++integer4;
}
this.serverPing.nrOfPlayers = String.valueOf(integer4);
this.serverPing.playerList = Joiner.on('\n').join(list3);
}
public static RealmsServer parse(final JsonObject jsonObject) {
final RealmsServer dip2 = new RealmsServer();
try {
dip2.id = JsonUtils.getLongOr("id", jsonObject, -1L);
dip2.remoteSubscriptionId = JsonUtils.getStringOr("remoteSubscriptionId", jsonObject, null);
dip2.name = JsonUtils.getStringOr("name", jsonObject, null);
dip2.motd = JsonUtils.getStringOr("motd", jsonObject, null);
dip2.state = getState(JsonUtils.getStringOr("state", jsonObject, State.CLOSED.name()));
dip2.owner = JsonUtils.getStringOr("owner", jsonObject, null);
if (jsonObject.get("players") != null && jsonObject.get("players").isJsonArray()) {
dip2.players = parseInvited(jsonObject.get("players").getAsJsonArray());
sortInvited(dip2);
}
else {
dip2.players = Lists.newArrayList();
}
dip2.daysLeft = JsonUtils.getIntOr("daysLeft", jsonObject, 0);
dip2.expired = JsonUtils.getBooleanOr("expired", jsonObject, false);
dip2.expiredTrial = JsonUtils.getBooleanOr("expiredTrial", jsonObject, false);
dip2.worldType = getWorldType(JsonUtils.getStringOr("worldType", jsonObject, WorldType.NORMAL.name()));
dip2.ownerUUID = JsonUtils.getStringOr("ownerUUID", jsonObject, "");
if (jsonObject.get("slots") != null && jsonObject.get("slots").isJsonArray()) {
dip2.slots = parseSlots(jsonObject.get("slots").getAsJsonArray());
}
else {
dip2.slots = createEmptySlots();
}
dip2.minigameName = JsonUtils.getStringOr("minigameName", jsonObject, null);
dip2.activeSlot = JsonUtils.getIntOr("activeSlot", jsonObject, -1);
dip2.minigameId = JsonUtils.getIntOr("minigameId", jsonObject, -1);
dip2.minigameImage = JsonUtils.getStringOr("minigameImage", jsonObject, null);
}
catch (Exception exception3) {
RealmsServer.LOGGER.error("Could not parse McoServer: " + exception3.getMessage());
}
return dip2;
}
private static void sortInvited(final RealmsServer dip) {
dip.players.sort((dim1, dim2) -> ComparisonChain.start().compareFalseFirst(dim2.getAccepted(), dim1.getAccepted()).compare(dim1.getName().toLowerCase(Locale.ROOT), dim2.getName().toLowerCase(Locale.ROOT)).result());
}
private static List<PlayerInfo> parseInvited(final JsonArray jsonArray) {
final List<PlayerInfo> list2 = Lists.newArrayList();
for (final JsonElement jsonElement4 : jsonArray) {
try {
final JsonObject jsonObject5 = jsonElement4.getAsJsonObject();
final PlayerInfo dim6 = new PlayerInfo();
dim6.setName(JsonUtils.getStringOr("name", jsonObject5, null));
dim6.setUuid(JsonUtils.getStringOr("uuid", jsonObject5, null));
dim6.setOperator(JsonUtils.getBooleanOr("operator", jsonObject5, false));
dim6.setAccepted(JsonUtils.getBooleanOr("accepted", jsonObject5, false));
dim6.setOnline(JsonUtils.getBooleanOr("online", jsonObject5, false));
list2.add(dim6);
}
catch (Exception ex) {}
}
return list2;
}
private static Map<Integer, RealmsWorldOptions> parseSlots(final JsonArray jsonArray) {
final Map<Integer, RealmsWorldOptions> map2 = Maps.newHashMap();
for (final JsonElement jsonElement4 : jsonArray) {
try {
final JsonObject jsonObject6 = jsonElement4.getAsJsonObject();
final JsonParser jsonParser7 = new JsonParser();
final JsonElement jsonElement5 = jsonParser7.parse(jsonObject6.get("options").getAsString());
RealmsWorldOptions div5;
if (jsonElement5 == null) {
div5 = RealmsWorldOptions.createDefaults();
}
else {
div5 = RealmsWorldOptions.parse(jsonElement5.getAsJsonObject());
}
final int integer9 = JsonUtils.getIntOr("slotId", jsonObject6, -1);
map2.put(integer9, div5);
}
catch (Exception ex) {}
}
for (int integer10 = 1; integer10 <= 3; ++integer10) {
if (!map2.containsKey(integer10)) {
map2.put(integer10, RealmsWorldOptions.createEmptyDefaults());
}
}
return map2;
}
private static Map<Integer, RealmsWorldOptions> createEmptySlots() {
final Map<Integer, RealmsWorldOptions> map1 = Maps.newHashMap();
map1.put(1, RealmsWorldOptions.createEmptyDefaults());
map1.put(2, RealmsWorldOptions.createEmptyDefaults());
map1.put(3, RealmsWorldOptions.createEmptyDefaults());
return map1;
}
public static RealmsServer parse(final String string) {
try {
return parse(new JsonParser().parse(string).getAsJsonObject());
}
catch (Exception exception2) {
RealmsServer.LOGGER.error("Could not parse McoServer: " + exception2.getMessage());
return new RealmsServer();
}
}
private static State getState(final String string) {
try {
return State.valueOf(string);
}
catch (Exception exception2) {
return State.CLOSED;
}
}
private static WorldType getWorldType(final String string) {
try {
return WorldType.valueOf(string);
}
catch (Exception exception2) {
return WorldType.NORMAL;
}
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.name, this.motd, this.state, this.owner, this.expired);
}
@Override
public boolean equals(final Object object) {
if (object == null) {
return false;
}
if (object == this) {
return true;
}
if (object.getClass() != this.getClass()) {
return false;
}
final RealmsServer dip3 = (RealmsServer)object;
return new EqualsBuilder().append(this.id, dip3.id).append(this.name, dip3.name).append(this.motd, dip3.motd).append(this.state, dip3.state).append(this.owner, dip3.owner).append(this.expired, dip3.expired).append(this.worldType, this.worldType).isEquals();
}
public RealmsServer clone() {
final RealmsServer dip2 = new RealmsServer();
dip2.id = this.id;
dip2.remoteSubscriptionId = this.remoteSubscriptionId;
dip2.name = this.name;
dip2.motd = this.motd;
dip2.state = this.state;
dip2.owner = this.owner;
dip2.players = this.players;
dip2.slots = this.cloneSlots(this.slots);
dip2.expired = this.expired;
dip2.expiredTrial = this.expiredTrial;
dip2.daysLeft = this.daysLeft;
dip2.serverPing = new RealmsServerPing();
dip2.serverPing.nrOfPlayers = this.serverPing.nrOfPlayers;
dip2.serverPing.playerList = this.serverPing.playerList;
dip2.worldType = this.worldType;
dip2.ownerUUID = this.ownerUUID;
dip2.minigameName = this.minigameName;
dip2.activeSlot = this.activeSlot;
dip2.minigameId = this.minigameId;
dip2.minigameImage = this.minigameImage;
return dip2;
}
public Map<Integer, RealmsWorldOptions> cloneSlots(final Map<Integer, RealmsWorldOptions> map) {
final Map<Integer, RealmsWorldOptions> map2 = Maps.newHashMap();
for (final Map.Entry<Integer, RealmsWorldOptions> entry5 : map.entrySet()) {
map2.put(entry5.getKey(), entry5.getValue().clone());
}
return map2;
}
public String getWorldName(final int integer) {
return this.name + " (" + this.slots.get(integer).getSlotName(integer) + ")";
}
static {
LOGGER = LogManager.getLogger();
}
public static class McoServerComparator implements Comparator<RealmsServer> {
private final String refOwner;
public McoServerComparator(final String string) {
this.refOwner = string;
}
@Override
public int compare(final RealmsServer dip1, final RealmsServer dip2) {
return ComparisonChain.start().compareTrueFirst(dip1.state == State.UNINITIALIZED, dip2.state == State.UNINITIALIZED).compareTrueFirst(dip1.expiredTrial, dip2.expiredTrial).compareTrueFirst(dip1.owner.equals(this.refOwner), dip2.owner.equals(this.refOwner)).compareFalseFirst(dip1.expired, dip2.expired).compareTrueFirst(dip1.state == State.OPEN, dip2.state == State.OPEN).compare(dip1.id, dip2.id).result();
}
}
public enum State {
CLOSED,
OPEN,
UNINITIALIZED;
}
public enum WorldType {
NORMAL,
MINIGAME,
ADVENTUREMAP,
EXPERIENCE,
INSPIRATION;
}
}

View File

@ -0,0 +1,33 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import com.google.gson.JsonObject;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonParser;
import org.apache.logging.log4j.Logger;
public class RealmsServerAddress extends ValueObject {
private static final Logger LOGGER;
public String address;
public String resourcePackUrl;
public String resourcePackHash;
public static RealmsServerAddress parse(final String string) {
final JsonParser jsonParser2 = new JsonParser();
final RealmsServerAddress diq3 = new RealmsServerAddress();
try {
final JsonObject jsonObject4 = jsonParser2.parse(string).getAsJsonObject();
diq3.address = JsonUtils.getStringOr("address", jsonObject4, null);
diq3.resourcePackUrl = JsonUtils.getStringOr("resourcePackUrl", jsonObject4, null);
diq3.resourcePackHash = JsonUtils.getStringOr("resourcePackHash", jsonObject4, null);
}
catch (Exception exception4) {
RealmsServerAddress.LOGGER.error("Could not parse RealmsServerAddress: " + exception4.getMessage());
}
return diq3;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,40 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import java.util.Iterator;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.common.collect.Lists;
import java.util.List;
import org.apache.logging.log4j.Logger;
public class RealmsServerList extends ValueObject {
private static final Logger LOGGER;
public List<RealmsServer> servers;
public static RealmsServerList parse(final String string) {
final RealmsServerList dir2 = new RealmsServerList();
dir2.servers = Lists.newArrayList();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
if (jsonObject4.get("servers").isJsonArray()) {
final JsonArray jsonArray5 = jsonObject4.get("servers").getAsJsonArray();
final Iterator<JsonElement> iterator6 = jsonArray5.iterator();
while (iterator6.hasNext()) {
dir2.servers.add(RealmsServer.parse(iterator6.next().getAsJsonObject()));
}
}
}
catch (Exception exception3) {
RealmsServerList.LOGGER.error("Could not parse McoServerList: " + exception3.getMessage());
}
return dir2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,11 @@
package com.mojang.realmsclient.dto;
public class RealmsServerPing extends ValueObject {
public volatile String nrOfPlayers;
public volatile String playerList;
public RealmsServerPing() {
this.nrOfPlayers = "0";
this.playerList = "";
}
}

View File

@ -0,0 +1,59 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import java.util.Iterator;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.common.collect.Lists;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonObject;
import java.util.List;
import com.google.gson.JsonParser;
import org.apache.logging.log4j.Logger;
public class RealmsServerPlayerList extends ValueObject {
private static final Logger LOGGER;
private static final JsonParser JSON_PARSER;
public long serverId;
public List<String> players;
public static RealmsServerPlayerList parse(final JsonObject jsonObject) {
final RealmsServerPlayerList dit2 = new RealmsServerPlayerList();
try {
dit2.serverId = JsonUtils.getLongOr("serverId", jsonObject, -1L);
final String string3 = JsonUtils.getStringOr("playerList", jsonObject, null);
if (string3 != null) {
final JsonElement jsonElement4 = RealmsServerPlayerList.JSON_PARSER.parse(string3);
if (jsonElement4.isJsonArray()) {
dit2.players = parsePlayers(jsonElement4.getAsJsonArray());
}
else {
dit2.players = Lists.newArrayList();
}
}
else {
dit2.players = Lists.newArrayList();
}
}
catch (Exception exception3) {
RealmsServerPlayerList.LOGGER.error("Could not parse RealmsServerPlayerList: " + exception3.getMessage());
}
return dit2;
}
private static List<String> parsePlayers(final JsonArray jsonArray) {
final List<String> list2 = Lists.newArrayList();
for (final JsonElement jsonElement4 : jsonArray) {
try {
list2.add(jsonElement4.getAsString());
}
catch (Exception ex) {}
}
return list2;
}
static {
LOGGER = LogManager.getLogger();
JSON_PARSER = new JsonParser();
}
}

Some files were not shown because too many files have changed in this diff Show More