Skip to content

Instantly share code, notes, and snippets.

@BoogieMonster1O1
Created May 14, 2020 13:00
Show Gist options
  • Save BoogieMonster1O1/f945b727534138cfbae9958365f55cb4 to your computer and use it in GitHub Desktop.
Save BoogieMonster1O1/f945b727534138cfbae9958365f55cb4 to your computer and use it in GitHub Desktop.
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
import io.github.cottonmc.cotton.gui.widget.WLabel;
import io.github.cottonmc.cotton.gui.widget.WListPanel;
import io.github.cottonmc.cotton.gui.widget.WPlainPanel;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.world.Difficulty;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.level.LevelProperties;
import java.util.LinkedList;
import java.util.List;
import java.util.function.BiConsumer;
import static java.lang.Math.floor;
import static net.minecraft.client.MinecraftClient.getInstance;
import static net.minecraft.world.GameRules.*;
import static boogie.utilmod.screens.WorldInfoScreen.GamerulesList.*;
public class WorldInfoScreen extends LightweightGuiDescription {
WorldInfoScreen(){
WPlainPanel root = new WPlainPanel();
root.setSize(356,204);
setRootPanel(root);
PlayerEntity player = getInstance().player;
World world;
assert player != null;
world = player.world;
Biome playerbiome = world.getBiome(player.getBlockPos());
Difficulty difficulty = world.getDifficulty();
long time = world.getTimeOfDay();
boolean raining = world.isRaining();
boolean thundering = world.isThundering();
String weather = I18n.translate("gui.utilities.world.clear");
if(raining) weather = I18n.translate("gui.utilities.world.raining");
if(thundering) weather = I18n.translate("gui.utilities.world.thundering");
double x = player.getX();
x = floor(x*10000) / 10000.0;
double y = player.getY();
y = floor(y*10000) / 10000.0;
double z = player.getZ();
z = floor(z*10000) / 10000.0;
String biome = playerbiome.toString();
String diff = difficulty.toString();
String wtime = Long.toString(time);
String wthr = weather;
String posX = Double.toString(x);
String posY = Double.toString(y);
String posZ = Double.toString(z);
biome = biome.replaceAll("net.minecraft.world.biome.","");
biome = biome.replaceAll("Biome","");
WLabel biomeLabel = new WLabel(I18n.translate("gui.utilities.world.biome") + biome);
WLabel diffLabel = new WLabel(I18n.translate("gui.utilities.world.difficulty") + diff);
WLabel wtimeLabel = new WLabel(I18n.translate("gui.utilities.world.time")+ wtime);
WLabel wthrLabel = new WLabel(I18n.translate("gui.utilities.world.weather") + wthr);
WLabel posXLabel = new WLabel(I18n.translate("gui.utilities.world.posx") + posX);
WLabel posYLabel = new WLabel(I18n.translate("gui.utilities.world.posy") + posY);
WLabel posZLabel = new WLabel(I18n.translate("gui.utilities.world.posz") + posZ);
root.add(posXLabel,210,15,8,1);
root.add(posYLabel,210,30,8,1);
root.add(posZLabel,210,45,8,1);
root.add(wthrLabel,210,60,8,1);
root.add(diffLabel,210,75,8,1);
root.add(biomeLabel,210,90,8,1);
root.add(wtimeLabel,210,105,8,1);
List<String> list = new LinkedList<>();
assert getInstance().player != null;
LevelProperties properties = getInstance().player.world.getLevelProperties();
GameRules rules = properties.getGameRules();
list.add(I18n.translate("gui.utilities.world.firespread") + rules.getBoolean(DO_FIRE_TICK));
list.add(I18n.translate("gui.utilities.world.mobgrief") + rules.getBoolean(MOB_GRIEFING));
list.add(I18n.translate("gui.utilities.world.keepinv") + rules.getBoolean(KEEP_INVENTORY));
list.add(I18n.translate("gui.utilities.world.mobspawn") + rules.getBoolean(DO_MOB_SPAWNING));
list.add(I18n.translate("gui.utilities.world.mobloot") + rules.getBoolean(DO_MOB_LOOT));
list.add(I18n.translate("gui.utilities.world.tiledrops") + rules.getBoolean(DO_TILE_DROPS));
list.add(I18n.translate("gui.utilities.world.entdrops") + rules.getBoolean(DO_ENTITY_DROPS));
list.add(I18n.translate("gui.utilities.world.cmdoutput") + rules.getBoolean(COMMAND_BLOCK_OUTPUT));
list.add(I18n.translate("gui.utilities.world.regen") + rules.getBoolean(NATURAL_REGENERATION));
list.add(I18n.translate("gui.utilities.world.daycycle") + rules.getBoolean(DO_DAYLIGHT_CYCLE));
list.add(I18n.translate("gui.utilities.world.admincmd") + rules.getBoolean(LOG_ADMIN_COMMANDS));
list.add(I18n.translate("gui.utilities.world.deathmsg") + rules.getBoolean(SHOW_DEATH_MESSAGES));
list.add(I18n.translate("gui.utilities.world.randomtick") + rules.getInt(RANDOM_TICK_SPEED));
list.add(I18n.translate("gui.utilities.world.cmdfeedback") + rules.getBoolean(SEND_COMMAND_FEEDBACK));
list.add(I18n.translate("gui.utilities.world.debuginfo") + rules.getBoolean(REDUCED_DEBUG_INFO));
list.add(I18n.translate("gui.utilities.world.genchunks") + rules.getBoolean(SPECTATORS_GENERATE_CHUNKS));
list.add(I18n.translate("gui.utilities.world.spawnrad") + rules.getInt(SPAWN_RADIUS));
list.add(I18n.translate("gui.utilities.world.entitycram") + rules.getInt(MAX_ENTITY_CRAMMING));
list.add(I18n.translate("gui.utilities.world.weathercyc") + rules.getBoolean(DO_WEATHER_CYCLE));
list.add(I18n.translate("gui.utilities.world.limited") + rules.getBoolean(DO_LIMITED_CRAFTING));
list.add(I18n.translate("gui.utilities.world.chainlength") + rules.getInt(MAX_COMMAND_CHAIN_LENGTH));
list.add(I18n.translate("gui.utilities.world.advancements") + rules.getBoolean(ANNOUNCE_ADVANCEMENTS));
list.add(I18n.translate("gui.utilities.world.raids") + rules.getBoolean(DISABLE_RAIDS));
list.add(I18n.translate("gui.utilities.world.insomnia") + rules.getBoolean(DO_INSOMNIA));
list.add(I18n.translate("gui.utilities.world.respawn") + rules.getBoolean(DO_IMMEDIATE_RESPAWN));
list.add(I18n.translate("gui.utilities.world.drown") + rules.getBoolean(DROWNING_DAMAGE));
list.add(I18n.translate("gui.utilities.world.fall") + rules.getBoolean(FALL_DAMAGE));
list.add(I18n.translate("gui.utilities.world.fire") + rules.getBoolean(FIRE_DAMAGE));
list.add(I18n.translate("gui.utilities.world.patrol") + rules.getBoolean(DO_PATROL_SPAWNING));
list.add(I18n.translate("gui.utilities.world.trader") + rules.getBoolean(DO_TRADER_SPAWNING));
BiConsumer<String,GamerulesList> bc = (strinj,gl)->{
gl.gList.setText(new LiteralText(strinj));
gl.add(gl.gList,10,10,100,15);
};
WListPanel<String,GamerulesList> gamerulesListWListPanel= new WListPanel<>(list,GamerulesList::new,bc);
root.add(gamerulesListWListPanel,10,35,100,180);
root.validate(this);
}
@Override
public void addPainters() {
getRootPanel().setBackgroundPainter(BackgroundPainter.VANILLA);
}
static class GamerulesList extends WGridPanel{
WLabel gList;
GamerulesList(){
gList = new WLabel("");
this.add(gList, 1, 2, 1, 10);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment