Update to 1.14.4

This commit is contained in:
Reno 2020-07-22 05:23:34 +00:00
commit fddde660f4
3251 changed files with 446143 additions and 0 deletions

64034
client.txt Normal file

File diff suppressed because it is too large Load Diff

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 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 csi) {
AL10.alSourcefv(this.source, 4100, new float[] { (float)csi.x, (float)csi.y, (float)csi.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 ctu) {
ctu.getAlBuffer().ifPresent(integer -> AL10.alSourcei(this.source, 4105, integer));
}
public void attachBufferStream(final AudioStream eai) {
this.stream = eai;
final AudioFormat audioFormat3 = eai.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,221 @@
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 ctp) {
if (!this.staticChannels.release(ctp) && !this.streamingChannels.release(ctp)) {
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 ctp) {
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) {
return null;
}
final Channel ctp2 = Channel.create();
if (ctp2 != null) {
this.activeChannels.add(ctp2);
}
return ctp2;
}
@Override
public boolean release(final Channel ctp) {
if (!this.activeChannels.remove(ctp)) {
return false;
}
ctp.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 ctp);
void cleanup();
int getMaxCount();
int getUsedCount();
}
}

View File

@ -0,0 +1,39 @@
package com.mojang.blaze3d.audio;
import org.lwjgl.openal.AL10;
import net.minecraft.world.phys.Vec3;
public class Listener {
public static final Vec3 UP;
private float gain;
public Listener() {
this.gain = 1.0f;
}
public void setListenerPosition(final Vec3 csi) {
AL10.alListener3f(4100, (float)csi.x, (float)csi.y, (float)csi.z);
}
public void setListenerOrientation(final Vec3 csi1, final Vec3 csi2) {
AL10.alListenerfv(4111, new float[] { (float)csi1.x, (float)csi1.y, (float)csi1.z, (float)csi2.x, (float)csi2.y, (float)csi2.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(new Vec3(0.0, 0.0, -1.0), Listener.UP);
}
static {
UP = new Vec3(0.0, 1.0, 0.0);
}
}

View File

@ -0,0 +1,223 @@
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 javax.annotation.Nullable;
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;
}
@Nullable
@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();
}
@Override
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,14 @@
package com.mojang.blaze3d.font;
import javax.annotation.Nullable;
import java.io.Closeable;
public interface GlyphProvider extends Closeable {
default void close() {
}
@Nullable
default RawGlyph getGlyph(final char character) {
return null;
}
}

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,143 @@
package com.mojang.blaze3d.font;
import com.mojang.blaze3d.platform.NativeImage;
import org.apache.logging.log4j.LogManager;
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.annotation.Nullable;
import java.nio.IntBuffer;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.stb.STBTruetype;
import it.unimi.dsi.fastutil.chars.CharArraySet;
import it.unimi.dsi.fastutil.chars.CharSet;
import org.lwjgl.stb.STBTTFontinfo;
import org.apache.logging.log4j.Logger;
public class TrueTypeGlyphProvider implements GlyphProvider {
private static final Logger LOGGER;
private final STBTTFontinfo font;
private final float oversample;
private final CharSet skip;
private final float shiftX;
private final float shiftY;
private final float pointScale;
private final float ascent;
public TrueTypeGlyphProvider(final STBTTFontinfo sTBTTFontinfo, final float float2, final float float3, final float float4, final float float5, final String string) {
this.skip = (CharSet)new CharArraySet();
this.font = sTBTTFontinfo;
this.oversample = float3;
string.chars().forEach(integer -> this.skip.add((char)(integer & 0xFFFF)));
this.shiftX = float4 * float3;
this.shiftY = float5 * float3;
this.pointScale = STBTruetype.stbtt_ScaleForPixelHeight(sTBTTFontinfo, float2 * float3);
try (final MemoryStack memoryStack8 = MemoryStack.stackPush()) {
final IntBuffer intBuffer10 = memoryStack8.mallocInt(1);
final IntBuffer intBuffer11 = memoryStack8.mallocInt(1);
final IntBuffer intBuffer12 = memoryStack8.mallocInt(1);
STBTruetype.stbtt_GetFontVMetrics(sTBTTFontinfo, intBuffer10, intBuffer11, intBuffer12);
this.ascent = intBuffer10.get(0) * this.pointScale;
}
}
@Nullable
@Override
public Glyph getGlyph(final char character) {
if (this.skip.contains(character)) {
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 integer9 = STBTruetype.stbtt_FindGlyphIndex(this.font, (int)character);
if (integer9 == 0) {
return null;
}
STBTruetype.stbtt_GetGlyphBitmapBoxSubpixel(this.font, integer9, this.pointScale, this.pointScale, this.shiftX, this.shiftY, intBuffer5, intBuffer6, intBuffer7, intBuffer8);
final int integer10 = intBuffer7.get(0) - intBuffer5.get(0);
final int integer11 = intBuffer8.get(0) - intBuffer6.get(0);
if (integer10 == 0 || integer11 == 0) {
return null;
}
final IntBuffer intBuffer9 = memoryStack3.mallocInt(1);
final IntBuffer intBuffer10 = memoryStack3.mallocInt(1);
STBTruetype.stbtt_GetGlyphHMetrics(this.font, integer9, 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, integer9);
}
}
public static STBTTFontinfo getStbttFontinfo(final ByteBuffer byteBuffer) throws IOException {
final STBTTFontinfo sTBTTFontinfo2 = STBTTFontinfo.create();
if (!STBTruetype.stbtt_InitFont(sTBTTFontinfo2, byteBuffer)) {
throw new IOException("Invalid ttf");
}
return sTBTTFontinfo2;
}
static {
LOGGER = LogManager.getLogger();
}
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) {
try (final NativeImage cuj4 = new NativeImage(NativeImage.Format.LUMINANCE, this.width, this.height, false)) {
cuj4.copyFromFont(TrueTypeGlyphProvider.this.font, this.index, this.width, this.height, TrueTypeGlyphProvider.this.pointScale, TrueTypeGlyphProvider.this.pointScale, TrueTypeGlyphProvider.this.shiftX, TrueTypeGlyphProvider.this.shiftY, 0, 0);
cuj4.upload(0, integer1, integer2, 0, 0, this.width, this.height, false);
}
}
@Override
public boolean isColored() {
return false;
}
}
}

View File

@ -0,0 +1,220 @@
package com.mojang.blaze3d.pipeline;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import java.nio.IntBuffer;
import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.GLX;
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) {
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 (!GLX.isUsingFBOs()) {
this.viewWidth = integer1;
this.viewHeight = integer2;
return;
}
GlStateManager.enableDepthTest();
if (this.frameBufferId >= 0) {
this.destroyBuffers();
}
this.createBuffers(integer1, integer2, boolean3);
GLX.glBindFramebuffer(GLX.GL_FRAMEBUFFER, 0);
}
public void destroyBuffers() {
if (!GLX.isUsingFBOs()) {
return;
}
this.unbindRead();
this.unbindWrite();
if (this.depthBufferId > -1) {
GLX.glDeleteRenderbuffers(this.depthBufferId);
this.depthBufferId = -1;
}
if (this.colorTextureId > -1) {
TextureUtil.releaseTextureId(this.colorTextureId);
this.colorTextureId = -1;
}
if (this.frameBufferId > -1) {
GLX.glBindFramebuffer(GLX.GL_FRAMEBUFFER, 0);
GLX.glDeleteFramebuffers(this.frameBufferId);
this.frameBufferId = -1;
}
}
public void createBuffers(final int integer1, final int integer2, final boolean boolean3) {
this.viewWidth = integer1;
this.viewHeight = integer2;
this.width = integer1;
this.height = integer2;
if (!GLX.isUsingFBOs()) {
this.clear(boolean3);
return;
}
this.frameBufferId = GLX.glGenFramebuffers();
this.colorTextureId = TextureUtil.generateTextureId();
if (this.useDepth) {
this.depthBufferId = GLX.glGenRenderbuffers();
}
this.setFilterMode(9728);
GlStateManager.bindTexture(this.colorTextureId);
GlStateManager.texImage2D(3553, 0, 32856, this.width, this.height, 0, 6408, 5121, null);
GLX.glBindFramebuffer(GLX.GL_FRAMEBUFFER, this.frameBufferId);
GLX.glFramebufferTexture2D(GLX.GL_FRAMEBUFFER, GLX.GL_COLOR_ATTACHMENT0, 3553, this.colorTextureId, 0);
if (this.useDepth) {
GLX.glBindRenderbuffer(GLX.GL_RENDERBUFFER, this.depthBufferId);
GLX.glRenderbufferStorage(GLX.GL_RENDERBUFFER, 33190, this.width, this.height);
GLX.glFramebufferRenderbuffer(GLX.GL_FRAMEBUFFER, GLX.GL_DEPTH_ATTACHMENT, GLX.GL_RENDERBUFFER, this.depthBufferId);
}
this.checkStatus();
this.clear(boolean3);
this.unbindRead();
}
public void setFilterMode(final int integer) {
if (GLX.isUsingFBOs()) {
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() {
final int integer2 = GLX.glCheckFramebufferStatus(GLX.GL_FRAMEBUFFER);
if (integer2 == GLX.GL_FRAMEBUFFER_COMPLETE) {
return;
}
if (integer2 == GLX.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
}
if (integer2 == GLX.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
}
if (integer2 == GLX.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER");
}
if (integer2 == GLX.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER");
}
throw new RuntimeException("glCheckFramebufferStatus returned unknown status:" + integer2);
}
public void bindRead() {
if (GLX.isUsingFBOs()) {
GlStateManager.bindTexture(this.colorTextureId);
}
}
public void unbindRead() {
if (GLX.isUsingFBOs()) {
GlStateManager.bindTexture(0);
}
}
public void bindWrite(final boolean boolean1) {
if (GLX.isUsingFBOs()) {
GLX.glBindFramebuffer(GLX.GL_FRAMEBUFFER, this.frameBufferId);
if (boolean1) {
GlStateManager.viewport(0, 0, this.viewWidth, this.viewHeight);
}
}
}
public void unbindWrite() {
if (GLX.isUsingFBOs()) {
GLX.glBindFramebuffer(GLX.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) {
if (!GLX.isUsingFBOs()) {
return;
}
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 cuz9 = Tesselator.getInstance();
final BufferBuilder cuw10 = cuz9.getBuilder();
cuw10.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR);
cuw10.vertex(0.0, float6, 0.0).uv(0.0, 0.0).color(255, 255, 255, 255).endVertex();
cuw10.vertex(float5, float6, 0.0).uv(float7, 0.0).color(255, 255, 255, 255).endVertex();
cuw10.vertex(float5, 0.0, 0.0).uv(float7, float8).color(255, 255, 255, 255).endVertex();
cuw10.vertex(0.0, 0.0, 0.0).uv(0.0, float8).color(255, 255, 255, 255).endVertex();
cuz9.end();
this.unbindRead();
GlStateManager.depthMask(true);
GlStateManager.colorMask(true, true, true, true);
}
public void clear(final boolean boolean1) {
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,44 @@
package com.mojang.blaze3d.platform;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.glfw.GLFWErrorCallback;
import net.minecraft.SharedConstants;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import java.nio.ByteBuffer;
public class ClipboardManager {
private final ByteBuffer clipboardScratchBuffer;
public ClipboardManager() {
this.clipboardScratchBuffer = ByteBuffer.allocateDirect(1024);
}
public String getClipboard(final long long1, final GLFWErrorCallbackI gLFWErrorCallbackI) {
final GLFWErrorCallback gLFWErrorCallback5 = GLFW.glfwSetErrorCallback(gLFWErrorCallbackI);
String string6 = GLFW.glfwGetClipboardString(long1);
string6 = ((string6 != null) ? SharedConstants.filterUnicodeSupplementary(string6) : "");
final GLFWErrorCallback gLFWErrorCallback6 = GLFW.glfwSetErrorCallback((GLFWErrorCallbackI)gLFWErrorCallback5);
if (gLFWErrorCallback6 != null) {
gLFWErrorCallback6.free();
}
return string6;
}
private void setClipboard(final long long1, final ByteBuffer byteBuffer, final String string) {
MemoryUtil.memUTF8((CharSequence)string, true, byteBuffer);
GLFW.glfwSetClipboardString(long1, byteBuffer);
}
public void setClipboard(final long long1, final String string) {
final int integer5 = MemoryUtil.memLengthUTF8((CharSequence)string, true);
if (integer5 < this.clipboardScratchBuffer.capacity()) {
this.setClipboard(long1, this.clipboardScratchBuffer, string);
this.clipboardScratchBuffer.clear();
}
else {
final ByteBuffer byteBuffer6 = ByteBuffer.allocateDirect(integer5);
this.setClipboard(long1, byteBuffer6, string);
}
}
}

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;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,884 @@
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 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) {
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,338 @@
package com.mojang.blaze3d.platform;
import com.google.common.collect.Maps;
import java.util.Objects;
import java.util.Map;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import java.lang.invoke.MethodType;
import java.lang.invoke.MethodHandles;
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) {
GLFW.glfwSetCursorPosCallback(long1, gLFWCursorPosCallbackI);
GLFW.glfwSetMouseButtonCallback(long1, gLFWMouseButtonCallbackI);
GLFW.glfwSetScrollCallback(long1, gLFWScrollCallbackI);
}
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));
}
}
@Nullable
public static String translateKeyCode(final int integer) {
return GLFW.glfwGetKeyName(integer, -1);
}
@Nullable
public static String translateScanCode(final int integer) {
return GLFW.glfwGetKeyName(-1, integer);
}
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"),
SCANCODE("scancode"),
MOUSE("key.mouse");
private static final String[] MOUSE_BUTTON_NAMES;
private final Int2ObjectMap<Key> map;
private final String defaultPrefix;
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) {
this.map = (Int2ObjectMap<Key>)new Int2ObjectOpenHashMap();
this.defaultPrefix = string3;
}
public Key getOrCreate(final int integer) {
if (this.map.containsKey(integer)) {
return (Key)this.map.get(integer);
}
String string3;
if (this == Type.MOUSE) {
if (integer <= 2) {
string3 = "." + Type.MOUSE_BUTTON_NAMES[integer];
}
else {
string3 = "." + (integer + 1);
}
}
else {
string3 = "." + integer;
}
final Key a4 = new Key(this.defaultPrefix + string3, this, integer);
this.map.put(integer, a4);
return a4;
}
public String getDefaultPrefix() {
return this.defaultPrefix;
}
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);
MOUSE_BUTTON_NAMES = new String[] { "left", "middle", "right" };
}
}
public static final class Key {
private final String name;
private final Type type;
private final int value;
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;
Key.NAME_MAP.put(string, this);
}
public Type getType() {
return this.type;
}
public int getValue() {
return this.value;
}
public String getName() {
return this.name;
}
@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,64 @@
package com.mojang.blaze3d.platform;
import com.mojang.math.Vector3f;
import java.nio.FloatBuffer;
public class Lighting {
private static final FloatBuffer BUFFER;
private static final Vector3f LIGHT_0;
private static final Vector3f LIGHT_1;
private static Vector3f createVector(final float float1, final float float2, final float float3) {
final Vector3f b4 = new Vector3f(float1, float2, float3);
b4.normalize();
return b4;
}
public static void turnOff() {
GlStateManager.disableLighting();
GlStateManager.disableLight(0);
GlStateManager.disableLight(1);
GlStateManager.disableColorMaterial();
}
public static void turnOn() {
GlStateManager.enableLighting();
GlStateManager.enableLight(0);
GlStateManager.enableLight(1);
GlStateManager.enableColorMaterial();
GlStateManager.colorMaterial(1032, 5634);
GlStateManager.light(16384, 4611, getBuffer(Lighting.LIGHT_0.x(), Lighting.LIGHT_0.y(), Lighting.LIGHT_0.z(), 0.0f));
final float float1 = 0.6f;
GlStateManager.light(16384, 4609, getBuffer(0.6f, 0.6f, 0.6f, 1.0f));
GlStateManager.light(16384, 4608, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
GlStateManager.light(16384, 4610, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
GlStateManager.light(16385, 4611, getBuffer(Lighting.LIGHT_1.x(), Lighting.LIGHT_1.y(), Lighting.LIGHT_1.z(), 0.0f));
GlStateManager.light(16385, 4609, getBuffer(0.6f, 0.6f, 0.6f, 1.0f));
GlStateManager.light(16385, 4608, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
GlStateManager.light(16385, 4610, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
GlStateManager.shadeModel(7424);
final float float2 = 0.4f;
GlStateManager.lightModel(2899, getBuffer(0.4f, 0.4f, 0.4f, 1.0f));
}
public static FloatBuffer getBuffer(final float float1, final float float2, final float float3, final float float4) {
Lighting.BUFFER.clear();
Lighting.BUFFER.put(float1).put(float2).put(float3).put(float4);
Lighting.BUFFER.flip();
return Lighting.BUFFER;
}
public static void turnOnGui() {
GlStateManager.pushMatrix();
GlStateManager.rotatef(-30.0f, 0.0f, 1.0f, 0.0f);
GlStateManager.rotatef(165.0f, 1.0f, 0.0f, 0.0f);
turnOn();
GlStateManager.popMatrix();
}
static {
BUFFER = MemoryTracker.createFloatBuffer(4);
LIGHT_0 = createVector(0.2f, 1.0f, -0.7f);
LIGHT_1 = createVector(-0.2f, 1.0f, 0.7f);
}
}

View File

@ -0,0 +1,36 @@
package com.mojang.blaze3d.platform;
import java.nio.FloatBuffer;
import java.nio.ByteOrder;
import java.nio.ByteBuffer;
public class MemoryTracker {
public static synchronized int genLists(final int integer) {
final int integer2 = GlStateManager.genLists(integer);
if (integer2 == 0) {
final int integer3 = GlStateManager.getError();
String string4 = "No error code reported";
if (integer3 != 0) {
string4 = GLX.getErrorString(integer3);
}
throw new IllegalStateException("glGenLists returned an ID of 0 for a count of " + integer + ", GL error (" + integer3 + "): " + string4);
}
return integer2;
}
public static synchronized void releaseLists(final int integer1, final int integer2) {
GlStateManager.deleteLists(integer1, integer2);
}
public static synchronized void releaseList(final int integer) {
releaseLists(integer, 1);
}
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,86 @@
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.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();
}
private void refreshVideoModes() {
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 cun4 = new VideoMode(buffer2);
if (cun4.getRedBits() >= 8 && cun4.getGreenBits() >= 8 && cun4.getBlueBits() >= 8) {
this.videoModes.add(cun4);
}
}
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) {
if (optional.isPresent()) {
final VideoMode cun3 = optional.get();
for (final VideoMode cun4 : this.videoModes) {
if (cun4.equals(cun3)) {
return cun4;
}
}
}
return this.getCurrentMode();
}
public int getVideoModeIndex(final VideoMode cun) {
return this.videoModes.indexOf(cun);
}
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,557 @@
package com.mojang.blaze3d.platform;
import org.lwjgl.stb.STBIWriteCallback;
import java.util.EnumSet;
import java.util.Base64;
import org.lwjgl.stb.STBImageResize;
import java.nio.channels.WritableByteChannel;
import org.lwjgl.stb.STBIWriteCallbackI;
import org.lwjgl.stb.STBImageWrite;
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 java.nio.file.FileSystems;
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;
public final class NativeImage implements AutoCloseable {
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 int 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 * integer3 * a.components();
this.useStbFree = false;
if (boolean4) {
this.pixels = MemoryUtil.nmemCalloc(1L, (long)this.size);
}
else {
this.pixels = MemoryUtil.nmemAlloc((long)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) {
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) {
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();
return MemoryUtil.memIntBuffer(this.pixels, this.size).get(integer1 + integer2 * this.width);
}
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();
MemoryUtil.memIntBuffer(this.pixels, this.size).put(integer1 + integer2 * this.width, 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));
}
return MemoryUtil.memByteBuffer(this.pixels, this.size).get((integer1 + integer2 * this.width) * this.format.components() + this.format.luminanceOrAlphaOffset() / 8);
}
public void blendPixel(final int integer1, final int integer2, final int integer3) {
if (this.format != Format.RGBA) {
throw new UnsupportedOperationException("Can only call blendPixel with RGBA format");
}
final int integer4 = this.getPixelRGBA(integer1, integer2);
final float float6 = (integer3 >> 24 & 0xFF) / 255.0f;
final float float7 = (integer3 >> 16 & 0xFF) / 255.0f;
final float float8 = (integer3 >> 8 & 0xFF) / 255.0f;
final float float9 = (integer3 >> 0 & 0xFF) / 255.0f;
final float float10 = (integer4 >> 24 & 0xFF) / 255.0f;
final float float11 = (integer4 >> 16 & 0xFF) / 255.0f;
final float float12 = (integer4 >> 8 & 0xFF) / 255.0f;
final float float13 = (integer4 >> 0 & 0xFF) / 255.0f;
final float float14 = float6;
final float float15 = 1.0f - float6;
float float16 = float6 * float14 + float10 * float15;
float float17 = float7 * float14 + float11 * float15;
float float18 = float8 * float14 + float12 * float15;
float float19 = float9 * float14 + float13 * float15;
if (float16 > 1.0f) {
float16 = 1.0f;
}
if (float17 > 1.0f) {
float17 = 1.0f;
}
if (float18 > 1.0f) {
float18 = 1.0f;
}
if (float19 > 1.0f) {
float19 = 1.0f;
}
final int integer5 = (int)(float16 * 255.0f);
final int integer6 = (int)(float17 * 255.0f);
final int integer7 = (int)(float18 * 255.0f);
final int integer8 = (int)(float19 * 255.0f);
this.setPixelRGBA(integer1, integer2, integer5 << 24 | integer6 << 16 | integer7 << 8 | integer8 << 0);
}
@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 = integer5 >> 24 & 0xFF;
final int integer7 = integer5 >> 16 & 0xFF;
final int integer8 = integer5 >> 8 & 0xFF;
final int integer9 = integer5 >> 0 & 0xFF;
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, 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) {
this.upload(integer1, integer2, integer3, integer4, integer5, integer6, integer7, false, false, boolean8);
}
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) {
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);
}
public void downloadTexture(final int integer, final boolean boolean2) {
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 downloadFrameBuffer(final boolean boolean1) {
this.checkAllocated();
this.format.setPackPixelStoreState();
if (boolean1) {
GlStateManager.pixelTransfer(3357, Float.MAX_VALUE);
}
GlStateManager.readPixels(0, 0, this.width, this.height, this.format.glFormat(), 5121, this.pixels);
if (boolean1) {
GlStateManager.pixelTransfer(3357, 0.0f);
}
}
public void writeToFile(final String string) throws IOException {
this.writeToFile(FileSystems.getDefault().getPath(string));
}
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])) {
final WriteCallback c5 = new WriteCallback(writableByteChannel3);
try {
if (!STBImageWrite.stbi_write_png_to_func((STBIWriteCallbackI)c5, 0L, this.getWidth(), this.getHeight(), this.format.components(), MemoryUtil.memByteBuffer(this.pixels, this.size), 0)) {
throw new IOException("Could not write image to the PNG file \"" + path.toAbsolutePath() + "\": " + STBImage.stbi_failure_reason());
}
}
finally {
c5.free();
}
c5.throwIfException();
}
}
public void copyFrom(final NativeImage cuj) {
if (cuj.format() != this.format) {
throw new UnsupportedOperationException("Image formats don't match.");
}
final int integer3 = this.format.components();
this.checkAllocated();
cuj.checkAllocated();
if (this.width == cuj.width) {
MemoryUtil.memCopy(cuj.pixels, this.pixels, (long)Math.min(this.size, cuj.size));
}
else {
final int integer4 = Math.min(this.getWidth(), cuj.getWidth());
for (int integer5 = Math.min(this.getHeight(), cuj.getHeight()), integer6 = 0; integer6 < integer5; ++integer6) {
final int integer7 = integer6 * cuj.getWidth() * integer3;
final int integer8 = integer6 * this.getWidth() * integer3;
MemoryUtil.memCopy(cuj.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 cuj) {
this.checkAllocated();
if (cuj.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, cuj.pixels, cuj.getWidth(), cuj.getHeight(), 0, integer5);
}
public void untrack() {
DebugMemoryUntracker.untrack(this.pixels);
}
public static NativeImage fromBase64(final String string) throws IOException {
try (final MemoryStack memoryStack2 = MemoryStack.stackPush()) {
final ByteBuffer byteBuffer4 = memoryStack2.UTF8((CharSequence)string.replaceAll("\n", ""), false);
final ByteBuffer byteBuffer5 = Base64.getDecoder().decode(byteBuffer4);
final ByteBuffer byteBuffer6 = memoryStack2.malloc(byteBuffer5.remaining());
byteBuffer6.put(byteBuffer5);
byteBuffer6.rewind();
return read(byteBuffer6);
}
}
static {
OPEN_OPTIONS = EnumSet.<StandardOpenOption>of(StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}
static class WriteCallback extends STBIWriteCallback {
private final WritableByteChannel output;
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;
}
public 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() {
GlStateManager.pixelStore(3333, this.components());
}
public void setUnpackPixelStoreState() {
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,91 @@
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 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 cui) {
this.monitors = (Long2ObjectMap<Monitor>)new Long2ObjectOpenHashMap();
this.monitorCreator = cui;
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, cui.createMonitor(long5));
}
}
}
private void onMonitorChange(final long long1, final int integer) {
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) {
return (Monitor)this.monitors.get(long1);
}
@Nullable
public Monitor findBestMonitor(final Window cuo) {
final long long3 = GLFW.glfwGetWindowMonitor(cuo.getWindow());
if (long3 != 0L) {
return this.getMonitor(long3);
}
final int integer5 = cuo.getX();
final int integer6 = integer5 + cuo.getScreenWidth();
final int integer7 = cuo.getY();
final int integer8 = integer7 + cuo.getScreenHeight();
int integer9 = -1;
Monitor cuh10 = null;
for (final Monitor cuh11 : this.monitors.values()) {
final int integer10 = cuh11.getX();
final int integer11 = integer10 + cuh11.getCurrentMode().getWidth();
final int integer12 = cuh11.getY();
final int integer13 = integer12 + cuh11.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) {
cuh10 = cuh11;
integer9 = integer20;
}
}
return cuh10;
}
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() {
final GLFWMonitorCallback gLFWMonitorCallback2 = GLFW.glfwSetMonitorCallback((GLFWMonitorCallbackI)null);
if (gLFWMonitorCallback2 != null) {
gLFWMonitorCallback2.free();
}
}
}

View File

@ -0,0 +1,5 @@
package com.mojang.blaze3d.platform;
public interface SnooperAccess {
void setFixedData(final String string, final Object object);
}

View File

@ -0,0 +1,128 @@
package com.mojang.blaze3d.platform;
import org.apache.logging.log4j.LogManager;
import org.lwjgl.opengl.GL11;
import java.io.File;
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 org.apache.logging.log4j.Logger;
public class TextureUtil {
private static final Logger LOGGER;
public static final int MIN_MIPMAP_LEVEL = 0;
private static final int DEFAULT_IMAGE_BUFFER_SIZE = 8192;
public static int generateTextureId() {
return GlStateManager.genTexture();
}
public static void releaseTextureId(final int integer) {
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) {
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) {
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) {
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 writeAsPNG(final String string, final int integer2, final int integer3, final int integer4, final int integer5) {
bind(integer2);
for (int integer6 = 0; integer6 <= integer3; ++integer6) {
final String string2 = string + "_" + integer6 + ".png";
final int integer7 = integer4 >> integer6;
final int integer8 = integer5 >> integer6;
try (final NativeImage cuj10 = new NativeImage(integer7, integer8, false)) {
cuj10.downloadTexture(integer6, false);
cuj10.writeToFile(string2);
TextureUtil.LOGGER.debug("Exported png to: {}", new File(string2).getAbsolutePath());
}
catch (IOException iOException10) {
TextureUtil.LOGGER.debug("Unable to write: ", (Throwable)iOException10);
}
}
}
public static void initTexture(final IntBuffer intBuffer, final int integer2, final int integer3) {
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 cun3 = (VideoMode)object;
return this.width == cun3.width && this.height == cun3.height && this.redBits == cun3.redBits && this.greenBits == cun3.greenBits && this.blueBits == cun3.blueBits && this.refreshRate == cun3.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,434 @@
package com.mojang.blaze3d.platform;
import org.apache.logging.log4j.LogManager;
import org.lwjgl.glfw.Callbacks;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import javax.annotation.Nullable;
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 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 minecraft;
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 double lastDrawTime;
private int framerateLimit;
private boolean vsync;
public Window(final WindowEventHandler cup, final ScreenManager cul, final DisplayData cuc, final String string4, final String string5) {
this.defaultErrorCallback = GLFWErrorCallback.create(this::defaultErrorCallback);
this.errorSection = "";
this.lastDrawTime = Double.MIN_VALUE;
this.screenManager = cul;
this.setBootGlErrorCallback();
this.setGlErrorSection("Pre startup");
this.minecraft = cup;
final Optional<VideoMode> optional7 = VideoMode.read(string4);
if (optional7.isPresent()) {
this.preferredFullscreenVideoMode = optional7;
}
else if (cuc.fullscreenWidth.isPresent() && cuc.fullscreenHeight.isPresent()) {
this.preferredFullscreenVideoMode = Optional.<VideoMode>of(new VideoMode(cuc.fullscreenWidth.getAsInt(), cuc.fullscreenHeight.getAsInt(), 8, 8, 8, 60));
}
else {
this.preferredFullscreenVideoMode = Optional.<VideoMode>empty();
}
final boolean isFullscreen = cuc.isFullscreen;
this.fullscreen = isFullscreen;
this.actuallyFullscreen = isFullscreen;
final Monitor cuh8 = cul.getMonitor(GLFW.glfwGetPrimaryMonitor());
final int n = (cuc.width > 0) ? cuc.width : 1;
this.width = n;
this.windowedWidth = n;
final int n2 = (cuc.height > 0) ? cuc.height : 1;
this.height = n2;
this.windowedHeight = n2;
GLFW.glfwDefaultWindowHints();
this.window = GLFW.glfwCreateWindow(this.width, this.height, (CharSequence)string5, (this.fullscreen && cuh8 != null) ? cuh8.getMonitor() : 0L, 0L);
if (cuh8 != null) {
final VideoMode cun9 = cuh8.getPreferredVidMode(this.fullscreen ? this.preferredFullscreenVideoMode : Optional.<VideoMode>empty());
final int n3 = cuh8.getX() + cun9.getWidth() / 2 - this.width / 2;
this.x = n3;
this.windowedX = n3;
final int n4 = cuh8.getY() + cun9.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);
}
public static void checkGlfwError(final BiConsumer<Integer, String> biConsumer) {
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 setupGuiState(final boolean boolean1) {
GlStateManager.clear(256, boolean1);
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
GlStateManager.ortho(0.0, this.getWidth() / this.getGuiScale(), this.getHeight() / this.getGuiScale(), 0.0, 1000.0, 3000.0);
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
GlStateManager.translatef(0.0f, 0.0f, -2000.0f);
}
public void setIcon(final InputStream inputStream1, final InputStream inputStream2) {
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 {
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 setGlErrorSection(final String string) {
this.errorSection = string;
}
private void setBootGlErrorCallback() {
GLFW.glfwSetErrorCallback(Window::bootCrash);
}
private static void bootCrash(final int integer, final long long2) {
throw new IllegalStateException("GLFW error " + integer + ": " + MemoryUtil.memUTF8(long2));
}
public void defaultErrorCallback(final int integer, final long long2) {
final String string5 = MemoryUtil.memUTF8(long2);
Window.LOGGER.error("########## GL ERROR ##########");
Window.LOGGER.error("@ {}", this.errorSection);
Window.LOGGER.error("{}: {}", integer, string5);
}
public void setDefaultGlErrorCallback() {
GLFW.glfwSetErrorCallback((GLFWErrorCallbackI)this.defaultErrorCallback).free();
}
public void updateVsync(final boolean boolean1) {
GLFW.glfwSwapInterval((int)((this.vsync = boolean1) ? 1 : 0));
}
@Override
public void close() {
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.minecraft.resizeDisplay();
}
}
private void refreshFramebufferSize() {
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.minecraft.setWindowActive(boolean2);
}
}
public void setFramerateLimit(final int integer) {
this.framerateLimit = integer;
}
public int getFramerateLimit() {
return this.framerateLimit;
}
public void updateDisplay(final boolean boolean1) {
GLFW.glfwSwapBuffers(this.window);
pollEventQueue();
if (this.fullscreen != this.actuallyFullscreen) {
this.actuallyFullscreen = this.fullscreen;
this.updateFullscreen(this.vsync);
}
}
public void limitDisplayFPS() {
double double2;
double double3;
for (double2 = this.lastDrawTime + 1.0 / this.getFramerateLimit(), double3 = GLFW.glfwGetTime(); double3 < double2; double3 = GLFW.glfwGetTime()) {
GLFW.glfwWaitEventsTimeout(double2 - double3);
}
this.lastDrawTime = double3;
}
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.minecraft.resizeDisplay();
}
}
private void setMode() {
final boolean boolean2 = GLFW.glfwGetWindowMonitor(this.window) != 0L;
if (this.fullscreen) {
final Monitor cuh3 = this.screenManager.findBestMonitor(this);
if (cuh3 == null) {
Window.LOGGER.warn("Failed to find suitable monitor for fullscreen mode");
this.fullscreen = false;
}
else {
final VideoMode cun4 = cuh3.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 = cun4.getWidth();
this.height = cun4.getHeight();
GLFW.glfwSetWindowMonitor(this.window, cuh3.getMonitor(), this.x, this.y, this.width, this.height, cun4.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) {
try {
this.setMode();
this.minecraft.resizeDisplay();
this.updateVsync(boolean1);
this.minecraft.updateDisplay(false);
}
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 long getWindow() {
return this.window;
}
public boolean isFullscreen() {
return this.fullscreen;
}
public int getWidth() {
return this.framebufferWidth;
}
public int getHeight() {
return this.framebufferHeight;
}
public static void pollEventQueue() {
GLFW.glfwPollEvents();
}
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();
}
}

View File

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

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 cve) {
}
}

View File

@ -0,0 +1,148 @@
package com.mojang.blaze3d.shaders;
import java.util.Locale;
import com.mojang.blaze3d.platform.GlStateManager;
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) {
GlStateManager.disableBlend();
return;
}
GlStateManager.enableBlend();
}
GlStateManager.blendEquation(this.blendFunc);
if (this.separateBlend) {
GlStateManager.blendFuncSeparate(this.srcColorFactor, this.dstColorFactor, this.srcAlphaFactor, this.dstAlphaFactor);
}
else {
GlStateManager.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 cur3 = (BlendMode)object;
return this.blendFunc == cur3.blendFunc && this.dstAlphaFactor == cur3.dstAlphaFactor && this.dstColorFactor == cur3.dstColorFactor && this.opaque == cur3.opaque && this.separateBlend == cur3.separateBlend && this.srcAlphaFactor == cur3.srcAlphaFactor && this.srcColorFactor == cur3.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,89 @@
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.GLX;
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 cus) {
++this.references;
GLX.glAttachShader(cus.getId(), this.id);
}
public void close() {
--this.references;
if (this.references <= 0) {
GLX.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 {
final String string2 = TextureUtil.readResourceAsString(inputStream);
if (string2 == null) {
throw new IOException("Could not load program " + a.getName());
}
final int integer5 = GLX.glCreateShader(a.getGlType());
GLX.glShaderSource(integer5, string2);
GLX.glCompileShader(integer5);
if (GLX.glGetShaderi(integer5, GLX.GL_COMPILE_STATUS) == 0) {
final String string3 = StringUtils.trim(GLX.glGetShaderInfoLog(integer5, 32768));
throw new IOException("Couldn't compile " + a.getName() + " program: " + string3);
}
final Program cut6 = new Program(a, integer5, string);
a.getPrograms().put(string, cut6);
return cut6;
}
public enum Type {
VERTEX("vertex", ".vsh", GLX.GL_VERTEX_SHADER),
FRAGMENT("fragment", ".fsh", GLX.GL_FRAGMENT_SHADER);
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,51 @@
package com.mojang.blaze3d.shaders;
import org.apache.logging.log4j.LogManager;
import java.io.IOException;
import com.mojang.blaze3d.platform.GLX;
import org.apache.logging.log4j.Logger;
public class ProgramManager {
private static final Logger LOGGER;
private static ProgramManager instance;
public static void createInstance() {
ProgramManager.instance = new ProgramManager();
}
public static ProgramManager getInstance() {
return ProgramManager.instance;
}
private ProgramManager() {
}
public void releaseProgram(final Effect cus) {
cus.getFragmentProgram().close();
cus.getVertexProgram().close();
GLX.glDeleteProgram(cus.getId());
}
public int createProgram() throws IOException {
final int integer2 = GLX.glCreateProgram();
if (integer2 <= 0) {
throw new IOException("Could not create shader program (returned program ID " + integer2 + ")");
}
return integer2;
}
public void linkProgram(final Effect cus) throws IOException {
cus.getFragmentProgram().attachToEffect(cus);
cus.getVertexProgram().attachToEffect(cus);
GLX.glLinkProgram(cus.getId());
final int integer3 = GLX.glGetProgrami(cus.getId(), GLX.GL_LINK_STATUS);
if (integer3 == 0) {
ProgramManager.LOGGER.warn("Error encountered when linking program containing VS {} and FS {}. Log output:", cus.getVertexProgram().getName(), cus.getFragmentProgram().getName());
ProgramManager.LOGGER.warn(GLX.glGetProgramInfoLog(cus.getId(), 32768));
}
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,268 @@
package com.mojang.blaze3d.shaders;
import org.apache.logging.log4j.LogManager;
import com.mojang.blaze3d.platform.GLX;
import com.mojang.math.Matrix4f;
import java.nio.Buffer;
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 cus) {
this.name = string;
this.count = integer3;
this.type = integer2;
this.parent = cus;
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();
}
@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 cve) {
this.floatValues.position(0);
cve.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: {
GLX.glUniform1(this.location, this.intValues);
break;
}
case 1: {
GLX.glUniform2(this.location, this.intValues);
break;
}
case 2: {
GLX.glUniform3(this.location, this.intValues);
break;
}
case 3: {
GLX.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: {
GLX.glUniform1(this.location, this.floatValues);
break;
}
case 5: {
GLX.glUniform2(this.location, this.floatValues);
break;
}
case 6: {
GLX.glUniform3(this.location, this.floatValues);
break;
}
case 7: {
GLX.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: {
GLX.glUniformMatrix2(this.location, false, this.floatValues);
break;
}
case 9: {
GLX.glUniformMatrix3(this.location, false, this.floatValues);
break;
}
case 10: {
GLX.glUniformMatrix4(this.location, false, this.floatValues);
break;
}
}
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,546 @@
package com.mojang.blaze3d.vertex;
import org.apache.logging.log4j.LogManager;
import java.nio.ByteOrder;
import java.util.BitSet;
import java.util.Arrays;
import com.google.common.primitives.Floats;
import com.mojang.blaze3d.platform.MemoryTracker;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import org.apache.logging.log4j.Logger;
public class BufferBuilder {
private static final Logger LOGGER;
private ByteBuffer buffer;
private IntBuffer intBuffer;
private ShortBuffer shortBuffer;
private FloatBuffer floatBuffer;
private int vertices;
private VertexFormatElement currentElement;
private int elementIndex;
private boolean noColor;
private int mode;
private double xo;
private double yo;
private double zo;
private VertexFormat format;
private boolean building;
public BufferBuilder(final int integer) {
this.buffer = MemoryTracker.createByteBuffer(integer * 4);
this.intBuffer = this.buffer.asIntBuffer();
this.shortBuffer = this.buffer.asShortBuffer();
this.floatBuffer = this.buffer.asFloatBuffer();
}
private void ensureCapacity(final int integer) {
if (this.vertices * this.format.getVertexSize() + 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 int integer4 = this.intBuffer.position();
final ByteBuffer byteBuffer6 = MemoryTracker.createByteBuffer(integer3);
this.buffer.position(0);
byteBuffer6.put(this.buffer);
byteBuffer6.rewind();
this.buffer = byteBuffer6;
this.floatBuffer = this.buffer.asFloatBuffer().asReadOnlyBuffer();
(this.intBuffer = this.buffer.asIntBuffer()).position(integer4);
(this.shortBuffer = this.buffer.asShortBuffer()).position(integer4 << 1);
}
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) {
final int integer4 = this.vertices / 4;
final float[] arr6 = new float[integer4];
for (int integer5 = 0; integer5 < integer4; ++integer5) {
arr6[integer5] = getQuadDistanceFromPlayer(this.floatBuffer, (float)(float1 + this.xo), (float)(float2 + this.yo), (float)(float3 + this.zo), this.format.getIntegerSize(), integer5 * this.format.getVertexSize());
}
final Integer[] arr7 = new Integer[integer4];
for (int integer6 = 0; integer6 < arr7.length; ++integer6) {
arr7[integer6] = integer6;
}
final Object o;
Arrays.<Integer>sort(arr7, (integer2, integer3) -> Floats.compare(o[integer3], o[integer2]));
final BitSet bitSet8 = new BitSet();
final int integer7 = this.format.getVertexSize();
final int[] arr8 = new int[integer7];
for (int integer8 = bitSet8.nextClearBit(0); integer8 < arr7.length; integer8 = bitSet8.nextClearBit(integer8 + 1)) {
final int integer9 = arr7[integer8];
if (integer9 != integer8) {
this.intBuffer.limit(integer9 * integer7 + integer7);
this.intBuffer.position(integer9 * integer7);
this.intBuffer.get(arr8);
for (int integer10 = integer9, integer11 = arr7[integer10]; integer10 != integer8; integer10 = integer11, integer11 = arr7[integer10]) {
this.intBuffer.limit(integer11 * integer7 + integer7);
this.intBuffer.position(integer11 * integer7);
final IntBuffer intBuffer15 = this.intBuffer.slice();
this.intBuffer.limit(integer10 * integer7 + integer7);
this.intBuffer.position(integer10 * integer7);
this.intBuffer.put(intBuffer15);
bitSet8.set(integer10);
}
this.intBuffer.limit(integer8 * integer7 + integer7);
this.intBuffer.position(integer8 * integer7);
this.intBuffer.put(arr8);
}
bitSet8.set(integer8);
}
}
public State getState() {
this.intBuffer.rewind();
final int integer2 = this.getBufferIndex();
this.intBuffer.limit(integer2);
final int[] arr3 = new int[integer2];
this.intBuffer.get(arr3);
this.intBuffer.limit(this.intBuffer.capacity());
this.intBuffer.position(integer2);
return new State(arr3, new VertexFormat(this.format));
}
private int getBufferIndex() {
return this.vertices * this.format.getIntegerSize();
}
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 a) {
this.intBuffer.clear();
this.ensureCapacity(a.array().length * 4);
this.intBuffer.put(a.array());
this.vertices = a.vertices();
this.format = new VertexFormat(a.getFormat());
}
public void clear() {
this.vertices = 0;
this.currentElement = null;
this.elementIndex = 0;
}
public void begin(final int integer, final VertexFormat cvc) {
if (this.building) {
throw new IllegalStateException("Already building!");
}
this.building = true;
this.clear();
this.mode = integer;
this.format = cvc;
this.currentElement = cvc.getElement(this.elementIndex);
this.noColor = false;
this.buffer.limit(this.buffer.capacity());
}
public BufferBuilder uv(final double double1, final double double2) {
final int integer6 = this.vertices * this.format.getVertexSize() + this.format.getOffset(this.elementIndex);
switch (this.currentElement.getType()) {
case FLOAT: {
this.buffer.putFloat(integer6, (float)double1);
this.buffer.putFloat(integer6 + 4, (float)double2);
break;
}
case UINT:
case INT: {
this.buffer.putInt(integer6, (int)double1);
this.buffer.putInt(integer6 + 4, (int)double2);
break;
}
case USHORT:
case SHORT: {
this.buffer.putShort(integer6, (short)double2);
this.buffer.putShort(integer6 + 2, (short)double1);
break;
}
case UBYTE:
case BYTE: {
this.buffer.put(integer6, (byte)double2);
this.buffer.put(integer6 + 1, (byte)double1);
break;
}
}
this.nextElement();
return this;
}
public BufferBuilder uv2(final int integer1, final int integer2) {
final int integer3 = this.vertices * this.format.getVertexSize() + this.format.getOffset(this.elementIndex);
switch (this.currentElement.getType()) {
case FLOAT: {
this.buffer.putFloat(integer3, (float)integer1);
this.buffer.putFloat(integer3 + 4, (float)integer2);
break;
}
case UINT:
case INT: {
this.buffer.putInt(integer3, integer1);
this.buffer.putInt(integer3 + 4, integer2);
break;
}
case USHORT:
case SHORT: {
this.buffer.putShort(integer3, (short)integer2);
this.buffer.putShort(integer3 + 2, (short)integer1);
break;
}
case UBYTE:
case BYTE: {
this.buffer.put(integer3, (byte)integer2);
this.buffer.put(integer3 + 1, (byte)integer1);
break;
}
}
this.nextElement();
return this;
}
public void faceTex2(final int integer1, final int integer2, final int integer3, final int integer4) {
final int integer5 = (this.vertices - 4) * this.format.getIntegerSize() + this.format.getUvOffset(1) / 4;
final int integer6 = this.format.getVertexSize() >> 2;
this.intBuffer.put(integer5, integer1);
this.intBuffer.put(integer5 + integer6, integer2);
this.intBuffer.put(integer5 + integer6 * 2, integer3);
this.intBuffer.put(integer5 + integer6 * 3, integer4);
}
public void postProcessFacePosition(final double double1, final double double2, final double double3) {
final int integer8 = this.format.getIntegerSize();
final int integer9 = (this.vertices - 4) * integer8;
for (int integer10 = 0; integer10 < 4; ++integer10) {
final int integer11 = integer9 + integer10 * integer8;
final int integer12 = integer11 + 1;
final int integer13 = integer12 + 1;
this.intBuffer.put(integer11, Float.floatToRawIntBits((float)(double1 + this.xo) + Float.intBitsToFloat(this.intBuffer.get(integer11))));
this.intBuffer.put(integer12, Float.floatToRawIntBits((float)(double2 + this.yo) + Float.intBitsToFloat(this.intBuffer.get(integer12))));
this.intBuffer.put(integer13, Float.floatToRawIntBits((float)(double3 + this.zo) + Float.intBitsToFloat(this.intBuffer.get(integer13))));
}
}
private int getStartingColorIndex(final int integer) {
return ((this.vertices - integer) * this.format.getVertexSize() + this.format.getColorOffset()) / 4;
}
public void faceTint(final float float1, final float float2, final float float3, final int integer) {
final int integer2 = this.getStartingColorIndex(integer);
int integer3 = -1;
if (!this.noColor) {
integer3 = this.intBuffer.get(integer2);
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
final int integer4 = (int)((integer3 & 0xFF) * float1);
final int integer5 = (int)((integer3 >> 8 & 0xFF) * float2);
final int integer6 = (int)((integer3 >> 16 & 0xFF) * float3);
integer3 &= 0xFF000000;
integer3 |= (integer6 << 16 | integer5 << 8 | integer4);
}
else {
final int integer4 = (int)((integer3 >> 24 & 0xFF) * float1);
final int integer5 = (int)((integer3 >> 16 & 0xFF) * float2);
final int integer6 = (int)((integer3 >> 8 & 0xFF) * float3);
integer3 &= 0xFF;
integer3 |= (integer4 << 24 | integer5 << 16 | integer6 << 8);
}
}
this.intBuffer.put(integer2, integer3);
}
private void fixupVertexColor(final int integer1, final int integer2) {
final int integer3 = this.getStartingColorIndex(integer2);
final int integer4 = integer1 >> 16 & 0xFF;
final int integer5 = integer1 >> 8 & 0xFF;
final int integer6 = integer1 & 0xFF;
this.putColor(integer3, integer4, integer5, integer6);
}
public void fixupVertexColor(final float float1, final float float2, final float float3, final int integer) {
final int integer2 = this.getStartingColorIndex(integer);
final int integer3 = clamp((int)(float1 * 255.0f), 0, 255);
final int integer4 = clamp((int)(float2 * 255.0f), 0, 255);
final int integer5 = clamp((int)(float3 * 255.0f), 0, 255);
this.putColor(integer2, integer3, integer4, integer5);
}
private static int clamp(final int integer1, final int integer2, final int integer3) {
if (integer1 < integer2) {
return integer2;
}
if (integer1 > integer3) {
return integer3;
}
return integer1;
}
private void putColor(final int integer1, final int integer2, final int integer3, final int integer4) {
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
this.intBuffer.put(integer1, 0xFF000000 | integer4 << 16 | integer3 << 8 | integer2);
}
else {
this.intBuffer.put(integer1, integer2 << 24 | integer3 << 16 | integer4 << 8 | 0xFF);
}
}
public void noColor() {
this.noColor = true;
}
public BufferBuilder 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));
}
public BufferBuilder color(final int integer1, final int integer2, final int integer3, final int integer4) {
if (this.noColor) {
return this;
}
final int integer5 = this.vertices * this.format.getVertexSize() + this.format.getOffset(this.elementIndex);
switch (this.currentElement.getType()) {
case FLOAT: {
this.buffer.putFloat(integer5, integer1 / 255.0f);
this.buffer.putFloat(integer5 + 4, integer2 / 255.0f);
this.buffer.putFloat(integer5 + 8, integer3 / 255.0f);
this.buffer.putFloat(integer5 + 12, integer4 / 255.0f);
break;
}
case UINT:
case INT: {
this.buffer.putFloat(integer5, (float)integer1);
this.buffer.putFloat(integer5 + 4, (float)integer2);
this.buffer.putFloat(integer5 + 8, (float)integer3);
this.buffer.putFloat(integer5 + 12, (float)integer4);
break;
}
case USHORT:
case SHORT: {
this.buffer.putShort(integer5, (short)integer1);
this.buffer.putShort(integer5 + 2, (short)integer2);
this.buffer.putShort(integer5 + 4, (short)integer3);
this.buffer.putShort(integer5 + 6, (short)integer4);
break;
}
case UBYTE:
case BYTE: {
if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
this.buffer.put(integer5, (byte)integer1);
this.buffer.put(integer5 + 1, (byte)integer2);
this.buffer.put(integer5 + 2, (byte)integer3);
this.buffer.put(integer5 + 3, (byte)integer4);
break;
}
this.buffer.put(integer5, (byte)integer4);
this.buffer.put(integer5 + 1, (byte)integer3);
this.buffer.put(integer5 + 2, (byte)integer2);
this.buffer.put(integer5 + 3, (byte)integer1);
break;
}
}
this.nextElement();
return this;
}
public void putBulkData(final int[] arr) {
this.ensureCapacity(arr.length * 4 + this.format.getVertexSize());
this.intBuffer.position(this.getBufferIndex());
this.intBuffer.put(arr);
this.vertices += arr.length / this.format.getIntegerSize();
}
public void endVertex() {
++this.vertices;
this.ensureCapacity(this.format.getVertexSize());
}
public BufferBuilder vertex(final double double1, final double double2, final double double3) {
final int integer8 = this.vertices * this.format.getVertexSize() + this.format.getOffset(this.elementIndex);
switch (this.currentElement.getType()) {
case FLOAT: {
this.buffer.putFloat(integer8, (float)(double1 + this.xo));
this.buffer.putFloat(integer8 + 4, (float)(double2 + this.yo));
this.buffer.putFloat(integer8 + 8, (float)(double3 + this.zo));
break;
}
case UINT:
case INT: {
this.buffer.putInt(integer8, Float.floatToRawIntBits((float)(double1 + this.xo)));
this.buffer.putInt(integer8 + 4, Float.floatToRawIntBits((float)(double2 + this.yo)));
this.buffer.putInt(integer8 + 8, Float.floatToRawIntBits((float)(double3 + this.zo)));
break;
}
case USHORT:
case SHORT: {
this.buffer.putShort(integer8, (short)(double1 + this.xo));
this.buffer.putShort(integer8 + 2, (short)(double2 + this.yo));
this.buffer.putShort(integer8 + 4, (short)(double3 + this.zo));
break;
}
case UBYTE:
case BYTE: {
this.buffer.put(integer8, (byte)(double1 + this.xo));
this.buffer.put(integer8 + 1, (byte)(double2 + this.yo));
this.buffer.put(integer8 + 2, (byte)(double3 + this.zo));
break;
}
}
this.nextElement();
return this;
}
public void postNormal(final float float1, final float float2, final float float3) {
final int integer5 = (byte)(float1 * 127.0f) & 0xFF;
final int integer6 = (byte)(float2 * 127.0f) & 0xFF;
final int integer7 = (byte)(float3 * 127.0f) & 0xFF;
final int integer8 = integer5 | integer6 << 8 | integer7 << 16;
final int integer9 = this.format.getVertexSize() >> 2;
final int integer10 = (this.vertices - 4) * integer9 + this.format.getNormalOffset() / 4;
this.intBuffer.put(integer10, integer8);
this.intBuffer.put(integer10 + integer9, integer8);
this.intBuffer.put(integer10 + integer9 * 2, integer8);
this.intBuffer.put(integer10 + integer9 * 3, integer8);
}
private void nextElement() {
++this.elementIndex;
this.elementIndex %= this.format.getElementCount();
this.currentElement = this.format.getElement(this.elementIndex);
if (this.currentElement.getUsage() == VertexFormatElement.Usage.PADDING) {
this.nextElement();
}
}
public BufferBuilder normal(final float float1, final float float2, final float float3) {
final int integer5 = this.vertices * this.format.getVertexSize() + this.format.getOffset(this.elementIndex);
switch (this.currentElement.getType()) {
case FLOAT: {
this.buffer.putFloat(integer5, float1);
this.buffer.putFloat(integer5 + 4, float2);
this.buffer.putFloat(integer5 + 8, float3);
break;
}
case UINT:
case INT: {
this.buffer.putInt(integer5, (int)float1);
this.buffer.putInt(integer5 + 4, (int)float2);
this.buffer.putInt(integer5 + 8, (int)float3);
break;
}
case USHORT:
case SHORT: {
this.buffer.putShort(integer5, (short)((int)float1 * 32767 & 0xFFFF));
this.buffer.putShort(integer5 + 2, (short)((int)float2 * 32767 & 0xFFFF));
this.buffer.putShort(integer5 + 4, (short)((int)float3 * 32767 & 0xFFFF));
break;
}
case UBYTE:
case BYTE: {
this.buffer.put(integer5, (byte)((int)float1 * 127 & 0xFF));
this.buffer.put(integer5 + 1, (byte)((int)float2 * 127 & 0xFF));
this.buffer.put(integer5 + 2, (byte)((int)float3 * 127 & 0xFF));
break;
}
}
this.nextElement();
return this;
}
public void offset(final double double1, final double double2, final double double3) {
this.xo = double1;
this.yo = double2;
this.zo = double3;
}
public void end() {
if (!this.building) {
throw new IllegalStateException("Not building!");
}
this.building = false;
this.buffer.position(0);
this.buffer.limit(this.getBufferIndex() * 4);
}
public ByteBuffer getBuffer() {
return this.buffer;
}
public VertexFormat getVertexFormat() {
return this.format;
}
public int getVertexCount() {
return this.vertices;
}
public int getDrawMode() {
return this.mode;
}
public void fixupQuadColor(final int integer) {
for (int integer2 = 0; integer2 < 4; ++integer2) {
this.fixupVertexColor(integer, integer2 + 1);
}
}
public void fixupQuadColor(final float float1, final float float2, final float float3) {
for (int integer5 = 0; integer5 < 4; ++integer5) {
this.fixupVertexColor(float1, float2, float3, integer5 + 1);
}
}
static {
LOGGER = LogManager.getLogger();
}
public class State {
private final int[] array;
private final VertexFormat format;
public State(final int[] arr, final VertexFormat cvc) {
this.array = arr;
this.format = cvc;
}
public int[] array() {
return this.array;
}
public int vertices() {
return this.array.length / this.format.getIntegerSize();
}
public VertexFormat getFormat() {
return this.format;
}
}
}

View File

@ -0,0 +1,76 @@
package com.mojang.blaze3d.vertex;
import java.util.List;
import java.nio.ByteBuffer;
import com.mojang.blaze3d.platform.GLX;
import com.mojang.blaze3d.platform.GlStateManager;
public class BufferUploader {
public void end(final BufferBuilder cuw) {
if (cuw.getVertexCount() > 0) {
final VertexFormat cvc3 = cuw.getVertexFormat();
final int integer4 = cvc3.getVertexSize();
final ByteBuffer byteBuffer5 = cuw.getBuffer();
final List<VertexFormatElement> list6 = cvc3.getElements();
for (int integer5 = 0; integer5 < list6.size(); ++integer5) {
final VertexFormatElement cvd8 = list6.get(integer5);
final VertexFormatElement.Usage b9 = cvd8.getUsage();
final int integer6 = cvd8.getType().getGlType();
final int integer7 = cvd8.getIndex();
byteBuffer5.position(cvc3.getOffset(integer5));
switch (b9) {
case POSITION: {
GlStateManager.vertexPointer(cvd8.getCount(), integer6, integer4, byteBuffer5);
GlStateManager.enableClientState(32884);
break;
}
case UV: {
GLX.glClientActiveTexture(GLX.GL_TEXTURE0 + integer7);
GlStateManager.texCoordPointer(cvd8.getCount(), integer6, integer4, byteBuffer5);
GlStateManager.enableClientState(32888);
GLX.glClientActiveTexture(GLX.GL_TEXTURE0);
break;
}
case COLOR: {
GlStateManager.colorPointer(cvd8.getCount(), integer6, integer4, byteBuffer5);
GlStateManager.enableClientState(32886);
break;
}
case NORMAL: {
GlStateManager.normalPointer(integer6, integer4, byteBuffer5);
GlStateManager.enableClientState(32885);
break;
}
}
}
GlStateManager.drawArrays(cuw.getDrawMode(), 0, cuw.getVertexCount());
for (int integer5 = 0, integer8 = list6.size(); integer5 < integer8; ++integer5) {
final VertexFormatElement cvd9 = list6.get(integer5);
final VertexFormatElement.Usage b10 = cvd9.getUsage();
final int integer7 = cvd9.getIndex();
switch (b10) {
case POSITION: {
GlStateManager.disableClientState(32884);
break;
}
case UV: {
GLX.glClientActiveTexture(GLX.GL_TEXTURE0 + integer7);
GlStateManager.disableClientState(32888);
GLX.glClientActiveTexture(GLX.GL_TEXTURE0);
break;
}
case COLOR: {
GlStateManager.disableClientState(32886);
GlStateManager.clearCurrentColor();
break;
}
case NORMAL: {
GlStateManager.disableClientState(32885);
break;
}
}
}
}
cuw.clear();
}
}

View File

@ -0,0 +1,43 @@
package com.mojang.blaze3d.vertex;
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_NORMAL;
public static final VertexFormatElement ELEMENT_PADDING;
public static final VertexFormat BLOCK;
public static final VertexFormat BLOCK_NORMALS;
public static final VertexFormat ENTITY;
public static final VertexFormat PARTICLE;
public static final VertexFormat POSITION;
public static final VertexFormat POSITION_COLOR;
public static final VertexFormat POSITION_TEX;
public static final VertexFormat POSITION_NORMAL;
public static final VertexFormat POSITION_TEX_COLOR;
public static final VertexFormat POSITION_TEX_NORMAL;
public static final VertexFormat POSITION_TEX2_COLOR;
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_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().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_COLOR).addElement(DefaultVertexFormat.ELEMENT_UV0).addElement(DefaultVertexFormat.ELEMENT_UV1);
BLOCK_NORMALS = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_COLOR).addElement(DefaultVertexFormat.ELEMENT_UV0).addElement(DefaultVertexFormat.ELEMENT_NORMAL).addElement(DefaultVertexFormat.ELEMENT_PADDING);
ENTITY = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_UV0).addElement(DefaultVertexFormat.ELEMENT_NORMAL).addElement(DefaultVertexFormat.ELEMENT_PADDING);
PARTICLE = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_UV0).addElement(DefaultVertexFormat.ELEMENT_COLOR).addElement(DefaultVertexFormat.ELEMENT_UV1);
POSITION = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION);
POSITION_COLOR = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_COLOR);
POSITION_TEX = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_UV0);
POSITION_NORMAL = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_NORMAL).addElement(DefaultVertexFormat.ELEMENT_PADDING);
POSITION_TEX_COLOR = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_UV0).addElement(DefaultVertexFormat.ELEMENT_COLOR);
POSITION_TEX_NORMAL = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_UV0).addElement(DefaultVertexFormat.ELEMENT_NORMAL).addElement(DefaultVertexFormat.ELEMENT_PADDING);
POSITION_TEX2_COLOR = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_UV0).addElement(DefaultVertexFormat.ELEMENT_UV1).addElement(DefaultVertexFormat.ELEMENT_COLOR);
POSITION_TEX_COLOR_NORMAL = new VertexFormat().addElement(DefaultVertexFormat.ELEMENT_POSITION).addElement(DefaultVertexFormat.ELEMENT_UV0).addElement(DefaultVertexFormat.ELEMENT_COLOR).addElement(DefaultVertexFormat.ELEMENT_NORMAL).addElement(DefaultVertexFormat.ELEMENT_PADDING);
}
}

View File

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

View File

@ -0,0 +1,42 @@
package com.mojang.blaze3d.vertex;
import com.mojang.blaze3d.platform.GlStateManager;
import java.nio.ByteBuffer;
import com.mojang.blaze3d.platform.GLX;
public class VertexBuffer {
private int id;
private final VertexFormat format;
private int vertexCount;
public VertexBuffer(final VertexFormat cvc) {
this.format = cvc;
this.id = GLX.glGenBuffers();
}
public void bind() {
GLX.glBindBuffer(GLX.GL_ARRAY_BUFFER, this.id);
}
public void upload(final ByteBuffer byteBuffer) {
this.bind();
GLX.glBufferData(GLX.GL_ARRAY_BUFFER, byteBuffer, 35044);
unbind();
this.vertexCount = byteBuffer.limit() / this.format.getVertexSize();
}
public void draw(final int integer) {
GlStateManager.drawArrays(integer, 0, this.vertexCount);
}
public static void unbind() {
GLX.glBindBuffer(GLX.GL_ARRAY_BUFFER, 0);
}
public void delete() {
if (this.id >= 0) {
GLX.glDeleteBuffers(this.id);
this.id = -1;
}
}
}

View File

@ -0,0 +1,15 @@
package com.mojang.blaze3d.vertex;
public class VertexBufferUploader extends BufferUploader {
private VertexBuffer buffer;
@Override
public void end(final BufferBuilder cuw) {
cuw.clear();
this.buffer.upload(cuw.getBuffer());
}
public void setBuffer(final VertexBuffer cva) {
this.buffer = cva;
}
}

View File

@ -0,0 +1,160 @@
package com.mojang.blaze3d.vertex;
import org.apache.logging.log4j.LogManager;
import com.google.common.collect.Lists;
import java.util.List;
import org.apache.logging.log4j.Logger;
public class VertexFormat {
private static final Logger LOGGER;
private final List<VertexFormatElement> elements;
private final List<Integer> offsets;
private int vertexSize;
private int colorOffset;
private final List<Integer> texOffset;
private int normalOffset;
public VertexFormat(final VertexFormat cvc) {
this();
for (int integer3 = 0; integer3 < cvc.getElementCount(); ++integer3) {
this.addElement(cvc.getElement(integer3));
}
this.vertexSize = cvc.getVertexSize();
}
public VertexFormat() {
this.elements = Lists.newArrayList();
this.offsets = Lists.newArrayList();
this.colorOffset = -1;
this.texOffset = Lists.newArrayList();
this.normalOffset = -1;
}
public void clear() {
this.elements.clear();
this.offsets.clear();
this.colorOffset = -1;
this.texOffset.clear();
this.normalOffset = -1;
this.vertexSize = 0;
}
public VertexFormat addElement(final VertexFormatElement cvd) {
if (cvd.isPosition() && this.hasPositionElement()) {
VertexFormat.LOGGER.warn("VertexFormat error: Trying to add a position VertexFormatElement when one already exists, ignoring.");
return this;
}
this.elements.add(cvd);
this.offsets.add(this.vertexSize);
switch (cvd.getUsage()) {
case NORMAL: {
this.normalOffset = this.vertexSize;
break;
}
case COLOR: {
this.colorOffset = this.vertexSize;
break;
}
case UV: {
this.texOffset.add(cvd.getIndex(), this.vertexSize);
break;
}
}
this.vertexSize += cvd.getByteSize();
return this;
}
public boolean hasNormal() {
return this.normalOffset >= 0;
}
public int getNormalOffset() {
return this.normalOffset;
}
public boolean hasColor() {
return this.colorOffset >= 0;
}
public int getColorOffset() {
return this.colorOffset;
}
public boolean hasUv(final int integer) {
return this.texOffset.size() - 1 >= integer;
}
public int getUvOffset(final int integer) {
return this.texOffset.get(integer);
}
@Override
public String toString() {
String string2 = "format: " + this.elements.size() + " elements: ";
for (int integer3 = 0; integer3 < this.elements.size(); ++integer3) {
string2 += this.elements.get(integer3).toString();
if (integer3 != this.elements.size() - 1) {
string2 += " ";
}
}
return string2;
}
private boolean hasPositionElement() {
for (int integer2 = 0, integer3 = this.elements.size(); integer2 < integer3; ++integer2) {
final VertexFormatElement cvd4 = this.elements.get(integer2);
if (cvd4.isPosition()) {
return true;
}
}
return false;
}
public int getIntegerSize() {
return this.getVertexSize() / 4;
}
public int getVertexSize() {
return this.vertexSize;
}
public List<VertexFormatElement> getElements() {
return this.elements;
}
public int getElementCount() {
return this.elements.size();
}
public VertexFormatElement getElement(final int integer) {
return this.elements.get(integer);
}
public int getOffset(final int integer) {
return this.offsets.get(integer);
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final VertexFormat cvc3 = (VertexFormat)object;
return this.vertexSize == cvc3.vertexSize && this.elements.equals(cvc3.elements) && this.offsets.equals(cvc3.offsets);
}
@Override
public int hashCode() {
int integer2 = this.elements.hashCode();
integer2 = 31 * integer2 + this.offsets.hashCode();
integer2 = 31 * integer2 + this.vertexSize;
return integer2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,135 @@
package com.mojang.blaze3d.vertex;
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;
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;
}
private final 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 getCount() {
return this.count;
}
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.type.getSize() * this.count;
}
public final boolean isPosition() {
return this.usage == Usage.POSITION;
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final VertexFormatElement cvd3 = (VertexFormatElement)object;
return this.count == cvd3.count && this.index == cvd3.index && this.type == cvd3.type && this.usage == cvd3.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;
}
static {
LOGGER = LogManager.getLogger();
}
public enum Usage {
POSITION("Position"),
NORMAL("Normal"),
COLOR("Vertex Color"),
UV("UV"),
MATRIX("Bone Matrix"),
BLEND_WEIGHT("Blend Weight"),
PADDING("Padding");
private final String name;
private Usage(final String string3) {
this.name = string3;
}
public String getName() {
return this.name;
}
}
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,134 @@
package com.mojang.math;
import java.nio.FloatBuffer;
import java.util.Arrays;
public final class Matrix4f {
private final float[] values;
public Matrix4f() {
this.values = new float[16];
}
public Matrix4f(final Quaternion a) {
this();
final float float3 = a.i();
final float float4 = a.j();
final float float5 = a.k();
final float float6 = a.r();
final float float7 = 2.0f * float3 * float3;
final float float8 = 2.0f * float4 * float4;
final float float9 = 2.0f * float5 * float5;
this.values[0] = 1.0f - float8 - float9;
this.values[5] = 1.0f - float9 - float7;
this.values[10] = 1.0f - float7 - float8;
this.values[15] = 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.values[1] = 2.0f * (float10 + float15);
this.values[4] = 2.0f * (float10 - float15);
this.values[2] = 2.0f * (float12 - float14);
this.values[8] = 2.0f * (float12 + float14);
this.values[6] = 2.0f * (float11 + float13);
this.values[9] = 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 cve3 = (Matrix4f)object;
return Arrays.equals(this.values, cve3.values);
}
@Override
public int hashCode() {
return Arrays.hashCode(this.values);
}
public void load(final FloatBuffer floatBuffer) {
this.load(floatBuffer, false);
}
public void load(final FloatBuffer floatBuffer, final boolean boolean2) {
if (boolean2) {
for (int integer4 = 0; integer4 < 4; ++integer4) {
for (int integer5 = 0; integer5 < 4; ++integer5) {
this.values[integer4 * 4 + integer5] = floatBuffer.get(integer5 * 4 + integer4);
}
}
}
else {
floatBuffer.get(this.values);
}
}
@Override
public String toString() {
final StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.append("Matrix4f:\n");
for (int integer3 = 0; integer3 < 4; ++integer3) {
for (int integer4 = 0; integer4 < 4; ++integer4) {
stringBuilder2.append(this.values[integer3 + integer4 * 4]);
if (integer4 != 3) {
stringBuilder2.append(" ");
}
}
stringBuilder2.append("\n");
}
return stringBuilder2.toString();
}
public void store(final FloatBuffer floatBuffer) {
this.store(floatBuffer, false);
}
public void store(final FloatBuffer floatBuffer, final boolean boolean2) {
if (boolean2) {
for (int integer4 = 0; integer4 < 4; ++integer4) {
for (int integer5 = 0; integer5 < 4; ++integer5) {
floatBuffer.put(integer5 * 4 + integer4, this.values[integer4 * 4 + integer5]);
}
}
}
else {
floatBuffer.put(this.values);
}
}
public void set(final int integer1, final int integer2, final float float3) {
this.values[integer1 + 4 * integer2] = float3;
}
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 cve7 = new Matrix4f();
cve7.set(0, 0, float5 / float2);
cve7.set(1, 1, float5);
cve7.set(2, 2, (float4 + float3) / (float3 - float4));
cve7.set(3, 2, -1.0f);
cve7.set(2, 3, 2.0f * float4 * float3 / (float3 - float4));
return cve7;
}
public static Matrix4f orthographic(final float float1, final float float2, final float float3, final float float4) {
final Matrix4f cve5 = new Matrix4f();
cve5.set(0, 0, 2.0f / float1);
cve5.set(1, 1, 2.0f / float2);
final float float5 = float4 - float3;
cve5.set(2, 2, -2.0f / float5);
cve5.set(3, 3, 1.0f);
cve5.set(0, 3, -1.0f);
cve5.set(1, 3, -1.0f);
cve5.set(2, 3, -(float4 + float3) / float5);
return cve5;
}
}

View File

@ -0,0 +1,123 @@
package com.mojang.math;
import java.util.Arrays;
public final class Quaternion {
private final float[] values;
public Quaternion() {
(this.values = new float[4])[4] = 1.0f;
}
public Quaternion(final float float1, final float float2, final float float3, final float float4) {
(this.values = new float[4])[0] = float1;
this.values[1] = float2;
this.values[2] = float3;
this.values[3] = float4;
}
public Quaternion(final Vector3f b, float float2, final boolean boolean3) {
if (boolean3) {
float2 *= 0.017453292f;
}
final float float3 = sin(float2 / 2.0f);
(this.values = new float[4])[0] = b.x() * float3;
this.values[1] = b.y() * float3;
this.values[2] = b.z() * float3;
this.values[3] = 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.values = new float[4])[0] = float4 * float7 * float9 + float5 * float6 * float8;
this.values[1] = float5 * float6 * float9 - float4 * float7 * float8;
this.values[2] = float4 * float6 * float9 + float5 * float7 * float8;
this.values[3] = float5 * float7 * float9 - float4 * float6 * float8;
}
public Quaternion(final Quaternion a) {
this.values = Arrays.copyOf(a.values, 4);
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Quaternion a3 = (Quaternion)object;
return Arrays.equals(this.values, a3.values);
}
@Override
public int hashCode() {
return Arrays.hashCode(this.values);
}
@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.values[0];
}
public float j() {
return this.values[1];
}
public float k() {
return this.values[2];
}
public float r() {
return this.values[3];
}
public void mul(final Quaternion a) {
final float float3 = this.i();
final float float4 = this.j();
final float float5 = this.k();
final float float6 = this.r();
final float float7 = a.i();
final float float8 = a.j();
final float float9 = a.k();
final float float10 = a.r();
this.values[0] = float6 * float7 + float3 * float10 + float4 * float9 - float5 * float8;
this.values[1] = float6 * float8 - float3 * float9 + float4 * float10 + float5 * float7;
this.values[2] = float6 * float9 + float3 * float8 - float4 * float7 + float5 * float10;
this.values[3] = float6 * float10 - float3 * float7 - float4 * float8 - float5 * float9;
}
public void conj() {
this.values[0] = -this.values[0];
this.values[1] = -this.values[1];
this.values[2] = -this.values[2];
}
private static float cos(final float float1) {
return (float)Math.cos(float1);
}
private static float sin(final float float1) {
return (float)Math.sin(float1);
}
}

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,144 @@
package com.mojang.math;
import net.minecraft.world.phys.Vec3;
import java.util.Arrays;
public final class Vector3f {
private final float[] values;
public Vector3f(final Vector3f b) {
this.values = Arrays.copyOf(b.values, 3);
}
public Vector3f() {
this.values = new float[3];
}
public Vector3f(final float float1, final float float2, final float float3) {
this.values = new float[] { float1, float2, float3 };
}
public Vector3f(final Vec3 csi) {
this.values = new float[] { (float)csi.x, (float)csi.y, (float)csi.z };
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Vector3f b3 = (Vector3f)object;
return Arrays.equals(this.values, b3.values);
}
@Override
public int hashCode() {
return Arrays.hashCode(this.values);
}
public float x() {
return this.values[0];
}
public float y() {
return this.values[1];
}
public float z() {
return this.values[2];
}
public void mul(final float float1) {
for (int integer3 = 0; integer3 < 3; ++integer3) {
final float[] values = this.values;
final int n = integer3;
values[n] *= float1;
}
}
private static float clamp(final float float1, final float float2, final float float3) {
if (float1 < float2) {
return float2;
}
if (float1 > float3) {
return float3;
}
return float1;
}
public void clamp(final float float1, final float float2) {
this.values[0] = clamp(this.values[0], float1, float2);
this.values[1] = clamp(this.values[1], float1, float2);
this.values[2] = clamp(this.values[2], float1, float2);
}
public void set(final float float1, final float float2, final float float3) {
this.values[0] = float1;
this.values[1] = float2;
this.values[2] = float3;
}
public void add(final float float1, final float float2, final float float3) {
final float[] values = this.values;
final int n = 0;
values[n] += float1;
final float[] values2 = this.values;
final int n2 = 1;
values2[n2] += float2;
final float[] values3 = this.values;
final int n3 = 2;
values3[n3] += float3;
}
public void sub(final Vector3f b) {
for (int integer3 = 0; integer3 < 3; ++integer3) {
final float[] values = this.values;
final int n = integer3;
values[n] -= b.values[integer3];
}
}
public float dot(final Vector3f b) {
float float3 = 0.0f;
for (int integer4 = 0; integer4 < 3; ++integer4) {
float3 += this.values[integer4] * b.values[integer4];
}
return float3;
}
public void normalize() {
float float2 = 0.0f;
for (int integer3 = 0; integer3 < 3; ++integer3) {
float2 += this.values[integer3] * this.values[integer3];
}
for (int integer3 = 0; integer3 < 3; ++integer3) {
final float[] values = this.values;
final int n = integer3;
values[n] /= float2;
}
}
public void cross(final Vector3f b) {
final float float3 = this.values[0];
final float float4 = this.values[1];
final float float5 = this.values[2];
final float float6 = b.x();
final float float7 = b.y();
final float float8 = b.z();
this.values[0] = float4 * float8 - float5 * float7;
this.values[1] = float5 * float6 - float3 * float8;
this.values[2] = float3 * float7 - float4 * float6;
}
public void transform(final Quaternion a) {
final Quaternion a2 = new Quaternion(a);
a2.mul(new Quaternion(this.x(), this.y(), this.z(), 0.0f));
final Quaternion a3 = new Quaternion(a);
a3.conj();
a2.mul(a3);
this.set(a2.i(), a2.j(), a2.k());
}
}

View File

@ -0,0 +1,76 @@
package com.mojang.math;
import java.util.Arrays;
public class Vector4f {
private final float[] values;
public Vector4f() {
this.values = new float[4];
}
public Vector4f(final float float1, final float float2, final float float3, final float float4) {
this.values = new float[] { float1, float2, float3, float4 };
}
@Override
public boolean equals(final Object object) {
if (this == object) {
return true;
}
if (object == null || this.getClass() != object.getClass()) {
return false;
}
final Vector4f cvg3 = (Vector4f)object;
return Arrays.equals(this.values, cvg3.values);
}
@Override
public int hashCode() {
return Arrays.hashCode(this.values);
}
public float x() {
return this.values[0];
}
public float y() {
return this.values[1];
}
public float z() {
return this.values[2];
}
public float w() {
return this.values[3];
}
public void mul(final Vector3f b) {
final float[] values = this.values;
final int n = 0;
values[n] *= b.x();
final float[] values2 = this.values;
final int n2 = 1;
values2[n2] *= b.y();
final float[] values3 = this.values;
final int n3 = 2;
values3[n3] *= b.z();
}
public void set(final float float1, final float float2, final float float3, final float float4) {
this.values[0] = float1;
this.values[1] = float2;
this.values[2] = float3;
this.values[3] = float4;
}
public void transform(final Quaternion a) {
final Quaternion a2 = new Quaternion(a);
a2.mul(new Quaternion(this.x(), this.y(), this.z(), 0.0f));
final Quaternion a3 = new Quaternion(a);
a3.conj();
a2.mul(a3);
this.set(a2.i(), a2.j(), a2.k(), this.w());
}
}

View File

@ -0,0 +1,41 @@
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;
this.matchIndex = 0;
}
public boolean keyPressed(final char character) {
if (character != this.chars[this.matchIndex]) {
this.reset();
return false;
}
++this.matchIndex;
if (this.matchIndex == this.chars.length) {
this.reset();
this.onCompletion.run();
return true;
}
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,426 @@
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 org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import java.util.regex.Matcher;
import java.util.Iterator;
import java.io.BufferedOutputStream;
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.realms.Realms;
import java.util.Locale;
import net.minecraft.realms.RealmsLevelSummary;
import org.apache.commons.lang3.StringUtils;
import net.minecraft.realms.RealmsSharedConstants;
import java.util.regex.Pattern;
import com.mojang.realmsclient.exception.RealmsDefaultUncaughtExceptionHandler;
import org.apache.http.HttpResponse;
import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import net.minecraft.realms.RealmsAnvilLevelStorageSource;
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 worldDownload, final String string, final RealmsDownloadLatestWorldScreen.DownloadStatus a, final RealmsAnvilLevelStorageSource realmsAnvilLevelStorageSource) {
if (this.currentThread != null) {
return;
}
(this.currentThread = new Thread() {
@Override
public void run() {
CloseableHttpClient closeableHttpClient2 = null;
try {
FileDownload.this.tempFile = File.createTempFile("backup", ".tar.gz");
FileDownload.this.request = new HttpGet(worldDownload.downloadLink);
closeableHttpClient2 = HttpClientBuilder.create().setDefaultRequestConfig(FileDownload.this.requestConfig).build();
final HttpResponse httpResponse3 = (HttpResponse)closeableHttpClient2.execute((HttpUriRequest)FileDownload.this.request);
a.totalBytes = Long.parseLong(httpResponse3.getFirstHeader("Content-Length").getValue());
if (httpResponse3.getStatusLine().getStatusCode() != 200) {
FileDownload.this.error = true;
FileDownload.this.request.abort();
return;
}
final OutputStream outputStream4 = new FileOutputStream(FileDownload.this.tempFile);
final ProgressListener b5 = new ProgressListener(string.trim(), FileDownload.this.tempFile, realmsAnvilLevelStorageSource, a, worldDownload);
final DownloadCountingOutputStream a6 = new DownloadCountingOutputStream(outputStream4);
a6.setListener(b5);
IOUtils.copy(httpResponse3.getEntity().getContent(), (OutputStream)a6);
}
catch (Exception exception3) {
FileDownload.LOGGER.error("Caught exception while downloading: " + exception3.getMessage());
FileDownload.this.error = true;
FileDownload.this.request.releaseConnection();
if (FileDownload.this.tempFile != null) {
FileDownload.this.tempFile.delete();
}
if (!FileDownload.this.error) {
if (!worldDownload.resourcePackUrl.isEmpty() && !worldDownload.resourcePackHash.isEmpty()) {
try {
FileDownload.this.tempFile = File.createTempFile("resources", ".tar.gz");
FileDownload.this.request = new HttpGet(worldDownload.resourcePackUrl);
final HttpResponse httpResponse3 = (HttpResponse)closeableHttpClient2.execute((HttpUriRequest)FileDownload.this.request);
a.totalBytes = Long.parseLong(httpResponse3.getFirstHeader("Content-Length").getValue());
if (httpResponse3.getStatusLine().getStatusCode() != 200) {
FileDownload.this.error = true;
FileDownload.this.request.abort();
return;
}
final OutputStream outputStream4 = new FileOutputStream(FileDownload.this.tempFile);
final ResourcePackProgressListener c5 = new ResourcePackProgressListener(FileDownload.this.tempFile, a, worldDownload);
final DownloadCountingOutputStream a6 = new DownloadCountingOutputStream(outputStream4);
a6.setListener(c5);
IOUtils.copy(httpResponse3.getEntity().getContent(), (OutputStream)a6);
}
catch (Exception exception3) {
FileDownload.LOGGER.error("Caught exception while downloading: " + exception3.getMessage());
FileDownload.this.error = true;
}
finally {
FileDownload.this.request.releaseConnection();
if (FileDownload.this.tempFile != null) {
FileDownload.this.tempFile.delete();
}
}
}
else {
FileDownload.this.finished = true;
}
}
if (closeableHttpClient2 != null) {
try {
closeableHttpClient2.close();
}
catch (IOException iOException3) {
FileDownload.LOGGER.error("Failed to close Realms download client");
}
}
}
finally {
FileDownload.this.request.releaseConnection();
if (FileDownload.this.tempFile != null) {
FileDownload.this.tempFile.delete();
}
if (!FileDownload.this.error) {
if (!worldDownload.resourcePackUrl.isEmpty() && !worldDownload.resourcePackHash.isEmpty()) {
try {
FileDownload.this.tempFile = File.createTempFile("resources", ".tar.gz");
FileDownload.this.request = new HttpGet(worldDownload.resourcePackUrl);
final HttpResponse httpResponse4 = (HttpResponse)closeableHttpClient2.execute((HttpUriRequest)FileDownload.this.request);
a.totalBytes = Long.parseLong(httpResponse4.getFirstHeader("Content-Length").getValue());
if (httpResponse4.getStatusLine().getStatusCode() != 200) {
FileDownload.this.error = true;
FileDownload.this.request.abort();
return;
}
final OutputStream outputStream5 = new FileOutputStream(FileDownload.this.tempFile);
final ResourcePackProgressListener c6 = new ResourcePackProgressListener(FileDownload.this.tempFile, a, worldDownload);
final DownloadCountingOutputStream a7 = new DownloadCountingOutputStream(outputStream5);
a7.setListener(c6);
IOUtils.copy(httpResponse4.getEntity().getContent(), (OutputStream)a7);
}
catch (Exception exception4) {
FileDownload.LOGGER.error("Caught exception while downloading: " + exception4.getMessage());
FileDownload.this.error = true;
FileDownload.this.request.releaseConnection();
if (FileDownload.this.tempFile != null) {
FileDownload.this.tempFile.delete();
}
}
finally {
FileDownload.this.request.releaseConnection();
if (FileDownload.this.tempFile != null) {
FileDownload.this.tempFile.delete();
}
}
}
else {
FileDownload.this.finished = true;
}
}
if (closeableHttpClient2 != null) {
try {
closeableHttpClient2.close();
}
catch (IOException iOException4) {
FileDownload.LOGGER.error("Failed to close Realms download client");
}
}
}
}
}).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 RealmsAnvilLevelStorageSource realmsAnvilLevelStorageSource) throws IOException {
final Pattern pattern5 = Pattern.compile(".*-([0-9]+)$");
int integer7 = 1;
for (final char character11 : RealmsSharedConstants.ILLEGAL_FILE_CHARACTERS) {
string = string.replace(character11, '_');
}
if (StringUtils.isEmpty((CharSequence)string)) {
string = "Realm";
}
string = findAvailableFolderName(string);
try {
for (final RealmsLevelSummary realmsLevelSummary9 : realmsAnvilLevelStorageSource.getLevelList()) {
if (realmsLevelSummary9.getLevelId().toLowerCase(Locale.ROOT).startsWith(string.toLowerCase(Locale.ROOT))) {
final Matcher matcher10 = pattern5.matcher(realmsLevelSummary9.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 (!realmsAnvilLevelStorageSource.isNewLevelIdAcceptable(string) || integer7 > 1) {
string2 = string + ((integer7 == 1) ? "" : ("-" + integer7));
if (!realmsAnvilLevelStorageSource.isNewLevelIdAcceptable(string2)) {
for (boolean boolean8 = false; !boolean8; boolean8 = true) {
++integer7;
string2 = string + ((integer7 == 1) ? "" : ("-" + integer7));
if (realmsAnvilLevelStorageSource.isNewLevelIdAcceptable(string2)) {}
}
}
}
else {
string2 = string;
}
TarArchiveInputStream tarArchiveInputStream8 = null;
final File file2 = new File(Realms.getGameDirectoryPath(), "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();
byte[] arr12 = new byte[1024];
final BufferedOutputStream bufferedOutputStream13 = new BufferedOutputStream(new FileOutputStream(file3));
int integer8 = 0;
while ((integer8 = tarArchiveInputStream8.read(arr12)) != -1) {
bufferedOutputStream13.write(arr12, 0, integer8);
}
bufferedOutputStream13.close();
arr12 = null;
}
}
}
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();
}
final RealmsAnvilLevelStorageSource realmsAnvilLevelStorageSource2 = realmsAnvilLevelStorageSource;
realmsAnvilLevelStorageSource2.renameLevel(string2, string2.trim());
final File file4 = new File(file2, string2 + File.separator + "level.dat");
Realms.deletePlayerTag(file4);
this.resourcePackPath = new File(file2, string2 + File.separator + "resources.zip");
}
}
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 RealmsAnvilLevelStorageSource levelStorageSource;
private final RealmsDownloadLatestWorldScreen.DownloadStatus downloadStatus;
private final WorldDownload worldDownload;
private ProgressListener(final String string, final File file, final RealmsAnvilLevelStorageSource realmsAnvilLevelStorageSource, final RealmsDownloadLatestWorldScreen.DownloadStatus a, final WorldDownload worldDownload) {
this.worldName = string;
this.tempFile = file;
this.levelStorageSource = realmsAnvilLevelStorageSource;
this.downloadStatus = a;
this.worldDownload = worldDownload;
}
@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 worldDownload) {
this.tempFile = file;
this.downloadStatus = a;
this.worldDownload = worldDownload;
}
@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,209 @@
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 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 AtomicBoolean cancelled;
private CompletableFuture<UploadResult> uploadTask;
private final RequestConfig requestConfig;
public FileUpload(final File file, final long long2, final int integer, final UploadInfo uploadInfo, final String string5, final String string6, final String string7, final UploadStatus cvq) {
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 = uploadInfo;
this.sessionId = string5;
this.username = string6;
this.clientVersion = string7;
this.uploadStatus = cvq;
}
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 cvq) {
super(inputStream);
this.content = inputStream;
this.length = long2;
this.uploadStatus = cvq;
}
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,87 @@
package com.mojang.realmsclient.client;
import java.net.SocketAddress;
import java.net.Socket;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.Comparator;
import java.util.ArrayList;
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 = new ArrayList<RegionPingResult>();
for (final Region a6 : arr) {
list2.add(new RegionPingResult(a6.name, ping(a6.endpoint)));
}
Collections.<RegionPingResult>sort(list2, new Comparator<RegionPingResult>() {
@Override
public int compare(final RegionPingResult regionPingResult1, final RegionPingResult regionPingResult2) {
return regionPingResult1.ping() - regionPingResult2.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 System.currentTimeMillis();
}
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,391 @@
package com.mojang.realmsclient.client;
import org.apache.logging.log4j.LogManager;
import com.mojang.realmsclient.exception.RealmsHttpException;
import com.mojang.realmsclient.exception.RetryCallException;
import java.net.URISyntaxException;
import java.net.URI;
import com.mojang.realmsclient.dto.PingResult;
import com.mojang.realmsclient.dto.RealmsNews;
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 java.io.UnsupportedEncodingException;
import com.mojang.realmsclient.dto.BackupList;
import com.mojang.realmsclient.dto.PlayerInfo;
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 java.io.IOException;
import com.mojang.realmsclient.exception.RealmsServiceException;
import com.mojang.realmsclient.dto.RealmsServerList;
import java.net.Proxy;
import net.minecraft.realms.Realms;
import com.google.gson.Gson;
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 Gson gson;
public static RealmsClient createRealmsClient() {
final String string1 = Realms.userName();
final String string2 = Realms.sessionId();
if (string1 == null || string2 == null) {
return null;
}
if (!RealmsClient.initialized) {
RealmsClient.initialized = true;
String string3 = System.getenv("realms.environment");
if (string3 == null) {
string3 = System.getProperty("realms.environment");
}
if (string3 != null) {
if ("LOCAL".equals(string3)) {
switchToLocal();
}
else if ("STAGE".equals(string3)) {
switchToStage();
}
}
}
return new RealmsClient(string2, string1, Realms.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, IOException {
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, IOException {
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, IOException {
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, IOException {
final RealmsDescriptionDto realmsDescriptionDto6 = 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(realmsDescriptionDto6);
this.execute(Request.post(string4, string5, 5000, 10000));
}
public Boolean mcoEnabled() throws RealmsServiceException, IOException {
final String string2 = this.url("mco/available");
final String string3 = this.execute(Request.get(string2));
return Boolean.valueOf(string3);
}
public Boolean stageAvailable() throws RealmsServiceException, IOException {
final String string2 = this.url("mco/stageAvailable");
final String string3 = this.execute(Request.get(string2));
return Boolean.valueOf(string3);
}
public CompatibleVersionResponse clientCompatible() throws RealmsServiceException, IOException {
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, IOException {
final PlayerInfo playerInfo5 = new PlayerInfo();
playerInfo5.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(playerInfo5)));
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, UnsupportedEncodingException {
final RealmsDescriptionDto realmsDescriptionDto6 = 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(realmsDescriptionDto6)));
}
public void updateSlot(final long long1, final int integer, final RealmsWorldOptions realmsWorldOptions) throws RealmsServiceException, UnsupportedEncodingException {
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 = realmsWorldOptions.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, IOException {
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, IOException {
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, IOException {
final RealmsWorldResetDto realmsWorldResetDto7 = 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(realmsWorldResetDto7), 30000, 80000));
return Boolean.valueOf(string3);
}
public Boolean resetWorldWithTemplate(final long long1, final String string) throws RealmsServiceException, IOException {
final RealmsWorldResetDto realmsWorldResetDto5 = 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(realmsWorldResetDto5), 30000, 80000));
return Boolean.valueOf(string3);
}
public Subscription subscriptionFor(final long long1) throws RealmsServiceException, IOException {
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 uploadInfo6 = new UploadInfo();
if (string != null) {
uploadInfo6.setToken(string);
}
final GsonBuilder gsonBuilder7 = new GsonBuilder();
gsonBuilder7.excludeFieldsWithoutExposeAnnotation();
final Gson gson8 = gsonBuilder7.create();
final String string3 = gson8.toJson(uploadInfo6);
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, IOException {
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 pingResult) throws RealmsServiceException {
final String string3 = this.url("regions/ping/stat");
this.execute(Request.post(string3, RealmsClient.gson.toJson(pingResult)));
}
public Boolean trialAvailable() throws RealmsServiceException, IOException {
final String string2 = this.url("trial");
final String string3 = this.execute(Request.get(string2));
return Boolean.valueOf(string3);
}
public RealmsServer createTrial(final String string1, final String string2) throws RealmsServiceException, IOException {
final RealmsDescriptionDto realmsDescriptionDto4 = new RealmsDescriptionDto(string1, string2);
final String string3 = RealmsClient.gson.toJson(realmsDescriptionDto4);
final String string4 = this.url("trial");
final String string5 = this.execute(Request.post(string4, string3, 5000, 10000));
return RealmsServer.parse(string5);
}
public void deleteWorld(final long long1) throws RealmsServiceException, IOException {
final String string4 = this.url("worlds" + "/$WORLD_ID".replace("$WORLD_ID", String.valueOf(long1)));
this.execute(Request.delete(string4));
}
private String url(final String string) {
return this.url(string, null);
}
private String url(final String string1, final String string2) {
try {
final URI uRI4 = new URI(RealmsClient.currentEnvironment.protocol, RealmsClient.currentEnvironment.baseUrl, "/" + string1, string2, null);
return uRI4.toASCIIString();
}
catch (URISyntaxException uRISyntaxException4) {
uRISyntaxException4.printStackTrace();
return null;
}
}
private String execute(final Request<?> cvp) throws RealmsServiceException {
cvp.cookie("sid", this.sessionId);
cvp.cookie("user", this.username);
cvp.cookie("version", Realms.getMinecraftVersionString());
try {
final int integer3 = cvp.responseCode();
if (integer3 == 503) {
final int integer4 = cvp.getRetryAfterHeader();
throw new RetryCallException(integer4);
}
final String string4 = cvp.text();
if (integer3 >= 200 && integer3 < 300) {
return string4;
}
if (integer3 == 401) {
final String string5 = cvp.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 cvo5 = new RealmsError(string4);
RealmsClient.LOGGER.error("Realms http code: " + integer3 + " - error code: " + cvo5.getErrorCode() + " - message: " + cvo5.getErrorMessage() + " - raw body: " + string4);
throw new RealmsServiceException(integer3, string4, cvo5);
}
catch (RealmsHttpException cvt3) {
throw new RealmsServiceException(500, "Could not connect to Realms: " + cvt3.getMessage(), -1, "");
}
}
static {
RealmsClient.currentEnvironment = Environment.PRODUCTION;
LOGGER = LogManager.getLogger();
gson = new Gson();
}
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,38 @@
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 String errorMessage;
private int errorCode;
public RealmsError(final String string) {
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
this.errorMessage = JsonUtils.getStringOr("errorMsg", jsonObject4, "");
this.errorCode = JsonUtils.getIntOr("errorCode", jsonObject4, -1);
}
catch (Exception exception3) {
RealmsError.LOGGER.error("Could not parse RealmsError: " + exception3.getMessage());
RealmsError.LOGGER.error("The error was: " + string);
}
}
public String getErrorMessage() {
return this.errorMessage;
}
public int getErrorCode() {
return this.errorCode;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,282 @@
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 {
int integer3 = 0;
final InputStream inputStream4 = this.connection.getInputStream();
while ((integer3 = inputStream4.read(arr2)) > 0) {}
inputStream4.close();
}
catch (Exception exception3) {
try {
final InputStream inputStream4 = this.connection.getErrorStream();
int integer4 = 0;
if (inputStream4 == null) {
return;
}
while ((integer4 = 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 cvp2 = this.doConnect();
this.connected = true;
return cvp2;
}
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 java.util.HashMap;
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 = new HashMap<String, String>();
this.changeList = new HashMap<String, String>();
}
public static Backup parse(final JsonElement jsonElement) {
final JsonObject jsonObject2 = jsonElement.getAsJsonObject();
final Backup backup3 = new Backup();
try {
backup3.backupId = JsonUtils.getStringOr("backupId", jsonObject2, "");
backup3.lastModifiedDate = JsonUtils.getDateOr("lastModifiedDate", jsonObject2);
backup3.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()) {
backup3.metadata.put(format(entry7.getKey()), entry7.getValue().getAsString());
}
}
}
}
catch (Exception exception4) {
Backup.LOGGER.error("Could not parse Backup: " + exception4.getMessage());
}
return backup3;
}
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, string2.length())).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 java.util.ArrayList;
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 backupList3 = new BackupList();
backupList3.backups = new ArrayList<Backup>();
try {
final JsonElement jsonElement4 = jsonParser2.parse(string).getAsJsonObject().get("backups");
if (jsonElement4.isJsonArray()) {
final Iterator<JsonElement> iterator5 = jsonElement4.getAsJsonArray().iterator();
while (iterator5.hasNext()) {
backupList3.backups.add(Backup.parse(iterator5.next()));
}
}
}
catch (Exception exception4) {
BackupList.LOGGER.error("Could not parse BackupList: " + exception4.getMessage());
}
return backupList3;
}
static {
LOGGER = LogManager.getLogger();
}
}

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 java.util.HashSet;
import java.util.Set;
public class Ops extends ValueObject {
public Set<String> ops;
public Ops() {
this.ops = new HashSet<String>();
}
public static Ops parse(final String string) {
final Ops ops2 = 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()) {
ops2.ops.add(jsonElement6.getAsString());
}
}
}
catch (Exception ex) {}
return ops2;
}
}

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 pendingInvite2 = new PendingInvite();
try {
pendingInvite2.invitationId = JsonUtils.getStringOr("invitationId", jsonObject, "");
pendingInvite2.worldName = JsonUtils.getStringOr("worldName", jsonObject, "");
pendingInvite2.worldOwnerName = JsonUtils.getStringOr("worldOwnerName", jsonObject, "");
pendingInvite2.worldOwnerUuid = JsonUtils.getStringOr("worldOwnerUuid", jsonObject, "");
pendingInvite2.date = JsonUtils.getDateOr("date", jsonObject);
}
catch (Exception exception3) {
PendingInvite.LOGGER.error("Could not parse PendingInvite: " + exception3.getMessage());
}
return pendingInvite2;
}
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 pendingInvitesList2 = 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()) {
pendingInvitesList2.pendingInvites.add(PendingInvite.parse(iterator5.next().getAsJsonObject()));
}
}
}
catch (Exception exception3) {
PendingInvitesList.LOGGER.error("Could not parse PendingInvitesList: " + exception3.getMessage());
}
return pendingInvitesList2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,14 @@
package com.mojang.realmsclient.dto;
import java.util.ArrayList;
import java.util.List;
public class PingResult extends ValueObject {
public List<RegionPingResult> pingResults;
public List<Long> worldIds;
public PingResult() {
this.pingResults = new ArrayList<RegionPingResult>();
this.worldIds = new ArrayList<Long>();
}
}

View File

@ -0,0 +1,55 @@
package com.mojang.realmsclient.dto;
public class PlayerInfo extends ValueObject {
private String name;
private String uuid;
private boolean operator;
private boolean accepted;
private boolean online;
public PlayerInfo() {
this.operator = false;
this.accepted = false;
this.online = false;
}
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,11 @@
package com.mojang.realmsclient.dto;
public class RealmsDescriptionDto extends ValueObject {
public String name;
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 realmsNews2 = new RealmsNews();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
realmsNews2.newsLink = JsonUtils.getStringOr("newsLink", jsonObject4, null);
}
catch (Exception exception3) {
RealmsNews.LOGGER.error("Could not parse RealmsNews: " + exception3.getMessage());
}
return realmsNews2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,308 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.google.gson.JsonParser;
import java.util.HashMap;
import com.google.gson.JsonElement;
import com.google.gson.JsonArray;
import java.util.Collections;
import java.util.Locale;
import com.google.common.collect.ComparisonChain;
import java.util.Comparator;
import java.util.ArrayList;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonObject;
import java.util.Iterator;
import com.mojang.realmsclient.util.RealmsUtil;
import net.minecraft.realms.Realms;
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 realmsServerPlayerList) {
final StringBuilder stringBuilder3 = new StringBuilder();
int integer4 = 0;
for (final String string6 : realmsServerPlayerList.players) {
if (string6.equals(Realms.getUUID())) {
continue;
}
String string7 = "";
try {
string7 = RealmsUtil.uuidToName(string6);
}
catch (Exception exception8) {
RealmsServer.LOGGER.error("Could not get name for " + string6, (Throwable)exception8);
continue;
}
if (stringBuilder3.length() > 0) {
stringBuilder3.append("\n");
}
stringBuilder3.append(string7);
++integer4;
}
this.serverPing.nrOfPlayers = String.valueOf(integer4);
this.serverPing.playerList = stringBuilder3.toString();
}
public static RealmsServer parse(final JsonObject jsonObject) {
final RealmsServer realmsServer2 = new RealmsServer();
try {
realmsServer2.id = JsonUtils.getLongOr("id", jsonObject, -1L);
realmsServer2.remoteSubscriptionId = JsonUtils.getStringOr("remoteSubscriptionId", jsonObject, null);
realmsServer2.name = JsonUtils.getStringOr("name", jsonObject, null);
realmsServer2.motd = JsonUtils.getStringOr("motd", jsonObject, null);
realmsServer2.state = getState(JsonUtils.getStringOr("state", jsonObject, State.CLOSED.name()));
realmsServer2.owner = JsonUtils.getStringOr("owner", jsonObject, null);
if (jsonObject.get("players") != null && jsonObject.get("players").isJsonArray()) {
realmsServer2.players = parseInvited(jsonObject.get("players").getAsJsonArray());
sortInvited(realmsServer2);
}
else {
realmsServer2.players = new ArrayList<PlayerInfo>();
}
realmsServer2.daysLeft = JsonUtils.getIntOr("daysLeft", jsonObject, 0);
realmsServer2.expired = JsonUtils.getBooleanOr("expired", jsonObject, false);
realmsServer2.expiredTrial = JsonUtils.getBooleanOr("expiredTrial", jsonObject, false);
realmsServer2.worldType = getWorldType(JsonUtils.getStringOr("worldType", jsonObject, WorldType.NORMAL.name()));
realmsServer2.ownerUUID = JsonUtils.getStringOr("ownerUUID", jsonObject, "");
if (jsonObject.get("slots") != null && jsonObject.get("slots").isJsonArray()) {
realmsServer2.slots = parseSlots(jsonObject.get("slots").getAsJsonArray());
}
else {
realmsServer2.slots = getEmptySlots();
}
realmsServer2.minigameName = JsonUtils.getStringOr("minigameName", jsonObject, null);
realmsServer2.activeSlot = JsonUtils.getIntOr("activeSlot", jsonObject, -1);
realmsServer2.minigameId = JsonUtils.getIntOr("minigameId", jsonObject, -1);
realmsServer2.minigameImage = JsonUtils.getStringOr("minigameImage", jsonObject, null);
}
catch (Exception exception3) {
RealmsServer.LOGGER.error("Could not parse McoServer: " + exception3.getMessage());
}
return realmsServer2;
}
private static void sortInvited(final RealmsServer realmsServer) {
Collections.<PlayerInfo>sort(realmsServer.players, new Comparator<PlayerInfo>() {
@Override
public int compare(final PlayerInfo playerInfo1, final PlayerInfo playerInfo2) {
return ComparisonChain.start().compare(playerInfo2.getAccepted(), playerInfo1.getAccepted()).compare(playerInfo1.getName().toLowerCase(Locale.ROOT), playerInfo2.getName().toLowerCase(Locale.ROOT)).result();
}
});
}
private static List<PlayerInfo> parseInvited(final JsonArray jsonArray) {
final ArrayList<PlayerInfo> arrayList2 = new ArrayList<PlayerInfo>();
for (final JsonElement jsonElement4 : jsonArray) {
try {
final JsonObject jsonObject5 = jsonElement4.getAsJsonObject();
final PlayerInfo playerInfo6 = new PlayerInfo();
playerInfo6.setName(JsonUtils.getStringOr("name", jsonObject5, null));
playerInfo6.setUuid(JsonUtils.getStringOr("uuid", jsonObject5, null));
playerInfo6.setOperator(JsonUtils.getBooleanOr("operator", jsonObject5, false));
playerInfo6.setAccepted(JsonUtils.getBooleanOr("accepted", jsonObject5, false));
playerInfo6.setOnline(JsonUtils.getBooleanOr("online", jsonObject5, false));
arrayList2.add(playerInfo6);
}
catch (Exception ex) {}
}
return arrayList2;
}
private static Map<Integer, RealmsWorldOptions> parseSlots(final JsonArray jsonArray) {
final Map<Integer, RealmsWorldOptions> map2 = new HashMap<Integer, RealmsWorldOptions>();
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 realmsWorldOptions5;
if (jsonElement5 == null) {
realmsWorldOptions5 = RealmsWorldOptions.getDefaults();
}
else {
realmsWorldOptions5 = RealmsWorldOptions.parse(jsonElement5.getAsJsonObject());
}
final int integer9 = JsonUtils.getIntOr("slotId", jsonObject6, -1);
map2.put(integer9, realmsWorldOptions5);
}
catch (Exception ex) {}
}
for (int integer10 = 1; integer10 <= 3; ++integer10) {
if (!map2.containsKey(integer10)) {
map2.put(integer10, RealmsWorldOptions.getEmptyDefaults());
}
}
return map2;
}
private static Map<Integer, RealmsWorldOptions> getEmptySlots() {
final HashMap<Integer, RealmsWorldOptions> hashMap1 = new HashMap<Integer, RealmsWorldOptions>();
hashMap1.put(1, RealmsWorldOptions.getEmptyDefaults());
hashMap1.put(2, RealmsWorldOptions.getEmptyDefaults());
hashMap1.put(3, RealmsWorldOptions.getEmptyDefaults());
return hashMap1;
}
public static RealmsServer parse(final String string) {
RealmsServer realmsServer2 = new RealmsServer();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
realmsServer2 = parse(jsonObject4);
}
catch (Exception exception3) {
RealmsServer.LOGGER.error("Could not parse McoServer: " + exception3.getMessage());
}
return realmsServer2;
}
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 new HashCodeBuilder(17, 37).append(this.id).append(this.name).append(this.motd).append(this.state).append(this.owner).append(this.expired).toHashCode();
}
@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 realmsServer3 = (RealmsServer)object;
return new EqualsBuilder().append(this.id, realmsServer3.id).append(this.name, realmsServer3.name).append(this.motd, realmsServer3.motd).append(this.state, realmsServer3.state).append(this.owner, realmsServer3.owner).append(this.expired, realmsServer3.expired).append(this.worldType, this.worldType).isEquals();
}
public RealmsServer clone() {
final RealmsServer realmsServer2 = new RealmsServer();
realmsServer2.id = this.id;
realmsServer2.remoteSubscriptionId = this.remoteSubscriptionId;
realmsServer2.name = this.name;
realmsServer2.motd = this.motd;
realmsServer2.state = this.state;
realmsServer2.owner = this.owner;
realmsServer2.players = this.players;
realmsServer2.slots = this.cloneSlots(this.slots);
realmsServer2.expired = this.expired;
realmsServer2.expiredTrial = this.expiredTrial;
realmsServer2.daysLeft = this.daysLeft;
realmsServer2.serverPing = new RealmsServerPing();
realmsServer2.serverPing.nrOfPlayers = this.serverPing.nrOfPlayers;
realmsServer2.serverPing.playerList = this.serverPing.playerList;
realmsServer2.worldType = this.worldType;
realmsServer2.ownerUUID = this.ownerUUID;
realmsServer2.minigameName = this.minigameName;
realmsServer2.activeSlot = this.activeSlot;
realmsServer2.minigameId = this.minigameId;
realmsServer2.minigameImage = this.minigameImage;
return realmsServer2;
}
public Map<Integer, RealmsWorldOptions> cloneSlots(final Map<Integer, RealmsWorldOptions> map) {
final Map<Integer, RealmsWorldOptions> map2 = new HashMap<Integer, RealmsWorldOptions>();
for (final Map.Entry<Integer, RealmsWorldOptions> entry5 : map.entrySet()) {
map2.put(entry5.getKey(), entry5.getValue().clone());
}
return map2;
}
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 realmsServer1, final RealmsServer realmsServer2) {
return ComparisonChain.start().compareTrueFirst(realmsServer1.state.equals(State.UNINITIALIZED), realmsServer2.state.equals(State.UNINITIALIZED)).compareTrueFirst(realmsServer1.expiredTrial, realmsServer2.expiredTrial).compareTrueFirst(realmsServer1.owner.equals(this.refOwner), realmsServer2.owner.equals(this.refOwner)).compareFalseFirst(realmsServer1.expired, realmsServer2.expired).compareTrueFirst(realmsServer1.state.equals(State.OPEN), realmsServer2.state.equals(State.OPEN)).compare(realmsServer1.id, realmsServer2.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 realmsServerAddress3 = new RealmsServerAddress();
try {
final JsonObject jsonObject4 = jsonParser2.parse(string).getAsJsonObject();
realmsServerAddress3.address = JsonUtils.getStringOr("address", jsonObject4, null);
realmsServerAddress3.resourcePackUrl = JsonUtils.getStringOr("resourcePackUrl", jsonObject4, null);
realmsServerAddress3.resourcePackHash = JsonUtils.getStringOr("resourcePackHash", jsonObject4, null);
}
catch (Exception exception4) {
RealmsServerAddress.LOGGER.error("Could not parse RealmsServerAddress: " + exception4.getMessage());
}
return realmsServerAddress3;
}
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 java.util.ArrayList;
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 realmsServerList2 = new RealmsServerList();
realmsServerList2.servers = new ArrayList<RealmsServer>();
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()) {
realmsServerList2.servers.add(RealmsServer.parse(iterator6.next().getAsJsonObject()));
}
}
}
catch (Exception exception3) {
RealmsServerList.LOGGER.error("Could not parse McoServerList: " + exception3.getMessage());
}
return realmsServerList2;
}
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 java.util.ArrayList;
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 jsonParser;
public long serverId;
public List<String> players;
public static RealmsServerPlayerList parse(final JsonObject jsonObject) {
final RealmsServerPlayerList realmsServerPlayerList2 = new RealmsServerPlayerList();
try {
realmsServerPlayerList2.serverId = JsonUtils.getLongOr("serverId", jsonObject, -1L);
final String string3 = JsonUtils.getStringOr("playerList", jsonObject, null);
if (string3 != null) {
final JsonElement jsonElement4 = RealmsServerPlayerList.jsonParser.parse(string3);
if (jsonElement4.isJsonArray()) {
realmsServerPlayerList2.players = parsePlayers(jsonElement4.getAsJsonArray());
}
else {
realmsServerPlayerList2.players = new ArrayList<String>();
}
}
else {
realmsServerPlayerList2.players = new ArrayList<String>();
}
}
catch (Exception exception3) {
RealmsServerPlayerList.LOGGER.error("Could not parse RealmsServerPlayerList: " + exception3.getMessage());
}
return realmsServerPlayerList2;
}
private static List<String> parsePlayers(final JsonArray jsonArray) {
final ArrayList<String> arrayList2 = new ArrayList<String>();
for (final JsonElement jsonElement4 : jsonArray) {
try {
arrayList2.add(jsonElement4.getAsString());
}
catch (Exception ex) {}
}
return arrayList2;
}
static {
LOGGER = LogManager.getLogger();
jsonParser = new JsonParser();
}
}

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 java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.Logger;
public class RealmsServerPlayerLists extends ValueObject {
private static final Logger LOGGER;
public List<RealmsServerPlayerList> servers;
public static RealmsServerPlayerLists parse(final String string) {
final RealmsServerPlayerLists realmsServerPlayerLists2 = new RealmsServerPlayerLists();
realmsServerPlayerLists2.servers = new ArrayList<RealmsServerPlayerList>();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
if (jsonObject4.get("lists").isJsonArray()) {
final JsonArray jsonArray5 = jsonObject4.get("lists").getAsJsonArray();
final Iterator<JsonElement> iterator6 = jsonArray5.iterator();
while (iterator6.hasNext()) {
realmsServerPlayerLists2.servers.add(RealmsServerPlayerList.parse(iterator6.next().getAsJsonObject()));
}
}
}
catch (Exception exception3) {
RealmsServerPlayerLists.LOGGER.error("Could not parse RealmsServerPlayerLists: " + exception3.getMessage());
}
return realmsServerPlayerLists2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,127 @@
package com.mojang.realmsclient.dto;
import net.minecraft.realms.RealmsScreen;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonObject;
public class RealmsWorldOptions extends ValueObject {
public Boolean pvp;
public Boolean spawnAnimals;
public Boolean spawnMonsters;
public Boolean spawnNPCs;
public Integer spawnProtection;
public Boolean commandBlocks;
public Boolean forceGameMode;
public Integer difficulty;
public Integer gameMode;
public String slotName;
public long templateId;
public String templateImage;
public boolean adventureMap;
public boolean empty;
private static final boolean forceGameModeDefault = false;
private static final boolean pvpDefault = true;
private static final boolean spawnAnimalsDefault = true;
private static final boolean spawnMonstersDefault = true;
private static final boolean spawnNPCsDefault = true;
private static final int spawnProtectionDefault = 0;
private static final boolean commandBlocksDefault = false;
private static final int difficultyDefault = 2;
private static final int gameModeDefault = 0;
private static final String slotNameDefault = "";
private static final long templateIdDefault = -1L;
private static final String templateImageDefault;
private static final boolean adventureMapDefault = false;
public RealmsWorldOptions(final Boolean boolean1, final Boolean boolean2, final Boolean boolean3, final Boolean boolean4, final Integer integer5, final Boolean boolean6, final Integer integer7, final Integer integer8, final Boolean boolean9, final String string) {
this.pvp = boolean1;
this.spawnAnimals = boolean2;
this.spawnMonsters = boolean3;
this.spawnNPCs = boolean4;
this.spawnProtection = integer5;
this.commandBlocks = boolean6;
this.difficulty = integer7;
this.gameMode = integer8;
this.forceGameMode = boolean9;
this.slotName = string;
}
public static RealmsWorldOptions getDefaults() {
return new RealmsWorldOptions(true, true, true, true, 0, false, 2, 0, false, "");
}
public static RealmsWorldOptions getEmptyDefaults() {
final RealmsWorldOptions realmsWorldOptions1 = new RealmsWorldOptions(true, true, true, true, 0, false, 2, 0, false, "");
realmsWorldOptions1.setEmpty(true);
return realmsWorldOptions1;
}
public void setEmpty(final boolean boolean1) {
this.empty = boolean1;
}
public static RealmsWorldOptions parse(final JsonObject jsonObject) {
final RealmsWorldOptions realmsWorldOptions2 = new RealmsWorldOptions(JsonUtils.getBooleanOr("pvp", jsonObject, true), JsonUtils.getBooleanOr("spawnAnimals", jsonObject, true), JsonUtils.getBooleanOr("spawnMonsters", jsonObject, true), JsonUtils.getBooleanOr("spawnNPCs", jsonObject, true), JsonUtils.getIntOr("spawnProtection", jsonObject, 0), JsonUtils.getBooleanOr("commandBlocks", jsonObject, false), JsonUtils.getIntOr("difficulty", jsonObject, 2), JsonUtils.getIntOr("gameMode", jsonObject, 0), JsonUtils.getBooleanOr("forceGameMode", jsonObject, false), JsonUtils.getStringOr("slotName", jsonObject, ""));
realmsWorldOptions2.templateId = JsonUtils.getLongOr("worldTemplateId", jsonObject, -1L);
realmsWorldOptions2.templateImage = JsonUtils.getStringOr("worldTemplateImage", jsonObject, RealmsWorldOptions.templateImageDefault);
realmsWorldOptions2.adventureMap = JsonUtils.getBooleanOr("adventureMap", jsonObject, false);
return realmsWorldOptions2;
}
public String getSlotName(final int integer) {
if (this.slotName != null && !this.slotName.isEmpty()) {
return this.slotName;
}
if (this.empty) {
return RealmsScreen.getLocalizedString("mco.configure.world.slot.empty");
}
return this.getDefaultSlotName(integer);
}
public String getDefaultSlotName(final int integer) {
return RealmsScreen.getLocalizedString("mco.configure.world.slot", integer);
}
public String toJson() {
final JsonObject jsonObject2 = new JsonObject();
if (!this.pvp) {
jsonObject2.addProperty("pvp", this.pvp);
}
if (!this.spawnAnimals) {
jsonObject2.addProperty("spawnAnimals", this.spawnAnimals);
}
if (!this.spawnMonsters) {
jsonObject2.addProperty("spawnMonsters", this.spawnMonsters);
}
if (!this.spawnNPCs) {
jsonObject2.addProperty("spawnNPCs", this.spawnNPCs);
}
if (this.spawnProtection != 0) {
jsonObject2.addProperty("spawnProtection", this.spawnProtection);
}
if (this.commandBlocks) {
jsonObject2.addProperty("commandBlocks", this.commandBlocks);
}
if (this.difficulty != 2) {
jsonObject2.addProperty("difficulty", this.difficulty);
}
if (this.gameMode != 0) {
jsonObject2.addProperty("gameMode", this.gameMode);
}
if (this.forceGameMode) {
jsonObject2.addProperty("forceGameMode", this.forceGameMode);
}
if (this.slotName != null && !this.slotName.equals("")) {
jsonObject2.addProperty("slotName", this.slotName);
}
return jsonObject2.toString();
}
public RealmsWorldOptions clone() {
return new RealmsWorldOptions(this.pvp, this.spawnAnimals, this.spawnMonsters, this.spawnNPCs, this.spawnProtection, this.commandBlocks, this.difficulty, this.gameMode, this.forceGameMode, this.slotName);
}
static {
templateImageDefault = null;
}
}

View File

@ -0,0 +1,15 @@
package com.mojang.realmsclient.dto;
public class RealmsWorldResetDto extends ValueObject {
private final String seed;
private final long worldTemplateId;
private final int levelType;
private final boolean generateStructures;
public RealmsWorldResetDto(final String string, final long long2, final int integer, final boolean boolean4) {
this.seed = string;
this.worldTemplateId = long2;
this.levelType = integer;
this.generateStructures = boolean4;
}
}

View File

@ -0,0 +1,22 @@
package com.mojang.realmsclient.dto;
import java.util.Locale;
public class RegionPingResult extends ValueObject {
private final String regionName;
private final int ping;
public RegionPingResult(final String string, final int integer) {
this.regionName = string;
this.ping = integer;
}
public int ping() {
return this.ping;
}
@Override
public String toString() {
return String.format(Locale.ROOT, "%s --> %.2f ms", this.regionName, Float.valueOf(this.ping));
}
}

View File

@ -0,0 +1,21 @@
package com.mojang.realmsclient.dto;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonObject;
public class ServerActivity extends ValueObject {
public String profileUuid;
public long joinTime;
public long leaveTime;
public static ServerActivity parse(final JsonObject jsonObject) {
final ServerActivity serverActivity2 = new ServerActivity();
try {
serverActivity2.profileUuid = JsonUtils.getStringOr("profileUuid", jsonObject, null);
serverActivity2.joinTime = JsonUtils.getLongOr("joinTime", jsonObject, Long.MIN_VALUE);
serverActivity2.leaveTime = JsonUtils.getLongOr("leaveTime", jsonObject, Long.MIN_VALUE);
}
catch (Exception ex) {}
return serverActivity2;
}
}

View File

@ -0,0 +1,39 @@
package com.mojang.realmsclient.dto;
import java.util.Iterator;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonElement;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.List;
public class ServerActivityList extends ValueObject {
public long periodInMillis;
public List<ServerActivity> serverActivities;
public ServerActivityList() {
this.serverActivities = new ArrayList<ServerActivity>();
}
public static ServerActivityList parse(final String string) {
final ServerActivityList serverActivityList2 = new ServerActivityList();
final JsonParser jsonParser3 = new JsonParser();
try {
final JsonElement jsonElement4 = jsonParser3.parse(string);
final JsonObject jsonObject5 = jsonElement4.getAsJsonObject();
serverActivityList2.periodInMillis = JsonUtils.getLongOr("periodInMillis", jsonObject5, -1L);
final JsonElement jsonElement5 = jsonObject5.get("playerActivityDto");
if (jsonElement5 != null && jsonElement5.isJsonArray()) {
final JsonArray jsonArray7 = jsonElement5.getAsJsonArray();
for (final JsonElement jsonElement6 : jsonArray7) {
final ServerActivity serverActivity10 = ServerActivity.parse(jsonElement6.getAsJsonObject());
serverActivityList2.serverActivities.add(serverActivity10);
}
}
}
catch (Exception ex) {}
return serverActivityList2;
}
}

View File

@ -0,0 +1,51 @@
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 Subscription extends ValueObject {
private static final Logger LOGGER;
public long startDate;
public int daysLeft;
public SubscriptionType type;
public Subscription() {
this.type = SubscriptionType.NORMAL;
}
public static Subscription parse(final String string) {
final Subscription subscription2 = new Subscription();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
subscription2.startDate = JsonUtils.getLongOr("startDate", jsonObject4, 0L);
subscription2.daysLeft = JsonUtils.getIntOr("daysLeft", jsonObject4, 0);
subscription2.type = typeFrom(JsonUtils.getStringOr("subscriptionType", jsonObject4, SubscriptionType.NORMAL.name()));
}
catch (Exception exception3) {
Subscription.LOGGER.error("Could not parse Subscription: " + exception3.getMessage());
}
return subscription2;
}
private static SubscriptionType typeFrom(final String string) {
try {
return SubscriptionType.valueOf(string);
}
catch (Exception exception2) {
return SubscriptionType.NORMAL;
}
}
static {
LOGGER = LogManager.getLogger();
}
public enum SubscriptionType {
NORMAL,
RECURRING;
}
}

