Jump to content

iAmRinzler

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by iAmRinzler

  1. Thanks for clearing that up. I'll look into the instance. I only thought the function needed the property type, not the specific property instance.
  2. I understand the bits of code that aren't valid java. I only posted them to illustrate that I have been attempting everything and Java is a fairly new language for me. I also understand that the forge documentation is pseudocode, that doesn't mean it is clear or 'good' pseudocode. From the Forge documentation. This confused me. If I can't use IProperty<EnumDyeColor> then how do I get the appropriate IProperty instance I want the value of? Thanks.
  3. Hello! How do I get the value of the property? I have been experimenting with blockstates recently but I can't seem to pass the appropriate argument to the .getValue(IProperty<T> property) function. if (args.length == 1 && args[0].equals("blockstate")) { World world = sender.getEntityWorld(); cDroid.setPos2(cDroid.getBlockPosUnderMouse()); sender.addChatMessage(new TextComponentString("Setting Block: " + cDroid.getPos2() + "\n")); System.out.println(world.getBlockState(cDroid.getPos2())); System.out.println(world.getBlockState(cDroid.getPos2()).getMaterial() + " THE MATERIAL"); System.out.println(world.getBlockState(cDroid.getPos2()).getProperties() + " THE PROPERTIES"); System.out.println(world.getBlockState(cDroid.getPos2()).getPropertyNames() + " THE PROPERTY NAMES."); System.out.println(world.getBlockState(cDroid.getPos2()).getBlock() + " THE BLOCK."); } This is a bit that I have written to dive into what I can do with blockstates. All the above calls provide the expected output. My issue is with getting individual values of the properties so i can run comparisons against similar blocks. I can't seem to pass the IProperty<T> property argument to the .getValue function properly. 1) I have a Wool block that has the property color=lime. 2) How do I pull the value 'lime' out of the property? The forge (https://mcforge.readthedocs.io/en/latest/blockstates/states/)documentation about blockstates tells me that I should pass .getValue(<PROPERTY>) to get the values of the properties. This clearly doesn't work and the compiler complains anyway I try and pass this argument. I have tried every way I can think of to pass the EnumDyeColor property to this function: .getValue(<EnumDyeColor>) //doesn't work .getValue(EnumDyeColor.LIME) //doesn't work .getValue(IProperty<EnumDyeColor> EnumDyeColor.LIME) //doesn't work For the sake of redundancy I won't post all my various attempts but none of them provide a property value (I have also tried passing PropertyEnum, the class used for the wool block colors as returned by blockstate.getProperties()). Sorry if I am missing something simple here... The only thing I'm trying to do right now is (in the case of wool blocks): If property color = X //do stuff If property color = Y //do different stuff
  4. Thanks I am looking at it now. Lot's going on in RenderGlobal but I will work around in it. For now though I think I can use recolorBlock on wool and glass to produce the effect I want for my testing.
  5. An example would be the case where I have set two position markers (BlockPos or Double X,Y,Z's idc) A and B and I want to do something like make A look Red and B look Green. When I say transparent I mean only that it isn't necessary to replace the texture of the native block. Or perhaps changing the color of an array of blocks such as the surface area of the rectangle given by two BlockPos. (If you've ever used the factions mod it could be that we highlight the blocks slightly when a chunk is claimed and remove the color if that chunk is unclaimed). sorry If I am aimlessly wandering here. I have been hittin' the coffee hard. Basically I would have the function in a ticker and have it update a block color/tint if some condition is true.
  6. Ah so if the blocks were dyed wool then color should update. I can make a test world using wool blocks for what I'm doing then and the recolorBlock function should be fine. For adding a transparent tint layer over the block faces should I be looking in the Render package? It seems like I should be using VertexBuffer in place of WorldRenderer but meh it is all very confusing.
  7. Hello again! So I am working on something and it came up that it would be a nice feature to change the color of a block based on...stuff (really anything). Specifically right now I am working with pathfinding algorithms such as A*, DFS, BFS, Dijkstra's etc. In the case of A* I would like to tint a block slightly to visually differentiate which blocks are in the open/closed lists, which blocks are being scanned, etc. I found the function in the block class: /** * Common way to recolor a block with an external tool * @param world The world * @param pos Block position in world * @param side The side hit with the coloring tool * @param color The color to change to * @return If the recoloring was successful */ @SuppressWarnings({ "unchecked", "rawtypes" }) public boolean recolorBlock(World world, BlockPos pos, EnumFacing side, net.minecraft.item.EnumDyeColor color) { IBlockState state = world.getBlockState(pos); for (IProperty prop : state.getProperties().keySet()) { if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class) { net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)state.getValue(prop); if (current != color) { world.setBlockState(pos, state.withProperty(prop, color)); return true; } } } return false; } This function doesn't seem to change the color of a block as expected though and always returns false for me. What should I do differently here? P.S. I have seen positions marked in classes that used WorldRenderer. But that doesn't seem to exist anymore.
  8. These are not the same thing. 2.5-10 is 0.0001048576 I think you meant 2.5 * 10-10 Also, you probably meant -7, not -10. yup. I caught that too. easy mistake to make sometimes.
  9. I understood the number itself and how floating point conversions are lossy (btw 2.5x10-7 == 0.00000025 != 2.5-10). I was only curious why it was being used there. It makes sense to clamp off the number at some small value though. Thanks! I appreciate your explanation!
  10. I am working on a rotation function that updates player's pitch and yaw based on the location of a block or entity near the player. I understand how to compute the angular change, theta, required from the players current look vector to the desired look vector using 2d or 3d vectors yada yada yada... All that being said when I am reviewing rotation functions that others have coded I see something like: final double d0 = x - mc.thePlayer.posX; final double d1 = z - mc.thePlayer.posZ; final double d2 = y - mc.thePlayer.posY - mc.thePlayer.getEyeHeight(); final double d3 = d0 * d0 + d2 * d2 + d1 * d1; if (d3 < 2.500000277905201E-7D) { return 0; } //DoStuff So my question is what is the significance of the number 2.500000277905201E-7? I haven't been able to find useful posts about it.
  11. I like Syntactic Sugar. It reminds me of the flavor of my tears when sitting through Data Structures and Algorithms a couple years ago.
  12. Exactly what I needed. Thanks! I have it working as I wanted now. However, do I need to handle the help text for each subcommand? I can't seem to access it otherwise. /help mymod gets the help text from the CommandTreeBase...but I can't seem to find the texts for the subcommands. I could just add a help argument branch for each subcommand... edit: I am generating the help text by simply having public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (args.length == 1 && args[0].equals("help")) { sender.addChatMessage(new TextComponentString(getCommandUsage(sender))); } } in my subcommand execution. Seems to be working fine, although perhaps there is a better way. For my mod's command, I added a help sub-command that extends CommandHelp , stores the instance of the base command and overrides CommandHelp#getCommandMap and CommandHelp#getSortedPossibleCommands to return values from the base command. CommandTreeBase provides a getCommandMap method, but you have to implement getSortedPossibleCommands yourself ( CommandHelp calls ICommandManager#getPossibleCommands and sorts the result). You can see the base command here and the help sub-command here. Unfortunately this prints the vanilla header (which says /help instead of /testmod3 help ), but you'd need to re-implement CommandHelp#execute yourself to get around this. For the help files I am now using if (args.length == 1 && args[0].equals("help")) { throw new WrongUsageException("commands.testmod.command1.usage", new Object[0]); //TextComponentTranslation tct = new TextComponentTranslation("commands.testmod.command1.usage", new Object[0]); //sender.addChatMessage(tct); } Seems to work fine. Both the WrongUsageException and the TextComponentTranslation are working to get the string from the lang file.
  13. Well I seem to have gotten it working but in order to do so I had to just create an entirely new testmod. I don't have the slightest clue what was wrong with the first testmod but nothing I was doing would allow the .lang file to be recognized. I should note that the first testmod file had somehow been built into it's own gradle project and was independent of my Minecraft Forge gradle project (although it could still use the forge classes etc). I closed that testmod gradle project and recoded a testmod in the Minecraft Forge src file and my .lang file is being read properly now. I must have somehow screwed something up, I wish I knew what. Hopefully it continues to work for me. Thanks Choonster and Animefan for the helps.
  14. commands.testmod.usage=/testmod <command> /test <command> /tm <command> commands.testmod.setpos1.usage=/testmod setpos1 sets position 1. commands.testmod.setpos2.usage=/testmod setpos2 sets position 2. this is all that is in it. File currently saved as en_us.lang. Inside assets.testmod.lang.
  15. Everything I have read said that it needed to be "en_US.lang". However, I changed it to lowercase per your suggestion and it still isn't working. I get usage: commands.testmod.usage. There seemed to be debate as to whether it should be in the src folder or the resources folder though. right now I have it in both...
  16. Had to reopen this question because I ran into an issue. I went ahead and created the en_US.lang file and saved it in UTF-8 with BOM. I saved the file in src/main/java/assets/testmod/lang/en_US.lang (For the record I have tried also saving it under assets.testmod.lang in the resources file too). I have refreshed and reloaded the project...nothing. Inside en_US.lang I have: commands.testmod.usage=/testmod <command> <arguments> then in my command file I have @Override public String getCommandUsage(ICommandSender sender) { return "commands.testmod.usage"; } however, when I run /help testmod I get the string "Usage: commands.testmod.usage" rather than what it should be "/testmod <command> <arguments>". I do not understand what I am doing incorrectly.
  17. In the source code for the native commands I see: public String getCommandUsage(ICommandSender sender) { return "commands.kill.usage"; } (as an example from the CommandKill class)... I have been trying to find the file that contains the help string for "commands.kill.usage" to no avail. How do I edit or create my own for my own commands? Up till now I have just put the help text directly in the return statement, such as return "Command <Argument | Argument> usage"; etc.
  18. Exactly what I needed. Thanks! I have it working as I wanted now. However, do I need to handle the help text for each subcommand? I can't seem to access it otherwise. /help mymod gets the help text from the CommandTreeBase...but I can't seem to find the texts for the subcommands. I could just add a help argument branch for each subcommand... edit: I am generating the help text by simply having public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (args.length == 1 && args[0].equals("help")) { sender.addChatMessage(new TextComponentString(getCommandUsage(sender))); } } in my subcommand execution. Seems to be working fine, although perhaps there is a better way.
  19. I am trying to set up a command structure that would use /myMod myNewCommand Arguments It seems that I could register 1 command class that uses /myMod as its sole alias and handle various subcommands during the execution of that single super command. An example of this follows: package kmm.TestMod.Commands; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; /** * * @author Rinzler */ public class CommandTester extends CommandBase { @Override public String getCommandName() { return "myModName"; } @Override public String getCommandUsage(ICommandSender sender) { return "help"; } @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { // World world = sender.getEntityWorld(); if(world.isRemote) { //do stuff } else { if(args[0].equals("myNewCommand1")) { if(args.length > 1) { //do myNewCommand1 plus Arguments } else { //do stuff for myNewCommand1 no arguments } } if(args[0].equals("myNewCommand2")) { if(args.length > 1) { //do stuff for myNewCommand2 plus arguments } else { //do stuff for myNewCommand2 no arguments } } //...more commands... } } } Is there a better way of doing this such that I can use /myMod as a command opener?
  20. Ok so I have the command doing exactly what I wanted it to do: 1)store the players current position. 2)alternately allow the player to store a specific position either by directly entering an integer x|~x y|~y z|~z. where the ~ symbol determines that the coordinate is to be a an integer distance from the players current pos. Thus, ~x is x blocks in the positive or negative x direction from the player's current position. Basically it works the same as /tp x y z or /tp ~x ~y ~z. I still have a couple questions that I am hoping someone has addressed already but I can't seem to find what I need in my googling. First of all, the command code: public class SetPos1 extends CommandBase { private final List aliases; private ControllerDroid controllerDroid; public SetPos1(ControllerDroid cDroid) { aliases = new ArrayList(); aliases.add("setpos1"); aliases.add("someFantasticModName setpos1"); this.controllerDroid = cDroid; } @Override public String getCommandName() { //The name of the command return "SetPositions"; } @Override public String getCommandUsage(ICommandSender sender) { //Help file summary. return "setpos1 | setpos1 x y z | setpos1 ~x ~y ~z"; } @Override public List<String> getCommandAliases() { //Return the List of aliases for this command return this.aliases; } @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { //Code Execution when command is run World world = sender.getEntityWorld(); int x = (int) sender.getCommandSenderEntity().posX; int y = (int) sender.getCommandSenderEntity().posY; int z = (int) sender.getCommandSenderEntity().posZ; if (world.isRemote) { //Code for client-side execution } else { //Code for server-side execution if (args.length == 3) { for (int i = 0; i < 3; i++) { if (i == 0) { if (args[i].startsWith("~")) { x = x + CommandBase.parseInt(args[i].substring(1)); } else { x = CommandBase.parseInt(args[i]); } } if (i == 1) { if (args[i].startsWith("~")) { y = y + CommandBase.parseInt(args[i].substring(1)); } else { y = CommandBase.parseInt(args[i]); } } if (i == 2) { if (args[i].startsWith("~")) { z = z + CommandBase.parseInt(args[i].substring(1)); } else { z = CommandBase.parseInt(args[i]); } } } controllerDroid.setPos1(x, y, z); } if (args.length == 0) { controllerDroid.setPos1(x, y, z); } sender.addChatMessage(new TextComponentString("Position 1 set to: [" + controllerDroid.getPos1().getX() + "=X, " + controllerDroid.getPos1().getY() + "=Y, " + controllerDroid.getPos1().getZ() + "=Z]")); } } @Override public boolean checkPermission(MinecraftServer server, ICommandSender sender) { //Does the sending entity have permission to use this command? Probably return true; } @Override public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { return null; } @Override public int compareTo(ICommand o) { return 0; } } So the code works as intended when I use /setpos1 and /setpos1 x y z and so on. However I kind of want the alias to be /SomeFantasticModName setpos1: alias.add("someFantasticModName setpos1"); this doesn't seem to work though and it throws Unknown Command. So what I want is to have my mod name as a prefix to the actual commands. However the execute method isn't being called at all on an alias with multiple words in the string. It seemed to me that I could just do alias.add("someFantasticModName"); and could then handle whatever command args[0] happened to be. This seemed incorrect though since /somfantasticmodname would call all of my commands at once which seems like something I don't want to do.
  21. Update: I read in a similar post by diesieben07 that I should be extending CommandBase in my command classes rather than implementing ICommand. (CommandBase already implements ICommand). I see that CommandBase has a few parse functions. I will dabble in that and see what I can do.
  22. I am hoping someone can assist me and I apologize in advance if my questions seem trivial. I haven't worked with Minecraft Forge modding for long. That being said, I will dive right into my question. My mod has command methods for setting a position in the world. The command works fine for setting the position to the sending entity's current position. (if I call /setpos1 my pos1 BlockPos variable is set to the entity's current X, Y, Z). The commands I have working was done as follows: 1) Create the command class and have that command class implement ICommand: public class SetPos1 implements ICommand ... 2) Register the new command during the FMLServerStartingEvent: event.RegisterServerCommand(new SetPos1(dcs)); Where dcs is an abstract class that keeps track of global variables for the mod such as the newly set position. 3) What I want to extend the command to do: I would like the player to be able to set positions other than their current position. So, two things: I want the command /setpos x y z and /setpos ~x ~y ~z. Where /setpos x y z sets the pos to the user-specified x y z coords (/setpos 256 64 512 for example) and where /setpos ~x ~y ~z sets the pos to the user-specified coords that are ~x ~y ~z units from their current position. (/setpos ~-10 ~10 ~10 would set the pos to the coords that are 10 blocks in the negative X direction, 10 blocks in the positive Y direction, and 10 blocks in the positive Z direction. Such that if the player issued the command at 0,0,0 the pos would be set to -10X, 10Y, 10Z). I am having trouble figuring out how to do this using the aliases. Can you help?
×
×
  • Create New...

Important Information

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