base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
package net.minecraft.client;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class AnvilConverterException extends Exception
{
public AnvilConverterException(String exceptionMessage)
{
super(exceptionMessage);
}
}

View File

@@ -0,0 +1,13 @@
package net.minecraft.client;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ClientBrandRetriever
{
public static String getClientModName()
{
return net.minecraftforge.fml.common.FMLCommonHandler.instance().getModName();
}
}

View File

@@ -0,0 +1,228 @@
package net.minecraft.client;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.util.IProgressUpdate;
import net.minecraft.util.MinecraftError;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class LoadingScreenRenderer implements IProgressUpdate
{
private String message = "";
/** A reference to the Minecraft object. */
private final Minecraft mc;
/** The text currently displayed (i.e. the argument to the last call to printText or displayString) */
private String currentlyDisplayedText = "";
/** The system's time represented in milliseconds. */
private long systemTime = Minecraft.getSystemTime();
/** True if the loading ended with a success */
private boolean loadingSuccess;
private final ScaledResolution scaledResolution;
private final Framebuffer framebuffer;
public LoadingScreenRenderer(Minecraft mcIn)
{
this.mc = mcIn;
this.scaledResolution = new ScaledResolution(mcIn);
this.framebuffer = new Framebuffer(mcIn.displayWidth, mcIn.displayHeight, false);
this.framebuffer.setFramebufferFilter(9728);
}
/**
* this string, followed by "working..." and then the "% complete" are the 3 lines shown. This resets progress to 0,
* and the WorkingString to "working...".
*/
public void resetProgressAndMessage(String message)
{
this.loadingSuccess = false;
this.displayString(message);
}
/**
* Shows the 'Saving level' string.
*/
public void displaySavingString(String message)
{
this.loadingSuccess = true;
this.displayString(message);
}
private void displayString(String message)
{
this.currentlyDisplayedText = message;
if (!this.mc.running)
{
if (!this.loadingSuccess)
{
throw new MinecraftError();
}
}
else
{
GlStateManager.clear(256);
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
if (OpenGlHelper.isFramebufferEnabled())
{
int i = this.scaledResolution.getScaleFactor();
GlStateManager.ortho(0.0D, (double)(this.scaledResolution.getScaledWidth() * i), (double)(this.scaledResolution.getScaledHeight() * i), 0.0D, 100.0D, 300.0D);
}
else
{
ScaledResolution scaledresolution = new ScaledResolution(this.mc);
GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 100.0D, 300.0D);
}
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
GlStateManager.translate(0.0F, 0.0F, -200.0F);
}
}
/**
* Displays a string on the loading screen supposed to indicate what is being done currently.
*/
public void displayLoadingString(String message)
{
if (!this.mc.running)
{
if (!this.loadingSuccess)
{
throw new MinecraftError();
}
}
else
{
this.systemTime = 0L;
this.message = message;
this.setLoadingProgress(-1);
this.systemTime = 0L;
}
}
/**
* Updates the progress bar on the loading screen to the specified amount.
*/
public void setLoadingProgress(int progress)
{
if (!this.mc.running)
{
if (!this.loadingSuccess)
{
throw new MinecraftError();
}
}
else
{
long i = Minecraft.getSystemTime();
if (i - this.systemTime >= 100L)
{
this.systemTime = i;
ScaledResolution scaledresolution = new ScaledResolution(this.mc);
int j = scaledresolution.getScaleFactor();
int k = scaledresolution.getScaledWidth();
int l = scaledresolution.getScaledHeight();
if (OpenGlHelper.isFramebufferEnabled())
{
this.framebuffer.framebufferClear();
}
else
{
GlStateManager.clear(256);
}
this.framebuffer.bindFramebuffer(false);
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 100.0D, 300.0D);
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
GlStateManager.translate(0.0F, 0.0F, -200.0F);
if (!OpenGlHelper.isFramebufferEnabled())
{
GlStateManager.clear(16640);
}
try
{
if (!net.minecraftforge.fml.client.FMLClientHandler.instance().handleLoadingScreen(scaledresolution)) //FML Don't render while FML's pre-screen is rendering
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
float f = 32.0F;
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos(0.0D, (double)l, 0.0D).tex(0.0D, (double)((float)l / 32.0F)).color(64, 64, 64, 255).endVertex();
bufferbuilder.pos((double)k, (double)l, 0.0D).tex((double)((float)k / 32.0F), (double)((float)l / 32.0F)).color(64, 64, 64, 255).endVertex();
bufferbuilder.pos((double)k, 0.0D, 0.0D).tex((double)((float)k / 32.0F), 0.0D).color(64, 64, 64, 255).endVertex();
bufferbuilder.pos(0.0D, 0.0D, 0.0D).tex(0.0D, 0.0D).color(64, 64, 64, 255).endVertex();
tessellator.draw();
if (progress >= 0)
{
int i1 = 100;
int j1 = 2;
int k1 = k / 2 - 50;
int l1 = l / 2 + 16;
GlStateManager.disableTexture2D();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
bufferbuilder.pos((double)k1, (double)l1, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)k1, (double)(l1 + 2), 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)(k1 + 100), (double)(l1 + 2), 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)(k1 + 100), (double)l1, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)k1, (double)l1, 0.0D).color(128, 255, 128, 255).endVertex();
bufferbuilder.pos((double)k1, (double)(l1 + 2), 0.0D).color(128, 255, 128, 255).endVertex();
bufferbuilder.pos((double)(k1 + progress), (double)(l1 + 2), 0.0D).color(128, 255, 128, 255).endVertex();
bufferbuilder.pos((double)(k1 + progress), (double)l1, 0.0D).color(128, 255, 128, 255).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
}
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
this.mc.fontRenderer.drawStringWithShadow(this.currentlyDisplayedText, (float)((k - this.mc.fontRenderer.getStringWidth(this.currentlyDisplayedText)) / 2), (float)(l / 2 - 4 - 16), 16777215);
this.mc.fontRenderer.drawStringWithShadow(this.message, (float)((k - this.mc.fontRenderer.getStringWidth(this.message)) / 2), (float)(l / 2 - 4 + 8), 16777215);
}
}
catch (java.io.IOException e)
{
throw new RuntimeException(e);
} //FML End
this.framebuffer.unbindFramebuffer();
if (OpenGlHelper.isFramebufferEnabled())
{
this.framebuffer.framebufferRender(k * j, l * j);
}
this.mc.updateDisplay();
try
{
Thread.yield();
}
catch (Exception var15)
{
;
}
}
}
}
public void setDoneWorking()
{
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,74 @@
package net.minecraft.client.audio;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ElytraSound extends MovingSound
{
private final EntityPlayerSP player;
private int time;
public ElytraSound(EntityPlayerSP p_i47113_1_)
{
super(SoundEvents.ITEM_ELYTRA_FLYING, SoundCategory.PLAYERS);
this.player = p_i47113_1_;
this.repeat = true;
this.repeatDelay = 0;
this.volume = 0.1F;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
++this.time;
if (!this.player.isDead && (this.time <= 20 || this.player.isElytraFlying()))
{
this.xPosF = (float)this.player.posX;
this.yPosF = (float)this.player.posY;
this.zPosF = (float)this.player.posZ;
float f = MathHelper.sqrt(this.player.motionX * this.player.motionX + this.player.motionZ * this.player.motionZ + this.player.motionY * this.player.motionY);
float f1 = f / 2.0F;
if ((double)f >= 0.01D)
{
this.volume = MathHelper.clamp(f1 * f1, 0.0F, 1.0F);
}
else
{
this.volume = 0.0F;
}
if (this.time < 20)
{
this.volume = 0.0F;
}
else if (this.time < 40)
{
this.volume = (float)((double)this.volume * ((double)(this.time - 20) / 20.0D));
}
float f2 = 0.8F;
if (this.volume > 0.8F)
{
this.pitch = 1.0F + (this.volume - 0.8F);
}
else
{
this.pitch = 1.0F;
}
}
else
{
this.donePlaying = true;
}
}
}

View File

@@ -0,0 +1,42 @@
package net.minecraft.client.audio;
import net.minecraft.entity.monster.EntityGuardian;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.SoundCategory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuardianSound extends MovingSound
{
private final EntityGuardian guardian;
public GuardianSound(EntityGuardian guardian)
{
super(SoundEvents.ENTITY_GUARDIAN_ATTACK, SoundCategory.HOSTILE);
this.guardian = guardian;
this.attenuationType = ISound.AttenuationType.NONE;
this.repeat = true;
this.repeatDelay = 0;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
if (!this.guardian.isDead && this.guardian.hasTargetedEntity())
{
this.xPosF = (float)this.guardian.posX;
this.yPosF = (float)this.guardian.posY;
this.zPosF = (float)this.guardian.posZ;
float f = this.guardian.getAttackAnimationScale(0.0F);
this.volume = 0.0F + 1.0F * f * f;
this.pitch = 0.7F + 0.5F * f;
}
else
{
this.donePlaying = true;
}
}
}

View File

@@ -0,0 +1,55 @@
package net.minecraft.client.audio;
import javax.annotation.Nullable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface ISound
{
ResourceLocation getSoundLocation();
@Nullable
SoundEventAccessor createAccessor(SoundHandler handler);
Sound getSound();
SoundCategory getCategory();
boolean canRepeat();
int getRepeatDelay();
float getVolume();
float getPitch();
float getXPosF();
float getYPosF();
float getZPosF();
ISound.AttenuationType getAttenuationType();
@SideOnly(Side.CLIENT)
public static enum AttenuationType
{
NONE(0),
LINEAR(2);
private final int type;
private AttenuationType(int typeIn)
{
this.type = typeIn;
}
public int getTypeInt()
{
return this.type;
}
}
}

View File

@@ -0,0 +1,12 @@
package net.minecraft.client.audio;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface ISoundEventAccessor<T>
{
int getWeight();
T cloneEntry();
}

View File

@@ -0,0 +1,10 @@
package net.minecraft.client.audio;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface ISoundEventListener
{
void soundPlay(ISound soundIn, SoundEventAccessor accessor);
}

View File

@@ -0,0 +1,11 @@
package net.minecraft.client.audio;
import net.minecraft.util.ITickable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface ITickableSound extends ISound, ITickable
{
boolean isDonePlaying();
}

View File

@@ -0,0 +1,22 @@
package net.minecraft.client.audio;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class MovingSound extends PositionedSound implements ITickableSound
{
protected boolean donePlaying;
protected MovingSound(SoundEvent soundIn, SoundCategory categoryIn)
{
super(soundIn, categoryIn);
}
public boolean isDonePlaying()
{
return this.donePlaying;
}
}

View File

@@ -0,0 +1,52 @@
package net.minecraft.client.audio;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class MovingSoundMinecart extends MovingSound
{
private final EntityMinecart minecart;
private float distance = 0.0F;
public MovingSoundMinecart(EntityMinecart minecartIn)
{
super(SoundEvents.ENTITY_MINECART_RIDING, SoundCategory.NEUTRAL);
this.minecart = minecartIn;
this.repeat = true;
this.repeatDelay = 0;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
if (this.minecart.isDead)
{
this.donePlaying = true;
}
else
{
this.xPosF = (float)this.minecart.posX;
this.yPosF = (float)this.minecart.posY;
this.zPosF = (float)this.minecart.posZ;
float f = MathHelper.sqrt(this.minecart.motionX * this.minecart.motionX + this.minecart.motionZ * this.minecart.motionZ);
if ((double)f >= 0.01D)
{
this.distance = MathHelper.clamp(this.distance + 0.0025F, 0.0F, 1.0F);
this.volume = 0.0F + MathHelper.clamp(f, 0.0F, 0.5F) * 0.7F;
}
else
{
this.distance = 0.0F;
this.volume = 0.0F;
}
}
}
}

View File

@@ -0,0 +1,50 @@
package net.minecraft.client.audio;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class MovingSoundMinecartRiding extends MovingSound
{
private final EntityPlayer player;
private final EntityMinecart minecart;
public MovingSoundMinecartRiding(EntityPlayer playerRiding, EntityMinecart minecart)
{
super(SoundEvents.ENTITY_MINECART_INSIDE, SoundCategory.NEUTRAL);
this.player = playerRiding;
this.minecart = minecart;
this.attenuationType = ISound.AttenuationType.NONE;
this.repeat = true;
this.repeatDelay = 0;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
if (!this.minecart.isDead && this.player.isRiding() && this.player.getRidingEntity() == this.minecart)
{
float f = MathHelper.sqrt(this.minecart.motionX * this.minecart.motionX + this.minecart.motionZ * this.minecart.motionZ);
if ((double)f >= 0.01D)
{
this.volume = 0.0F + MathHelper.clamp(f, 0.0F, 1.0F) * 0.75F;
}
else
{
this.volume = 0.0F;
}
}
else
{
this.donePlaying = true;
}
}
}

View File

@@ -0,0 +1,111 @@
package net.minecraft.client.audio;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.ITickable;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class MusicTicker implements ITickable
{
private final Random rand = new Random();
private final Minecraft mc;
private ISound currentMusic;
private int timeUntilNextMusic = 100;
public MusicTicker(Minecraft mcIn)
{
this.mc = mcIn;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
MusicTicker.MusicType musicticker$musictype = this.mc.getAmbientMusicType();
if (this.currentMusic != null)
{
if (!musicticker$musictype.getMusicLocation().getSoundName().equals(this.currentMusic.getSoundLocation()))
{
this.mc.getSoundHandler().stopSound(this.currentMusic);
this.timeUntilNextMusic = MathHelper.getInt(this.rand, 0, musicticker$musictype.getMinDelay() / 2);
}
if (!this.mc.getSoundHandler().isSoundPlaying(this.currentMusic))
{
this.currentMusic = null;
this.timeUntilNextMusic = Math.min(MathHelper.getInt(this.rand, musicticker$musictype.getMinDelay(), musicticker$musictype.getMaxDelay()), this.timeUntilNextMusic);
}
}
this.timeUntilNextMusic = Math.min(this.timeUntilNextMusic, musicticker$musictype.getMaxDelay());
if (this.currentMusic == null && this.timeUntilNextMusic-- <= 0)
{
this.playMusic(musicticker$musictype);
}
}
/**
* Plays a music track for the maximum allowable period of time
*/
public void playMusic(MusicTicker.MusicType requestedMusicType)
{
this.currentMusic = PositionedSoundRecord.getMusicRecord(requestedMusicType.getMusicLocation());
this.mc.getSoundHandler().playSound(this.currentMusic);
this.timeUntilNextMusic = Integer.MAX_VALUE;
}
@SideOnly(Side.CLIENT)
public static enum MusicType
{
MENU(SoundEvents.MUSIC_MENU, 20, 600),
GAME(SoundEvents.MUSIC_GAME, 12000, 24000),
CREATIVE(SoundEvents.MUSIC_CREATIVE, 1200, 3600),
CREDITS(SoundEvents.MUSIC_CREDITS, 0, 0),
NETHER(SoundEvents.MUSIC_NETHER, 1200, 3600),
END_BOSS(SoundEvents.MUSIC_DRAGON, 0, 0),
END(SoundEvents.MUSIC_END, 6000, 24000);
private final SoundEvent musicLocation;
private final int minDelay;
private final int maxDelay;
private MusicType(SoundEvent musicLocationIn, int minDelayIn, int maxDelayIn)
{
this.musicLocation = musicLocationIn;
this.minDelay = minDelayIn;
this.maxDelay = maxDelayIn;
}
/**
* Gets the {@link SoundEvent} containing the current music track's location
*/
public SoundEvent getMusicLocation()
{
return this.musicLocation;
}
/**
* Returns the minimum delay between playing music of this type.
*/
public int getMinDelay()
{
return this.minDelay;
}
/**
* Returns the maximum delay between playing music of this type.
*/
public int getMaxDelay()
{
return this.maxDelay;
}
}
}

View File

@@ -0,0 +1,112 @@
package net.minecraft.client.audio;
import javax.annotation.Nullable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class PositionedSound implements ISound
{
protected Sound sound;
@Nullable
private SoundEventAccessor soundEvent;
protected SoundCategory category;
protected ResourceLocation positionedSoundLocation;
protected float volume;
protected float pitch;
protected float xPosF;
protected float yPosF;
protected float zPosF;
protected boolean repeat;
/** The number of ticks between repeating the sound */
protected int repeatDelay;
protected ISound.AttenuationType attenuationType;
protected PositionedSound(SoundEvent soundIn, SoundCategory categoryIn)
{
this(soundIn.getSoundName(), categoryIn);
}
protected PositionedSound(ResourceLocation soundId, SoundCategory categoryIn)
{
this.volume = 1.0F;
this.pitch = 1.0F;
this.attenuationType = ISound.AttenuationType.LINEAR;
this.positionedSoundLocation = soundId;
this.category = categoryIn;
}
public ResourceLocation getSoundLocation()
{
return this.positionedSoundLocation;
}
public SoundEventAccessor createAccessor(SoundHandler handler)
{
this.soundEvent = handler.getAccessor(this.positionedSoundLocation);
if (this.soundEvent == null)
{
this.sound = SoundHandler.MISSING_SOUND;
}
else
{
this.sound = this.soundEvent.cloneEntry();
}
return this.soundEvent;
}
public Sound getSound()
{
return this.sound;
}
public SoundCategory getCategory()
{
return this.category;
}
public boolean canRepeat()
{
return this.repeat;
}
public int getRepeatDelay()
{
return this.repeatDelay;
}
public float getVolume()
{
return this.volume * this.sound.getVolume();
}
public float getPitch()
{
return this.pitch * this.sound.getPitch();
}
public float getXPosF()
{
return this.xPosF;
}
public float getYPosF()
{
return this.yPosF;
}
public float getZPosF()
{
return this.zPosF;
}
public ISound.AttenuationType getAttenuationType()
{
return this.attenuationType;
}
}

View File

@@ -0,0 +1,60 @@
package net.minecraft.client.audio;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class PositionedSoundRecord extends PositionedSound
{
public PositionedSoundRecord(SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, BlockPos pos)
{
this(soundIn, categoryIn, volumeIn, pitchIn, (float)pos.getX() + 0.5F, (float)pos.getY() + 0.5F, (float)pos.getZ() + 0.5F);
}
public static PositionedSoundRecord getMasterRecord(SoundEvent soundIn, float pitchIn)
{
return getRecord(soundIn, pitchIn, 0.25F);
}
public static PositionedSoundRecord getRecord(SoundEvent soundIn, float pitchIn, float volumeIn)
{
return new PositionedSoundRecord(soundIn, SoundCategory.MASTER, volumeIn, pitchIn, false, 0, ISound.AttenuationType.NONE, 0.0F, 0.0F, 0.0F);
}
public static PositionedSoundRecord getMusicRecord(SoundEvent soundIn)
{
return new PositionedSoundRecord(soundIn, SoundCategory.MUSIC, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, 0.0F, 0.0F, 0.0F);
}
public static PositionedSoundRecord getRecordSoundRecord(SoundEvent soundIn, float xIn, float yIn, float zIn)
{
return new PositionedSoundRecord(soundIn, SoundCategory.RECORDS, 4.0F, 1.0F, false, 0, ISound.AttenuationType.LINEAR, xIn, yIn, zIn);
}
public PositionedSoundRecord(SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, float xIn, float yIn, float zIn)
{
this(soundIn, categoryIn, volumeIn, pitchIn, false, 0, ISound.AttenuationType.LINEAR, xIn, yIn, zIn);
}
private PositionedSoundRecord(SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, boolean repeatIn, int repeatDelayIn, ISound.AttenuationType attenuationTypeIn, float xIn, float yIn, float zIn)
{
this(soundIn.getSoundName(), categoryIn, volumeIn, pitchIn, repeatIn, repeatDelayIn, attenuationTypeIn, xIn, yIn, zIn);
}
public PositionedSoundRecord(ResourceLocation soundId, SoundCategory categoryIn, float volumeIn, float pitchIn, boolean repeatIn, int repeatDelayIn, ISound.AttenuationType attenuationTypeIn, float xIn, float yIn, float zIn)
{
super(soundId, categoryIn);
this.volume = volumeIn;
this.pitch = pitchIn;
this.xPosF = xIn;
this.yPosF = yIn;
this.zPosF = zIn;
this.repeat = repeatIn;
this.repeatDelay = repeatDelayIn;
this.attenuationType = attenuationTypeIn;
}
}

View File

@@ -0,0 +1,93 @@
package net.minecraft.client.audio;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Sound implements ISoundEventAccessor<Sound>
{
private final ResourceLocation name;
private final float volume;
private final float pitch;
private final int weight;
private final Sound.Type type;
private final boolean streaming;
public Sound(String nameIn, float volumeIn, float pitchIn, int weightIn, Sound.Type typeIn, boolean p_i46526_6_)
{
this.name = new ResourceLocation(nameIn);
this.volume = volumeIn;
this.pitch = pitchIn;
this.weight = weightIn;
this.type = typeIn;
this.streaming = p_i46526_6_;
}
public ResourceLocation getSoundLocation()
{
return this.name;
}
public ResourceLocation getSoundAsOggLocation()
{
return new ResourceLocation(this.name.getResourceDomain(), "sounds/" + this.name.getResourcePath() + ".ogg");
}
public float getVolume()
{
return this.volume;
}
public float getPitch()
{
return this.pitch;
}
public int getWeight()
{
return this.weight;
}
public Sound cloneEntry()
{
return this;
}
public Sound.Type getType()
{
return this.type;
}
public boolean isStreaming()
{
return this.streaming;
}
@SideOnly(Side.CLIENT)
public static enum Type
{
FILE("file"),
SOUND_EVENT("event");
private final String name;
private Type(String nameIn)
{
this.name = nameIn;
}
public static Sound.Type getByName(String nameIn)
{
for (Sound.Type sound$type : values())
{
if (sound$type.name.equals(nameIn))
{
return sound$type;
}
}
return null;
}
}
}

View File

@@ -0,0 +1,80 @@
package net.minecraft.client.audio;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class SoundEventAccessor implements ISoundEventAccessor<Sound>
{
private final List<ISoundEventAccessor<Sound>> accessorList = Lists.<ISoundEventAccessor<Sound>>newArrayList();
private final Random rnd = new Random();
private final ResourceLocation location;
private final ITextComponent subtitle;
public SoundEventAccessor(ResourceLocation locationIn, @Nullable String subtitleIn)
{
this.location = locationIn;
this.subtitle = subtitleIn == null ? null : new TextComponentTranslation(subtitleIn, new Object[0]);
}
public int getWeight()
{
int i = 0;
for (ISoundEventAccessor<Sound> isoundeventaccessor : this.accessorList)
{
i += isoundeventaccessor.getWeight();
}
return i;
}
public Sound cloneEntry()
{
int i = this.getWeight();
if (!this.accessorList.isEmpty() && i != 0)
{
int j = this.rnd.nextInt(i);
for (ISoundEventAccessor<Sound> isoundeventaccessor : this.accessorList)
{
j -= isoundeventaccessor.getWeight();
if (j < 0)
{
return isoundeventaccessor.cloneEntry();
}
}
return SoundHandler.MISSING_SOUND;
}
else
{
return SoundHandler.MISSING_SOUND;
}
}
public void addSound(ISoundEventAccessor<Sound> p_188715_1_)
{
this.accessorList.add(p_188715_1_);
}
public ResourceLocation getLocation()
{
return this.location;
}
@Nullable
public ITextComponent getSubtitle()
{
return this.subtitle;
}
}

View File

@@ -0,0 +1,344 @@
package net.minecraft.client.audio;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ITickable;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class SoundHandler implements IResourceManagerReloadListener, ITickable
{
public static final Sound MISSING_SOUND = new Sound("meta:missing_sound", 1.0F, 1.0F, 1, Sound.Type.FILE, false);
private static final Logger LOGGER = LogManager.getLogger();
private static final Gson GSON = (new GsonBuilder()).registerTypeHierarchyAdapter(ITextComponent.class, new ITextComponent.Serializer()).registerTypeAdapter(SoundList.class, new SoundListSerializer()).create();
private static final ParameterizedType TYPE = new ParameterizedType()
{
public Type[] getActualTypeArguments()
{
return new Type[] {String.class, SoundList.class};
}
public Type getRawType()
{
return Map.class;
}
public Type getOwnerType()
{
return null;
}
};
private final SoundRegistry soundRegistry = new SoundRegistry();
private final SoundManager sndManager;
private final IResourceManager mcResourceManager;
public SoundHandler(IResourceManager manager, GameSettings gameSettingsIn)
{
this.mcResourceManager = manager;
this.sndManager = new SoundManager(this, gameSettingsIn);
}
public void onResourceManagerReload(IResourceManager resourceManager)
{
this.soundRegistry.clearMap();
java.util.List<net.minecraft.util.Tuple<ResourceLocation, SoundList>> resources = new java.util.LinkedList<>();
for (String s : resourceManager.getResourceDomains())
{
try
{
for (IResource iresource : resourceManager.getAllResources(new ResourceLocation(s, "sounds.json")))
{
try
{
Map<String, SoundList> map = this.getSoundMap(iresource.getInputStream());
for (Entry<String, SoundList> entry : map.entrySet())
{
resources.add(new net.minecraft.util.Tuple<>(new ResourceLocation(s, entry.getKey()), entry.getValue()));
}
}
catch (RuntimeException runtimeexception)
{
LOGGER.warn("Invalid sounds.json", (Throwable)runtimeexception);
}
}
}
catch (IOException var11)
{
;
}
}
net.minecraftforge.fml.common.ProgressManager.ProgressBar resourcesBar = net.minecraftforge.fml.common.ProgressManager.push("Loading sounds", resources.size());
resources.forEach(entry ->
{
resourcesBar.step(entry.getFirst().toString());
try
{
this.loadSoundResource(entry.getFirst(), entry.getSecond());
}
catch (RuntimeException e)
{
LOGGER.warn("Invalid sounds.json", e);
}
});
net.minecraftforge.fml.common.ProgressManager.pop(resourcesBar);
for (ResourceLocation resourcelocation : this.soundRegistry.getKeys())
{
SoundEventAccessor soundeventaccessor = (SoundEventAccessor)this.soundRegistry.getObject(resourcelocation);
if (soundeventaccessor.getSubtitle() instanceof TextComponentTranslation)
{
String s1 = ((TextComponentTranslation)soundeventaccessor.getSubtitle()).getKey();
if (!I18n.hasKey(s1))
{
LOGGER.debug("Missing subtitle {} for event: {}", s1, resourcelocation);
}
}
}
for (ResourceLocation resourcelocation1 : this.soundRegistry.getKeys())
{
if (SoundEvent.REGISTRY.getObject(resourcelocation1) == null)
{
LOGGER.debug("Not having sound event for: {}", (Object)resourcelocation1);
}
}
this.sndManager.reloadSoundSystem();
}
@Nullable
protected Map<String, SoundList> getSoundMap(InputStream stream)
{
Map map;
try
{
map = (Map)JsonUtils.fromJson(GSON, new InputStreamReader(stream, StandardCharsets.UTF_8), TYPE);
}
finally
{
IOUtils.closeQuietly(stream);
}
return map;
}
private void loadSoundResource(ResourceLocation location, SoundList sounds)
{
SoundEventAccessor soundeventaccessor = (SoundEventAccessor)this.soundRegistry.getObject(location);
boolean flag = soundeventaccessor == null;
if (flag || sounds.canReplaceExisting())
{
if (!flag)
{
LOGGER.debug("Replaced sound event location {}", (Object)location);
}
soundeventaccessor = new SoundEventAccessor(location, sounds.getSubtitle());
this.soundRegistry.add(soundeventaccessor);
}
for (final Sound sound : sounds.getSounds())
{
final ResourceLocation resourcelocation = sound.getSoundLocation();
ISoundEventAccessor<Sound> isoundeventaccessor;
switch (sound.getType())
{
case FILE:
if (!this.validateSoundResource(sound, location))
{
continue;
}
isoundeventaccessor = sound;
break;
case SOUND_EVENT:
isoundeventaccessor = new ISoundEventAccessor<Sound>()
{
public int getWeight()
{
SoundEventAccessor soundeventaccessor1 = (SoundEventAccessor)SoundHandler.this.soundRegistry.getObject(resourcelocation);
return soundeventaccessor1 == null ? 0 : soundeventaccessor1.getWeight();
}
public Sound cloneEntry()
{
SoundEventAccessor soundeventaccessor1 = (SoundEventAccessor)SoundHandler.this.soundRegistry.getObject(resourcelocation);
if (soundeventaccessor1 == null)
{
return SoundHandler.MISSING_SOUND;
}
else
{
Sound sound1 = soundeventaccessor1.cloneEntry();
return new Sound(sound1.getSoundLocation().toString(), sound1.getVolume() * sound.getVolume(), sound1.getPitch() * sound.getPitch(), sound.getWeight(), Sound.Type.FILE, sound1.isStreaming() || sound.isStreaming());
}
}
};
break;
default:
throw new IllegalStateException("Unknown SoundEventRegistration type: " + sound.getType());
}
soundeventaccessor.addSound(isoundeventaccessor);
}
}
private boolean validateSoundResource(Sound p_184401_1_, ResourceLocation p_184401_2_)
{
ResourceLocation resourcelocation = p_184401_1_.getSoundAsOggLocation();
IResource iresource = null;
boolean flag;
try
{
iresource = this.mcResourceManager.getResource(resourcelocation);
iresource.getInputStream();
return true;
}
catch (FileNotFoundException var11)
{
LOGGER.warn("File {} does not exist, cannot add it to event {}", resourcelocation, p_184401_2_);
flag = false;
}
catch (IOException ioexception)
{
LOGGER.warn("Could not load sound file {}, cannot add it to event {}", resourcelocation, p_184401_2_, ioexception);
flag = false;
return flag;
}
finally
{
IOUtils.closeQuietly((Closeable)iresource);
}
return flag;
}
@Nullable
public SoundEventAccessor getAccessor(ResourceLocation location)
{
return (SoundEventAccessor)this.soundRegistry.getObject(location);
}
/**
* Play a sound
*/
public void playSound(ISound sound)
{
this.sndManager.playSound(sound);
}
/**
* Plays the sound in n ticks
*/
public void playDelayedSound(ISound sound, int delay)
{
this.sndManager.playDelayedSound(sound, delay);
}
public void setListener(EntityPlayer player, float p_147691_2_)
{
this.sndManager.setListener(player, p_147691_2_);
}
public void setListener(net.minecraft.entity.Entity entity, float partialTicks)
{
this.sndManager.setListener(entity, partialTicks);
}
public void pauseSounds()
{
this.sndManager.pauseAllSounds();
}
public void stopSounds()
{
this.sndManager.stopAllSounds();
}
public void unloadSounds()
{
this.sndManager.unloadSoundSystem();
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
this.sndManager.updateAllSounds();
}
public void resumeSounds()
{
this.sndManager.resumeAllSounds();
}
public void setSoundLevel(SoundCategory category, float volume)
{
if (category == SoundCategory.MASTER && volume <= 0.0F)
{
this.stopSounds();
}
this.sndManager.setVolume(category, volume);
}
public void stopSound(ISound soundIn)
{
this.sndManager.stopSound(soundIn);
}
public boolean isSoundPlaying(ISound sound)
{
return this.sndManager.isSoundPlaying(sound);
}
public void addListener(ISoundEventListener listener)
{
this.sndManager.addListener(listener);
}
public void removeListener(ISoundEventListener listener)
{
this.sndManager.removeListener(listener);
}
public void stop(String p_189520_1_, SoundCategory p_189520_2_)
{
this.sndManager.stop(p_189520_1_, p_189520_2_);
}
}

View File

@@ -0,0 +1,38 @@
package net.minecraft.client.audio;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class SoundList
{
private final List<Sound> sounds;
/** if true it will override all the sounds from the resourcepacks loaded before */
private final boolean replaceExisting;
private final String subtitle;
public SoundList(List<Sound> soundsIn, boolean replceIn, String subtitleIn)
{
this.sounds = soundsIn;
this.replaceExisting = replceIn;
this.subtitle = subtitleIn;
}
public List<Sound> getSounds()
{
return this.sounds;
}
public boolean canReplaceExisting()
{
return this.replaceExisting;
}
@Nullable
public String getSubtitle()
{
return this.subtitle;
}
}

View File

@@ -0,0 +1,82 @@
package net.minecraft.client.audio;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.List;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.Validate;
@SideOnly(Side.CLIENT)
public class SoundListSerializer implements JsonDeserializer<SoundList>
{
public SoundList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "entry");
boolean flag = JsonUtils.getBoolean(jsonobject, "replace", false);
String s = JsonUtils.getString(jsonobject, "subtitle", (String)null);
List<Sound> list = this.deserializeSounds(jsonobject);
return new SoundList(list, flag, s);
}
private List<Sound> deserializeSounds(JsonObject object)
{
List<Sound> list = Lists.<Sound>newArrayList();
if (object.has("sounds"))
{
JsonArray jsonarray = JsonUtils.getJsonArray(object, "sounds");
for (int i = 0; i < jsonarray.size(); ++i)
{
JsonElement jsonelement = jsonarray.get(i);
if (JsonUtils.isString(jsonelement))
{
String s = JsonUtils.getString(jsonelement, "sound");
list.add(new Sound(s, 1.0F, 1.0F, 1, Sound.Type.FILE, false));
}
else
{
list.add(this.deserializeSound(JsonUtils.getJsonObject(jsonelement, "sound")));
}
}
}
return list;
}
private Sound deserializeSound(JsonObject object)
{
String s = JsonUtils.getString(object, "name");
Sound.Type sound$type = this.deserializeType(object, Sound.Type.FILE);
float f = JsonUtils.getFloat(object, "volume", 1.0F);
Validate.isTrue(f > 0.0F, "Invalid volume");
float f1 = JsonUtils.getFloat(object, "pitch", 1.0F);
Validate.isTrue(f1 > 0.0F, "Invalid pitch");
int i = JsonUtils.getInt(object, "weight", 1);
Validate.isTrue(i > 0, "Invalid weight");
boolean flag = JsonUtils.getBoolean(object, "stream", false);
return new Sound(s, f, f1, i, sound$type, flag);
}
private Sound.Type deserializeType(JsonObject object, Sound.Type defaultValue)
{
Sound.Type sound$type = defaultValue;
if (object.has("type"))
{
sound$type = Sound.Type.getByName(JsonUtils.getString(object, "type"));
Validate.notNull(sound$type, "Invalid type");
}
return sound$type;
}
}

View File

@@ -0,0 +1,645 @@
package net.minecraft.client.audio;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import io.netty.util.internal.ThreadLocalRandom;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import paulscode.sound.SoundSystem;
import paulscode.sound.SoundSystemConfig;
import paulscode.sound.SoundSystemException;
import paulscode.sound.SoundSystemLogger;
import paulscode.sound.Source;
import paulscode.sound.codecs.CodecJOrbis;
import paulscode.sound.libraries.LibraryLWJGLOpenAL;
@SideOnly(Side.CLIENT)
public class SoundManager
{
/** The marker used for logging */
private static final Marker LOG_MARKER = MarkerManager.getMarker("SOUNDS");
private static final Logger LOGGER = LogManager.getLogger();
private static final Set<ResourceLocation> UNABLE_TO_PLAY = Sets.<ResourceLocation>newHashSet();
/** A reference to the sound handler. */
public final SoundHandler sndHandler;
/** Reference to the GameSettings object. */
private final GameSettings options;
/** A reference to the sound system. */
private SoundManager.SoundSystemStarterThread sndSystem;
/** Set to true when the SoundManager has been initialised. */
private boolean loaded;
/** A counter for how long the sound manager has been running */
private int playTime;
/** Identifiers of all currently playing sounds. Type: HashBiMap<String, ISound> */
private final Map<String, ISound> playingSounds = HashBiMap.<String, ISound>create();
/** Inverse map of currently playing sounds, automatically mirroring changes in original map */
private final Map<ISound, String> invPlayingSounds;
private final Multimap<SoundCategory, String> categorySounds;
/** A subset of playingSounds, this contains only ITickableSounds */
private final List<ITickableSound> tickableSounds;
/** Contains sounds to play in n ticks. Type: HashMap<ISound, Integer> */
private final Map<ISound, Integer> delayedSounds;
/** The future time in which to stop this sound. Type: HashMap<String, Integer> */
private final Map<String, Integer> playingSoundsStopTime;
private final List<ISoundEventListener> listeners;
private final List<String> pausedChannels;
public SoundManager(SoundHandler p_i45119_1_, GameSettings p_i45119_2_)
{
this.invPlayingSounds = ((BiMap)this.playingSounds).inverse();
this.categorySounds = HashMultimap.<SoundCategory, String>create();
this.tickableSounds = Lists.<ITickableSound>newArrayList();
this.delayedSounds = Maps.<ISound, Integer>newHashMap();
this.playingSoundsStopTime = Maps.<String, Integer>newHashMap();
this.listeners = Lists.<ISoundEventListener>newArrayList();
this.pausedChannels = Lists.<String>newArrayList();
this.sndHandler = p_i45119_1_;
this.options = p_i45119_2_;
try
{
SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
SoundSystemConfig.setCodec("ogg", CodecJOrbis.class);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.SoundSetupEvent(this));
}
catch (SoundSystemException soundsystemexception)
{
LOGGER.error(LOG_MARKER, "Error linking with the LibraryJavaSound plug-in", (Throwable)soundsystemexception);
}
}
public void reloadSoundSystem()
{
UNABLE_TO_PLAY.clear();
for (SoundEvent soundevent : SoundEvent.REGISTRY)
{
ResourceLocation resourcelocation = soundevent.getSoundName();
if (this.sndHandler.getAccessor(resourcelocation) == null)
{
LOGGER.warn("Missing sound for event: {}", SoundEvent.REGISTRY.getNameForObject(soundevent));
UNABLE_TO_PLAY.add(resourcelocation);
}
}
this.unloadSoundSystem();
this.loadSoundSystem();
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.SoundLoadEvent(this));
}
/**
* Tries to add the paulscode library and the relevant codecs. If it fails, the master volume will be set to zero.
*/
private synchronized void loadSoundSystem()
{
if (!this.loaded)
{
try
{
(new Thread(new Runnable()
{
public void run()
{
SoundSystemConfig.setLogger(new SoundSystemLogger()
{
public void message(String p_message_1_, int p_message_2_)
{
if (!p_message_1_.isEmpty())
{
SoundManager.LOGGER.info(p_message_1_);
}
}
public void importantMessage(String p_importantMessage_1_, int p_importantMessage_2_)
{
if (!p_importantMessage_1_.isEmpty())
{
SoundManager.LOGGER.warn(p_importantMessage_1_);
}
}
public void errorMessage(String p_errorMessage_1_, String p_errorMessage_2_, int p_errorMessage_3_)
{
if (!p_errorMessage_2_.isEmpty())
{
SoundManager.LOGGER.error("Error in class '{}'", (Object)p_errorMessage_1_);
SoundManager.LOGGER.error(p_errorMessage_2_);
}
}
});
SoundManager.this.sndSystem = SoundManager.this.new SoundSystemStarterThread();
SoundManager.this.loaded = true;
SoundManager.this.sndSystem.setMasterVolume(SoundManager.this.options.getSoundLevel(SoundCategory.MASTER));
SoundManager.LOGGER.info(SoundManager.LOG_MARKER, "Sound engine started");
}
}, "Sound Library Loader")).start();
}
catch (RuntimeException runtimeexception)
{
LOGGER.error(LOG_MARKER, "Error starting SoundSystem. Turning off sounds & music", (Throwable)runtimeexception);
this.options.setSoundLevel(SoundCategory.MASTER, 0.0F);
this.options.saveOptions();
}
}
}
private float getVolume(SoundCategory category)
{
return category != null && category != SoundCategory.MASTER ? this.options.getSoundLevel(category) : 1.0F;
}
public void setVolume(SoundCategory category, float volume)
{
if (this.loaded)
{
if (category == SoundCategory.MASTER)
{
this.sndSystem.setMasterVolume(volume);
}
else
{
for (String s : this.categorySounds.get(category))
{
ISound isound = this.playingSounds.get(s);
float f = this.getClampedVolume(isound);
if (f <= 0.0F)
{
this.stopSound(isound);
}
else
{
this.sndSystem.setVolume(s, f);
}
}
}
}
}
/**
* Cleans up the Sound System
*/
public void unloadSoundSystem()
{
if (this.loaded)
{
this.stopAllSounds();
this.sndSystem.cleanup();
this.loaded = false;
}
}
/**
* Stops all currently playing sounds
*/
public void stopAllSounds()
{
if (this.loaded)
{
for (String s : this.playingSounds.keySet())
{
this.sndSystem.stop(s);
}
this.pausedChannels.clear(); //Forge: MC-35856 Fixed paused sounds repeating when switching worlds
this.playingSounds.clear();
this.delayedSounds.clear();
this.tickableSounds.clear();
this.categorySounds.clear();
this.playingSoundsStopTime.clear();
}
}
public void addListener(ISoundEventListener listener)
{
this.listeners.add(listener);
}
public void removeListener(ISoundEventListener listener)
{
this.listeners.remove(listener);
}
public void updateAllSounds()
{
++this.playTime;
for (ITickableSound itickablesound : this.tickableSounds)
{
itickablesound.update();
if (itickablesound.isDonePlaying())
{
this.stopSound(itickablesound);
}
else
{
String s = this.invPlayingSounds.get(itickablesound);
this.sndSystem.setVolume(s, this.getClampedVolume(itickablesound));
this.sndSystem.setPitch(s, this.getClampedPitch(itickablesound));
this.sndSystem.setPosition(s, itickablesound.getXPosF(), itickablesound.getYPosF(), itickablesound.getZPosF());
}
}
Iterator<Entry<String, ISound>> iterator = this.playingSounds.entrySet().iterator();
while (iterator.hasNext())
{
Entry<String, ISound> entry = (Entry)iterator.next();
String s1 = entry.getKey();
ISound isound = entry.getValue();
if (!this.sndSystem.playing(s1))
{
int i = ((Integer)this.playingSoundsStopTime.get(s1)).intValue();
if (i <= this.playTime)
{
int j = isound.getRepeatDelay();
if (isound.canRepeat() && j > 0)
{
this.delayedSounds.put(isound, Integer.valueOf(this.playTime + j));
}
iterator.remove();
LOGGER.debug(LOG_MARKER, "Removed channel {} because it's not playing anymore", (Object)s1);
this.sndSystem.removeSource(s1);
this.playingSoundsStopTime.remove(s1);
try
{
this.categorySounds.remove(isound.getCategory(), s1);
}
catch (RuntimeException var8)
{
;
}
if (isound instanceof ITickableSound)
{
this.tickableSounds.remove(isound);
}
}
}
}
Iterator<Entry<ISound, Integer>> iterator1 = this.delayedSounds.entrySet().iterator();
while (iterator1.hasNext())
{
Entry<ISound, Integer> entry1 = (Entry)iterator1.next();
if (this.playTime >= ((Integer)entry1.getValue()).intValue())
{
ISound isound1 = entry1.getKey();
if (isound1 instanceof ITickableSound)
{
((ITickableSound)isound1).update();
}
this.playSound(isound1);
iterator1.remove();
}
}
}
/**
* Returns true if the sound is playing or still within time
*/
public boolean isSoundPlaying(ISound sound)
{
if (!this.loaded)
{
return false;
}
else
{
String s = this.invPlayingSounds.get(sound);
if (s == null)
{
return false;
}
else
{
return this.sndSystem.playing(s) || this.playingSoundsStopTime.containsKey(s) && ((Integer)this.playingSoundsStopTime.get(s)).intValue() <= this.playTime;
}
}
}
public void stopSound(ISound sound)
{
if (this.loaded)
{
String s = this.invPlayingSounds.get(sound);
if (s != null)
{
this.sndSystem.stop(s);
}
}
}
public void playSound(ISound p_sound)
{
if (this.loaded)
{
p_sound = net.minecraftforge.client.ForgeHooksClient.playSound(this, p_sound);
if (p_sound == null) return;
SoundEventAccessor soundeventaccessor = p_sound.createAccessor(this.sndHandler);
ResourceLocation resourcelocation = p_sound.getSoundLocation();
if (soundeventaccessor == null)
{
if (UNABLE_TO_PLAY.add(resourcelocation))
{
LOGGER.warn(LOG_MARKER, "Unable to play unknown soundEvent: {}", (Object)resourcelocation);
}
}
else
{
if (!this.listeners.isEmpty())
{
for (ISoundEventListener isoundeventlistener : this.listeners)
{
isoundeventlistener.soundPlay(p_sound, soundeventaccessor);
}
}
if (this.sndSystem.getMasterVolume() <= 0.0F)
{
LOGGER.debug(LOG_MARKER, "Skipped playing soundEvent: {}, master volume was zero", (Object)resourcelocation);
}
else
{
Sound sound = p_sound.getSound();
if (sound == SoundHandler.MISSING_SOUND)
{
if (UNABLE_TO_PLAY.add(resourcelocation))
{
LOGGER.warn(LOG_MARKER, "Unable to play empty soundEvent: {}", (Object)resourcelocation);
}
}
else
{
float f3 = p_sound.getVolume();
float f = 16.0F;
if (f3 > 1.0F)
{
f *= f3;
}
SoundCategory soundcategory = p_sound.getCategory();
float f1 = this.getClampedVolume(p_sound);
float f2 = this.getClampedPitch(p_sound);
if (f1 == 0.0F)
{
LOGGER.debug(LOG_MARKER, "Skipped playing sound {}, volume was zero.", (Object)sound.getSoundLocation());
}
else
{
boolean flag = p_sound.canRepeat() && p_sound.getRepeatDelay() == 0;
String s = MathHelper.getRandomUUID(ThreadLocalRandom.current()).toString();
ResourceLocation resourcelocation1 = sound.getSoundAsOggLocation();
if (sound.isStreaming())
{
this.sndSystem.newStreamingSource(false, s, getURLForSoundResource(resourcelocation1), resourcelocation1.toString(), flag, p_sound.getXPosF(), p_sound.getYPosF(), p_sound.getZPosF(), p_sound.getAttenuationType().getTypeInt(), f);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.PlayStreamingSourceEvent(this, p_sound, s));
}
else
{
this.sndSystem.newSource(false, s, getURLForSoundResource(resourcelocation1), resourcelocation1.toString(), flag, p_sound.getXPosF(), p_sound.getYPosF(), p_sound.getZPosF(), p_sound.getAttenuationType().getTypeInt(), f);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.sound.PlaySoundSourceEvent(this, p_sound, s));
}
LOGGER.debug(LOG_MARKER, "Playing sound {} for event {} as channel {}", sound.getSoundLocation(), resourcelocation, s);
this.sndSystem.setPitch(s, f2);
this.sndSystem.setVolume(s, f1);
this.sndSystem.play(s);
this.playingSoundsStopTime.put(s, Integer.valueOf(this.playTime + 20));
this.playingSounds.put(s, p_sound);
this.categorySounds.put(soundcategory, s);
if (p_sound instanceof ITickableSound)
{
this.tickableSounds.add((ITickableSound)p_sound);
}
}
}
}
}
}
}
private float getClampedPitch(ISound soundIn)
{
return MathHelper.clamp(soundIn.getPitch(), 0.5F, 2.0F);
}
private float getClampedVolume(ISound soundIn)
{
return MathHelper.clamp(soundIn.getVolume() * this.getVolume(soundIn.getCategory()), 0.0F, 1.0F);
}
/**
* Pauses all currently playing sounds
*/
public void pauseAllSounds()
{
for (Entry<String, ISound> entry : this.playingSounds.entrySet())
{
String s = entry.getKey();
boolean flag = this.isSoundPlaying(entry.getValue());
if (flag)
{
LOGGER.debug(LOG_MARKER, "Pausing channel {}", (Object)s);
this.sndSystem.pause(s);
this.pausedChannels.add(s);
}
}
}
/**
* Resumes playing all currently playing sounds (after pauseAllSounds)
*/
public void resumeAllSounds()
{
for (String s : this.pausedChannels)
{
LOGGER.debug(LOG_MARKER, "Resuming channel {}", (Object)s);
this.sndSystem.play(s);
}
this.pausedChannels.clear();
}
/**
* Adds a sound to play in n tick
*/
public void playDelayedSound(ISound sound, int delay)
{
this.delayedSounds.put(sound, Integer.valueOf(this.playTime + delay));
}
private static URL getURLForSoundResource(final ResourceLocation p_148612_0_)
{
String s = String.format("%s:%s:%s", "mcsounddomain", p_148612_0_.getResourceDomain(), p_148612_0_.getResourcePath());
URLStreamHandler urlstreamhandler = new URLStreamHandler()
{
protected URLConnection openConnection(URL p_openConnection_1_)
{
return new URLConnection(p_openConnection_1_)
{
public void connect() throws IOException
{
}
public InputStream getInputStream() throws IOException
{
return Minecraft.getMinecraft().getResourceManager().getResource(p_148612_0_).getInputStream();
}
};
}
};
try
{
return new URL((URL)null, s, urlstreamhandler);
}
catch (MalformedURLException var4)
{
throw new Error("TODO: Sanely handle url exception! :D");
}
}
/**
* Sets the listener of sounds
*/
public void setListener(EntityPlayer player, float p_148615_2_)
{
setListener((net.minecraft.entity.Entity) player, p_148615_2_);
}
public void setListener(net.minecraft.entity.Entity player, float p_148615_2_)
{
if (this.loaded && player != null)
{
float f = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * p_148615_2_;
float f1 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * p_148615_2_;
double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double)p_148615_2_;
double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double)p_148615_2_ + (double)player.getEyeHeight();
double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double)p_148615_2_;
float f2 = MathHelper.cos((f1 + 90.0F) * 0.017453292F);
float f3 = MathHelper.sin((f1 + 90.0F) * 0.017453292F);
float f4 = MathHelper.cos(-f * 0.017453292F);
float f5 = MathHelper.sin(-f * 0.017453292F);
float f6 = MathHelper.cos((-f + 90.0F) * 0.017453292F);
float f7 = MathHelper.sin((-f + 90.0F) * 0.017453292F);
float f8 = f2 * f4;
float f9 = f3 * f4;
float f10 = f2 * f6;
float f11 = f3 * f6;
this.sndSystem.setListenerPosition((float)d0, (float)d1, (float)d2);
this.sndSystem.setListenerOrientation(f8, f5, f9, f10, f7, f11);
}
}
public void stop(String p_189567_1_, SoundCategory p_189567_2_)
{
if (p_189567_2_ != null)
{
for (String s : this.categorySounds.get(p_189567_2_))
{
ISound isound = this.playingSounds.get(s);
if (p_189567_1_.isEmpty())
{
this.stopSound(isound);
}
else if (isound.getSoundLocation().equals(new ResourceLocation(p_189567_1_)))
{
this.stopSound(isound);
}
}
}
else if (p_189567_1_.isEmpty())
{
this.stopAllSounds();
}
else
{
for (ISound isound1 : this.playingSounds.values())
{
if (isound1.getSoundLocation().equals(new ResourceLocation(p_189567_1_)))
{
this.stopSound(isound1);
}
}
}
}
@SideOnly(Side.CLIENT)
class SoundSystemStarterThread extends SoundSystem
{
private SoundSystemStarterThread()
{
}
public boolean playing(String p_playing_1_)
{
synchronized (SoundSystemConfig.THREAD_SYNC)
{
if (this.soundLibrary == null)
{
return false;
}
else
{
Source source = (Source)this.soundLibrary.getSources().get(p_playing_1_);
if (source == null)
{
return false;
}
else
{
return source.playing() || source.paused() || source.preLoad;
}
}
}
}
}
}

View File

@@ -0,0 +1,37 @@
package net.minecraft.client.audio;
import com.google.common.collect.Maps;
import java.util.Map;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistrySimple;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class SoundRegistry extends RegistrySimple<ResourceLocation, SoundEventAccessor>
{
/** Contains all registered sound */
private Map<ResourceLocation, SoundEventAccessor> soundRegistry;
/**
* Creates the Map we will use to map keys to their registered values.
*/
protected Map<ResourceLocation, SoundEventAccessor> createUnderlyingMap()
{
this.soundRegistry = Maps.<ResourceLocation, SoundEventAccessor>newHashMap();
return this.soundRegistry;
}
public void add(SoundEventAccessor accessor)
{
this.putObject(accessor.getLocation(), accessor);
}
/**
* Reset the underlying sound map (Called on resource manager reload)
*/
public void clearMap()
{
this.soundRegistry.clear();
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.client.audio;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,175 @@
package net.minecraft.client.entity;
import com.mojang.authlib.GameProfile;
import java.io.File;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.renderer.ImageBufferDownload;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraft.world.GameType;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class AbstractClientPlayer extends EntityPlayer
{
private NetworkPlayerInfo playerInfo;
public float rotateElytraX;
public float rotateElytraY;
public float rotateElytraZ;
public AbstractClientPlayer(World worldIn, GameProfile playerProfile)
{
super(worldIn, playerProfile);
}
/**
* Returns true if the player is in spectator mode.
*/
public boolean isSpectator()
{
NetworkPlayerInfo networkplayerinfo = Minecraft.getMinecraft().getConnection().getPlayerInfo(this.getGameProfile().getId());
return networkplayerinfo != null && networkplayerinfo.getGameType() == GameType.SPECTATOR;
}
public boolean isCreative()
{
NetworkPlayerInfo networkplayerinfo = Minecraft.getMinecraft().getConnection().getPlayerInfo(this.getGameProfile().getId());
return networkplayerinfo != null && networkplayerinfo.getGameType() == GameType.CREATIVE;
}
/**
* Checks if this instance of AbstractClientPlayer has any associated player data.
*/
public boolean hasPlayerInfo()
{
return this.getPlayerInfo() != null;
}
@Nullable
protected NetworkPlayerInfo getPlayerInfo()
{
if (this.playerInfo == null)
{
this.playerInfo = Minecraft.getMinecraft().getConnection().getPlayerInfo(this.getUniqueID());
}
return this.playerInfo;
}
/**
* Returns true if the player has an associated skin.
*/
public boolean hasSkin()
{
NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
return networkplayerinfo != null && networkplayerinfo.hasLocationSkin();
}
/**
* Returns true if the player instance has an associated skin.
*/
public ResourceLocation getLocationSkin()
{
NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
return networkplayerinfo == null ? DefaultPlayerSkin.getDefaultSkin(this.getUniqueID()) : networkplayerinfo.getLocationSkin();
}
@Nullable
public ResourceLocation getLocationCape()
{
NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
return networkplayerinfo == null ? null : networkplayerinfo.getLocationCape();
}
public boolean isPlayerInfoSet()
{
return this.getPlayerInfo() != null;
}
/**
* Gets the special Elytra texture for the player.
*/
@Nullable
public ResourceLocation getLocationElytra()
{
NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
return networkplayerinfo == null ? null : networkplayerinfo.getLocationElytra();
}
public static ThreadDownloadImageData getDownloadImageSkin(ResourceLocation resourceLocationIn, String username)
{
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ITextureObject itextureobject = texturemanager.getTexture(resourceLocationIn);
if (itextureobject == null)
{
itextureobject = new ThreadDownloadImageData((File)null, String.format("http://skins.minecraft.net/MinecraftSkins/%s.png", StringUtils.stripControlCodes(username)), DefaultPlayerSkin.getDefaultSkin(getOfflineUUID(username)), new ImageBufferDownload());
texturemanager.loadTexture(resourceLocationIn, itextureobject);
}
return (ThreadDownloadImageData)itextureobject;
}
/**
* Returns true if the username has an associated skin.
*/
public static ResourceLocation getLocationSkin(String username)
{
return new ResourceLocation("skins/" + StringUtils.stripControlCodes(username));
}
public String getSkinType()
{
NetworkPlayerInfo networkplayerinfo = this.getPlayerInfo();
return networkplayerinfo == null ? DefaultPlayerSkin.getSkinType(this.getUniqueID()) : networkplayerinfo.getSkinType();
}
public float getFovModifier()
{
float f = 1.0F;
if (this.capabilities.isFlying)
{
f *= 1.1F;
}
IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
f = (float)((double)f * ((iattributeinstance.getAttributeValue() / (double)this.capabilities.getWalkSpeed() + 1.0D) / 2.0D));
if (this.capabilities.getWalkSpeed() == 0.0F || Float.isNaN(f) || Float.isInfinite(f))
{
f = 1.0F;
}
if (this.isHandActive() && this.getActiveItemStack().getItem() == Items.BOW)
{
int i = this.getItemInUseMaxCount();
float f1 = (float)i / 20.0F;
if (f1 > 1.0F)
{
f1 = 1.0F;
}
else
{
f1 = f1 * f1;
}
f *= 1.0F - f1 * 0.15F;
}
return net.minecraftforge.client.ForgeHooksClient.getOffsetFOV(this, f);
}
}

View File

@@ -0,0 +1,171 @@
package net.minecraft.client.entity;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class EntityOtherPlayerMP extends AbstractClientPlayer
{
private int otherPlayerMPPosRotationIncrements;
private double otherPlayerMPX;
private double otherPlayerMPY;
private double otherPlayerMPZ;
private double otherPlayerMPYaw;
private double otherPlayerMPPitch;
public EntityOtherPlayerMP(World worldIn, GameProfile gameProfileIn)
{
super(worldIn, gameProfileIn);
this.stepHeight = 1.0F;
this.noClip = true;
this.renderOffsetY = 0.25F;
}
/**
* Checks if the entity is in range to render.
*/
public boolean isInRangeToRenderDist(double distance)
{
double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 10.0D;
if (Double.isNaN(d0))
{
d0 = 1.0D;
}
d0 = d0 * 64.0D * getRenderDistanceWeight();
return distance < d0 * d0;
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource source, float amount)
{
net.minecraftforge.common.ForgeHooks.onPlayerAttack(this, source, amount);
return true;
}
/**
* Set the position and rotation values directly without any clamping.
*/
public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
{
this.otherPlayerMPX = x;
this.otherPlayerMPY = y;
this.otherPlayerMPZ = z;
this.otherPlayerMPYaw = (double)yaw;
this.otherPlayerMPPitch = (double)pitch;
this.otherPlayerMPPosRotationIncrements = posRotationIncrements;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
this.renderOffsetY = 0.0F;
super.onUpdate();
this.prevLimbSwingAmount = this.limbSwingAmount;
double d0 = this.posX - this.prevPosX;
double d1 = this.posZ - this.prevPosZ;
float f = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
if (f > 1.0F)
{
f = 1.0F;
}
this.limbSwingAmount += (f - this.limbSwingAmount) * 0.4F;
this.limbSwing += this.limbSwingAmount;
}
/**
* Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
* use this to react to sunlight and start to burn.
*/
public void onLivingUpdate()
{
if (this.otherPlayerMPPosRotationIncrements > 0)
{
double d0 = this.posX + (this.otherPlayerMPX - this.posX) / (double)this.otherPlayerMPPosRotationIncrements;
double d1 = this.posY + (this.otherPlayerMPY - this.posY) / (double)this.otherPlayerMPPosRotationIncrements;
double d2 = this.posZ + (this.otherPlayerMPZ - this.posZ) / (double)this.otherPlayerMPPosRotationIncrements;
double d3;
for (d3 = this.otherPlayerMPYaw - (double)this.rotationYaw; d3 < -180.0D; d3 += 360.0D)
{
;
}
while (d3 >= 180.0D)
{
d3 -= 360.0D;
}
this.rotationYaw = (float)((double)this.rotationYaw + d3 / (double)this.otherPlayerMPPosRotationIncrements);
this.rotationPitch = (float)((double)this.rotationPitch + (this.otherPlayerMPPitch - (double)this.rotationPitch) / (double)this.otherPlayerMPPosRotationIncrements);
--this.otherPlayerMPPosRotationIncrements;
this.setPosition(d0, d1, d2);
this.setRotation(this.rotationYaw, this.rotationPitch);
}
this.prevCameraYaw = this.cameraYaw;
this.updateArmSwingProgress();
float f1 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
float f = (float)Math.atan(-this.motionY * 0.20000000298023224D) * 15.0F;
if (f1 > 0.1F)
{
f1 = 0.1F;
}
if (!this.onGround || this.getHealth() <= 0.0F)
{
f1 = 0.0F;
}
if (this.onGround || this.getHealth() <= 0.0F)
{
f = 0.0F;
}
this.cameraYaw += (f1 - this.cameraYaw) * 0.4F;
this.cameraPitch += (f - this.cameraPitch) * 0.8F;
this.world.profiler.startSection("push");
this.collideWithNearbyEntities();
this.world.profiler.endSection();
}
/**
* Send a chat message to the CommandSender
*/
public void sendMessage(ITextComponent component)
{
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(component);
}
/**
* Returns {@code true} if the CommandSender is allowed to execute the command, {@code false} if not
*/
public boolean canUseCommand(int permLevel, String commandName)
{
return false;
}
/**
* Get the position in the world. <b>{@code null} is not allowed!</b> If you are not an entity in the world, return
* the coordinates 0, 0, 0
*/
public BlockPos getPosition()
{
return new BlockPos(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.client.entity;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,60 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.network.play.server.SPacketUpdateBossInfo;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.BossInfo;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BossInfoClient extends BossInfo
{
protected float rawPercent;
protected long percentSetTime;
public BossInfoClient(SPacketUpdateBossInfo packetIn)
{
super(packetIn.getUniqueId(), packetIn.getName(), packetIn.getColor(), packetIn.getOverlay());
this.rawPercent = packetIn.getPercent();
this.percent = packetIn.getPercent();
this.percentSetTime = Minecraft.getSystemTime();
this.setDarkenSky(packetIn.shouldDarkenSky());
this.setPlayEndBossMusic(packetIn.shouldPlayEndBossMusic());
this.setCreateFog(packetIn.shouldCreateFog());
}
public void setPercent(float percentIn)
{
this.percent = this.getPercent();
this.rawPercent = percentIn;
this.percentSetTime = Minecraft.getSystemTime();
}
public float getPercent()
{
long i = Minecraft.getSystemTime() - this.percentSetTime;
float f = MathHelper.clamp((float)i / 100.0F, 0.0F, 1.0F);
return this.percent + (this.rawPercent - this.percent) * f;
}
public void updateFromPacket(SPacketUpdateBossInfo packetIn)
{
switch (packetIn.getOperation())
{
case UPDATE_NAME:
this.setName(packetIn.getName());
break;
case UPDATE_PCT:
this.setPercent(packetIn.getPercent());
break;
case UPDATE_STYLE:
this.setColor(packetIn.getColor());
this.setOverlay(packetIn.getOverlay());
break;
case UPDATE_PROPERTIES:
this.setDarkenSky(packetIn.shouldDarkenSky());
this.setPlayEndBossMusic(packetIn.shouldPlayEndBossMusic());
}
}
}

View File

@@ -0,0 +1,37 @@
package net.minecraft.client.gui;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ChatLine
{
/** GUI Update Counter value this Line was created at */
private final int updateCounterCreated;
private final ITextComponent lineString;
/** int value to refer to existing Chat Lines, can be 0 which means unreferrable */
private final int chatLineID;
public ChatLine(int updateCounterCreatedIn, ITextComponent lineStringIn, int chatLineIDIn)
{
this.lineString = lineStringIn;
this.updateCounterCreated = updateCounterCreatedIn;
this.chatLineID = chatLineIDIn;
}
public ITextComponent getChatComponent()
{
return this.lineString;
}
public int getUpdatedCounter()
{
return this.updateCounterCreated;
}
public int getChatLineID()
{
return this.chatLineID;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,220 @@
package net.minecraft.client.gui;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Gui
{
public static final ResourceLocation OPTIONS_BACKGROUND = new ResourceLocation("textures/gui/options_background.png");
public static final ResourceLocation STAT_ICONS = new ResourceLocation("textures/gui/container/stats_icons.png");
public static final ResourceLocation ICONS = new ResourceLocation("textures/gui/icons.png");
protected float zLevel;
/**
* Draws a thin horizontal line between two points.
*/
protected void drawHorizontalLine(int startX, int endX, int y, int color)
{
if (endX < startX)
{
int i = startX;
startX = endX;
endX = i;
}
drawRect(startX, y, endX + 1, y + 1, color);
}
/**
* Draw a 1 pixel wide vertical line. Args : x, y1, y2, color
*/
protected void drawVerticalLine(int x, int startY, int endY, int color)
{
if (endY < startY)
{
int i = startY;
startY = endY;
endY = i;
}
drawRect(x, startY + 1, x + 1, endY, color);
}
/**
* Draws a solid color rectangle with the specified coordinates and color.
*/
public static void drawRect(int left, int top, int right, int bottom, int color)
{
if (left < right)
{
int i = left;
left = right;
right = i;
}
if (top < bottom)
{
int j = top;
top = bottom;
bottom = j;
}
float f3 = (float)(color >> 24 & 255) / 255.0F;
float f = (float)(color >> 16 & 255) / 255.0F;
float f1 = (float)(color >> 8 & 255) / 255.0F;
float f2 = (float)(color & 255) / 255.0F;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.color(f, f1, f2, f3);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.pos((double)left, (double)bottom, 0.0D).endVertex();
bufferbuilder.pos((double)right, (double)bottom, 0.0D).endVertex();
bufferbuilder.pos((double)right, (double)top, 0.0D).endVertex();
bufferbuilder.pos((double)left, (double)top, 0.0D).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
/**
* Draws a rectangle with a vertical gradient between the specified colors (ARGB format). Args : x1, y1, x2, y2,
* topColor, bottomColor
*/
protected void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor)
{
float f = (float)(startColor >> 24 & 255) / 255.0F;
float f1 = (float)(startColor >> 16 & 255) / 255.0F;
float f2 = (float)(startColor >> 8 & 255) / 255.0F;
float f3 = (float)(startColor & 255) / 255.0F;
float f4 = (float)(endColor >> 24 & 255) / 255.0F;
float f5 = (float)(endColor >> 16 & 255) / 255.0F;
float f6 = (float)(endColor >> 8 & 255) / 255.0F;
float f7 = (float)(endColor & 255) / 255.0F;
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.shadeModel(7425);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
bufferbuilder.pos((double)right, (double)top, (double)this.zLevel).color(f1, f2, f3, f).endVertex();
bufferbuilder.pos((double)left, (double)top, (double)this.zLevel).color(f1, f2, f3, f).endVertex();
bufferbuilder.pos((double)left, (double)bottom, (double)this.zLevel).color(f5, f6, f7, f4).endVertex();
bufferbuilder.pos((double)right, (double)bottom, (double)this.zLevel).color(f5, f6, f7, f4).endVertex();
tessellator.draw();
GlStateManager.shadeModel(7424);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
}
/**
* Renders the specified text to the screen, center-aligned. Args : renderer, string, x, y, color
*/
public void drawCenteredString(FontRenderer fontRendererIn, String text, int x, int y, int color)
{
fontRendererIn.drawStringWithShadow(text, (float)(x - fontRendererIn.getStringWidth(text) / 2), (float)y, color);
}
/**
* Renders the specified text to the screen. Args : renderer, string, x, y, color
*/
public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color)
{
fontRendererIn.drawStringWithShadow(text, (float)x, (float)y, color);
}
/**
* Draws a textured rectangle at the current z-value.
*/
public void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height)
{
float f = 0.00390625F;
float f1 = 0.00390625F;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((double)(x + 0), (double)(y + height), (double)this.zLevel).tex((double)((float)(textureX + 0) * 0.00390625F), (double)((float)(textureY + height) * 0.00390625F)).endVertex();
bufferbuilder.pos((double)(x + width), (double)(y + height), (double)this.zLevel).tex((double)((float)(textureX + width) * 0.00390625F), (double)((float)(textureY + height) * 0.00390625F)).endVertex();
bufferbuilder.pos((double)(x + width), (double)(y + 0), (double)this.zLevel).tex((double)((float)(textureX + width) * 0.00390625F), (double)((float)(textureY + 0) * 0.00390625F)).endVertex();
bufferbuilder.pos((double)(x + 0), (double)(y + 0), (double)this.zLevel).tex((double)((float)(textureX + 0) * 0.00390625F), (double)((float)(textureY + 0) * 0.00390625F)).endVertex();
tessellator.draw();
}
/**
* Draws a textured rectangle using the texture currently bound to the TextureManager
*/
public void drawTexturedModalRect(float xCoord, float yCoord, int minU, int minV, int maxU, int maxV)
{
float f = 0.00390625F;
float f1 = 0.00390625F;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((double)(xCoord + 0.0F), (double)(yCoord + (float)maxV), (double)this.zLevel).tex((double)((float)(minU + 0) * 0.00390625F), (double)((float)(minV + maxV) * 0.00390625F)).endVertex();
bufferbuilder.pos((double)(xCoord + (float)maxU), (double)(yCoord + (float)maxV), (double)this.zLevel).tex((double)((float)(minU + maxU) * 0.00390625F), (double)((float)(minV + maxV) * 0.00390625F)).endVertex();
bufferbuilder.pos((double)(xCoord + (float)maxU), (double)(yCoord + 0.0F), (double)this.zLevel).tex((double)((float)(minU + maxU) * 0.00390625F), (double)((float)(minV + 0) * 0.00390625F)).endVertex();
bufferbuilder.pos((double)(xCoord + 0.0F), (double)(yCoord + 0.0F), (double)this.zLevel).tex((double)((float)(minU + 0) * 0.00390625F), (double)((float)(minV + 0) * 0.00390625F)).endVertex();
tessellator.draw();
}
/**
* Draws a texture rectangle using the texture currently bound to the TextureManager
*/
public void drawTexturedModalRect(int xCoord, int yCoord, TextureAtlasSprite textureSprite, int widthIn, int heightIn)
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((double)(xCoord + 0), (double)(yCoord + heightIn), (double)this.zLevel).tex((double)textureSprite.getMinU(), (double)textureSprite.getMaxV()).endVertex();
bufferbuilder.pos((double)(xCoord + widthIn), (double)(yCoord + heightIn), (double)this.zLevel).tex((double)textureSprite.getMaxU(), (double)textureSprite.getMaxV()).endVertex();
bufferbuilder.pos((double)(xCoord + widthIn), (double)(yCoord + 0), (double)this.zLevel).tex((double)textureSprite.getMaxU(), (double)textureSprite.getMinV()).endVertex();
bufferbuilder.pos((double)(xCoord + 0), (double)(yCoord + 0), (double)this.zLevel).tex((double)textureSprite.getMinU(), (double)textureSprite.getMinV()).endVertex();
tessellator.draw();
}
/**
* Draws a textured rectangle at z = 0. Args: x, y, u, v, width, height, textureWidth, textureHeight
*/
public static void drawModalRectWithCustomSizedTexture(int x, int y, float u, float v, int width, int height, float textureWidth, float textureHeight)
{
float f = 1.0F / textureWidth;
float f1 = 1.0F / textureHeight;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)height) * f1)).endVertex();
bufferbuilder.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)width) * f), (double)((v + (float)height) * f1)).endVertex();
bufferbuilder.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)width) * f), (double)(v * f1)).endVertex();
bufferbuilder.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
tessellator.draw();
}
/**
* Draws a scaled, textured, tiled modal rect at z = 0. This method isn't used anywhere in vanilla code.
*/
public static void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight)
{
float f = 1.0F / tileWidth;
float f1 = 1.0F / tileHeight;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((double)x, (double)(y + height), 0.0D).tex((double)(u * f), (double)((v + (float)vHeight) * f1)).endVertex();
bufferbuilder.pos((double)(x + width), (double)(y + height), 0.0D).tex((double)((u + (float)uWidth) * f), (double)((v + (float)vHeight) * f1)).endVertex();
bufferbuilder.pos((double)(x + width), (double)y, 0.0D).tex((double)((u + (float)uWidth) * f), (double)(v * f1)).endVertex();
bufferbuilder.pos((double)x, (double)y, 0.0D).tex((double)(u * f), (double)(v * f1)).endVertex();
tessellator.draw();
}
}

View File

@@ -0,0 +1,147 @@
package net.minecraft.client.gui;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.UUID;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.network.play.server.SPacketUpdateBossInfo;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.BossInfo;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiBossOverlay extends Gui
{
private static final ResourceLocation GUI_BARS_TEXTURES = new ResourceLocation("textures/gui/bars.png");
private final Minecraft client;
private final Map<UUID, BossInfoClient> mapBossInfos = Maps.<UUID, BossInfoClient>newLinkedHashMap();
public GuiBossOverlay(Minecraft clientIn)
{
this.client = clientIn;
}
public void renderBossHealth()
{
if (!this.mapBossInfos.isEmpty())
{
ScaledResolution scaledresolution = new ScaledResolution(this.client);
int i = scaledresolution.getScaledWidth();
int j = 12;
for (BossInfoClient bossinfoclient : this.mapBossInfos.values())
{
int k = i / 2 - 91;
net.minecraftforge.client.event.RenderGameOverlayEvent.BossInfo event =
net.minecraftforge.client.ForgeHooksClient.bossBarRenderPre(scaledresolution, bossinfoclient, k, j, 10 + this.client.fontRenderer.FONT_HEIGHT);
if (!event.isCanceled()) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.client.getTextureManager().bindTexture(GUI_BARS_TEXTURES);
this.render(k, j, bossinfoclient);
String s = bossinfoclient.getName().getFormattedText();
this.client.fontRenderer.drawStringWithShadow(s, (float)(i / 2 - this.client.fontRenderer.getStringWidth(s) / 2), (float)(j - 9), 16777215);
}
j += event.getIncrement();
net.minecraftforge.client.ForgeHooksClient.bossBarRenderPost(scaledresolution);
if (j >= scaledresolution.getScaledHeight() / 3)
{
break;
}
}
}
}
private void render(int x, int y, BossInfo info)
{
this.drawTexturedModalRect(x, y, 0, info.getColor().ordinal() * 5 * 2, 182, 5);
if (info.getOverlay() != BossInfo.Overlay.PROGRESS)
{
this.drawTexturedModalRect(x, y, 0, 80 + (info.getOverlay().ordinal() - 1) * 5 * 2, 182, 5);
}
int i = (int)(info.getPercent() * 183.0F);
if (i > 0)
{
this.drawTexturedModalRect(x, y, 0, info.getColor().ordinal() * 5 * 2 + 5, i, 5);
if (info.getOverlay() != BossInfo.Overlay.PROGRESS)
{
this.drawTexturedModalRect(x, y, 0, 80 + (info.getOverlay().ordinal() - 1) * 5 * 2 + 5, i, 5);
}
}
}
public void read(SPacketUpdateBossInfo packetIn)
{
if (packetIn.getOperation() == SPacketUpdateBossInfo.Operation.ADD)
{
this.mapBossInfos.put(packetIn.getUniqueId(), new BossInfoClient(packetIn));
}
else if (packetIn.getOperation() == SPacketUpdateBossInfo.Operation.REMOVE)
{
this.mapBossInfos.remove(packetIn.getUniqueId());
}
else
{
((BossInfoClient)this.mapBossInfos.get(packetIn.getUniqueId())).updateFromPacket(packetIn);
}
}
public void clearBossInfos()
{
this.mapBossInfos.clear();
}
public boolean shouldPlayEndBossMusic()
{
if (!this.mapBossInfos.isEmpty())
{
for (BossInfo bossinfo : this.mapBossInfos.values())
{
if (bossinfo.shouldPlayEndBossMusic())
{
return true;
}
}
}
return false;
}
public boolean shouldDarkenSky()
{
if (!this.mapBossInfos.isEmpty())
{
for (BossInfo bossinfo : this.mapBossInfos.values())
{
if (bossinfo.shouldDarkenSky())
{
return true;
}
}
}
return false;
}
public boolean shouldCreateFog()
{
if (!this.mapBossInfos.isEmpty())
{
for (BossInfo bossinfo : this.mapBossInfos.values())
{
if (bossinfo.shouldCreateFog())
{
return true;
}
}
}
return false;
}
}

View File

@@ -0,0 +1,160 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiButton extends Gui
{
protected static final ResourceLocation BUTTON_TEXTURES = new ResourceLocation("textures/gui/widgets.png");
/** Button width in pixels */
public int width;
/** Button height in pixels */
public int height;
/** The x position of this control. */
public int x;
/** The y position of this control. */
public int y;
/** The string displayed on this control. */
public String displayString;
public int id;
/** True if this control is enabled, false to disable. */
public boolean enabled;
/** Hides the button completely if false. */
public boolean visible;
protected boolean hovered;
public int packedFGColour; //FML
public GuiButton(int buttonId, int x, int y, String buttonText)
{
this(buttonId, x, y, 200, 20, buttonText);
}
public GuiButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText)
{
this.width = 200;
this.height = 20;
this.enabled = true;
this.visible = true;
this.id = buttonId;
this.x = x;
this.y = y;
this.width = widthIn;
this.height = heightIn;
this.displayString = buttonText;
}
/**
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
* this button.
*/
protected int getHoverState(boolean mouseOver)
{
int i = 1;
if (!this.enabled)
{
i = 0;
}
else if (mouseOver)
{
i = 2;
}
return i;
}
/**
* Draws this button to the screen.
*/
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
FontRenderer fontrenderer = mc.fontRenderer;
mc.getTextureManager().bindTexture(BUTTON_TEXTURES);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
int i = this.getHoverState(this.hovered);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
this.mouseDragged(mc, mouseX, mouseY);
int j = 14737632;
if (packedFGColour != 0)
{
j = packedFGColour;
}
else
if (!this.enabled)
{
j = 10526880;
}
else if (this.hovered)
{
j = 16777120;
}
this.drawCenteredString(fontrenderer, this.displayString, this.x + this.width / 2, this.y + (this.height - 8) / 2, j);
}
}
/**
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
*/
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
{
}
/**
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
*/
public void mouseReleased(int mouseX, int mouseY)
{
}
/**
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
* e).
*/
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
return this.enabled && this.visible && mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
}
/**
* Whether the mouse cursor is currently over the button.
*/
public boolean isMouseOver()
{
return this.hovered;
}
public void drawButtonForegroundLayer(int mouseX, int mouseY)
{
}
public void playPressSound(SoundHandler soundHandlerIn)
{
soundHandlerIn.playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
}
public int getButtonWidth()
{
return this.width;
}
public void setWidth(int width)
{
this.width = width;
}
}

View File

@@ -0,0 +1,54 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiButtonImage extends GuiButton
{
private final ResourceLocation resourceLocation;
private final int xTexStart;
private final int yTexStart;
private final int yDiffText;
public GuiButtonImage(int p_i47392_1_, int p_i47392_2_, int p_i47392_3_, int p_i47392_4_, int p_i47392_5_, int p_i47392_6_, int p_i47392_7_, int p_i47392_8_, ResourceLocation p_i47392_9_)
{
super(p_i47392_1_, p_i47392_2_, p_i47392_3_, p_i47392_4_, p_i47392_5_, "");
this.xTexStart = p_i47392_6_;
this.yTexStart = p_i47392_7_;
this.yDiffText = p_i47392_8_;
this.resourceLocation = p_i47392_9_;
}
public void setPosition(int p_191746_1_, int p_191746_2_)
{
this.x = p_191746_1_;
this.y = p_191746_2_;
}
/**
* Draws this button to the screen.
*/
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
mc.getTextureManager().bindTexture(this.resourceLocation);
GlStateManager.disableDepth();
int i = this.xTexStart;
int j = this.yTexStart;
if (this.hovered)
{
j += this.yDiffText;
}
this.drawTexturedModalRect(this.x, this.y, i, j, this.width, this.height);
GlStateManager.enableDepth();
}
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiButtonLanguage extends GuiButton
{
public GuiButtonLanguage(int buttonID, int xPos, int yPos)
{
super(buttonID, xPos, yPos, 20, 20, "");
}
/**
* Draws this button to the screen.
*/
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
mc.getTextureManager().bindTexture(GuiButton.BUTTON_TEXTURES);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
boolean flag = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
int i = 106;
if (flag)
{
i += this.height;
}
this.drawTexturedModalRect(this.x, this.y, 0, i, this.width, this.height);
}
}
}

View File

@@ -0,0 +1,108 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.realms.RealmsButton;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiButtonRealmsProxy extends GuiButton
{
private final RealmsButton realmsButton;
public GuiButtonRealmsProxy(RealmsButton realmsButtonIn, int buttonId, int x, int y, String text)
{
super(buttonId, x, y, text);
this.realmsButton = realmsButtonIn;
}
public GuiButtonRealmsProxy(RealmsButton realmsButtonIn, int buttonId, int x, int y, String text, int widthIn, int heightIn)
{
super(buttonId, x, y, widthIn, heightIn, text);
this.realmsButton = realmsButtonIn;
}
public int getId()
{
return this.id;
}
public boolean getEnabled()
{
return this.enabled;
}
public void setEnabled(boolean isEnabled)
{
this.enabled = isEnabled;
}
public void setText(String text)
{
super.displayString = text;
}
public int getButtonWidth()
{
return super.getButtonWidth();
}
public int getPositionY()
{
return this.y;
}
/**
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
* e).
*/
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.realmsButton.clicked(mouseX, mouseY);
}
return super.mousePressed(mc, mouseX, mouseY);
}
/**
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
*/
public void mouseReleased(int mouseX, int mouseY)
{
this.realmsButton.released(mouseX, mouseY);
}
/**
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
*/
public void mouseDragged(Minecraft mc, int mouseX, int mouseY)
{
this.realmsButton.renderBg(mouseX, mouseY);
}
public RealmsButton getRealmsButton()
{
return this.realmsButton;
}
/**
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
* this button.
*/
public int getHoverState(boolean mouseOver)
{
return this.realmsButton.getYImage(mouseOver);
}
public int getYImage(boolean p_154312_1_)
{
return super.getHoverState(p_154312_1_);
}
public int getHeight()
{
return this.height;
}
}

View File

@@ -0,0 +1,77 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiButtonToggle extends GuiButton
{
protected ResourceLocation resourceLocation;
protected boolean stateTriggered;
protected int xTexStart;
protected int yTexStart;
protected int xDiffTex;
protected int yDiffTex;
public GuiButtonToggle(int buttonId, int xIn, int yIn, int widthIn, int heightIn, boolean buttonText)
{
super(buttonId, xIn, yIn, widthIn, heightIn, "");
this.stateTriggered = buttonText;
}
public void initTextureValues(int xTexStartIn, int yTexStartIn, int xDiffTexIn, int yDiffTexIn, ResourceLocation resourceLocationIn)
{
this.xTexStart = xTexStartIn;
this.yTexStart = yTexStartIn;
this.xDiffTex = xDiffTexIn;
this.yDiffTex = yDiffTexIn;
this.resourceLocation = resourceLocationIn;
}
public void setStateTriggered(boolean p_191753_1_)
{
this.stateTriggered = p_191753_1_;
}
public boolean isStateTriggered()
{
return this.stateTriggered;
}
public void setPosition(int p_191752_1_, int p_191752_2_)
{
this.x = p_191752_1_;
this.y = p_191752_2_;
}
/**
* Draws this button to the screen.
*/
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
mc.getTextureManager().bindTexture(this.resourceLocation);
GlStateManager.disableDepth();
int i = this.xTexStart;
int j = this.yTexStart;
if (this.stateTriggered)
{
i += this.xDiffTex;
}
if (this.hovered)
{
j += this.yDiffTex;
}
this.drawTexturedModalRect(this.x, this.y, i, j, this.width, this.height);
GlStateManager.enableDepth();
}
}
}

View File

@@ -0,0 +1,312 @@
package net.minecraft.client.gui;
import java.io.IOException;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ITabCompleter;
import net.minecraft.util.TabCompleter;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@SideOnly(Side.CLIENT)
public class GuiChat extends GuiScreen implements ITabCompleter
{
private static final Logger LOGGER = LogManager.getLogger();
private String historyBuffer = "";
/**
* keeps position of which chat message you will select when you press up, (does not increase for duplicated
* messages sent immediately after each other)
*/
private int sentHistoryCursor = -1;
private TabCompleter tabCompleter;
/** Chat entry field */
protected GuiTextField inputField;
/** is the text that appears when you press the chat key and the input box appears pre-filled */
private String defaultInputFieldText = "";
public GuiChat()
{
}
public GuiChat(String defaultText)
{
this.defaultInputFieldText = defaultText;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
Keyboard.enableRepeatEvents(true);
this.sentHistoryCursor = this.mc.ingameGUI.getChatGUI().getSentMessages().size();
this.inputField = new GuiTextField(0, this.fontRenderer, 4, this.height - 12, this.width - 4, 12);
this.inputField.setMaxStringLength(256);
this.inputField.setEnableBackgroundDrawing(false);
this.inputField.setFocused(true);
this.inputField.setText(this.defaultInputFieldText);
this.inputField.setCanLoseFocus(false);
this.tabCompleter = new GuiChat.ChatTabCompleter(this.inputField);
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
this.mc.ingameGUI.getChatGUI().resetScroll();
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
this.inputField.updateCursorCounter();
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
this.tabCompleter.resetRequested();
if (keyCode == 15)
{
this.tabCompleter.complete();
}
else
{
this.tabCompleter.resetDidComplete();
}
if (keyCode == 1)
{
this.mc.displayGuiScreen((GuiScreen)null);
}
else if (keyCode != 28 && keyCode != 156)
{
if (keyCode == 200)
{
this.getSentHistory(-1);
}
else if (keyCode == 208)
{
this.getSentHistory(1);
}
else if (keyCode == 201)
{
this.mc.ingameGUI.getChatGUI().scroll(this.mc.ingameGUI.getChatGUI().getLineCount() - 1);
}
else if (keyCode == 209)
{
this.mc.ingameGUI.getChatGUI().scroll(-this.mc.ingameGUI.getChatGUI().getLineCount() + 1);
}
else
{
this.inputField.textboxKeyTyped(typedChar, keyCode);
}
}
else
{
String s = this.inputField.getText().trim();
if (!s.isEmpty())
{
this.sendChatMessage(s);
}
this.mc.displayGuiScreen((GuiScreen)null);
}
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
int i = Mouse.getEventDWheel();
if (i != 0)
{
if (i > 1)
{
i = 1;
}
if (i < -1)
{
i = -1;
}
if (!isShiftKeyDown())
{
i *= 7;
}
this.mc.ingameGUI.getChatGUI().scroll(i);
}
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
if (mouseButton == 0)
{
ITextComponent itextcomponent = this.mc.ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());
if (itextcomponent != null && this.handleComponentClick(itextcomponent))
{
return;
}
}
this.inputField.mouseClicked(mouseX, mouseY, mouseButton);
super.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Sets the text of the chat
*/
protected void setText(String newChatText, boolean shouldOverwrite)
{
if (shouldOverwrite)
{
this.inputField.setText(newChatText);
}
else
{
this.inputField.writeText(newChatText);
}
}
/**
* input is relative and is applied directly to the sentHistoryCursor so -1 is the previous message, 1 is the next
* message from the current cursor position
*/
public void getSentHistory(int msgPos)
{
int i = this.sentHistoryCursor + msgPos;
int j = this.mc.ingameGUI.getChatGUI().getSentMessages().size();
i = MathHelper.clamp(i, 0, j);
if (i != this.sentHistoryCursor)
{
if (i == j)
{
this.sentHistoryCursor = j;
this.inputField.setText(this.historyBuffer);
}
else
{
if (this.sentHistoryCursor == j)
{
this.historyBuffer = this.inputField.getText();
}
this.inputField.setText((String)this.mc.ingameGUI.getChatGUI().getSentMessages().get(i));
this.sentHistoryCursor = i;
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
drawRect(2, this.height - 14, this.width - 2, this.height - 2, Integer.MIN_VALUE);
this.inputField.drawTextBox();
ITextComponent itextcomponent = this.mc.ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());
if (itextcomponent != null && itextcomponent.getStyle().getHoverEvent() != null)
{
this.handleComponentHover(itextcomponent, mouseX, mouseY);
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
public boolean doesGuiPauseGame()
{
return false;
}
/**
* Sets the list of tab completions, as long as they were previously requested.
*/
public void setCompletions(String... newCompletions)
{
this.tabCompleter.setCompletions(newCompletions);
}
@SideOnly(Side.CLIENT)
public static class ChatTabCompleter extends TabCompleter
{
/** The instance of the Minecraft client */
private final Minecraft client = Minecraft.getMinecraft();
public ChatTabCompleter(GuiTextField p_i46749_1_)
{
super(p_i46749_1_, false);
}
/**
* Called when tab key pressed. If it's the first time we tried to complete this string, we ask the server
* for completions. When the server responds, this method gets called again (via setCompletions).
*/
public void complete()
{
super.complete();
if (this.completions.size() > 1)
{
StringBuilder stringbuilder = new StringBuilder();
for (String s : this.completions)
{
if (stringbuilder.length() > 0)
{
stringbuilder.append(", ");
}
stringbuilder.append(s);
}
this.client.ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new TextComponentString(stringbuilder.toString()), 1);
}
}
@Nullable
public BlockPos getTargetBlockPos()
{
BlockPos blockpos = null;
if (this.client.objectMouseOver != null && this.client.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
{
blockpos = this.client.objectMouseOver.getBlockPos();
}
return blockpos;
}
}
}

View File

@@ -0,0 +1,120 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.realms.RealmsClickableScrolledSelectionList;
import net.minecraft.realms.Tezzelator;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Mouse;
@SideOnly(Side.CLIENT)
public class GuiClickableScrolledSelectionListProxy extends GuiSlot
{
private final RealmsClickableScrolledSelectionList proxy;
public GuiClickableScrolledSelectionListProxy(RealmsClickableScrolledSelectionList selectionList, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
{
super(Minecraft.getMinecraft(), widthIn, heightIn, topIn, bottomIn, slotHeightIn);
this.proxy = selectionList;
}
protected int getSize()
{
return this.proxy.getItemCount();
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
this.proxy.selectItem(slotIndex, isDoubleClick, mouseX, mouseY);
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return this.proxy.isSelectedItem(slotIndex);
}
protected void drawBackground()
{
this.proxy.renderBackground();
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
this.proxy.renderItem(slotIndex, xPos, yPos, heightIn, mouseXIn, mouseYIn);
}
public int width()
{
return this.width;
}
public int mouseY()
{
return this.mouseY;
}
public int mouseX()
{
return this.mouseX;
}
/**
* Return the height of the content being scrolled
*/
protected int getContentHeight()
{
return this.proxy.getMaxPosition();
}
protected int getScrollBarX()
{
return this.proxy.getScrollbarPosition();
}
public void handleMouseInput()
{
super.handleMouseInput();
if (this.scrollMultiplier > 0.0F && Mouse.getEventButtonState())
{
this.proxy.customMouseEvent(this.top, this.bottom, this.headerPadding, this.amountScrolled, this.slotHeight);
}
}
public void renderSelected(int p_178043_1_, int p_178043_2_, int p_178043_3_, Tezzelator p_178043_4_)
{
this.proxy.renderSelected(p_178043_1_, p_178043_2_, p_178043_3_, p_178043_4_);
}
/**
* Draws the selection box around the selected slot element.
*/
protected void drawSelectionBox(int insideLeft, int insideTop, int mouseXIn, int mouseYIn, float partialTicks)
{
int i = this.getSize();
for (int j = 0; j < i; ++j)
{
int k = insideTop + j * this.slotHeight + this.headerPadding;
int l = this.slotHeight - 4;
if (k > this.bottom || k + l < this.top)
{
this.updateItemPos(j, insideLeft, k, partialTicks);
}
if (this.showSelectionBox && this.isSelected(j))
{
this.renderSelected(this.width, k, l, Tezzelator.instance);
}
this.drawSlot(j, insideLeft, k, l, mouseXIn, mouseYIn, partialTicks);
}
}
}

View File

@@ -0,0 +1,322 @@
package net.minecraft.client.gui;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import javax.annotation.Nullable;
import net.minecraft.client.resources.I18n;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.minecraft.tileentity.CommandBlockBaseLogic;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.util.ITabCompleter;
import net.minecraft.util.TabCompleter;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiCommandBlock extends GuiScreen implements ITabCompleter
{
/** Text field containing the command block's command. */
private GuiTextField commandTextField;
private GuiTextField previousOutputTextField;
private final TileEntityCommandBlock commandBlock;
/** "Done" button for the GUI. */
private GuiButton doneBtn;
private GuiButton cancelBtn;
private GuiButton outputBtn;
private GuiButton modeBtn;
private GuiButton conditionalBtn;
private GuiButton autoExecBtn;
private boolean trackOutput;
private TileEntityCommandBlock.Mode commandBlockMode = TileEntityCommandBlock.Mode.REDSTONE;
private TabCompleter tabCompleter;
private boolean conditional;
private boolean automatic;
public GuiCommandBlock(TileEntityCommandBlock commandBlockIn)
{
this.commandBlock = commandBlockIn;
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
this.commandTextField.updateCursorCounter();
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
final CommandBlockBaseLogic commandblockbaselogic = this.commandBlock.getCommandBlockLogic();
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
this.doneBtn = this.addButton(new GuiButton(0, this.width / 2 - 4 - 150, this.height / 4 + 120 + 12, 150, 20, I18n.format("gui.done")));
this.cancelBtn = this.addButton(new GuiButton(1, this.width / 2 + 4, this.height / 4 + 120 + 12, 150, 20, I18n.format("gui.cancel")));
this.outputBtn = this.addButton(new GuiButton(4, this.width / 2 + 150 - 20, 135, 20, 20, "O"));
this.modeBtn = this.addButton(new GuiButton(5, this.width / 2 - 50 - 100 - 4, 165, 100, 20, I18n.format("advMode.mode.sequence")));
this.conditionalBtn = this.addButton(new GuiButton(6, this.width / 2 - 50, 165, 100, 20, I18n.format("advMode.mode.unconditional")));
this.autoExecBtn = this.addButton(new GuiButton(7, this.width / 2 + 50 + 4, 165, 100, 20, I18n.format("advMode.mode.redstoneTriggered")));
this.commandTextField = new GuiTextField(2, this.fontRenderer, this.width / 2 - 150, 50, 300, 20);
this.commandTextField.setMaxStringLength(32500);
this.commandTextField.setFocused(true);
this.previousOutputTextField = new GuiTextField(3, this.fontRenderer, this.width / 2 - 150, 135, 276, 20);
this.previousOutputTextField.setMaxStringLength(32500);
this.previousOutputTextField.setEnabled(false);
this.previousOutputTextField.setText("-");
this.doneBtn.enabled = false;
this.outputBtn.enabled = false;
this.modeBtn.enabled = false;
this.conditionalBtn.enabled = false;
this.autoExecBtn.enabled = false;
this.tabCompleter = new TabCompleter(this.commandTextField, true)
{
@Nullable
public BlockPos getTargetBlockPos()
{
return commandblockbaselogic.getPosition();
}
};
}
public void updateGui()
{
CommandBlockBaseLogic commandblockbaselogic = this.commandBlock.getCommandBlockLogic();
this.commandTextField.setText(commandblockbaselogic.getCommand());
this.trackOutput = commandblockbaselogic.shouldTrackOutput();
this.commandBlockMode = this.commandBlock.getMode();
this.conditional = this.commandBlock.isConditional();
this.automatic = this.commandBlock.isAuto();
this.updateCmdOutput();
this.updateMode();
this.updateConditional();
this.updateAutoExec();
this.doneBtn.enabled = true;
this.outputBtn.enabled = true;
this.modeBtn.enabled = true;
this.conditionalBtn.enabled = true;
this.autoExecBtn.enabled = true;
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
CommandBlockBaseLogic commandblockbaselogic = this.commandBlock.getCommandBlockLogic();
if (button.id == 1)
{
commandblockbaselogic.setTrackOutput(this.trackOutput);
this.mc.displayGuiScreen((GuiScreen)null);
}
else if (button.id == 0)
{
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
commandblockbaselogic.fillInInfo(packetbuffer);
packetbuffer.writeString(this.commandTextField.getText());
packetbuffer.writeBoolean(commandblockbaselogic.shouldTrackOutput());
packetbuffer.writeString(this.commandBlockMode.name());
packetbuffer.writeBoolean(this.conditional);
packetbuffer.writeBoolean(this.automatic);
this.mc.getConnection().sendPacket(new CPacketCustomPayload("MC|AutoCmd", packetbuffer));
if (!commandblockbaselogic.shouldTrackOutput())
{
commandblockbaselogic.setLastOutput((ITextComponent)null);
}
this.mc.displayGuiScreen((GuiScreen)null);
}
else if (button.id == 4)
{
commandblockbaselogic.setTrackOutput(!commandblockbaselogic.shouldTrackOutput());
this.updateCmdOutput();
}
else if (button.id == 5)
{
this.nextMode();
this.updateMode();
}
else if (button.id == 6)
{
this.conditional = !this.conditional;
this.updateConditional();
}
else if (button.id == 7)
{
this.automatic = !this.automatic;
this.updateAutoExec();
}
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
this.tabCompleter.resetRequested();
if (keyCode == 15)
{
this.tabCompleter.complete();
}
else
{
this.tabCompleter.resetDidComplete();
}
this.commandTextField.textboxKeyTyped(typedChar, keyCode);
this.previousOutputTextField.textboxKeyTyped(typedChar, keyCode);
if (keyCode != 28 && keyCode != 156)
{
if (keyCode == 1)
{
this.actionPerformed(this.cancelBtn);
}
}
else
{
this.actionPerformed(this.doneBtn);
}
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.commandTextField.mouseClicked(mouseX, mouseY, mouseButton);
this.previousOutputTextField.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, I18n.format("advMode.setCommand"), this.width / 2, 20, 16777215);
this.drawString(this.fontRenderer, I18n.format("advMode.command"), this.width / 2 - 150, 40, 10526880);
this.commandTextField.drawTextBox();
int i = 75;
int j = 0;
this.drawString(this.fontRenderer, I18n.format("advMode.nearestPlayer"), this.width / 2 - 140, i + j++ * this.fontRenderer.FONT_HEIGHT, 10526880);
this.drawString(this.fontRenderer, I18n.format("advMode.randomPlayer"), this.width / 2 - 140, i + j++ * this.fontRenderer.FONT_HEIGHT, 10526880);
this.drawString(this.fontRenderer, I18n.format("advMode.allPlayers"), this.width / 2 - 140, i + j++ * this.fontRenderer.FONT_HEIGHT, 10526880);
this.drawString(this.fontRenderer, I18n.format("advMode.allEntities"), this.width / 2 - 140, i + j++ * this.fontRenderer.FONT_HEIGHT, 10526880);
this.drawString(this.fontRenderer, I18n.format("advMode.self"), this.width / 2 - 140, i + j++ * this.fontRenderer.FONT_HEIGHT, 10526880);
if (!this.previousOutputTextField.getText().isEmpty())
{
i = i + j * this.fontRenderer.FONT_HEIGHT + 1;
this.drawString(this.fontRenderer, I18n.format("advMode.previousOutput"), this.width / 2 - 150, i + 4, 10526880);
this.previousOutputTextField.drawTextBox();
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
private void updateCmdOutput()
{
CommandBlockBaseLogic commandblockbaselogic = this.commandBlock.getCommandBlockLogic();
if (commandblockbaselogic.shouldTrackOutput())
{
this.outputBtn.displayString = "O";
if (commandblockbaselogic.getLastOutput() != null)
{
this.previousOutputTextField.setText(commandblockbaselogic.getLastOutput().getUnformattedText());
}
}
else
{
this.outputBtn.displayString = "X";
this.previousOutputTextField.setText("-");
}
}
private void updateMode()
{
switch (this.commandBlockMode)
{
case SEQUENCE:
this.modeBtn.displayString = I18n.format("advMode.mode.sequence");
break;
case AUTO:
this.modeBtn.displayString = I18n.format("advMode.mode.auto");
break;
case REDSTONE:
this.modeBtn.displayString = I18n.format("advMode.mode.redstone");
}
}
private void nextMode()
{
switch (this.commandBlockMode)
{
case SEQUENCE:
this.commandBlockMode = TileEntityCommandBlock.Mode.AUTO;
break;
case AUTO:
this.commandBlockMode = TileEntityCommandBlock.Mode.REDSTONE;
break;
case REDSTONE:
this.commandBlockMode = TileEntityCommandBlock.Mode.SEQUENCE;
}
}
private void updateConditional()
{
if (this.conditional)
{
this.conditionalBtn.displayString = I18n.format("advMode.mode.conditional");
}
else
{
this.conditionalBtn.displayString = I18n.format("advMode.mode.unconditional");
}
}
private void updateAutoExec()
{
if (this.automatic)
{
this.autoExecBtn.displayString = I18n.format("advMode.mode.autoexec.bat");
}
else
{
this.autoExecBtn.displayString = I18n.format("advMode.mode.redstoneTriggered");
}
}
/**
* Sets the list of tab completions, as long as they were previously requested.
*/
public void setCompletions(String... newCompletions)
{
this.tabCompleter.setCompletions(newCompletions);
}
}

View File

@@ -0,0 +1,79 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiConfirmOpenLink extends GuiYesNo
{
/** Text to warn players from opening unsafe links. */
private final String openLinkWarning;
/** Label for the Copy to Clipboard button. */
private final String copyLinkButtonText;
private final String linkText;
private boolean showSecurityWarning = true;
public GuiConfirmOpenLink(GuiYesNoCallback parentScreenIn, String linkTextIn, int parentButtonClickedIdIn, boolean trusted)
{
super(parentScreenIn, I18n.format(trusted ? "chat.link.confirmTrusted" : "chat.link.confirm"), linkTextIn, parentButtonClickedIdIn);
this.confirmButtonText = I18n.format(trusted ? "chat.link.open" : "gui.yes");
this.cancelButtonText = I18n.format(trusted ? "gui.cancel" : "gui.no");
this.copyLinkButtonText = I18n.format("chat.copy");
this.openLinkWarning = I18n.format("chat.link.warning");
this.linkText = linkTextIn;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
this.buttonList.clear();
this.buttonList.add(new GuiButton(0, this.width / 2 - 50 - 105, this.height / 6 + 96, 100, 20, this.confirmButtonText));
this.buttonList.add(new GuiButton(2, this.width / 2 - 50, this.height / 6 + 96, 100, 20, this.copyLinkButtonText));
this.buttonList.add(new GuiButton(1, this.width / 2 - 50 + 105, this.height / 6 + 96, 100, 20, this.cancelButtonText));
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 2)
{
this.copyLinkToClipboard();
}
this.parentScreen.confirmClicked(button.id == 0, this.parentButtonClickedId);
}
/**
* Copies the link to the system clipboard.
*/
public void copyLinkToClipboard()
{
setClipboardString(this.linkText);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
super.drawScreen(mouseX, mouseY, partialTicks);
if (this.showSecurityWarning)
{
this.drawCenteredString(this.fontRenderer, this.openLinkWarning, this.width / 2, 110, 16764108);
}
}
public void disableSecurityWarning()
{
this.showSecurityWarning = false;
}
}

View File

@@ -0,0 +1,179 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiControls extends GuiScreen
{
private static final GameSettings.Options[] OPTIONS_ARR = new GameSettings.Options[] {GameSettings.Options.INVERT_MOUSE, GameSettings.Options.SENSITIVITY, GameSettings.Options.TOUCHSCREEN, GameSettings.Options.AUTO_JUMP};
/** A reference to the screen object that created this. Used for navigating between screens. */
private final GuiScreen parentScreen;
protected String screenTitle = "Controls";
/** Reference to the GameSettings object. */
private final GameSettings options;
/** The ID of the button that has been pressed. */
public KeyBinding buttonId;
public long time;
private GuiKeyBindingList keyBindingList;
private GuiButton buttonReset;
public GuiControls(GuiScreen screen, GameSettings settings)
{
this.parentScreen = screen;
this.options = settings;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.keyBindingList = new GuiKeyBindingList(this, this.mc);
this.buttonList.add(new GuiButton(200, this.width / 2 - 155 + 160, this.height - 29, 150, 20, I18n.format("gui.done")));
this.buttonReset = this.addButton(new GuiButton(201, this.width / 2 - 155, this.height - 29, 150, 20, I18n.format("controls.resetAll")));
this.screenTitle = I18n.format("controls.title");
int i = 0;
for (GameSettings.Options gamesettings$options : OPTIONS_ARR)
{
if (gamesettings$options.isFloat())
{
this.buttonList.add(new GuiOptionSlider(gamesettings$options.getOrdinal(), this.width / 2 - 155 + i % 2 * 160, 18 + 24 * (i >> 1), gamesettings$options));
}
else
{
this.buttonList.add(new GuiOptionButton(gamesettings$options.getOrdinal(), this.width / 2 - 155 + i % 2 * 160, 18 + 24 * (i >> 1), gamesettings$options, this.options.getKeyBinding(gamesettings$options)));
}
++i;
}
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.keyBindingList.handleMouseInput();
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 200)
{
this.mc.displayGuiScreen(this.parentScreen);
}
else if (button.id == 201)
{
for (KeyBinding keybinding : this.mc.gameSettings.keyBindings)
{
keybinding.setToDefault();
}
KeyBinding.resetKeyBindingArrayAndHash();
}
else if (button.id < 100 && button instanceof GuiOptionButton)
{
this.options.setOptionValue(((GuiOptionButton)button).getOption(), 1);
button.displayString = this.options.getKeyBinding(GameSettings.Options.byOrdinal(button.id));
}
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
if (this.buttonId != null)
{
this.buttonId.setKeyModifierAndCode(net.minecraftforge.client.settings.KeyModifier.getActiveModifier(), -100 + mouseButton);
this.options.setOptionKeyBinding(this.buttonId, -100 + mouseButton);
this.buttonId = null;
KeyBinding.resetKeyBindingArrayAndHash();
}
else if (mouseButton != 0 || !this.keyBindingList.mouseClicked(mouseX, mouseY, mouseButton))
{
super.mouseClicked(mouseX, mouseY, mouseButton);
}
}
/**
* Called when a mouse button is released.
*/
protected void mouseReleased(int mouseX, int mouseY, int state)
{
if (state != 0 || !this.keyBindingList.mouseReleased(mouseX, mouseY, state))
{
super.mouseReleased(mouseX, mouseY, state);
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (this.buttonId != null)
{
if (keyCode == 1)
{
this.buttonId.setKeyModifierAndCode(net.minecraftforge.client.settings.KeyModifier.NONE, 0);
this.options.setOptionKeyBinding(this.buttonId, 0);
}
else if (keyCode != 0)
{
this.buttonId.setKeyModifierAndCode(net.minecraftforge.client.settings.KeyModifier.getActiveModifier(), keyCode);
this.options.setOptionKeyBinding(this.buttonId, keyCode);
}
else if (typedChar > 0)
{
this.buttonId.setKeyModifierAndCode(net.minecraftforge.client.settings.KeyModifier.getActiveModifier(), typedChar + 256);
this.options.setOptionKeyBinding(this.buttonId, typedChar + 256);
}
if (!net.minecraftforge.client.settings.KeyModifier.isKeyCodeModifier(keyCode))
this.buttonId = null;
this.time = Minecraft.getSystemTime();
KeyBinding.resetKeyBindingArrayAndHash();
}
else
{
super.keyTyped(typedChar, keyCode);
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.keyBindingList.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 8, 16777215);
boolean flag = false;
for (KeyBinding keybinding : this.options.keyBindings)
{
if (!keybinding.isSetToDefaultValue())
{
flag = true;
break;
}
}
this.buttonReset.enabled = flag;
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,296 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.gen.FlatGeneratorInfo;
import net.minecraft.world.gen.FlatLayerInfo;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiCreateFlatWorld extends GuiScreen
{
private final GuiCreateWorld createWorldGui;
private FlatGeneratorInfo generatorInfo = FlatGeneratorInfo.getDefaultFlatGenerator();
/** The title given to the flat world currently in creation */
private String flatWorldTitle;
/** The text used to identify the material for a layer */
private String materialText;
/** The text used to identify the height of a layer */
private String heightText;
private GuiCreateFlatWorld.Details createFlatWorldListSlotGui;
/** The (unused and permenantly hidden) add layer button */
private GuiButton addLayerButton;
/** The (unused and permenantly hidden) edit layer button */
private GuiButton editLayerButton;
/** The remove layer button */
private GuiButton removeLayerButton;
public GuiCreateFlatWorld(GuiCreateWorld createWorldGuiIn, String preset)
{
this.createWorldGui = createWorldGuiIn;
this.setPreset(preset);
}
/**
* Gets the superflat preset in the text format described on the Superflat article on the Minecraft Wiki
*/
public String getPreset()
{
return this.generatorInfo.toString();
}
/**
* Sets the superflat preset. Invalid or null values will result in the default superflat preset being used.
*/
public void setPreset(String preset)
{
this.generatorInfo = FlatGeneratorInfo.createFlatGeneratorFromString(preset);
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
this.flatWorldTitle = I18n.format("createWorld.customize.flat.title");
this.materialText = I18n.format("createWorld.customize.flat.tile");
this.heightText = I18n.format("createWorld.customize.flat.height");
this.createFlatWorldListSlotGui = new GuiCreateFlatWorld.Details();
this.addLayerButton = this.addButton(new GuiButton(2, this.width / 2 - 154, this.height - 52, 100, 20, I18n.format("createWorld.customize.flat.addLayer") + " (NYI)"));
this.editLayerButton = this.addButton(new GuiButton(3, this.width / 2 - 50, this.height - 52, 100, 20, I18n.format("createWorld.customize.flat.editLayer") + " (NYI)"));
this.removeLayerButton = this.addButton(new GuiButton(4, this.width / 2 - 155, this.height - 52, 150, 20, I18n.format("createWorld.customize.flat.removeLayer")));
this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, I18n.format("gui.done")));
this.buttonList.add(new GuiButton(5, this.width / 2 + 5, this.height - 52, 150, 20, I18n.format("createWorld.customize.presets")));
this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, I18n.format("gui.cancel")));
this.addLayerButton.visible = false;
this.editLayerButton.visible = false;
this.generatorInfo.updateLayers();
this.onLayersChanged();
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.createFlatWorldListSlotGui.handleMouseInput();
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
int i = this.generatorInfo.getFlatLayers().size() - this.createFlatWorldListSlotGui.selectedLayer - 1;
if (button.id == 1)
{
this.mc.displayGuiScreen(this.createWorldGui);
}
else if (button.id == 0)
{
this.createWorldGui.chunkProviderSettingsJson = this.getPreset();
this.mc.displayGuiScreen(this.createWorldGui);
}
else if (button.id == 5)
{
this.mc.displayGuiScreen(new GuiFlatPresets(this));
}
else if (button.id == 4 && this.hasSelectedLayer())
{
this.generatorInfo.getFlatLayers().remove(i);
this.createFlatWorldListSlotGui.selectedLayer = Math.min(this.createFlatWorldListSlotGui.selectedLayer, this.generatorInfo.getFlatLayers().size() - 1);
}
this.generatorInfo.updateLayers();
this.onLayersChanged();
}
/**
* Would update whether or not the edit and remove buttons are enabled, but is currently disabled and always
* disables the buttons (which are invisible anyways)
*/
public void onLayersChanged()
{
boolean flag = this.hasSelectedLayer();
this.removeLayerButton.enabled = flag;
this.editLayerButton.enabled = flag;
this.editLayerButton.enabled = false;
this.addLayerButton.enabled = false;
}
/**
* Returns whether there is a valid layer selection
*/
private boolean hasSelectedLayer()
{
return this.createFlatWorldListSlotGui.selectedLayer > -1 && this.createFlatWorldListSlotGui.selectedLayer < this.generatorInfo.getFlatLayers().size();
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.createFlatWorldListSlotGui.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRenderer, this.flatWorldTitle, this.width / 2, 8, 16777215);
int i = this.width / 2 - 92 - 16;
this.drawString(this.fontRenderer, this.materialText, i, 32, 16777215);
this.drawString(this.fontRenderer, this.heightText, i + 2 + 213 - this.fontRenderer.getStringWidth(this.heightText), 32, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
@SideOnly(Side.CLIENT)
class Details extends GuiSlot
{
/**
* The currently selected layer; -1 if there is no selection. This is in the order that it is displayed on-
* screen, with the topmost layer having index 0.
*/
public int selectedLayer = -1;
public Details()
{
super(GuiCreateFlatWorld.this.mc, GuiCreateFlatWorld.this.width, GuiCreateFlatWorld.this.height, 43, GuiCreateFlatWorld.this.height - 60, 24);
}
/**
* Draws an item with a background at the given coordinates. The item and its background are 20 pixels tall/wide
* (though only the inner 18x18 is actually drawn on)
*/
private void drawItem(int x, int z, ItemStack itemToDraw)
{
this.drawItemBackground(x + 1, z + 1);
GlStateManager.enableRescaleNormal();
if (!itemToDraw.isEmpty())
{
RenderHelper.enableGUIStandardItemLighting();
GuiCreateFlatWorld.this.itemRender.renderItemIntoGUI(itemToDraw, x + 2, z + 2);
RenderHelper.disableStandardItemLighting();
}
GlStateManager.disableRescaleNormal();
}
/**
* Draws the background icon for an item, with the indented texture from stats.png
*/
private void drawItemBackground(int x, int y)
{
this.drawItemBackground(x, y, 0, 0);
}
/**
* Draws the background icon for an item, using a texture from stats.png with the given coords
*/
private void drawItemBackground(int x, int z, int textureX, int textureY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(Gui.STAT_ICONS);
float f = 0.0078125F;
float f1 = 0.0078125F;
int i = 18;
int j = 18;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((double)(x + 0), (double)(z + 18), (double)GuiCreateFlatWorld.this.zLevel).tex((double)((float)(textureX + 0) * 0.0078125F), (double)((float)(textureY + 18) * 0.0078125F)).endVertex();
bufferbuilder.pos((double)(x + 18), (double)(z + 18), (double)GuiCreateFlatWorld.this.zLevel).tex((double)((float)(textureX + 18) * 0.0078125F), (double)((float)(textureY + 18) * 0.0078125F)).endVertex();
bufferbuilder.pos((double)(x + 18), (double)(z + 0), (double)GuiCreateFlatWorld.this.zLevel).tex((double)((float)(textureX + 18) * 0.0078125F), (double)((float)(textureY + 0) * 0.0078125F)).endVertex();
bufferbuilder.pos((double)(x + 0), (double)(z + 0), (double)GuiCreateFlatWorld.this.zLevel).tex((double)((float)(textureX + 0) * 0.0078125F), (double)((float)(textureY + 0) * 0.0078125F)).endVertex();
tessellator.draw();
}
protected int getSize()
{
return GuiCreateFlatWorld.this.generatorInfo.getFlatLayers().size();
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
this.selectedLayer = slotIndex;
GuiCreateFlatWorld.this.onLayersChanged();
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return slotIndex == this.selectedLayer;
}
protected void drawBackground()
{
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
FlatLayerInfo flatlayerinfo = (FlatLayerInfo)GuiCreateFlatWorld.this.generatorInfo.getFlatLayers().get(GuiCreateFlatWorld.this.generatorInfo.getFlatLayers().size() - slotIndex - 1);
IBlockState iblockstate = flatlayerinfo.getLayerMaterial();
Block block = iblockstate.getBlock();
Item item = Item.getItemFromBlock(block);
if (item == Items.AIR)
{
if (block != Blocks.WATER && block != Blocks.FLOWING_WATER)
{
if (block == Blocks.LAVA || block == Blocks.FLOWING_LAVA)
{
item = Items.LAVA_BUCKET;
}
}
else
{
item = Items.WATER_BUCKET;
}
}
ItemStack itemstack = new ItemStack(item, 1, item.getHasSubtypes() ? block.getMetaFromState(iblockstate) : 0);
String s = item.getItemStackDisplayName(itemstack);
this.drawItem(xPos, yPos, itemstack);
GuiCreateFlatWorld.this.fontRenderer.drawString(s, xPos + 18 + 5, yPos + 3, 16777215);
String s1;
if (slotIndex == 0)
{
s1 = I18n.format("createWorld.customize.flat.layer.top", flatlayerinfo.getLayerCount());
}
else if (slotIndex == GuiCreateFlatWorld.this.generatorInfo.getFlatLayers().size() - 1)
{
s1 = I18n.format("createWorld.customize.flat.layer.bottom", flatlayerinfo.getLayerCount());
}
else
{
s1 = I18n.format("createWorld.customize.flat.layer", flatlayerinfo.getLayerCount());
}
GuiCreateFlatWorld.this.fontRenderer.drawString(s1, xPos + 2 + 213 - GuiCreateFlatWorld.this.fontRenderer.getStringWidth(s1), yPos + 3, 16777215);
}
protected int getScrollBarX()
{
return this.width - 70;
}
}
}

View File

@@ -0,0 +1,547 @@
package net.minecraft.client.gui;
import java.io.IOException;
import java.util.Random;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.world.GameType;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.WorldType;
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.StringUtils;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiCreateWorld extends GuiScreen
{
private final GuiScreen parentScreen;
private GuiTextField worldNameField;
private GuiTextField worldSeedField;
private String saveDirName;
private String gameMode = "survival";
/** Used to save away the game mode when the current "debug" world type is chosen (forcing it to spectator mode) */
private String savedGameMode;
private boolean generateStructuresEnabled = true;
/** If cheats are allowed */
private boolean allowCheats;
/**
* User explicitly clicked "Allow Cheats" at some point
* Prevents value changes due to changing game mode
*/
private boolean allowCheatsWasSetByUser;
private boolean bonusChestEnabled;
/** Set to true when "hardcore" is the currently-selected gamemode */
private boolean hardCoreMode;
private boolean alreadyGenerated;
private boolean inMoreWorldOptionsDisplay;
private GuiButton btnGameMode;
private GuiButton btnMoreOptions;
private GuiButton btnMapFeatures;
private GuiButton btnBonusItems;
private GuiButton btnMapType;
private GuiButton btnAllowCommands;
private GuiButton btnCustomizeType;
private String gameModeDesc1;
private String gameModeDesc2;
private String worldSeed;
private String worldName;
private int selectedIndex;
public String chunkProviderSettingsJson = "";
/** These filenames are known to be restricted on one or more OS's. */
private static final String[] DISALLOWED_FILENAMES = 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"};
public GuiCreateWorld(GuiScreen p_i46320_1_)
{
this.parentScreen = p_i46320_1_;
this.worldSeed = "";
this.worldName = I18n.format("selectWorld.newWorld");
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
this.worldNameField.updateCursorCounter();
this.worldSeedField.updateCursorCounter();
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, I18n.format("selectWorld.create")));
this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, I18n.format("gui.cancel")));
this.btnGameMode = this.addButton(new GuiButton(2, this.width / 2 - 75, 115, 150, 20, I18n.format("selectWorld.gameMode")));
this.btnMoreOptions = this.addButton(new GuiButton(3, this.width / 2 - 75, 187, 150, 20, I18n.format("selectWorld.moreWorldOptions")));
this.btnMapFeatures = this.addButton(new GuiButton(4, this.width / 2 - 155, 100, 150, 20, I18n.format("selectWorld.mapFeatures")));
this.btnMapFeatures.visible = false;
this.btnBonusItems = this.addButton(new GuiButton(7, this.width / 2 + 5, 151, 150, 20, I18n.format("selectWorld.bonusItems")));
this.btnBonusItems.visible = false;
this.btnMapType = this.addButton(new GuiButton(5, this.width / 2 + 5, 100, 150, 20, I18n.format("selectWorld.mapType")));
this.btnMapType.visible = false;
this.btnAllowCommands = this.addButton(new GuiButton(6, this.width / 2 - 155, 151, 150, 20, I18n.format("selectWorld.allowCommands")));
this.btnAllowCommands.visible = false;
this.btnCustomizeType = this.addButton(new GuiButton(8, this.width / 2 + 5, 120, 150, 20, I18n.format("selectWorld.customizeType")));
this.btnCustomizeType.visible = false;
this.worldNameField = new GuiTextField(9, this.fontRenderer, this.width / 2 - 100, 60, 200, 20);
this.worldNameField.setFocused(true);
this.worldNameField.setText(this.worldName);
this.worldSeedField = new GuiTextField(10, this.fontRenderer, this.width / 2 - 100, 60, 200, 20);
this.worldSeedField.setText(this.worldSeed);
this.showMoreWorldOptions(this.inMoreWorldOptionsDisplay);
this.calcSaveDirName();
this.updateDisplayState();
}
/**
* Determine a save-directory name from the world name
*/
private void calcSaveDirName()
{
this.saveDirName = this.worldNameField.getText().trim();
for (char c0 : ChatAllowedCharacters.ILLEGAL_FILE_CHARACTERS)
{
this.saveDirName = this.saveDirName.replace(c0, '_');
}
if (StringUtils.isEmpty(this.saveDirName))
{
this.saveDirName = "World";
}
this.saveDirName = getUncollidingSaveDirName(this.mc.getSaveLoader(), this.saveDirName);
}
/**
* Sets displayed GUI elements according to the current settings state
*/
private void updateDisplayState()
{
this.btnGameMode.displayString = I18n.format("selectWorld.gameMode") + ": " + I18n.format("selectWorld.gameMode." + this.gameMode);
this.gameModeDesc1 = I18n.format("selectWorld.gameMode." + this.gameMode + ".line1");
this.gameModeDesc2 = I18n.format("selectWorld.gameMode." + this.gameMode + ".line2");
this.btnMapFeatures.displayString = I18n.format("selectWorld.mapFeatures") + " ";
if (this.generateStructuresEnabled)
{
this.btnMapFeatures.displayString = this.btnMapFeatures.displayString + I18n.format("options.on");
}
else
{
this.btnMapFeatures.displayString = this.btnMapFeatures.displayString + I18n.format("options.off");
}
this.btnBonusItems.displayString = I18n.format("selectWorld.bonusItems") + " ";
if (this.bonusChestEnabled && !this.hardCoreMode)
{
this.btnBonusItems.displayString = this.btnBonusItems.displayString + I18n.format("options.on");
}
else
{
this.btnBonusItems.displayString = this.btnBonusItems.displayString + I18n.format("options.off");
}
this.btnMapType.displayString = I18n.format("selectWorld.mapType") + " " + I18n.format(WorldType.WORLD_TYPES[this.selectedIndex].getTranslationKey());
this.btnAllowCommands.displayString = I18n.format("selectWorld.allowCommands") + " ";
if (this.allowCheats && !this.hardCoreMode)
{
this.btnAllowCommands.displayString = this.btnAllowCommands.displayString + I18n.format("options.on");
}
else
{
this.btnAllowCommands.displayString = this.btnAllowCommands.displayString + I18n.format("options.off");
}
}
/**
* Ensures that a proposed directory name doesn't collide with existing names.
* Returns the name, possibly modified to avoid collisions.
*/
public static String getUncollidingSaveDirName(ISaveFormat saveLoader, String name)
{
name = name.replaceAll("[\\./\"]", "_");
for (String s : DISALLOWED_FILENAMES)
{
if (name.equalsIgnoreCase(s))
{
name = "_" + name + "_";
}
}
while (saveLoader.getWorldInfo(name) != null)
{
name = name + "-";
}
return name;
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 1)
{
this.mc.displayGuiScreen(this.parentScreen);
}
else if (button.id == 0)
{
this.mc.displayGuiScreen((GuiScreen)null);
if (this.alreadyGenerated)
{
return;
}
this.alreadyGenerated = true;
long i = (new Random()).nextLong();
String s = this.worldSeedField.getText();
if (!StringUtils.isEmpty(s))
{
try
{
long j = Long.parseLong(s);
if (j != 0L)
{
i = j;
}
}
catch (NumberFormatException var7)
{
i = (long)s.hashCode();
}
}
WorldType.WORLD_TYPES[this.selectedIndex].onGUICreateWorldPress();
WorldSettings worldsettings = new WorldSettings(i, GameType.getByName(this.gameMode), this.generateStructuresEnabled, this.hardCoreMode, WorldType.WORLD_TYPES[this.selectedIndex]);
worldsettings.setGeneratorOptions(this.chunkProviderSettingsJson);
if (this.bonusChestEnabled && !this.hardCoreMode)
{
worldsettings.enableBonusChest();
}
if (this.allowCheats && !this.hardCoreMode)
{
worldsettings.enableCommands();
}
this.mc.launchIntegratedServer(this.saveDirName, this.worldNameField.getText().trim(), worldsettings);
}
else if (button.id == 3)
{
this.toggleMoreWorldOptions();
}
else if (button.id == 2)
{
if ("survival".equals(this.gameMode))
{
if (!this.allowCheatsWasSetByUser)
{
this.allowCheats = false;
}
this.hardCoreMode = false;
this.gameMode = "hardcore";
this.hardCoreMode = true;
this.btnAllowCommands.enabled = false;
this.btnBonusItems.enabled = false;
this.updateDisplayState();
}
else if ("hardcore".equals(this.gameMode))
{
if (!this.allowCheatsWasSetByUser)
{
this.allowCheats = true;
}
this.hardCoreMode = false;
this.gameMode = "creative";
this.updateDisplayState();
this.hardCoreMode = false;
this.btnAllowCommands.enabled = true;
this.btnBonusItems.enabled = true;
}
else
{
if (!this.allowCheatsWasSetByUser)
{
this.allowCheats = false;
}
this.gameMode = "survival";
this.updateDisplayState();
this.btnAllowCommands.enabled = true;
this.btnBonusItems.enabled = true;
this.hardCoreMode = false;
}
this.updateDisplayState();
}
else if (button.id == 4)
{
this.generateStructuresEnabled = !this.generateStructuresEnabled;
this.updateDisplayState();
}
else if (button.id == 7)
{
this.bonusChestEnabled = !this.bonusChestEnabled;
this.updateDisplayState();
}
else if (button.id == 5)
{
++this.selectedIndex;
if (this.selectedIndex >= WorldType.WORLD_TYPES.length)
{
this.selectedIndex = 0;
}
while (!this.canSelectCurWorldType())
{
++this.selectedIndex;
if (this.selectedIndex >= WorldType.WORLD_TYPES.length)
{
this.selectedIndex = 0;
}
}
this.chunkProviderSettingsJson = "";
this.updateDisplayState();
this.showMoreWorldOptions(this.inMoreWorldOptionsDisplay);
}
else if (button.id == 6)
{
this.allowCheatsWasSetByUser = true;
this.allowCheats = !this.allowCheats;
this.updateDisplayState();
}
else if (button.id == 8)
{
WorldType.WORLD_TYPES[this.selectedIndex].onCustomizeButton(mc, this);
}
}
}
/**
* Returns whether the currently-selected world type is actually acceptable for selection
* Used to hide the "debug" world type unless the shift key is depressed.
*/
private boolean canSelectCurWorldType()
{
WorldType worldtype = WorldType.WORLD_TYPES[this.selectedIndex];
if (worldtype != null && worldtype.canBeCreated())
{
return worldtype == WorldType.DEBUG_ALL_BLOCK_STATES ? isShiftKeyDown() : true;
}
else
{
return false;
}
}
/**
* Toggles between initial world-creation display, and "more options" display.
* Called when user clicks "More World Options..." or "Done" (same button, different labels depending on current
* display).
*/
private void toggleMoreWorldOptions()
{
this.showMoreWorldOptions(!this.inMoreWorldOptionsDisplay);
}
/**
* Shows additional world-creation options if toggle is true, otherwise shows main world-creation elements
*/
private void showMoreWorldOptions(boolean toggle)
{
this.inMoreWorldOptionsDisplay = toggle;
if (WorldType.WORLD_TYPES[this.selectedIndex] == WorldType.DEBUG_ALL_BLOCK_STATES)
{
this.btnGameMode.visible = !this.inMoreWorldOptionsDisplay;
this.btnGameMode.enabled = false;
if (this.savedGameMode == null)
{
this.savedGameMode = this.gameMode;
}
this.gameMode = "spectator";
this.btnMapFeatures.visible = false;
this.btnBonusItems.visible = false;
this.btnMapType.visible = this.inMoreWorldOptionsDisplay;
this.btnAllowCommands.visible = false;
this.btnCustomizeType.visible = false;
}
else
{
this.btnGameMode.visible = !this.inMoreWorldOptionsDisplay;
this.btnGameMode.enabled = true;
if (this.savedGameMode != null)
{
this.gameMode = this.savedGameMode;
this.savedGameMode = null;
}
this.btnMapFeatures.visible = this.inMoreWorldOptionsDisplay && WorldType.WORLD_TYPES[this.selectedIndex] != WorldType.CUSTOMIZED;
this.btnBonusItems.visible = this.inMoreWorldOptionsDisplay;
this.btnMapType.visible = this.inMoreWorldOptionsDisplay;
this.btnAllowCommands.visible = this.inMoreWorldOptionsDisplay;
this.btnCustomizeType.visible = this.inMoreWorldOptionsDisplay && WorldType.WORLD_TYPES[this.selectedIndex].isCustomizable();
}
this.updateDisplayState();
if (this.inMoreWorldOptionsDisplay)
{
this.btnMoreOptions.displayString = I18n.format("gui.done");
}
else
{
this.btnMoreOptions.displayString = I18n.format("selectWorld.moreWorldOptions");
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (this.worldNameField.isFocused() && !this.inMoreWorldOptionsDisplay)
{
this.worldNameField.textboxKeyTyped(typedChar, keyCode);
this.worldName = this.worldNameField.getText();
}
else if (this.worldSeedField.isFocused() && this.inMoreWorldOptionsDisplay)
{
this.worldSeedField.textboxKeyTyped(typedChar, keyCode);
this.worldSeed = this.worldSeedField.getText();
}
if (keyCode == 28 || keyCode == 156)
{
this.actionPerformed(this.buttonList.get(0));
}
(this.buttonList.get(0)).enabled = !this.worldNameField.getText().isEmpty();
this.calcSaveDirName();
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
if (this.inMoreWorldOptionsDisplay)
{
this.worldSeedField.mouseClicked(mouseX, mouseY, mouseButton);
}
else
{
this.worldNameField.mouseClicked(mouseX, mouseY, mouseButton);
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, I18n.format("selectWorld.create"), this.width / 2, 20, -1);
if (this.inMoreWorldOptionsDisplay)
{
this.drawString(this.fontRenderer, I18n.format("selectWorld.enterSeed"), this.width / 2 - 100, 47, -6250336);
this.drawString(this.fontRenderer, I18n.format("selectWorld.seedInfo"), this.width / 2 - 100, 85, -6250336);
if (this.btnMapFeatures.visible)
{
this.drawString(this.fontRenderer, I18n.format("selectWorld.mapFeatures.info"), this.width / 2 - 150, 122, -6250336);
}
if (this.btnAllowCommands.visible)
{
this.drawString(this.fontRenderer, I18n.format("selectWorld.allowCommands.info"), this.width / 2 - 150, 172, -6250336);
}
this.worldSeedField.drawTextBox();
if (WorldType.WORLD_TYPES[this.selectedIndex].hasInfoNotice())
{
this.fontRenderer.drawSplitString(I18n.format(WorldType.WORLD_TYPES[this.selectedIndex].getInfoTranslationKey()), this.btnMapType.x + 2, this.btnMapType.y + 22, this.btnMapType.getButtonWidth(), 10526880);
}
}
else
{
this.drawString(this.fontRenderer, I18n.format("selectWorld.enterName"), this.width / 2 - 100, 47, -6250336);
this.drawString(this.fontRenderer, I18n.format("selectWorld.resultFolder") + " " + this.saveDirName, this.width / 2 - 100, 85, -6250336);
this.worldNameField.drawTextBox();
this.drawString(this.fontRenderer, this.gameModeDesc1, this.width / 2 - 100, 137, -6250336);
this.drawString(this.fontRenderer, this.gameModeDesc2, this.width / 2 - 100, 149, -6250336);
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Set the initial values of a new world to create, from the values from an existing world.
*
* Called after construction when a user selects the "Recreate" button.
*/
public void recreateFromExistingWorld(WorldInfo original)
{
this.worldName = I18n.format("selectWorld.newWorld.copyOf", original.getWorldName());
this.worldSeed = original.getSeed() + "";
this.selectedIndex = original.getTerrainType().getId();
this.chunkProviderSettingsJson = original.getGeneratorOptions();
this.generateStructuresEnabled = original.isMapFeaturesEnabled();
this.allowCheats = original.areCommandsAllowed();
if (original.isHardcoreModeEnabled())
{
this.gameMode = "hardcore";
}
else if (original.getGameType().isSurvivalOrAdventure())
{
this.gameMode = "survival";
}
else if (original.getGameType().isCreative())
{
this.gameMode = "creative";
}
}
}

View File

@@ -0,0 +1,127 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.EnumPlayerModelParts;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiCustomizeSkin extends GuiScreen
{
/** The parent GUI for this GUI */
private final GuiScreen parentScreen;
/** The title of the GUI. */
private String title;
public GuiCustomizeSkin(GuiScreen parentScreenIn)
{
this.parentScreen = parentScreenIn;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
int i = 0;
this.title = I18n.format("options.skinCustomisation.title");
for (EnumPlayerModelParts enumplayermodelparts : EnumPlayerModelParts.values())
{
this.buttonList.add(new GuiCustomizeSkin.ButtonPart(enumplayermodelparts.getPartId(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, enumplayermodelparts));
++i;
}
this.buttonList.add(new GuiOptionButton(199, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), GameSettings.Options.MAIN_HAND, this.mc.gameSettings.getKeyBinding(GameSettings.Options.MAIN_HAND)));
++i;
if (i % 2 == 1)
{
++i;
}
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 24 * (i >> 1), I18n.format("gui.done")));
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (keyCode == 1)
{
this.mc.gameSettings.saveOptions();
}
super.keyTyped(typedChar, keyCode);
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 200)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(this.parentScreen);
}
else if (button.id == 199)
{
this.mc.gameSettings.setOptionValue(GameSettings.Options.MAIN_HAND, 1);
button.displayString = this.mc.gameSettings.getKeyBinding(GameSettings.Options.MAIN_HAND);
this.mc.gameSettings.sendSettingsToServer();
}
else if (button instanceof GuiCustomizeSkin.ButtonPart)
{
EnumPlayerModelParts enumplayermodelparts = ((GuiCustomizeSkin.ButtonPart)button).playerModelParts;
this.mc.gameSettings.switchModelPartEnabled(enumplayermodelparts);
button.displayString = this.getMessage(enumplayermodelparts);
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 20, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
private String getMessage(EnumPlayerModelParts playerModelParts)
{
String s;
if (this.mc.gameSettings.getModelParts().contains(playerModelParts))
{
s = I18n.format("options.on");
}
else
{
s = I18n.format("options.off");
}
return playerModelParts.getName().getFormattedText() + ": " + s;
}
@SideOnly(Side.CLIENT)
class ButtonPart extends GuiButton
{
private final EnumPlayerModelParts playerModelParts;
private ButtonPart(int p_i45514_2_, int p_i45514_3_, int p_i45514_4_, int p_i45514_5_, int p_i45514_6_, EnumPlayerModelParts playerModelParts)
{
super(p_i45514_2_, p_i45514_3_, p_i45514_4_, p_i45514_5_, p_i45514_6_, GuiCustomizeSkin.this.getMessage(playerModelParts));
this.playerModelParts = playerModelParts;
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,77 @@
package net.minecraft.client.gui;
import java.io.IOException;
import java.util.List;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiDisconnected extends GuiScreen
{
private final String reason;
private final ITextComponent message;
private List<String> multilineMessage;
private final GuiScreen parentScreen;
private int textHeight;
public GuiDisconnected(GuiScreen screen, String reasonLocalizationKey, ITextComponent chatComp)
{
this.parentScreen = screen;
this.reason = I18n.format(reasonLocalizationKey);
this.message = chatComp;
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
this.multilineMessage = this.fontRenderer.listFormattedStringToWidth(this.message.getFormattedText(), this.width - 50);
this.textHeight = this.multilineMessage.size() * this.fontRenderer.FONT_HEIGHT;
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, Math.min(this.height / 2 + this.textHeight / 2 + this.fontRenderer.FONT_HEIGHT, this.height - 30), I18n.format("gui.toMenu")));
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 0)
{
this.mc.displayGuiScreen(this.parentScreen);
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, this.reason, this.width / 2, this.height / 2 - this.textHeight / 2 - this.fontRenderer.FONT_HEIGHT * 2, 11184810);
int i = this.height / 2 - this.textHeight / 2;
if (this.multilineMessage != null)
{
for (String s : this.multilineMessage)
{
this.drawCenteredString(this.fontRenderer, s, this.width / 2, i, 16777215);
i += this.fontRenderer.FONT_HEIGHT;
}
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,36 @@
package net.minecraft.client.gui;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiDownloadTerrain extends GuiScreen
{
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawBackground(0);
this.drawCenteredString(this.fontRenderer, I18n.format("multiplayer.downloadingTerrain"), this.width / 2, this.height / 2 - 50, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
public boolean doesGuiPauseGame()
{
return false;
}
}

View File

@@ -0,0 +1,340 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.model.ModelBook;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerEnchantment;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnchantmentNameParts;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IWorldNameable;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.glu.Project;
@SideOnly(Side.CLIENT)
public class GuiEnchantment extends GuiContainer
{
/** The ResourceLocation containing the Enchantment GUI texture location */
private static final ResourceLocation ENCHANTMENT_TABLE_GUI_TEXTURE = new ResourceLocation("textures/gui/container/enchanting_table.png");
/** The ResourceLocation containing the texture for the Book rendered above the enchantment table */
private static final ResourceLocation ENCHANTMENT_TABLE_BOOK_TEXTURE = new ResourceLocation("textures/entity/enchanting_table_book.png");
/** The ModelBook instance used for rendering the book on the Enchantment table */
private static final ModelBook MODEL_BOOK = new ModelBook();
/** The player inventory currently bound to this GuiEnchantment instance. */
private final InventoryPlayer playerInventory;
/** A Random instance for use with the enchantment gui */
private final Random random = new Random();
private final ContainerEnchantment container;
public int ticks;
public float flip;
public float oFlip;
public float flipT;
public float flipA;
public float open;
public float oOpen;
private ItemStack last = ItemStack.EMPTY;
private final IWorldNameable nameable;
public GuiEnchantment(InventoryPlayer inventory, World worldIn, IWorldNameable nameable)
{
super(new ContainerEnchantment(inventory, worldIn));
this.playerInventory = inventory;
this.container = (ContainerEnchantment)this.inventorySlots;
this.nameable = nameable;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
this.fontRenderer.drawString(this.nameable.getDisplayName().getUnformattedText(), 12, 5, 4210752);
this.fontRenderer.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
super.updateScreen();
this.tickBook();
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
for (int k = 0; k < 3; ++k)
{
int l = mouseX - (i + 60);
int i1 = mouseY - (j + 14 + 19 * k);
if (l >= 0 && i1 >= 0 && l < 108 && i1 < 19 && this.container.enchantItem(this.mc.player, k))
{
this.mc.playerController.sendEnchantPacket(this.container.windowId, k);
}
}
}
/**
* Draws the background layer of this container (behind the items).
*/
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(ENCHANTMENT_TABLE_GUI_TEXTURE);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
GlStateManager.pushMatrix();
GlStateManager.matrixMode(5889);
GlStateManager.pushMatrix();
GlStateManager.loadIdentity();
ScaledResolution scaledresolution = new ScaledResolution(this.mc);
GlStateManager.viewport((scaledresolution.getScaledWidth() - 320) / 2 * scaledresolution.getScaleFactor(), (scaledresolution.getScaledHeight() - 240) / 2 * scaledresolution.getScaleFactor(), 320 * scaledresolution.getScaleFactor(), 240 * scaledresolution.getScaleFactor());
GlStateManager.translate(-0.34F, 0.23F, 0.0F);
Project.gluPerspective(90.0F, 1.3333334F, 9.0F, 80.0F);
float f = 1.0F;
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
RenderHelper.enableStandardItemLighting();
GlStateManager.translate(0.0F, 3.3F, -16.0F);
GlStateManager.scale(1.0F, 1.0F, 1.0F);
float f1 = 5.0F;
GlStateManager.scale(5.0F, 5.0F, 5.0F);
GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
this.mc.getTextureManager().bindTexture(ENCHANTMENT_TABLE_BOOK_TEXTURE);
GlStateManager.rotate(20.0F, 1.0F, 0.0F, 0.0F);
float f2 = this.oOpen + (this.open - this.oOpen) * partialTicks;
GlStateManager.translate((1.0F - f2) * 0.2F, (1.0F - f2) * 0.1F, (1.0F - f2) * 0.25F);
GlStateManager.rotate(-(1.0F - f2) * 90.0F - 90.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
float f3 = this.oFlip + (this.flip - this.oFlip) * partialTicks + 0.25F;
float f4 = this.oFlip + (this.flip - this.oFlip) * partialTicks + 0.75F;
f3 = (f3 - (float)MathHelper.fastFloor((double)f3)) * 1.6F - 0.3F;
f4 = (f4 - (float)MathHelper.fastFloor((double)f4)) * 1.6F - 0.3F;
if (f3 < 0.0F)
{
f3 = 0.0F;
}
if (f4 < 0.0F)
{
f4 = 0.0F;
}
if (f3 > 1.0F)
{
f3 = 1.0F;
}
if (f4 > 1.0F)
{
f4 = 1.0F;
}
GlStateManager.enableRescaleNormal();
MODEL_BOOK.render((Entity)null, 0.0F, f3, f4, f2, 0.0F, 0.0625F);
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
GlStateManager.matrixMode(5889);
GlStateManager.viewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
GlStateManager.popMatrix();
GlStateManager.matrixMode(5888);
GlStateManager.popMatrix();
RenderHelper.disableStandardItemLighting();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
EnchantmentNameParts.getInstance().reseedRandomGenerator((long)this.container.xpSeed);
int k = this.container.getLapisAmount();
for (int l = 0; l < 3; ++l)
{
int i1 = i + 60;
int j1 = i1 + 20;
this.zLevel = 0.0F;
this.mc.getTextureManager().bindTexture(ENCHANTMENT_TABLE_GUI_TEXTURE);
int k1 = this.container.enchantLevels[l];
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
if (k1 == 0)
{
this.drawTexturedModalRect(i1, j + 14 + 19 * l, 0, 185, 108, 19);
}
else
{
String s = "" + k1;
int l1 = 86 - this.fontRenderer.getStringWidth(s);
String s1 = EnchantmentNameParts.getInstance().generateNewRandomName(this.fontRenderer, l1);
FontRenderer fontrenderer = this.mc.standardGalacticFontRenderer;
int i2 = 6839882;
if (((k < l + 1 || this.mc.player.experienceLevel < k1) && !this.mc.player.capabilities.isCreativeMode) || this.container.enchantClue[l] == -1) // Forge: render buttons as disabled when enchantable but enchantability not met on lower levels
{
this.drawTexturedModalRect(i1, j + 14 + 19 * l, 0, 185, 108, 19);
this.drawTexturedModalRect(i1 + 1, j + 15 + 19 * l, 16 * l, 239, 16, 16);
fontrenderer.drawSplitString(s1, j1, j + 16 + 19 * l, l1, (i2 & 16711422) >> 1);
i2 = 4226832;
}
else
{
int j2 = mouseX - (i + 60);
int k2 = mouseY - (j + 14 + 19 * l);
if (j2 >= 0 && k2 >= 0 && j2 < 108 && k2 < 19)
{
this.drawTexturedModalRect(i1, j + 14 + 19 * l, 0, 204, 108, 19);
i2 = 16777088;
}
else
{
this.drawTexturedModalRect(i1, j + 14 + 19 * l, 0, 166, 108, 19);
}
this.drawTexturedModalRect(i1 + 1, j + 15 + 19 * l, 16 * l, 223, 16, 16);
fontrenderer.drawSplitString(s1, j1, j + 16 + 19 * l, l1, i2);
i2 = 8453920;
}
fontrenderer = this.mc.fontRenderer;
fontrenderer.drawStringWithShadow(s, (float)(j1 + 86 - fontrenderer.getStringWidth(s)), (float)(j + 16 + 19 * l + 7), i2);
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
partialTicks = this.mc.getTickLength();
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
boolean flag = this.mc.player.capabilities.isCreativeMode;
int i = this.container.getLapisAmount();
for (int j = 0; j < 3; ++j)
{
int k = this.container.enchantLevels[j];
Enchantment enchantment = Enchantment.getEnchantmentByID(this.container.enchantClue[j]);
int l = this.container.worldClue[j];
int i1 = j + 1;
if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0)
{
List<String> list = Lists.<String>newArrayList();
list.add("" + TextFormatting.WHITE + TextFormatting.ITALIC + I18n.format("container.enchant.clue", enchantment == null ? "" : enchantment.getTranslatedName(l)));
if(enchantment == null) java.util.Collections.addAll(list, "", TextFormatting.RED + I18n.format("forge.container.enchant.limitedEnchantability")); else
if (!flag)
{
list.add("");
if (this.mc.player.experienceLevel < k)
{
list.add(TextFormatting.RED + I18n.format("container.enchant.level.requirement", this.container.enchantLevels[j]));
}
else
{
String s;
if (i1 == 1)
{
s = I18n.format("container.enchant.lapis.one");
}
else
{
s = I18n.format("container.enchant.lapis.many", i1);
}
TextFormatting textformatting = i >= i1 ? TextFormatting.GRAY : TextFormatting.RED;
list.add(textformatting + "" + s);
if (i1 == 1)
{
s = I18n.format("container.enchant.level.one");
}
else
{
s = I18n.format("container.enchant.level.many", i1);
}
list.add(TextFormatting.GRAY + "" + s);
}
}
this.drawHoveringText(list, mouseX, mouseY);
break;
}
}
}
public void tickBook()
{
ItemStack itemstack = this.inventorySlots.getSlot(0).getStack();
if (!ItemStack.areItemStacksEqual(itemstack, this.last))
{
this.last = itemstack;
while (true)
{
this.flipT += (float)(this.random.nextInt(4) - this.random.nextInt(4));
if (this.flip > this.flipT + 1.0F || this.flip < this.flipT - 1.0F)
{
break;
}
}
}
++this.ticks;
this.oFlip = this.flip;
this.oOpen = this.open;
boolean flag = false;
for (int i = 0; i < 3; ++i)
{
if (this.container.enchantLevels[i] != 0)
{
flag = true;
}
}
if (flag)
{
this.open += 0.2F;
}
else
{
this.open -= 0.2F;
}
this.open = MathHelper.clamp(this.open, 0.0F, 1.0F);
float f1 = (this.flipT - this.flip) * 0.4F;
float f = 0.2F;
f1 = MathHelper.clamp(f1, -0.2F, 0.2F);
this.flipA += (f1 - this.flipA) * 0.9F;
this.flip += this.flipA;
}
}

View File

@@ -0,0 +1,56 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiErrorScreen extends GuiScreen
{
private final String title;
private final String message;
public GuiErrorScreen(String titleIn, String messageIn)
{
this.title = titleIn;
this.message = messageIn;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, 140, I18n.format("gui.cancel")));
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawGradientRect(0, 0, this.width, this.height, -12574688, -11530224);
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 90, 16777215);
this.drawCenteredString(this.fontRenderer, this.message, this.width / 2, 110, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
this.mc.displayGuiScreen((GuiScreen)null);
}
}

View File

@@ -0,0 +1,285 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.minecraft.block.BlockTallGrass;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
import net.minecraft.init.Biomes;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.FlatGeneratorInfo;
import net.minecraft.world.gen.FlatLayerInfo;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiFlatPresets extends GuiScreen
{
private static final List<GuiFlatPresets.LayerItem> FLAT_WORLD_PRESETS = Lists.<GuiFlatPresets.LayerItem>newArrayList();
/** The parent GUI */
private final GuiCreateFlatWorld parentScreen;
private String presetsTitle;
private String presetsShare;
private String listText;
private GuiFlatPresets.ListSlot list;
private GuiButton btnSelect;
private GuiTextField export;
public GuiFlatPresets(GuiCreateFlatWorld p_i46318_1_)
{
this.parentScreen = p_i46318_1_;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
Keyboard.enableRepeatEvents(true);
this.presetsTitle = I18n.format("createWorld.customize.presets.title");
this.presetsShare = I18n.format("createWorld.customize.presets.share");
this.listText = I18n.format("createWorld.customize.presets.list");
this.export = new GuiTextField(2, this.fontRenderer, 50, 40, this.width - 100, 20);
this.list = new GuiFlatPresets.ListSlot();
this.export.setMaxStringLength(1230);
this.export.setText(this.parentScreen.getPreset());
this.btnSelect = this.addButton(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20, I18n.format("createWorld.customize.presets.select")));
this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, I18n.format("gui.cancel")));
this.updateButtonValidity();
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.list.handleMouseInput();
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
this.export.mouseClicked(mouseX, mouseY, mouseButton);
super.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (!this.export.textboxKeyTyped(typedChar, keyCode))
{
super.keyTyped(typedChar, keyCode);
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 0 && this.hasValidSelection())
{
this.parentScreen.setPreset(this.export.getText());
this.mc.displayGuiScreen(this.parentScreen);
}
else if (button.id == 1)
{
this.mc.displayGuiScreen(this.parentScreen);
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.list.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRenderer, this.presetsTitle, this.width / 2, 8, 16777215);
this.drawString(this.fontRenderer, this.presetsShare, 50, 30, 10526880);
this.drawString(this.fontRenderer, this.listText, 50, 70, 10526880);
this.export.drawTextBox();
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
this.export.updateCursorCounter();
super.updateScreen();
}
public void updateButtonValidity()
{
this.btnSelect.enabled = this.hasValidSelection();
}
private boolean hasValidSelection()
{
return this.list.selected > -1 && this.list.selected < FLAT_WORLD_PRESETS.size() || this.export.getText().length() > 1;
}
private static void registerPreset(String name, Item icon, Biome biome, List<String> features, FlatLayerInfo... layers)
{
registerPreset(name, icon, 0, biome, features, layers);
}
private static void registerPreset(String name, Item icon, int iconMetadata, Biome biome, List<String> features, FlatLayerInfo... layers)
{
FlatGeneratorInfo flatgeneratorinfo = new FlatGeneratorInfo();
for (int i = layers.length - 1; i >= 0; --i)
{
flatgeneratorinfo.getFlatLayers().add(layers[i]);
}
flatgeneratorinfo.setBiome(Biome.getIdForBiome(biome));
flatgeneratorinfo.updateLayers();
for (String s : features)
{
flatgeneratorinfo.getWorldFeatures().put(s, Maps.newHashMap());
}
FLAT_WORLD_PRESETS.add(new GuiFlatPresets.LayerItem(icon, iconMetadata, name, flatgeneratorinfo.toString()));
}
static
{
registerPreset(I18n.format("createWorld.customize.preset.classic_flat"), Item.getItemFromBlock(Blocks.GRASS), Biomes.PLAINS, Arrays.asList("village"), new FlatLayerInfo(1, Blocks.GRASS), new FlatLayerInfo(2, Blocks.DIRT), new FlatLayerInfo(1, Blocks.BEDROCK));
registerPreset(I18n.format("createWorld.customize.preset.tunnelers_dream"), Item.getItemFromBlock(Blocks.STONE), Biomes.EXTREME_HILLS, Arrays.asList("biome_1", "dungeon", "decoration", "stronghold", "mineshaft"), new FlatLayerInfo(1, Blocks.GRASS), new FlatLayerInfo(5, Blocks.DIRT), new FlatLayerInfo(230, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK));
registerPreset(I18n.format("createWorld.customize.preset.water_world"), Items.WATER_BUCKET, Biomes.DEEP_OCEAN, Arrays.asList("biome_1", "oceanmonument"), new FlatLayerInfo(90, Blocks.WATER), new FlatLayerInfo(5, Blocks.SAND), new FlatLayerInfo(5, Blocks.DIRT), new FlatLayerInfo(5, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK));
registerPreset(I18n.format("createWorld.customize.preset.overworld"), Item.getItemFromBlock(Blocks.TALLGRASS), BlockTallGrass.EnumType.GRASS.getMeta(), Biomes.PLAINS, Arrays.asList("village", "biome_1", "decoration", "stronghold", "mineshaft", "dungeon", "lake", "lava_lake"), new FlatLayerInfo(1, Blocks.GRASS), new FlatLayerInfo(3, Blocks.DIRT), new FlatLayerInfo(59, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK));
registerPreset(I18n.format("createWorld.customize.preset.snowy_kingdom"), Item.getItemFromBlock(Blocks.SNOW_LAYER), Biomes.ICE_PLAINS, Arrays.asList("village", "biome_1"), new FlatLayerInfo(1, Blocks.SNOW_LAYER), new FlatLayerInfo(1, Blocks.GRASS), new FlatLayerInfo(3, Blocks.DIRT), new FlatLayerInfo(59, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK));
registerPreset(I18n.format("createWorld.customize.preset.bottomless_pit"), Items.FEATHER, Biomes.PLAINS, Arrays.asList("village", "biome_1"), new FlatLayerInfo(1, Blocks.GRASS), new FlatLayerInfo(3, Blocks.DIRT), new FlatLayerInfo(2, Blocks.COBBLESTONE));
registerPreset(I18n.format("createWorld.customize.preset.desert"), Item.getItemFromBlock(Blocks.SAND), Biomes.DESERT, Arrays.asList("village", "biome_1", "decoration", "stronghold", "mineshaft", "dungeon"), new FlatLayerInfo(8, Blocks.SAND), new FlatLayerInfo(52, Blocks.SANDSTONE), new FlatLayerInfo(3, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK));
registerPreset(I18n.format("createWorld.customize.preset.redstone_ready"), Items.REDSTONE, Biomes.DESERT, Collections.emptyList(), new FlatLayerInfo(52, Blocks.SANDSTONE), new FlatLayerInfo(3, Blocks.STONE), new FlatLayerInfo(1, Blocks.BEDROCK));
registerPreset(I18n.format("createWorld.customize.preset.the_void"), Item.getItemFromBlock(Blocks.BARRIER), Biomes.VOID, Arrays.asList("decoration"), new FlatLayerInfo(1, Blocks.AIR));
}
@SideOnly(Side.CLIENT)
static class LayerItem
{
public Item icon;
public int iconMetadata;
public String name;
public String generatorInfo;
public LayerItem(Item iconIn, int iconMetadataIn, String nameIn, String generatorInfoIn)
{
this.icon = iconIn;
this.iconMetadata = iconMetadataIn;
this.name = nameIn;
this.generatorInfo = generatorInfoIn;
}
}
@SideOnly(Side.CLIENT)
class ListSlot extends GuiSlot
{
public int selected = -1;
public ListSlot()
{
super(GuiFlatPresets.this.mc, GuiFlatPresets.this.width, GuiFlatPresets.this.height, 80, GuiFlatPresets.this.height - 37, 24);
}
private void renderIcon(int p_178054_1_, int p_178054_2_, Item icon, int iconMetadata)
{
this.blitSlotBg(p_178054_1_ + 1, p_178054_2_ + 1);
GlStateManager.enableRescaleNormal();
RenderHelper.enableGUIStandardItemLighting();
GuiFlatPresets.this.itemRender.renderItemIntoGUI(new ItemStack(icon, 1, icon.getHasSubtypes() ? iconMetadata : 0), p_178054_1_ + 2, p_178054_2_ + 2);
RenderHelper.disableStandardItemLighting();
GlStateManager.disableRescaleNormal();
}
private void blitSlotBg(int p_148173_1_, int p_148173_2_)
{
this.blitSlotIcon(p_148173_1_, p_148173_2_, 0, 0);
}
private void blitSlotIcon(int p_148171_1_, int p_148171_2_, int p_148171_3_, int p_148171_4_)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(Gui.STAT_ICONS);
float f = 0.0078125F;
float f1 = 0.0078125F;
int i = 18;
int j = 18;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((double)(p_148171_1_ + 0), (double)(p_148171_2_ + 18), (double)GuiFlatPresets.this.zLevel).tex((double)((float)(p_148171_3_ + 0) * 0.0078125F), (double)((float)(p_148171_4_ + 18) * 0.0078125F)).endVertex();
bufferbuilder.pos((double)(p_148171_1_ + 18), (double)(p_148171_2_ + 18), (double)GuiFlatPresets.this.zLevel).tex((double)((float)(p_148171_3_ + 18) * 0.0078125F), (double)((float)(p_148171_4_ + 18) * 0.0078125F)).endVertex();
bufferbuilder.pos((double)(p_148171_1_ + 18), (double)(p_148171_2_ + 0), (double)GuiFlatPresets.this.zLevel).tex((double)((float)(p_148171_3_ + 18) * 0.0078125F), (double)((float)(p_148171_4_ + 0) * 0.0078125F)).endVertex();
bufferbuilder.pos((double)(p_148171_1_ + 0), (double)(p_148171_2_ + 0), (double)GuiFlatPresets.this.zLevel).tex((double)((float)(p_148171_3_ + 0) * 0.0078125F), (double)((float)(p_148171_4_ + 0) * 0.0078125F)).endVertex();
tessellator.draw();
}
protected int getSize()
{
return GuiFlatPresets.FLAT_WORLD_PRESETS.size();
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
this.selected = slotIndex;
GuiFlatPresets.this.updateButtonValidity();
GuiFlatPresets.this.export.setText((GuiFlatPresets.FLAT_WORLD_PRESETS.get(GuiFlatPresets.this.list.selected)).generatorInfo);
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return slotIndex == this.selected;
}
protected void drawBackground()
{
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
GuiFlatPresets.LayerItem guiflatpresets$layeritem = GuiFlatPresets.FLAT_WORLD_PRESETS.get(slotIndex);
this.renderIcon(xPos, yPos, guiflatpresets$layeritem.icon, guiflatpresets$layeritem.iconMetadata);
GuiFlatPresets.this.fontRenderer.drawString(guiflatpresets$layeritem.name, xPos + 18 + 5, yPos + 6, 16777215);
}
}
}

View File

@@ -0,0 +1,200 @@
package net.minecraft.client.gui;
import java.io.IOException;
import javax.annotation.Nullable;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiGameOver extends GuiScreen
{
/** The integer value containing the number of ticks that have passed since the player's death */
private int enableButtonsTimer;
private final ITextComponent causeOfDeath;
public GuiGameOver(@Nullable ITextComponent causeOfDeathIn)
{
this.causeOfDeath = causeOfDeathIn;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
this.enableButtonsTimer = 0;
if (this.mc.world.getWorldInfo().isHardcoreModeEnabled())
{
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 72, I18n.format("deathScreen.spectate")));
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 96, I18n.format("deathScreen." + (this.mc.isIntegratedServerRunning() ? "deleteWorld" : "leaveServer"))));
}
else
{
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 72, I18n.format("deathScreen.respawn")));
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 96, I18n.format("deathScreen.titleScreen")));
if (this.mc.getSession() == null)
{
(this.buttonList.get(1)).enabled = false;
}
}
for (GuiButton guibutton : this.buttonList)
{
guibutton.enabled = false;
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
switch (button.id)
{
case 0:
this.mc.player.respawnPlayer();
this.mc.displayGuiScreen((GuiScreen)null);
break;
case 1:
if (this.mc.world.getWorldInfo().isHardcoreModeEnabled())
{
this.mc.displayGuiScreen(new GuiMainMenu());
}
else
{
GuiYesNo guiyesno = new GuiYesNo(this, I18n.format("deathScreen.quit.confirm"), "", I18n.format("deathScreen.titleScreen"), I18n.format("deathScreen.respawn"), 0);
this.mc.displayGuiScreen(guiyesno);
guiyesno.setButtonDelay(20);
}
}
}
public void confirmClicked(boolean result, int id)
{
if (result)
{
if (this.mc.world != null)
{
this.mc.world.sendQuittingDisconnectingPacket();
}
this.mc.loadWorld((WorldClient)null);
this.mc.displayGuiScreen(new GuiMainMenu());
}
else
{
this.mc.player.respawnPlayer();
this.mc.displayGuiScreen((GuiScreen)null);
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
boolean flag = this.mc.world.getWorldInfo().isHardcoreModeEnabled();
this.drawGradientRect(0, 0, this.width, this.height, 1615855616, -1602211792);
GlStateManager.pushMatrix();
GlStateManager.scale(2.0F, 2.0F, 2.0F);
this.drawCenteredString(this.fontRenderer, I18n.format(flag ? "deathScreen.title.hardcore" : "deathScreen.title"), this.width / 2 / 2, 30, 16777215);
GlStateManager.popMatrix();
if (this.causeOfDeath != null)
{
this.drawCenteredString(this.fontRenderer, this.causeOfDeath.getFormattedText(), this.width / 2, 85, 16777215);
}
this.drawCenteredString(this.fontRenderer, I18n.format("deathScreen.score") + ": " + TextFormatting.YELLOW + this.mc.player.getScore(), this.width / 2, 100, 16777215);
if (this.causeOfDeath != null && mouseY > 85 && mouseY < 85 + this.fontRenderer.FONT_HEIGHT)
{
ITextComponent itextcomponent = this.getClickedComponentAt(mouseX);
if (itextcomponent != null && itextcomponent.getStyle().getHoverEvent() != null)
{
this.handleComponentHover(itextcomponent, mouseX, mouseY);
}
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Nullable
public ITextComponent getClickedComponentAt(int p_184870_1_)
{
if (this.causeOfDeath == null)
{
return null;
}
else
{
int i = this.mc.fontRenderer.getStringWidth(this.causeOfDeath.getFormattedText());
int j = this.width / 2 - i / 2;
int k = this.width / 2 + i / 2;
int l = j;
if (p_184870_1_ >= j && p_184870_1_ <= k)
{
for (ITextComponent itextcomponent : this.causeOfDeath)
{
l += this.mc.fontRenderer.getStringWidth(GuiUtilRenderComponents.removeTextColorsIfConfigured(itextcomponent.getUnformattedComponentText(), false));
if (l > p_184870_1_)
{
return itextcomponent;
}
}
return null;
}
else
{
return null;
}
}
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
public boolean doesGuiPauseGame()
{
return false;
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
super.updateScreen();
++this.enableButtonsTimer;
if (this.enableButtonsTimer == 20)
{
for (GuiButton guibutton : this.buttonList)
{
guibutton.enabled = true;
}
}
}
}

View File

@@ -0,0 +1,62 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerHopper;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiHopper extends GuiContainer
{
/** The ResourceLocation containing the gui texture for the hopper */
private static final ResourceLocation HOPPER_GUI_TEXTURE = new ResourceLocation("textures/gui/container/hopper.png");
/** The player inventory currently bound to this GUI instance */
private final IInventory playerInventory;
/** The hopper inventory bound to this GUI instance */
private final IInventory hopperInventory;
public GuiHopper(InventoryPlayer playerInv, IInventory hopperInv)
{
super(new ContainerHopper(playerInv, hopperInv, Minecraft.getMinecraft().player));
this.playerInventory = playerInv;
this.hopperInventory = hopperInv;
this.allowUserInput = false;
this.ySize = 133;
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
this.fontRenderer.drawString(this.hopperInventory.getDisplayName().getUnformattedText(), 8, 6, 4210752);
this.fontRenderer.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
}
/**
* Draws the background layer of this container (behind the items).
*/
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(HOPPER_GUI_TEXTURE);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,118 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.gui.achievement.GuiStats;
import net.minecraft.client.gui.advancements.GuiScreenAdvancements;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.resources.I18n;
import net.minecraft.realms.RealmsBridge;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiIngameMenu extends GuiScreen
{
private int saveStep;
private int visibleTime;
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.saveStep = 0;
this.buttonList.clear();
int i = -16;
int j = 98;
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + -16, I18n.format("menu.returnToMenu")));
if (!this.mc.isIntegratedServerRunning())
{
(this.buttonList.get(0)).displayString = I18n.format("menu.disconnect");
}
this.buttonList.add(new GuiButton(4, this.width / 2 - 100, this.height / 4 + 24 + -16, I18n.format("menu.returnToGame")));
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + -16, 98, 20, I18n.format("menu.options")));
this.buttonList.add(new GuiButton(12, this.width / 2 + 2, this.height / 4 + 96 + i, 98, 20, I18n.format("fml.menu.modoptions")));
GuiButton guibutton = this.addButton(new GuiButton(7, this.width / 2 - 100, this.height / 4 + 72 + -16, 200, 20, I18n.format("menu.shareToLan", new Object[0])));
guibutton.enabled = this.mc.isSingleplayer() && !this.mc.getIntegratedServer().getPublic();
this.buttonList.add(new GuiButton(5, this.width / 2 - 100, this.height / 4 + 48 + -16, 98, 20, I18n.format("gui.advancements")));
this.buttonList.add(new GuiButton(6, this.width / 2 + 2, this.height / 4 + 48 + -16, 98, 20, I18n.format("gui.stats")));
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
switch (button.id)
{
case 0:
this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings));
break;
case 1:
boolean flag = this.mc.isIntegratedServerRunning();
boolean flag1 = this.mc.isConnectedToRealms();
button.enabled = false;
this.mc.world.sendQuittingDisconnectingPacket();
this.mc.loadWorld((WorldClient)null);
if (flag)
{
this.mc.displayGuiScreen(new GuiMainMenu());
}
else if (flag1)
{
RealmsBridge realmsbridge = new RealmsBridge();
realmsbridge.switchToRealms(new GuiMainMenu());
}
else
{
this.mc.displayGuiScreen(new GuiMultiplayer(new GuiMainMenu()));
}
case 2:
case 3:
default:
break;
case 4:
this.mc.displayGuiScreen((GuiScreen)null);
this.mc.setIngameFocus();
break;
case 5:
if (this.mc.player != null)
this.mc.displayGuiScreen(new GuiScreenAdvancements(this.mc.player.connection.getAdvancementManager()));
break;
case 6:
if (this.mc.player != null)
this.mc.displayGuiScreen(new GuiStats(this, this.mc.player.getStatFileWriter()));
break;
case 7:
this.mc.displayGuiScreen(new GuiShareToLan(this));
break;
case 12:
net.minecraftforge.fml.client.FMLClientHandler.instance().showInGameModOptions(this);
break;
}
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
super.updateScreen();
++this.visibleTime;
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, I18n.format("menu.game"), this.width / 2, 40, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,210 @@
package net.minecraft.client.gui;
import java.util.Arrays;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.ArrayUtils;
@SideOnly(Side.CLIENT)
public class GuiKeyBindingList extends GuiListExtended
{
private final GuiControls controlsScreen;
private final Minecraft mc;
private final GuiListExtended.IGuiListEntry[] listEntries;
private int maxListLabelWidth;
public GuiKeyBindingList(GuiControls controls, Minecraft mcIn)
{
super(mcIn, controls.width + 45, controls.height, 63, controls.height - 32, 20);
this.controlsScreen = controls;
this.mc = mcIn;
KeyBinding[] akeybinding = (KeyBinding[])ArrayUtils.clone(mcIn.gameSettings.keyBindings);
this.listEntries = new GuiListExtended.IGuiListEntry[akeybinding.length + KeyBinding.getKeybinds().size()];
Arrays.sort((Object[])akeybinding);
int i = 0;
String s = null;
for (KeyBinding keybinding : akeybinding)
{
String s1 = keybinding.getKeyCategory();
if (!s1.equals(s))
{
s = s1;
this.listEntries[i++] = new GuiKeyBindingList.CategoryEntry(s1);
}
int j = mcIn.fontRenderer.getStringWidth(I18n.format(keybinding.getKeyDescription()));
if (j > this.maxListLabelWidth)
{
this.maxListLabelWidth = j;
}
this.listEntries[i++] = new GuiKeyBindingList.KeyEntry(keybinding);
}
}
protected int getSize()
{
return this.listEntries.length;
}
/**
* Gets the IGuiListEntry object for the given index
*/
public GuiListExtended.IGuiListEntry getListEntry(int index)
{
return this.listEntries[index];
}
protected int getScrollBarX()
{
return super.getScrollBarX() + 35;
}
/**
* Gets the width of the list
*/
public int getListWidth()
{
return super.getListWidth() + 32;
}
@SideOnly(Side.CLIENT)
public class CategoryEntry implements GuiListExtended.IGuiListEntry
{
private final String labelText;
private final int labelWidth;
public CategoryEntry(String name)
{
this.labelText = I18n.format(name);
this.labelWidth = GuiKeyBindingList.this.mc.fontRenderer.getStringWidth(this.labelText);
}
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks)
{
GuiKeyBindingList.this.mc.fontRenderer.drawString(this.labelText, GuiKeyBindingList.this.mc.currentScreen.width / 2 - this.labelWidth / 2, y + slotHeight - GuiKeyBindingList.this.mc.fontRenderer.FONT_HEIGHT - 1, 16777215);
}
/**
* Called when the mouse is clicked within this entry. Returning true means that something within this entry was
* clicked and the list should not be dragged.
*/
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY)
{
return false;
}
/**
* Fired when the mouse button is released. Arguments: index, x, y, mouseEvent, relativeX, relativeY
*/
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY)
{
}
public void updatePosition(int slotIndex, int x, int y, float partialTicks)
{
}
}
@SideOnly(Side.CLIENT)
public class KeyEntry implements GuiListExtended.IGuiListEntry
{
/** The keybinding specified for this KeyEntry */
private final KeyBinding keybinding;
/** The localized key description for this KeyEntry */
private final String keyDesc;
private final GuiButton btnChangeKeyBinding;
private final GuiButton btnReset;
private KeyEntry(KeyBinding name)
{
this.keybinding = name;
this.keyDesc = I18n.format(name.getKeyDescription());
this.btnChangeKeyBinding = new GuiButton(0, 0, 0, 95, 20, I18n.format(name.getKeyDescription()));
this.btnReset = new GuiButton(0, 0, 0, 50, 20, I18n.format("controls.reset"));
}
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks)
{
boolean flag = GuiKeyBindingList.this.controlsScreen.buttonId == this.keybinding;
GuiKeyBindingList.this.mc.fontRenderer.drawString(this.keyDesc, x + 90 - GuiKeyBindingList.this.maxListLabelWidth, y + slotHeight / 2 - GuiKeyBindingList.this.mc.fontRenderer.FONT_HEIGHT / 2, 16777215);
this.btnReset.x = x + 210;
this.btnReset.y = y;
this.btnReset.enabled = !this.keybinding.isSetToDefaultValue();
this.btnReset.drawButton(GuiKeyBindingList.this.mc, mouseX, mouseY, partialTicks);
this.btnChangeKeyBinding.x = x + 105;
this.btnChangeKeyBinding.y = y;
this.btnChangeKeyBinding.displayString = this.keybinding.getDisplayName();
boolean flag1 = false;
boolean keyCodeModifierConflict = true; // less severe form of conflict, like SHIFT conflicting with SHIFT+G
if (this.keybinding.getKeyCode() != 0)
{
for (KeyBinding keybinding : GuiKeyBindingList.this.mc.gameSettings.keyBindings)
{
if (keybinding != this.keybinding && keybinding.conflicts(this.keybinding))
{
flag1 = true;
keyCodeModifierConflict &= keybinding.hasKeyCodeModifierConflict(this.keybinding);
}
}
}
if (flag)
{
this.btnChangeKeyBinding.displayString = TextFormatting.WHITE + "> " + TextFormatting.YELLOW + this.btnChangeKeyBinding.displayString + TextFormatting.WHITE + " <";
}
else if (flag1)
{
this.btnChangeKeyBinding.displayString = (keyCodeModifierConflict ? TextFormatting.GOLD : TextFormatting.RED) + this.btnChangeKeyBinding.displayString;
}
this.btnChangeKeyBinding.drawButton(GuiKeyBindingList.this.mc, mouseX, mouseY, partialTicks);
}
/**
* Called when the mouse is clicked within this entry. Returning true means that something within this entry was
* clicked and the list should not be dragged.
*/
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY)
{
if (this.btnChangeKeyBinding.mousePressed(GuiKeyBindingList.this.mc, mouseX, mouseY))
{
GuiKeyBindingList.this.controlsScreen.buttonId = this.keybinding;
return true;
}
else if (this.btnReset.mousePressed(GuiKeyBindingList.this.mc, mouseX, mouseY))
{
this.keybinding.setToDefault();
GuiKeyBindingList.this.mc.gameSettings.setOptionKeyBinding(this.keybinding, this.keybinding.getKeyCodeDefault());
KeyBinding.resetKeyBindingArrayAndHash();
return true;
}
else
{
return false;
}
}
/**
* Fired when the mouse button is released. Arguments: index, x, y, mouseEvent, relativeX, relativeY
*/
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY)
{
this.btnChangeKeyBinding.mouseReleased(x, y);
this.btnReset.mouseReleased(x, y);
}
public void updatePosition(int slotIndex, int x, int y, float partialTicks)
{
}
}
}

View File

@@ -0,0 +1,101 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiLabel extends Gui
{
protected int width = 200;
protected int height = 20;
public int x;
public int y;
private final List<String> labels;
public int id;
private boolean centered;
public boolean visible = true;
private boolean labelBgEnabled;
private final int textColor;
private int backColor;
private int ulColor;
private int brColor;
private final FontRenderer fontRenderer;
private int border;
public GuiLabel(FontRenderer fontRendererObj, int p_i45540_2_, int p_i45540_3_, int p_i45540_4_, int p_i45540_5_, int p_i45540_6_, int p_i45540_7_)
{
this.fontRenderer = fontRendererObj;
this.id = p_i45540_2_;
this.x = p_i45540_3_;
this.y = p_i45540_4_;
this.width = p_i45540_5_;
this.height = p_i45540_6_;
this.labels = Lists.<String>newArrayList();
this.centered = false;
this.labelBgEnabled = false;
this.textColor = p_i45540_7_;
this.backColor = -1;
this.ulColor = -1;
this.brColor = -1;
this.border = 0;
}
public void addLine(String p_175202_1_)
{
this.labels.add(I18n.format(p_175202_1_));
}
/**
* Sets the Label to be centered
*/
public GuiLabel setCentered()
{
this.centered = true;
return this;
}
public void drawLabel(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
this.drawLabelBackground(mc, mouseX, mouseY);
int i = this.y + this.height / 2 + this.border / 2;
int j = i - this.labels.size() * 10 / 2;
for (int k = 0; k < this.labels.size(); ++k)
{
if (this.centered)
{
this.drawCenteredString(this.fontRenderer, this.labels.get(k), this.x + this.width / 2, j + k * 10, this.textColor);
}
else
{
this.drawString(this.fontRenderer, this.labels.get(k), this.x, j + k * 10, this.textColor);
}
}
}
}
protected void drawLabelBackground(Minecraft mcIn, int p_146160_2_, int p_146160_3_)
{
if (this.labelBgEnabled)
{
int i = this.width + this.border * 2;
int j = this.height + this.border * 2;
int k = this.x - this.border;
int l = this.y - this.border;
drawRect(k, l, k + i, l + j, this.backColor);
this.drawHorizontalLine(k, k + i, l, this.ulColor);
this.drawHorizontalLine(k, k + i, l + j, this.brColor);
this.drawVerticalLine(k, l, l + j, this.ulColor);
this.drawVerticalLine(k + i, l, l + j, this.brColor);
}
}
}

View File

@@ -0,0 +1,171 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.Language;
import net.minecraft.client.resources.LanguageManager;
import net.minecraft.client.settings.GameSettings;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiLanguage extends GuiScreen
{
/** The parent Gui screen */
protected GuiScreen parentScreen;
/** The List GuiSlot object reference. */
private GuiLanguage.List list;
/** Reference to the GameSettings object. */
private final GameSettings game_settings_3;
/** Reference to the LanguageManager object. */
private final LanguageManager languageManager;
/** A button which allows the user to determine if the Unicode font should be forced. */
private GuiOptionButton forceUnicodeFontBtn;
/** The button to confirm the current settings. */
private GuiOptionButton confirmSettingsBtn;
public GuiLanguage(GuiScreen screen, GameSettings gameSettingsObj, LanguageManager manager)
{
this.parentScreen = screen;
this.game_settings_3 = gameSettingsObj;
this.languageManager = manager;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.forceUnicodeFontBtn = (GuiOptionButton)this.addButton(new GuiOptionButton(100, this.width / 2 - 155, this.height - 38, GameSettings.Options.FORCE_UNICODE_FONT, this.game_settings_3.getKeyBinding(GameSettings.Options.FORCE_UNICODE_FONT)));
this.confirmSettingsBtn = (GuiOptionButton)this.addButton(new GuiOptionButton(6, this.width / 2 - 155 + 160, this.height - 38, I18n.format("gui.done")));
this.list = new GuiLanguage.List(this.mc);
this.list.registerScrollButtons(7, 8);
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.list.handleMouseInput();
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
switch (button.id)
{
case 5:
break;
case 6:
this.mc.displayGuiScreen(this.parentScreen);
break;
case 100:
if (button instanceof GuiOptionButton)
{
this.game_settings_3.setOptionValue(((GuiOptionButton)button).getOption(), 1);
button.displayString = this.game_settings_3.getKeyBinding(GameSettings.Options.FORCE_UNICODE_FONT);
ScaledResolution scaledresolution = new ScaledResolution(this.mc);
int i = scaledresolution.getScaledWidth();
int j = scaledresolution.getScaledHeight();
this.setWorldAndResolution(this.mc, i, j);
}
break;
default:
this.list.actionPerformed(button);
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.list.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRenderer, I18n.format("options.language"), this.width / 2, 16, 16777215);
this.drawCenteredString(this.fontRenderer, "(" + I18n.format("options.languageWarning") + ")", this.width / 2, this.height - 56, 8421504);
super.drawScreen(mouseX, mouseY, partialTicks);
}
@SideOnly(Side.CLIENT)
class List extends GuiSlot
{
/** A list containing the many different locale language codes. */
private final java.util.List<String> langCodeList = Lists.<String>newArrayList();
/** The map containing the Locale-Language pairs. */
private final Map<String, Language> languageMap = Maps.<String, Language>newHashMap();
public List(Minecraft mcIn)
{
super(mcIn, GuiLanguage.this.width, GuiLanguage.this.height, 32, GuiLanguage.this.height - 65 + 4, 18);
for (Language language : GuiLanguage.this.languageManager.getLanguages())
{
this.languageMap.put(language.getLanguageCode(), language);
this.langCodeList.add(language.getLanguageCode());
}
}
protected int getSize()
{
return this.langCodeList.size();
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
Language language = this.languageMap.get(this.langCodeList.get(slotIndex));
GuiLanguage.this.languageManager.setCurrentLanguage(language);
GuiLanguage.this.game_settings_3.language = language.getLanguageCode();
net.minecraftforge.fml.client.FMLClientHandler.instance().refreshResources(net.minecraftforge.client.resource.VanillaResourceType.LANGUAGES);
GuiLanguage.this.fontRenderer.setUnicodeFlag(GuiLanguage.this.languageManager.isCurrentLocaleUnicode() || GuiLanguage.this.game_settings_3.forceUnicodeFont);
GuiLanguage.this.fontRenderer.setBidiFlag(GuiLanguage.this.languageManager.isCurrentLanguageBidirectional());
GuiLanguage.this.confirmSettingsBtn.displayString = I18n.format("gui.done");
GuiLanguage.this.forceUnicodeFontBtn.displayString = GuiLanguage.this.game_settings_3.getKeyBinding(GameSettings.Options.FORCE_UNICODE_FONT);
GuiLanguage.this.game_settings_3.saveOptions();
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return ((String)this.langCodeList.get(slotIndex)).equals(GuiLanguage.this.languageManager.getCurrentLanguage().getLanguageCode());
}
/**
* Return the height of the content being scrolled
*/
protected int getContentHeight()
{
return this.getSize() * 18;
}
protected void drawBackground()
{
GuiLanguage.this.drawDefaultBackground();
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
GuiLanguage.this.fontRenderer.setBidiFlag(true);
GuiLanguage.this.drawCenteredString(GuiLanguage.this.fontRenderer, ((Language)this.languageMap.get(this.langCodeList.get(slotIndex))).toString(), this.width / 2, yPos + 1, 16777215);
GuiLanguage.this.fontRenderer.setBidiFlag(GuiLanguage.this.languageManager.getCurrentLanguage().isBidirectional());
}
}
}

View File

@@ -0,0 +1,59 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiListButton extends GuiButton
{
private boolean value;
/** The localization string used by this control. */
private final String localizationStr;
/** The GuiResponder Object reference. */
private final GuiPageButtonList.GuiResponder guiResponder;
public GuiListButton(GuiPageButtonList.GuiResponder responder, int buttonId, int x, int y, String localizationStrIn, boolean valueIn)
{
super(buttonId, x, y, 150, 20, "");
this.localizationStr = localizationStrIn;
this.value = valueIn;
this.displayString = this.buildDisplayString();
this.guiResponder = responder;
}
/**
* Builds the localized display string for this GuiListButton
*/
private String buildDisplayString()
{
return I18n.format(this.localizationStr) + ": " + I18n.format(this.value ? "gui.yes" : "gui.no");
}
public void setValue(boolean valueIn)
{
this.value = valueIn;
this.displayString = this.buildDisplayString();
this.guiResponder.setEntryValue(this.id, valueIn);
}
/**
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
* e).
*/
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.value = !this.value;
this.displayString = this.buildDisplayString();
this.guiResponder.setEntryValue(this.id, this.value);
return true;
}
else
{
return false;
}
}
}

View File

@@ -0,0 +1,106 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class GuiListExtended extends GuiSlot
{
public GuiListExtended(Minecraft mcIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
{
super(mcIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn);
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return false;
}
protected void drawBackground()
{
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
this.getListEntry(slotIndex).drawEntry(slotIndex, xPos, yPos, this.getListWidth(), heightIn, mouseXIn, mouseYIn, this.isMouseYWithinSlotBounds(mouseYIn) && this.getSlotIndexFromScreenCoords(mouseXIn, mouseYIn) == slotIndex, partialTicks);
}
protected void updateItemPos(int entryID, int insideLeft, int yPos, float partialTicks)
{
this.getListEntry(entryID).updatePosition(entryID, insideLeft, yPos, partialTicks);
}
public boolean mouseClicked(int mouseX, int mouseY, int mouseEvent)
{
if (this.isMouseYWithinSlotBounds(mouseY))
{
int i = this.getSlotIndexFromScreenCoords(mouseX, mouseY);
if (i >= 0)
{
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int k = this.top + 4 - this.getAmountScrolled() + i * this.slotHeight + this.headerPadding;
int l = mouseX - j;
int i1 = mouseY - k;
if (this.getListEntry(i).mousePressed(i, mouseX, mouseY, mouseEvent, l, i1))
{
this.setEnabled(false);
return true;
}
}
}
return false;
}
public boolean mouseReleased(int x, int y, int mouseEvent)
{
for (int i = 0; i < this.getSize(); ++i)
{
int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int k = this.top + 4 - this.getAmountScrolled() + i * this.slotHeight + this.headerPadding;
int l = x - j;
int i1 = y - k;
this.getListEntry(i).mouseReleased(i, x, y, mouseEvent, l, i1);
}
this.setEnabled(true);
return false;
}
/**
* Gets the IGuiListEntry object for the given index
*/
public abstract GuiListExtended.IGuiListEntry getListEntry(int index);
@SideOnly(Side.CLIENT)
public interface IGuiListEntry
{
void updatePosition(int slotIndex, int x, int y, float partialTicks);
void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks);
/**
* Called when the mouse is clicked within this entry. Returning true means that something within this entry was
* clicked and the list should not be dragged.
*/
boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY);
/**
* Fired when the mouse button is released. Arguments: index, x, y, mouseEvent, relativeX, relativeY
*/
void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY);
}
}

View File

@@ -0,0 +1,107 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.AnvilConverterException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.WorldSummary;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class GuiListWorldSelection extends GuiListExtended
{
private static final Logger LOGGER = LogManager.getLogger();
private final GuiWorldSelection worldSelection;
private final List<GuiListWorldSelectionEntry> entries = Lists.<GuiListWorldSelectionEntry>newArrayList();
/** Index to the currently selected world */
private int selectedIdx = -1;
public GuiListWorldSelection(GuiWorldSelection p_i46590_1_, Minecraft clientIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
{
super(clientIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn);
this.worldSelection = p_i46590_1_;
this.refreshList();
}
public void refreshList()
{
ISaveFormat isaveformat = this.mc.getSaveLoader();
List<WorldSummary> list;
try
{
list = isaveformat.getSaveList();
}
catch (AnvilConverterException anvilconverterexception)
{
LOGGER.error("Couldn't load level list", (Throwable)anvilconverterexception);
this.mc.displayGuiScreen(new GuiErrorScreen(I18n.format("selectWorld.unable_to_load"), anvilconverterexception.getMessage()));
return;
}
Collections.sort(list);
for (WorldSummary worldsummary : list)
{
this.entries.add(new GuiListWorldSelectionEntry(this, worldsummary, this.mc.getSaveLoader()));
}
}
/**
* Gets the IGuiListEntry object for the given index
*/
public GuiListWorldSelectionEntry getListEntry(int index)
{
return this.entries.get(index);
}
protected int getSize()
{
return this.entries.size();
}
protected int getScrollBarX()
{
return super.getScrollBarX() + 20;
}
/**
* Gets the width of the list
*/
public int getListWidth()
{
return super.getListWidth() + 50;
}
public void selectWorld(int idx)
{
this.selectedIdx = idx;
this.worldSelection.selectWorld(this.getSelectedWorld());
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return slotIndex == this.selectedIdx;
}
@Nullable
public GuiListWorldSelectionEntry getSelectedWorld()
{
return this.selectedIdx >= 0 && this.selectedIdx < this.getSize() ? this.getListEntry(this.selectedIdx) : null;
}
public GuiWorldSelection getGuiWorldSelection()
{
return this.worldSelection;
}
}

View File

@@ -0,0 +1,304 @@
package net.minecraft.client.gui;
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.resources.I18n;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.ISaveHandler;
import net.minecraft.world.storage.WorldInfo;
import net.minecraft.world.storage.WorldSummary;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class GuiListWorldSelectionEntry implements GuiListExtended.IGuiListEntry
{
private static final Logger LOGGER = LogManager.getLogger();
private static final DateFormat DATE_FORMAT = new SimpleDateFormat();
private static final ResourceLocation ICON_MISSING = new ResourceLocation("textures/misc/unknown_server.png");
private static final ResourceLocation ICON_OVERLAY_LOCATION = new ResourceLocation("textures/gui/world_selection.png");
private final Minecraft client;
private final GuiWorldSelection worldSelScreen;
private final WorldSummary worldSummary;
private final ResourceLocation iconLocation;
private final GuiListWorldSelection containingListSel;
private File iconFile;
private DynamicTexture icon;
private long lastClickTime;
public GuiListWorldSelectionEntry(GuiListWorldSelection listWorldSelIn, WorldSummary worldSummaryIn, ISaveFormat saveFormat)
{
this.containingListSel = listWorldSelIn;
this.worldSelScreen = listWorldSelIn.getGuiWorldSelection();
this.worldSummary = worldSummaryIn;
this.client = Minecraft.getMinecraft();
this.iconLocation = new ResourceLocation("worlds/" + worldSummaryIn.getFileName() + "/icon");
this.iconFile = saveFormat.getFile(worldSummaryIn.getFileName(), "icon.png");
if (!this.iconFile.isFile())
{
this.iconFile = null;
}
this.loadServerIcon();
}
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks)
{
String s = this.worldSummary.getDisplayName();
String s1 = this.worldSummary.getFileName() + " (" + DATE_FORMAT.format(new Date(this.worldSummary.getLastTimePlayed())) + ")";
String s2 = "";
if (StringUtils.isEmpty(s))
{
s = I18n.format("selectWorld.world") + " " + (slotIndex + 1);
}
if (this.worldSummary.requiresConversion())
{
s2 = I18n.format("selectWorld.conversion") + " " + s2;
}
else
{
s2 = I18n.format("gameMode." + this.worldSummary.getEnumGameType().getName());
if (this.worldSummary.isHardcoreModeEnabled())
{
s2 = TextFormatting.DARK_RED + I18n.format("gameMode.hardcore") + TextFormatting.RESET;
}
if (this.worldSummary.getCheatsEnabled())
{
s2 = s2 + ", " + I18n.format("selectWorld.cheats");
}
String s3 = this.worldSummary.getVersionName();
if (this.worldSummary.markVersionInList())
{
if (this.worldSummary.askToOpenWorld())
{
s2 = s2 + ", " + I18n.format("selectWorld.version") + " " + TextFormatting.RED + s3 + TextFormatting.RESET;
}
else
{
s2 = s2 + ", " + I18n.format("selectWorld.version") + " " + TextFormatting.ITALIC + s3 + TextFormatting.RESET;
}
}
else
{
s2 = s2 + ", " + I18n.format("selectWorld.version") + " " + s3;
}
}
this.client.fontRenderer.drawString(s, x + 32 + 3, y + 1, 16777215);
this.client.fontRenderer.drawString(s1, x + 32 + 3, y + this.client.fontRenderer.FONT_HEIGHT + 3, 8421504);
this.client.fontRenderer.drawString(s2, x + 32 + 3, y + this.client.fontRenderer.FONT_HEIGHT + this.client.fontRenderer.FONT_HEIGHT + 3, 8421504);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.client.getTextureManager().bindTexture(this.icon != null ? this.iconLocation : ICON_MISSING);
GlStateManager.enableBlend();
Gui.drawModalRectWithCustomSizedTexture(x, y, 0.0F, 0.0F, 32, 32, 32.0F, 32.0F);
GlStateManager.disableBlend();
if (this.client.gameSettings.touchscreen || isSelected)
{
this.client.getTextureManager().bindTexture(ICON_OVERLAY_LOCATION);
Gui.drawRect(x, y, x + 32, y + 32, -1601138544);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
int j = mouseX - x;
int i = j < 32 ? 32 : 0;
if (this.worldSummary.markVersionInList())
{
Gui.drawModalRectWithCustomSizedTexture(x, y, 32.0F, (float)i, 32, 32, 256.0F, 256.0F);
if (this.worldSummary.askToOpenWorld())
{
Gui.drawModalRectWithCustomSizedTexture(x, y, 96.0F, (float)i, 32, 32, 256.0F, 256.0F);
if (j < 32)
{
this.worldSelScreen.setVersionTooltip(TextFormatting.RED + I18n.format("selectWorld.tooltip.fromNewerVersion1") + "\n" + TextFormatting.RED + I18n.format("selectWorld.tooltip.fromNewerVersion2"));
}
}
else
{
Gui.drawModalRectWithCustomSizedTexture(x, y, 64.0F, (float)i, 32, 32, 256.0F, 256.0F);
if (j < 32)
{
this.worldSelScreen.setVersionTooltip(TextFormatting.GOLD + I18n.format("selectWorld.tooltip.snapshot1") + "\n" + TextFormatting.GOLD + I18n.format("selectWorld.tooltip.snapshot2"));
}
}
}
else
{
Gui.drawModalRectWithCustomSizedTexture(x, y, 0.0F, (float)i, 32, 32, 256.0F, 256.0F);
}
}
}
/**
* Called when the mouse is clicked within this entry. Returning true means that something within this entry was
* clicked and the list should not be dragged.
*/
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY)
{
this.containingListSel.selectWorld(slotIndex);
if (relativeX <= 32 && relativeX < 32)
{
this.joinWorld();
return true;
}
else if (Minecraft.getSystemTime() - this.lastClickTime < 250L)
{
this.joinWorld();
return true;
}
else
{
this.lastClickTime = Minecraft.getSystemTime();
return false;
}
}
public void joinWorld()
{
if (this.worldSummary.askToOpenWorld())
{
this.client.displayGuiScreen(new GuiYesNo(new GuiYesNoCallback()
{
public void confirmClicked(boolean result, int id)
{
if (result)
{
GuiListWorldSelectionEntry.this.loadWorld();
}
else
{
GuiListWorldSelectionEntry.this.client.displayGuiScreen(GuiListWorldSelectionEntry.this.worldSelScreen);
}
}
}, I18n.format("selectWorld.versionQuestion"), I18n.format("selectWorld.versionWarning", this.worldSummary.getVersionName()), I18n.format("selectWorld.versionJoinButton"), I18n.format("gui.cancel"), 0));
}
else
{
this.loadWorld();
}
}
public void deleteWorld()
{
this.client.displayGuiScreen(new GuiYesNo(new GuiYesNoCallback()
{
public void confirmClicked(boolean result, int id)
{
if (result)
{
GuiListWorldSelectionEntry.this.client.displayGuiScreen(new GuiScreenWorking());
ISaveFormat isaveformat = GuiListWorldSelectionEntry.this.client.getSaveLoader();
isaveformat.flushCache();
isaveformat.deleteWorldDirectory(GuiListWorldSelectionEntry.this.worldSummary.getFileName());
GuiListWorldSelectionEntry.this.containingListSel.refreshList();
}
GuiListWorldSelectionEntry.this.client.displayGuiScreen(GuiListWorldSelectionEntry.this.worldSelScreen);
}
}, I18n.format("selectWorld.deleteQuestion"), "'" + this.worldSummary.getDisplayName() + "' " + I18n.format("selectWorld.deleteWarning"), I18n.format("selectWorld.deleteButton"), I18n.format("gui.cancel"), 0));
}
public void editWorld()
{
this.client.displayGuiScreen(new GuiWorldEdit(this.worldSelScreen, this.worldSummary.getFileName()));
}
public void recreateWorld()
{
this.client.displayGuiScreen(new GuiScreenWorking());
GuiCreateWorld guicreateworld = new GuiCreateWorld(this.worldSelScreen);
ISaveHandler isavehandler = this.client.getSaveLoader().getSaveLoader(this.worldSummary.getFileName(), false);
WorldInfo worldinfo = isavehandler.loadWorldInfo();
isavehandler.flush();
if (worldinfo != null)
{
guicreateworld.recreateFromExistingWorld(worldinfo);
this.client.displayGuiScreen(guicreateworld);
}
}
private void loadWorld()
{
this.client.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
if (this.client.getSaveLoader().canLoadWorld(this.worldSummary.getFileName()))
{
net.minecraftforge.fml.client.FMLClientHandler.instance().tryLoadExistingWorld(worldSelScreen, this.worldSummary);
}
}
private void loadServerIcon()
{
boolean flag = this.iconFile != null && this.iconFile.isFile();
if (flag)
{
BufferedImage bufferedimage;
try
{
bufferedimage = ImageIO.read(this.iconFile);
Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide");
Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high");
}
catch (Throwable throwable)
{
LOGGER.error("Invalid icon for world {}", this.worldSummary.getFileName(), throwable);
this.iconFile = null;
return;
}
if (this.icon == null)
{
this.icon = new DynamicTexture(bufferedimage.getWidth(), bufferedimage.getHeight());
this.client.getTextureManager().loadTexture(this.iconLocation, this.icon);
}
bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), this.icon.getTextureData(), 0, bufferedimage.getWidth());
this.icon.updateDynamicTexture();
}
else if (!flag)
{
this.client.getTextureManager().deleteTexture(this.iconLocation);
this.icon = null;
}
}
/**
* Fired when the mouse button is released. Arguments: index, x, y, mouseEvent, relativeX, relativeY
*/
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY)
{
}
public void updatePosition(int slotIndex, int x, int y, float partialTicks)
{
}
}

View File

@@ -0,0 +1,101 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiLockIconButton extends GuiButton
{
private boolean locked;
public GuiLockIconButton(int buttonId, int x, int y)
{
super(buttonId, x, y, 20, 20, "");
}
public boolean isLocked()
{
return this.locked;
}
public void setLocked(boolean lockedIn)
{
this.locked = lockedIn;
}
/**
* Draws this button to the screen.
*/
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
mc.getTextureManager().bindTexture(GuiButton.BUTTON_TEXTURES);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
boolean flag = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
GuiLockIconButton.Icon guilockiconbutton$icon;
if (this.locked)
{
if (!this.enabled)
{
guilockiconbutton$icon = GuiLockIconButton.Icon.LOCKED_DISABLED;
}
else if (flag)
{
guilockiconbutton$icon = GuiLockIconButton.Icon.LOCKED_HOVER;
}
else
{
guilockiconbutton$icon = GuiLockIconButton.Icon.LOCKED;
}
}
else if (!this.enabled)
{
guilockiconbutton$icon = GuiLockIconButton.Icon.UNLOCKED_DISABLED;
}
else if (flag)
{
guilockiconbutton$icon = GuiLockIconButton.Icon.UNLOCKED_HOVER;
}
else
{
guilockiconbutton$icon = GuiLockIconButton.Icon.UNLOCKED;
}
this.drawTexturedModalRect(this.x, this.y, guilockiconbutton$icon.getX(), guilockiconbutton$icon.getY(), this.width, this.height);
}
}
@SideOnly(Side.CLIENT)
static enum Icon
{
LOCKED(0, 146),
LOCKED_HOVER(0, 166),
LOCKED_DISABLED(0, 186),
UNLOCKED(20, 146),
UNLOCKED_HOVER(20, 166),
UNLOCKED_DISABLED(20, 186);
private final int x;
private final int y;
private Icon(int xIn, int yIn)
{
this.x = xIn;
this.y = yIn;
}
public int getX()
{
return this.x;
}
public int getY()
{
return this.y;
}
}
}

View File

@@ -0,0 +1,668 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Runnables;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.realms.RealmsBridge;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.WorldServerDemo;
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.util.glu.Project;
@SideOnly(Side.CLIENT)
public class GuiMainMenu extends GuiScreen
{
private static final Logger LOGGER = LogManager.getLogger();
private static final Random RANDOM = new Random();
/**
* A random number between 0.0 and 1.0, used to determine if the title screen says <a
* href="https://minecraft.gamepedia.com/Menu_screen#Minceraft">Minceraft</a> instead of Minecraft. Set during
* construction; if the value is less than .0001, then Minceraft is displayed.
*/
private final float minceraftRoll;
/** The splash message. */
private String splashText;
private GuiButton buttonResetDemo;
/** Timer used to rotate the panorama, increases every tick. */
private float panoramaTimer;
/** Texture allocated for the current viewport of the main menu's panorama background. */
private DynamicTexture viewportTexture;
/** The Object object utilized as a thread lock when performing non thread-safe operations */
private final Object threadLock = new Object();
public static final String MORE_INFO_TEXT = "Please click " + TextFormatting.UNDERLINE + "here" + TextFormatting.RESET + " for more information.";
/** Width of openGLWarning2 */
private int openGLWarning2Width;
/** Width of openGLWarning1 */
private int openGLWarning1Width;
/** Left x coordinate of the OpenGL warning */
private int openGLWarningX1;
/** Top y coordinate of the OpenGL warning */
private int openGLWarningY1;
/** Right x coordinate of the OpenGL warning */
private int openGLWarningX2;
/** Bottom y coordinate of the OpenGL warning */
private int openGLWarningY2;
/** OpenGL graphics card warning. */
private String openGLWarning1;
/** OpenGL graphics card warning. */
private String openGLWarning2;
/** Link to the Mojang Support about minimum requirements */
private String openGLWarningLink;
private static final ResourceLocation SPLASH_TEXTS = new ResourceLocation("texts/splashes.txt");
private static final ResourceLocation MINECRAFT_TITLE_TEXTURES = new ResourceLocation("textures/gui/title/minecraft.png");
private static final ResourceLocation field_194400_H = new ResourceLocation("textures/gui/title/edition.png");
/** An array of all the paths to the panorama pictures. */
private static final ResourceLocation[] TITLE_PANORAMA_PATHS = new ResourceLocation[] {new ResourceLocation("textures/gui/title/background/panorama_0.png"), new ResourceLocation("textures/gui/title/background/panorama_1.png"), new ResourceLocation("textures/gui/title/background/panorama_2.png"), new ResourceLocation("textures/gui/title/background/panorama_3.png"), new ResourceLocation("textures/gui/title/background/panorama_4.png"), new ResourceLocation("textures/gui/title/background/panorama_5.png")};
private ResourceLocation backgroundTexture;
/** Minecraft Realms button. */
private GuiButton realmsButton;
/** Has the check for a realms notification screen been performed? */
private boolean hasCheckedForRealmsNotification;
/**
* A screen generated by realms for notifications; drawn in adition to the main menu (buttons and such from both are
* drawn at the same time). May be null.
*/
private GuiScreen realmsNotification;
private int widthCopyright;
private int widthCopyrightRest;
private GuiButton modButton;
private net.minecraftforge.client.gui.NotificationModUpdateScreen modUpdateNotification;
public GuiMainMenu()
{
this.openGLWarning2 = MORE_INFO_TEXT;
this.splashText = "missingno";
IResource iresource = null;
try
{
List<String> list = Lists.<String>newArrayList();
iresource = Minecraft.getMinecraft().getResourceManager().getResource(SPLASH_TEXTS);
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(iresource.getInputStream(), StandardCharsets.UTF_8));
String s;
while ((s = bufferedreader.readLine()) != null)
{
s = s.trim();
if (!s.isEmpty())
{
list.add(s);
}
}
if (!list.isEmpty())
{
while (true)
{
this.splashText = list.get(RANDOM.nextInt(list.size()));
if (this.splashText.hashCode() != 125780783)
{
break;
}
}
}
}
catch (IOException var8)
{
;
}
finally
{
IOUtils.closeQuietly((Closeable)iresource);
}
this.minceraftRoll = RANDOM.nextFloat();
this.openGLWarning1 = "";
if (!GLContext.getCapabilities().OpenGL20 && !OpenGlHelper.areShadersSupported())
{
this.openGLWarning1 = I18n.format("title.oldgl1");
this.openGLWarning2 = I18n.format("title.oldgl2");
this.openGLWarningLink = "https://help.mojang.com/customer/portal/articles/325948?ref=game";
}
}
/**
* Is there currently a realms notification screen, and are realms notifications enabled?
*/
private boolean areRealmsNotificationsEnabled()
{
return Minecraft.getMinecraft().gameSettings.getOptionOrdinalValue(GameSettings.Options.REALMS_NOTIFICATIONS) && this.realmsNotification != null;
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
if (this.areRealmsNotificationsEnabled())
{
this.realmsNotification.updateScreen();
}
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
public boolean doesGuiPauseGame()
{
return false;
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.viewportTexture = new DynamicTexture(256, 256);
this.backgroundTexture = this.mc.getTextureManager().getDynamicTextureLocation("background", this.viewportTexture);
this.widthCopyright = this.fontRenderer.getStringWidth("Copyright Mojang AB. Do not distribute!");
this.widthCopyrightRest = this.width - this.widthCopyright - 2;
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
if (calendar.get(2) + 1 == 12 && calendar.get(5) == 24)
{
this.splashText = "Merry X-mas!";
}
else if (calendar.get(2) + 1 == 1 && calendar.get(5) == 1)
{
this.splashText = "Happy new year!";
}
else if (calendar.get(2) + 1 == 10 && calendar.get(5) == 31)
{
this.splashText = "OOoooOOOoooo! Spooky!";
}
int i = 24;
int j = this.height / 4 + 48;
if (this.mc.isDemo())
{
this.addDemoButtons(j, 24);
}
else
{
this.addSingleplayerMultiplayerButtons(j, 24);
}
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, j + 72 + 12, 98, 20, I18n.format("menu.options")));
this.buttonList.add(new GuiButton(4, this.width / 2 + 2, j + 72 + 12, 98, 20, I18n.format("menu.quit")));
this.buttonList.add(new GuiButtonLanguage(5, this.width / 2 - 124, j + 72 + 12));
synchronized (this.threadLock)
{
this.openGLWarning1Width = this.fontRenderer.getStringWidth(this.openGLWarning1);
this.openGLWarning2Width = this.fontRenderer.getStringWidth(this.openGLWarning2);
int k = Math.max(this.openGLWarning1Width, this.openGLWarning2Width);
this.openGLWarningX1 = (this.width - k) / 2;
this.openGLWarningY1 = (this.buttonList.get(0)).y - 24;
this.openGLWarningX2 = this.openGLWarningX1 + k;
this.openGLWarningY2 = this.openGLWarningY1 + 24;
}
this.mc.setConnectedToRealms(false);
if (Minecraft.getMinecraft().gameSettings.getOptionOrdinalValue(GameSettings.Options.REALMS_NOTIFICATIONS) && !this.hasCheckedForRealmsNotification)
{
RealmsBridge realmsbridge = new RealmsBridge();
this.realmsNotification = realmsbridge.getNotificationScreen(this);
this.hasCheckedForRealmsNotification = true;
}
if (this.areRealmsNotificationsEnabled())
{
this.realmsNotification.setGuiSize(this.width, this.height);
this.realmsNotification.initGui();
}
modUpdateNotification = net.minecraftforge.client.gui.NotificationModUpdateScreen.init(this, modButton);
}
/**
* Adds Singleplayer and Multiplayer buttons on Main Menu for players who have bought the game.
*/
private void addSingleplayerMultiplayerButtons(int p_73969_1_, int p_73969_2_)
{
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, p_73969_1_, I18n.format("menu.singleplayer")));
this.buttonList.add(new GuiButton(2, this.width / 2 - 100, p_73969_1_ + p_73969_2_ * 1, I18n.format("menu.multiplayer")));
this.realmsButton = this.addButton(new GuiButton(14, this.width / 2 + 2, p_73969_1_ + p_73969_2_ * 2, 98, 20, I18n.format("menu.online").replace("Minecraft", "").trim()));
this.buttonList.add(modButton = new GuiButton(6, this.width / 2 - 100, p_73969_1_ + p_73969_2_ * 2, 98, 20, I18n.format("fml.menu.mods")));
}
/**
* Adds Demo buttons on Main Menu for players who are playing Demo.
*/
private void addDemoButtons(int p_73972_1_, int p_73972_2_)
{
this.buttonList.add(new GuiButton(11, this.width / 2 - 100, p_73972_1_, I18n.format("menu.playdemo")));
this.buttonResetDemo = this.addButton(new GuiButton(12, this.width / 2 - 100, p_73972_1_ + p_73972_2_ * 1, I18n.format("menu.resetdemo")));
ISaveFormat isaveformat = this.mc.getSaveLoader();
WorldInfo worldinfo = isaveformat.getWorldInfo("Demo_World");
if (worldinfo == null)
{
this.buttonResetDemo.enabled = false;
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 0)
{
this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings));
}
if (button.id == 5)
{
this.mc.displayGuiScreen(new GuiLanguage(this, this.mc.gameSettings, this.mc.getLanguageManager()));
}
if (button.id == 1)
{
this.mc.displayGuiScreen(new GuiWorldSelection(this));
}
if (button.id == 2)
{
this.mc.displayGuiScreen(new GuiMultiplayer(this));
}
if (button.id == 14 && this.realmsButton.visible)
{
this.switchToRealms();
}
if (button.id == 4)
{
this.mc.shutdown();
}
if (button.id == 6)
{
this.mc.displayGuiScreen(new net.minecraftforge.fml.client.GuiModList(this));
}
if (button.id == 11)
{
this.mc.launchIntegratedServer("Demo_World", "Demo_World", WorldServerDemo.DEMO_WORLD_SETTINGS);
}
if (button.id == 12)
{
ISaveFormat isaveformat = this.mc.getSaveLoader();
WorldInfo worldinfo = isaveformat.getWorldInfo("Demo_World");
if (worldinfo != null)
{
this.mc.displayGuiScreen(new GuiYesNo(this, I18n.format("selectWorld.deleteQuestion"), "'" + worldinfo.getWorldName() + "' " + I18n.format("selectWorld.deleteWarning"), I18n.format("selectWorld.deleteButton"), I18n.format("gui.cancel"), 12));
}
}
}
private void switchToRealms()
{
RealmsBridge realmsbridge = new RealmsBridge();
realmsbridge.switchToRealms(this);
}
public void confirmClicked(boolean result, int id)
{
if (result && id == 12)
{
ISaveFormat isaveformat = this.mc.getSaveLoader();
isaveformat.flushCache();
isaveformat.deleteWorldDirectory("Demo_World");
this.mc.displayGuiScreen(this);
}
else if (id == 12)
{
this.mc.displayGuiScreen(this);
}
else if (id == 13)
{
if (result)
{
try
{
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop").invoke((Object)null);
oclass.getMethod("browse", URI.class).invoke(object, new URI(this.openGLWarningLink));
}
catch (Throwable throwable)
{
LOGGER.error("Couldn't open link", throwable);
}
}
this.mc.displayGuiScreen(this);
}
}
/**
* Draws the main menu panorama
*/
private void drawPanorama(int mouseX, int mouseY, float partialTicks)
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
GlStateManager.matrixMode(5889);
GlStateManager.pushMatrix();
GlStateManager.loadIdentity();
Project.gluPerspective(120.0F, 1.0F, 0.05F, 10.0F);
GlStateManager.matrixMode(5888);
GlStateManager.pushMatrix();
GlStateManager.loadIdentity();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(90.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
GlStateManager.disableCull();
GlStateManager.depthMask(false);
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
int i = 8;
for (int j = 0; j < 64; ++j)
{
GlStateManager.pushMatrix();
float f = ((float)(j % 8) / 8.0F - 0.5F) / 64.0F;
float f1 = ((float)(j / 8) / 8.0F - 0.5F) / 64.0F;
float f2 = 0.0F;
GlStateManager.translate(f, f1, 0.0F);
GlStateManager.rotate(MathHelper.sin(this.panoramaTimer / 400.0F) * 25.0F + 20.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(-this.panoramaTimer * 0.1F, 0.0F, 1.0F, 0.0F);
for (int k = 0; k < 6; ++k)
{
GlStateManager.pushMatrix();
if (k == 1)
{
GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
}
if (k == 2)
{
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
}
if (k == 3)
{
GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
}
if (k == 4)
{
GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
}
if (k == 5)
{
GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
}
this.mc.getTextureManager().bindTexture(TITLE_PANORAMA_PATHS[k]);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
int l = 255 / (j + 1);
float f3 = 0.0F;
bufferbuilder.pos(-1.0D, -1.0D, 1.0D).tex(0.0D, 0.0D).color(255, 255, 255, l).endVertex();
bufferbuilder.pos(1.0D, -1.0D, 1.0D).tex(1.0D, 0.0D).color(255, 255, 255, l).endVertex();
bufferbuilder.pos(1.0D, 1.0D, 1.0D).tex(1.0D, 1.0D).color(255, 255, 255, l).endVertex();
bufferbuilder.pos(-1.0D, 1.0D, 1.0D).tex(0.0D, 1.0D).color(255, 255, 255, l).endVertex();
tessellator.draw();
GlStateManager.popMatrix();
}
GlStateManager.popMatrix();
GlStateManager.colorMask(true, true, true, false);
}
bufferbuilder.setTranslation(0.0D, 0.0D, 0.0D);
GlStateManager.colorMask(true, true, true, true);
GlStateManager.matrixMode(5889);
GlStateManager.popMatrix();
GlStateManager.matrixMode(5888);
GlStateManager.popMatrix();
GlStateManager.depthMask(true);
GlStateManager.enableCull();
GlStateManager.enableDepth();
}
/**
* Rotate and blurs the skybox view in the main menu
*/
private void rotateAndBlurSkybox()
{
this.mc.getTextureManager().bindTexture(this.backgroundTexture);
GlStateManager.glTexParameteri(3553, 10241, 9729);
GlStateManager.glTexParameteri(3553, 10240, 9729);
GlStateManager.glCopyTexSubImage2D(3553, 0, 0, 0, 0, 0, 256, 256);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.colorMask(true, true, true, false);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
GlStateManager.disableAlpha();
int i = 3;
for (int j = 0; j < 3; ++j)
{
float f = 1.0F / (float)(j + 1);
int k = this.width;
int l = this.height;
float f1 = (float)(j - 1) / 256.0F;
bufferbuilder.pos((double)k, (double)l, (double)this.zLevel).tex((double)(0.0F + f1), 1.0D).color(1.0F, 1.0F, 1.0F, f).endVertex();
bufferbuilder.pos((double)k, 0.0D, (double)this.zLevel).tex((double)(1.0F + f1), 1.0D).color(1.0F, 1.0F, 1.0F, f).endVertex();
bufferbuilder.pos(0.0D, 0.0D, (double)this.zLevel).tex((double)(1.0F + f1), 0.0D).color(1.0F, 1.0F, 1.0F, f).endVertex();
bufferbuilder.pos(0.0D, (double)l, (double)this.zLevel).tex((double)(0.0F + f1), 0.0D).color(1.0F, 1.0F, 1.0F, f).endVertex();
}
tessellator.draw();
GlStateManager.enableAlpha();
GlStateManager.colorMask(true, true, true, true);
}
/**
* Renders the skybox in the main menu
*/
private void renderSkybox(int mouseX, int mouseY, float partialTicks)
{
this.mc.getFramebuffer().unbindFramebuffer();
GlStateManager.viewport(0, 0, 256, 256);
this.drawPanorama(mouseX, mouseY, partialTicks);
this.rotateAndBlurSkybox();
this.rotateAndBlurSkybox();
this.rotateAndBlurSkybox();
this.rotateAndBlurSkybox();
this.rotateAndBlurSkybox();
this.rotateAndBlurSkybox();
this.rotateAndBlurSkybox();
this.mc.getFramebuffer().bindFramebuffer(true);
GlStateManager.viewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
float f = 120.0F / (float)(this.width > this.height ? this.width : this.height);
float f1 = (float)this.height * f / 256.0F;
float f2 = (float)this.width * f / 256.0F;
int i = this.width;
int j = this.height;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos(0.0D, (double)j, (double)this.zLevel).tex((double)(0.5F - f1), (double)(0.5F + f2)).color(1.0F, 1.0F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos((double)i, (double)j, (double)this.zLevel).tex((double)(0.5F - f1), (double)(0.5F - f2)).color(1.0F, 1.0F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos((double)i, 0.0D, (double)this.zLevel).tex((double)(0.5F + f1), (double)(0.5F - f2)).color(1.0F, 1.0F, 1.0F, 1.0F).endVertex();
bufferbuilder.pos(0.0D, 0.0D, (double)this.zLevel).tex((double)(0.5F + f1), (double)(0.5F + f2)).color(1.0F, 1.0F, 1.0F, 1.0F).endVertex();
tessellator.draw();
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.panoramaTimer += partialTicks;
GlStateManager.disableAlpha();
this.renderSkybox(mouseX, mouseY, partialTicks);
GlStateManager.enableAlpha();
int i = 274;
int j = this.width / 2 - 137;
int k = 30;
this.drawGradientRect(0, 0, this.width, this.height, -2130706433, 16777215);
this.drawGradientRect(0, 0, this.width, this.height, 0, Integer.MIN_VALUE);
this.mc.getTextureManager().bindTexture(MINECRAFT_TITLE_TEXTURES);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
if ((double)this.minceraftRoll < 1.0E-4D)
{
this.drawTexturedModalRect(j + 0, 30, 0, 0, 99, 44);
this.drawTexturedModalRect(j + 99, 30, 129, 0, 27, 44);
this.drawTexturedModalRect(j + 99 + 26, 30, 126, 0, 3, 44);
this.drawTexturedModalRect(j + 99 + 26 + 3, 30, 99, 0, 26, 44);
this.drawTexturedModalRect(j + 155, 30, 0, 45, 155, 44);
}
else
{
this.drawTexturedModalRect(j + 0, 30, 0, 0, 155, 44);
this.drawTexturedModalRect(j + 155, 30, 0, 45, 155, 44);
}
this.mc.getTextureManager().bindTexture(field_194400_H);
drawModalRectWithCustomSizedTexture(j + 88, 67, 0.0F, 0.0F, 98, 14, 128.0F, 16.0F);
this.splashText = net.minecraftforge.client.ForgeHooksClient.renderMainMenu(this, this.fontRenderer, this.width, this.height, this.splashText);
GlStateManager.pushMatrix();
GlStateManager.translate((float)(this.width / 2 + 90), 70.0F, 0.0F);
GlStateManager.rotate(-20.0F, 0.0F, 0.0F, 1.0F);
float f = 1.8F - MathHelper.abs(MathHelper.sin((float)(Minecraft.getSystemTime() % 1000L) / 1000.0F * ((float)Math.PI * 2F)) * 0.1F);
f = f * 100.0F / (float)(this.fontRenderer.getStringWidth(this.splashText) + 32);
GlStateManager.scale(f, f, f);
this.drawCenteredString(this.fontRenderer, this.splashText, 0, -8, -256);
GlStateManager.popMatrix();
String s = "Minecraft 1.12.2";
if (this.mc.isDemo())
{
s = s + " Demo";
}
else
{
s = s + ("release".equalsIgnoreCase(this.mc.getVersionType()) ? "" : "/" + this.mc.getVersionType());
}
java.util.List<String> brandings = com.google.common.collect.Lists.reverse(net.minecraftforge.fml.common.FMLCommonHandler.instance().getBrandings(true));
for (int brdline = 0; brdline < brandings.size(); brdline++)
{
String brd = brandings.get(brdline);
if (!com.google.common.base.Strings.isNullOrEmpty(brd))
{
this.drawString(this.fontRenderer, brd, 2, this.height - ( 10 + brdline * (this.fontRenderer.FONT_HEIGHT + 1)), 16777215);
}
}
this.drawString(this.fontRenderer, "Copyright Mojang AB. Do not distribute!", this.widthCopyrightRest, this.height - 10, -1);
if (mouseX > this.widthCopyrightRest && mouseX < this.widthCopyrightRest + this.widthCopyright && mouseY > this.height - 10 && mouseY < this.height && Mouse.isInsideWindow())
{
drawRect(this.widthCopyrightRest, this.height - 1, this.widthCopyrightRest + this.widthCopyright, this.height, -1);
}
if (this.openGLWarning1 != null && !this.openGLWarning1.isEmpty())
{
drawRect(this.openGLWarningX1 - 2, this.openGLWarningY1 - 2, this.openGLWarningX2 + 2, this.openGLWarningY2 - 1, 1428160512);
this.drawString(this.fontRenderer, this.openGLWarning1, this.openGLWarningX1, this.openGLWarningY1, -1);
this.drawString(this.fontRenderer, this.openGLWarning2, (this.width - this.openGLWarning2Width) / 2, (this.buttonList.get(0)).y - 12, -1);
}
super.drawScreen(mouseX, mouseY, partialTicks);
if (this.areRealmsNotificationsEnabled())
{
this.realmsNotification.drawScreen(mouseX, mouseY, partialTicks);
}
modUpdateNotification.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
synchronized (this.threadLock)
{
if (!this.openGLWarning1.isEmpty() && !StringUtils.isNullOrEmpty(this.openGLWarningLink) && mouseX >= this.openGLWarningX1 && mouseX <= this.openGLWarningX2 && mouseY >= this.openGLWarningY1 && mouseY <= this.openGLWarningY2)
{
GuiConfirmOpenLink guiconfirmopenlink = new GuiConfirmOpenLink(this, this.openGLWarningLink, 13, true);
guiconfirmopenlink.disableSecurityWarning();
this.mc.displayGuiScreen(guiconfirmopenlink);
}
}
if (this.areRealmsNotificationsEnabled())
{
this.realmsNotification.mouseClicked(mouseX, mouseY, mouseButton);
}
if (mouseX > this.widthCopyrightRest && mouseX < this.widthCopyrightRest + this.widthCopyright && mouseY > this.height - 10 && mouseY < this.height)
{
this.mc.displayGuiScreen(new GuiWinGame(false, Runnables.doNothing()));
}
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
if (this.realmsNotification != null)
{
this.realmsNotification.onGuiClosed();
}
}
}

View File

@@ -0,0 +1,62 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiMemoryErrorScreen extends GuiScreen
{
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
this.buttonList.add(new GuiOptionButton(0, this.width / 2 - 155, this.height / 4 + 120 + 12, I18n.format("gui.toTitle")));
this.buttonList.add(new GuiOptionButton(1, this.width / 2 - 155 + 160, this.height / 4 + 120 + 12, I18n.format("menu.quit")));
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 0)
{
this.mc.displayGuiScreen(new GuiMainMenu());
}
else if (button.id == 1)
{
this.mc.shutdown();
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, "Out of memory!", this.width / 2, this.height / 4 - 60 + 20, 16777215);
this.drawString(this.fontRenderer, "Minecraft has run out of memory.", this.width / 2 - 140, this.height / 4 - 60 + 60 + 0, 10526880);
this.drawString(this.fontRenderer, "This could be caused by a bug in the game or by the", this.width / 2 - 140, this.height / 4 - 60 + 60 + 18, 10526880);
this.drawString(this.fontRenderer, "Java Virtual Machine not being allocated enough", this.width / 2 - 140, this.height / 4 - 60 + 60 + 27, 10526880);
this.drawString(this.fontRenderer, "memory.", this.width / 2 - 140, this.height / 4 - 60 + 60 + 36, 10526880);
this.drawString(this.fontRenderer, "To prevent level corruption, the current game has quit.", this.width / 2 - 140, this.height / 4 - 60 + 60 + 54, 10526880);
this.drawString(this.fontRenderer, "We've tried to free up enough memory to let you go back to", this.width / 2 - 140, this.height / 4 - 60 + 60 + 63, 10526880);
this.drawString(this.fontRenderer, "the main menu and back to playing, but this may not have worked.", this.width / 2 - 140, this.height / 4 - 60 + 60 + 72, 10526880);
this.drawString(this.fontRenderer, "Please restart the game if you see this message again.", this.width / 2 - 140, this.height / 4 - 60 + 60 + 81, 10526880);
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,276 @@
package net.minecraft.client.gui;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ContainerMerchant;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class GuiMerchant extends GuiContainer
{
private static final Logger LOGGER = LogManager.getLogger();
/** The GUI texture for the villager merchant GUI. */
private static final ResourceLocation MERCHANT_GUI_TEXTURE = new ResourceLocation("textures/gui/container/villager.png");
/** The current IMerchant instance in use for this specific merchant. */
private final IMerchant merchant;
/** The button which proceeds to the next available merchant recipe. */
private GuiMerchant.MerchantButton nextButton;
/** Returns to the previous Merchant recipe if one is applicable. */
private GuiMerchant.MerchantButton previousButton;
/** The integer value corresponding to the currently selected merchant recipe. */
private int selectedMerchantRecipe;
/** The chat component utilized by this GuiMerchant instance. */
private final ITextComponent chatComponent;
public GuiMerchant(InventoryPlayer p_i45500_1_, IMerchant p_i45500_2_, World worldIn)
{
super(new ContainerMerchant(p_i45500_1_, p_i45500_2_, worldIn));
this.merchant = p_i45500_2_;
this.chatComponent = p_i45500_2_.getDisplayName();
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.nextButton = (GuiMerchant.MerchantButton)this.addButton(new GuiMerchant.MerchantButton(1, i + 120 + 27, j + 24 - 1, true));
this.previousButton = (GuiMerchant.MerchantButton)this.addButton(new GuiMerchant.MerchantButton(2, i + 36 - 19, j + 24 - 1, false));
this.nextButton.enabled = false;
this.previousButton.enabled = false;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.chatComponent.getUnformattedText();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
super.updateScreen();
MerchantRecipeList merchantrecipelist = this.merchant.getRecipes(this.mc.player);
if (merchantrecipelist != null)
{
this.nextButton.enabled = this.selectedMerchantRecipe < merchantrecipelist.size() - 1;
this.previousButton.enabled = this.selectedMerchantRecipe > 0;
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
boolean flag = false;
if (button == this.nextButton)
{
++this.selectedMerchantRecipe;
MerchantRecipeList merchantrecipelist = this.merchant.getRecipes(this.mc.player);
if (merchantrecipelist != null && this.selectedMerchantRecipe >= merchantrecipelist.size())
{
this.selectedMerchantRecipe = merchantrecipelist.size() - 1;
}
flag = true;
}
else if (button == this.previousButton)
{
--this.selectedMerchantRecipe;
if (this.selectedMerchantRecipe < 0)
{
this.selectedMerchantRecipe = 0;
}
flag = true;
}
if (flag)
{
((ContainerMerchant)this.inventorySlots).setCurrentRecipeIndex(this.selectedMerchantRecipe);
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
packetbuffer.writeInt(this.selectedMerchantRecipe);
this.mc.getConnection().sendPacket(new CPacketCustomPayload("MC|TrSel", packetbuffer));
}
}
/**
* Draws the background layer of this container (behind the items).
*/
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(MERCHANT_GUI_TEXTURE);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
MerchantRecipeList merchantrecipelist = this.merchant.getRecipes(this.mc.player);
if (merchantrecipelist != null && !merchantrecipelist.isEmpty())
{
int k = this.selectedMerchantRecipe;
if (k < 0 || k >= merchantrecipelist.size())
{
return;
}
MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k);
if (merchantrecipe.isRecipeDisabled())
{
this.mc.getTextureManager().bindTexture(MERCHANT_GUI_TEXTURE);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableLighting();
this.drawTexturedModalRect(this.guiLeft + 83, this.guiTop + 21, 212, 0, 28, 21);
this.drawTexturedModalRect(this.guiLeft + 83, this.guiTop + 51, 212, 0, 28, 21);
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
MerchantRecipeList merchantrecipelist = this.merchant.getRecipes(this.mc.player);
if (merchantrecipelist != null && !merchantrecipelist.isEmpty())
{
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
int k = this.selectedMerchantRecipe;
MerchantRecipe merchantrecipe = (MerchantRecipe)merchantrecipelist.get(k);
ItemStack itemstack = merchantrecipe.getItemToBuy();
ItemStack itemstack1 = merchantrecipe.getSecondItemToBuy();
ItemStack itemstack2 = merchantrecipe.getItemToSell();
GlStateManager.pushMatrix();
RenderHelper.enableGUIStandardItemLighting();
GlStateManager.disableLighting();
GlStateManager.enableRescaleNormal();
GlStateManager.enableColorMaterial();
GlStateManager.enableLighting();
this.itemRender.zLevel = 100.0F;
this.itemRender.renderItemAndEffectIntoGUI(itemstack, i + 36, j + 24);
this.itemRender.renderItemOverlays(this.fontRenderer, itemstack, i + 36, j + 24);
if (!itemstack1.isEmpty())
{
this.itemRender.renderItemAndEffectIntoGUI(itemstack1, i + 62, j + 24);
this.itemRender.renderItemOverlays(this.fontRenderer, itemstack1, i + 62, j + 24);
}
this.itemRender.renderItemAndEffectIntoGUI(itemstack2, i + 120, j + 24);
this.itemRender.renderItemOverlays(this.fontRenderer, itemstack2, i + 120, j + 24);
this.itemRender.zLevel = 0.0F;
GlStateManager.disableLighting();
if (this.isPointInRegion(36, 24, 16, 16, mouseX, mouseY) && !itemstack.isEmpty())
{
this.renderToolTip(itemstack, mouseX, mouseY);
}
else if (!itemstack1.isEmpty() && this.isPointInRegion(62, 24, 16, 16, mouseX, mouseY) && !itemstack1.isEmpty())
{
this.renderToolTip(itemstack1, mouseX, mouseY);
}
else if (!itemstack2.isEmpty() && this.isPointInRegion(120, 24, 16, 16, mouseX, mouseY) && !itemstack2.isEmpty())
{
this.renderToolTip(itemstack2, mouseX, mouseY);
}
else if (merchantrecipe.isRecipeDisabled() && (this.isPointInRegion(83, 21, 28, 21, mouseX, mouseY) || this.isPointInRegion(83, 51, 28, 21, mouseX, mouseY)))
{
this.drawHoveringText(I18n.format("merchant.deprecated"), mouseX, mouseY);
}
GlStateManager.popMatrix();
GlStateManager.enableLighting();
GlStateManager.enableDepth();
RenderHelper.enableStandardItemLighting();
}
this.renderHoveredToolTip(mouseX, mouseY);
}
public IMerchant getMerchant()
{
return this.merchant;
}
@SideOnly(Side.CLIENT)
static class MerchantButton extends GuiButton
{
private final boolean forward;
public MerchantButton(int buttonID, int x, int y, boolean p_i1095_4_)
{
super(buttonID, x, y, 12, 19, "");
this.forward = p_i1095_4_;
}
/**
* Draws this button to the screen.
*/
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
mc.getTextureManager().bindTexture(GuiMerchant.MERCHANT_GUI_TEXTURE);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
boolean flag = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
int i = 0;
int j = 176;
if (!this.enabled)
{
j += this.width * 2;
}
else if (flag)
{
j += this.width;
}
if (!this.forward)
{
i += this.height;
}
this.drawTexturedModalRect(this.x, this.y, j, i, this.width, this.height);
}
}
}
}

View File

@@ -0,0 +1,494 @@
package net.minecraft.client.gui;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.List;
import net.minecraft.client.multiplayer.GuiConnecting;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.ServerList;
import net.minecraft.client.network.LanServerDetector;
import net.minecraft.client.network.LanServerInfo;
import net.minecraft.client.network.ServerPinger;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiMultiplayer extends GuiScreen
{
private static final Logger LOGGER = LogManager.getLogger();
private final ServerPinger oldServerPinger = new ServerPinger();
private final GuiScreen parentScreen;
private ServerSelectionList serverListSelector;
private ServerList savedServerList;
private GuiButton btnEditServer;
private GuiButton btnSelectServer;
private GuiButton btnDeleteServer;
private boolean deletingServer;
private boolean addingServer;
private boolean editingServer;
private boolean directConnect;
/** The text to be displayed when the player's cursor hovers over a server listing. */
private String hoveringText;
private ServerData selectedServer;
private LanServerDetector.LanServerList lanServerList;
private LanServerDetector.ThreadLanServerFind lanServerDetector;
private boolean initialized;
public GuiMultiplayer(GuiScreen parentScreen)
{
this.parentScreen = parentScreen;
net.minecraftforge.fml.client.FMLClientHandler.instance().setupServerList();
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
if (this.initialized)
{
this.serverListSelector.setDimensions(this.width, this.height, 32, this.height - 64);
}
else
{
this.initialized = true;
this.savedServerList = new ServerList(this.mc);
this.savedServerList.loadServerList();
this.lanServerList = new LanServerDetector.LanServerList();
try
{
this.lanServerDetector = new LanServerDetector.ThreadLanServerFind(this.lanServerList);
this.lanServerDetector.start();
}
catch (Exception exception)
{
LOGGER.warn("Unable to start LAN server detection: {}", (Object)exception.getMessage());
}
this.serverListSelector = new ServerSelectionList(this, this.mc, this.width, this.height, 32, this.height - 64, 36);
this.serverListSelector.updateOnlineServers(this.savedServerList);
}
this.createButtons();
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.serverListSelector.handleMouseInput();
}
public void createButtons()
{
this.btnEditServer = this.addButton(new GuiButton(7, this.width / 2 - 154, this.height - 28, 70, 20, I18n.format("selectServer.edit")));
this.btnDeleteServer = this.addButton(new GuiButton(2, this.width / 2 - 74, this.height - 28, 70, 20, I18n.format("selectServer.delete")));
this.btnSelectServer = this.addButton(new GuiButton(1, this.width / 2 - 154, this.height - 52, 100, 20, I18n.format("selectServer.select")));
this.buttonList.add(new GuiButton(4, this.width / 2 - 50, this.height - 52, 100, 20, I18n.format("selectServer.direct")));
this.buttonList.add(new GuiButton(3, this.width / 2 + 4 + 50, this.height - 52, 100, 20, I18n.format("selectServer.add")));
this.buttonList.add(new GuiButton(8, this.width / 2 + 4, this.height - 28, 70, 20, I18n.format("selectServer.refresh")));
this.buttonList.add(new GuiButton(0, this.width / 2 + 4 + 76, this.height - 28, 75, 20, I18n.format("gui.cancel")));
this.selectServer(this.serverListSelector.getSelected());
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
super.updateScreen();
if (this.lanServerList.getWasUpdated())
{
List<LanServerInfo> list = this.lanServerList.getLanServers();
this.lanServerList.setWasNotUpdated();
this.serverListSelector.updateNetworkServers(list);
}
this.oldServerPinger.pingPendingNetworks();
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
if (this.lanServerDetector != null)
{
this.lanServerDetector.interrupt();
this.lanServerDetector = null;
}
this.oldServerPinger.clearPendingNetworks();
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
GuiListExtended.IGuiListEntry guilistextended$iguilistentry = this.serverListSelector.getSelected() < 0 ? null : this.serverListSelector.getListEntry(this.serverListSelector.getSelected());
if (button.id == 2 && guilistextended$iguilistentry instanceof ServerListEntryNormal)
{
String s4 = ((ServerListEntryNormal)guilistextended$iguilistentry).getServerData().serverName;
if (s4 != null)
{
this.deletingServer = true;
String s = I18n.format("selectServer.deleteQuestion");
String s1 = "'" + s4 + "' " + I18n.format("selectServer.deleteWarning");
String s2 = I18n.format("selectServer.deleteButton");
String s3 = I18n.format("gui.cancel");
GuiYesNo guiyesno = new GuiYesNo(this, s, s1, s2, s3, this.serverListSelector.getSelected());
this.mc.displayGuiScreen(guiyesno);
}
}
else if (button.id == 1)
{
this.connectToSelected();
}
else if (button.id == 4)
{
this.directConnect = true;
this.selectedServer = new ServerData(I18n.format("selectServer.defaultName"), "", false);
this.mc.displayGuiScreen(new GuiScreenServerList(this, this.selectedServer));
}
else if (button.id == 3)
{
this.addingServer = true;
this.selectedServer = new ServerData(I18n.format("selectServer.defaultName"), "", false);
this.mc.displayGuiScreen(new GuiScreenAddServer(this, this.selectedServer));
}
else if (button.id == 7 && guilistextended$iguilistentry instanceof ServerListEntryNormal)
{
this.editingServer = true;
ServerData serverdata = ((ServerListEntryNormal)guilistextended$iguilistentry).getServerData();
this.selectedServer = new ServerData(serverdata.serverName, serverdata.serverIP, false);
this.selectedServer.copyFrom(serverdata);
this.mc.displayGuiScreen(new GuiScreenAddServer(this, this.selectedServer));
}
else if (button.id == 0)
{
this.mc.displayGuiScreen(this.parentScreen);
}
else if (button.id == 8)
{
this.refreshServerList();
}
}
}
private void refreshServerList()
{
this.mc.displayGuiScreen(new GuiMultiplayer(this.parentScreen));
}
public void confirmClicked(boolean result, int id)
{
GuiListExtended.IGuiListEntry guilistextended$iguilistentry = this.serverListSelector.getSelected() < 0 ? null : this.serverListSelector.getListEntry(this.serverListSelector.getSelected());
if (this.deletingServer)
{
this.deletingServer = false;
if (result && guilistextended$iguilistentry instanceof ServerListEntryNormal)
{
this.savedServerList.removeServerData(this.serverListSelector.getSelected());
this.savedServerList.saveServerList();
this.serverListSelector.setSelectedSlotIndex(-1);
this.serverListSelector.updateOnlineServers(this.savedServerList);
}
this.mc.displayGuiScreen(this);
}
else if (this.directConnect)
{
this.directConnect = false;
if (result)
{
this.connectToServer(this.selectedServer);
}
else
{
this.mc.displayGuiScreen(this);
}
}
else if (this.addingServer)
{
this.addingServer = false;
if (result)
{
this.savedServerList.addServerData(this.selectedServer);
this.savedServerList.saveServerList();
this.serverListSelector.setSelectedSlotIndex(-1);
this.serverListSelector.updateOnlineServers(this.savedServerList);
}
this.mc.displayGuiScreen(this);
}
else if (this.editingServer)
{
this.editingServer = false;
if (result && guilistextended$iguilistentry instanceof ServerListEntryNormal)
{
ServerData serverdata = ((ServerListEntryNormal)guilistextended$iguilistentry).getServerData();
serverdata.serverName = this.selectedServer.serverName;
serverdata.serverIP = this.selectedServer.serverIP;
serverdata.copyFrom(this.selectedServer);
this.savedServerList.saveServerList();
this.serverListSelector.updateOnlineServers(this.savedServerList);
}
this.mc.displayGuiScreen(this);
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
int i = this.serverListSelector.getSelected();
GuiListExtended.IGuiListEntry guilistextended$iguilistentry = i < 0 ? null : this.serverListSelector.getListEntry(i);
if (keyCode == 63)
{
this.refreshServerList();
}
else
{
if (i >= 0)
{
if (keyCode == 200)
{
if (isShiftKeyDown())
{
if (i > 0 && guilistextended$iguilistentry instanceof ServerListEntryNormal)
{
this.savedServerList.swapServers(i, i - 1);
this.selectServer(this.serverListSelector.getSelected() - 1);
this.serverListSelector.scrollBy(-this.serverListSelector.getSlotHeight());
this.serverListSelector.updateOnlineServers(this.savedServerList);
}
}
else if (i > 0)
{
this.selectServer(this.serverListSelector.getSelected() - 1);
this.serverListSelector.scrollBy(-this.serverListSelector.getSlotHeight());
if (this.serverListSelector.getListEntry(this.serverListSelector.getSelected()) instanceof ServerListEntryLanScan)
{
if (this.serverListSelector.getSelected() > 0)
{
this.selectServer(this.serverListSelector.getSize() - 1);
this.serverListSelector.scrollBy(-this.serverListSelector.getSlotHeight());
}
else
{
this.selectServer(-1);
}
}
}
else
{
this.selectServer(-1);
}
}
else if (keyCode == 208)
{
if (isShiftKeyDown())
{
if (i < this.savedServerList.countServers() - 1)
{
this.savedServerList.swapServers(i, i + 1);
this.selectServer(i + 1);
this.serverListSelector.scrollBy(this.serverListSelector.getSlotHeight());
this.serverListSelector.updateOnlineServers(this.savedServerList);
}
}
else if (i < this.serverListSelector.getSize())
{
this.selectServer(this.serverListSelector.getSelected() + 1);
this.serverListSelector.scrollBy(this.serverListSelector.getSlotHeight());
if (this.serverListSelector.getListEntry(this.serverListSelector.getSelected()) instanceof ServerListEntryLanScan)
{
if (this.serverListSelector.getSelected() < this.serverListSelector.getSize() - 1)
{
this.selectServer(this.serverListSelector.getSize() + 1);
this.serverListSelector.scrollBy(this.serverListSelector.getSlotHeight());
}
else
{
this.selectServer(-1);
}
}
}
else
{
this.selectServer(-1);
}
}
else if (keyCode != 28 && keyCode != 156)
{
super.keyTyped(typedChar, keyCode);
}
else
{
this.actionPerformed(this.buttonList.get(2));
}
}
else
{
super.keyTyped(typedChar, keyCode);
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.hoveringText = null;
this.drawDefaultBackground();
this.serverListSelector.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRenderer, I18n.format("multiplayer.title"), this.width / 2, 20, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
if (this.hoveringText != null)
{
this.drawHoveringText(Lists.newArrayList(Splitter.on("\n").split(this.hoveringText)), mouseX, mouseY);
}
}
public void connectToSelected()
{
GuiListExtended.IGuiListEntry guilistextended$iguilistentry = this.serverListSelector.getSelected() < 0 ? null : this.serverListSelector.getListEntry(this.serverListSelector.getSelected());
if (guilistextended$iguilistentry instanceof ServerListEntryNormal)
{
this.connectToServer(((ServerListEntryNormal)guilistextended$iguilistentry).getServerData());
}
else if (guilistextended$iguilistentry instanceof ServerListEntryLanDetected)
{
LanServerInfo lanserverinfo = ((ServerListEntryLanDetected)guilistextended$iguilistentry).getServerData();
this.connectToServer(new ServerData(lanserverinfo.getServerMotd(), lanserverinfo.getServerIpPort(), true));
}
}
private void connectToServer(ServerData server)
{
net.minecraftforge.fml.client.FMLClientHandler.instance().connectToServer(this, server);
}
public void selectServer(int index)
{
this.serverListSelector.setSelectedSlotIndex(index);
GuiListExtended.IGuiListEntry guilistextended$iguilistentry = index < 0 ? null : this.serverListSelector.getListEntry(index);
this.btnSelectServer.enabled = false;
this.btnEditServer.enabled = false;
this.btnDeleteServer.enabled = false;
if (guilistextended$iguilistentry != null && !(guilistextended$iguilistentry instanceof ServerListEntryLanScan))
{
this.btnSelectServer.enabled = true;
if (guilistextended$iguilistentry instanceof ServerListEntryNormal)
{
this.btnEditServer.enabled = true;
this.btnDeleteServer.enabled = true;
}
}
}
public ServerPinger getOldServerPinger()
{
return this.oldServerPinger;
}
public void setHoveringText(String p_146793_1_)
{
this.hoveringText = p_146793_1_;
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.serverListSelector.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Called when a mouse button is released.
*/
protected void mouseReleased(int mouseX, int mouseY, int state)
{
super.mouseReleased(mouseX, mouseY, state);
this.serverListSelector.mouseReleased(mouseX, mouseY, state);
}
public ServerList getServerList()
{
return this.savedServerList;
}
public boolean canMoveUp(ServerListEntryNormal p_175392_1_, int p_175392_2_)
{
return p_175392_2_ > 0;
}
public boolean canMoveDown(ServerListEntryNormal p_175394_1_, int p_175394_2_)
{
return p_175394_2_ < this.savedServerList.countServers() - 1;
}
public void moveServerUp(ServerListEntryNormal p_175391_1_, int p_175391_2_, boolean p_175391_3_)
{
int i = p_175391_3_ ? 0 : p_175391_2_ - 1;
this.savedServerList.swapServers(p_175391_2_, i);
if (this.serverListSelector.getSelected() == p_175391_2_)
{
this.selectServer(i);
}
this.serverListSelector.updateOnlineServers(this.savedServerList);
}
public void moveServerDown(ServerListEntryNormal p_175393_1_, int p_175393_2_, boolean p_175393_3_)
{
int i = p_175393_3_ ? this.savedServerList.countServers() - 1 : p_175393_2_ + 1;
this.savedServerList.swapServers(p_175393_2_, i);
if (this.serverListSelector.getSelected() == p_175393_2_)
{
this.selectServer(i);
}
this.serverListSelector.updateOnlineServers(this.savedServerList);
}
}

View File

@@ -0,0 +1,386 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class GuiNewChat extends Gui
{
private static final Logger LOGGER = LogManager.getLogger();
private final Minecraft mc;
/** A list of messages previously sent through the chat GUI */
private final List<String> sentMessages = Lists.<String>newArrayList();
/** Chat lines to be displayed in the chat box */
private final List<ChatLine> chatLines = Lists.<ChatLine>newArrayList();
/** List of the ChatLines currently drawn */
private final List<ChatLine> drawnChatLines = Lists.<ChatLine>newArrayList();
private int scrollPos;
private boolean isScrolled;
public GuiNewChat(Minecraft mcIn)
{
this.mc = mcIn;
}
public void drawChat(int updateCounter)
{
if (this.mc.gameSettings.chatVisibility != EntityPlayer.EnumChatVisibility.HIDDEN)
{
int i = this.getLineCount();
int j = this.drawnChatLines.size();
float f = this.mc.gameSettings.chatOpacity * 0.9F + 0.1F;
if (j > 0)
{
boolean flag = false;
if (this.getChatOpen())
{
flag = true;
}
float f1 = this.getChatScale();
int k = MathHelper.ceil((float)this.getChatWidth() / f1);
GlStateManager.pushMatrix();
GlStateManager.translate(2.0F, 8.0F, 0.0F);
GlStateManager.scale(f1, f1, 1.0F);
int l = 0;
for (int i1 = 0; i1 + this.scrollPos < this.drawnChatLines.size() && i1 < i; ++i1)
{
ChatLine chatline = this.drawnChatLines.get(i1 + this.scrollPos);
if (chatline != null)
{
int j1 = updateCounter - chatline.getUpdatedCounter();
if (j1 < 200 || flag)
{
double d0 = (double)j1 / 200.0D;
d0 = 1.0D - d0;
d0 = d0 * 10.0D;
d0 = MathHelper.clamp(d0, 0.0D, 1.0D);
d0 = d0 * d0;
int l1 = (int)(255.0D * d0);
if (flag)
{
l1 = 255;
}
l1 = (int)((float)l1 * f);
++l;
if (l1 > 3)
{
int i2 = 0;
int j2 = -i1 * 9;
drawRect(-2, j2 - 9, 0 + k + 4, j2, l1 / 2 << 24);
String s = chatline.getChatComponent().getFormattedText();
GlStateManager.enableBlend();
this.mc.fontRenderer.drawStringWithShadow(s, 0.0F, (float)(j2 - 8), 16777215 + (l1 << 24));
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
}
}
}
if (flag)
{
int k2 = this.mc.fontRenderer.FONT_HEIGHT;
GlStateManager.translate(-3.0F, 0.0F, 0.0F);
int l2 = j * k2 + j;
int i3 = l * k2 + l;
int j3 = this.scrollPos * i3 / j;
int k1 = i3 * i3 / l2;
if (l2 != i3)
{
int k3 = j3 > 0 ? 170 : 96;
int l3 = this.isScrolled ? 13382451 : 3355562;
drawRect(0, -j3, 2, -j3 - k1, l3 + (k3 << 24));
drawRect(2, -j3, 1, -j3 - k1, 13421772 + (k3 << 24));
}
}
GlStateManager.popMatrix();
}
}
}
/**
* Clears the chat.
*/
public void clearChatMessages(boolean p_146231_1_)
{
this.drawnChatLines.clear();
this.chatLines.clear();
if (p_146231_1_)
{
this.sentMessages.clear();
}
}
public void printChatMessage(ITextComponent chatComponent)
{
this.printChatMessageWithOptionalDeletion(chatComponent, 0);
}
/**
* prints the ChatComponent to Chat. If the ID is not 0, deletes an existing Chat Line of that ID from the GUI
*/
public void printChatMessageWithOptionalDeletion(ITextComponent chatComponent, int chatLineId)
{
this.setChatLine(chatComponent, chatLineId, this.mc.ingameGUI.getUpdateCounter(), false);
LOGGER.info("[CHAT] {}", (Object)chatComponent.getUnformattedText().replaceAll("\r", "\\\\r").replaceAll("\n", "\\\\n"));
}
private void setChatLine(ITextComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly)
{
if (chatLineId != 0)
{
this.deleteChatLine(chatLineId);
}
int i = MathHelper.floor((float)this.getChatWidth() / this.getChatScale());
List<ITextComponent> list = GuiUtilRenderComponents.splitText(chatComponent, i, this.mc.fontRenderer, false, false);
boolean flag = this.getChatOpen();
for (ITextComponent itextcomponent : list)
{
if (flag && this.scrollPos > 0)
{
this.isScrolled = true;
this.scroll(1);
}
this.drawnChatLines.add(0, new ChatLine(updateCounter, itextcomponent, chatLineId));
}
while (this.drawnChatLines.size() > 100)
{
this.drawnChatLines.remove(this.drawnChatLines.size() - 1);
}
if (!displayOnly)
{
this.chatLines.add(0, new ChatLine(updateCounter, chatComponent, chatLineId));
while (this.chatLines.size() > 100)
{
this.chatLines.remove(this.chatLines.size() - 1);
}
}
}
public void refreshChat()
{
this.drawnChatLines.clear();
this.resetScroll();
for (int i = this.chatLines.size() - 1; i >= 0; --i)
{
ChatLine chatline = this.chatLines.get(i);
this.setChatLine(chatline.getChatComponent(), chatline.getChatLineID(), chatline.getUpdatedCounter(), true);
}
}
/**
* Gets the list of messages previously sent through the chat GUI
*/
public List<String> getSentMessages()
{
return this.sentMessages;
}
/**
* Adds this string to the list of sent messages, for recall using the up/down arrow keys
*/
public void addToSentMessages(String message)
{
if (this.sentMessages.isEmpty() || !((String)this.sentMessages.get(this.sentMessages.size() - 1)).equals(message))
{
this.sentMessages.add(message);
}
}
/**
* Resets the chat scroll (executed when the GUI is closed, among others)
*/
public void resetScroll()
{
this.scrollPos = 0;
this.isScrolled = false;
}
/**
* Scrolls the chat by the given number of lines.
*/
public void scroll(int amount)
{
this.scrollPos += amount;
int i = this.drawnChatLines.size();
if (this.scrollPos > i - this.getLineCount())
{
this.scrollPos = i - this.getLineCount();
}
if (this.scrollPos <= 0)
{
this.scrollPos = 0;
this.isScrolled = false;
}
}
/**
* Gets the chat component under the mouse
*/
@Nullable
public ITextComponent getChatComponent(int mouseX, int mouseY)
{
if (!this.getChatOpen())
{
return null;
}
else
{
ScaledResolution scaledresolution = new ScaledResolution(this.mc);
int i = scaledresolution.getScaleFactor();
float f = this.getChatScale();
int j = mouseX / i - 2;
int k = mouseY / i - 40;
j = MathHelper.floor((float)j / f);
k = MathHelper.floor((float)k / f);
if (j >= 0 && k >= 0)
{
int l = Math.min(this.getLineCount(), this.drawnChatLines.size());
if (j <= MathHelper.floor((float)this.getChatWidth() / this.getChatScale()) && k < this.mc.fontRenderer.FONT_HEIGHT * l + l)
{
int i1 = k / this.mc.fontRenderer.FONT_HEIGHT + this.scrollPos;
if (i1 >= 0 && i1 < this.drawnChatLines.size())
{
ChatLine chatline = this.drawnChatLines.get(i1);
int j1 = 0;
for (ITextComponent itextcomponent : chatline.getChatComponent())
{
if (itextcomponent instanceof TextComponentString)
{
j1 += this.mc.fontRenderer.getStringWidth(GuiUtilRenderComponents.removeTextColorsIfConfigured(((TextComponentString)itextcomponent).getText(), false));
if (j1 > j)
{
return itextcomponent;
}
}
}
}
return null;
}
else
{
return null;
}
}
else
{
return null;
}
}
}
/**
* Returns true if the chat GUI is open
*/
public boolean getChatOpen()
{
return this.mc.currentScreen instanceof GuiChat;
}
/**
* finds and deletes a Chat line by ID
*/
public void deleteChatLine(int id)
{
Iterator<ChatLine> iterator = this.drawnChatLines.iterator();
while (iterator.hasNext())
{
ChatLine chatline = iterator.next();
if (chatline.getChatLineID() == id)
{
iterator.remove();
}
}
iterator = this.chatLines.iterator();
while (iterator.hasNext())
{
ChatLine chatline1 = iterator.next();
if (chatline1.getChatLineID() == id)
{
iterator.remove();
break;
}
}
}
public int getChatWidth()
{
return calculateChatboxWidth(this.mc.gameSettings.chatWidth);
}
public int getChatHeight()
{
return calculateChatboxHeight(this.getChatOpen() ? this.mc.gameSettings.chatHeightFocused : this.mc.gameSettings.chatHeightUnfocused);
}
/**
* Returns the chatscale from mc.gameSettings.chatScale
*/
public float getChatScale()
{
return this.mc.gameSettings.chatScale;
}
public static int calculateChatboxWidth(float scale)
{
int i = 320;
int j = 40;
return MathHelper.floor(scale * 280.0F + 40.0F);
}
public static int calculateChatboxHeight(float scale)
{
int i = 180;
int j = 20;
return MathHelper.floor(scale * 160.0F + 20.0F);
}
public int getLineCount()
{
return this.getChatHeight() / 9;
}
}

View File

@@ -0,0 +1,27 @@
package net.minecraft.client.gui;
import net.minecraft.client.settings.GameSettings;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiOptionButton extends GuiButton
{
private final GameSettings.Options enumOptions;
public GuiOptionButton(int p_i45011_1_, int p_i45011_2_, int p_i45011_3_, String p_i45011_4_)
{
this(p_i45011_1_, p_i45011_2_, p_i45011_3_, (GameSettings.Options)null, p_i45011_4_);
}
public GuiOptionButton(int p_i45013_1_, int p_i45013_2_, int p_i45013_3_, GameSettings.Options p_i45013_4_, String p_i45013_5_)
{
super(p_i45013_1_, p_i45013_2_, p_i45013_3_, 150, 20, p_i45013_5_);
this.enumOptions = p_i45013_4_;
}
public GameSettings.Options getOption()
{
return this.enumOptions;
}
}

View File

@@ -0,0 +1,97 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiOptionSlider extends GuiButton
{
private float sliderValue;
public boolean dragging;
private final GameSettings.Options options;
private final float minValue;
private final float maxValue;
public GuiOptionSlider(int buttonId, int x, int y, GameSettings.Options optionIn)
{
this(buttonId, x, y, optionIn, 0.0F, 1.0F);
}
public GuiOptionSlider(int buttonId, int x, int y, GameSettings.Options optionIn, float minValueIn, float maxValue)
{
super(buttonId, x, y, 150, 20, "");
this.sliderValue = 1.0F;
this.options = optionIn;
this.minValue = minValueIn;
this.maxValue = maxValue;
Minecraft minecraft = Minecraft.getMinecraft();
this.sliderValue = optionIn.normalizeValue(minecraft.gameSettings.getOptionFloatValue(optionIn));
this.displayString = minecraft.gameSettings.getKeyBinding(optionIn);
}
/**
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
* this button.
*/
protected int getHoverState(boolean mouseOver)
{
return 0;
}
/**
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
*/
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
if (this.dragging)
{
this.sliderValue = (float)(mouseX - (this.x + 4)) / (float)(this.width - 8);
this.sliderValue = MathHelper.clamp(this.sliderValue, 0.0F, 1.0F);
float f = this.options.denormalizeValue(this.sliderValue);
mc.gameSettings.setOptionFloatValue(this.options, f);
this.sliderValue = this.options.normalizeValue(f);
this.displayString = mc.gameSettings.getKeyBinding(this.options);
}
mc.getTextureManager().bindTexture(BUTTON_TEXTURES);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.x + (int)(this.sliderValue * (float)(this.width - 8)), this.y, 0, 66, 4, 20);
this.drawTexturedModalRect(this.x + (int)(this.sliderValue * (float)(this.width - 8)) + 4, this.y, 196, 66, 4, 20);
}
}
/**
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
* e).
*/
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.sliderValue = (float)(mouseX - (this.x + 4)) / (float)(this.width - 8);
this.sliderValue = MathHelper.clamp(this.sliderValue, 0.0F, 1.0F);
mc.gameSettings.setOptionFloatValue(this.options, this.options.denormalizeValue(this.sliderValue));
this.displayString = mc.gameSettings.getKeyBinding(this.options);
this.dragging = true;
return true;
}
else
{
return false;
}
}
/**
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
*/
public void mouseReleased(int mouseX, int mouseY)
{
this.dragging = false;
}
}

View File

@@ -0,0 +1,216 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.EnumDifficulty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiOptions extends GuiScreen
{
private static final GameSettings.Options[] SCREEN_OPTIONS = new GameSettings.Options[] {GameSettings.Options.FOV};
private final GuiScreen lastScreen;
/** Reference to the GameSettings object. */
private final GameSettings settings;
private GuiButton difficultyButton;
private GuiLockIconButton lockButton;
protected String title = "Options";
public GuiOptions(GuiScreen p_i1046_1_, GameSettings p_i1046_2_)
{
this.lastScreen = p_i1046_1_;
this.settings = p_i1046_2_;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.title = I18n.format("options.title");
int i = 0;
for (GameSettings.Options gamesettings$options : SCREEN_OPTIONS)
{
if (gamesettings$options.isFloat())
{
this.buttonList.add(new GuiOptionSlider(gamesettings$options.getOrdinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 12 + 24 * (i >> 1), gamesettings$options));
}
else
{
GuiOptionButton guioptionbutton = new GuiOptionButton(gamesettings$options.getOrdinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 12 + 24 * (i >> 1), gamesettings$options, this.settings.getKeyBinding(gamesettings$options));
this.buttonList.add(guioptionbutton);
}
++i;
}
if (this.mc.world != null)
{
EnumDifficulty enumdifficulty = this.mc.world.getDifficulty();
this.difficultyButton = new GuiButton(108, this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 12 + 24 * (i >> 1), 150, 20, this.getDifficultyText(enumdifficulty));
this.buttonList.add(this.difficultyButton);
if (this.mc.isSingleplayer() && !this.mc.world.getWorldInfo().isHardcoreModeEnabled())
{
this.difficultyButton.setWidth(this.difficultyButton.getButtonWidth() - 20);
this.lockButton = new GuiLockIconButton(109, this.difficultyButton.x + this.difficultyButton.getButtonWidth(), this.difficultyButton.y);
this.buttonList.add(this.lockButton);
this.lockButton.setLocked(this.mc.world.getWorldInfo().isDifficultyLocked());
this.lockButton.enabled = !this.lockButton.isLocked();
this.difficultyButton.enabled = !this.lockButton.isLocked();
}
else
{
this.difficultyButton.enabled = false;
}
}
else
{
this.buttonList.add(new GuiOptionButton(GameSettings.Options.REALMS_NOTIFICATIONS.getOrdinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 12 + 24 * (i >> 1), GameSettings.Options.REALMS_NOTIFICATIONS, this.settings.getKeyBinding(GameSettings.Options.REALMS_NOTIFICATIONS)));
}
this.buttonList.add(new GuiButton(110, this.width / 2 - 155, this.height / 6 + 48 - 6, 150, 20, I18n.format("options.skinCustomisation")));
this.buttonList.add(new GuiButton(106, this.width / 2 + 5, this.height / 6 + 48 - 6, 150, 20, I18n.format("options.sounds")));
this.buttonList.add(new GuiButton(101, this.width / 2 - 155, this.height / 6 + 72 - 6, 150, 20, I18n.format("options.video")));
this.buttonList.add(new GuiButton(100, this.width / 2 + 5, this.height / 6 + 72 - 6, 150, 20, I18n.format("options.controls")));
this.buttonList.add(new GuiButton(102, this.width / 2 - 155, this.height / 6 + 96 - 6, 150, 20, I18n.format("options.language")));
this.buttonList.add(new GuiButton(103, this.width / 2 + 5, this.height / 6 + 96 - 6, 150, 20, I18n.format("options.chat.title")));
this.buttonList.add(new GuiButton(105, this.width / 2 - 155, this.height / 6 + 120 - 6, 150, 20, I18n.format("options.resourcepack")));
this.buttonList.add(new GuiButton(104, this.width / 2 + 5, this.height / 6 + 120 - 6, 150, 20, I18n.format("options.snooper.view")));
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, I18n.format("gui.done")));
}
public String getDifficultyText(EnumDifficulty p_175355_1_)
{
ITextComponent itextcomponent = new TextComponentString("");
itextcomponent.appendSibling(new TextComponentTranslation("options.difficulty", new Object[0]));
itextcomponent.appendText(": ");
itextcomponent.appendSibling(new TextComponentTranslation(p_175355_1_.getDifficultyResourceKey(), new Object[0]));
return itextcomponent.getFormattedText();
}
public void confirmClicked(boolean result, int id)
{
this.mc.displayGuiScreen(this);
if (id == 109 && result && this.mc.world != null)
{
this.mc.world.getWorldInfo().setDifficultyLocked(true);
this.lockButton.setLocked(true);
this.lockButton.enabled = false;
this.difficultyButton.enabled = false;
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (keyCode == 1)
{
this.mc.gameSettings.saveOptions();
}
super.keyTyped(typedChar, keyCode);
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id < 100 && button instanceof GuiOptionButton)
{
GameSettings.Options gamesettings$options = ((GuiOptionButton)button).getOption();
this.settings.setOptionValue(gamesettings$options, 1);
button.displayString = this.settings.getKeyBinding(GameSettings.Options.byOrdinal(button.id));
}
if (button.id == 108)
{
this.mc.world.getWorldInfo().setDifficulty(EnumDifficulty.getDifficultyEnum(this.mc.world.getDifficulty().getDifficultyId() + 1));
this.difficultyButton.displayString = this.getDifficultyText(this.mc.world.getDifficulty());
}
if (button.id == 109)
{
this.mc.displayGuiScreen(new GuiYesNo(this, (new TextComponentTranslation("difficulty.lock.title", new Object[0])).getFormattedText(), (new TextComponentTranslation("difficulty.lock.question", new Object[] {new TextComponentTranslation(this.mc.world.getWorldInfo().getDifficulty().getDifficultyResourceKey(), new Object[0])})).getFormattedText(), 109));
}
if (button.id == 110)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(new GuiCustomizeSkin(this));
}
if (button.id == 101)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(new GuiVideoSettings(this, this.settings));
}
if (button.id == 100)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(new GuiControls(this, this.settings));
}
if (button.id == 102)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(new GuiLanguage(this, this.settings, this.mc.getLanguageManager()));
}
if (button.id == 103)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(new ScreenChatOptions(this, this.settings));
}
if (button.id == 104)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(new GuiSnooper(this, this.settings));
}
if (button.id == 200)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(this.lastScreen);
}
if (button.id == 105)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(new GuiScreenResourcePacks(this));
}
if (button.id == 106)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(new GuiScreenOptionsSounds(this, this.settings));
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,149 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiOptionsRowList extends GuiListExtended
{
private final List<GuiOptionsRowList.Row> options = Lists.<GuiOptionsRowList.Row>newArrayList();
public GuiOptionsRowList(Minecraft mcIn, int p_i45015_2_, int p_i45015_3_, int p_i45015_4_, int p_i45015_5_, int p_i45015_6_, GameSettings.Options... p_i45015_7_)
{
super(mcIn, p_i45015_2_, p_i45015_3_, p_i45015_4_, p_i45015_5_, p_i45015_6_);
this.centerListVertically = false;
for (int i = 0; i < p_i45015_7_.length; i += 2)
{
GameSettings.Options gamesettings$options = p_i45015_7_[i];
GameSettings.Options gamesettings$options1 = i < p_i45015_7_.length - 1 ? p_i45015_7_[i + 1] : null;
GuiButton guibutton = this.createButton(mcIn, p_i45015_2_ / 2 - 155, 0, gamesettings$options);
GuiButton guibutton1 = this.createButton(mcIn, p_i45015_2_ / 2 - 155 + 160, 0, gamesettings$options1);
this.options.add(new GuiOptionsRowList.Row(guibutton, guibutton1));
}
}
private GuiButton createButton(Minecraft mcIn, int p_148182_2_, int p_148182_3_, GameSettings.Options options)
{
if (options == null)
{
return null;
}
else
{
int i = options.getOrdinal();
return (GuiButton)(options.isFloat() ? new GuiOptionSlider(i, p_148182_2_, p_148182_3_, options) : new GuiOptionButton(i, p_148182_2_, p_148182_3_, options, mcIn.gameSettings.getKeyBinding(options)));
}
}
/**
* Gets the IGuiListEntry object for the given index
*/
public GuiOptionsRowList.Row getListEntry(int index)
{
return this.options.get(index);
}
protected int getSize()
{
return this.options.size();
}
/**
* Gets the width of the list
*/
public int getListWidth()
{
return 400;
}
protected int getScrollBarX()
{
return super.getScrollBarX() + 32;
}
@SideOnly(Side.CLIENT)
public static class Row implements GuiListExtended.IGuiListEntry
{
private final Minecraft client = Minecraft.getMinecraft();
private final GuiButton buttonA;
private final GuiButton buttonB;
public Row(GuiButton buttonAIn, GuiButton buttonBIn)
{
this.buttonA = buttonAIn;
this.buttonB = buttonBIn;
}
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks)
{
if (this.buttonA != null)
{
this.buttonA.y = y;
this.buttonA.drawButton(this.client, mouseX, mouseY, partialTicks);
}
if (this.buttonB != null)
{
this.buttonB.y = y;
this.buttonB.drawButton(this.client, mouseX, mouseY, partialTicks);
}
}
/**
* Called when the mouse is clicked within this entry. Returning true means that something within this entry
* was clicked and the list should not be dragged.
*/
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY)
{
if (this.buttonA.mousePressed(this.client, mouseX, mouseY))
{
if (this.buttonA instanceof GuiOptionButton)
{
this.client.gameSettings.setOptionValue(((GuiOptionButton)this.buttonA).getOption(), 1);
this.buttonA.displayString = this.client.gameSettings.getKeyBinding(GameSettings.Options.byOrdinal(this.buttonA.id));
}
return true;
}
else if (this.buttonB != null && this.buttonB.mousePressed(this.client, mouseX, mouseY))
{
if (this.buttonB instanceof GuiOptionButton)
{
this.client.gameSettings.setOptionValue(((GuiOptionButton)this.buttonB).getOption(), 1);
this.buttonB.displayString = this.client.gameSettings.getKeyBinding(GameSettings.Options.byOrdinal(this.buttonB.id));
}
return true;
}
else
{
return false;
}
}
/**
* Fired when the mouse button is released. Arguments: index, x, y, mouseEvent, relativeX, relativeY
*/
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY)
{
if (this.buttonA != null)
{
this.buttonA.mouseReleased(x, y);
}
if (this.buttonB != null)
{
this.buttonB.mouseReleased(x, y);
}
}
public void updatePosition(int slotIndex, int x, int y, float partialTicks)
{
}
}
}

View File

@@ -0,0 +1,303 @@
package net.minecraft.client.gui;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.UnmodifiableIterator;
import java.util.List;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.ClientBrandRetriever;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.FrameTimer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.WorldType;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.Display;
@SideOnly(Side.CLIENT)
public class GuiOverlayDebug extends Gui
{
private final Minecraft mc;
private final FontRenderer fontRenderer;
public GuiOverlayDebug(Minecraft mc)
{
this.mc = mc;
this.fontRenderer = mc.fontRenderer;
}
public void renderDebugInfo(ScaledResolution scaledResolutionIn)
{
this.mc.mcProfiler.startSection("debug");
GlStateManager.pushMatrix();
this.renderDebugInfoLeft();
this.renderDebugInfoRight(scaledResolutionIn);
GlStateManager.popMatrix();
if (this.mc.gameSettings.showLagometer)
{
this.renderLagometer();
}
this.mc.mcProfiler.endSection();
}
protected void renderDebugInfoLeft()
{
List<String> list = this.call();
list.add("");
list.add("Debug: Pie [shift]: " + (this.mc.gameSettings.showDebugProfilerChart ? "visible" : "hidden") + " FPS [alt]: " + (this.mc.gameSettings.showLagometer ? "visible" : "hidden"));
list.add("For help: press F3 + Q");
for (int i = 0; i < list.size(); ++i)
{
String s = list.get(i);
if (!Strings.isNullOrEmpty(s))
{
int j = this.fontRenderer.FONT_HEIGHT;
int k = this.fontRenderer.getStringWidth(s);
int l = 2;
int i1 = 2 + j * i;
drawRect(1, i1 - 1, 2 + k + 1, i1 + j - 1, -1873784752);
this.fontRenderer.drawString(s, 2, i1, 14737632);
}
}
}
protected void renderDebugInfoRight(ScaledResolution scaledRes)
{
List<String> list = this.getDebugInfoRight();
for (int i = 0; i < list.size(); ++i)
{
String s = list.get(i);
if (!Strings.isNullOrEmpty(s))
{
int j = this.fontRenderer.FONT_HEIGHT;
int k = this.fontRenderer.getStringWidth(s);
int l = scaledRes.getScaledWidth() - 2 - k;
int i1 = 2 + j * i;
drawRect(l - 1, i1 - 1, l + k + 1, i1 + j - 1, -1873784752);
this.fontRenderer.drawString(s, l, i1, 14737632);
}
}
}
@SuppressWarnings("incomplete-switch")
protected List<String> call()
{
BlockPos blockpos = new BlockPos(this.mc.getRenderViewEntity().posX, this.mc.getRenderViewEntity().getEntityBoundingBox().minY, this.mc.getRenderViewEntity().posZ);
if (this.mc.isReducedDebug())
{
return Lists.newArrayList("Minecraft 1.12.2 (" + this.mc.getVersion() + "/" + ClientBrandRetriever.getClientModName() + ")", this.mc.debug, this.mc.renderGlobal.getDebugInfoRenders(), this.mc.renderGlobal.getDebugInfoEntities(), "P: " + this.mc.effectRenderer.getStatistics() + ". T: " + this.mc.world.getDebugLoadedEntities(), this.mc.world.getProviderName(), "", String.format("Chunk-relative: %d %d %d", blockpos.getX() & 15, blockpos.getY() & 15, blockpos.getZ() & 15));
}
else
{
Entity entity = this.mc.getRenderViewEntity();
EnumFacing enumfacing = entity.getHorizontalFacing();
String s = "Invalid";
switch (enumfacing)
{
case NORTH:
s = "Towards negative Z";
break;
case SOUTH:
s = "Towards positive Z";
break;
case WEST:
s = "Towards negative X";
break;
case EAST:
s = "Towards positive X";
}
List<String> list = Lists.newArrayList("Minecraft 1.12.2 (" + this.mc.getVersion() + "/" + ClientBrandRetriever.getClientModName() + ("release".equalsIgnoreCase(this.mc.getVersionType()) ? "" : "/" + this.mc.getVersionType()) + ")", this.mc.debug, this.mc.renderGlobal.getDebugInfoRenders(), this.mc.renderGlobal.getDebugInfoEntities(), "P: " + this.mc.effectRenderer.getStatistics() + ". T: " + this.mc.world.getDebugLoadedEntities(), this.mc.world.getProviderName(), "", String.format("XYZ: %.3f / %.5f / %.3f", this.mc.getRenderViewEntity().posX, this.mc.getRenderViewEntity().getEntityBoundingBox().minY, this.mc.getRenderViewEntity().posZ), String.format("Block: %d %d %d", blockpos.getX(), blockpos.getY(), blockpos.getZ()), String.format("Chunk: %d %d %d in %d %d %d", blockpos.getX() & 15, blockpos.getY() & 15, blockpos.getZ() & 15, blockpos.getX() >> 4, blockpos.getY() >> 4, blockpos.getZ() >> 4), String.format("Facing: %s (%s) (%.1f / %.1f)", enumfacing, s, MathHelper.wrapDegrees(entity.rotationYaw), MathHelper.wrapDegrees(entity.rotationPitch)));
if (this.mc.world != null)
{
Chunk chunk = this.mc.world.getChunkFromBlockCoords(blockpos);
if (this.mc.world.isBlockLoaded(blockpos) && blockpos.getY() >= 0 && blockpos.getY() < 256)
{
if (!chunk.isEmpty())
{
list.add("Biome: " + chunk.getBiome(blockpos, this.mc.world.getBiomeProvider()).getBiomeName());
list.add("Light: " + chunk.getLightSubtracted(blockpos, 0) + " (" + chunk.getLightFor(EnumSkyBlock.SKY, blockpos) + " sky, " + chunk.getLightFor(EnumSkyBlock.BLOCK, blockpos) + " block)");
DifficultyInstance difficultyinstance = this.mc.world.getDifficultyForLocation(blockpos);
if (this.mc.isIntegratedServerRunning() && this.mc.getIntegratedServer() != null)
{
EntityPlayerMP entityplayermp = this.mc.getIntegratedServer().getPlayerList().getPlayerByUUID(this.mc.player.getUniqueID());
if (entityplayermp != null)
{
difficultyinstance = entityplayermp.world.getDifficultyForLocation(new BlockPos(entityplayermp));
}
}
list.add(String.format("Local Difficulty: %.2f // %.2f (Day %d)", difficultyinstance.getAdditionalDifficulty(), difficultyinstance.getClampedAdditionalDifficulty(), this.mc.world.getWorldTime() / 24000L));
}
else
{
list.add("Waiting for chunk...");
}
}
else
{
list.add("Outside of world...");
}
}
if (this.mc.entityRenderer != null && this.mc.entityRenderer.isShaderActive())
{
list.add("Shader: " + this.mc.entityRenderer.getShaderGroup().getShaderGroupName());
}
if (this.mc.objectMouseOver != null && this.mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK && this.mc.objectMouseOver.getBlockPos() != null)
{
BlockPos blockpos1 = this.mc.objectMouseOver.getBlockPos();
list.add(String.format("Looking at: %d %d %d", blockpos1.getX(), blockpos1.getY(), blockpos1.getZ()));
}
return list;
}
}
protected <T extends Comparable<T>> List<String> getDebugInfoRight()
{
long i = Runtime.getRuntime().maxMemory();
long j = Runtime.getRuntime().totalMemory();
long k = Runtime.getRuntime().freeMemory();
long l = j - k;
List<String> list = Lists.newArrayList(String.format("Java: %s %dbit", System.getProperty("java.version"), this.mc.isJava64bit() ? 64 : 32), String.format("Mem: % 2d%% %03d/%03dMB", l * 100L / i, bytesToMb(l), bytesToMb(i)), String.format("Allocated: % 2d%% %03dMB", j * 100L / i, bytesToMb(j)), "", String.format("CPU: %s", OpenGlHelper.getCpu()), "", String.format("Display: %dx%d (%s)", Display.getWidth(), Display.getHeight(), GlStateManager.glGetString(7936)), GlStateManager.glGetString(7937), GlStateManager.glGetString(7938));
list.add("");
list.addAll(net.minecraftforge.fml.common.FMLCommonHandler.instance().getBrandings(false));
if (this.mc.isReducedDebug())
{
return list;
}
else
{
if (this.mc.objectMouseOver != null && this.mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK && this.mc.objectMouseOver.getBlockPos() != null)
{
BlockPos blockpos = this.mc.objectMouseOver.getBlockPos();
IBlockState iblockstate = this.mc.world.getBlockState(blockpos);
if (this.mc.world.getWorldType() != WorldType.DEBUG_ALL_BLOCK_STATES)
{
iblockstate = iblockstate.getActualState(this.mc.world, blockpos);
}
list.add("");
list.add(String.valueOf(Block.REGISTRY.getNameForObject(iblockstate.getBlock())));
IProperty<T> iproperty;
String s;
for (UnmodifiableIterator unmodifiableiterator = iblockstate.getProperties().entrySet().iterator(); unmodifiableiterator.hasNext(); list.add(iproperty.getName() + ": " + s))
{
Entry < IProperty<?>, Comparable<? >> entry = (Entry)unmodifiableiterator.next();
iproperty = (IProperty)entry.getKey();
T t = (T)entry.getValue();
s = iproperty.getName(t);
if (Boolean.TRUE.equals(t))
{
s = TextFormatting.GREEN + s;
}
else if (Boolean.FALSE.equals(t))
{
s = TextFormatting.RED + s;
}
}
}
return list;
}
}
public void renderLagometer()
{
GlStateManager.disableDepth();
FrameTimer frametimer = this.mc.getFrameTimer();
int i = frametimer.getLastIndex();
int j = frametimer.getIndex();
long[] along = frametimer.getFrames();
ScaledResolution scaledresolution = new ScaledResolution(this.mc);
int k = i;
int l = 0;
drawRect(0, scaledresolution.getScaledHeight() - 60, 240, scaledresolution.getScaledHeight(), -1873784752);
while (k != j)
{
int i1 = frametimer.getLagometerValue(along[k], 30);
int j1 = this.getFrameColor(MathHelper.clamp(i1, 0, 60), 0, 30, 60);
this.drawVerticalLine(l, scaledresolution.getScaledHeight(), scaledresolution.getScaledHeight() - i1, j1);
++l;
k = frametimer.parseIndex(k + 1);
}
drawRect(1, scaledresolution.getScaledHeight() - 30 + 1, 14, scaledresolution.getScaledHeight() - 30 + 10, -1873784752);
this.fontRenderer.drawString("60", 2, scaledresolution.getScaledHeight() - 30 + 2, 14737632);
this.drawHorizontalLine(0, 239, scaledresolution.getScaledHeight() - 30, -1);
drawRect(1, scaledresolution.getScaledHeight() - 60 + 1, 14, scaledresolution.getScaledHeight() - 60 + 10, -1873784752);
this.fontRenderer.drawString("30", 2, scaledresolution.getScaledHeight() - 60 + 2, 14737632);
this.drawHorizontalLine(0, 239, scaledresolution.getScaledHeight() - 60, -1);
this.drawHorizontalLine(0, 239, scaledresolution.getScaledHeight() - 1, -1);
this.drawVerticalLine(0, scaledresolution.getScaledHeight() - 60, scaledresolution.getScaledHeight(), -1);
this.drawVerticalLine(239, scaledresolution.getScaledHeight() - 60, scaledresolution.getScaledHeight(), -1);
if (this.mc.gameSettings.limitFramerate <= 120)
{
this.drawHorizontalLine(0, 239, scaledresolution.getScaledHeight() - 60 + this.mc.gameSettings.limitFramerate / 2, -16711681);
}
GlStateManager.enableDepth();
}
private int getFrameColor(int p_181552_1_, int p_181552_2_, int p_181552_3_, int p_181552_4_)
{
return p_181552_1_ < p_181552_3_ ? this.blendColors(-16711936, -256, (float)p_181552_1_ / (float)p_181552_3_) : this.blendColors(-256, -65536, (float)(p_181552_1_ - p_181552_3_) / (float)(p_181552_4_ - p_181552_3_));
}
private int blendColors(int p_181553_1_, int p_181553_2_, float p_181553_3_)
{
int i = p_181553_1_ >> 24 & 255;
int j = p_181553_1_ >> 16 & 255;
int k = p_181553_1_ >> 8 & 255;
int l = p_181553_1_ & 255;
int i1 = p_181553_2_ >> 24 & 255;
int j1 = p_181553_2_ >> 16 & 255;
int k1 = p_181553_2_ >> 8 & 255;
int l1 = p_181553_2_ & 255;
int i2 = MathHelper.clamp((int)((float)i + (float)(i1 - i) * p_181553_3_), 0, 255);
int j2 = MathHelper.clamp((int)((float)j + (float)(j1 - j) * p_181553_3_), 0, 255);
int k2 = MathHelper.clamp((int)((float)k + (float)(k1 - k) * p_181553_3_), 0, 255);
int l2 = MathHelper.clamp((int)((float)l + (float)(l1 - l) * p_181553_3_), 0, 255);
return i2 << 24 | j2 << 16 | k2 << 8 | l2;
}
private static long bytesToMb(long bytes)
{
return bytes / 1024L / 1024L;
}
}

View File

@@ -0,0 +1,664 @@
package net.minecraft.client.gui;
import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.util.IntHashMap;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiPageButtonList extends GuiListExtended
{
private final List<GuiPageButtonList.GuiEntry> entries = Lists.<GuiPageButtonList.GuiEntry>newArrayList();
private final IntHashMap<Gui> componentMap = new IntHashMap<Gui>();
private final List<GuiTextField> editBoxes = Lists.<GuiTextField>newArrayList();
private final GuiPageButtonList.GuiListEntry[][] pages;
private int page;
private final GuiPageButtonList.GuiResponder responder;
private Gui focusedControl;
public GuiPageButtonList(Minecraft mcIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn, GuiPageButtonList.GuiResponder p_i45536_7_, GuiPageButtonList.GuiListEntry[]... p_i45536_8_)
{
super(mcIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn);
this.responder = p_i45536_7_;
this.pages = p_i45536_8_;
this.centerListVertically = false;
this.populateComponents();
this.populateEntries();
}
private void populateComponents()
{
for (GuiPageButtonList.GuiListEntry[] aguipagebuttonlist$guilistentry : this.pages)
{
for (int i = 0; i < aguipagebuttonlist$guilistentry.length; i += 2)
{
GuiPageButtonList.GuiListEntry guipagebuttonlist$guilistentry = aguipagebuttonlist$guilistentry[i];
GuiPageButtonList.GuiListEntry guipagebuttonlist$guilistentry1 = i < aguipagebuttonlist$guilistentry.length - 1 ? aguipagebuttonlist$guilistentry[i + 1] : null;
Gui gui = this.createEntry(guipagebuttonlist$guilistentry, 0, guipagebuttonlist$guilistentry1 == null);
Gui gui1 = this.createEntry(guipagebuttonlist$guilistentry1, 160, guipagebuttonlist$guilistentry == null);
GuiPageButtonList.GuiEntry guipagebuttonlist$guientry = new GuiPageButtonList.GuiEntry(gui, gui1);
this.entries.add(guipagebuttonlist$guientry);
if (guipagebuttonlist$guilistentry != null && gui != null)
{
this.componentMap.addKey(guipagebuttonlist$guilistentry.getId(), gui);
if (gui instanceof GuiTextField)
{
this.editBoxes.add((GuiTextField)gui);
}
}
if (guipagebuttonlist$guilistentry1 != null && gui1 != null)
{
this.componentMap.addKey(guipagebuttonlist$guilistentry1.getId(), gui1);
if (gui1 instanceof GuiTextField)
{
this.editBoxes.add((GuiTextField)gui1);
}
}
}
}
}
private void populateEntries()
{
this.entries.clear();
for (int i = 0; i < this.pages[this.page].length; i += 2)
{
GuiPageButtonList.GuiListEntry guipagebuttonlist$guilistentry = this.pages[this.page][i];
GuiPageButtonList.GuiListEntry guipagebuttonlist$guilistentry1 = i < this.pages[this.page].length - 1 ? this.pages[this.page][i + 1] : null;
Gui gui = this.componentMap.lookup(guipagebuttonlist$guilistentry.getId());
Gui gui1 = guipagebuttonlist$guilistentry1 != null ? (Gui)this.componentMap.lookup(guipagebuttonlist$guilistentry1.getId()) : null;
GuiPageButtonList.GuiEntry guipagebuttonlist$guientry = new GuiPageButtonList.GuiEntry(gui, gui1);
this.entries.add(guipagebuttonlist$guientry);
}
}
public void setPage(int p_181156_1_)
{
if (p_181156_1_ != this.page)
{
int i = this.page;
this.page = p_181156_1_;
this.populateEntries();
this.markVisibility(i, p_181156_1_);
this.amountScrolled = 0.0F;
}
}
public int getPage()
{
return this.page;
}
public int getPageCount()
{
return this.pages.length;
}
public Gui getFocusedControl()
{
return this.focusedControl;
}
public void previousPage()
{
if (this.page > 0)
{
this.setPage(this.page - 1);
}
}
public void nextPage()
{
if (this.page < this.pages.length - 1)
{
this.setPage(this.page + 1);
}
}
public Gui getComponent(int p_178061_1_)
{
return this.componentMap.lookup(p_178061_1_);
}
private void markVisibility(int p_178060_1_, int p_178060_2_)
{
for (GuiPageButtonList.GuiListEntry guipagebuttonlist$guilistentry : this.pages[p_178060_1_])
{
if (guipagebuttonlist$guilistentry != null)
{
this.setComponentVisibility(this.componentMap.lookup(guipagebuttonlist$guilistentry.getId()), false);
}
}
for (GuiPageButtonList.GuiListEntry guipagebuttonlist$guilistentry1 : this.pages[p_178060_2_])
{
if (guipagebuttonlist$guilistentry1 != null)
{
this.setComponentVisibility(this.componentMap.lookup(guipagebuttonlist$guilistentry1.getId()), true);
}
}
}
private void setComponentVisibility(Gui p_178066_1_, boolean p_178066_2_)
{
if (p_178066_1_ instanceof GuiButton)
{
((GuiButton)p_178066_1_).visible = p_178066_2_;
}
else if (p_178066_1_ instanceof GuiTextField)
{
((GuiTextField)p_178066_1_).setVisible(p_178066_2_);
}
else if (p_178066_1_ instanceof GuiLabel)
{
((GuiLabel)p_178066_1_).visible = p_178066_2_;
}
}
@Nullable
private Gui createEntry(@Nullable GuiPageButtonList.GuiListEntry p_178058_1_, int p_178058_2_, boolean p_178058_3_)
{
if (p_178058_1_ instanceof GuiPageButtonList.GuiSlideEntry)
{
return this.createSlider(this.width / 2 - 155 + p_178058_2_, 0, (GuiPageButtonList.GuiSlideEntry)p_178058_1_);
}
else if (p_178058_1_ instanceof GuiPageButtonList.GuiButtonEntry)
{
return this.createButton(this.width / 2 - 155 + p_178058_2_, 0, (GuiPageButtonList.GuiButtonEntry)p_178058_1_);
}
else if (p_178058_1_ instanceof GuiPageButtonList.EditBoxEntry)
{
return this.createTextField(this.width / 2 - 155 + p_178058_2_, 0, (GuiPageButtonList.EditBoxEntry)p_178058_1_);
}
else
{
return p_178058_1_ instanceof GuiPageButtonList.GuiLabelEntry ? this.createLabel(this.width / 2 - 155 + p_178058_2_, 0, (GuiPageButtonList.GuiLabelEntry)p_178058_1_, p_178058_3_) : null;
}
}
public void setActive(boolean p_181155_1_)
{
for (GuiPageButtonList.GuiEntry guipagebuttonlist$guientry : this.entries)
{
if (guipagebuttonlist$guientry.component1 instanceof GuiButton)
{
((GuiButton)guipagebuttonlist$guientry.component1).enabled = p_181155_1_;
}
if (guipagebuttonlist$guientry.component2 instanceof GuiButton)
{
((GuiButton)guipagebuttonlist$guientry.component2).enabled = p_181155_1_;
}
}
}
public boolean mouseClicked(int mouseX, int mouseY, int mouseEvent)
{
boolean flag = super.mouseClicked(mouseX, mouseY, mouseEvent);
int i = this.getSlotIndexFromScreenCoords(mouseX, mouseY);
if (i >= 0)
{
GuiPageButtonList.GuiEntry guipagebuttonlist$guientry = this.getListEntry(i);
if (this.focusedControl != guipagebuttonlist$guientry.focusedControl && this.focusedControl != null && this.focusedControl instanceof GuiTextField)
{
((GuiTextField)this.focusedControl).setFocused(false);
}
this.focusedControl = guipagebuttonlist$guientry.focusedControl;
}
return flag;
}
private GuiSlider createSlider(int p_178067_1_, int p_178067_2_, GuiPageButtonList.GuiSlideEntry p_178067_3_)
{
GuiSlider guislider = new GuiSlider(this.responder, p_178067_3_.getId(), p_178067_1_, p_178067_2_, p_178067_3_.getCaption(), p_178067_3_.getMinValue(), p_178067_3_.getMaxValue(), p_178067_3_.getInitalValue(), p_178067_3_.getFormatter());
guislider.visible = p_178067_3_.shouldStartVisible();
return guislider;
}
private GuiListButton createButton(int p_178065_1_, int p_178065_2_, GuiPageButtonList.GuiButtonEntry p_178065_3_)
{
GuiListButton guilistbutton = new GuiListButton(this.responder, p_178065_3_.getId(), p_178065_1_, p_178065_2_, p_178065_3_.getCaption(), p_178065_3_.getInitialValue());
guilistbutton.visible = p_178065_3_.shouldStartVisible();
return guilistbutton;
}
private GuiTextField createTextField(int p_178068_1_, int p_178068_2_, GuiPageButtonList.EditBoxEntry p_178068_3_)
{
GuiTextField guitextfield = new GuiTextField(p_178068_3_.getId(), this.mc.fontRenderer, p_178068_1_, p_178068_2_, 150, 20);
guitextfield.setText(p_178068_3_.getCaption());
guitextfield.setGuiResponder(this.responder);
guitextfield.setVisible(p_178068_3_.shouldStartVisible());
guitextfield.setValidator(p_178068_3_.getFilter());
return guitextfield;
}
private GuiLabel createLabel(int p_178063_1_, int p_178063_2_, GuiPageButtonList.GuiLabelEntry p_178063_3_, boolean p_178063_4_)
{
GuiLabel guilabel;
if (p_178063_4_)
{
guilabel = new GuiLabel(this.mc.fontRenderer, p_178063_3_.getId(), p_178063_1_, p_178063_2_, this.width - p_178063_1_ * 2, 20, -1);
}
else
{
guilabel = new GuiLabel(this.mc.fontRenderer, p_178063_3_.getId(), p_178063_1_, p_178063_2_, 150, 20, -1);
}
guilabel.visible = p_178063_3_.shouldStartVisible();
guilabel.addLine(p_178063_3_.getCaption());
guilabel.setCentered();
return guilabel;
}
public void onKeyPressed(char p_178062_1_, int p_178062_2_)
{
if (this.focusedControl instanceof GuiTextField)
{
GuiTextField guitextfield = (GuiTextField)this.focusedControl;
if (!GuiScreen.isKeyComboCtrlV(p_178062_2_))
{
if (p_178062_2_ == 15)
{
guitextfield.setFocused(false);
int k = this.editBoxes.indexOf(this.focusedControl);
if (GuiScreen.isShiftKeyDown())
{
if (k == 0)
{
k = this.editBoxes.size() - 1;
}
else
{
--k;
}
}
else if (k == this.editBoxes.size() - 1)
{
k = 0;
}
else
{
++k;
}
this.focusedControl = this.editBoxes.get(k);
guitextfield = (GuiTextField)this.focusedControl;
guitextfield.setFocused(true);
int l = guitextfield.y + this.slotHeight;
int i1 = guitextfield.y;
if (l > this.bottom)
{
this.amountScrolled += (float)(l - this.bottom);
}
else if (i1 < this.top)
{
this.amountScrolled = (float)i1;
}
}
else
{
guitextfield.textboxKeyTyped(p_178062_1_, p_178062_2_);
}
}
else
{
String s = GuiScreen.getClipboardString();
String[] astring = s.split(";");
int i = this.editBoxes.indexOf(this.focusedControl);
int j = i;
for (String s1 : astring)
{
GuiTextField guitextfield1 = this.editBoxes.get(j);
guitextfield1.setText(s1);
guitextfield1.setResponderEntryValue(guitextfield1.getId(), s1);
if (j == this.editBoxes.size() - 1)
{
j = 0;
}
else
{
++j;
}
if (j == i)
{
break;
}
}
}
}
}
/**
* Gets the IGuiListEntry object for the given index
*/
public GuiPageButtonList.GuiEntry getListEntry(int index)
{
return this.entries.get(index);
}
public int getSize()
{
return this.entries.size();
}
/**
* Gets the width of the list
*/
public int getListWidth()
{
return 400;
}
protected int getScrollBarX()
{
return super.getScrollBarX() + 32;
}
@SideOnly(Side.CLIENT)
public static class EditBoxEntry extends GuiPageButtonList.GuiListEntry
{
private final Predicate<String> filter;
public EditBoxEntry(int p_i45534_1_, String p_i45534_2_, boolean p_i45534_3_, Predicate<String> p_i45534_4_)
{
super(p_i45534_1_, p_i45534_2_, p_i45534_3_);
this.filter = (Predicate)MoreObjects.firstNonNull(p_i45534_4_, Predicates.alwaysTrue());
}
public Predicate<String> getFilter()
{
return this.filter;
}
}
@SideOnly(Side.CLIENT)
public static class GuiButtonEntry extends GuiPageButtonList.GuiListEntry
{
private final boolean initialValue;
public GuiButtonEntry(int p_i45535_1_, String p_i45535_2_, boolean p_i45535_3_, boolean p_i45535_4_)
{
super(p_i45535_1_, p_i45535_2_, p_i45535_3_);
this.initialValue = p_i45535_4_;
}
public boolean getInitialValue()
{
return this.initialValue;
}
}
@SideOnly(Side.CLIENT)
public static class GuiEntry implements GuiListExtended.IGuiListEntry
{
private final Minecraft client = Minecraft.getMinecraft();
private final Gui component1;
private final Gui component2;
private Gui focusedControl;
public GuiEntry(@Nullable Gui p_i45533_1_, @Nullable Gui p_i45533_2_)
{
this.component1 = p_i45533_1_;
this.component2 = p_i45533_2_;
}
public Gui getComponent1()
{
return this.component1;
}
public Gui getComponent2()
{
return this.component2;
}
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks)
{
this.renderComponent(this.component1, y, mouseX, mouseY, false, partialTicks);
this.renderComponent(this.component2, y, mouseX, mouseY, false, partialTicks);
}
private void renderComponent(Gui p_192636_1_, int p_192636_2_, int p_192636_3_, int p_192636_4_, boolean p_192636_5_, float p_192636_6_)
{
if (p_192636_1_ != null)
{
if (p_192636_1_ instanceof GuiButton)
{
this.renderButton((GuiButton)p_192636_1_, p_192636_2_, p_192636_3_, p_192636_4_, p_192636_5_, p_192636_6_);
}
else if (p_192636_1_ instanceof GuiTextField)
{
this.renderTextField((GuiTextField)p_192636_1_, p_192636_2_, p_192636_5_);
}
else if (p_192636_1_ instanceof GuiLabel)
{
this.renderLabel((GuiLabel)p_192636_1_, p_192636_2_, p_192636_3_, p_192636_4_, p_192636_5_);
}
}
}
private void renderButton(GuiButton p_192635_1_, int p_192635_2_, int p_192635_3_, int p_192635_4_, boolean p_192635_5_, float p_192635_6_)
{
p_192635_1_.y = p_192635_2_;
if (!p_192635_5_)
{
p_192635_1_.drawButton(this.client, p_192635_3_, p_192635_4_, p_192635_6_);
}
}
private void renderTextField(GuiTextField p_178027_1_, int p_178027_2_, boolean p_178027_3_)
{
p_178027_1_.y = p_178027_2_;
if (!p_178027_3_)
{
p_178027_1_.drawTextBox();
}
}
private void renderLabel(GuiLabel p_178025_1_, int p_178025_2_, int p_178025_3_, int p_178025_4_, boolean p_178025_5_)
{
p_178025_1_.y = p_178025_2_;
if (!p_178025_5_)
{
p_178025_1_.drawLabel(this.client, p_178025_3_, p_178025_4_);
}
}
public void updatePosition(int slotIndex, int x, int y, float partialTicks)
{
this.renderComponent(this.component1, y, 0, 0, true, partialTicks);
this.renderComponent(this.component2, y, 0, 0, true, partialTicks);
}
/**
* Called when the mouse is clicked within this entry. Returning true means that something within this entry
* was clicked and the list should not be dragged.
*/
public boolean mousePressed(int slotIndex, int mouseX, int mouseY, int mouseEvent, int relativeX, int relativeY)
{
boolean flag = this.clickComponent(this.component1, mouseX, mouseY, mouseEvent);
boolean flag1 = this.clickComponent(this.component2, mouseX, mouseY, mouseEvent);
return flag || flag1;
}
private boolean clickComponent(Gui p_178026_1_, int p_178026_2_, int p_178026_3_, int p_178026_4_)
{
if (p_178026_1_ == null)
{
return false;
}
else if (p_178026_1_ instanceof GuiButton)
{
return this.clickButton((GuiButton)p_178026_1_, p_178026_2_, p_178026_3_, p_178026_4_);
}
else
{
if (p_178026_1_ instanceof GuiTextField)
{
this.clickTextField((GuiTextField)p_178026_1_, p_178026_2_, p_178026_3_, p_178026_4_);
}
return false;
}
}
private boolean clickButton(GuiButton p_178023_1_, int p_178023_2_, int p_178023_3_, int p_178023_4_)
{
boolean flag = p_178023_1_.mousePressed(this.client, p_178023_2_, p_178023_3_);
if (flag)
{
this.focusedControl = p_178023_1_;
}
return flag;
}
private void clickTextField(GuiTextField p_178018_1_, int p_178018_2_, int p_178018_3_, int p_178018_4_)
{
p_178018_1_.mouseClicked(p_178018_2_, p_178018_3_, p_178018_4_);
if (p_178018_1_.isFocused())
{
this.focusedControl = p_178018_1_;
}
}
/**
* Fired when the mouse button is released. Arguments: index, x, y, mouseEvent, relativeX, relativeY
*/
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY)
{
this.releaseComponent(this.component1, x, y, mouseEvent);
this.releaseComponent(this.component2, x, y, mouseEvent);
}
private void releaseComponent(Gui p_178016_1_, int p_178016_2_, int p_178016_3_, int p_178016_4_)
{
if (p_178016_1_ != null)
{
if (p_178016_1_ instanceof GuiButton)
{
this.releaseButton((GuiButton)p_178016_1_, p_178016_2_, p_178016_3_, p_178016_4_);
}
}
}
private void releaseButton(GuiButton p_178019_1_, int p_178019_2_, int p_178019_3_, int p_178019_4_)
{
p_178019_1_.mouseReleased(p_178019_2_, p_178019_3_);
}
}
@SideOnly(Side.CLIENT)
public static class GuiLabelEntry extends GuiPageButtonList.GuiListEntry
{
public GuiLabelEntry(int p_i45532_1_, String p_i45532_2_, boolean p_i45532_3_)
{
super(p_i45532_1_, p_i45532_2_, p_i45532_3_);
}
}
@SideOnly(Side.CLIENT)
public static class GuiListEntry
{
private final int id;
private final String caption;
private final boolean startVisible;
public GuiListEntry(int p_i45531_1_, String p_i45531_2_, boolean p_i45531_3_)
{
this.id = p_i45531_1_;
this.caption = p_i45531_2_;
this.startVisible = p_i45531_3_;
}
public int getId()
{
return this.id;
}
public String getCaption()
{
return this.caption;
}
public boolean shouldStartVisible()
{
return this.startVisible;
}
}
@SideOnly(Side.CLIENT)
public interface GuiResponder
{
void setEntryValue(int id, boolean value);
void setEntryValue(int id, float value);
void setEntryValue(int id, String value);
}
@SideOnly(Side.CLIENT)
public static class GuiSlideEntry extends GuiPageButtonList.GuiListEntry
{
private final GuiSlider.FormatHelper formatter;
private final float minValue;
private final float maxValue;
private final float initialValue;
public GuiSlideEntry(int p_i45530_1_, String p_i45530_2_, boolean p_i45530_3_, GuiSlider.FormatHelper p_i45530_4_, float p_i45530_5_, float p_i45530_6_, float p_i45530_7_)
{
super(p_i45530_1_, p_i45530_2_, p_i45530_3_);
this.formatter = p_i45530_4_;
this.minValue = p_i45530_5_;
this.maxValue = p_i45530_6_;
this.initialValue = p_i45530_7_;
}
public GuiSlider.FormatHelper getFormatter()
{
return this.formatter;
}
public float getMinValue()
{
return this.minValue;
}
public float getMaxValue()
{
return this.maxValue;
}
public float getInitalValue()
{
return this.initialValue;
}
}
}

View File

@@ -0,0 +1,401 @@
package net.minecraft.client.gui;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;
import com.mojang.authlib.GameProfile;
import java.util.Comparator;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EnumPlayerModelParts;
import net.minecraft.scoreboard.IScoreCriteria;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.GameType;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiPlayerTabOverlay extends Gui
{
private static final Ordering<NetworkPlayerInfo> ENTRY_ORDERING = Ordering.from(new GuiPlayerTabOverlay.PlayerComparator());
private final Minecraft mc;
private final GuiIngame guiIngame;
private ITextComponent footer;
private ITextComponent header;
/** The last time the playerlist was opened (went from not being renderd, to being rendered) */
private long lastTimeOpened;
/** Weither or not the playerlist is currently being rendered */
private boolean isBeingRendered;
public GuiPlayerTabOverlay(Minecraft mcIn, GuiIngame guiIngameIn)
{
this.mc = mcIn;
this.guiIngame = guiIngameIn;
}
/**
* Returns the name that should be renderd for the player supplied
*/
public String getPlayerName(NetworkPlayerInfo networkPlayerInfoIn)
{
return networkPlayerInfoIn.getDisplayName() != null ? networkPlayerInfoIn.getDisplayName().getFormattedText() : ScorePlayerTeam.formatPlayerName(networkPlayerInfoIn.getPlayerTeam(), networkPlayerInfoIn.getGameProfile().getName());
}
/**
* Called by GuiIngame to update the information stored in the playerlist, does not actually render the list,
* however.
*/
public void updatePlayerList(boolean willBeRendered)
{
if (willBeRendered && !this.isBeingRendered)
{
this.lastTimeOpened = Minecraft.getSystemTime();
}
this.isBeingRendered = willBeRendered;
}
/**
* Renders the playerlist, its background, headers and footers.
*/
public void renderPlayerlist(int width, Scoreboard scoreboardIn, @Nullable ScoreObjective scoreObjectiveIn)
{
NetHandlerPlayClient nethandlerplayclient = this.mc.player.connection;
List<NetworkPlayerInfo> list = ENTRY_ORDERING.<NetworkPlayerInfo>sortedCopy(nethandlerplayclient.getPlayerInfoMap());
int i = 0;
int j = 0;
for (NetworkPlayerInfo networkplayerinfo : list)
{
int k = this.mc.fontRenderer.getStringWidth(this.getPlayerName(networkplayerinfo));
i = Math.max(i, k);
if (scoreObjectiveIn != null && scoreObjectiveIn.getRenderType() != IScoreCriteria.EnumRenderType.HEARTS)
{
k = this.mc.fontRenderer.getStringWidth(" " + scoreboardIn.getOrCreateScore(networkplayerinfo.getGameProfile().getName(), scoreObjectiveIn).getScorePoints());
j = Math.max(j, k);
}
}
list = list.subList(0, Math.min(list.size(), 80));
int l3 = list.size();
int i4 = l3;
int j4;
for (j4 = 1; i4 > 20; i4 = (l3 + j4 - 1) / j4)
{
++j4;
}
boolean flag = this.mc.isIntegratedServerRunning() || this.mc.getConnection().getNetworkManager().isEncrypted();
int l;
if (scoreObjectiveIn != null)
{
if (scoreObjectiveIn.getRenderType() == IScoreCriteria.EnumRenderType.HEARTS)
{
l = 90;
}
else
{
l = j;
}
}
else
{
l = 0;
}
int i1 = Math.min(j4 * ((flag ? 9 : 0) + i + l + 13), width - 50) / j4;
int j1 = width / 2 - (i1 * j4 + (j4 - 1) * 5) / 2;
int k1 = 10;
int l1 = i1 * j4 + (j4 - 1) * 5;
List<String> list1 = null;
if (this.header != null)
{
list1 = this.mc.fontRenderer.listFormattedStringToWidth(this.header.getFormattedText(), width - 50);
for (String s : list1)
{
l1 = Math.max(l1, this.mc.fontRenderer.getStringWidth(s));
}
}
List<String> list2 = null;
if (this.footer != null)
{
list2 = this.mc.fontRenderer.listFormattedStringToWidth(this.footer.getFormattedText(), width - 50);
for (String s1 : list2)
{
l1 = Math.max(l1, this.mc.fontRenderer.getStringWidth(s1));
}
}
if (list1 != null)
{
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + list1.size() * this.mc.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE);
for (String s2 : list1)
{
int i2 = this.mc.fontRenderer.getStringWidth(s2);
this.mc.fontRenderer.drawStringWithShadow(s2, (float)(width / 2 - i2 / 2), (float)k1, -1);
k1 += this.mc.fontRenderer.FONT_HEIGHT;
}
++k1;
}
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + i4 * 9, Integer.MIN_VALUE);
for (int k4 = 0; k4 < l3; ++k4)
{
int l4 = k4 / i4;
int i5 = k4 % i4;
int j2 = j1 + l4 * i1 + l4 * 5;
int k2 = k1 + i5 * 9;
drawRect(j2, k2, j2 + i1, k2 + 8, 553648127);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
if (k4 < list.size())
{
NetworkPlayerInfo networkplayerinfo1 = list.get(k4);
GameProfile gameprofile = networkplayerinfo1.getGameProfile();
if (flag)
{
EntityPlayer entityplayer = this.mc.world.getPlayerEntityByUUID(gameprofile.getId());
boolean flag1 = entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.CAPE) && ("Dinnerbone".equals(gameprofile.getName()) || "Grumm".equals(gameprofile.getName()));
this.mc.getTextureManager().bindTexture(networkplayerinfo1.getLocationSkin());
int l2 = 8 + (flag1 ? 8 : 0);
int i3 = 8 * (flag1 ? -1 : 1);
Gui.drawScaledCustomSizeModalRect(j2, k2, 8.0F, (float)l2, 8, i3, 8, 8, 64.0F, 64.0F);
if (entityplayer != null && entityplayer.isWearing(EnumPlayerModelParts.HAT))
{
int j3 = 8 + (flag1 ? 8 : 0);
int k3 = 8 * (flag1 ? -1 : 1);
Gui.drawScaledCustomSizeModalRect(j2, k2, 40.0F, (float)j3, 8, k3, 8, 8, 64.0F, 64.0F);
}
j2 += 9;
}
String s4 = this.getPlayerName(networkplayerinfo1);
if (networkplayerinfo1.getGameType() == GameType.SPECTATOR)
{
this.mc.fontRenderer.drawStringWithShadow(TextFormatting.ITALIC + s4, (float)j2, (float)k2, -1862270977);
}
else
{
this.mc.fontRenderer.drawStringWithShadow(s4, (float)j2, (float)k2, -1);
}
if (scoreObjectiveIn != null && networkplayerinfo1.getGameType() != GameType.SPECTATOR)
{
int k5 = j2 + i + 1;
int l5 = k5 + l;
if (l5 - k5 > 5)
{
this.drawScoreboardValues(scoreObjectiveIn, k2, gameprofile.getName(), k5, l5, networkplayerinfo1);
}
}
this.drawPing(i1, j2 - (flag ? 9 : 0), k2, networkplayerinfo1);
}
}
if (list2 != null)
{
k1 = k1 + i4 * 9 + 1;
drawRect(width / 2 - l1 / 2 - 1, k1 - 1, width / 2 + l1 / 2 + 1, k1 + list2.size() * this.mc.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE);
for (String s3 : list2)
{
int j5 = this.mc.fontRenderer.getStringWidth(s3);
this.mc.fontRenderer.drawStringWithShadow(s3, (float)(width / 2 - j5 / 2), (float)k1, -1);
k1 += this.mc.fontRenderer.FONT_HEIGHT;
}
}
}
protected void drawPing(int p_175245_1_, int p_175245_2_, int p_175245_3_, NetworkPlayerInfo networkPlayerInfoIn)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(ICONS);
int i = 0;
int j;
if (networkPlayerInfoIn.getResponseTime() < 0)
{
j = 5;
}
else if (networkPlayerInfoIn.getResponseTime() < 150)
{
j = 0;
}
else if (networkPlayerInfoIn.getResponseTime() < 300)
{
j = 1;
}
else if (networkPlayerInfoIn.getResponseTime() < 600)
{
j = 2;
}
else if (networkPlayerInfoIn.getResponseTime() < 1000)
{
j = 3;
}
else
{
j = 4;
}
this.zLevel += 100.0F;
this.drawTexturedModalRect(p_175245_2_ + p_175245_1_ - 11, p_175245_3_, 0, 176 + j * 8, 10, 8);
this.zLevel -= 100.0F;
}
private void drawScoreboardValues(ScoreObjective objective, int p_175247_2_, String name, int p_175247_4_, int p_175247_5_, NetworkPlayerInfo info)
{
int i = objective.getScoreboard().getOrCreateScore(name, objective).getScorePoints();
if (objective.getRenderType() == IScoreCriteria.EnumRenderType.HEARTS)
{
this.mc.getTextureManager().bindTexture(ICONS);
if (this.lastTimeOpened == info.getRenderVisibilityId())
{
if (i < info.getLastHealth())
{
info.setLastHealthTime(Minecraft.getSystemTime());
info.setHealthBlinkTime((long)(this.guiIngame.getUpdateCounter() + 20));
}
else if (i > info.getLastHealth())
{
info.setLastHealthTime(Minecraft.getSystemTime());
info.setHealthBlinkTime((long)(this.guiIngame.getUpdateCounter() + 10));
}
}
if (Minecraft.getSystemTime() - info.getLastHealthTime() > 1000L || this.lastTimeOpened != info.getRenderVisibilityId())
{
info.setLastHealth(i);
info.setDisplayHealth(i);
info.setLastHealthTime(Minecraft.getSystemTime());
}
info.setRenderVisibilityId(this.lastTimeOpened);
info.setLastHealth(i);
int j = MathHelper.ceil((float)Math.max(i, info.getDisplayHealth()) / 2.0F);
int k = Math.max(MathHelper.ceil((float)(i / 2)), Math.max(MathHelper.ceil((float)(info.getDisplayHealth() / 2)), 10));
boolean flag = info.getHealthBlinkTime() > (long)this.guiIngame.getUpdateCounter() && (info.getHealthBlinkTime() - (long)this.guiIngame.getUpdateCounter()) / 3L % 2L == 1L;
if (j > 0)
{
float f = Math.min((float)(p_175247_5_ - p_175247_4_ - 4) / (float)k, 9.0F);
if (f > 3.0F)
{
for (int l = j; l < k; ++l)
{
this.drawTexturedModalRect((float)p_175247_4_ + (float)l * f, (float)p_175247_2_, flag ? 25 : 16, 0, 9, 9);
}
for (int j1 = 0; j1 < j; ++j1)
{
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, flag ? 25 : 16, 0, 9, 9);
if (flag)
{
if (j1 * 2 + 1 < info.getDisplayHealth())
{
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, 70, 0, 9, 9);
}
if (j1 * 2 + 1 == info.getDisplayHealth())
{
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, 79, 0, 9, 9);
}
}
if (j1 * 2 + 1 < i)
{
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, j1 >= 10 ? 160 : 52, 0, 9, 9);
}
if (j1 * 2 + 1 == i)
{
this.drawTexturedModalRect((float)p_175247_4_ + (float)j1 * f, (float)p_175247_2_, j1 >= 10 ? 169 : 61, 0, 9, 9);
}
}
}
else
{
float f1 = MathHelper.clamp((float)i / 20.0F, 0.0F, 1.0F);
int i1 = (int)((1.0F - f1) * 255.0F) << 16 | (int)(f1 * 255.0F) << 8;
String s = "" + (float)i / 2.0F;
if (p_175247_5_ - this.mc.fontRenderer.getStringWidth(s + "hp") >= p_175247_4_)
{
s = s + "hp";
}
this.mc.fontRenderer.drawStringWithShadow(s, (float)((p_175247_5_ + p_175247_4_) / 2 - this.mc.fontRenderer.getStringWidth(s) / 2), (float)p_175247_2_, i1);
}
}
}
else
{
String s1 = TextFormatting.YELLOW + "" + i;
this.mc.fontRenderer.drawStringWithShadow(s1, (float)(p_175247_5_ - this.mc.fontRenderer.getStringWidth(s1)), (float)p_175247_2_, 16777215);
}
}
public void setFooter(@Nullable ITextComponent footerIn)
{
this.footer = footerIn;
}
public void setHeader(@Nullable ITextComponent headerIn)
{
this.header = headerIn;
}
public void resetFooterHeader()
{
this.header = null;
this.footer = null;
}
@SideOnly(Side.CLIENT)
static class PlayerComparator implements Comparator<NetworkPlayerInfo>
{
private PlayerComparator()
{
}
public int compare(NetworkPlayerInfo p_compare_1_, NetworkPlayerInfo p_compare_2_)
{
ScorePlayerTeam scoreplayerteam = p_compare_1_.getPlayerTeam();
ScorePlayerTeam scoreplayerteam1 = p_compare_2_.getPlayerTeam();
return ComparisonChain.start().compareTrueFirst(p_compare_1_.getGameType() != GameType.SPECTATOR, p_compare_2_.getGameType() != GameType.SPECTATOR).compare(scoreplayerteam != null ? scoreplayerteam.getName() : "", scoreplayerteam1 != null ? scoreplayerteam1.getName() : "").compare(p_compare_1_.getGameProfile().getName(), p_compare_2_.getGameProfile().getName()).result();
}
}
}

View File

@@ -0,0 +1,231 @@
package net.minecraft.client.gui;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerRepair;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiRepair extends GuiContainer implements IContainerListener
{
private static final ResourceLocation ANVIL_RESOURCE = new ResourceLocation("textures/gui/container/anvil.png");
private final ContainerRepair anvil;
private GuiTextField nameField;
private final InventoryPlayer playerInventory;
public GuiRepair(InventoryPlayer inventoryIn, World worldIn)
{
super(new ContainerRepair(inventoryIn, worldIn, Minecraft.getMinecraft().player));
this.playerInventory = inventoryIn;
this.anvil = (ContainerRepair)this.inventorySlots;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
Keyboard.enableRepeatEvents(true);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.nameField = new GuiTextField(0, this.fontRenderer, i + 62, j + 24, 103, 12);
this.nameField.setTextColor(-1);
this.nameField.setDisabledTextColour(-1);
this.nameField.setEnableBackgroundDrawing(false);
this.nameField.setMaxStringLength(35);
this.inventorySlots.removeListener(this);
this.inventorySlots.addListener(this);
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
super.onGuiClosed();
Keyboard.enableRepeatEvents(false);
this.inventorySlots.removeListener(this);
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
GlStateManager.disableLighting();
GlStateManager.disableBlend();
this.fontRenderer.drawString(I18n.format("container.repair"), 60, 6, 4210752);
if (this.anvil.maximumCost > 0)
{
int i = 8453920;
boolean flag = true;
String s = I18n.format("container.repair.cost", this.anvil.maximumCost);
if (this.anvil.maximumCost >= 40 && !this.mc.player.capabilities.isCreativeMode)
{
s = I18n.format("container.repair.expensive");
i = 16736352;
}
else if (!this.anvil.getSlot(2).getHasStack())
{
flag = false;
}
else if (!this.anvil.getSlot(2).canTakeStack(this.playerInventory.player))
{
i = 16736352;
}
if (flag)
{
int j = -16777216 | (i & 16579836) >> 2 | i & -16777216;
int k = this.xSize - 8 - this.fontRenderer.getStringWidth(s);
int l = 67;
if (this.fontRenderer.getUnicodeFlag())
{
drawRect(k - 3, 65, this.xSize - 7, 77, -16777216);
drawRect(k - 2, 66, this.xSize - 8, 76, -12895429);
}
else
{
this.fontRenderer.drawString(s, k, 68, j);
this.fontRenderer.drawString(s, k + 1, 67, j);
this.fontRenderer.drawString(s, k + 1, 68, j);
}
this.fontRenderer.drawString(s, k, 67, i);
}
}
GlStateManager.enableLighting();
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (this.nameField.textboxKeyTyped(typedChar, keyCode))
{
this.renameItem();
}
else
{
super.keyTyped(typedChar, keyCode);
}
}
private void renameItem()
{
String s = this.nameField.getText();
Slot slot = this.anvil.getSlot(0);
if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && s.equals(slot.getStack().getDisplayName()))
{
s = "";
}
this.anvil.updateItemName(s);
this.mc.player.connection.sendPacket(new CPacketCustomPayload("MC|ItemName", (new PacketBuffer(Unpooled.buffer())).writeString(s)));
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.nameField.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
GlStateManager.disableLighting();
GlStateManager.disableBlend();
this.nameField.drawTextBox();
}
/**
* Draws the background layer of this container (behind the items).
*/
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(ANVIL_RESOURCE);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
this.drawTexturedModalRect(i + 59, j + 20, 0, this.ySize + (this.anvil.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
if ((this.anvil.getSlot(0).getHasStack() || this.anvil.getSlot(1).getHasStack()) && !this.anvil.getSlot(2).getHasStack())
{
this.drawTexturedModalRect(i + 99, j + 45, this.xSize, 0, 28, 21);
}
}
/**
* update the crafting window inventory with the items in the list
*/
public void sendAllContents(Container containerToSend, NonNullList<ItemStack> itemsList)
{
this.sendSlotContents(containerToSend, 0, containerToSend.getSlot(0).getStack());
}
/**
* Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
* contents of that slot.
*/
public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack)
{
if (slotInd == 0)
{
this.nameField.setText(stack.isEmpty() ? "" : stack.getDisplayName());
this.nameField.setEnabled(!stack.isEmpty());
if (!stack.isEmpty())
{
this.renameItem();
}
}
}
/**
* Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress,
* and enchanting level. Normally the first int identifies which variable to update, and the second contains the new
* value. Both are truncated to shorts in non-local SMP.
*/
public void sendWindowProperty(Container containerIn, int varToUpdate, int newValue)
{
}
public void sendAllWindowProperties(Container containerIn, IInventory inventory)
{
}
}

View File

@@ -0,0 +1,22 @@
package net.minecraft.client.gui;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.ResourcePackListEntry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiResourcePackAvailable extends GuiResourcePackList
{
public GuiResourcePackAvailable(Minecraft mcIn, int p_i45054_2_, int p_i45054_3_, List<ResourcePackListEntry> p_i45054_4_)
{
super(mcIn, p_i45054_2_, p_i45054_3_, p_i45054_4_);
}
protected String getListHeader()
{
return I18n.format("resourcePack.available.title");
}
}

View File

@@ -0,0 +1,67 @@
package net.minecraft.client.gui;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.ResourcePackListEntry;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class GuiResourcePackList extends GuiListExtended
{
protected final Minecraft mc;
protected final List<ResourcePackListEntry> resourcePackEntries;
public GuiResourcePackList(Minecraft mcIn, int p_i45055_2_, int p_i45055_3_, List<ResourcePackListEntry> p_i45055_4_)
{
super(mcIn, p_i45055_2_, p_i45055_3_, 32, p_i45055_3_ - 55 + 4, 36);
this.mc = mcIn;
this.resourcePackEntries = p_i45055_4_;
this.centerListVertically = false;
this.setHasListHeader(true, (int)((float)mcIn.fontRenderer.FONT_HEIGHT * 1.5F));
}
/**
* Handles drawing a list's header row.
*/
protected void drawListHeader(int insideLeft, int insideTop, Tessellator tessellatorIn)
{
String s = TextFormatting.UNDERLINE + "" + TextFormatting.BOLD + this.getListHeader();
this.mc.fontRenderer.drawString(s, insideLeft + this.width / 2 - this.mc.fontRenderer.getStringWidth(s) / 2, Math.min(this.top + 3, insideTop), 16777215);
}
protected abstract String getListHeader();
public List<ResourcePackListEntry> getList()
{
return this.resourcePackEntries;
}
protected int getSize()
{
return this.getList().size();
}
/**
* Gets the IGuiListEntry object for the given index
*/
public ResourcePackListEntry getListEntry(int index)
{
return (ResourcePackListEntry)this.getList().get(index);
}
/**
* Gets the width of the list
*/
public int getListWidth()
{
return this.width;
}
protected int getScrollBarX()
{
return this.right - 6;
}
}

View File

@@ -0,0 +1,22 @@
package net.minecraft.client.gui;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.ResourcePackListEntry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiResourcePackSelected extends GuiResourcePackList
{
public GuiResourcePackSelected(Minecraft mcIn, int p_i45056_2_, int p_i45056_3_, List<ResourcePackListEntry> p_i45056_4_)
{
super(mcIn, p_i45056_2_, p_i45056_3_, p_i45056_4_);
}
protected String getListHeader()
{
return I18n.format("resourcePack.selected.title");
}
}

View File

@@ -0,0 +1,795 @@
package net.minecraft.client.gui;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.awt.Toolkit;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@SideOnly(Side.CLIENT)
public abstract class GuiScreen extends Gui implements GuiYesNoCallback
{
private static final Logger LOGGER = LogManager.getLogger();
private static final Set<String> PROTOCOLS = Sets.newHashSet("http", "https");
private static final Splitter NEWLINE_SPLITTER = Splitter.on('\n');
/** Reference to the Minecraft object. */
public Minecraft mc;
/** Holds a instance of RenderItem, used to draw the achievement icons on screen (is based on ItemStack) */
protected RenderItem itemRender;
/** The width of the screen object. */
public int width;
/** The height of the screen object. */
public int height;
/** A list of all the buttons in this container. */
protected List<GuiButton> buttonList = Lists.<GuiButton>newArrayList();
/** A list of all the labels in this container. */
protected List<GuiLabel> labelList = Lists.<GuiLabel>newArrayList();
public boolean allowUserInput;
/** The FontRenderer used by GuiScreen */
protected FontRenderer fontRenderer;
/** The button that was just pressed. */
protected GuiButton selectedButton;
private int eventButton;
private long lastMouseEvent;
/** Tracks the number of fingers currently on the screen. Prevents subsequent fingers registering as clicks. */
private int touchValue;
private URI clickedLinkURI;
private boolean focused;
protected boolean keyHandled, mouseHandled; // Forge: allow canceling key and mouse Post events from handleMouseInput and handleKeyboardInput
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
for (int i = 0; i < this.buttonList.size(); ++i)
{
((GuiButton)this.buttonList.get(i)).drawButton(this.mc, mouseX, mouseY, partialTicks);
}
for (int j = 0; j < this.labelList.size(); ++j)
{
((GuiLabel)this.labelList.get(j)).drawLabel(this.mc, mouseX, mouseY);
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (keyCode == 1)
{
this.mc.displayGuiScreen((GuiScreen)null);
if (this.mc.currentScreen == null)
{
this.mc.setIngameFocus();
}
}
}
/**
* Adds a control to this GUI's button list. Any type that subclasses button may be added (particularly, GuiSlider,
* but not text fields).
*
* @return The control passed in.
*
* @param buttonIn The control to add
*/
protected <T extends GuiButton> T addButton(T buttonIn)
{
this.buttonList.add(buttonIn);
return buttonIn;
}
/**
* Returns a string stored in the system clipboard.
*/
public static String getClipboardString()
{
try
{
Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents((Object)null);
if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor))
{
return (String)transferable.getTransferData(DataFlavor.stringFlavor);
}
}
catch (Exception var1)
{
;
}
return "";
}
/**
* Stores the given string in the system clipboard
*/
public static void setClipboardString(String copyText)
{
if (!StringUtils.isEmpty(copyText))
{
try
{
StringSelection stringselection = new StringSelection(copyText);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringselection, (ClipboardOwner)null);
}
catch (Exception var2)
{
;
}
}
}
protected void renderToolTip(ItemStack stack, int x, int y)
{
FontRenderer font = stack.getItem().getFontRenderer(stack);
net.minecraftforge.fml.client.config.GuiUtils.preItemToolTip(stack);
this.drawHoveringText(this.getItemToolTip(stack), x, y, (font == null ? fontRenderer : font));
net.minecraftforge.fml.client.config.GuiUtils.postItemToolTip();
}
public List<String> getItemToolTip(ItemStack p_191927_1_)
{
List<String> list = p_191927_1_.getTooltip(this.mc.player, this.mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL);
for (int i = 0; i < list.size(); ++i)
{
if (i == 0)
{
list.set(i, p_191927_1_.getRarity().rarityColor + (String)list.get(i));
}
else
{
list.set(i, TextFormatting.GRAY + (String)list.get(i));
}
}
return list;
}
/**
* Draws the given text as a tooltip.
*/
public void drawHoveringText(String text, int x, int y)
{
this.drawHoveringText(Arrays.asList(text), x, y);
}
public void setFocused(boolean hasFocusedControlIn)
{
this.focused = hasFocusedControlIn;
}
public boolean isFocused()
{
return this.focused;
}
/**
* Draws a List of strings as a tooltip. Every entry is drawn on a seperate line.
*/
public void drawHoveringText(List<String> textLines, int x, int y)
{
drawHoveringText(textLines, x, y, fontRenderer);
}
protected void drawHoveringText(List<String> textLines, int x, int y, FontRenderer font)
{
net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText(textLines, x, y, width, height, -1, font);
if (false && !textLines.isEmpty())
{
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
int i = 0;
for (String s : textLines)
{
int j = this.fontRenderer.getStringWidth(s);
if (j > i)
{
i = j;
}
}
int l1 = x + 12;
int i2 = y - 12;
int k = 8;
if (textLines.size() > 1)
{
k += 2 + (textLines.size() - 1) * 10;
}
if (l1 + i > this.width)
{
l1 -= 28 + i;
}
if (i2 + k + 6 > this.height)
{
i2 = this.height - k - 6;
}
this.zLevel = 300.0F;
this.itemRender.zLevel = 300.0F;
int l = -267386864;
this.drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, -267386864, -267386864);
this.drawGradientRect(l1 - 3, i2 + k + 3, l1 + i + 3, i2 + k + 4, -267386864, -267386864);
this.drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 + k + 3, -267386864, -267386864);
this.drawGradientRect(l1 - 4, i2 - 3, l1 - 3, i2 + k + 3, -267386864, -267386864);
this.drawGradientRect(l1 + i + 3, i2 - 3, l1 + i + 4, i2 + k + 3, -267386864, -267386864);
int i1 = 1347420415;
int j1 = 1344798847;
this.drawGradientRect(l1 - 3, i2 - 3 + 1, l1 - 3 + 1, i2 + k + 3 - 1, 1347420415, 1344798847);
this.drawGradientRect(l1 + i + 2, i2 - 3 + 1, l1 + i + 3, i2 + k + 3 - 1, 1347420415, 1344798847);
this.drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 - 3 + 1, 1347420415, 1347420415);
this.drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, 1344798847, 1344798847);
for (int k1 = 0; k1 < textLines.size(); ++k1)
{
String s1 = textLines.get(k1);
this.fontRenderer.drawStringWithShadow(s1, (float)l1, (float)i2, -1);
if (k1 == 0)
{
i2 += 2;
}
i2 += 10;
}
this.zLevel = 0.0F;
this.itemRender.zLevel = 0.0F;
GlStateManager.enableLighting();
GlStateManager.enableDepth();
RenderHelper.enableStandardItemLighting();
GlStateManager.enableRescaleNormal();
}
}
/**
* Draws the hover event specified by the given chat component
*/
protected void handleComponentHover(ITextComponent component, int x, int y)
{
if (component != null && component.getStyle().getHoverEvent() != null)
{
HoverEvent hoverevent = component.getStyle().getHoverEvent();
if (hoverevent.getAction() == HoverEvent.Action.SHOW_ITEM)
{
ItemStack itemstack = ItemStack.EMPTY;
try
{
NBTBase nbtbase = JsonToNBT.getTagFromJson(hoverevent.getValue().getUnformattedText());
if (nbtbase instanceof NBTTagCompound)
{
itemstack = new ItemStack((NBTTagCompound)nbtbase);
}
}
catch (NBTException var9)
{
;
}
if (itemstack.isEmpty())
{
this.drawHoveringText(TextFormatting.RED + "Invalid Item!", x, y);
}
else
{
this.renderToolTip(itemstack, x, y);
}
}
else if (hoverevent.getAction() == HoverEvent.Action.SHOW_ENTITY)
{
if (this.mc.gameSettings.advancedItemTooltips)
{
try
{
NBTTagCompound nbttagcompound = JsonToNBT.getTagFromJson(hoverevent.getValue().getUnformattedText());
List<String> list = Lists.<String>newArrayList();
list.add(nbttagcompound.getString("name"));
if (nbttagcompound.hasKey("type", 8))
{
String s = nbttagcompound.getString("type");
list.add("Type: " + s);
}
list.add(nbttagcompound.getString("id"));
this.drawHoveringText(list, x, y);
}
catch (NBTException var8)
{
this.drawHoveringText(TextFormatting.RED + "Invalid Entity!", x, y);
}
}
}
else if (hoverevent.getAction() == HoverEvent.Action.SHOW_TEXT)
{
this.drawHoveringText(this.mc.fontRenderer.listFormattedStringToWidth(hoverevent.getValue().getFormattedText(), Math.max(this.width / 2, 200)), x, y);
}
GlStateManager.disableLighting();
}
}
/**
* Sets the text of the chat
*/
protected void setText(String newChatText, boolean shouldOverwrite)
{
}
/**
* Executes the click event specified by the given chat component
*/
public boolean handleComponentClick(ITextComponent component)
{
if (component == null)
{
return false;
}
else
{
ClickEvent clickevent = component.getStyle().getClickEvent();
if (isShiftKeyDown())
{
if (component.getStyle().getInsertion() != null)
{
this.setText(component.getStyle().getInsertion(), false);
}
}
else if (clickevent != null)
{
if (clickevent.getAction() == ClickEvent.Action.OPEN_URL)
{
if (!this.mc.gameSettings.chatLinks)
{
return false;
}
try
{
URI uri = new URI(clickevent.getValue());
String s = uri.getScheme();
if (s == null)
{
throw new URISyntaxException(clickevent.getValue(), "Missing protocol");
}
if (!PROTOCOLS.contains(s.toLowerCase(Locale.ROOT)))
{
throw new URISyntaxException(clickevent.getValue(), "Unsupported protocol: " + s.toLowerCase(Locale.ROOT));
}
if (this.mc.gameSettings.chatLinksPrompt)
{
this.clickedLinkURI = uri;
this.mc.displayGuiScreen(new GuiConfirmOpenLink(this, clickevent.getValue(), 31102009, false));
}
else
{
this.openWebLink(uri);
}
}
catch (URISyntaxException urisyntaxexception)
{
LOGGER.error("Can't open url for {}", clickevent, urisyntaxexception);
}
}
else if (clickevent.getAction() == ClickEvent.Action.OPEN_FILE)
{
URI uri1 = (new File(clickevent.getValue())).toURI();
this.openWebLink(uri1);
}
else if (clickevent.getAction() == ClickEvent.Action.SUGGEST_COMMAND)
{
this.setText(clickevent.getValue(), true);
}
else if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
{
this.sendChatMessage(clickevent.getValue(), false);
}
else
{
LOGGER.error("Don't know how to handle {}", (Object)clickevent);
}
return true;
}
return false;
}
}
/**
* Used to add chat messages to the client's GuiChat.
*/
public void sendChatMessage(String msg)
{
this.sendChatMessage(msg, true);
}
public void sendChatMessage(String msg, boolean addToChat)
{
msg = net.minecraftforge.event.ForgeEventFactory.onClientSendMessage(msg);
if (msg.isEmpty()) return;
if (addToChat)
{
this.mc.ingameGUI.getChatGUI().addToSentMessages(msg);
}
if (net.minecraftforge.client.ClientCommandHandler.instance.executeCommand(mc.player, msg) != 0) return;
this.mc.player.sendChatMessage(msg);
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
if (mouseButton == 0)
{
for (int i = 0; i < this.buttonList.size(); ++i)
{
GuiButton guibutton = this.buttonList.get(i);
if (guibutton.mousePressed(this.mc, mouseX, mouseY))
{
net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Pre event = new net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList);
if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event))
break;
guibutton = event.getButton();
this.selectedButton = guibutton;
guibutton.playPressSound(this.mc.getSoundHandler());
this.actionPerformed(guibutton);
if (this.equals(this.mc.currentScreen))
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Post(this, event.getButton(), this.buttonList));
}
}
}
}
/**
* Called when a mouse button is released.
*/
protected void mouseReleased(int mouseX, int mouseY, int state)
{
if (this.selectedButton != null && state == 0)
{
this.selectedButton.mouseReleased(mouseX, mouseY);
this.selectedButton = null;
}
}
/**
* Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY,
* lastButtonClicked & timeSinceMouseClick.
*/
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick)
{
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
}
/**
* Causes the screen to lay out its subcomponents again. This is the equivalent of the Java call
* Container.validate()
*/
public void setWorldAndResolution(Minecraft mc, int width, int height)
{
this.mc = mc;
this.itemRender = mc.getRenderItem();
this.fontRenderer = mc.fontRenderer;
this.width = width;
this.height = height;
if (!net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent.Pre(this, this.buttonList)))
{
this.buttonList.clear();
this.initGui();
}
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent.Post(this, this.buttonList));
}
/**
* Set the gui to the specified width and height
*/
public void setGuiSize(int w, int h)
{
this.width = w;
this.height = h;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
}
/**
* Delegates mouse and keyboard input.
*/
public void handleInput() throws IOException
{
if (Mouse.isCreated())
{
while (Mouse.next())
{
this.mouseHandled = false;
if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.MouseInputEvent.Pre(this))) continue;
this.handleMouseInput();
if (this.equals(this.mc.currentScreen) && !this.mouseHandled) net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.MouseInputEvent.Post(this));
}
}
if (Keyboard.isCreated())
{
while (Keyboard.next())
{
this.keyHandled = false;
if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent.Pre(this))) continue;
this.handleKeyboardInput();
if (this.equals(this.mc.currentScreen) && !this.keyHandled) net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent.Post(this));
}
}
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
int k = Mouse.getEventButton();
if (Mouse.getEventButtonState())
{
if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
{
return;
}
this.eventButton = k;
this.lastMouseEvent = Minecraft.getSystemTime();
this.mouseClicked(i, j, this.eventButton);
}
else if (k != -1)
{
if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
{
return;
}
this.eventButton = -1;
this.mouseReleased(i, j, k);
}
else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
{
long l = Minecraft.getSystemTime() - this.lastMouseEvent;
this.mouseClickMove(i, j, this.eventButton, l);
}
}
/**
* Handles keyboard input.
*/
public void handleKeyboardInput() throws IOException
{
char c0 = Keyboard.getEventCharacter();
if (Keyboard.getEventKey() == 0 && c0 >= ' ' || Keyboard.getEventKeyState())
{
this.keyTyped(c0, Keyboard.getEventKey());
}
this.mc.dispatchKeypresses();
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
}
/**
* Draws either a gradient over the background screen (when it exists) or a flat gradient over background.png
*/
public void drawDefaultBackground()
{
this.drawWorldBackground(0);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.BackgroundDrawnEvent(this));
}
public void drawWorldBackground(int tint)
{
if (this.mc.world != null)
{
this.drawGradientRect(0, 0, this.width, this.height, -1072689136, -804253680);
}
else
{
this.drawBackground(tint);
}
}
/**
* Draws the background (i is always 0 as of 1.2.2)
*/
public void drawBackground(int tint)
{
GlStateManager.disableLighting();
GlStateManager.disableFog();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
this.mc.getTextureManager().bindTexture(OPTIONS_BACKGROUND);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos(0.0D, (double)this.height, 0.0D).tex(0.0D, (double)((float)this.height / 32.0F + (float)tint)).color(64, 64, 64, 255).endVertex();
bufferbuilder.pos((double)this.width, (double)this.height, 0.0D).tex((double)((float)this.width / 32.0F), (double)((float)this.height / 32.0F + (float)tint)).color(64, 64, 64, 255).endVertex();
bufferbuilder.pos((double)this.width, 0.0D, 0.0D).tex((double)((float)this.width / 32.0F), (double)tint).color(64, 64, 64, 255).endVertex();
bufferbuilder.pos(0.0D, 0.0D, 0.0D).tex(0.0D, (double)tint).color(64, 64, 64, 255).endVertex();
tessellator.draw();
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
public boolean doesGuiPauseGame()
{
return true;
}
public void confirmClicked(boolean result, int id)
{
if (id == 31102009)
{
if (result)
{
this.openWebLink(this.clickedLinkURI);
}
this.clickedLinkURI = null;
this.mc.displayGuiScreen(this);
}
}
private void openWebLink(URI url)
{
try
{
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop").invoke((Object)null);
oclass.getMethod("browse", URI.class).invoke(object, url);
}
catch (Throwable throwable1)
{
Throwable throwable = throwable1.getCause();
LOGGER.error("Couldn't open link: {}", (Object)(throwable == null ? "<UNKNOWN>" : throwable.getMessage()));
}
}
/**
* Returns true if either windows ctrl key is down or if either mac meta key is down
*/
public static boolean isCtrlKeyDown()
{
if (Minecraft.IS_RUNNING_ON_MAC)
{
return Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220);
}
else
{
return Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157);
}
}
/**
* Returns true if either shift key is down
*/
public static boolean isShiftKeyDown()
{
return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54);
}
/**
* Returns true if either alt key is down
*/
public static boolean isAltKeyDown()
{
return Keyboard.isKeyDown(56) || Keyboard.isKeyDown(184);
}
public static boolean isKeyComboCtrlX(int keyID)
{
return keyID == 45 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
}
public static boolean isKeyComboCtrlV(int keyID)
{
return keyID == 47 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
}
public static boolean isKeyComboCtrlC(int keyID)
{
return keyID == 46 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
}
public static boolean isKeyComboCtrlA(int keyID)
{
return keyID == 30 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown();
}
/**
* Called when the GUI is resized in order to update the world and the resolution
*/
public void onResize(Minecraft mcIn, int w, int h)
{
this.setWorldAndResolution(mcIn, w, h);
}
}

View File

@@ -0,0 +1,169 @@
package net.minecraft.client.gui;
import com.google.common.base.Predicate;
import java.io.IOException;
import java.net.IDN;
import javax.annotation.Nullable;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.StringUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiScreenAddServer extends GuiScreen
{
private final GuiScreen parentScreen;
private final ServerData serverData;
private GuiTextField serverIPField;
private GuiTextField serverNameField;
private GuiButton serverResourcePacks;
private final Predicate<String> addressFilter = new Predicate<String>()
{
public boolean apply(@Nullable String p_apply_1_)
{
if (StringUtils.isNullOrEmpty(p_apply_1_))
{
return true;
}
else
{
String[] astring = p_apply_1_.split(":");
if (astring.length == 0)
{
return true;
}
else
{
try
{
String s = IDN.toASCII(astring[0]);
return true;
}
catch (IllegalArgumentException var4)
{
return false;
}
}
}
}
};
public GuiScreenAddServer(GuiScreen parentScreenIn, ServerData serverDataIn)
{
this.parentScreen = parentScreenIn;
this.serverData = serverDataIn;
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
this.serverNameField.updateCursorCounter();
this.serverIPField.updateCursorCounter();
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 18, I18n.format("addServer.add")));
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 18, I18n.format("gui.cancel")));
this.serverResourcePacks = this.addButton(new GuiButton(2, this.width / 2 - 100, this.height / 4 + 72, I18n.format("addServer.resourcePack") + ": " + this.serverData.getResourceMode().getMotd().getFormattedText()));
this.serverNameField = new GuiTextField(0, this.fontRenderer, this.width / 2 - 100, 66, 200, 20);
this.serverNameField.setFocused(true);
this.serverNameField.setText(this.serverData.serverName);
this.serverIPField = new GuiTextField(1, this.fontRenderer, this.width / 2 - 100, 106, 200, 20);
this.serverIPField.setMaxStringLength(128);
this.serverIPField.setText(this.serverData.serverIP);
this.serverIPField.setValidator(this.addressFilter);
(this.buttonList.get(0)).enabled = !this.serverIPField.getText().isEmpty() && this.serverIPField.getText().split(":").length > 0 && !this.serverNameField.getText().isEmpty();
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 2)
{
this.serverData.setResourceMode(ServerData.ServerResourceMode.values()[(this.serverData.getResourceMode().ordinal() + 1) % ServerData.ServerResourceMode.values().length]);
this.serverResourcePacks.displayString = I18n.format("addServer.resourcePack") + ": " + this.serverData.getResourceMode().getMotd().getFormattedText();
}
else if (button.id == 1)
{
this.parentScreen.confirmClicked(false, 0);
}
else if (button.id == 0)
{
this.serverData.serverName = this.serverNameField.getText();
this.serverData.serverIP = this.serverIPField.getText();
this.parentScreen.confirmClicked(true, 0);
}
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
this.serverNameField.textboxKeyTyped(typedChar, keyCode);
this.serverIPField.textboxKeyTyped(typedChar, keyCode);
if (keyCode == 15)
{
this.serverNameField.setFocused(!this.serverNameField.isFocused());
this.serverIPField.setFocused(!this.serverIPField.isFocused());
}
if (keyCode == 28 || keyCode == 156)
{
this.actionPerformed(this.buttonList.get(0));
}
(this.buttonList.get(0)).enabled = !this.serverIPField.getText().isEmpty() && this.serverIPField.getText().split(":").length > 0 && !this.serverNameField.getText().isEmpty();
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.serverIPField.mouseClicked(mouseX, mouseY, mouseButton);
this.serverNameField.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, I18n.format("addServer.title"), this.width / 2, 17, 16777215);
this.drawString(this.fontRenderer, I18n.format("addServer.enterName"), this.width / 2 - 100, 53, 10526880);
this.drawString(this.fontRenderer, I18n.format("addServer.enterIp"), this.width / 2 - 100, 94, 10526880);
this.serverNameField.drawTextBox();
this.serverIPField.drawTextBox();
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,657 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import com.google.gson.JsonParseException;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemWrittenBook;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiScreenBook extends GuiScreen
{
private static final Logger LOGGER = LogManager.getLogger();
private static final ResourceLocation BOOK_GUI_TEXTURES = new ResourceLocation("textures/gui/book.png");
/** The player editing the book */
private final EntityPlayer editingPlayer;
private final ItemStack book;
/** Whether the book is signed or can still be edited */
private final boolean bookIsUnsigned;
/** Whether the book's title or contents has been modified since being opened */
private boolean bookIsModified;
/** Determines if the signing screen is open */
private boolean bookGettingSigned;
/** Update ticks since the gui was opened */
private int updateCount;
private final int bookImageWidth = 192;
private final int bookImageHeight = 192;
private int bookTotalPages = 1;
private int currPage;
private NBTTagList bookPages;
private String bookTitle = "";
private List<ITextComponent> cachedComponents;
private int cachedPage = -1;
private GuiScreenBook.NextPageButton buttonNextPage;
private GuiScreenBook.NextPageButton buttonPreviousPage;
private GuiButton buttonDone;
/** The GuiButton to sign this book. */
private GuiButton buttonSign;
private GuiButton buttonFinalize;
private GuiButton buttonCancel;
public GuiScreenBook(EntityPlayer player, ItemStack book, boolean isUnsigned)
{
this.editingPlayer = player;
this.book = book;
this.bookIsUnsigned = isUnsigned;
if (book.hasTagCompound())
{
NBTTagCompound nbttagcompound = book.getTagCompound();
this.bookPages = nbttagcompound.getTagList("pages", 8).copy();
this.bookTotalPages = this.bookPages.tagCount();
if (this.bookTotalPages < 1)
{
this.bookPages.appendTag(new NBTTagString("")); // Forge: fix MC-1685
this.bookTotalPages = 1;
}
}
if (this.bookPages == null && isUnsigned)
{
this.bookPages = new NBTTagList();
this.bookPages.appendTag(new NBTTagString(""));
this.bookTotalPages = 1;
}
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
super.updateScreen();
++this.updateCount;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
Keyboard.enableRepeatEvents(true);
if (this.bookIsUnsigned)
{
this.buttonSign = this.addButton(new GuiButton(3, this.width / 2 - 100, 196, 98, 20, I18n.format("book.signButton")));
this.buttonDone = this.addButton(new GuiButton(0, this.width / 2 + 2, 196, 98, 20, I18n.format("gui.done")));
this.buttonFinalize = this.addButton(new GuiButton(5, this.width / 2 - 100, 196, 98, 20, I18n.format("book.finalizeButton")));
this.buttonCancel = this.addButton(new GuiButton(4, this.width / 2 + 2, 196, 98, 20, I18n.format("gui.cancel")));
}
else
{
this.buttonDone = this.addButton(new GuiButton(0, this.width / 2 - 100, 196, 200, 20, I18n.format("gui.done")));
}
int i = (this.width - 192) / 2;
int j = 2;
this.buttonNextPage = (GuiScreenBook.NextPageButton)this.addButton(new GuiScreenBook.NextPageButton(1, i + 120, 156, true));
this.buttonPreviousPage = (GuiScreenBook.NextPageButton)this.addButton(new GuiScreenBook.NextPageButton(2, i + 38, 156, false));
this.updateButtons();
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
private void updateButtons()
{
this.buttonNextPage.visible = !this.bookGettingSigned && (this.currPage < this.bookTotalPages - 1 || this.bookIsUnsigned);
this.buttonPreviousPage.visible = !this.bookGettingSigned && this.currPage > 0;
this.buttonDone.visible = !this.bookIsUnsigned || !this.bookGettingSigned;
if (this.bookIsUnsigned)
{
this.buttonSign.visible = !this.bookGettingSigned;
this.buttonCancel.visible = this.bookGettingSigned;
this.buttonFinalize.visible = this.bookGettingSigned;
this.buttonFinalize.enabled = !this.bookTitle.trim().isEmpty();
}
}
private void sendBookToServer(boolean publish) throws IOException
{
if (this.bookIsUnsigned && this.bookIsModified)
{
if (this.bookPages != null)
{
while (this.bookPages.tagCount() > 1)
{
String s = this.bookPages.getStringTagAt(this.bookPages.tagCount() - 1);
if (!s.isEmpty())
{
break;
}
this.bookPages.removeTag(this.bookPages.tagCount() - 1);
}
if (this.book.hasTagCompound())
{
NBTTagCompound nbttagcompound = this.book.getTagCompound();
nbttagcompound.setTag("pages", this.bookPages);
}
else
{
this.book.setTagInfo("pages", this.bookPages);
}
String s1 = "MC|BEdit";
if (publish)
{
s1 = "MC|BSign";
this.book.setTagInfo("author", new NBTTagString(this.editingPlayer.getName()));
this.book.setTagInfo("title", new NBTTagString(this.bookTitle.trim()));
}
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
packetbuffer.writeItemStack(this.book);
this.mc.getConnection().sendPacket(new CPacketCustomPayload(s1, packetbuffer));
}
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 0)
{
this.mc.displayGuiScreen((GuiScreen)null);
this.sendBookToServer(false);
}
else if (button.id == 3 && this.bookIsUnsigned)
{
this.bookGettingSigned = true;
}
else if (button.id == 1)
{
if (this.currPage < this.bookTotalPages - 1)
{
++this.currPage;
}
else if (this.bookIsUnsigned)
{
this.addNewPage();
if (this.currPage < this.bookTotalPages - 1)
{
++this.currPage;
}
}
}
else if (button.id == 2)
{
if (this.currPage > 0)
{
--this.currPage;
}
}
else if (button.id == 5 && this.bookGettingSigned)
{
this.sendBookToServer(true);
this.mc.displayGuiScreen((GuiScreen)null);
}
else if (button.id == 4 && this.bookGettingSigned)
{
this.bookGettingSigned = false;
}
this.updateButtons();
}
}
private void addNewPage()
{
if (this.bookPages != null && this.bookPages.tagCount() < 50)
{
this.bookPages.appendTag(new NBTTagString(""));
++this.bookTotalPages;
this.bookIsModified = true;
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
super.keyTyped(typedChar, keyCode);
if (this.bookIsUnsigned)
{
if (this.bookGettingSigned)
{
this.keyTypedInTitle(typedChar, keyCode);
}
else
{
this.keyTypedInBook(typedChar, keyCode);
}
}
}
/**
* Processes keystrokes when editing the text of a book
*/
private void keyTypedInBook(char typedChar, int keyCode)
{
if (GuiScreen.isKeyComboCtrlV(keyCode))
{
this.pageInsertIntoCurrent(GuiScreen.getClipboardString());
}
else
{
switch (keyCode)
{
case 14:
String s = this.pageGetCurrent();
if (!s.isEmpty())
{
this.pageSetCurrent(s.substring(0, s.length() - 1));
}
return;
case 28:
case 156:
this.pageInsertIntoCurrent("\n");
return;
default:
if (ChatAllowedCharacters.isAllowedCharacter(typedChar))
{
this.pageInsertIntoCurrent(Character.toString(typedChar));
}
}
}
}
/**
* Processes keystrokes when editing the title of a book
*/
private void keyTypedInTitle(char typedChar, int keyCode) throws IOException
{
switch (keyCode)
{
case 14:
if (!this.bookTitle.isEmpty())
{
this.bookTitle = this.bookTitle.substring(0, this.bookTitle.length() - 1);
this.updateButtons();
}
return;
case 28:
case 156:
if (!this.bookTitle.isEmpty())
{
this.sendBookToServer(true);
this.mc.displayGuiScreen((GuiScreen)null);
}
return;
default:
if (this.bookTitle.length() < 16 && ChatAllowedCharacters.isAllowedCharacter(typedChar))
{
this.bookTitle = this.bookTitle + Character.toString(typedChar);
this.updateButtons();
this.bookIsModified = true;
}
}
}
/**
* Returns the entire text of the current page as determined by currPage
*/
private String pageGetCurrent()
{
return this.bookPages != null && this.currPage >= 0 && this.currPage < this.bookPages.tagCount() ? this.bookPages.getStringTagAt(this.currPage) : "";
}
/**
* Sets the text of the current page as determined by currPage
*/
private void pageSetCurrent(String p_146457_1_)
{
if (this.bookPages != null && this.currPage >= 0 && this.currPage < this.bookPages.tagCount())
{
this.bookPages.set(this.currPage, new NBTTagString(p_146457_1_));
this.bookIsModified = true;
}
}
/**
* Processes any text getting inserted into the current page, enforcing the page size limit
*/
private void pageInsertIntoCurrent(String p_146459_1_)
{
String s = this.pageGetCurrent();
String s1 = s + p_146459_1_;
int i = this.fontRenderer.getWordWrappedHeight(s1 + "" + TextFormatting.BLACK + "_", 118);
if (i <= 128 && s1.length() < 256)
{
this.pageSetCurrent(s1);
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(BOOK_GUI_TEXTURES);
int i = (this.width - 192) / 2;
int j = 2;
this.drawTexturedModalRect(i, 2, 0, 0, 192, 192);
if (this.bookGettingSigned)
{
String s = this.bookTitle;
if (this.bookIsUnsigned)
{
if (this.updateCount / 6 % 2 == 0)
{
s = s + "" + TextFormatting.BLACK + "_";
}
else
{
s = s + "" + TextFormatting.GRAY + "_";
}
}
String s1 = I18n.format("book.editTitle");
int k = this.fontRenderer.getStringWidth(s1);
this.fontRenderer.drawString(s1, i + 36 + (116 - k) / 2, 34, 0);
int l = this.fontRenderer.getStringWidth(s);
this.fontRenderer.drawString(s, i + 36 + (116 - l) / 2, 50, 0);
String s2 = I18n.format("book.byAuthor", this.editingPlayer.getName());
int i1 = this.fontRenderer.getStringWidth(s2);
this.fontRenderer.drawString(TextFormatting.DARK_GRAY + s2, i + 36 + (116 - i1) / 2, 60, 0);
String s3 = I18n.format("book.finalizeWarning");
this.fontRenderer.drawSplitString(s3, i + 36, 82, 116, 0);
}
else
{
String s4 = I18n.format("book.pageIndicator", this.currPage + 1, this.bookTotalPages);
String s5 = "";
if (this.bookPages != null && this.currPage >= 0 && this.currPage < this.bookPages.tagCount())
{
s5 = this.bookPages.getStringTagAt(this.currPage);
}
if (this.bookIsUnsigned)
{
if (this.fontRenderer.getBidiFlag())
{
s5 = s5 + "_";
}
else if (this.updateCount / 6 % 2 == 0)
{
s5 = s5 + "" + TextFormatting.BLACK + "_";
}
else
{
s5 = s5 + "" + TextFormatting.GRAY + "_";
}
}
else if (this.cachedPage != this.currPage)
{
if (ItemWrittenBook.validBookTagContents(this.book.getTagCompound()))
{
try
{
ITextComponent itextcomponent = ITextComponent.Serializer.jsonToComponent(s5);
this.cachedComponents = itextcomponent != null ? GuiUtilRenderComponents.splitText(itextcomponent, 116, this.fontRenderer, true, true) : null;
}
catch (JsonParseException var13)
{
this.cachedComponents = null;
}
}
else
{
TextComponentString textcomponentstring = new TextComponentString(TextFormatting.DARK_RED + "* Invalid book tag *");
this.cachedComponents = Lists.newArrayList(textcomponentstring);
}
this.cachedPage = this.currPage;
}
int j1 = this.fontRenderer.getStringWidth(s4);
this.fontRenderer.drawString(s4, i - j1 + 192 - 44, 18, 0);
if (this.cachedComponents == null)
{
this.fontRenderer.drawSplitString(s5, i + 36, 34, 116, 0);
}
else
{
int k1 = Math.min(128 / this.fontRenderer.FONT_HEIGHT, this.cachedComponents.size());
for (int l1 = 0; l1 < k1; ++l1)
{
ITextComponent itextcomponent2 = this.cachedComponents.get(l1);
this.fontRenderer.drawString(itextcomponent2.getUnformattedText(), i + 36, 34 + l1 * this.fontRenderer.FONT_HEIGHT, 0);
}
ITextComponent itextcomponent1 = this.getClickedComponentAt(mouseX, mouseY);
if (itextcomponent1 != null)
{
this.handleComponentHover(itextcomponent1, mouseX, mouseY);
}
}
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
if (mouseButton == 0)
{
ITextComponent itextcomponent = this.getClickedComponentAt(mouseX, mouseY);
if (itextcomponent != null && this.handleComponentClick(itextcomponent))
{
return;
}
}
super.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Executes the click event specified by the given chat component
*/
public boolean handleComponentClick(ITextComponent component)
{
ClickEvent clickevent = component.getStyle().getClickEvent();
if (clickevent == null)
{
return false;
}
else if (clickevent.getAction() == ClickEvent.Action.CHANGE_PAGE)
{
String s = clickevent.getValue();
try
{
int i = Integer.parseInt(s) - 1;
if (i >= 0 && i < this.bookTotalPages && i != this.currPage)
{
this.currPage = i;
this.updateButtons();
return true;
}
}
catch (Throwable var5)
{
;
}
return false;
}
else
{
boolean flag = super.handleComponentClick(component);
if (flag && clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
{
this.mc.displayGuiScreen((GuiScreen)null);
}
return flag;
}
}
@Nullable
public ITextComponent getClickedComponentAt(int p_175385_1_, int p_175385_2_)
{
if (this.cachedComponents == null)
{
return null;
}
else
{
int i = p_175385_1_ - (this.width - 192) / 2 - 36;
int j = p_175385_2_ - 2 - 16 - 16;
if (i >= 0 && j >= 0)
{
int k = Math.min(128 / this.fontRenderer.FONT_HEIGHT, this.cachedComponents.size());
if (i <= 116 && j < this.mc.fontRenderer.FONT_HEIGHT * k + k)
{
int l = j / this.mc.fontRenderer.FONT_HEIGHT;
if (l >= 0 && l < this.cachedComponents.size())
{
ITextComponent itextcomponent = this.cachedComponents.get(l);
int i1 = 0;
for (ITextComponent itextcomponent1 : itextcomponent)
{
if (itextcomponent1 instanceof TextComponentString)
{
i1 += this.mc.fontRenderer.getStringWidth(((TextComponentString)itextcomponent1).getText());
if (i1 > i)
{
return itextcomponent1;
}
}
}
}
return null;
}
else
{
return null;
}
}
else
{
return null;
}
}
}
@SideOnly(Side.CLIENT)
static class NextPageButton extends GuiButton
{
private final boolean isForward;
public NextPageButton(int buttonId, int x, int y, boolean isForwardIn)
{
super(buttonId, x, y, 23, 13, "");
this.isForward = isForwardIn;
}
/**
* Draws this button to the screen.
*/
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
{
if (this.visible)
{
boolean flag = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(GuiScreenBook.BOOK_GUI_TEXTURES);
int i = 0;
int j = 192;
if (flag)
{
i += 23;
}
if (!this.isForward)
{
j += 13;
}
this.drawTexturedModalRect(this.x, this.y, i, j, 23, 13);
}
}
}
}

View File

@@ -0,0 +1,246 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.List;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.gen.ChunkGeneratorSettings;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiScreenCustomizePresets extends GuiScreen
{
private static final List<GuiScreenCustomizePresets.Info> PRESETS = Lists.<GuiScreenCustomizePresets.Info>newArrayList();
private GuiScreenCustomizePresets.ListPreset list;
private GuiButton select;
private GuiTextField export;
private final GuiCustomizeWorldScreen parent;
protected String title = "Customize World Presets";
private String shareText;
private String listText;
public GuiScreenCustomizePresets(GuiCustomizeWorldScreen parentIn)
{
this.parent = parentIn;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
Keyboard.enableRepeatEvents(true);
this.title = I18n.format("createWorld.customize.custom.presets.title");
this.shareText = I18n.format("createWorld.customize.presets.share");
this.listText = I18n.format("createWorld.customize.presets.list");
this.export = new GuiTextField(2, this.fontRenderer, 50, 40, this.width - 100, 20);
this.list = new GuiScreenCustomizePresets.ListPreset();
this.export.setMaxStringLength(2000);
this.export.setText(this.parent.saveValues());
this.select = this.addButton(new GuiButton(0, this.width / 2 - 102, this.height - 27, 100, 20, I18n.format("createWorld.customize.presets.select")));
this.buttonList.add(new GuiButton(1, this.width / 2 + 3, this.height - 27, 100, 20, I18n.format("gui.cancel")));
this.updateButtonValidity();
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.list.handleMouseInput();
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
this.export.mouseClicked(mouseX, mouseY, mouseButton);
super.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (!this.export.textboxKeyTyped(typedChar, keyCode))
{
super.keyTyped(typedChar, keyCode);
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
switch (button.id)
{
case 0:
this.parent.loadValues(this.export.getText());
this.mc.displayGuiScreen(this.parent);
break;
case 1:
this.mc.displayGuiScreen(this.parent);
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.list.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 8, 16777215);
this.drawString(this.fontRenderer, this.shareText, 50, 30, 10526880);
this.drawString(this.fontRenderer, this.listText, 50, 70, 10526880);
this.export.drawTextBox();
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
this.export.updateCursorCounter();
super.updateScreen();
}
public void updateButtonValidity()
{
this.select.enabled = this.hasValidSelection();
}
private boolean hasValidSelection()
{
return this.list.selected > -1 && this.list.selected < PRESETS.size() || this.export.getText().length() > 1;
}
static
{
ChunkGeneratorSettings.Factory chunkgeneratorsettings$factory = ChunkGeneratorSettings.Factory.jsonToFactory("{ \"coordinateScale\":684.412, \"heightScale\":684.412, \"upperLimitScale\":512.0, \"lowerLimitScale\":512.0, \"depthNoiseScaleX\":200.0, \"depthNoiseScaleZ\":200.0, \"depthNoiseScaleExponent\":0.5, \"mainNoiseScaleX\":5000.0, \"mainNoiseScaleY\":1000.0, \"mainNoiseScaleZ\":5000.0, \"baseSize\":8.5, \"stretchY\":8.0, \"biomeDepthWeight\":2.0, \"biomeDepthOffset\":0.5, \"biomeScaleWeight\":2.0, \"biomeScaleOffset\":0.375, \"useCaves\":true, \"useDungeons\":true, \"dungeonChance\":8, \"useStrongholds\":true, \"useVillages\":true, \"useMineShafts\":true, \"useTemples\":true, \"useRavines\":true, \"useWaterLakes\":true, \"waterLakeChance\":4, \"useLavaLakes\":true, \"lavaLakeChance\":80, \"useLavaOceans\":false, \"seaLevel\":255 }");
ResourceLocation resourcelocation = new ResourceLocation("textures/gui/presets/water.png");
PRESETS.add(new GuiScreenCustomizePresets.Info(I18n.format("createWorld.customize.custom.preset.waterWorld"), resourcelocation, chunkgeneratorsettings$factory));
chunkgeneratorsettings$factory = ChunkGeneratorSettings.Factory.jsonToFactory("{\"coordinateScale\":3000.0, \"heightScale\":6000.0, \"upperLimitScale\":250.0, \"lowerLimitScale\":512.0, \"depthNoiseScaleX\":200.0, \"depthNoiseScaleZ\":200.0, \"depthNoiseScaleExponent\":0.5, \"mainNoiseScaleX\":80.0, \"mainNoiseScaleY\":160.0, \"mainNoiseScaleZ\":80.0, \"baseSize\":8.5, \"stretchY\":10.0, \"biomeDepthWeight\":1.0, \"biomeDepthOffset\":0.0, \"biomeScaleWeight\":1.0, \"biomeScaleOffset\":0.0, \"useCaves\":true, \"useDungeons\":true, \"dungeonChance\":8, \"useStrongholds\":true, \"useVillages\":true, \"useMineShafts\":true, \"useTemples\":true, \"useRavines\":true, \"useWaterLakes\":true, \"waterLakeChance\":4, \"useLavaLakes\":true, \"lavaLakeChance\":80, \"useLavaOceans\":false, \"seaLevel\":63 }");
resourcelocation = new ResourceLocation("textures/gui/presets/isles.png");
PRESETS.add(new GuiScreenCustomizePresets.Info(I18n.format("createWorld.customize.custom.preset.isleLand"), resourcelocation, chunkgeneratorsettings$factory));
chunkgeneratorsettings$factory = ChunkGeneratorSettings.Factory.jsonToFactory("{\"coordinateScale\":684.412, \"heightScale\":684.412, \"upperLimitScale\":512.0, \"lowerLimitScale\":512.0, \"depthNoiseScaleX\":200.0, \"depthNoiseScaleZ\":200.0, \"depthNoiseScaleExponent\":0.5, \"mainNoiseScaleX\":5000.0, \"mainNoiseScaleY\":1000.0, \"mainNoiseScaleZ\":5000.0, \"baseSize\":8.5, \"stretchY\":5.0, \"biomeDepthWeight\":2.0, \"biomeDepthOffset\":1.0, \"biomeScaleWeight\":4.0, \"biomeScaleOffset\":1.0, \"useCaves\":true, \"useDungeons\":true, \"dungeonChance\":8, \"useStrongholds\":true, \"useVillages\":true, \"useMineShafts\":true, \"useTemples\":true, \"useRavines\":true, \"useWaterLakes\":true, \"waterLakeChance\":4, \"useLavaLakes\":true, \"lavaLakeChance\":80, \"useLavaOceans\":false, \"seaLevel\":63 }");
resourcelocation = new ResourceLocation("textures/gui/presets/delight.png");
PRESETS.add(new GuiScreenCustomizePresets.Info(I18n.format("createWorld.customize.custom.preset.caveDelight"), resourcelocation, chunkgeneratorsettings$factory));
chunkgeneratorsettings$factory = ChunkGeneratorSettings.Factory.jsonToFactory("{\"coordinateScale\":738.41864, \"heightScale\":157.69133, \"upperLimitScale\":801.4267, \"lowerLimitScale\":1254.1643, \"depthNoiseScaleX\":374.93652, \"depthNoiseScaleZ\":288.65228, \"depthNoiseScaleExponent\":1.2092624, \"mainNoiseScaleX\":1355.9908, \"mainNoiseScaleY\":745.5343, \"mainNoiseScaleZ\":1183.464, \"baseSize\":1.8758626, \"stretchY\":1.7137525, \"biomeDepthWeight\":1.7553768, \"biomeDepthOffset\":3.4701107, \"biomeScaleWeight\":1.0, \"biomeScaleOffset\":2.535211, \"useCaves\":true, \"useDungeons\":true, \"dungeonChance\":8, \"useStrongholds\":true, \"useVillages\":true, \"useMineShafts\":true, \"useTemples\":true, \"useRavines\":true, \"useWaterLakes\":true, \"waterLakeChance\":4, \"useLavaLakes\":true, \"lavaLakeChance\":80, \"useLavaOceans\":false, \"seaLevel\":63 }");
resourcelocation = new ResourceLocation("textures/gui/presets/madness.png");
PRESETS.add(new GuiScreenCustomizePresets.Info(I18n.format("createWorld.customize.custom.preset.mountains"), resourcelocation, chunkgeneratorsettings$factory));
chunkgeneratorsettings$factory = ChunkGeneratorSettings.Factory.jsonToFactory("{\"coordinateScale\":684.412, \"heightScale\":684.412, \"upperLimitScale\":512.0, \"lowerLimitScale\":512.0, \"depthNoiseScaleX\":200.0, \"depthNoiseScaleZ\":200.0, \"depthNoiseScaleExponent\":0.5, \"mainNoiseScaleX\":1000.0, \"mainNoiseScaleY\":3000.0, \"mainNoiseScaleZ\":1000.0, \"baseSize\":8.5, \"stretchY\":10.0, \"biomeDepthWeight\":1.0, \"biomeDepthOffset\":0.0, \"biomeScaleWeight\":1.0, \"biomeScaleOffset\":0.0, \"useCaves\":true, \"useDungeons\":true, \"dungeonChance\":8, \"useStrongholds\":true, \"useVillages\":true, \"useMineShafts\":true, \"useTemples\":true, \"useRavines\":true, \"useWaterLakes\":true, \"waterLakeChance\":4, \"useLavaLakes\":true, \"lavaLakeChance\":80, \"useLavaOceans\":false, \"seaLevel\":20 }");
resourcelocation = new ResourceLocation("textures/gui/presets/drought.png");
PRESETS.add(new GuiScreenCustomizePresets.Info(I18n.format("createWorld.customize.custom.preset.drought"), resourcelocation, chunkgeneratorsettings$factory));
chunkgeneratorsettings$factory = ChunkGeneratorSettings.Factory.jsonToFactory("{\"coordinateScale\":684.412, \"heightScale\":684.412, \"upperLimitScale\":2.0, \"lowerLimitScale\":64.0, \"depthNoiseScaleX\":200.0, \"depthNoiseScaleZ\":200.0, \"depthNoiseScaleExponent\":0.5, \"mainNoiseScaleX\":80.0, \"mainNoiseScaleY\":160.0, \"mainNoiseScaleZ\":80.0, \"baseSize\":8.5, \"stretchY\":12.0, \"biomeDepthWeight\":1.0, \"biomeDepthOffset\":0.0, \"biomeScaleWeight\":1.0, \"biomeScaleOffset\":0.0, \"useCaves\":true, \"useDungeons\":true, \"dungeonChance\":8, \"useStrongholds\":true, \"useVillages\":true, \"useMineShafts\":true, \"useTemples\":true, \"useRavines\":true, \"useWaterLakes\":true, \"waterLakeChance\":4, \"useLavaLakes\":true, \"lavaLakeChance\":80, \"useLavaOceans\":false, \"seaLevel\":6 }");
resourcelocation = new ResourceLocation("textures/gui/presets/chaos.png");
PRESETS.add(new GuiScreenCustomizePresets.Info(I18n.format("createWorld.customize.custom.preset.caveChaos"), resourcelocation, chunkgeneratorsettings$factory));
chunkgeneratorsettings$factory = ChunkGeneratorSettings.Factory.jsonToFactory("{\"coordinateScale\":684.412, \"heightScale\":684.412, \"upperLimitScale\":512.0, \"lowerLimitScale\":512.0, \"depthNoiseScaleX\":200.0, \"depthNoiseScaleZ\":200.0, \"depthNoiseScaleExponent\":0.5, \"mainNoiseScaleX\":80.0, \"mainNoiseScaleY\":160.0, \"mainNoiseScaleZ\":80.0, \"baseSize\":8.5, \"stretchY\":12.0, \"biomeDepthWeight\":1.0, \"biomeDepthOffset\":0.0, \"biomeScaleWeight\":1.0, \"biomeScaleOffset\":0.0, \"useCaves\":true, \"useDungeons\":true, \"dungeonChance\":8, \"useStrongholds\":true, \"useVillages\":true, \"useMineShafts\":true, \"useTemples\":true, \"useRavines\":true, \"useWaterLakes\":true, \"waterLakeChance\":4, \"useLavaLakes\":true, \"lavaLakeChance\":80, \"useLavaOceans\":true, \"seaLevel\":40 }");
resourcelocation = new ResourceLocation("textures/gui/presets/luck.png");
PRESETS.add(new GuiScreenCustomizePresets.Info(I18n.format("createWorld.customize.custom.preset.goodLuck"), resourcelocation, chunkgeneratorsettings$factory));
}
@SideOnly(Side.CLIENT)
static class Info
{
public String name;
public ResourceLocation texture;
public ChunkGeneratorSettings.Factory settings;
public Info(String nameIn, ResourceLocation textureIn, ChunkGeneratorSettings.Factory settingsIn)
{
this.name = nameIn;
this.texture = textureIn;
this.settings = settingsIn;
}
}
@SideOnly(Side.CLIENT)
class ListPreset extends GuiSlot
{
public int selected = -1;
public ListPreset()
{
super(GuiScreenCustomizePresets.this.mc, GuiScreenCustomizePresets.this.width, GuiScreenCustomizePresets.this.height, 80, GuiScreenCustomizePresets.this.height - 32, 38);
}
protected int getSize()
{
return GuiScreenCustomizePresets.PRESETS.size();
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
this.selected = slotIndex;
GuiScreenCustomizePresets.this.updateButtonValidity();
GuiScreenCustomizePresets.this.export.setText((GuiScreenCustomizePresets.PRESETS.get(GuiScreenCustomizePresets.this.list.selected)).settings.toString());
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return slotIndex == this.selected;
}
protected void drawBackground()
{
}
private void blitIcon(int p_178051_1_, int p_178051_2_, ResourceLocation texture)
{
int i = p_178051_1_ + 5;
GuiScreenCustomizePresets.this.drawHorizontalLine(i - 1, i + 32, p_178051_2_ - 1, -2039584);
GuiScreenCustomizePresets.this.drawHorizontalLine(i - 1, i + 32, p_178051_2_ + 32, -6250336);
GuiScreenCustomizePresets.this.drawVerticalLine(i - 1, p_178051_2_ - 1, p_178051_2_ + 32, -2039584);
GuiScreenCustomizePresets.this.drawVerticalLine(i + 32, p_178051_2_ - 1, p_178051_2_ + 32, -6250336);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
int j = 32;
int k = 32;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos((double)(i + 0), (double)(p_178051_2_ + 32), 0.0D).tex(0.0D, 1.0D).endVertex();
bufferbuilder.pos((double)(i + 32), (double)(p_178051_2_ + 32), 0.0D).tex(1.0D, 1.0D).endVertex();
bufferbuilder.pos((double)(i + 32), (double)(p_178051_2_ + 0), 0.0D).tex(1.0D, 0.0D).endVertex();
bufferbuilder.pos((double)(i + 0), (double)(p_178051_2_ + 0), 0.0D).tex(0.0D, 0.0D).endVertex();
tessellator.draw();
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
GuiScreenCustomizePresets.Info guiscreencustomizepresets$info = GuiScreenCustomizePresets.PRESETS.get(slotIndex);
this.blitIcon(xPos, yPos, guiscreencustomizepresets$info.texture);
GuiScreenCustomizePresets.this.fontRenderer.drawString(guiscreencustomizepresets$info.name, xPos + 32 + 10, yPos + 14, 16777215);
}
}
}

View File

@@ -0,0 +1,91 @@
package net.minecraft.client.gui;
import java.io.IOException;
import java.net.URI;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@SideOnly(Side.CLIENT)
public class GuiScreenDemo extends GuiScreen
{
private static final Logger LOGGER = LogManager.getLogger();
private static final ResourceLocation DEMO_BACKGROUND_LOCATION = new ResourceLocation("textures/gui/demo_background.png");
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
int i = -16;
this.buttonList.add(new GuiButton(1, this.width / 2 - 116, this.height / 2 + 62 + -16, 114, 20, I18n.format("demo.help.buy")));
this.buttonList.add(new GuiButton(2, this.width / 2 + 2, this.height / 2 + 62 + -16, 114, 20, I18n.format("demo.help.later")));
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
switch (button.id)
{
case 1:
button.enabled = false;
try
{
Class<?> oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop").invoke((Object)null);
oclass.getMethod("browse", URI.class).invoke(object, new URI("http://www.minecraft.net/store?source=demo"));
}
catch (Throwable throwable)
{
LOGGER.error("Couldn't open link", throwable);
}
break;
case 2:
this.mc.displayGuiScreen((GuiScreen)null);
this.mc.setIngameFocus();
}
}
/**
* Draws either a gradient over the background screen (when it exists) or a flat gradient over background.png
*/
public void drawDefaultBackground()
{
super.drawDefaultBackground();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(DEMO_BACKGROUND_LOCATION);
int i = (this.width - 248) / 2;
int j = (this.height - 166) / 2;
this.drawTexturedModalRect(i, j, 0, 0, 248, 166);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
int i = (this.width - 248) / 2 + 10;
int j = (this.height - 166) / 2 + 8;
this.fontRenderer.drawString(I18n.format("demo.help.title"), i, j, 2039583);
j = j + 12;
GameSettings gamesettings = this.mc.gameSettings;
this.fontRenderer.drawString(I18n.format("demo.help.movementShort", gamesettings.keyBindForward.getDisplayName(), gamesettings.keyBindLeft.getDisplayName(), gamesettings.keyBindBack.getDisplayName(), gamesettings.keyBindRight.getDisplayName()), i, j, 5197647);
this.fontRenderer.drawString(I18n.format("demo.help.movementMouse"), i, j + 12, 5197647);
this.fontRenderer.drawString(I18n.format("demo.help.jump", gamesettings.keyBindJump.getDisplayName()), i, j + 24, 5197647);
this.fontRenderer.drawString(I18n.format("demo.help.inventory", gamesettings.keyBindInventory.getDisplayName()), i, j + 36, 5197647);
this.fontRenderer.drawSplitString(I18n.format("demo.help.fullWrapped"), i, j + 68, 218, 2039583);
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,197 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiScreenOptionsSounds extends GuiScreen
{
private final GuiScreen parent;
/** Reference to the GameSettings object. */
private final GameSettings game_settings_4;
protected String title = "Options";
private String offDisplayString;
public GuiScreenOptionsSounds(GuiScreen parentIn, GameSettings settingsIn)
{
this.parent = parentIn;
this.game_settings_4 = settingsIn;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.title = I18n.format("options.sounds.title");
this.offDisplayString = I18n.format("options.off");
int i = 0;
this.buttonList.add(new GuiScreenOptionsSounds.Button(SoundCategory.MASTER.ordinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 12 + 24 * (i >> 1), SoundCategory.MASTER, true));
i = i + 2;
for (SoundCategory soundcategory : SoundCategory.values())
{
if (soundcategory != SoundCategory.MASTER)
{
this.buttonList.add(new GuiScreenOptionsSounds.Button(soundcategory.ordinal(), this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 12 + 24 * (i >> 1), soundcategory, false));
++i;
}
}
int j = this.width / 2 - 75;
int k = this.height / 6 - 12;
++i;
this.buttonList.add(new GuiOptionButton(201, j, k + 24 * (i >> 1), GameSettings.Options.SHOW_SUBTITLES, this.game_settings_4.getKeyBinding(GameSettings.Options.SHOW_SUBTITLES)));
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, I18n.format("gui.done")));
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (keyCode == 1)
{
this.mc.gameSettings.saveOptions();
}
super.keyTyped(typedChar, keyCode);
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 200)
{
this.mc.gameSettings.saveOptions();
this.mc.displayGuiScreen(this.parent);
}
else if (button.id == 201)
{
this.mc.gameSettings.setOptionValue(GameSettings.Options.SHOW_SUBTITLES, 1);
button.displayString = this.mc.gameSettings.getKeyBinding(GameSettings.Options.SHOW_SUBTITLES);
this.mc.gameSettings.saveOptions();
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 15, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
protected String getDisplayString(SoundCategory category)
{
float f = this.game_settings_4.getSoundLevel(category);
return f == 0.0F ? this.offDisplayString : (int)(f * 100.0F) + "%";
}
@SideOnly(Side.CLIENT)
class Button extends GuiButton
{
private final SoundCategory category;
private final String categoryName;
public float volume = 1.0F;
public boolean pressed;
public Button(int buttonId, int x, int y, SoundCategory categoryIn, boolean master)
{
super(buttonId, x, y, master ? 310 : 150, 20, "");
this.category = categoryIn;
this.categoryName = I18n.format("soundCategory." + categoryIn.getName());
this.displayString = this.categoryName + ": " + GuiScreenOptionsSounds.this.getDisplayString(categoryIn);
this.volume = GuiScreenOptionsSounds.this.game_settings_4.getSoundLevel(categoryIn);
}
/**
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering
* over this button.
*/
protected int getHoverState(boolean mouseOver)
{
return 0;
}
/**
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
*/
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
if (this.pressed)
{
this.volume = (float)(mouseX - (this.x + 4)) / (float)(this.width - 8);
this.volume = MathHelper.clamp(this.volume, 0.0F, 1.0F);
mc.gameSettings.setSoundLevel(this.category, this.volume);
mc.gameSettings.saveOptions();
this.displayString = this.categoryName + ": " + GuiScreenOptionsSounds.this.getDisplayString(this.category);
}
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.x + (int)(this.volume * (float)(this.width - 8)), this.y, 0, 66, 4, 20);
this.drawTexturedModalRect(this.x + (int)(this.volume * (float)(this.width - 8)) + 4, this.y, 196, 66, 4, 20);
}
}
/**
* Returns true if the mouse has been pressed on this control. Equivalent of
* MouseListener.mousePressed(MouseEvent e).
*/
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.volume = (float)(mouseX - (this.x + 4)) / (float)(this.width - 8);
this.volume = MathHelper.clamp(this.volume, 0.0F, 1.0F);
mc.gameSettings.setSoundLevel(this.category, this.volume);
mc.gameSettings.saveOptions();
this.displayString = this.categoryName + ": " + GuiScreenOptionsSounds.this.getDisplayString(this.category);
this.pressed = true;
return true;
}
else
{
return false;
}
}
public void playPressSound(SoundHandler soundHandlerIn)
{
}
/**
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
*/
public void mouseReleased(int mouseX, int mouseY)
{
if (this.pressed)
{
GuiScreenOptionsSounds.this.mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
}
this.pressed = false;
}
}
}

View File

@@ -0,0 +1,254 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.realms.RealmsButton;
import net.minecraft.realms.RealmsScreen;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiScreenRealmsProxy extends GuiScreen
{
private final RealmsScreen proxy;
public GuiScreenRealmsProxy(RealmsScreen proxyIn)
{
this.proxy = proxyIn;
this.buttonList = Collections.<GuiButton>synchronizedList(Lists.newArrayList());
}
public RealmsScreen getProxy()
{
return this.proxy;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.proxy.init();
super.initGui();
}
public void drawCenteredString(String text, int x, int y, int color)
{
super.drawCenteredString(this.fontRenderer, text, x, y, color);
}
public void drawString(String text, int x, int y, int color, boolean p_154322_5_)
{
if (p_154322_5_)
{
super.drawString(this.fontRenderer, text, x, y, color);
}
else
{
this.fontRenderer.drawString(text, x, y, color);
}
}
/**
* Draws a textured rectangle at the current z-value.
*/
public void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height)
{
this.proxy.blit(x, y, textureX, textureY, width, height);
super.drawTexturedModalRect(x, y, textureX, textureY, width, height);
}
/**
* Draws a rectangle with a vertical gradient between the specified colors (ARGB format). Args : x1, y1, x2, y2,
* topColor, bottomColor
*/
public void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor)
{
super.drawGradientRect(left, top, right, bottom, startColor, endColor);
}
/**
* Draws either a gradient over the background screen (when it exists) or a flat gradient over background.png
*/
public void drawDefaultBackground()
{
super.drawDefaultBackground();
}
/**
* Returns true if this GUI should pause the game when it is displayed in single-player
*/
public boolean doesGuiPauseGame()
{
return super.doesGuiPauseGame();
}
public void drawWorldBackground(int tint)
{
super.drawWorldBackground(tint);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.proxy.render(mouseX, mouseY, partialTicks);
}
public void renderToolTip(ItemStack stack, int x, int y)
{
super.renderToolTip(stack, x, y);
}
/**
* Draws the given text as a tooltip.
*/
public void drawHoveringText(String text, int x, int y)
{
super.drawHoveringText(text, x, y);
}
/**
* Draws a List of strings as a tooltip. Every entry is drawn on a seperate line.
*/
public void drawHoveringText(List<String> textLines, int x, int y)
{
super.drawHoveringText(textLines, x, y);
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
this.proxy.tick();
super.updateScreen();
}
public int getFontHeight()
{
return this.fontRenderer.FONT_HEIGHT;
}
public int getStringWidth(String text)
{
return this.fontRenderer.getStringWidth(text);
}
public void fontDrawShadow(String text, int x, int y, int color)
{
this.fontRenderer.drawStringWithShadow(text, (float)x, (float)y, color);
}
public List<String> fontSplit(String text, int wrapWidth)
{
return this.fontRenderer.listFormattedStringToWidth(text, wrapWidth);
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
public final void actionPerformed(GuiButton button) throws IOException
{
this.proxy.buttonClicked(((GuiButtonRealmsProxy)button).getRealmsButton());
}
public void buttonsClear()
{
this.buttonList.clear();
}
public void buttonsAdd(RealmsButton button)
{
this.buttonList.add(button.getProxy());
}
public List<RealmsButton> buttons()
{
List<RealmsButton> list = Lists.<RealmsButton>newArrayListWithExpectedSize(this.buttonList.size());
for (GuiButton guibutton : this.buttonList)
{
list.add(((GuiButtonRealmsProxy)guibutton).getRealmsButton());
}
return list;
}
public void buttonsRemove(RealmsButton button)
{
this.buttonList.remove(button.getProxy());
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
this.proxy.mouseClicked(mouseX, mouseY, mouseButton);
super.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
this.proxy.mouseEvent();
super.handleMouseInput();
}
/**
* Handles keyboard input.
*/
public void handleKeyboardInput() throws IOException
{
this.proxy.keyboardEvent();
super.handleKeyboardInput();
}
/**
* Called when a mouse button is released.
*/
public void mouseReleased(int mouseX, int mouseY, int state)
{
this.proxy.mouseReleased(mouseX, mouseY, state);
}
/**
* Called when a mouse button is pressed and the mouse is moved around. Parameters are : mouseX, mouseY,
* lastButtonClicked & timeSinceMouseClick.
*/
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick)
{
this.proxy.mouseDragged(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
public void keyTyped(char typedChar, int keyCode) throws IOException
{
this.proxy.keyPressed(typedChar, keyCode);
}
public void confirmClicked(boolean result, int id)
{
this.proxy.confirmResult(result, id);
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
this.proxy.removed();
super.onGuiClosed();
}
}

View File

@@ -0,0 +1,211 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.ResourcePackListEntry;
import net.minecraft.client.resources.ResourcePackListEntryDefault;
import net.minecraft.client.resources.ResourcePackListEntryFound;
import net.minecraft.client.resources.ResourcePackListEntryServer;
import net.minecraft.client.resources.ResourcePackRepository;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiScreenResourcePacks extends GuiScreen
{
private final GuiScreen parentScreen;
/** List of available resource packs */
private List<ResourcePackListEntry> availableResourcePacks;
/** List of selected resource packs */
private List<ResourcePackListEntry> selectedResourcePacks;
/** List component that contains the available resource packs */
private GuiResourcePackAvailable availableResourcePacksList;
/** List component that contains the selected resource packs */
private GuiResourcePackSelected selectedResourcePacksList;
private boolean changed;
public GuiScreenResourcePacks(GuiScreen parentScreenIn)
{
this.parentScreen = parentScreenIn;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.add(new GuiOptionButton(2, this.width / 2 - 154, this.height - 48, I18n.format("resourcePack.openFolder")));
this.buttonList.add(new GuiOptionButton(1, this.width / 2 + 4, this.height - 48, I18n.format("gui.done")));
if (!this.changed)
{
this.availableResourcePacks = Lists.<ResourcePackListEntry>newArrayList();
this.selectedResourcePacks = Lists.<ResourcePackListEntry>newArrayList();
ResourcePackRepository resourcepackrepository = this.mc.getResourcePackRepository();
resourcepackrepository.updateRepositoryEntriesAll();
List<ResourcePackRepository.Entry> list = Lists.newArrayList(resourcepackrepository.getRepositoryEntriesAll());
list.removeAll(resourcepackrepository.getRepositoryEntries());
for (ResourcePackRepository.Entry resourcepackrepository$entry : list)
{
this.availableResourcePacks.add(new ResourcePackListEntryFound(this, resourcepackrepository$entry));
}
ResourcePackRepository.Entry resourcepackrepository$entry2 = resourcepackrepository.getResourcePackEntry();
if (resourcepackrepository$entry2 != null)
{
this.selectedResourcePacks.add(new ResourcePackListEntryServer(this, resourcepackrepository.getServerResourcePack()));
}
for (ResourcePackRepository.Entry resourcepackrepository$entry1 : Lists.reverse(resourcepackrepository.getRepositoryEntries()))
{
this.selectedResourcePacks.add(new ResourcePackListEntryFound(this, resourcepackrepository$entry1));
}
this.selectedResourcePacks.add(new ResourcePackListEntryDefault(this));
}
this.availableResourcePacksList = new GuiResourcePackAvailable(this.mc, 200, this.height, this.availableResourcePacks);
this.availableResourcePacksList.setSlotXBoundsFromLeft(this.width / 2 - 4 - 200);
this.availableResourcePacksList.registerScrollButtons(7, 8);
this.selectedResourcePacksList = new GuiResourcePackSelected(this.mc, 200, this.height, this.selectedResourcePacks);
this.selectedResourcePacksList.setSlotXBoundsFromLeft(this.width / 2 + 4);
this.selectedResourcePacksList.registerScrollButtons(7, 8);
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.selectedResourcePacksList.handleMouseInput();
this.availableResourcePacksList.handleMouseInput();
}
public boolean hasResourcePackEntry(ResourcePackListEntry resourcePackEntry)
{
return this.selectedResourcePacks.contains(resourcePackEntry);
}
/**
* Returns the list containing the resource pack entry, returns the selected list if it is selected, otherwise
* returns the available list
*/
public List<ResourcePackListEntry> getListContaining(ResourcePackListEntry resourcePackEntry)
{
return this.hasResourcePackEntry(resourcePackEntry) ? this.selectedResourcePacks : this.availableResourcePacks;
}
/**
* Returns a list containing the available resource packs
*/
public List<ResourcePackListEntry> getAvailableResourcePacks()
{
return this.availableResourcePacks;
}
/**
* Returns a list containing the selected resource packs
*/
public List<ResourcePackListEntry> getSelectedResourcePacks()
{
return this.selectedResourcePacks;
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 2)
{
File file1 = this.mc.getResourcePackRepository().getDirResourcepacks();
OpenGlHelper.openFile(file1);
}
else if (button.id == 1)
{
if (this.changed)
{
List<ResourcePackRepository.Entry> list = Lists.<ResourcePackRepository.Entry>newArrayList();
for (ResourcePackListEntry resourcepacklistentry : this.selectedResourcePacks)
{
if (resourcepacklistentry instanceof ResourcePackListEntryFound)
{
list.add(((ResourcePackListEntryFound)resourcepacklistentry).getResourcePackEntry());
}
}
Collections.reverse(list);
this.mc.getResourcePackRepository().setRepositories(list);
this.mc.gameSettings.resourcePacks.clear();
this.mc.gameSettings.incompatibleResourcePacks.clear();
for (ResourcePackRepository.Entry resourcepackrepository$entry : list)
{
this.mc.gameSettings.resourcePacks.add(resourcepackrepository$entry.getResourcePackName());
if (resourcepackrepository$entry.getPackFormat() != 3)
{
this.mc.gameSettings.incompatibleResourcePacks.add(resourcepackrepository$entry.getResourcePackName());
}
}
this.mc.gameSettings.saveOptions();
this.mc.refreshResources();
}
this.mc.displayGuiScreen(this.parentScreen);
}
}
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.availableResourcePacksList.mouseClicked(mouseX, mouseY, mouseButton);
this.selectedResourcePacksList.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Called when a mouse button is released.
*/
protected void mouseReleased(int mouseX, int mouseY, int state)
{
super.mouseReleased(mouseX, mouseY, state);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawBackground(0);
this.availableResourcePacksList.drawScreen(mouseX, mouseY, partialTicks);
this.selectedResourcePacksList.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRenderer, I18n.format("resourcePack.title"), this.width / 2, 16, 16777215);
this.drawCenteredString(this.fontRenderer, I18n.format("resourcePack.folderInfo"), this.width / 2 - 77, this.height - 26, 8421504);
super.drawScreen(mouseX, mouseY, partialTicks);
}
/**
* Marks the selected resource packs list as changed to trigger a resource reload when the screen is closed
*/
public void markChanged()
{
this.changed = true;
}
}

View File

@@ -0,0 +1,113 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
@SideOnly(Side.CLIENT)
public class GuiScreenServerList extends GuiScreen
{
private final GuiScreen lastScreen;
private final ServerData serverData;
private GuiTextField ipEdit;
public GuiScreenServerList(GuiScreen lastScreenIn, ServerData serverDataIn)
{
this.lastScreen = lastScreenIn;
this.serverData = serverDataIn;
}
/**
* Called from the main game loop to update the screen.
*/
public void updateScreen()
{
this.ipEdit.updateCursorCounter();
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
Keyboard.enableRepeatEvents(true);
this.buttonList.clear();
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, I18n.format("selectServer.select")));
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, I18n.format("gui.cancel")));
this.ipEdit = new GuiTextField(2, this.fontRenderer, this.width / 2 - 100, 116, 200, 20);
this.ipEdit.setMaxStringLength(128);
this.ipEdit.setFocused(true);
this.ipEdit.setText(this.mc.gameSettings.lastServer);
(this.buttonList.get(0)).enabled = !this.ipEdit.getText().isEmpty() && this.ipEdit.getText().split(":").length > 0;
}
/**
* Called when the screen is unloaded. Used to disable keyboard repeat events
*/
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
this.mc.gameSettings.lastServer = this.ipEdit.getText();
this.mc.gameSettings.saveOptions();
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 1)
{
this.lastScreen.confirmClicked(false, 0);
}
else if (button.id == 0)
{
this.serverData.serverIP = this.ipEdit.getText();
this.lastScreen.confirmClicked(true, 0);
}
}
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (this.ipEdit.textboxKeyTyped(typedChar, keyCode))
{
(this.buttonList.get(0)).enabled = !this.ipEdit.getText().isEmpty() && this.ipEdit.getText().split(":").length > 0;
}
else if (keyCode == 28 || keyCode == 156)
{
this.actionPerformed(this.buttonList.get(0));
}
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.ipEdit.mouseClicked(mouseX, mouseY, mouseButton);
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, I18n.format("selectServer.direct"), this.width / 2, 20, 16777215);
this.drawString(this.fontRenderer, I18n.format("addServer.enterIp"), this.width / 2 - 100, 100, 10526880);
this.ipEdit.drawTextBox();
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,75 @@
package net.minecraft.client.gui;
import net.minecraft.util.IProgressUpdate;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiScreenWorking extends GuiScreen implements IProgressUpdate
{
private String title = "";
private String stage = "";
private int progress;
private boolean doneWorking;
/**
* Shows the 'Saving level' string.
*/
public void displaySavingString(String message)
{
this.resetProgressAndMessage(message);
}
/**
* this string, followed by "working..." and then the "% complete" are the 3 lines shown. This resets progress to 0,
* and the WorkingString to "working...".
*/
public void resetProgressAndMessage(String message)
{
this.title = message;
this.displayLoadingString("Working...");
}
/**
* Displays a string on the loading screen supposed to indicate what is being done currently.
*/
public void displayLoadingString(String message)
{
this.stage = message;
this.setLoadingProgress(0);
}
/**
* Updates the progress bar on the loading screen to the specified amount.
*/
public void setLoadingProgress(int progress)
{
this.progress = progress;
}
public void setDoneWorking()
{
this.doneWorking = true;
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
if (this.doneWorking)
{
if (!this.mc.isConnectedToRealms())
{
this.mc.displayGuiScreen((GuiScreen)null);
}
}
else
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 70, 16777215);
this.drawCenteredString(this.fontRenderer, this.stage + " " + this.progress + "%", this.width / 2, 90, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
}
}

View File

@@ -0,0 +1,119 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.GameType;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiShareToLan extends GuiScreen
{
private final GuiScreen lastScreen;
private GuiButton allowCheatsButton;
private GuiButton gameModeButton;
private String gameMode = "survival";
private boolean allowCheats;
public GuiShareToLan(GuiScreen lastScreenIn)
{
this.lastScreen = lastScreenIn;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.buttonList.clear();
this.buttonList.add(new GuiButton(101, this.width / 2 - 155, this.height - 28, 150, 20, I18n.format("lanServer.start")));
this.buttonList.add(new GuiButton(102, this.width / 2 + 5, this.height - 28, 150, 20, I18n.format("gui.cancel")));
this.gameModeButton = this.addButton(new GuiButton(104, this.width / 2 - 155, 100, 150, 20, I18n.format("selectWorld.gameMode")));
this.allowCheatsButton = this.addButton(new GuiButton(103, this.width / 2 + 5, 100, 150, 20, I18n.format("selectWorld.allowCommands")));
this.updateDisplayNames();
}
private void updateDisplayNames()
{
this.gameModeButton.displayString = I18n.format("selectWorld.gameMode") + ": " + I18n.format("selectWorld.gameMode." + this.gameMode);
this.allowCheatsButton.displayString = I18n.format("selectWorld.allowCommands") + " ";
if (this.allowCheats)
{
this.allowCheatsButton.displayString = this.allowCheatsButton.displayString + I18n.format("options.on");
}
else
{
this.allowCheatsButton.displayString = this.allowCheatsButton.displayString + I18n.format("options.off");
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 102)
{
this.mc.displayGuiScreen(this.lastScreen);
}
else if (button.id == 104)
{
if ("spectator".equals(this.gameMode))
{
this.gameMode = "creative";
}
else if ("creative".equals(this.gameMode))
{
this.gameMode = "adventure";
}
else if ("adventure".equals(this.gameMode))
{
this.gameMode = "survival";
}
else
{
this.gameMode = "spectator";
}
this.updateDisplayNames();
}
else if (button.id == 103)
{
this.allowCheats = !this.allowCheats;
this.updateDisplayNames();
}
else if (button.id == 101)
{
this.mc.displayGuiScreen((GuiScreen)null);
String s = this.mc.getIntegratedServer().shareToLAN(GameType.getByName(this.gameMode), this.allowCheats);
ITextComponent itextcomponent;
if (s != null)
{
itextcomponent = new TextComponentTranslation("commands.publish.started", new Object[] {s});
}
else
{
itextcomponent = new TextComponentString("commands.publish.failed");
}
this.mc.ingameGUI.getChatGUI().printChatMessage(itextcomponent);
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.drawCenteredString(this.fontRenderer, I18n.format("lanServer.title"), this.width / 2, 50, 16777215);
this.drawCenteredString(this.fontRenderer, I18n.format("lanServer.otherPlayers"), this.width / 2, 82, 16777215);
super.drawScreen(mouseX, mouseY, partialTicks);
}
}

View File

@@ -0,0 +1,159 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.realms.RealmsSimpleScrolledSelectionList;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiSimpleScrolledSelectionListProxy extends GuiSlot
{
private final RealmsSimpleScrolledSelectionList realmsScrolledSelectionList;
public GuiSimpleScrolledSelectionListProxy(RealmsSimpleScrolledSelectionList realmsScrolledSelectionListIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
{
super(Minecraft.getMinecraft(), widthIn, heightIn, topIn, bottomIn, slotHeightIn);
this.realmsScrolledSelectionList = realmsScrolledSelectionListIn;
}
protected int getSize()
{
return this.realmsScrolledSelectionList.getItemCount();
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
this.realmsScrolledSelectionList.selectItem(slotIndex, isDoubleClick, mouseX, mouseY);
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return this.realmsScrolledSelectionList.isSelectedItem(slotIndex);
}
protected void drawBackground()
{
this.realmsScrolledSelectionList.renderBackground();
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
this.realmsScrolledSelectionList.renderItem(slotIndex, xPos, yPos, heightIn, mouseXIn, mouseYIn);
}
public int getWidth()
{
return this.width;
}
public int getMouseY()
{
return this.mouseY;
}
public int getMouseX()
{
return this.mouseX;
}
/**
* Return the height of the content being scrolled
*/
protected int getContentHeight()
{
return this.realmsScrolledSelectionList.getMaxPosition();
}
protected int getScrollBarX()
{
return this.realmsScrolledSelectionList.getScrollbarPosition();
}
public void handleMouseInput()
{
super.handleMouseInput();
}
public void drawScreen(int mouseXIn, int mouseYIn, float partialTicks)
{
if (this.visible)
{
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
this.drawBackground();
int i = this.getScrollBarX();
int j = i + 6;
this.bindAmountScrolled();
GlStateManager.disableLighting();
GlStateManager.disableFog();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int l = this.top + 4 - (int)this.amountScrolled;
if (this.hasListHeader)
{
this.drawListHeader(k, l, tessellator);
}
this.drawSelectionBox(k, l, mouseXIn, mouseYIn, partialTicks);
GlStateManager.disableDepth();
this.overlayBackground(0, this.top, 255, 255);
this.overlayBackground(this.bottom, this.height, 255, 255);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
GlStateManager.disableAlpha();
GlStateManager.shadeModel(7425);
GlStateManager.disableTexture2D();
int i1 = this.getMaxScroll();
if (i1 > 0)
{
int j1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
j1 = MathHelper.clamp(j1, 32, this.bottom - this.top - 8);
int k1 = (int)this.amountScrolled * (this.bottom - this.top - j1) / i1 + this.top;
if (k1 < this.top)
{
k1 = this.top;
}
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)(k1 + j1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j, (double)(k1 + j1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j, (double)k1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)i, (double)k1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)(k1 + j1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(j - 1), (double)(k1 + j1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(j - 1), (double)k1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)i, (double)k1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
tessellator.draw();
}
this.renderDecorations(mouseXIn, mouseYIn);
GlStateManager.enableTexture2D();
GlStateManager.shadeModel(7424);
GlStateManager.enableAlpha();
GlStateManager.disableBlend();
}
}
}

View File

@@ -0,0 +1,71 @@
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.resources.I18n;
import net.minecraft.network.play.client.CPacketEntityAction;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiSleepMP extends GuiChat
{
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
super.initGui();
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height - 40, I18n.format("multiplayer.stopSleeping")));
}
/**
* Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
* KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
*/
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (keyCode == 1)
{
this.wakeFromSleep();
}
else if (keyCode != 28 && keyCode != 156)
{
super.keyTyped(typedChar, keyCode);
}
else
{
String s = this.inputField.getText().trim();
if (!s.isEmpty())
{
this.sendChatMessage(s); // Forge: fix vanilla not adding messages to the sent list while sleeping
}
this.inputField.setText("");
this.mc.ingameGUI.getChatGUI().resetScroll();
}
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.id == 1)
{
this.wakeFromSleep();
}
else
{
super.actionPerformed(button);
}
}
private void wakeFromSleep()
{
NetHandlerPlayClient nethandlerplayclient = this.mc.player.connection;
nethandlerplayclient.sendPacket(new CPacketEntityAction(this.mc.player, CPacketEntityAction.Action.STOP_SLEEPING));
}
}

View File

@@ -0,0 +1,167 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiSlider extends GuiButton
{
private float sliderPosition = 1.0F;
public boolean isMouseDown;
private final String name;
private final float min;
private final float max;
private final GuiPageButtonList.GuiResponder responder;
private GuiSlider.FormatHelper formatHelper;
public GuiSlider(GuiPageButtonList.GuiResponder guiResponder, int idIn, int x, int y, String nameIn, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter)
{
super(idIn, x, y, 150, 20, "");
this.name = nameIn;
this.min = minIn;
this.max = maxIn;
this.sliderPosition = (defaultValue - minIn) / (maxIn - minIn);
this.formatHelper = formatter;
this.responder = guiResponder;
this.displayString = this.getDisplayString();
}
/**
* Gets the value of the slider.
* @return A value that will under normal circumstances be between the slider's {@link #min} and {@link #max}
* values, unless it was manually set out of that range.
*/
public float getSliderValue()
{
return this.min + (this.max - this.min) * this.sliderPosition;
}
/**
* Sets the slider's value, optionally notifying the associated {@linkplain GuiPageButtonList.GuiResponder
* responder} of the change.
*/
public void setSliderValue(float value, boolean notifyResponder)
{
this.sliderPosition = (value - this.min) / (this.max - this.min);
this.displayString = this.getDisplayString();
if (notifyResponder)
{
this.responder.setEntryValue(this.id, this.getSliderValue());
}
}
/**
* Gets the slider's position.
* @return The position of the slider, which will under normal circumstances be between 0 and 1, unless it was
* manually set out of that range.
*/
public float getSliderPosition()
{
return this.sliderPosition;
}
private String getDisplayString()
{
return this.formatHelper == null ? I18n.format(this.name) + ": " + this.getSliderValue() : this.formatHelper.getText(this.id, I18n.format(this.name), this.getSliderValue());
}
/**
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
* this button.
*/
protected int getHoverState(boolean mouseOver)
{
return 0;
}
/**
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
*/
protected void mouseDragged(Minecraft mc, int mouseX, int mouseY)
{
if (this.visible)
{
if (this.isMouseDown)
{
this.sliderPosition = (float)(mouseX - (this.x + 4)) / (float)(this.width - 8);
if (this.sliderPosition < 0.0F)
{
this.sliderPosition = 0.0F;
}
if (this.sliderPosition > 1.0F)
{
this.sliderPosition = 1.0F;
}
this.displayString = this.getDisplayString();
this.responder.setEntryValue(this.id, this.getSliderValue());
}
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(this.x + (int)(this.sliderPosition * (float)(this.width - 8)), this.y, 0, 66, 4, 20);
this.drawTexturedModalRect(this.x + (int)(this.sliderPosition * (float)(this.width - 8)) + 4, this.y, 196, 66, 4, 20);
}
}
/**
* Sets the position of the slider and notifies the associated {@linkplain GuiPageButtonList.GuiResponder responder}
* of the change
*/
public void setSliderPosition(float position)
{
this.sliderPosition = position;
this.displayString = this.getDisplayString();
this.responder.setEntryValue(this.id, this.getSliderValue());
}
/**
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
* e).
*/
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
if (super.mousePressed(mc, mouseX, mouseY))
{
this.sliderPosition = (float)(mouseX - (this.x + 4)) / (float)(this.width - 8);
if (this.sliderPosition < 0.0F)
{
this.sliderPosition = 0.0F;
}
if (this.sliderPosition > 1.0F)
{
this.sliderPosition = 1.0F;
}
this.displayString = this.getDisplayString();
this.responder.setEntryValue(this.id, this.getSliderValue());
this.isMouseDown = true;
return true;
}
else
{
return false;
}
}
/**
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
*/
public void mouseReleased(int mouseX, int mouseY)
{
this.isMouseDown = false;
}
@SideOnly(Side.CLIENT)
public interface FormatHelper
{
String getText(int id, String name, float value);
}
}

View File

@@ -0,0 +1,522 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Mouse;
@SideOnly(Side.CLIENT)
public abstract class GuiSlot
{
protected final Minecraft mc;
public int width;
public int height;
/** The top of the slot container. Affects the overlays and scrolling. */
public int top;
/** The bottom of the slot container. Affects the overlays and scrolling. */
public int bottom;
public int right;
public int left;
/** The height of a slot. */
public final int slotHeight;
/** The buttonID of the button used to scroll up */
private int scrollUpButtonID;
/** The buttonID of the button used to scroll down */
private int scrollDownButtonID;
protected int mouseX;
protected int mouseY;
protected boolean centerListVertically = true;
/** Where the mouse was in the window when you first clicked to scroll */
protected int initialClickY = -2;
/**
* What to multiply the amount you moved your mouse by (used for slowing down scrolling when over the items and not
* on the scroll bar)
*/
protected float scrollMultiplier;
/** How far down this slot has been scrolled */
protected float amountScrolled;
/** The element in the list that was selected */
protected int selectedElement = -1;
/** The time when this button was last clicked. */
protected long lastClicked;
protected boolean visible = true;
/** Set to true if a selected element in this gui will show an outline box */
protected boolean showSelectionBox = true;
protected boolean hasListHeader;
public int headerPadding;
private boolean enabled = true;
public GuiSlot(Minecraft mcIn, int width, int height, int topIn, int bottomIn, int slotHeightIn)
{
this.mc = mcIn;
this.width = width;
this.height = height;
this.top = topIn;
this.bottom = bottomIn;
this.slotHeight = slotHeightIn;
this.left = 0;
this.right = width;
}
public void setDimensions(int widthIn, int heightIn, int topIn, int bottomIn)
{
this.width = widthIn;
this.height = heightIn;
this.top = topIn;
this.bottom = bottomIn;
this.left = 0;
this.right = widthIn;
}
public void setShowSelectionBox(boolean showSelectionBoxIn)
{
this.showSelectionBox = showSelectionBoxIn;
}
/**
* Sets hasListHeader and headerHeight. Params: hasListHeader, headerHeight. If hasListHeader is false headerHeight
* is set to 0.
*/
protected void setHasListHeader(boolean hasListHeaderIn, int headerPaddingIn)
{
this.hasListHeader = hasListHeaderIn;
this.headerPadding = headerPaddingIn;
if (!hasListHeaderIn)
{
this.headerPadding = 0;
}
}
protected abstract int getSize();
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected abstract void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY);
/**
* Returns true if the element passed in is currently selected
*/
protected abstract boolean isSelected(int slotIndex);
/**
* Return the height of the content being scrolled
*/
protected int getContentHeight()
{
return this.getSize() * this.slotHeight + this.headerPadding;
}
protected abstract void drawBackground();
protected void updateItemPos(int entryID, int insideLeft, int yPos, float partialTicks)
{
}
protected abstract void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks);
/**
* Handles drawing a list's header row.
*/
protected void drawListHeader(int insideLeft, int insideTop, Tessellator tessellatorIn)
{
}
protected void clickedHeader(int p_148132_1_, int p_148132_2_)
{
}
protected void renderDecorations(int mouseXIn, int mouseYIn)
{
}
public int getSlotIndexFromScreenCoords(int posX, int posY)
{
int i = this.left + this.width / 2 - this.getListWidth() / 2;
int j = this.left + this.width / 2 + this.getListWidth() / 2;
int k = posY - this.top - this.headerPadding + (int)this.amountScrolled - 4;
int l = k / this.slotHeight;
return posX < this.getScrollBarX() && posX >= i && posX <= j && l >= 0 && k >= 0 && l < this.getSize() ? l : -1;
}
/**
* Registers the IDs that can be used for the scrollbar's up/down buttons.
*/
public void registerScrollButtons(int scrollUpButtonIDIn, int scrollDownButtonIDIn)
{
this.scrollUpButtonID = scrollUpButtonIDIn;
this.scrollDownButtonID = scrollDownButtonIDIn;
}
/**
* Stop the thing from scrolling out of bounds
*/
protected void bindAmountScrolled()
{
this.amountScrolled = MathHelper.clamp(this.amountScrolled, 0.0F, (float)this.getMaxScroll());
}
public int getMaxScroll()
{
return Math.max(0, this.getContentHeight() - (this.bottom - this.top - 4));
}
/**
* Returns the amountScrolled field as an integer.
*/
public int getAmountScrolled()
{
return (int)this.amountScrolled;
}
public boolean isMouseYWithinSlotBounds(int p_148141_1_)
{
return p_148141_1_ >= this.top && p_148141_1_ <= this.bottom && this.mouseX >= this.left && this.mouseX <= this.right;
}
/**
* Scrolls the slot by the given amount. A positive value scrolls down, and a negative value scrolls up.
*/
public void scrollBy(int amount)
{
this.amountScrolled += (float)amount;
this.bindAmountScrolled();
this.initialClickY = -2;
}
public void actionPerformed(GuiButton button)
{
if (button.enabled)
{
if (button.id == this.scrollUpButtonID)
{
this.amountScrolled -= (float)(this.slotHeight * 2 / 3);
this.initialClickY = -2;
this.bindAmountScrolled();
}
else if (button.id == this.scrollDownButtonID)
{
this.amountScrolled += (float)(this.slotHeight * 2 / 3);
this.initialClickY = -2;
this.bindAmountScrolled();
}
}
}
public void drawScreen(int mouseXIn, int mouseYIn, float partialTicks)
{
if (this.visible)
{
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
this.drawBackground();
int i = this.getScrollBarX();
int j = i + 6;
this.bindAmountScrolled();
GlStateManager.disableLighting();
GlStateManager.disableFog();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
// Forge: background rendering moved into separate method.
this.drawContainerBackground(tessellator);
int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2;
int l = this.top + 4 - (int)this.amountScrolled;
if (this.hasListHeader)
{
this.drawListHeader(k, l, tessellator);
}
this.drawSelectionBox(k, l, mouseXIn, mouseYIn, partialTicks);
GlStateManager.disableDepth();
this.overlayBackground(0, this.top, 255, 255);
this.overlayBackground(this.bottom, this.height, 255, 255);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
GlStateManager.disableAlpha();
GlStateManager.shadeModel(7425);
GlStateManager.disableTexture2D();
int i1 = 4;
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)this.left, (double)(this.top + 4), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 0).endVertex();
bufferbuilder.pos((double)this.right, (double)(this.top + 4), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 0).endVertex();
bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)this.right, (double)(this.bottom - 4), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 0).endVertex();
bufferbuilder.pos((double)this.left, (double)(this.bottom - 4), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 0).endVertex();
tessellator.draw();
int j1 = this.getMaxScroll();
if (j1 > 0)
{
int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight();
k1 = MathHelper.clamp(k1, 32, this.bottom - this.top - 8);
int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top;
if (l1 < this.top)
{
l1 = this.top;
}
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
tessellator.draw();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex();
bufferbuilder.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex();
tessellator.draw();
}
this.renderDecorations(mouseXIn, mouseYIn);
GlStateManager.enableTexture2D();
GlStateManager.shadeModel(7424);
GlStateManager.enableAlpha();
GlStateManager.disableBlend();
}
}
public void handleMouseInput()
{
if (this.isMouseYWithinSlotBounds(this.mouseY))
{
if (Mouse.getEventButton() == 0 && Mouse.getEventButtonState() && this.mouseY >= this.top && this.mouseY <= this.bottom)
{
int i = (this.width - this.getListWidth()) / 2;
int j = (this.width + this.getListWidth()) / 2;
int k = this.mouseY - this.top - this.headerPadding + (int)this.amountScrolled - 4;
int l = k / this.slotHeight;
if (l < this.getSize() && this.mouseX >= i && this.mouseX <= j && l >= 0 && k >= 0)
{
this.elementClicked(l, false, this.mouseX, this.mouseY);
this.selectedElement = l;
}
else if (this.mouseX >= i && this.mouseX <= j && k < 0)
{
this.clickedHeader(this.mouseX - i, this.mouseY - this.top + (int)this.amountScrolled - 4);
}
}
if (Mouse.isButtonDown(0) && this.getEnabled())
{
if (this.initialClickY == -1)
{
boolean flag1 = true;
if (this.mouseY >= this.top && this.mouseY <= this.bottom)
{
int j2 = (this.width - this.getListWidth()) / 2;
int k2 = (this.width + this.getListWidth()) / 2;
int l2 = this.mouseY - this.top - this.headerPadding + (int)this.amountScrolled - 4;
int i1 = l2 / this.slotHeight;
if (i1 < this.getSize() && this.mouseX >= j2 && this.mouseX <= k2 && i1 >= 0 && l2 >= 0)
{
boolean flag = i1 == this.selectedElement && Minecraft.getSystemTime() - this.lastClicked < 250L;
this.elementClicked(i1, flag, this.mouseX, this.mouseY);
this.selectedElement = i1;
this.lastClicked = Minecraft.getSystemTime();
}
else if (this.mouseX >= j2 && this.mouseX <= k2 && l2 < 0)
{
this.clickedHeader(this.mouseX - j2, this.mouseY - this.top + (int)this.amountScrolled - 4);
flag1 = false;
}
int i3 = this.getScrollBarX();
int j1 = i3 + 6;
if (this.mouseX >= i3 && this.mouseX <= j1)
{
this.scrollMultiplier = -1.0F;
int k1 = this.getMaxScroll();
if (k1 < 1)
{
k1 = 1;
}
int l1 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight());
l1 = MathHelper.clamp(l1, 32, this.bottom - this.top - 8);
this.scrollMultiplier /= (float)(this.bottom - this.top - l1) / (float)k1;
}
else
{
this.scrollMultiplier = 1.0F;
}
if (flag1)
{
this.initialClickY = this.mouseY;
}
else
{
this.initialClickY = -2;
}
}
else
{
this.initialClickY = -2;
}
}
else if (this.initialClickY >= 0)
{
this.amountScrolled -= (float)(this.mouseY - this.initialClickY) * this.scrollMultiplier;
this.initialClickY = this.mouseY;
}
}
else
{
this.initialClickY = -1;
}
int i2 = Mouse.getEventDWheel();
if (i2 != 0)
{
if (i2 > 0)
{
i2 = -1;
}
else if (i2 < 0)
{
i2 = 1;
}
this.amountScrolled += (float)(i2 * this.slotHeight / 2);
}
}
}
public void setEnabled(boolean enabledIn)
{
this.enabled = enabledIn;
}
public boolean getEnabled()
{
return this.enabled;
}
/**
* Gets the width of the list
*/
public int getListWidth()
{
return 220;
}
/**
* Draws the selection box around the selected slot element.
*/
protected void drawSelectionBox(int insideLeft, int insideTop, int mouseXIn, int mouseYIn, float partialTicks)
{
int i = this.getSize();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
for (int j = 0; j < i; ++j)
{
int k = insideTop + j * this.slotHeight + this.headerPadding;
int l = this.slotHeight - 4;
if (k > this.bottom || k + l < this.top)
{
this.updateItemPos(j, insideLeft, k, partialTicks);
}
if (this.showSelectionBox && this.isSelected(j))
{
int i1 = this.left + (this.width / 2 - this.getListWidth() / 2);
int j1 = this.left + this.width / 2 + this.getListWidth() / 2;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableTexture2D();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)i1, (double)(k + l + 2), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j1, (double)(k + l + 2), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)j1, (double)(k - 2), 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)i1, (double)(k - 2), 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex();
bufferbuilder.pos((double)(i1 + 1), (double)(k + l + 1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)(j1 - 1), (double)(k + l + 1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)(j1 - 1), (double)(k - 1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex();
bufferbuilder.pos((double)(i1 + 1), (double)(k - 1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
}
this.drawSlot(j, insideLeft, k, l, mouseXIn, mouseYIn, partialTicks);
}
}
protected int getScrollBarX()
{
return this.width / 2 + 124;
}
/**
* Overlays the background to hide scrolled items
*/
protected void overlayBackground(int startY, int endY, int startAlpha, int endAlpha)
{
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
bufferbuilder.pos((double)this.left, (double)endY, 0.0D).tex(0.0D, (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex();
bufferbuilder.pos((double)(this.left + this.width), (double)endY, 0.0D).tex((double)((float)this.width / 32.0F), (double)((float)endY / 32.0F)).color(64, 64, 64, endAlpha).endVertex();
bufferbuilder.pos((double)(this.left + this.width), (double)startY, 0.0D).tex((double)((float)this.width / 32.0F), (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex();
bufferbuilder.pos((double)this.left, (double)startY, 0.0D).tex(0.0D, (double)((float)startY / 32.0F)).color(64, 64, 64, startAlpha).endVertex();
tessellator.draw();
}
/**
* Sets the left and right bounds of the slot. Param is the left bound, right is calculated as left + width.
*/
public void setSlotXBoundsFromLeft(int leftIn)
{
this.left = leftIn;
this.right = leftIn + this.width;
}
public int getSlotHeight()
{
return this.slotHeight;
}
protected void drawContainerBackground(Tessellator tessellator)
{
BufferBuilder buffer = tessellator.getBuffer();
this.mc.getTextureManager().bindTexture(Gui.OPTIONS_BACKGROUND);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float f = 32.0F;
buffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);
buffer.pos((double)this.left, (double)this.bottom, 0.0D).tex((double)((float)this.left / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
buffer.pos((double)this.right, (double)this.bottom, 0.0D).tex((double)((float)this.right / f), (double)((float)(this.bottom + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
buffer.pos((double)this.right, (double)this.top, 0.0D).tex((double)((float)this.right / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
buffer.pos((double)this.left, (double)this.top, 0.0D).tex((double)((float)this.left / f), (double)((float)(this.top + (int)this.amountScrolled) / f)).color(32, 32, 32, 255).endVertex();
tessellator.draw();
}
}

View File

@@ -0,0 +1,82 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.realms.RealmsScrolledSelectionList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiSlotRealmsProxy extends GuiSlot
{
private final RealmsScrolledSelectionList selectionList;
public GuiSlotRealmsProxy(RealmsScrolledSelectionList selectionListIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn)
{
super(Minecraft.getMinecraft(), widthIn, heightIn, topIn, bottomIn, slotHeightIn);
this.selectionList = selectionListIn;
}
protected int getSize()
{
return this.selectionList.getItemCount();
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
this.selectionList.selectItem(slotIndex, isDoubleClick, mouseX, mouseY);
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return this.selectionList.isSelectedItem(slotIndex);
}
protected void drawBackground()
{
this.selectionList.renderBackground();
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
this.selectionList.renderItem(slotIndex, xPos, yPos, heightIn, mouseXIn, mouseYIn);
}
public int getWidth()
{
return this.width;
}
public int getMouseY()
{
return this.mouseY;
}
public int getMouseX()
{
return this.mouseX;
}
/**
* Return the height of the content being scrolled
*/
protected int getContentHeight()
{
return this.selectionList.getMaxPosition();
}
protected int getScrollBarX()
{
return this.selectionList.getScrollbarPosition();
}
public void handleMouseInput()
{
super.handleMouseInput();
}
}

View File

@@ -0,0 +1,164 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.TreeMap;
import java.util.Map.Entry;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.GameSettings;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiSnooper extends GuiScreen
{
private final GuiScreen lastScreen;
/** Reference to the GameSettings object. */
private final GameSettings game_settings_2;
private final java.util.List<String> keys = Lists.<String>newArrayList();
private final java.util.List<String> values = Lists.<String>newArrayList();
private String title;
private String[] desc;
private GuiSnooper.List list;
private GuiButton toggleButton;
public GuiSnooper(GuiScreen p_i1061_1_, GameSettings p_i1061_2_)
{
this.lastScreen = p_i1061_1_;
this.game_settings_2 = p_i1061_2_;
}
/**
* Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
* window resizes, the buttonList is cleared beforehand.
*/
public void initGui()
{
this.title = I18n.format("options.snooper.title");
String s = I18n.format("options.snooper.desc");
java.util.List<String> list = Lists.<String>newArrayList();
for (String s1 : this.fontRenderer.listFormattedStringToWidth(s, this.width - 30))
{
list.add(s1);
}
this.desc = (String[])list.toArray(new String[list.size()]);
this.keys.clear();
this.values.clear();
this.toggleButton = this.addButton(new GuiButton(1, this.width / 2 - 152, this.height - 30, 150, 20, this.game_settings_2.getKeyBinding(GameSettings.Options.SNOOPER_ENABLED)));
this.buttonList.add(new GuiButton(2, this.width / 2 + 2, this.height - 30, 150, 20, I18n.format("gui.done")));
boolean flag = this.mc.getIntegratedServer() != null && this.mc.getIntegratedServer().getPlayerUsageSnooper() != null;
for (Entry<String, String> entry : (new TreeMap<String, String>(this.mc.getPlayerUsageSnooper().getCurrentStats())).entrySet())
{
this.keys.add((flag ? "C " : "") + (String)entry.getKey());
this.values.add(this.fontRenderer.trimStringToWidth(entry.getValue(), this.width - 220));
}
if (flag)
{
for (Entry<String, String> entry1 : (new TreeMap<String, String>(this.mc.getIntegratedServer().getPlayerUsageSnooper().getCurrentStats())).entrySet())
{
this.keys.add("S " + (String)entry1.getKey());
this.values.add(this.fontRenderer.trimStringToWidth(entry1.getValue(), this.width - 220));
}
}
this.list = new GuiSnooper.List();
}
/**
* Handles mouse input.
*/
public void handleMouseInput() throws IOException
{
super.handleMouseInput();
this.list.handleMouseInput();
}
/**
* Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
*/
protected void actionPerformed(GuiButton button) throws IOException
{
if (button.enabled)
{
if (button.id == 2)
{
this.game_settings_2.saveOptions();
this.game_settings_2.saveOptions();
this.mc.displayGuiScreen(this.lastScreen);
}
if (button.id == 1)
{
this.game_settings_2.setOptionValue(GameSettings.Options.SNOOPER_ENABLED, 1);
this.toggleButton.displayString = this.game_settings_2.getKeyBinding(GameSettings.Options.SNOOPER_ENABLED);
}
}
}
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
this.list.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(this.fontRenderer, this.title, this.width / 2, 8, 16777215);
int i = 22;
for (String s : this.desc)
{
this.drawCenteredString(this.fontRenderer, s, this.width / 2, i, 8421504);
i += this.fontRenderer.FONT_HEIGHT;
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
@SideOnly(Side.CLIENT)
class List extends GuiSlot
{
public List()
{
super(GuiSnooper.this.mc, GuiSnooper.this.width, GuiSnooper.this.height, 80, GuiSnooper.this.height - 40, GuiSnooper.this.fontRenderer.FONT_HEIGHT + 1);
}
protected int getSize()
{
return GuiSnooper.this.keys.size();
}
/**
* The element in the slot that was clicked, boolean for whether it was double clicked or not
*/
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY)
{
}
/**
* Returns true if the element passed in is currently selected
*/
protected boolean isSelected(int slotIndex)
{
return false;
}
protected void drawBackground()
{
}
protected void drawSlot(int slotIndex, int xPos, int yPos, int heightIn, int mouseXIn, int mouseYIn, float partialTicks)
{
GuiSnooper.this.fontRenderer.drawString(GuiSnooper.this.keys.get(slotIndex), 10, yPos, 16777215);
GuiSnooper.this.fontRenderer.drawString(GuiSnooper.this.values.get(slotIndex), 230, yPos, 16777215);
}
protected int getScrollBarX()
{
return this.width - 10;
}
}
}

View File

@@ -0,0 +1,189 @@
package net.minecraft.client.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.spectator.ISpectatorMenuObject;
import net.minecraft.client.gui.spectator.ISpectatorMenuRecipient;
import net.minecraft.client.gui.spectator.SpectatorMenu;
import net.minecraft.client.gui.spectator.categories.SpectatorDetails;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiSpectator extends Gui implements ISpectatorMenuRecipient
{
private static final ResourceLocation WIDGETS = new ResourceLocation("textures/gui/widgets.png");
public static final ResourceLocation SPECTATOR_WIDGETS = new ResourceLocation("textures/gui/spectator_widgets.png");
private final Minecraft mc;
private long lastSelectionTime;
private SpectatorMenu menu;
public GuiSpectator(Minecraft mcIn)
{
this.mc = mcIn;
}
public void onHotbarSelected(int p_175260_1_)
{
this.lastSelectionTime = Minecraft.getSystemTime();
if (this.menu != null)
{
this.menu.selectSlot(p_175260_1_);
}
else
{
this.menu = new SpectatorMenu(this);
}
}
private float getHotbarAlpha()
{
long i = this.lastSelectionTime - Minecraft.getSystemTime() + 5000L;
return MathHelper.clamp((float)i / 2000.0F, 0.0F, 1.0F);
}
public void renderTooltip(ScaledResolution p_175264_1_, float p_175264_2_)
{
if (this.menu != null)
{
float f = this.getHotbarAlpha();
if (f <= 0.0F)
{
this.menu.exit();
}
else
{
int i = p_175264_1_.getScaledWidth() / 2;
float f1 = this.zLevel;
this.zLevel = -90.0F;
float f2 = (float)p_175264_1_.getScaledHeight() - 22.0F * f;
SpectatorDetails spectatordetails = this.menu.getCurrentPage();
this.renderPage(p_175264_1_, f, i, f2, spectatordetails);
this.zLevel = f1;
}
}
}
protected void renderPage(ScaledResolution p_175258_1_, float p_175258_2_, int p_175258_3_, float p_175258_4_, SpectatorDetails p_175258_5_)
{
GlStateManager.enableRescaleNormal();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.color(1.0F, 1.0F, 1.0F, p_175258_2_);
this.mc.getTextureManager().bindTexture(WIDGETS);
this.drawTexturedModalRect((float)(p_175258_3_ - 91), p_175258_4_, 0, 0, 182, 22);
if (p_175258_5_.getSelectedSlot() >= 0)
{
this.drawTexturedModalRect((float)(p_175258_3_ - 91 - 1 + p_175258_5_.getSelectedSlot() * 20), p_175258_4_ - 1.0F, 0, 22, 24, 22);
}
RenderHelper.enableGUIStandardItemLighting();
for (int i = 0; i < 9; ++i)
{
this.renderSlot(i, p_175258_1_.getScaledWidth() / 2 - 90 + i * 20 + 2, p_175258_4_ + 3.0F, p_175258_2_, p_175258_5_.getObject(i));
}
RenderHelper.disableStandardItemLighting();
GlStateManager.disableRescaleNormal();
GlStateManager.disableBlend();
}
private void renderSlot(int p_175266_1_, int p_175266_2_, float p_175266_3_, float p_175266_4_, ISpectatorMenuObject p_175266_5_)
{
this.mc.getTextureManager().bindTexture(SPECTATOR_WIDGETS);
if (p_175266_5_ != SpectatorMenu.EMPTY_SLOT)
{
int i = (int)(p_175266_4_ * 255.0F);
GlStateManager.pushMatrix();
GlStateManager.translate((float)p_175266_2_, p_175266_3_, 0.0F);
float f = p_175266_5_.isEnabled() ? 1.0F : 0.25F;
GlStateManager.color(f, f, f, p_175266_4_);
p_175266_5_.renderIcon(f, i);
GlStateManager.popMatrix();
String s = String.valueOf(this.mc.gameSettings.keyBindsHotbar[p_175266_1_].getDisplayName());
if (i > 3 && p_175266_5_.isEnabled())
{
this.mc.fontRenderer.drawStringWithShadow(s, (float)(p_175266_2_ + 19 - 2 - this.mc.fontRenderer.getStringWidth(s)), p_175266_3_ + 6.0F + 3.0F, 16777215 + (i << 24));
}
}
}
public void renderSelectedItem(ScaledResolution p_175263_1_)
{
int i = (int)(this.getHotbarAlpha() * 255.0F);
if (i > 3 && this.menu != null)
{
ISpectatorMenuObject ispectatormenuobject = this.menu.getSelectedItem();
String s = ispectatormenuobject == SpectatorMenu.EMPTY_SLOT ? this.menu.getSelectedCategory().getPrompt().getFormattedText() : ispectatormenuobject.getSpectatorName().getFormattedText();
if (s != null)
{
int j = (p_175263_1_.getScaledWidth() - this.mc.fontRenderer.getStringWidth(s)) / 2;
int k = p_175263_1_.getScaledHeight() - 35;
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
this.mc.fontRenderer.drawStringWithShadow(s, (float)j, (float)k, 16777215 + (i << 24));
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
}
public void onSpectatorMenuClosed(SpectatorMenu menu)
{
this.menu = null;
this.lastSelectionTime = 0L;
}
public boolean isMenuActive()
{
return this.menu != null;
}
public void onMouseScroll(int p_175259_1_)
{
int i;
for (i = this.menu.getSelectedSlot() + p_175259_1_; i >= 0 && i <= 8 && (this.menu.getItem(i) == SpectatorMenu.EMPTY_SLOT || !this.menu.getItem(i).isEnabled()); i += p_175259_1_)
{
;
}
if (i >= 0 && i <= 8)
{
this.menu.selectSlot(i);
this.lastSelectionTime = Minecraft.getSystemTime();
}
}
public void onMiddleClick()
{
this.lastSelectionTime = Minecraft.getSystemTime();
if (this.isMenuActive())
{
int i = this.menu.getSelectedSlot();
if (i != -1)
{
this.menu.selectSlot(i);
}
}
else
{
this.menu = new SpectatorMenu(this);
}
}
}

View File

@@ -0,0 +1,170 @@
package net.minecraft.client.gui;
import com.google.common.collect.Lists;
import java.util.Iterator;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.ISoundEventListener;
import net.minecraft.client.audio.SoundEventAccessor;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiSubtitleOverlay extends Gui implements ISoundEventListener
{
private final Minecraft client;
private final List<GuiSubtitleOverlay.Subtitle> subtitles = Lists.<GuiSubtitleOverlay.Subtitle>newArrayList();
private boolean enabled;
public GuiSubtitleOverlay(Minecraft clientIn)
{
this.client = clientIn;
}
public void renderSubtitles(ScaledResolution resolution)
{
if (!this.enabled && this.client.gameSettings.showSubtitles)
{
this.client.getSoundHandler().addListener(this);
this.enabled = true;
}
else if (this.enabled && !this.client.gameSettings.showSubtitles)
{
this.client.getSoundHandler().removeListener(this);
this.enabled = false;
}
if (this.enabled && !this.subtitles.isEmpty())
{
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
Vec3d vec3d = new Vec3d(this.client.player.posX, this.client.player.posY + (double)this.client.player.getEyeHeight(), this.client.player.posZ);
Vec3d vec3d1 = (new Vec3d(0.0D, 0.0D, -1.0D)).rotatePitch(-this.client.player.rotationPitch * 0.017453292F).rotateYaw(-this.client.player.rotationYaw * 0.017453292F);
Vec3d vec3d2 = (new Vec3d(0.0D, 1.0D, 0.0D)).rotatePitch(-this.client.player.rotationPitch * 0.017453292F).rotateYaw(-this.client.player.rotationYaw * 0.017453292F);
Vec3d vec3d3 = vec3d1.crossProduct(vec3d2);
int i = 0;
int j = 0;
Iterator<GuiSubtitleOverlay.Subtitle> iterator = this.subtitles.iterator();
while (iterator.hasNext())
{
GuiSubtitleOverlay.Subtitle guisubtitleoverlay$subtitle = iterator.next();
if (guisubtitleoverlay$subtitle.getStartTime() + 3000L <= Minecraft.getSystemTime())
{
iterator.remove();
}
else
{
j = Math.max(j, this.client.fontRenderer.getStringWidth(guisubtitleoverlay$subtitle.getString()));
}
}
j = j + this.client.fontRenderer.getStringWidth("<") + this.client.fontRenderer.getStringWidth(" ") + this.client.fontRenderer.getStringWidth(">") + this.client.fontRenderer.getStringWidth(" ");
for (GuiSubtitleOverlay.Subtitle guisubtitleoverlay$subtitle1 : this.subtitles)
{
int k = 255;
String s = guisubtitleoverlay$subtitle1.getString();
Vec3d vec3d4 = guisubtitleoverlay$subtitle1.getLocation().subtract(vec3d).normalize();
double d0 = -vec3d3.dotProduct(vec3d4);
double d1 = -vec3d1.dotProduct(vec3d4);
boolean flag = d1 > 0.5D;
int l = j / 2;
int i1 = this.client.fontRenderer.FONT_HEIGHT;
int j1 = i1 / 2;
float f = 1.0F;
int k1 = this.client.fontRenderer.getStringWidth(s);
int l1 = MathHelper.floor(MathHelper.clampedLerp(255.0D, 75.0D, (double)((float)(Minecraft.getSystemTime() - guisubtitleoverlay$subtitle1.getStartTime()) / 3000.0F)));
int i2 = l1 << 16 | l1 << 8 | l1;
GlStateManager.pushMatrix();
GlStateManager.translate((float)resolution.getScaledWidth() - (float)l * 1.0F - 2.0F, (float)(resolution.getScaledHeight() - 30) - (float)(i * (i1 + 1)) * 1.0F, 0.0F);
GlStateManager.scale(1.0F, 1.0F, 1.0F);
drawRect(-l - 1, -j1 - 1, l + 1, j1 + 1, -872415232);
GlStateManager.enableBlend();
if (!flag)
{
if (d0 > 0.0D)
{
this.client.fontRenderer.drawString(">", l - this.client.fontRenderer.getStringWidth(">"), -j1, i2 + -16777216);
}
else if (d0 < 0.0D)
{
this.client.fontRenderer.drawString("<", -l, -j1, i2 + -16777216);
}
}
this.client.fontRenderer.drawString(s, -k1 / 2, -j1, i2 + -16777216);
GlStateManager.popMatrix();
++i;
}
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
public void soundPlay(ISound soundIn, SoundEventAccessor accessor)
{
if (accessor.getSubtitle() != null)
{
String s = accessor.getSubtitle().getFormattedText();
if (!this.subtitles.isEmpty())
{
for (GuiSubtitleOverlay.Subtitle guisubtitleoverlay$subtitle : this.subtitles)
{
if (guisubtitleoverlay$subtitle.getString().equals(s))
{
guisubtitleoverlay$subtitle.refresh(new Vec3d((double)soundIn.getXPosF(), (double)soundIn.getYPosF(), (double)soundIn.getZPosF()));
return;
}
}
}
this.subtitles.add(new GuiSubtitleOverlay.Subtitle(s, new Vec3d((double)soundIn.getXPosF(), (double)soundIn.getYPosF(), (double)soundIn.getZPosF())));
}
}
@SideOnly(Side.CLIENT)
public class Subtitle
{
private final String subtitle;
private long startTime;
private Vec3d location;
public Subtitle(String subtitleIn, Vec3d locationIn)
{
this.subtitle = subtitleIn;
this.location = locationIn;
this.startTime = Minecraft.getSystemTime();
}
public String getString()
{
return this.subtitle;
}
public long getStartTime()
{
return this.startTime;
}
public Vec3d getLocation()
{
return this.location;
}
public void refresh(Vec3d locationIn)
{
this.location = locationIn;
this.startTime = Minecraft.getSystemTime();
}
}
}

View File

@@ -0,0 +1,830 @@
package net.minecraft.client.gui;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiTextField extends Gui
{
private final int id;
private final FontRenderer fontRenderer;
public int x;
public int y;
/** The width of this text field. */
public int width;
public int height;
/** Has the current text being edited on the textbox. */
private String text = "";
private int maxStringLength = 32;
private int cursorCounter;
private boolean enableBackgroundDrawing = true;
/** if true the textbox can lose focus by clicking elsewhere on the screen */
private boolean canLoseFocus = true;
/** If this value is true along with isEnabled, keyTyped will process the keys. */
private boolean isFocused;
/** If this value is true along with isFocused, keyTyped will process the keys. */
private boolean isEnabled = true;
/** The current character index that should be used as start of the rendered text. */
private int lineScrollOffset;
private int cursorPosition;
/** other selection position, maybe the same as the cursor */
private int selectionEnd;
private int enabledColor = 14737632;
private int disabledColor = 7368816;
/** True if this textbox is visible */
private boolean visible = true;
private GuiPageButtonList.GuiResponder guiResponder;
/** Called to check if the text is valid */
private Predicate<String> validator = Predicates.<String>alwaysTrue();
public GuiTextField(int componentId, FontRenderer fontrendererObj, int x, int y, int par5Width, int par6Height)
{
this.id = componentId;
this.fontRenderer = fontrendererObj;
this.x = x;
this.y = y;
this.width = par5Width;
this.height = par6Height;
}
/**
* Sets the GuiResponder associated with this text box.
*/
public void setGuiResponder(GuiPageButtonList.GuiResponder guiResponderIn)
{
this.guiResponder = guiResponderIn;
}
/**
* Increments the cursor counter
*/
public void updateCursorCounter()
{
++this.cursorCounter;
}
/**
* Sets the text of the textbox, and moves the cursor to the end.
*/
public void setText(String textIn)
{
if (this.validator.apply(textIn))
{
if (textIn.length() > this.maxStringLength)
{
this.text = textIn.substring(0, this.maxStringLength);
}
else
{
this.text = textIn;
}
this.setCursorPositionEnd();
}
}
/**
* Returns the contents of the textbox
*/
public String getText()
{
return this.text;
}
/**
* returns the text between the cursor and selectionEnd
*/
public String getSelectedText()
{
int i = this.cursorPosition < this.selectionEnd ? this.cursorPosition : this.selectionEnd;
int j = this.cursorPosition < this.selectionEnd ? this.selectionEnd : this.cursorPosition;
return this.text.substring(i, j);
}
public void setValidator(Predicate<String> theValidator)
{
this.validator = theValidator;
}
/**
* Adds the given text after the cursor, or replaces the currently selected text if there is a selection.
*/
public void writeText(String textToWrite)
{
String s = "";
String s1 = ChatAllowedCharacters.filterAllowedCharacters(textToWrite);
int i = this.cursorPosition < this.selectionEnd ? this.cursorPosition : this.selectionEnd;
int j = this.cursorPosition < this.selectionEnd ? this.selectionEnd : this.cursorPosition;
int k = this.maxStringLength - this.text.length() - (i - j);
if (!this.text.isEmpty())
{
s = s + this.text.substring(0, i);
}
int l;
if (k < s1.length())
{
s = s + s1.substring(0, k);
l = k;
}
else
{
s = s + s1;
l = s1.length();
}
if (!this.text.isEmpty() && j < this.text.length())
{
s = s + this.text.substring(j);
}
if (this.validator.apply(s))
{
this.text = s;
this.moveCursorBy(i - this.selectionEnd + l);
this.setResponderEntryValue(this.id, this.text);
}
}
/**
* Notifies this text box's {@linkplain GuiPageButtonList.GuiResponder responder} that the text has changed.
*/
public void setResponderEntryValue(int idIn, String textIn)
{
if (this.guiResponder != null)
{
this.guiResponder.setEntryValue(idIn, textIn);
}
}
/**
* Deletes the given number of words from the current cursor's position, unless there is currently a selection, in
* which case the selection is deleted instead.
*/
public void deleteWords(int num)
{
if (!this.text.isEmpty())
{
if (this.selectionEnd != this.cursorPosition)
{
this.writeText("");
}
else
{
this.deleteFromCursor(this.getNthWordFromCursor(num) - this.cursorPosition);
}
}
}
/**
* Deletes the given number of characters from the current cursor's position, unless there is currently a selection,
* in which case the selection is deleted instead.
*/
public void deleteFromCursor(int num)
{
if (!this.text.isEmpty())
{
if (this.selectionEnd != this.cursorPosition)
{
this.writeText("");
}
else
{
boolean flag = num < 0;
int i = flag ? this.cursorPosition + num : this.cursorPosition;
int j = flag ? this.cursorPosition : this.cursorPosition + num;
String s = "";
if (i >= 0)
{
s = this.text.substring(0, i);
}
if (j < this.text.length())
{
s = s + this.text.substring(j);
}
if (this.validator.apply(s))
{
this.text = s;
if (flag)
{
this.moveCursorBy(num);
}
this.setResponderEntryValue(this.id, this.text);
}
}
}
}
public int getId()
{
return this.id;
}
/**
* Gets the starting index of the word at the specified number of words away from the cursor position.
*/
public int getNthWordFromCursor(int numWords)
{
return this.getNthWordFromPos(numWords, this.getCursorPosition());
}
/**
* Gets the starting index of the word at a distance of the specified number of words away from the given position.
*/
public int getNthWordFromPos(int n, int pos)
{
return this.getNthWordFromPosWS(n, pos, true);
}
/**
* Like getNthWordFromPos (which wraps this), but adds option for skipping consecutive spaces
*/
public int getNthWordFromPosWS(int n, int pos, boolean skipWs)
{
int i = pos;
boolean flag = n < 0;
int j = Math.abs(n);
for (int k = 0; k < j; ++k)
{
if (!flag)
{
int l = this.text.length();
i = this.text.indexOf(32, i);
if (i == -1)
{
i = l;
}
else
{
while (skipWs && i < l && this.text.charAt(i) == ' ')
{
++i;
}
}
}
else
{
while (skipWs && i > 0 && this.text.charAt(i - 1) == ' ')
{
--i;
}
while (i > 0 && this.text.charAt(i - 1) != ' ')
{
--i;
}
}
}
return i;
}
/**
* Moves the text cursor by a specified number of characters and clears the selection
*/
public void moveCursorBy(int num)
{
this.setCursorPosition(this.selectionEnd + num);
}
/**
* Sets the current position of the cursor.
*/
public void setCursorPosition(int pos)
{
this.cursorPosition = pos;
int i = this.text.length();
this.cursorPosition = MathHelper.clamp(this.cursorPosition, 0, i);
this.setSelectionPos(this.cursorPosition);
}
/**
* Moves the cursor to the very start of this text box.
*/
public void setCursorPositionZero()
{
this.setCursorPosition(0);
}
/**
* Moves the cursor to the very end of this text box.
*/
public void setCursorPositionEnd()
{
this.setCursorPosition(this.text.length());
}
/**
* Call this method from your GuiScreen to process the keys into the textbox
*/
public boolean textboxKeyTyped(char typedChar, int keyCode)
{
if (!this.isFocused)
{
return false;
}
else if (GuiScreen.isKeyComboCtrlA(keyCode))
{
this.setCursorPositionEnd();
this.setSelectionPos(0);
return true;
}
else if (GuiScreen.isKeyComboCtrlC(keyCode))
{
GuiScreen.setClipboardString(this.getSelectedText());
return true;
}
else if (GuiScreen.isKeyComboCtrlV(keyCode))
{
if (this.isEnabled)
{
this.writeText(GuiScreen.getClipboardString());
}
return true;
}
else if (GuiScreen.isKeyComboCtrlX(keyCode))
{
GuiScreen.setClipboardString(this.getSelectedText());
if (this.isEnabled)
{
this.writeText("");
}
return true;
}
else
{
switch (keyCode)
{
case 14:
if (GuiScreen.isCtrlKeyDown())
{
if (this.isEnabled)
{
this.deleteWords(-1);
}
}
else if (this.isEnabled)
{
this.deleteFromCursor(-1);
}
return true;
case 199:
if (GuiScreen.isShiftKeyDown())
{
this.setSelectionPos(0);
}
else
{
this.setCursorPositionZero();
}
return true;
case 203:
if (GuiScreen.isShiftKeyDown())
{
if (GuiScreen.isCtrlKeyDown())
{
this.setSelectionPos(this.getNthWordFromPos(-1, this.getSelectionEnd()));
}
else
{
this.setSelectionPos(this.getSelectionEnd() - 1);
}
}
else if (GuiScreen.isCtrlKeyDown())
{
this.setCursorPosition(this.getNthWordFromCursor(-1));
}
else
{
this.moveCursorBy(-1);
}
return true;
case 205:
if (GuiScreen.isShiftKeyDown())
{
if (GuiScreen.isCtrlKeyDown())
{
this.setSelectionPos(this.getNthWordFromPos(1, this.getSelectionEnd()));
}
else
{
this.setSelectionPos(this.getSelectionEnd() + 1);
}
}
else if (GuiScreen.isCtrlKeyDown())
{
this.setCursorPosition(this.getNthWordFromCursor(1));
}
else
{
this.moveCursorBy(1);
}
return true;
case 207:
if (GuiScreen.isShiftKeyDown())
{
this.setSelectionPos(this.text.length());
}
else
{
this.setCursorPositionEnd();
}
return true;
case 211:
if (GuiScreen.isCtrlKeyDown())
{
if (this.isEnabled)
{
this.deleteWords(1);
}
}
else if (this.isEnabled)
{
this.deleteFromCursor(1);
}
return true;
default:
if (ChatAllowedCharacters.isAllowedCharacter(typedChar))
{
if (this.isEnabled)
{
this.writeText(Character.toString(typedChar));
}
return true;
}
else
{
return false;
}
}
}
}
/**
* Called when mouse is clicked, regardless as to whether it is over this button or not.
*/
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton)
{
boolean flag = mouseX >= this.x && mouseX < this.x + this.width && mouseY >= this.y && mouseY < this.y + this.height;
if (this.canLoseFocus)
{
this.setFocused(flag);
}
if (this.isFocused && flag && mouseButton == 0)
{
int i = mouseX - this.x;
if (this.enableBackgroundDrawing)
{
i -= 4;
}
String s = this.fontRenderer.trimStringToWidth(this.text.substring(this.lineScrollOffset), this.getWidth());
this.setCursorPosition(this.fontRenderer.trimStringToWidth(s, i).length() + this.lineScrollOffset);
return true;
}
else
{
return false;
}
}
/**
* Draws the textbox
*/
public void drawTextBox()
{
if (this.getVisible())
{
if (this.getEnableBackgroundDrawing())
{
drawRect(this.x - 1, this.y - 1, this.x + this.width + 1, this.y + this.height + 1, -6250336);
drawRect(this.x, this.y, this.x + this.width, this.y + this.height, -16777216);
}
int i = this.isEnabled ? this.enabledColor : this.disabledColor;
int j = this.cursorPosition - this.lineScrollOffset;
int k = this.selectionEnd - this.lineScrollOffset;
String s = this.fontRenderer.trimStringToWidth(this.text.substring(this.lineScrollOffset), this.getWidth());
boolean flag = j >= 0 && j <= s.length();
boolean flag1 = this.isFocused && this.cursorCounter / 6 % 2 == 0 && flag;
int l = this.enableBackgroundDrawing ? this.x + 4 : this.x;
int i1 = this.enableBackgroundDrawing ? this.y + (this.height - 8) / 2 : this.y;
int j1 = l;
if (k > s.length())
{
k = s.length();
}
if (!s.isEmpty())
{
String s1 = flag ? s.substring(0, j) : s;
j1 = this.fontRenderer.drawStringWithShadow(s1, (float)l, (float)i1, i);
}
boolean flag2 = this.cursorPosition < this.text.length() || this.text.length() >= this.getMaxStringLength();
int k1 = j1;
if (!flag)
{
k1 = j > 0 ? l + this.width : l;
}
else if (flag2)
{
k1 = j1 - 1;
--j1;
}
if (!s.isEmpty() && flag && j < s.length())
{
j1 = this.fontRenderer.drawStringWithShadow(s.substring(j), (float)j1, (float)i1, i);
}
if (flag1)
{
if (flag2)
{
Gui.drawRect(k1, i1 - 1, k1 + 1, i1 + 1 + this.fontRenderer.FONT_HEIGHT, -3092272);
}
else
{
this.fontRenderer.drawStringWithShadow("_", (float)k1, (float)i1, i);
}
}
if (k != j)
{
int l1 = l + this.fontRenderer.getStringWidth(s.substring(0, k));
this.drawSelectionBox(k1, i1 - 1, l1 - 1, i1 + 1 + this.fontRenderer.FONT_HEIGHT);
}
}
}
/**
* Draws the blue selection box.
*/
private void drawSelectionBox(int startX, int startY, int endX, int endY)
{
if (startX < endX)
{
int i = startX;
startX = endX;
endX = i;
}
if (startY < endY)
{
int j = startY;
startY = endY;
endY = j;
}
if (endX > this.x + this.width)
{
endX = this.x + this.width;
}
if (startX > this.x + this.width)
{
startX = this.x + this.width;
}
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferbuilder = tessellator.getBuffer();
GlStateManager.color(0.0F, 0.0F, 255.0F, 255.0F);
GlStateManager.disableTexture2D();
GlStateManager.enableColorLogic();
GlStateManager.colorLogicOp(GlStateManager.LogicOp.OR_REVERSE);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION);
bufferbuilder.pos((double)startX, (double)endY, 0.0D).endVertex();
bufferbuilder.pos((double)endX, (double)endY, 0.0D).endVertex();
bufferbuilder.pos((double)endX, (double)startY, 0.0D).endVertex();
bufferbuilder.pos((double)startX, (double)startY, 0.0D).endVertex();
tessellator.draw();
GlStateManager.disableColorLogic();
GlStateManager.enableTexture2D();
}
/**
* Sets the maximum length for the text in this text box. If the current text is longer than this length, the
* current text will be trimmed.
*/
public void setMaxStringLength(int length)
{
this.maxStringLength = length;
if (this.text.length() > length)
{
this.text = this.text.substring(0, length);
}
}
/**
* returns the maximum number of character that can be contained in this textbox
*/
public int getMaxStringLength()
{
return this.maxStringLength;
}
/**
* returns the current position of the cursor
*/
public int getCursorPosition()
{
return this.cursorPosition;
}
/**
* Gets whether the background and outline of this text box should be drawn (true if so).
*/
public boolean getEnableBackgroundDrawing()
{
return this.enableBackgroundDrawing;
}
/**
* Sets whether or not the background and outline of this text box should be drawn.
*/
public void setEnableBackgroundDrawing(boolean enableBackgroundDrawingIn)
{
this.enableBackgroundDrawing = enableBackgroundDrawingIn;
}
/**
* Sets the color to use when drawing this text box's text. A different color is used if this text box is disabled.
*/
public void setTextColor(int color)
{
this.enabledColor = color;
}
/**
* Sets the color to use for text in this text box when this text box is disabled.
*/
public void setDisabledTextColour(int color)
{
this.disabledColor = color;
}
/**
* Sets focus to this gui element
*/
public void setFocused(boolean isFocusedIn)
{
if (isFocusedIn && !this.isFocused)
{
this.cursorCounter = 0;
}
this.isFocused = isFocusedIn;
if (Minecraft.getMinecraft().currentScreen != null)
{
Minecraft.getMinecraft().currentScreen.setFocused(isFocusedIn);
}
}
/**
* Getter for the focused field
*/
public boolean isFocused()
{
return this.isFocused;
}
/**
* Sets whether this text box is enabled. Disabled text boxes cannot be typed in.
*/
public void setEnabled(boolean enabled)
{
this.isEnabled = enabled;
}
/**
* the side of the selection that is not the cursor, may be the same as the cursor
*/
public int getSelectionEnd()
{
return this.selectionEnd;
}
/**
* returns the width of the textbox depending on if background drawing is enabled
*/
public int getWidth()
{
return this.getEnableBackgroundDrawing() ? this.width - 8 : this.width;
}
/**
* Sets the position of the selection anchor (the selection anchor and the cursor position mark the edges of the
* selection). If the anchor is set beyond the bounds of the current text, it will be put back inside.
*/
public void setSelectionPos(int position)
{
int i = this.text.length();
if (position > i)
{
position = i;
}
if (position < 0)
{
position = 0;
}
this.selectionEnd = position;
if (this.fontRenderer != null)
{
if (this.lineScrollOffset > i)
{
this.lineScrollOffset = i;
}
int j = this.getWidth();
String s = this.fontRenderer.trimStringToWidth(this.text.substring(this.lineScrollOffset), j);
int k = s.length() + this.lineScrollOffset;
if (position == this.lineScrollOffset)
{
this.lineScrollOffset -= this.fontRenderer.trimStringToWidth(this.text, j, true).length();
}
if (position > k)
{
this.lineScrollOffset += position - k;
}
else if (position <= this.lineScrollOffset)
{
this.lineScrollOffset -= this.lineScrollOffset - position;
}
this.lineScrollOffset = MathHelper.clamp(this.lineScrollOffset, 0, i);
}
}
/**
* Sets whether this text box loses focus when something other than it is clicked.
*/
public void setCanLoseFocus(boolean canLoseFocusIn)
{
this.canLoseFocus = canLoseFocusIn;
}
/**
* returns true if this textbox is visible
*/
public boolean getVisible()
{
return this.visible;
}
/**
* Sets whether or not this textbox is visible
*/
public void setVisible(boolean isVisible)
{
this.visible = isVisible;
}
}

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