Jump to content

PlanetTeamSpeak

Members
  • Posts

    52
  • Joined

  • Last visited

Posts posted by PlanetTeamSpeak

  1. In a command.

    fakeplayer.java

    package com.ptsmods.morecommands.commands;
    
    import java.util.ArrayList;
    import java.util.UUID;
    
    import com.mojang.authlib.GameProfile;
    import com.mojang.util.UUIDTypeAdapter;
    import com.ptsmods.morecommands.miscellaneous.CommandType;
    import com.ptsmods.morecommands.miscellaneous.PacketDispatcher;
    import com.ptsmods.morecommands.miscellaneous.Permission;
    import com.ptsmods.morecommands.miscellaneous.Reference;
    import com.ptsmods.morecommands.miscellaneous.SPacketRegisterFakePlayer;
    
    import net.minecraft.command.ICommandSender;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraft.network.EnumPacketDirection;
    import net.minecraft.network.NetHandlerPlayServer;
    import net.minecraft.network.NetworkManager;
    import net.minecraft.server.MinecraftServer;
    import net.minecraft.server.management.PlayerInteractionManager;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.world.GameType;
    
    public class fakePlayer {
    
    	public fakePlayer() {
    	}
    
    	public static class CommandfakePlayer extends com.ptsmods.morecommands.miscellaneous.CommandBase {
    
    		@Override
    		public java.util.List getAliases() {
    			ArrayList aliases = new ArrayList();
    			return aliases;
    		}
    
    		@Override
    		public java.util.List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
    			return new ArrayList();
    		}
    
    		@Override
    		public String getName() {
    			return "fakeplayer";
    		}
    
    		@Override
    		public String getUsage(ICommandSender sender) {
    			return usage;
    		}
    
    		@Override
    		public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    			if (args.length != 0) {
    				if (args[0].length() > 16) Reference.sendMessage(sender, "The name has to be 16 characters at most.");
    				else {
    					Reference.sendMessage(sender, "Creating the fake player, please stand still, this will only take a few seconds.");
    					EntityPlayer player = (EntityPlayer) sender;
    					String uuid = Reference.getUUIDFromName(args[0]);
    					GameProfile profile = new GameProfile(uuid == null ? UUID.randomUUID() : UUIDTypeAdapter.fromString(uuid), args[0]);
    					EntityPlayerMP fakePlayer = new EntityPlayerMP(server, server.getWorld(player.dimension), profile, new PlayerInteractionManager(player.world));
    					NetworkManager netManager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
    					server.getPlayerList().initializeConnectionToPlayer(netManager, fakePlayer, new NetHandlerPlayServer(server, netManager, fakePlayer));
    					Reference.fakePlayers.add(fakePlayer);
    					for (EntityPlayerMP player1 : server.getPlayerList().getPlayers())
    						if (!Reference.fakePlayers.contains(player1)) PacketDispatcher.sendTo(new SPacketRegisterFakePlayer(fakePlayer), player1);
    					fakePlayer.setPositionAndRotation(0, 0, 0, player.rotationYaw, player.rotationPitch);
    					fakePlayer.setPositionAndUpdate(player.posX, player.posY, player.posZ);
    					fakePlayer.setGameType(GameType.CREATIVE);
    					Reference.sendMessage(sender, "The player " + fakePlayer.getName() + " has been made with the UUID " + fakePlayer.getUniqueID().toString() + ".");
    				}
    			} else Reference.sendCommandUsage(sender, usage);
    		}
    
    		@Override
    		public CommandType getCommandType() {
    			return CommandType.SERVER;
    		}
    
    		@Override
    		public Permission getPermission() {
    			return new Permission(Reference.MOD_ID, "fakeplayer", "Permission to use the fakeplayer command.", true);
    		}
    
    		private String usage = "/fakeplayer <name> Creates a fake player.";
    
    	}
    
    }

     

  2. I have made a custom packet using Forge's SimpleImpl packet system which is supposed to send a packet from the server to the client, but nothing seems to be happening. Am I doing something wrong?

    SPacketRegisterFakePlayer.java:

    package com.ptsmods.morecommands.miscellaneous;
    
    import java.nio.charset.Charset;
    import java.util.UUID;
    
    import com.ptsmods.morecommands.miscellaneous.Reference.LogType;
    
    import io.netty.buffer.ByteBuf;
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraftforge.fml.common.FMLCommonHandler;
    import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
    import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
    import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
    
    public class SPacketRegisterFakePlayer implements IMessage {
    
    	private EntityPlayerMP player;
    
    	public SPacketRegisterFakePlayer() {
    
    	}
    
    	public SPacketRegisterFakePlayer(EntityPlayerMP player) {
    		this.player = player;
    	}
    
    	@Override
    	public void fromBytes(ByteBuf buf) {
    		UUID id = UUID.fromString(buf.readCharSequence(buf.readableBytes(), Charset.defaultCharset()).toString());
    		Reference.print(LogType.INFO, "Reading packet data.", id.toString());
    		try {
    			player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(id);
    		} catch (Throwable e) {
    			e.printStackTrace();
    			return;
    		}
    	}
    
    	@Override
    	public void toBytes(ByteBuf buf) {
    		Reference.print(LogType.INFO, "Writing packet data.");
    		buf.writeCharSequence(player.getUniqueID().toString(), Charset.defaultCharset());
    	}
    
    	public EntityPlayerMP getPlayer() {
    		return player;
    	}
    
    	public static class Handler implements IMessageHandler<SPacketRegisterFakePlayer, IMessage> {
    
    		@Override
    		public IMessage onMessage(SPacketRegisterFakePlayer message, MessageContext ctx) {
    			Reference.print(LogType.INFO, "Processing packet data.");
    			EntityPlayerMP player = message.getPlayer();
    			Reference.fakePlayers.add(player);
    			return null;
    		}
    	}
    
    }

    PacketDispatcher.java:

    package com.ptsmods.morecommands.miscellaneous;
    
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraftforge.fml.common.network.NetworkRegistry;
    import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
    import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
    import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    public class PacketDispatcher {
    	private static final SimpleNetworkWrapper DISPATCHER = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MOD_ID);
    
    	public static void registerPackets() {
    		DISPATCHER.registerMessage(SPacketRegisterFakePlayer.Handler.class, SPacketRegisterFakePlayer.class, 0, Side.CLIENT);
    	}
    
    	public static void sendTo(IMessage message, EntityPlayerMP player) {
    		DISPATCHER.sendTo(message, player);
    	}
    
    	public static void sendToAll(IMessage message) {
    		DISPATCHER.sendToAll(message);
    	}
    
    	public static void sendToAllAround(IMessage message, TargetPoint targetPoint) {
    		DISPATCHER.sendToAllAround(message, targetPoint);
    	}
    
    	public static void sendToDimension(IMessage message, int dim) {
    		DISPATCHER.sendToDimension(message, dim);
    	}
    
    	@SideOnly(Side.CLIENT)
    	public static void sendToServer(IMessage message) {
    		DISPATCHER.sendToServer(message);
    	}
    
    }

     

  3. I have now made a class according to MovingSoundMinecart, but once played it doesn't do anything.

    EasterEgg.java:

    package com.ptsmods.morecommands.miscellaneous;
    
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.audio.MovingSound;
    import net.minecraft.util.SoundCategory;
    import net.minecraft.util.SoundEvent;
    
    public class EasterEgg extends MovingSound {
    
    	protected EasterEgg(SoundEvent sound, SoundCategory category) {
    		super(sound, category);
    		volume = 1F;
    		pitch = 0F;
    		repeat = true;
    		repeatDelay = 190;
    	}
    
    	@Override
    	public void update() {
    		xPosF = Minecraft.getMinecraft().player.getPosition().getX() + 0.5F;
    		yPosF = Minecraft.getMinecraft().player.getPosition().getX() + 0.5F;
    		zPosF = Minecraft.getMinecraft().player.getPosition().getY() + 0.5F;
    		donePlaying = !Reference.easterEggLoopEnabled;
    	}
    
    }

     

  4. Every method that plays a sound (EntityPlayer.playSound(), EntityPlayerSP.playSound() and SoundHandler.playSound()) all play sounds at a fixed BlockPos, is there any way to make this sound play directly to the player with the sound following the player just like how music works? This has to be done on the client side FYI.

  5. I have made a class implementing ISound, but when I try to play it with Minecraft.getMinecraft().getSoundHandler().playSound(new EasterEgg()), nothing happens not even an error in the console saying the sound doesn't exist.

    EasterEgg.java:

    package com.ptsmods.morecommands.miscellaneous;
    
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.audio.ISound;
    import net.minecraft.client.audio.Sound;
    import net.minecraft.client.audio.SoundEventAccessor;
    import net.minecraft.client.audio.SoundHandler;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.util.SoundCategory;
    
    public class EasterEgg implements ISound {
    
    	private ResourceLocation location;
    	private SoundEventAccessor soundEvent;
    	private Sound sound;
    
    	public EasterEgg() {
    		location = new ResourceLocation("morecommands:easteregg");
    		try {
    			createAccessor(Minecraft.getMinecraft().getSoundHandler());
    		} catch (Throwable e) {}
    	}
    
    	@Override
    	public ResourceLocation getSoundLocation() {
    		return location;
    	}
    
    	@Override
    	public SoundEventAccessor createAccessor(SoundHandler handler) {
    		soundEvent = handler.getAccessor(location);
    
    		if (soundEvent == null)
    			sound = SoundHandler.MISSING_SOUND;
    		else
    			sound = soundEvent.cloneEntry();
    
    		return soundEvent;
    	}
    
    	@Override
    	public Sound getSound() {
    		return sound;
    	}
    
    	@Override
    	public SoundCategory getCategory() {
    		return SoundCategory.PLAYERS;
    	}
    
    	@Override
    	public boolean canRepeat() {
    		return true;
    	}
    
    	@Override
    	public int getRepeatDelay() {
    		return 10;
    	}
    
    	@Override
    	public float getVolume() {
    		return 100;
    	}
    
    	@Override
    	public float getPitch() {
    		return 0;
    	}
    
    	@Override
    	public float getXPosF() {
    		return 0;
    	}
    
    	@Override
    	public float getYPosF() {
    		return 0;
    	}
    
    	@Override
    	public float getZPosF() {
    		return 0;
    	}
    
    	@Override
    	public AttenuationType getAttenuationType() {
    		return AttenuationType.LINEAR;
    	}
    
    }

    Sounds.json:

    {
      "easteregg": {
        "category": "players",
        "sounds": [
          {
            "name": "morecommands:easteregg",
            "stream": true
          }
        ]
      }
    }

     

  6. After a while of trying to figuring out how, I managed to build the mod with shadowjar, but the problem is still here. According to javadecompilers.com it still says ClientCommandHandler.instance.registerCommand(ICommand). I built it with the command gradlew shadowJar (since gradlew build gave an error saying MISSING REPLACEMENT DATA FOR MAPPING_CHANNEL) with the following build.gradle:

    buildscript {
        repositories {
            jcenter()
            maven {
                name = "forge"
                url = "http://files.minecraftforge.net/maven"
            }
        }
        dependencies {
            classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
        }
    }
    
    plugins {
        id 'com.github.johnrengelman.shadow' version '1.2.4'
    }
    
    apply plugin: 'net.minecraftforge.gradle.forge'
    
    version = "1.26.1"
    group = "com.ptsmods.morecommands" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
    archivesBaseName = "MoreCommands"
    
    sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
    compileJava {
        sourceCompatibility = targetCompatibility = '1.8'
    }
    
    minecraft {
        version = "1.12-14.21.1.2387"
        runDir = "run"
        mappings = "snapshot_20170624"
        makeObfSourceJar = false
    }
    
    dependencies {
        compile 'org.javassist:javassist:3.22.0-CR2'
        compile 'org.reflections:reflections:0.9.10'
        compile 'org.yaml:snakeyaml:1.18'
        compile 'com.google.guava:guava:23.0'
    }
    
    shadowJar {
        dependencies {
            include(dependency('org.javassist:javassist:3.22.0-CR2'))
            include(dependency('org.reflections:reflections:0.9.10'))
            include(dependency('org.yaml:snakeyaml:1.18'))
            include(dependency('com.google.guava:guava:23.0'))
        }
    
        classifier '' // Replace the default JAR
    }
    
    reobf {
        shadowJar {} // Reobfuscate the shadowed JAR
    }
    
    processResources {
        // this will ensure that this task is redone when the versions change.
        inputs.property "version", project.version
        inputs.property "mcversion", project.minecraft.version
    
        // replace stuff in mcmod.info, nothing else
        from(sourceSets.main.resources.srcDirs) {
            include 'mcmod.info'
    
            // replace version and mcversion
            expand 'version': project.version, 'mcversion': project.minecraft.version
        }
    
        // copy everything else, that's not the mcmod.info
        from(sourceSets.main.resources.srcDirs) {
            exclude 'mcmod.info'
        }
    }
    
    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
        options.compilerArgs.add('-Xlint:unchecked')
    }
    
    tasks.withType(Javadoc) {
        options.encoding = 'UTF-8'
    }
    
    task javadocJar(type: Jar, dependsOn: javadoc) {
        from javadoc.destinationDir
        classifier = 'javadoc'
    }
    
    artifacts {
        archives javadocJar
        archives shadowJar
    }

     

  7. According to javadecompilers.com, it doesn't. Maybe this is because I build it with a custom made gradle task? Which is

    task renameJar(type: Jar) {
        manifest {
            attributes 'Implementation-Title': 'MoreCommands',
                'Implementation-Version': version,
                'Main-Class': 'com.ptsmods.morecommands.MoreCommands'
        }
        
        baseName = 'morecommands_' + version + '_mc1.11-1.12.1'
        from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
        with jar
    }

     

  8. package com.ptsmods.morecommands;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Set;
    
    import org.reflections.Reflections;
    
    import com.ptsmods.morecommands.commands.chelp.Commandchelp;
    import com.ptsmods.morecommands.commands.enchant.Commandenchant;
    import com.ptsmods.morecommands.commands.fixTime.CommandfixTime;
    import com.ptsmods.morecommands.miscellaneous.CommandBase;
    import com.ptsmods.morecommands.miscellaneous.CommandType;
    import com.ptsmods.morecommands.miscellaneous.IncorrectCommandType;
    import com.ptsmods.morecommands.miscellaneous.Reference;
    import com.ptsmods.morecommands.miscellaneous.Reference.LogType;
    
    import net.minecraft.block.Block;
    import net.minecraft.client.settings.KeyBinding;
    import net.minecraft.command.ICommand;
    import net.minecraft.init.Blocks;
    import net.minecraftforge.client.ClientCommandHandler;
    import net.minecraftforge.fml.client.registry.ClientRegistry;
    import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    public abstract class Initialize {
    
    	public static void registerCommands(FMLServerStartingEvent event) {
    		Reference.print(LogType.INFO, "Registering MoreCommands server sided commands.");
    
    		ICommand[] nonRegistryCommands = new ICommand[] {new CommandfixTime(), new Commandenchant()};
    		ICommand[] commands;
    		try {
    			commands = Reference.getCommandRegistry(CommandType.SERVER).toArray(new ICommand[0]);
    		} catch (IncorrectCommandType e1) {
    			e1.printStackTrace();
    			return;
    		}
    
    		Integer counter = 0;
    		Integer fails = 0;
    		List<String> failList = new ArrayList<>();
    
    		for (ICommand command : commands)
    			try {
    				event.registerServerCommand(command);
    				counter += 1;
    			} catch (Exception e) {fails += 1; failList.add(command.getName()); continue;}
    
    		for (ICommand command : nonRegistryCommands)
    			try {
    				event.registerServerCommand(command);
    				counter += 1;
    			} catch (Exception e) {
    				fails += 1;
    				failList.add(command.getName());
    				e.printStackTrace();
    				continue;
    			}
    
    		Reference.print(LogType.INFO, "Successfully registered " + counter.toString() + " server sided commands, with " + fails.toString() + " fails.");
    		if (!(failList.size() == 0)) Reference.print(LogType.INFO, "Failed to register " + CommandBase.joinNiceString(failList.toArray(new String[0])));
    	}
    
    	@SideOnly(Side.CLIENT)
    	public static void registerClientCommands() {
    		Reference.print(LogType.INFO, "Registering MoreCommands client sided commands.");
    
    		ICommand[] nonRegistryCommands = new ICommand[] {new Commandchelp()};
    		ICommand[] commands;
    		try {
    			commands = Reference.getCommandRegistry(CommandType.CLIENT).toArray(new ICommand[0]);
    		} catch (IncorrectCommandType e1) {
    			e1.printStackTrace();
    			return;
    		}
    
    		Integer counter = 0;
    		Integer fails = 0;
    		List<String> failList = new ArrayList<>();
    
    		for (ICommand command : commands)
    			try {
    				ClientCommandHandler.instance.registerCommand(command);
    				counter += 1;
    			} catch (Exception e) {fails += 1; failList.add(command.getName()); continue;}
    
    		for (ICommand command : nonRegistryCommands)
    			try {
    				ClientCommandHandler.instance.registerCommand(command);
    				counter += 1;
    			} catch (Exception e) {
    				fails += 1;
    				failList.add(command.getName());
    				e.printStackTrace();
    				continue;
    			}
    
    		Reference.print(LogType.INFO, "Successfully registered " + counter.toString() + " client sided commands, with " + fails.toString() + " fails.");
    		if (!(failList.size() == 0)) Reference.print(LogType.INFO, "Failed to register " + CommandBase.joinNiceString(failList.toArray(new String[0])));
    	}
    
    	public static void setupBlockLists() {
    		Reference.print(LogType.INFO, "Setting up the MoreCommands block blacklist.");
    
    		Block[] blacklist = {Blocks.AIR, Blocks.LAVA, Blocks.CACTUS, Blocks.MAGMA, Blocks.ACACIA_FENCE, Blocks.ACACIA_FENCE_GATE, Blocks.BIRCH_FENCE, Blocks.BIRCH_FENCE_GATE, Blocks.DARK_OAK_FENCE, Blocks.DARK_OAK_FENCE_GATE,
    				Blocks.JUNGLE_FENCE, Blocks.JUNGLE_FENCE_GATE, Blocks.NETHER_BRICK_FENCE, Blocks.OAK_FENCE, Blocks.OAK_FENCE_GATE, Blocks.SPRUCE_FENCE, Blocks.SPRUCE_FENCE_GATE, Blocks.FIRE, Blocks.WEB, Blocks.MOB_SPAWNER,
    				Blocks.END_PORTAL, Blocks.END_PORTAL_FRAME, Blocks.TNT, Blocks.IRON_TRAPDOOR, Blocks.TRAPDOOR, Blocks.BREWING_STAND};
    
    		Integer counter = 0;
    
    		for (Block element : blacklist) {
    			Reference.addBlockToBlacklist(element);
    			counter += 1;
    		}
    
    		Reference.print(LogType.INFO, "Successfully set up the block blacklist and added " + counter.toString() + " blocks.");
    		Reference.print(LogType.INFO, "Setting up the MoreCommands block whitelist.");
    
    		Block[] whitelist = {Blocks.AIR, Blocks.DEADBUSH, Blocks.VINE, Blocks.TALLGRASS, Blocks.ACACIA_DOOR, Blocks.BIRCH_DOOR, Blocks.DARK_OAK_DOOR, Blocks.IRON_DOOR, Blocks.JUNGLE_DOOR, Blocks.OAK_DOOR, Blocks.SPRUCE_DOOR,
    				Blocks.DOUBLE_PLANT, Blocks.RED_FLOWER, Blocks.YELLOW_FLOWER, Blocks.BROWN_MUSHROOM, Blocks.RED_MUSHROOM, Blocks.WATERLILY, Blocks.BEETROOTS, Blocks.CARROTS, Blocks.WHEAT, Blocks.POTATOES, Blocks.PUMPKIN_STEM,
    				Blocks.MELON_STEM, Blocks.SNOW_LAYER};
    
    		counter = 0;
    
    		for (Block element : whitelist) {
    			Reference.addBlockToWhitelist(element);
    			counter += 1;
    		}
    
    		Reference.print(LogType.INFO, "Successfully set up the block whitelist and added " + counter.toString() + " blocks.");
    	}
    
    	public static void setupCommandRegistry() {
    		Set<Class<? extends CommandBase>> commands = new Reflections("com.ptsmods.morecommands.commands").getSubTypesOf(CommandBase.class);
    
    		for (Class<? extends CommandBase> command : commands) {
    			try {
    				Reference.addCommandToRegistry(command.newInstance().getCommandType(), command.newInstance());
    				command.newInstance().getPermission(); // just so it's registered in the permissions.
    			} catch (IncorrectCommandType e) {
    				e.printStackTrace();
    			} catch (InstantiationException | IllegalAccessException e) {
    				e.printStackTrace();
    			} catch (NoClassDefFoundError e) {};
    		}
    	}
    
    	@SideOnly(Side.CLIENT)
    	public static void registerKeyBinds() {
    		HashMap<String, KeyBinding> keyBindings = Reference.getKeyBindings();
    		for (String keyBinding : keyBindings.keySet())
    			ClientRegistry.registerKeyBinding(keyBindings.get(keyBinding));
    	}
    
    }

    It's being called from postInit, it used to work just fine but I have been getting a lot of errors lately which idk where they came from.

  9. I have made an overlay gui with some information of the player but when you hover over an entity it dissapears.

    InfoOverlay.class:

    package com.ptsmods.morecommands.miscellaneous;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.gui.Gui;
    import net.minecraft.util.math.MathHelper;
    import net.minecraft.util.text.TextFormatting;
    import net.minecraft.world.EnumSkyBlock;
    import net.minecraftforge.fml.common.FMLCommonHandler;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    @SideOnly(Side.CLIENT)
    public class InfoOverlay extends Gui {
    
    	private Minecraft mc;
    	
    	public InfoOverlay() {
    		this.mc = Minecraft.getMinecraft();
    		this.zLevel = Float.MAX_VALUE;
    		try {
    			Reference.loadInfoOverlayConfig();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		drawStrings(parseInfoOverlayConfig(Reference.getInfoOverlayConfig()).toArray(new String[0]));
    	}
    	
    	private void drawString(String string, int row) {
    		int defaultHeight = 2;
    		int defaultWidth = 2;
    		if (Reference.setVariables.containsKey("defaultHeight") && Reference.isInteger(Reference.setVariables.get("defaultHeight"))) defaultHeight = Integer.parseInt(Reference.setVariables.get("defaultHeight"));
    		if (Reference.setVariables.containsKey("defaultWidth") && Reference.isInteger(Reference.setVariables.get("defaultWidth"))) defaultWidth = Integer.parseInt(Reference.setVariables.get("defaultWidth"));
    		drawString(this.mc.fontRenderer, string, defaultWidth, row*10 + defaultHeight, Integer.parseInt("FFFFFF", 16));
    	}
    	
    	private void drawStrings(String... strings) {
    		for (int x = 0; x < strings.length; x++) {
    			drawString(strings[x], x);
    		}
    	}
    	
    	private TextFormatting getRandomColor() {
    		if (Reference.Random.randInt(101) == 0) {
    			Reference.lastColor = Reference.getRandomColor("WHITE");
    		}
    		return Reference.lastColor;
    	}
    	
        private List<String> parseInfoOverlayConfig(List<String> config) {
        	Minecraft mc = Minecraft.getMinecraft();
        	List<String> output = new ArrayList<String>();
        	Reference.setVariables = new HashMap<String, String>();
        	try {
    	    	for (String line : config) {
    	    		if (line.startsWith("var ")) {
    	    			if (line.split(" ").length == 4) Reference.setVariables.put(line.split(" ")[1], line.split(" ")[3]);
    	    		} else {
    	    			line = line.replaceAll("\\{playerName\\}", mc.player.getName())
    		    		.replaceAll("\\{x\\}", String.format("%f", mc.player.getPositionVector().x))
    		    		.replaceAll("\\{y\\}", String.format("%f", mc.player.getPositionVector().y))
    		    		.replaceAll("\\{z\\}", String.format("%f", mc.player.getPositionVector().z))
    		    		.replaceAll("\\{chunkX\\}", "" + mc.player.chunkCoordX)
    		    		.replaceAll("\\{chunkY\\}", "" + mc.player.chunkCoordY)
    		    		.replaceAll("\\{chunkZ\\}", "" + mc.player.chunkCoordZ)
    		    		.replaceAll("\\{yaw\\}", "" + MathHelper.wrapDegrees(mc.player.rotationYaw))
    		    		.replaceAll("\\{pitch\\}", "" + MathHelper.wrapDegrees(mc.player.rotationPitch))
    		    		.replaceAll("\\{biome\\}", mc.world.getBiome(mc.player.getPosition()).getBiomeName())
    		    		.replaceAll("\\{difficulty\\}", mc.world.getWorldInfo().getDifficulty().name())
    		    		.replaceAll("\\{blocksPerSec\\}", String.format("%f", Reference.blocksPerSecond))
    		    		.replaceAll("\\{toggleKey\\}", Reference.getKeyBindingByName("toggleOverlay").getDisplayName())
    		    		.replaceAll("\\{configFile\\}", new File("config/MoreCommands/infoOverlay.txt").getAbsolutePath().replaceAll("\\\\", "\\\\\\\\")) // replacing 1 backslash with 2 so backslashes actually show
    		    		.replaceAll("\\{facing\\}", Reference.getLookDirectionFromLookVec(mc.player.getLookVec()))
    		    		.replaceAll("\\{time\\}", Reference.parseTime(FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(mc.player.dimension).getWorldTime() % 24000L, false))
    		    		.replaceAll("\\{UUID\\}", mc.player.getUniqueID().toString())
    		    		.replaceAll("\\{holding\\}", Reference.getLocalizedName(mc.player.getHeldItemMainhand().getItem()))
    		    		.replaceAll("\\{rainbow\\}", "" + getRandomColor())
    		    		.replaceAll("\\{easterEgg\\}", ":O, you found the easter egg!")
    		    		.replaceAll("\\{xp\\}", "" + mc.player.experienceTotal)
    		    		.replaceAll("\\{xpLevel\\}", "" + mc.player.experienceLevel)
    		    		.replaceAll("\\{gamemode\\}", FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(mc.player.getName()).interactionManager.getGameType().getName())
    		    		.replaceAll("\\{fps\\}", "" + mc.getDebugFPS())
    		    		.replaceAll("\\{blockLight\\}", "" + mc.world.getChunkFromBlockCoords(mc.player.getPosition()).getLightFor(EnumSkyBlock.BLOCK, mc.player.getPosition()))
    		    		.replaceAll("\\{skyLight\\}", "" + mc.world.getChunkFromBlockCoords(mc.player.getPosition()).getLightFor(EnumSkyBlock.SKY, mc.player.getPosition()))
    	    			.replaceAll("\\{lookingAtX\\}", "" + mc.objectMouseOver.getBlockPos().getX())
    	    			.replaceAll("\\{lookingAtY\\}", "" + mc.objectMouseOver.getBlockPos().getY())
    	    			.replaceAll("\\{lookingAtZ\\}", "" + mc.objectMouseOver.getBlockPos().getZ())
    	    			.replaceAll("\\{lookingAt\\}", "" + Reference.getLocalizedName(mc.world.getBlockState(mc.objectMouseOver.getBlockPos()).getBlock()))
    	    			.replaceAll("\\{isSingleplayer\\}", "" + FMLCommonHandler.instance().getMinecraftServerInstance().isSinglePlayer());
    		    		if (line.equals("") || !line.split("//")[0].equals("")) output.add(line.split("//")[0]);
    	    		}
    	    	}
        	} catch (NullPointerException e) {}
        	return output;
        }
    }

    How I render it (in ClientEventHandler.class):

    @SubscribeEvent
    public void onRenderGui(RenderGameOverlayEvent.Post event) {
    	if (event.getType() == ElementType.EXPERIENCE && Reference.isInfoOverlayEnabled()) new InfoOverlay();
    }

     

  10. I have made a custom keybinding which works fine but whenever I launch the game, go to options and click controls, the game crashes for some reason.

    Here's how I registered the keybinding:

    KeyBinding keyBind = new KeyBinding("Toggle overlay", Keyboard.KEY_C, "MoreCommands")
    ClientRegistry.registerKeyBinding(keyBind);

    Crash report:

    java.lang.NullPointerException: Rendering screen
    	at net.minecraft.client.gui.GuiListExtended.updateItemPos(GuiListExtended.java:41)
    	at net.minecraft.client.gui.GuiSlot.drawSelectionBox(GuiSlot.java:446)
    	at net.minecraft.client.gui.GuiSlot.drawScreen(GuiSlot.java:236)
    	at net.minecraft.client.gui.GuiControls.drawScreen(GuiControls.java:163)
    	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:349)
    	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1168)
    	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1192)
    	at net.minecraft.client.Minecraft.run(Minecraft.java:436)
    	at net.minecraft.client.main.Main.main(Main.java:118)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    	at GradleStart.main(GradleStart.java:26)

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.