View File

@ -0,0 +1,64 @@
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 com.google.gson.annotations.Expose;
import org.apache.logging.log4j.Logger;
public class UploadInfo extends ValueObject {
private static final Logger LOGGER;
@Expose
private boolean worldClosed;
@Expose
private String token;
@Expose
private String uploadEndpoint;
private int port;
public UploadInfo() {
this.token = "";
this.uploadEndpoint = "";
}
public static UploadInfo parse(final String string) {
final UploadInfo uploadInfo2 = new UploadInfo();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
uploadInfo2.worldClosed = JsonUtils.getBooleanOr("worldClosed", jsonObject4, false);
uploadInfo2.token = JsonUtils.getStringOr("token", jsonObject4, null);
uploadInfo2.uploadEndpoint = JsonUtils.getStringOr("uploadEndpoint", jsonObject4, null);
uploadInfo2.port = JsonUtils.getIntOr("port", jsonObject4, 8080);
}
catch (Exception exception3) {
UploadInfo.LOGGER.error("Could not parse UploadInfo: " + exception3.getMessage());
}
return uploadInfo2;
}
public String getToken() {
return this.token;
}
public String getUploadEndpoint() {
return this.uploadEndpoint;
}
public boolean isWorldClosed() {
return this.worldClosed;
}
public void setToken(final String string) {
this.token = string;
}
public int getPort() {
return this.port;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,26 @@
package com.mojang.realmsclient.dto;
import java.lang.reflect.Modifier;
import java.lang.reflect.Field;
public abstract class ValueObject {
@Override
public String toString() {
final StringBuilder stringBuilder2 = new StringBuilder("{");
for (final Field field6 : this.getClass().getFields()) {
if (!isStatic(field6)) {
try {
stringBuilder2.append(field6.getName()).append("=").append(field6.get(this)).append(" ");
}
catch (IllegalAccessException illegalAccessException7) {}
}
}
stringBuilder2.deleteCharAt(stringBuilder2.length() - 1);
stringBuilder2.append('}');
return stringBuilder2.toString();
}
private static boolean isStatic(final Field field) {
return Modifier.isStatic(field.getModifiers());
}
}

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 WorldDownload extends ValueObject {
private static final Logger LOGGER;
public String downloadLink;
public String resourcePackUrl;
public String resourcePackHash;
public static WorldDownload parse(final String string) {
final JsonParser jsonParser2 = new JsonParser();
final JsonObject jsonObject3 = jsonParser2.parse(string).getAsJsonObject();
final WorldDownload worldDownload4 = new WorldDownload();
try {
worldDownload4.downloadLink = JsonUtils.getStringOr("downloadLink", jsonObject3, "");
worldDownload4.resourcePackUrl = JsonUtils.getStringOr("resourcePackUrl", jsonObject3, "");
worldDownload4.resourcePackHash = JsonUtils.getStringOr("resourcePackHash", jsonObject3, "");
}
catch (Exception exception5) {
WorldDownload.LOGGER.error("Could not parse WorldDownload: " + exception5.getMessage());
}
return worldDownload4;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,50 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonObject;
import org.apache.logging.log4j.Logger;
public class WorldTemplate extends ValueObject {
private static final Logger LOGGER;
public String id;
public String name;
public String version;
public String author;
public String link;
public String image;
public String trailer;
public String recommendedPlayers;
public WorldTemplateType type;
public static WorldTemplate parse(final JsonObject jsonObject) {
final WorldTemplate worldTemplate2 = new WorldTemplate();
try {
worldTemplate2.id = JsonUtils.getStringOr("id", jsonObject, "");
worldTemplate2.name = JsonUtils.getStringOr("name", jsonObject, "");
worldTemplate2.version = JsonUtils.getStringOr("version", jsonObject, "");
worldTemplate2.author = JsonUtils.getStringOr("author", jsonObject, "");
worldTemplate2.link = JsonUtils.getStringOr("link", jsonObject, "");
worldTemplate2.image = JsonUtils.getStringOr("image", jsonObject, null);
worldTemplate2.trailer = JsonUtils.getStringOr("trailer", jsonObject, "");
worldTemplate2.recommendedPlayers = JsonUtils.getStringOr("recommendedPlayers", jsonObject, "");
worldTemplate2.type = WorldTemplateType.valueOf(JsonUtils.getStringOr("type", jsonObject, WorldTemplateType.WORLD_TEMPLATE.name()));
}
catch (Exception exception3) {
WorldTemplate.LOGGER.error("Could not parse WorldTemplate: " + exception3.getMessage());
}
return worldTemplate2;
}
static {
LOGGER = LogManager.getLogger();
}
public enum WorldTemplateType {
WORLD_TEMPLATE,
MINIGAME,
ADVENTUREMAP,
EXPERIENCE,
INSPIRATION;
}
}

View File

@ -0,0 +1,60 @@
package com.mojang.realmsclient.dto;
import org.apache.logging.log4j.LogManager;
import java.util.Iterator;
import com.google.gson.JsonObject;
import com.mojang.realmsclient.util.JsonUtils;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.logging.log4j.Logger;
public class WorldTemplatePaginatedList extends ValueObject {
private static final Logger LOGGER;
public List<WorldTemplate> templates;
public int page;
public int size;
public int total;
public WorldTemplatePaginatedList() {
}
public WorldTemplatePaginatedList(final int integer) {
this.templates = Collections.<WorldTemplate>emptyList();
this.page = 0;
this.size = integer;
this.total = -1;
}
public boolean isLastPage() {
return this.page * this.size >= this.total && this.page > 0 && this.total > 0 && this.size > 0;
}
public static WorldTemplatePaginatedList parse(final String string) {
final WorldTemplatePaginatedList worldTemplatePaginatedList2 = new WorldTemplatePaginatedList();
worldTemplatePaginatedList2.templates = new ArrayList<WorldTemplate>();
try {
final JsonParser jsonParser3 = new JsonParser();
final JsonObject jsonObject4 = jsonParser3.parse(string).getAsJsonObject();
if (jsonObject4.get("templates").isJsonArray()) {
final Iterator<JsonElement> iterator5 = jsonObject4.get("templates").getAsJsonArray().iterator();
while (iterator5.hasNext()) {
worldTemplatePaginatedList2.templates.add(WorldTemplate.parse(iterator5.next().getAsJsonObject()));
}
}
worldTemplatePaginatedList2.page = JsonUtils.getIntOr("page", jsonObject4, 0);
worldTemplatePaginatedList2.size = JsonUtils.getIntOr("size", jsonObject4, 0);
worldTemplatePaginatedList2.total = JsonUtils.getIntOr("total", jsonObject4, 0);
}
catch (Exception exception3) {
WorldTemplatePaginatedList.LOGGER.error("Could not parse WorldTemplatePaginatedList: " + exception3.getMessage());
}
return worldTemplatePaginatedList2;
}
static {
LOGGER = LogManager.getLogger();
}
}

View File

@ -0,0 +1,17 @@
package com.mojang.realmsclient.exception;
import org.apache.logging.log4j.Logger;
public class RealmsDefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private final Logger logger;
public RealmsDefaultUncaughtExceptionHandler(final Logger logger) {
this.logger = logger;
}
@Override
public void uncaughtException(final Thread thread, final Throwable throwable) {
this.logger.error("Caught previously unhandled exception :");
this.logger.error(throwable);
}
}

View File

@ -0,0 +1,7 @@
package com.mojang.realmsclient.exception;
public class RealmsHttpException extends RuntimeException {
public RealmsHttpException(final String string, final Exception exception) {
super(string, exception);
}
}

View File

@ -0,0 +1,37 @@
package com.mojang.realmsclient.exception;
import net.minecraft.realms.RealmsScreen;
import com.mojang.realmsclient.client.RealmsError;
public class RealmsServiceException extends Exception {
public final int httpResultCode;
public final String httpResponseContent;
public final int errorCode;
public final String errorMsg;
public RealmsServiceException(final int integer, final String string, final RealmsError cvo) {
super(string);
this.httpResultCode = integer;
this.httpResponseContent = string;
this.errorCode = cvo.getErrorCode();
this.errorMsg = cvo.getErrorMessage();
}
public RealmsServiceException(final int integer1, final String string2, final int integer3, final String string4) {
super(string2);
this.httpResultCode = integer1;
this.httpResponseContent = string2;
this.errorCode = integer3;
this.errorMsg = string4;
}
@Override
public String toString() {
if (this.errorCode == -1) {
return "Realms (" + this.httpResultCode + ") " + this.httpResponseContent;
}
final String string2 = "mco.errorMessage." + this.errorCode;
final String string3 = RealmsScreen.getLocalizedString(string2);
return (string3.equals(string2) ? this.errorMsg : string3) + " - " + this.errorCode;
}
}

View File

@ -0,0 +1,15 @@
package com.mojang.realmsclient.exception;
public class RetryCallException extends RealmsServiceException {
public final int delaySeconds;
public RetryCallException(final int integer) {
super(503, "Retry operation", -1, "");
if (integer < 0 || integer > 120) {
this.delaySeconds = 5;
}
else {
this.delaySeconds = integer;
}
}
}

View File

@ -0,0 +1,69 @@
package com.mojang.realmsclient.gui;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.Locale;
import java.util.regex.Pattern;
import java.util.Map;
public enum ChatFormatting {
BLACK('0'),
DARK_BLUE('1'),
DARK_GREEN('2'),
DARK_AQUA('3'),
DARK_RED('4'),
DARK_PURPLE('5'),
GOLD('6'),
GRAY('7'),
DARK_GRAY('8'),
BLUE('9'),
GREEN('a'),
AQUA('b'),
RED('c'),
LIGHT_PURPLE('d'),
YELLOW('e'),
WHITE('f'),
OBFUSCATED('k', true),
BOLD('l', true),
STRIKETHROUGH('m', true),
UNDERLINE('n', true),
ITALIC('o', true),
RESET('r');
private static final Map<Character, ChatFormatting> FORMATTING_BY_CHAR;
private static final Map<String, ChatFormatting> FORMATTING_BY_NAME;
private static final Pattern STRIP_FORMATTING_PATTERN;
private final char code;
private final boolean isFormat;
private final String toString;
private ChatFormatting(final char character) {
this(character, false);
}
private ChatFormatting(final char character, final boolean boolean4) {
this.code = character;
this.isFormat = boolean4;
this.toString = "§" + character;
}
public char getChar() {
return this.code;
}
public String getName() {
return this.name().toLowerCase(Locale.ROOT);
}
@Override
public String toString() {
return this.toString;
}
static {
FORMATTING_BY_CHAR = Arrays.<ChatFormatting>stream(values()).collect(Collectors.toMap(ChatFormatting::getChar, cvw -> cvw));
FORMATTING_BY_NAME = Arrays.<ChatFormatting>stream(values()).collect(Collectors.toMap(ChatFormatting::getName, cvw -> cvw));
STRIP_FORMATTING_PATTERN = Pattern.compile("(?i)§[0-9A-FK-OR]");
}
}

View File

@ -0,0 +1,32 @@
package com.mojang.realmsclient.gui;
import com.mojang.realmsclient.gui.screens.RealmsLongRunningMcoTaskScreen;
public abstract class LongRunningTask implements Runnable {
protected RealmsLongRunningMcoTaskScreen longRunningMcoTaskScreen;
public void setScreen(final RealmsLongRunningMcoTaskScreen cwo) {
this.longRunningMcoTaskScreen = cwo;
}
public void error(final String string) {
this.longRunningMcoTaskScreen.error(string);
}
public void setTitle(final String string) {
this.longRunningMcoTaskScreen.setTitle(string);
}
public boolean aborted() {
return this.longRunningMcoTaskScreen.aborted();
}
public void tick() {
}
public void init() {
}
public void abortTask() {
}
}

View File

@ -0,0 +1,7 @@
package com.mojang.realmsclient.gui;
public class RealmsConstants {
public static int row(final int integer) {
return 40 + integer * 13;
}
}

View File

@ -0,0 +1,369 @@
package com.mojang.realmsclient.gui;
import com.mojang.realmsclient.dto.RealmsNews;
import com.mojang.realmsclient.util.RealmsPersistence;
import com.mojang.realmsclient.client.RealmsClient;
import org.apache.logging.log4j.LogManager;
import java.util.Comparator;
import java.util.Collections;
import net.minecraft.realms.Realms;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ConcurrentHashMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.concurrent.Executors;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import com.mojang.realmsclient.dto.RealmsServerPlayerLists;
import java.util.List;
import com.mojang.realmsclient.dto.RealmsServer;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.logging.log4j.Logger;
public class RealmsDataFetcher {
private static final Logger LOGGER;
private final ScheduledExecutorService scheduler;
private volatile boolean stopped;
private final ServerListUpdateTask serverListUpdateTask;
private final PendingInviteUpdateTask pendingInviteUpdateTask;
private final TrialAvailabilityTask trialAvailabilityTask;
private final LiveStatsTask liveStatsTask;
private final UnreadNewsTask unreadNewsTask;
private final Set<RealmsServer> removedServers;
private List<RealmsServer> servers;
private RealmsServerPlayerLists livestats;
private int pendingInvitesCount;
private boolean trialAvailable;
private boolean hasUnreadNews;
private String newsLink;
private ScheduledFuture<?> serverListScheduledFuture;
private ScheduledFuture<?> pendingInviteScheduledFuture;
private ScheduledFuture<?> trialAvailableScheduledFuture;
private ScheduledFuture<?> liveStatsScheduledFuture;
private ScheduledFuture<?> unreadNewsScheduledFuture;
private final Map<Task, Boolean> fetchStatus;
public RealmsDataFetcher() {
this.scheduler = Executors.newScheduledThreadPool(3);
this.stopped = true;
this.serverListUpdateTask = new ServerListUpdateTask();
this.pendingInviteUpdateTask = new PendingInviteUpdateTask();
this.trialAvailabilityTask = new TrialAvailabilityTask();
this.liveStatsTask = new LiveStatsTask();
this.unreadNewsTask = new UnreadNewsTask();
this.removedServers = Sets.newHashSet();
this.servers = Lists.newArrayList();
this.fetchStatus = new ConcurrentHashMap<Task, Boolean>(Task.values().length);
}
public boolean isStopped() {
return this.stopped;
}
public synchronized void init() {
if (this.stopped) {
this.stopped = false;
this.cancelTasks();
this.scheduleTasks();
}
}
public synchronized void initWithSpecificTaskList(final List<Task> list) {
if (this.stopped) {
this.stopped = false;
this.cancelTasks();
for (final Task d4 : list) {
this.fetchStatus.put(d4, false);
switch (d4) {
case SERVER_LIST: {
this.serverListScheduledFuture = this.scheduler.scheduleAtFixedRate(this.serverListUpdateTask, 0L, 60L, TimeUnit.SECONDS);
continue;
}
case PENDING_INVITE: {
this.pendingInviteScheduledFuture = this.scheduler.scheduleAtFixedRate(this.pendingInviteUpdateTask, 0L, 10L, TimeUnit.SECONDS);
continue;
}
case TRIAL_AVAILABLE: {
this.trialAvailableScheduledFuture = this.scheduler.scheduleAtFixedRate(this.trialAvailabilityTask, 0L, 60L, TimeUnit.SECONDS);
continue;
}
case LIVE_STATS: {
this.liveStatsScheduledFuture = this.scheduler.scheduleAtFixedRate(this.liveStatsTask, 0L, 10L, TimeUnit.SECONDS);
continue;
}
case UNREAD_NEWS: {
this.unreadNewsScheduledFuture = this.scheduler.scheduleAtFixedRate(this.unreadNewsTask, 0L, 300L, TimeUnit.SECONDS);
continue;
}
}
}
}
}
public boolean isFetchedSinceLastTry(final Task d) {
final Boolean boolean3 = this.fetchStatus.get(d);
return boolean3 != null && boolean3;
}
public void markClean() {
for (final Task d3 : this.fetchStatus.keySet()) {
this.fetchStatus.put(d3, false);
}
}
public synchronized void forceUpdate() {
this.stop();
this.init();
}
public synchronized List<RealmsServer> getServers() {
return Lists.newArrayList(this.servers);
}
public synchronized int getPendingInvitesCount() {
return this.pendingInvitesCount;
}
public synchronized boolean isTrialAvailable() {
return this.trialAvailable;
}
public synchronized RealmsServerPlayerLists getLivestats() {
return this.livestats;
}
public synchronized boolean hasUnreadNews() {
return this.hasUnreadNews;
}
public synchronized String newsLink() {
return this.newsLink;
}
public synchronized void stop() {
this.stopped = true;
this.cancelTasks();
}
private void scheduleTasks() {
for (final Task d5 : Task.values()) {
this.fetchStatus.put(d5, false);
}
this.serverListScheduledFuture = this.scheduler.scheduleAtFixedRate(this.serverListUpdateTask, 0L, 60L, TimeUnit.SECONDS);
this.pendingInviteScheduledFuture = this.scheduler.scheduleAtFixedRate(this.pendingInviteUpdateTask, 0L, 10L, TimeUnit.SECONDS);
this.trialAvailableScheduledFuture = this.scheduler.scheduleAtFixedRate(this.trialAvailabilityTask, 0L, 60L, TimeUnit.SECONDS);
this.liveStatsScheduledFuture = this.scheduler.scheduleAtFixedRate(this.liveStatsTask, 0L, 10L, TimeUnit.SECONDS);
this.unreadNewsScheduledFuture = this.scheduler.scheduleAtFixedRate(this.unreadNewsTask, 0L, 300L, TimeUnit.SECONDS);
}
private void cancelTasks() {
try {
if (this.serverListScheduledFuture != null) {
this.serverListScheduledFuture.cancel(false);
}
if (this.pendingInviteScheduledFuture != null) {
this.pendingInviteScheduledFuture.cancel(false);
}
if (this.trialAvailableScheduledFuture != null) {
this.trialAvailableScheduledFuture.cancel(false);
}
if (this.liveStatsScheduledFuture != null) {
this.liveStatsScheduledFuture.cancel(false);
}
if (this.unreadNewsScheduledFuture != null) {
this.unreadNewsScheduledFuture.cancel(false);
}
}
catch (Exception exception2) {
RealmsDataFetcher.LOGGER.error("Failed to cancel Realms tasks", (Throwable)exception2);
}
}
private synchronized void setServers(final List<RealmsServer> list) {
int integer3 = 0;
for (final RealmsServer realmsServer5 : this.removedServers) {
if (list.remove(realmsServer5)) {
++integer3;
}
}
if (integer3 == 0) {
this.removedServers.clear();
}
this.servers = list;
}
public synchronized void removeItem(final RealmsServer realmsServer) {
this.servers.remove(realmsServer);
this.removedServers.add(realmsServer);
}
private void sort(final List<RealmsServer> list) {
Collections.<RealmsServer>sort(list, new RealmsServer.McoServerComparator(Realms.getName()));
}
private boolean isActive() {
return !this.stopped;
}
static {
LOGGER = LogManager.getLogger();
}
class ServerListUpdateTask implements Runnable {
private ServerListUpdateTask() {
}
@Override
public void run() {
if (RealmsDataFetcher.this.isActive()) {
this.updateServersList();
}
}
private void updateServersList() {
try {
final RealmsClient cvm2 = RealmsClient.createRealmsClient();
if (cvm2 != null) {
final List<RealmsServer> list3 = cvm2.listWorlds().servers;
if (list3 != null) {
RealmsDataFetcher.this.sort(list3);
RealmsDataFetcher.this.setServers(list3);
RealmsDataFetcher.this.fetchStatus.put(Task.SERVER_LIST, true);
}
else {
RealmsDataFetcher.LOGGER.warn("Realms server list was null or empty");
}
}
}
catch (Exception exception2) {
RealmsDataFetcher.this.fetchStatus.put(Task.SERVER_LIST, true);
RealmsDataFetcher.LOGGER.error("Couldn't get server list", (Throwable)exception2);
}
}
}
class PendingInviteUpdateTask implements Runnable {
private PendingInviteUpdateTask() {
}
@Override
public void run() {
if (RealmsDataFetcher.this.isActive()) {
this.updatePendingInvites();
}
}
private void updatePendingInvites() {
try {
final RealmsClient cvm2 = RealmsClient.createRealmsClient();
if (cvm2 != null) {
RealmsDataFetcher.this.pendingInvitesCount = cvm2.pendingInvitesCount();
RealmsDataFetcher.this.fetchStatus.put(Task.PENDING_INVITE, true);
}
}
catch (Exception exception2) {
RealmsDataFetcher.LOGGER.error("Couldn't get pending invite count", (Throwable)exception2);
}
}
}
class TrialAvailabilityTask implements Runnable {
private TrialAvailabilityTask() {
}
@Override
public void run() {
if (RealmsDataFetcher.this.isActive()) {
this.getTrialAvailable();
}
}
private void getTrialAvailable() {
try {
final RealmsClient cvm2 = RealmsClient.createRealmsClient();
if (cvm2 != null) {
RealmsDataFetcher.this.trialAvailable = cvm2.trialAvailable();
RealmsDataFetcher.this.fetchStatus.put(Task.TRIAL_AVAILABLE, true);
}
}
catch (Exception exception2) {
RealmsDataFetcher.LOGGER.error("Couldn't get trial availability", (Throwable)exception2);
}
}
}
class LiveStatsTask implements Runnable {
private LiveStatsTask() {
}
@Override
public void run() {
if (RealmsDataFetcher.this.isActive()) {
this.getLiveStats();
}
}
private void getLiveStats() {
try {
final RealmsClient cvm2 = RealmsClient.createRealmsClient();
if (cvm2 != null) {
RealmsDataFetcher.this.livestats = cvm2.getLiveStats();
RealmsDataFetcher.this.fetchStatus.put(Task.LIVE_STATS, true);
}
}
catch (Exception exception2) {
RealmsDataFetcher.LOGGER.error("Couldn't get live stats", (Throwable)exception2);
}
}
}
class UnreadNewsTask implements Runnable {
private UnreadNewsTask() {
}
@Override
public void run() {
if (RealmsDataFetcher.this.isActive()) {
this.getUnreadNews();
}
}
private void getUnreadNews() {
try {
final RealmsClient cvm2 = RealmsClient.createRealmsClient();
if (cvm2 != null) {
RealmsNews realmsNews3 = null;
try {
realmsNews3 = cvm2.getNews();
}
catch (Exception ex) {}
final RealmsPersistence.RealmsPersistenceData a4 = RealmsPersistence.readFile();
if (realmsNews3 != null) {
final String string5 = realmsNews3.newsLink;
if (string5 != null && !string5.equals(a4.newsLink)) {
a4.hasUnreadNews = true;
a4.newsLink = string5;
RealmsPersistence.writeFile(a4);
}
}
RealmsDataFetcher.this.hasUnreadNews = a4.hasUnreadNews;
RealmsDataFetcher.this.newsLink = a4.newsLink;
RealmsDataFetcher.this.fetchStatus.put(Task.UNREAD_NEWS, true);
}
}
catch (Exception exception2) {
RealmsDataFetcher.LOGGER.error("Couldn't get unread news", (Throwable)exception2);
}
}
}
public enum Task {
SERVER_LIST,
PENDING_INVITE,
TRIAL_AVAILABLE,
LIVE_STATS,
UNREAD_NEWS;
}
}

View File

@ -0,0 +1,201 @@
package com.mojang.realmsclient.gui;
import javax.annotation.Nonnull;
import net.minecraft.realms.RealmsScreen;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.realms.RealmsMth;
import com.mojang.realmsclient.util.RealmsTextureManager;
import javax.annotation.Nullable;
import net.minecraft.realms.RealmsButtonProxy;
import net.minecraft.realms.Realms;
import com.mojang.realmsclient.dto.RealmsWorldOptions;
import java.util.function.Consumer;
import com.mojang.realmsclient.dto.RealmsServer;
import java.util.function.Supplier;
import net.minecraft.realms.RealmsButton;
public class RealmsWorldSlotButton extends RealmsButton {
private final Supplier<RealmsServer> serverDataProvider;
private final Consumer<String> toolTipSetter;
private final Listener listener;
private final int slotIndex;
private int animTick;
private State state;
public RealmsWorldSlotButton(final int integer1, final int integer2, final int integer3, final int integer4, final Supplier<RealmsServer> supplier, final Consumer<String> consumer, final int integer7, final int integer8, final Listener b) {
super(integer7, integer1, integer2, integer3, integer4, "");
this.serverDataProvider = supplier;
this.slotIndex = integer8;
this.toolTipSetter = consumer;
this.listener = b;
}
@Override
public void render(final int integer1, final int integer2, final float float3) {
super.render(integer1, integer2, float3);
}
@Override
public void tick() {
++this.animTick;
final RealmsServer realmsServer2 = this.serverDataProvider.get();
if (realmsServer2 == null) {
return;
}
final RealmsWorldOptions realmsWorldOptions5 = realmsServer2.slots.get(this.slotIndex);
final boolean boolean10 = this.slotIndex == 4;
boolean boolean11;
String string4;
long long6;
String string5;
boolean boolean12;
if (boolean10) {
boolean11 = realmsServer2.worldType.equals(RealmsServer.WorldType.MINIGAME);
string4 = "Minigame";
long6 = realmsServer2.minigameId;
string5 = realmsServer2.minigameImage;
boolean12 = (realmsServer2.minigameId == -1);
}
else {
boolean11 = (realmsServer2.activeSlot == this.slotIndex && !realmsServer2.worldType.equals(RealmsServer.WorldType.MINIGAME));
string4 = realmsWorldOptions5.getSlotName(this.slotIndex);
long6 = realmsWorldOptions5.templateId;
string5 = realmsWorldOptions5.templateImage;
boolean12 = realmsWorldOptions5.empty;
}
String string6 = null;
Action a11;
if (boolean11) {
final boolean boolean13 = realmsServer2.state == RealmsServer.State.OPEN || realmsServer2.state == RealmsServer.State.CLOSED;
if (realmsServer2.expired || !boolean13) {
a11 = Action.NOTHING;
}
else {
a11 = Action.JOIN;
string6 = Realms.getLocalizedString("mco.configure.world.slot.tooltip.active");
}
}
else if (boolean10) {
if (realmsServer2.expired) {
a11 = Action.NOTHING;
}
else {
a11 = Action.SWITCH_SLOT;
string6 = Realms.getLocalizedString("mco.configure.world.slot.tooltip.minigame");
}
}
else {
a11 = Action.SWITCH_SLOT;
string6 = Realms.getLocalizedString("mco.configure.world.slot.tooltip");
}
this.state = new State(boolean11, string4, long6, string5, boolean12, boolean10, a11, string6);
String string7;
if (a11 == Action.NOTHING) {
string7 = string4;
}
else if (boolean10) {
if (boolean12) {
string7 = string6;
}
else {
string7 = string6 + " " + string4 + " " + realmsServer2.minigameName;
}
}
else {
string7 = string6 + " " + string4;
}
this.setMessage(string7);
}
@Override
public void renderButton(final int integer1, final int integer2, final float float3) {
if (this.state == null) {
return;
}
final RealmsButtonProxy realmsButtonProxy5 = this.getProxy();
this.drawSlotFrame(realmsButtonProxy5.x, realmsButtonProxy5.y, integer1, integer2, this.state.isCurrentlyActiveSlot, this.state.slotName, this.slotIndex, this.state.imageId, this.state.image, this.state.empty, this.state.minigame, this.state.action, this.state.actionPrompt);
}
private void drawSlotFrame(final int integer1, final int integer2, final int integer3, final int integer4, final boolean boolean5, final String string6, final int integer7, final long long8, @Nullable final String string9, final boolean boolean10, final boolean boolean11, final Action a, @Nullable final String string13) {
final boolean boolean12 = this.getProxy().isHovered();
if (this.getProxy().isMouseOver(integer3, integer4) && string13 != null) {
this.toolTipSetter.accept(string13);
}
if (boolean11) {
RealmsTextureManager.bindWorldTemplate(String.valueOf(long8), string9);
}
else if (boolean10) {
Realms.bind("realms:textures/gui/realms/empty_frame.png");
}
else if (string9 != null && long8 != -1L) {
RealmsTextureManager.bindWorldTemplate(String.valueOf(long8), string9);
}
else if (integer7 == 1) {
Realms.bind("textures/gui/title/background/panorama_0.png");
}
else if (integer7 == 2) {
Realms.bind("textures/gui/title/background/panorama_2.png");
}
else if (integer7 == 3) {
Realms.bind("textures/gui/title/background/panorama_3.png");
}
if (boolean5) {
final float float17 = 0.85f + 0.15f * RealmsMth.cos(this.animTick * 0.2f);
GlStateManager.color4f(float17, float17, float17, 1.0f);
}
else {
GlStateManager.color4f(0.56f, 0.56f, 0.56f, 1.0f);
}
RealmsScreen.blit(integer1 + 3, integer2 + 3, 0.0f, 0.0f, 74, 74, 74, 74);
Realms.bind("realms:textures/gui/realms/slot_frame.png");
final boolean boolean13 = boolean12 && a != Action.NOTHING;
if (boolean13) {
GlStateManager.color4f(1.0f, 1.0f, 1.0f, 1.0f);
}
else if (boolean5) {
GlStateManager.color4f(0.8f, 0.8f, 0.8f, 1.0f);
}
else {
GlStateManager.color4f(0.56f, 0.56f, 0.56f, 1.0f);
}
RealmsScreen.blit(integer1, integer2, 0.0f, 0.0f, 80, 80, 80, 80);
this.drawCenteredString(string6, integer1 + 40, integer2 + 66, 16777215);
}
@Override
public void onPress() {
this.listener.onSlotClick(this.slotIndex, this.state.action, this.state.minigame, this.state.empty);
}
public enum Action {
NOTHING,
SWITCH_SLOT,
JOIN;
}
public static class State {
final boolean isCurrentlyActiveSlot;
final String slotName;
final long imageId;
public final String image;
public final boolean empty;
final boolean minigame;
public final Action action;
final String actionPrompt;
State(final boolean boolean1, final String string2, final long long3, @Nullable final String string4, final boolean boolean5, final boolean boolean6, @Nonnull final Action a, @Nullable final String string8) {
this.isCurrentlyActiveSlot = boolean1;
this.slotName = string2;
this.imageId = long3;
this.image = string4;
this.empty = boolean5;
this.minigame = boolean6;
this.action = a;
this.actionPrompt = string8;
}
}
public interface Listener {
void onSlotClick(final int integer, @Nonnull final Action a, final boolean boolean3, final boolean boolean4);
}
}

View File

@ -0,0 +1,68 @@
package com.mojang.realmsclient.gui;
import net.minecraft.realms.RealmListEntry;
import java.util.Iterator;
import net.minecraft.realms.RealmsObjectSelectionList;
import java.util.List;
public abstract class RowButton {
public final int width;
public final int height;
public final int xOffset;
public final int yOffset;
public RowButton(final int integer1, final int integer2, final int integer3, final int integer4) {
this.width = integer1;
this.height = integer2;
this.xOffset = integer3;
this.yOffset = integer4;
}
public void drawForRowAt(final int integer1, final int integer2, final int integer3, final int integer4) {
final int integer5 = integer1 + this.xOffset;
final int integer6 = integer2 + this.yOffset;
boolean boolean8 = false;
if (integer3 >= integer5 && integer3 <= integer5 + this.width && integer4 >= integer6 && integer4 <= integer6 + this.height) {
boolean8 = true;
}
this.draw(integer5, integer6, boolean8);
}
protected abstract void draw(final int integer1, final int integer2, final boolean boolean3);
public int getRight() {
return this.xOffset + this.width;
}
public int getBottom() {
return this.yOffset + this.height;
}
public abstract void onClick(final int integer);
public static void drawButtonsInRow(final List<RowButton> list, final RealmsObjectSelectionList realmsObjectSelectionList, final int integer3, final int integer4, final int integer5, final int integer6) {
for (final RowButton cwb8 : list) {
if (realmsObjectSelectionList.getRowWidth() > cwb8.getRight()) {
cwb8.drawForRowAt(integer3, integer4, integer5, integer6);
}
}
}
public static void rowButtonMouseClicked(final RealmsObjectSelectionList realmsObjectSelectionList, final RealmListEntry realmListEntry, final List<RowButton> list, final int integer, final double double5, final double double6) {
if (integer == 0) {
final int integer2 = realmsObjectSelectionList.children().indexOf(realmListEntry);
if (integer2 > -1) {
realmsObjectSelectionList.selectItem(integer2);
final int integer3 = realmsObjectSelectionList.getRowLeft();
final int integer4 = realmsObjectSelectionList.getRowTop(integer2);
final int integer5 = (int)(double5 - integer3);
final int integer6 = (int)(double6 - integer4);
for (final RowButton cwb15 : list) {
if (integer5 >= cwb15.xOffset && integer5 <= cwb15.getRight() && integer6 >= cwb15.yOffset && integer6 <= cwb15.getBottom()) {
cwb15.onClick(integer2);
}
}
}
}
}
}

View File

@ -0,0 +1,138 @@
package com.mojang.realmsclient.gui.screens;
import net.minecraft.realms.Tezzelator;
import net.minecraft.realms.RealmsSimpleScrolledSelectionList;
import java.util.Locale;
import net.minecraft.realms.RealmsGuiEventListener;
import net.minecraft.realms.AbstractRealmsButton;
import net.minecraft.realms.Realms;
import net.minecraft.realms.RealmsButton;
import java.util.Iterator;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import com.mojang.realmsclient.dto.Backup;
import net.minecraft.realms.RealmsScreen;
public class RealmsBackupInfoScreen extends RealmsScreen {
private final RealmsScreen lastScreen;
private final int BUTTON_BACK_ID = 0;
private final Backup backup;
private final List<String> keys;
private BackupInfoList backupInfoList;
String[] difficulties;
String[] gameModes;
public RealmsBackupInfoScreen(final RealmsScreen realmsScreen, final Backup backup) {
this.keys = new ArrayList<String>();
this.difficulties = new String[] { RealmsScreen.getLocalizedString("options.difficulty.peaceful"), RealmsScreen.getLocalizedString("options.difficulty.easy"), RealmsScreen.getLocalizedString("options.difficulty.normal"), RealmsScreen.getLocalizedString("options.difficulty.hard") };
this.gameModes = new String[] { RealmsScreen.getLocalizedString("selectWorld.gameMode.survival"), RealmsScreen.getLocalizedString("selectWorld.gameMode.creative"), RealmsScreen.getLocalizedString("selectWorld.gameMode.adventure") };
this.lastScreen = realmsScreen;
this.backup = backup;
if (backup.changeList != null) {
for (final Map.Entry<String, String> entry5 : backup.changeList.entrySet()) {
this.keys.add(entry5.getKey());
}
}
}
@Override
public void tick() {
}
@Override
public void init() {
this.setKeyboardHandlerSendRepeatsToGui(true);
this.buttonsAdd(new RealmsButton(0, this.width() / 2 - 100, this.height() / 4 + 120 + 24, RealmsScreen.getLocalizedString("gui.back")) {
@Override
public void onPress() {
Realms.setScreen(RealmsBackupInfoScreen.this.lastScreen);
}
});
this.addWidget(this.backupInfoList = new BackupInfoList());
this.focusOn(this.backupInfoList);
}
@Override
public void removed() {
this.setKeyboardHandlerSendRepeatsToGui(false);
}
@Override
public boolean keyPressed(final int integer1, final int integer2, final int integer3) {
if (integer1 == 256) {
Realms.setScreen(this.lastScreen);
return true;
}
return super.keyPressed(integer1, integer2, integer3);
}
@Override
public void render(final int integer1, final int integer2, final float float3) {
this.renderBackground();
this.drawCenteredString("Changes from last backup", this.width() / 2, 10, 16777215);
this.backupInfoList.render(integer1, integer2, float3);
super.render(integer1, integer2, float3);
}
private String checkForSpecificMetadata(final String string1, final String string2) {
final String string3 = string1.toLowerCase(Locale.ROOT);
if (string3.contains("game") && string3.contains("mode")) {
return this.gameModeMetadata(string2);
}
if (string3.contains("game") && string3.contains("difficulty")) {
return this.gameDifficultyMetadata(string2);
}
return string2;
}
private String gameDifficultyMetadata(final String string) {
try {
return this.difficulties[Integer.parseInt(string)];
}
catch (Exception exception3) {
return "UNKNOWN";
}
}
private String gameModeMetadata(final String string) {
try {
return this.gameModes[Integer.parseInt(string)];
}
catch (Exception exception3) {
return "UNKNOWN";
}
}
class BackupInfoList extends RealmsSimpleScrolledSelectionList {
public BackupInfoList() {
super(RealmsBackupInfoScreen.this.width(), RealmsBackupInfoScreen.this.height(), 32, RealmsBackupInfoScreen.this.height() - 64, 36);
}
@Override
public int getItemCount() {
return RealmsBackupInfoScreen.this.backup.changeList.size();
}
@Override
public boolean isSelectedItem(final int integer) {
return false;
}
@Override
public int getMaxPosition() {
return this.getItemCount() * 36;
}
@Override
public void renderBackground() {
}
public void renderItem(final int integer1, final int integer2, final int integer3, final int integer4, final Tezzelator tezzelator, final int integer6, final int integer7) {
final String string9 = RealmsBackupInfoScreen.this.keys.get(integer1);
RealmsBackupInfoScreen.this.drawString(string9, this.width() / 2 - 40, integer3, 10526880);
final String string10 = RealmsBackupInfoScreen.this.backup.changeList.get(string9);
RealmsBackupInfoScreen.this.drawString(RealmsBackupInfoScreen.this.checkForSpecificMetadata(string9, string10), this.width() / 2 - 40, integer3 + 12, 16777215);
}
}
}

View File

@ -0,0 +1,420 @@
package com.mojang.realmsclient.gui.screens;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.realms.RealmListEntry;
import net.minecraft.realms.RealmsObjectSelectionList;
import org.apache.logging.log4j.LogManager;
import com.mojang.realmsclient.gui.LongRunningTask;
import com.mojang.realmsclient.util.RealmsTasks;
import com.mojang.realmsclient.dto.RealmsWorldOptions;
import java.util.Date;
import net.minecraft.realms.RealmsConfirmResultListener;
import com.mojang.realmsclient.util.RealmsUtil;
import net.minecraft.realms.RealmsGuiEventListener;
import net.minecraft.realms.AbstractRealmsButton;
import com.mojang.realmsclient.gui.RealmsConstants;
import java.text.DateFormat;
import java.util.Iterator;
import com.mojang.realmsclient.exception.RealmsServiceException;
import net.minecraft.realms.Realms;
import com.mojang.realmsclient.client.RealmsClient;
import java.util.Collections;
import net.minecraft.realms.RealmsLabel;
import com.mojang.realmsclient.dto.RealmsServer;
import net.minecraft.realms.RealmsButton;
import com.mojang.realmsclient.dto.Backup;
import java.util.List;
import org.apache.logging.log4j.Logger;
import net.minecraft.realms.RealmsScreen;
public class RealmsBackupScreen extends RealmsScreen {
private static final Logger LOGGER;
private static int lastScrollPosition;
private final RealmsConfigureWorldScreen lastScreen;
private List<Backup> backups;
private String toolTip;
private BackupObjectSelectionList backupObjectSelectionList;
private int selectedBackup;
private final int slotId;
private RealmsButton downloadButton;
private RealmsButton restoreButton;
private RealmsButton changesButton;
private Boolean noBackups;
private final RealmsServer serverData;
private RealmsLabel titleLabel;
public RealmsBackupScreen(final RealmsConfigureWorldScreen cwg, final RealmsServer realmsServer, final int integer) {
this.backups = Collections.<Backup>emptyList();
this.selectedBackup = -1;
this.noBackups = false;
this.lastScreen = cwg;
this.serverData = realmsServer;
this.slotId = integer;
}
@Override
public void init() {
this.setKeyboardHandlerSendRepeatsToGui(true);
this.backupObjectSelectionList = new BackupObjectSelectionList();
if (RealmsBackupScreen.lastScrollPosition != -1) {
this.backupObjectSelectionList.scroll(RealmsBackupScreen.lastScrollPosition);
}
new Thread("Realms-fetch-backups") {
@Override
public void run() {
final RealmsClient cvm2 = RealmsClient.createRealmsClient();
try {
final List<Backup> list3 = cvm2.backupsFor(RealmsBackupScreen.this.serverData.id).backups;
final Iterator<Backup> iterator;
Backup backup4;
Realms.execute(() -> {
RealmsBackupScreen.this.backups = list3;
RealmsBackupScreen.this.noBackups = RealmsBackupScreen.this.backups.isEmpty();
RealmsBackupScreen.this.backupObjectSelectionList.clear();
RealmsBackupScreen.this.backups.iterator();
while (iterator.hasNext()) {
backup4 = iterator.next();
RealmsBackupScreen.this.backupObjectSelectionList.addEntry(backup4);
}
RealmsBackupScreen.this.generateChangeList();
});
}
catch (RealmsServiceException cvu3) {
RealmsBackupScreen.LOGGER.error("Couldn't request backups", (Throwable)cvu3);
}
}
}.start();
this.postInit();
}
private void generateChangeList() {
if (this.backups.size() <= 1) {
return;
}
for (int integer2 = 0; integer2 < this.backups.size() - 1; ++integer2) {
final Backup backup3 = this.backups.get(integer2);
final Backup backup4 = this.backups.get(integer2 + 1);
if (!backup3.metadata.isEmpty()) {
if (!backup4.metadata.isEmpty()) {
for (final String string6 : backup3.metadata.keySet()) {
if (!string6.contains("Uploaded") && backup4.metadata.containsKey(string6)) {
if (backup3.metadata.get(string6).equals(backup4.metadata.get(string6))) {
continue;
}
this.addToChangeList(backup3, string6);
}
else {
this.addToChangeList(backup3, string6);
}
}
}
}
}
}
private void addToChangeList(final Backup backup, final String string) {
if (string.contains("Uploaded")) {
final String string2 = DateFormat.getDateTimeInstance(3, 3).format(backup.lastModifiedDate);
backup.changeList.put(string, string2);
backup.setUploadedVersion(true);
}
else {
backup.changeList.put(string, backup.metadata.get(string));
}
}
private void postInit() {
this.buttonsAdd(this.downloadButton = new RealmsButton(2, this.width() - 135, RealmsConstants.row(1), 120, 20, RealmsScreen.getLocalizedString("mco.backup.button.download")) {
@Override
public void onPress() {
RealmsBackupScreen.this.downloadClicked();
}
});
this.buttonsAdd(this.restoreButton = new RealmsButton(3, this.width() - 135, RealmsConstants.row(3), 120, 20, RealmsScreen.getLocalizedString("mco.backup.button.restore")) {
@Override
public void onPress() {
RealmsBackupScreen.this.restoreClicked(RealmsBackupScreen.this.selectedBackup);
}
});
this.buttonsAdd(this.changesButton = new RealmsButton(4, this.width() - 135, RealmsConstants.row(5), 120, 20, RealmsScreen.getLocalizedString("mco.backup.changes.tooltip")) {
@Override
public void onPress() {
Realms.setScreen(new RealmsBackupInfoScreen(RealmsBackupScreen.this, RealmsBackupScreen.this.backups.get(RealmsBackupScreen.this.selectedBackup)));
RealmsBackupScreen.this.selectedBackup = -1;
}
});
this.buttonsAdd(new RealmsButton(0, this.width() - 100, this.height() - 35, 85, 20, RealmsScreen.getLocalizedString("gui.back")) {
@Override
public void onPress() {
Realms.setScreen(RealmsBackupScreen.this.lastScreen);
}
});
this.addWidget(this.backupObjectSelectionList);
this.addWidget(this.titleLabel = new RealmsLabel(RealmsScreen.getLocalizedString("mco.configure.world.backup"), this.width() / 2, 12, 16777215));
this.focusOn(this.backupObjectSelectionList);
this.updateButtonStates();
this.narrateLabels();
}
private void updateButtonStates() {
this.restoreButton.setVisible(this.shouldRestoreButtonBeVisible());
this.changesButton.setVisible(this.shouldChangesButtonBeVisible());
}
private boolean shouldChangesButtonBeVisible() {
return this.selectedBackup != -1 && !this.backups.get(this.selectedBackup).changeList.isEmpty();
}
private boolean shouldRestoreButtonBeVisible() {
return this.selectedBackup != -1 && !this.serverData.expired;
}
@Override
public void tick() {
super.tick();
}
@Override
public boolean keyPressed(final int integer1, final int integer2, final int integer3) {
if (integer1 == 256) {
Realms.setScreen(this.lastScreen);
return true;
}
return super.keyPressed(integer1, integer2, integer3);
}
private void restoreClicked(final int integer) {
if (integer >= 0 && integer < this.backups.size() && !this.serverData.expired) {
this.selectedBackup = integer;
final Date date3 = this.backups.get(integer).lastModifiedDate;
final String string4 = DateFormat.getDateTimeInstance(3, 3).format(date3);
final String string5 = RealmsUtil.convertToAgePresentation(System.currentTimeMillis() - date3.getTime());
final String string6 = RealmsScreen.getLocalizedString("mco.configure.world.restore.question.line1", string4, string5);
final String string7 = RealmsScreen.getLocalizedString("mco.configure.world.restore.question.line2");
Realms.setScreen(new RealmsLongConfirmationScreen(this, RealmsLongConfirmationScreen.Type.Warning, string6, string7, true, 1));
}
}
private void downloadClicked() {
final String string2 = RealmsScreen.getLocalizedString("mco.configure.world.restore.download.question.line1");
final String string3 = RealmsScreen.getLocalizedString("mco.configure.world.restore.download.question.line2");
Realms.setScreen(new RealmsLongConfirmationScreen(this, RealmsLongConfirmationScreen.Type.Info, string2, string3, true, 2));
}
private void downloadWorldData() {
final RealmsTasks.DownloadTask b2 = new RealmsTasks.DownloadTask(this.serverData.id, this.slotId, this.serverData.name + " (" + this.serverData.slots.get(this.serverData.activeSlot).getSlotName(this.serverData.activeSlot) + ")", this);
final RealmsLongRunningMcoTaskScreen cwo3 = new RealmsLongRunningMcoTaskScreen(this.lastScreen.getNewScreen(), b2);
cwo3.start();
Realms.setScreen(cwo3);
}
@Override
public void confirmResult(final boolean boolean1, final int integer) {
if (boolean1 && integer == 1) {
this.restore();
}
else if (integer == 1) {
this.selectedBackup = -1;
Realms.setScreen(this);
}
else if (boolean1 && integer == 2) {
this.downloadWorldData();
}
else {
Realms.setScreen(this);
}
}
private void restore() {
final Backup backup2 = this.backups.get(this.selectedBackup);
this.selectedBackup = -1;
final RealmsTasks.RestoreTask g3 = new RealmsTasks.RestoreTask(backup2, this.serverData.id, this.lastScreen);
final RealmsLongRunningMcoTaskScreen cwo4 = new RealmsLongRunningMcoTaskScreen(this.lastScreen.getNewScreen(), g3);
cwo4.start();
Realms.setScreen(cwo4);
}
@Override
public void render(final int integer1, final int integer2, final float float3) {
this.toolTip = null;
this.renderBackground();
this.backupObjectSelectionList.render(integer1, integer2, float3);
this.titleLabel.render(this);
this.drawString(RealmsScreen.getLocalizedString("mco.configure.world.backup"), (this.width() - 150) / 2 - 90, 20, 10526880);
if (this.noBackups) {
this.drawString(RealmsScreen.getLocalizedString("mco.backup.nobackups"), 20, this.height() / 2 - 10, 16777215);
}
this.downloadButton.active(!this.noBackups);
super.render(integer1, integer2, float3);
if (this.toolTip != null) {
this.renderMousehoverTooltip(this.toolTip, integer1, integer2);
}
}
protected void renderMousehoverTooltip(final String string, final int integer2, final int integer3) {
if (string == null) {
return;
}
final int integer4 = integer2 + 12;
final int integer5 = integer3 - 12;
final int integer6 = this.fontWidth(string);
this.fillGradient(integer4 - 3, integer5 - 3, integer4 + integer6 + 3, integer5 + 8 + 3, -1073741824, -1073741824);
this.fontDrawShadow(string, integer4, integer5, 16777215);
}
static {
LOGGER = LogManager.getLogger();
RealmsBackupScreen.lastScrollPosition = -1;
}
class BackupObjectSelectionList extends RealmsObjectSelectionList {
public BackupObjectSelectionList() {
super(RealmsBackupScreen.this.width() - 150, RealmsBackupScreen.this.height(), 32, RealmsBackupScreen.this.height() - 15, 36);
}
public void addEntry(final Backup backup) {
this.addEntry(new BackupObjectSelectionListEntry(backup));
}
@Override
public int getRowWidth() {
return (int)(this.width() * 0.93);
}
@Override
public boolean isFocused() {
return RealmsBackupScreen.this.isFocused(this);
}
@Override
public int getItemCount() {
return RealmsBackupScreen.this.backups.size();
}
@Override
public int getMaxPosition() {
return this.getItemCount() * 36;
}
@Override
public void renderBackground() {
RealmsBackupScreen.this.renderBackground();
}
@Override
public boolean mouseClicked(final double double1, final double double2, final int integer) {
if (integer != 0) {
return false;
}
if (double1 < this.getScrollbarPosition() && double2 >= this.y0() && double2 <= this.y1()) {
final int integer2 = this.width() / 2 - 92;
final int integer3 = this.width();
final int integer4 = (int)Math.floor(double2 - this.y0()) - this.headerHeight() + this.getScroll();
final int integer5 = integer4 / this.itemHeight();
if (double1 >= integer2 && double1 <= integer3 && integer5 >= 0 && integer4 >= 0 && integer5 < this.getItemCount()) {
this.selectItem(integer5);
this.itemClicked(integer4, integer5, double1, double2, this.width());
}
return true;
}
return false;
}
@Override
public int getScrollbarPosition() {
return this.width() - 5;
}
@Override
public void itemClicked(final int integer1, final int integer2, final double double3, final double double4, final int integer5) {
final int integer6 = this.width() - 35;
final int integer7 = integer2 * this.itemHeight() + 36 - this.getScroll();
final int integer8 = integer6 + 10;
final int integer9 = integer7 - 3;
if (double3 >= integer6 && double3 <= integer6 + 9 && double4 >= integer7 && double4 <= integer7 + 9) {
if (!RealmsBackupScreen.this.backups.get(integer2).changeList.isEmpty()) {
RealmsBackupScreen.this.selectedBackup = -1;
RealmsBackupScreen.lastScrollPosition = this.getScroll();
Realms.setScreen(new RealmsBackupInfoScreen(RealmsBackupScreen.this, RealmsBackupScreen.this.backups.get(integer2)));
}
}
else if (double3 >= integer8 && double3 < integer8 + 13 && double4 >= integer9 && double4 < integer9 + 15) {
RealmsBackupScreen.lastScrollPosition = this.getScroll();
RealmsBackupScreen.this.restoreClicked(integer2);
}
}
@Override
public void selectItem(final int integer) {
this.setSelected(integer);
if (integer != -1) {
Realms.narrateNow(RealmsScreen.getLocalizedString("narrator.select", RealmsBackupScreen.this.backups.get(integer).lastModifiedDate.toString()));
}
this.selectInviteListItem(integer);
}
public void selectInviteListItem(final int integer) {
RealmsBackupScreen.this.selectedBackup = integer;
RealmsBackupScreen.this.updateButtonStates();
}
}
class BackupObjectSelectionListEntry extends RealmListEntry {
final Backup mBackup;
public BackupObjectSelectionListEntry(final Backup backup) {
this.mBackup = backup;
}
@Override
public void render(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 float float9) {
this.renderBackupItem(this.mBackup, integer3 - 40, integer2, integer6, integer7);
}
private void renderBackupItem(final Backup backup, final int integer2, final int integer3, final int integer4, final int integer5) {
final int integer6 = backup.isUploadedVersion() ? -8388737 : 16777215;
RealmsBackupScreen.this.drawString("Backup (" + RealmsUtil.convertToAgePresentation(System.currentTimeMillis() - backup.lastModifiedDate.getTime()) + ")", integer2 + 40, integer3 + 1, integer6);
RealmsBackupScreen.this.drawString(this.getMediumDatePresentation(backup.lastModifiedDate), integer2 + 40, integer3 + 12, 5000268);
final int integer7 = RealmsBackupScreen.this.width() - 175;
final int integer8 = -3;
final int integer9 = integer7 - 10;
final int integer10 = 0;
if (!RealmsBackupScreen.this.serverData.expired) {
this.drawRestore(integer7, integer3 - 3, integer4, integer5);
}
if (!backup.changeList.isEmpty()) {
this.drawInfo(integer9, integer3 + 0, integer4, integer5);
}
}
private String getMediumDatePresentation(final Date date) {
return DateFormat.getDateTimeInstance(3, 3).format(date);
}
private void drawRestore(final int integer1, final int integer2, final int integer3, final int integer4) {
final boolean boolean6 = integer3 >= integer1 && integer3 <= integer1 + 12 && integer4 >= integer2 && integer4 <= integer2 + 14 && integer4 < RealmsBackupScreen.this.height() - 15 && integer4 > 32;
RealmsScreen.bind("realms:textures/gui/realms/restore_icon.png");
GlStateManager.color4f(1.0f, 1.0f, 1.0f, 1.0f);
GlStateManager.pushMatrix();
GlStateManager.scalef(0.5f, 0.5f, 0.5f);
RealmsScreen.blit(integer1 * 2, integer2 * 2, 0.0f, boolean6 ? 28.0f : 0.0f, 23, 28, 23, 56);
GlStateManager.popMatrix();
if (boolean6) {
RealmsBackupScreen.this.toolTip = RealmsScreen.getLocalizedString("mco.backup.button.restore");
}
}
private void drawInfo(final int integer1, final int integer2, final int integer3, final int integer4) {
final boolean boolean6 = integer3 >= integer1 && integer3 <= integer1 + 8 && integer4 >= integer2 && integer4 <= integer2 + 8 && integer4 < RealmsBackupScreen.this.height() - 15 && integer4 > 32;
RealmsScreen.bind("realms:textures/gui/realms/plus_icon.png");
GlStateManager.color4f(1.0f, 1.0f, 1.0f, 1.0f);
GlStateManager.pushMatrix();
GlStateManager.scalef(0.5f, 0.5f, 0.5f);
RealmsScreen.blit(integer1 * 2, integer2 * 2, 0.0f, boolean6 ? 15.0f : 0.0f, 15, 15, 15, 30);
GlStateManager.popMatrix();
if (boolean6) {
RealmsBackupScreen.this.toolTip = RealmsScreen.getLocalizedString("mco.backup.changes.tooltip");
}
}
}
}

View File

@ -0,0 +1,327 @@
package com.mojang.realmsclient.gui.screens;
import java.util.Arrays;
import org.apache.logging.log4j.LogManager;
import net.minecraft.realms.RealmsConfirmResultListener;
import net.minecraft.realms.RealmsMth;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.realmsclient.util.RealmsTextureManager;
import com.mojang.realmsclient.dto.WorldDownload;
import com.mojang.realmsclient.gui.LongRunningTask;
import com.mojang.realmsclient.util.RealmsTasks;
import java.io.IOException;
import com.mojang.realmsclient.exception.RealmsServiceException;
import com.mojang.realmsclient.client.RealmsClient;
import java.util.Iterator;
import net.minecraft.realms.Realms;
import com.mojang.realmsclient.dto.RealmsWorldOptions;
import java.util.Map;
import net.minecraft.realms.AbstractRealmsButton;
import net.minecraft.realms.RealmsButton;
import com.mojang.realmsclient.gui.RealmsConstants;
import java.util.ArrayList;
import java.util.List;
import com.mojang.realmsclient.dto.RealmsServer;
import com.mojang.realmsclient.RealmsMainScreen;
import org.apache.logging.log4j.Logger;
import net.minecraft.realms.RealmsScreen;
public class RealmsBrokenWorldScreen extends RealmsScreen {
private static final Logger LOGGER;
private final RealmsScreen lastScreen;
private final RealmsMainScreen mainScreen;
private RealmsServer serverData;
private final long serverId;
private String title;
private final String message;
private int left_x;
private int right_x;
private final int default_button_width = 80;
private final int default_button_offset = 5;
private static final List<Integer> playButtonIds;
private static final List<Integer> resetButtonIds;
private static final List<Integer> downloadButtonIds;
private static final List<Integer> downloadConfirmationIds;
private final List<Integer> slotsThatHasBeenDownloaded;
private int animTick;
public RealmsBrokenWorldScreen(final RealmsScreen realmsScreen, final RealmsMainScreen cvi, final long long3) {
this.title = RealmsScreen.getLocalizedString("mco.brokenworld.title");
this.message = RealmsScreen.getLocalizedString("mco.brokenworld.message.line1") + "\\n" + RealmsScreen.getLocalizedString("mco.brokenworld.message.line2");
this.slotsThatHasBeenDownloaded = new ArrayList<Integer>();
this.lastScreen = realmsScreen;
this.mainScreen = cvi;
this.serverId = long3;
}
public void setTitle(final String string) {
this.title = string;
}
@Override
public void init() {
this.left_x = this.width() / 2 - 150;
this.right_x = this.width() / 2 + 190;
this.buttonsAdd(new RealmsButton(0, this.right_x - 80 + 8, RealmsConstants.row(13) - 5, 70, 20, RealmsScreen.getLocalizedString("gui.back")) {
@Override
public void onPress() {
RealmsBrokenWorldScreen.this.backButtonClicked();
}
});
if (this.serverData == null) {
this.fetchServerData(this.serverId);
}
else {
this.addButtons();
}
this.setKeyboardHandlerSendRepeatsToGui(true);
}
public void addButtons() {
for (final Map.Entry<Integer, RealmsWorldOptions> entry3 : this.serverData.slots.entrySet()) {
final RealmsWorldOptions realmsWorldOptions4 = entry3.getValue();
final boolean boolean5 = entry3.getKey() != this.serverData.activeSlot || this.serverData.worldType.equals(RealmsServer.WorldType.MINIGAME);
RealmsButton realmsButton6;
if (boolean5) {
realmsButton6 = new PlayButton(RealmsBrokenWorldScreen.playButtonIds.get(entry3.getKey() - 1), this.getFramePositionX(entry3.getKey()), RealmsScreen.getLocalizedString("mco.brokenworld.play"));
}
else {
realmsButton6 = new DownloadButton(RealmsBrokenWorldScreen.downloadButtonIds.get(entry3.getKey() - 1), this.getFramePositionX(entry3.getKey()), RealmsScreen.getLocalizedString("mco.brokenworld.download"));
}
if (this.slotsThatHasBeenDownloaded.contains(entry3.getKey())) {
realmsButton6.active(false);
realmsButton6.setMessage(RealmsScreen.getLocalizedString("mco.brokenworld.downloaded"));
}
this.buttonsAdd(realmsButton6);
this.buttonsAdd(new RealmsButton((int)RealmsBrokenWorldScreen.resetButtonIds.get(entry3.getKey() - 1), this.getFramePositionX(entry3.getKey()), RealmsConstants.row(10), 80, 20, RealmsScreen.getLocalizedString("mco.brokenworld.reset")) {
@Override
public void onPress() {
final int integer2 = RealmsBrokenWorldScreen.resetButtonIds.indexOf(this.id()) + 1;
final RealmsResetWorldScreen cwu3 = new RealmsResetWorldScreen(RealmsBrokenWorldScreen.this, RealmsBrokenWorldScreen.this.serverData, RealmsBrokenWorldScreen.this);
if (integer2 != RealmsBrokenWorldScreen.this.serverData.activeSlot || RealmsBrokenWorldScreen.this.serverData.worldType.equals(RealmsServer.WorldType.MINIGAME)) {
cwu3.setSlot(integer2);
}
cwu3.setConfirmationId(14);
Realms.setScreen(cwu3);
}
});
}
}
@Override
public void tick() {
++this.animTick;
}
@Override
public void render(final int integer1, final int integer2, final float float3) {
this.renderBackground();
super.render(integer1, integer2, float3);
this.drawCenteredString(this.title, this.width() / 2, 17, 16777215);
final String[] arr5 = this.message.split("\\\\n");
for (int integer3 = 0; integer3 < arr5.length; ++integer3) {
this.drawCenteredString(arr5[integer3], this.width() / 2, RealmsConstants.row(-1) + 3 + integer3 * 12, 10526880);
}
if (this.serverData == null) {
return;
}
for (final Map.Entry<Integer, RealmsWorldOptions> entry7 : this.serverData.slots.entrySet()) {
if (entry7.getValue().templateImage != null && entry7.getValue().templateId != -1L) {
this.drawSlotFrame(this.getFramePositionX(entry7.getKey()), RealmsConstants.row(1) + 5, integer1, integer2, this.serverData.activeSlot == entry7.getKey() && !this.isMinigame(), entry7.getValue().getSlotName(entry7.getKey()), entry7.getKey(), entry7.getValue().templateId, entry7.getValue().templateImage, entry7.getValue().empty);
}
else {
this.drawSlotFrame(this.getFramePositionX(entry7.getKey()), RealmsConstants.row(1) + 5, integer1, integer2, this.serverData.activeSlot == entry7.getKey() && !this.isMinigame(), entry7.getValue().getSlotName(entry7.getKey()), entry7.getKey(), -1L, null, entry7.getValue().empty);
}
}
}
private int getFramePositionX(final int integer) {
return this.left_x + (integer - 1) * 110;
}
@Override
public void removed() {
this.setKeyboardHandlerSendRepeatsToGui(false);
}
@Override
public boolean keyPressed(final int integer1, final int integer2, final int integer3) {
if (integer1 == 256) {
this.backButtonClicked();
return true;
}
return super.keyPressed(integer1, integer2, integer3);
}
private void backButtonClicked() {
Realms.setScreen(this.lastScreen);
}
private void fetchServerData(final long long1) {
new Thread() {
@Override
public void run() {
final RealmsClient cvm2 = RealmsClient.createRealmsClient();
try {
RealmsBrokenWorldScreen.this.serverData = cvm2.getOwnWorld(long1);
RealmsBrokenWorldScreen.this.addButtons();
}
catch (RealmsServiceException cvu3) {
RealmsBrokenWorldScreen.LOGGER.error("Couldn't get own world");
Realms.setScreen(new RealmsGenericErrorScreen(cvu3.getMessage(), RealmsBrokenWorldScreen.this.lastScreen));
}
catch (IOException iOException3) {
RealmsBrokenWorldScreen.LOGGER.error("Couldn't parse response getting own world");
}
}
}.start();
}
@Override
public void confirmResult(final boolean boolean1, final int integer) {
if (!boolean1) {
Realms.setScreen(this);
return;
}
if (integer == 13 || integer == 14) {
new Thread() {
@Override
public void run() {
final RealmsClient cvm2 = RealmsClient.createRealmsClient();
if (RealmsBrokenWorldScreen.this.serverData.state.equals(RealmsServer.State.CLOSED)) {
final RealmsTasks.OpenServerTask c3 = new RealmsTasks.OpenServerTask(RealmsBrokenWorldScreen.this.serverData, RealmsBrokenWorldScreen.this, RealmsBrokenWorldScreen.this.lastScreen, true);
final RealmsLongRunningMcoTaskScreen cwo4 = new RealmsLongRunningMcoTaskScreen(RealmsBrokenWorldScreen.this, c3);
cwo4.start();
Realms.setScreen(cwo4);
}
else {
try {
RealmsBrokenWorldScreen.this.mainScreen.newScreen().play(cvm2.getOwnWorld(RealmsBrokenWorldScreen.this.serverId), RealmsBrokenWorldScreen.this);
}
catch (RealmsServiceException cvu3) {
RealmsBrokenWorldScreen.LOGGER.error("Couldn't get own world");
Realms.setScreen(RealmsBrokenWorldScreen.this.lastScreen);
}
catch (IOException iOException3) {
RealmsBrokenWorldScreen.LOGGER.error("Couldn't parse response getting own world");
Realms.setScreen(RealmsBrokenWorldScreen.this.lastScreen);
}
}
}
}.start();
}
else if (RealmsBrokenWorldScreen.downloadButtonIds.contains(integer)) {
this.downloadWorld(RealmsBrokenWorldScreen.downloadButtonIds.indexOf(integer) + 1);
}
else if (RealmsBrokenWorldScreen.downloadConfirmationIds.contains(integer)) {
this.slotsThatHasBeenDownloaded.add(RealmsBrokenWorldScreen.downloadConfirmationIds.indexOf(integer) + 1);
this.childrenClear();
this.addButtons();
}
}
private void downloadWorld(final int integer) {
final RealmsClient cvm3 = RealmsClient.createRealmsClient();
try {
final WorldDownload worldDownload4 = cvm3.download(this.serverData.id, integer);
final RealmsDownloadLatestWorldScreen cwk5 = new RealmsDownloadLatestWorldScreen(this, worldDownload4, this.serverData.name + " (" + this.serverData.slots.get(integer).getSlotName(integer) + ")");
cwk5.setConfirmationId(RealmsBrokenWorldScreen.downloadConfirmationIds.get(integer - 1));
Realms.setScreen(cwk5);
}
catch (RealmsServiceException cvu4) {
RealmsBrokenWorldScreen.LOGGER.error("Couldn't download world data");
Realms.setScreen(new RealmsGenericErrorScreen(cvu4, this));
}
}
private boolean isMinigame() {
return this.serverData != null && this.serverData.worldType.equals(RealmsServer.WorldType.MINIGAME);
}
private void drawSlotFrame(final int integer1, final int integer2, final int integer3, final int integer4, final boolean boolean5, final String string6, final int integer7, final long long8, final String string9, final boolean boolean10) {
if (boolean10) {
RealmsScreen.bind("realms:textures/gui/realms/empty_frame.png");
}
else if (string9 != null && long8 != -1L) {
RealmsTextureManager.bindWorldTemplate(String.valueOf(long8), string9);
}
else if (integer7 == 1) {
RealmsScreen.bind("textures/gui/title/background/panorama_0.png");
}
else if (integer7 == 2) {
RealmsScreen.bind("textures/gui/title/background/panorama_2.png");
}
else if (integer7 == 3) {
RealmsScreen.bind("textures/gui/title/background/panorama_3.png");
}
else {
RealmsTextureManager.bindWorldTemplate(String.valueOf(this.serverData.minigameId), this.serverData.minigameImage);
}
if (!boolean5) {
GlStateManager.color4f(0.56f, 0.56f, 0.56f, 1.0f);
}
else if (boolean5) {
final float float13 = 0.9f + 0.1f * RealmsMth.cos(this.animTick * 0.2f);
GlStateManager.color4f(float13, float13, float13, 1.0f);
}
RealmsScreen.blit(integer1 + 3, integer2 + 3, 0.0f, 0.0f, 74, 74, 74, 74);
RealmsScreen.bind("realms:textures/gui/realms/slot_frame.png");
if (boolean5) {
GlStateManager.color4f(1.0f, 1.0f, 1.0f, 1.0f);
}
else {
GlStateManager.color4f(0.56f, 0.56f, 0.56f, 1.0f);
}
RealmsScreen.blit(integer1, integer2, 0.0f, 0.0f, 80, 80, 80, 80);
this.drawCenteredString(string6, integer1 + 40, integer2 + 66, 16777215);
}
private void switchSlot(final int integer) {
final RealmsTasks.SwitchSlotTask i3 = new RealmsTasks.SwitchSlotTask(this.serverData.id, integer, this, 13);
final RealmsLongRunningMcoTaskScreen cwo4 = new RealmsLongRunningMcoTaskScreen(this.lastScreen, i3);
cwo4.start();
Realms.setScreen(cwo4);
}
static {
LOGGER = LogManager.getLogger();
playButtonIds = Arrays.<Integer>asList(1, 2, 3);
resetButtonIds = Arrays.<Integer>asList(4, 5, 6);
downloadButtonIds = Arrays.<Integer>asList(7, 8, 9);
downloadConfirmationIds = Arrays.<Integer>asList(10, 11, 12);
}
class PlayButton extends RealmsButton {
public PlayButton(final int integer2, final int integer3, final String string) {
super(integer2, integer3, RealmsConstants.row(8), 80, 20, string);
}
@Override
public void onPress() {
final int integer2 = RealmsBrokenWorldScreen.playButtonIds.indexOf(this.id()) + 1;
if (RealmsBrokenWorldScreen.this.serverData.slots.get(integer2).empty) {
final RealmsResetWorldScreen cwu3 = new RealmsResetWorldScreen(RealmsBrokenWorldScreen.this, RealmsBrokenWorldScreen.this.serverData, RealmsBrokenWorldScreen.this, RealmsScreen.getLocalizedString("mco.configure.world.switch.slot"), RealmsScreen.getLocalizedString("mco.configure.world.switch.slot.subtitle"), 10526880, RealmsScreen.getLocalizedString("gui.cancel"));
cwu3.setSlot(integer2);
cwu3.setResetTitle(RealmsScreen.getLocalizedString("mco.create.world.reset.title"));
cwu3.setConfirmationId(14);
Realms.setScreen(cwu3);
}
else {
RealmsBrokenWorldScreen.this.switchSlot(integer2);
}
}
}
class DownloadButton extends RealmsButton {
public DownloadButton(final int integer2, final int integer3, final String string) {
super(integer2, integer3, RealmsConstants.row(8), 80, 20, string);
}
@Override
public void onPress() {
final String string2 = RealmsScreen.getLocalizedString("mco.configure.world.restore.download.question.line1");
final String string3 = RealmsScreen.getLocalizedString("mco.configure.world.restore.download.question.line2");
Realms.setScreen(new RealmsLongConfirmationScreen(RealmsBrokenWorldScreen.this, RealmsLongConfirmationScreen.Type.Info, string2, string3, true, this.id()));
}
}
}

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