Jump to content

olrustyeye

Members
  • Posts

    26
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by olrustyeye

  1. On 6/12/2017 at 1:57 PM, HashtagShell said:

    Depends on how much you already know.

     

    If you have almost no knowledge of Java at all, you should go through a tutorial/course/JLS first, you won't learn what alien syntax means by just looking at it (unless you already know C# or the like).

    If you have quite good knowledge of the syntax, but not the APIs or quirks (return-in-finally, reflection, ASM, unsafe, etc.), it is well worth going through some example code, for instance, ASM is used quite heavily in Forge. Still, expect to be reading lots of papers and manuals; the likes of ASM will hardly make any sense without a prior understanding of the internals of the JVM, ie. having at least skimmed through the JVMS.

    If you already know how Java and all its quirks work, there is still a lot to learn in public domain code - best practices, keeping good code readability, algorithms and ideas. For example, once you already know how to render stuff in OpenGL, going through a few examples of how people have solved some rendering concepts will over time make you understand how to render your own shapes in the most efficient way (Though, rendering might not be the best example since it also requires a lot of knowledge outside the field of informational technology - math; rendering is a no-no without knowing trig and vectors).

     

    TL;DR: You will profit from reading open-source code, if you already know the language syntax and API basics, if you don't, do a tutorial or something first.

    Perfect. Sounds like an ideal situation for me. 
    I went to college and took HTML + CSS but mostly focused on Java and C++. I never quite got a niche anywhere with it and that wasn't my focus as far as degreewise.
    I now work for a technology company and I really really want to get much better at coding in general. Beyond arrays loops and methods. I think this is a good place to start for sure!

  2. 22 minutes ago, HashtagShell said:

    Usually, the method names chosen by the MCP team already describe the purpose of a method well enough, and if not, many methods have a JavaDoc added as well.

    When a method is either unnamed or without a JavaDoc, you are welcome to name it and its parameters according to its purpose, adding a JavaDoc if necessary, and submit it either via the MCPBot_Reborn bot in #mcp on the Esper IRC, or by submitting an issue on the MCP github.

    Lol, I don't think you guys get what I'm saying.
    I'm literally just wanting to do this as an exercise to help me understand the more advanced features of java. Nothing more. In the process I simply was stating that it would be nice to have a reference guide similar to google does for their scripts. While i'm already going through the code I might as well do that. 
    My question was is it actually going to teach me anything?

  3. On 6/10/2017 at 2:20 PM, Alexiy said:

    What is there to dissect? The source code is available. If you mean to edit the minecraft code directly, then you'll have to set up a custom environment - the code is located in gradle's cache directory as a Jar.

    I think you misunderstand. By dissect I mean go through the code and pull out the methods and how they work. Obviously anyone can see the code. I don't mean editting anything. Much like you'd diagram a sentence I want to do the same to the minecraft code. 

  4. 2 minutes ago, Demon Llama said:

    Ah thanks. I actually looked through all that and couldn't find enough info :/ 

    Compared to bukkit, it's a lot less documentation. Darn I really wanted to work through this awesome book too D: 

    I modded minecraft back in 1.3 and 1.5. Fun fact I actually owned the One Stop Mod Shop way way long ago haha. Things have changed, but the syntax on the basic stuff like blocks are the same. Find what version the book is using and switch to that go through it and then all you'll need to do is update your syntax!

     

  5. 17 minutes ago, Demon Llama said:

    Awwww. Thanks though. And thanks for the forum tips :D

     

    Where can I find a documentation list for the Minecraft/Forge methods, events, classes, etc?

     

    Thanks again!

    I wish there was more documentation. Sadly it's severly lacking. Not for forge's lack of trying but things change so much and few people actually want to go through the code and find things. 
    That being said there is some pretty useful stuff here. 
    https://mcforge.readthedocs.io/en/latest/
    Nothing like what you're looking for but it's a good resource for what is there. 

  6. Welcome!

    A few important things. 
    1) It's best if you use the code quotations tool in the forum or use Pastebin to show us the code. 
    2) It's super helpful if you let us know what version you are running. It also does not work with me and the reason is there isn't a ChatComponentText in the Util's as far as I can see. Probably it was moved to a different name/function. 

     

    My guess is that you'll need to find updated code for this particular portion. I see a "ChatAllowedCharacters" but thats it for chat under the Util's hierarchy. Sorry. Thats the best I can do for you :(. Hopefully someone smarter has a better idea!

    • Like 1
  7. 7 minutes ago, Draco18s said:

    It's a pain in the ass.

    Stop now.

     

    If you want to look at what I did in 1.7.10 (which involved heavy use of things that shant be talked about) you can have a look at my event handler class:

    https://github.com/Draco18s/HarderStuff/blob/master/src/main/java/com/draco18s/wildlife/WildlifeEventHandler.java

     

    Roughly:

    1) store the original biome data, we need to keep records of what they are so we can calculate time offsets properly

    2) modify the shit out of these numbers because some of them are garbage. We also need to calculate the variance delta (deserts have greater temperature variance than oceans because of water's thermal capacity)

    3) get the current date, look up the seasonal sine waves, multiply by variance delta, add to the base value, apply back to the biome

     

    It's ugly and there's hacks all over the place. One of the most annoying was having to deal with ice. Ice doesn't melt on its own, but water will freeze. Have fun handling that.

    Hmm. I have ADHD and I hyperfocus, so unfortunately there is no stopping me. It's only prolonging the inevitable. My solution I think is to slam my head against my desk until I go into a coma. Then I wont have to deal with this... haha.


    No but seriously. I was afraid of that. Looks like a lot of hacking, which means I'll put it off for a while until I understand the biome/temperature/entire game mechanics a bit better. 
    Also I never considered the impact a mod like this would have on the Nether and The End. Although it doesn't rain there or anything I edit in the overworld will be edited there and could cause issues later on. 

    Why do I like coding again? Why can't I be into gardening or something? ¬¬

    • Like 1
  8. One thing I want to add in my mod is seasons. I remember a while back a seasons mod which actually had seperate season where you woke up out of bed and BAM it was winter. 
    What I want to do is have a ease of transition and unpredictable. 
    What I want to know is how hard is this going to be. I would say my java experience is about a 3/10. I've taken a few classes and made a text game, but I'm not experienced enough to really hard code something like a forge API. 

    My initial thoughts on this project is to look at the temperature code already in the Biomes and begin there to run something every day which rerolls the temperature as it were. and depending on the biome it would fluctuate in a 28 day cycle of 4. The idea would be as it gets colder rain would become snow. Getting more advanced I'd like to turn the biome color brown in fall-spring then green in the spring-fall. 

    So again my question is: Is this WAY above my head and should I spend more time coding other things for now while I learn? Or is this something that's pretty easy to code? I'd rather not post 100 topics on the modder support asking how to do this or that. Nor would I like to waste my time on a mod that I'm not ready to write. 
    Thanks for the help! :)

  9. I'm very interested in dissecting the minecraft code for myself. I really want to learn more Java coding, and I figured going through the code and pulling out the methods and commenting how it works would be a great way to do this. 

    I was just wondering about if this would be useful to others/the modding community? The obvious answer is yes of course, but I also don't know if someone has already done this, or if going through he code is even worth my time? I was wondering what people thought?  Am I crazy and probably going to lose interest? Or is this something thats worth the effort?

  10. I'm currently working on a bit of code to access the drops for Granite, Diorite and Andesite. I little secret: I'm trying to make a geology type mod where theres a chance of dropping certain things while digging in the mines. 
    Anyways. Here's my code right now. 

    https://pastebin.com/GEV33S4j
    Here's what I've done for tests
    Created a new itemstack accessing the Granite by the metadata. It works applies to ALL stone rather then just granite. 
    I've tried using the name Granite. Doesn't work either. 
    I can't use idea because I believe (And I may be wrong) that the reason for meta data is many blocks under ONE id. 

    I feel like the answer may be pretty simple. So I'm hoping someone can tell me I'm a noob and to use minecraftmagic.dowhatIwant(Granite);

     

  11. 2 hours ago, Draco18s said:

    Generics are fucking awesome and it's the one tool in the toolbox I don't have when working in Unity that I miss (or at least, not to the same degree: there's typed lists and such, but everything needs to be strictly defined at compile time: no contravariance or covaraiance which means that I can't generically define delegate methods).

     

    Also, this method declaration is insane:

    https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/flowers/OreFlowersBase.java#L204

    It can technically be simplified, but not by a whole lot.

    Generics expand to meet the expanding generics? Lol. 
     

  12. 43 minutes ago, diesieben07 said:

    You could get rid of the ugly cast by not using raw types. getDrops returns a List<ItemStack>, therefor listIterator also returns ListIterator<ItemStack>. Raw types are a legacy thing and should never be used in modern Java code.

    Also, don't call remove on the list while you are iterating, this will crash. You need to use the remove method on the iterator to remove the current element.

    Holy crap... this is powerful stuff!
    It's funny how I'm not thinking in Java terms sometimes. I think I remember back in my college days (Now 4 years ago JEEZ) using lists. I totally forgot how easy they are. :P
    Thank you!!!!
    This is solved!

     

    For those wondering reading this in the future here is the key:
     

    		if (event.getState().getBlock() == Blocks.BLOCK_YOU_WANT_TO_EDIT)
    		{
    				event.getDrops().add(new ItemStack(YourModItemOrBlock.Item_Or_Block, Number_Of_It)); //This adds the item or block you want to 
    																									// You want to add to the block.
    				ListIterator<ItemStack> drops = event.getDrops().listIterator(); //This Gets the drop and puts it into a list of ItemStacks
    				while(drops.hasNext()) // Using a while loop so we don't get out of the bounds of the list
    					{
    					ItemStack element = drops.next(); //gets the next itemstack in the list
    					if(element.getItem() == Block/Item.BLOCK_OR_ITEM_YOU_WANT_TO_EDIT) // Does the list Item also match the item you want gone?
    						{					
    						drops.remove();	//remove it!
    						}
    					}
    			}



    Now that is some pretty beautiful code. Thanks for the help everyone I learned a TON from this little exercise!

  13. Yes!!! I got it to work. I don't love the fact I'm casting "element" into an itemstack I feel like that can be refined. But I have another issue I encountered. 
    This code does NOT work with redstone. It's only removing one of the redstone. It's interesting because it should be checking it over and over until it deletes all of them right? 

    Everything else works like a charm!

    		if (event.getState().getBlock() == Blocks.LIT_REDSTONE_ORE){
    			 Utils.getLogger().info("IronBlock Accessed. This method is Working");
    				event.getDrops().add(new ItemStack(Blocks.DIAMOND_BLOCK, 1));
    		
    				ListIterator drops = event.getDrops().listIterator();
    				while(drops.hasNext()){
    				Object element = drops.next();
    			
    				 Utils.getLogger().info(element);
    				if(((ItemStack) element).getItem() == Items.REDSTONE){
    				event.getDrops().remove(element);
    				 Utils.getLogger().info("WE DID IT!");
    				}
    				}
    			}
    		if (event.getState().getBlock() == Blocks.REDSTONE_ORE){
    			 Utils.getLogger().info("IronBlock Accessed. This method is Working");
    				event.getDrops().add(new ItemStack(Blocks.DIAMOND_BLOCK, 1));
    		
    				ListIterator drops = event.getDrops().listIterator();
    				while(drops.hasNext()){
    				Object element = drops.next();
    			
    				 Utils.getLogger().info(element);
    				if(((ItemStack) element).getItem() == Items.REDSTONE){
    				event.getDrops().remove(element);
    				
    				 Utils.getLogger().info("WE DID IT!");
    				}
    				}
    			}

    hehe well this isn't the ONLY issue actually. I"m also having an issue of trying to access the metadata of for dyes for lapis ore. I think I might be able to figure that one out, but if not I might be back. 

  14. 		if (event.getState().getBlock() == Blocks.IRON_ORE){
    		 Utils.getLogger().info("IronBlock Accessed. This method is Working");
    			event.getDrops().add(new ItemStack(Blocks.DIAMOND_BLOCK, 1));
    	
    			ListIterator drops = event.getDrops().listIterator();
    			while(drops.hasNext()){
    			Object element = drops.next();
    			
    			if(element == Item.getItemFromBlock(Blocks.IRON_ORE)){
    			event.getDrops().remove(element);
    			 Utils.getLogger().info("WE DID IT!");
    			}
    			}
    		}

    So I got the whileloop going now,

    my issue is I think I'm deleting the element rather then a block in the element. I'm not sure how to tell it to remove what I want it to at this point. :/ 
    Actually theres a problem with the If statement because it's not returning me...oh I think I might know what the issue might be. Element is an itemstack not an item...
    Still before I go test that. It's not returning true so theres an issue there. 

  15. 4 minutes ago, Jay Avery said:

    I was on the 'noob' side of these conversations for many months, so it seems only fair to pay it forward when I can! :)

     

    Ah yes, you have the right idea! To handle this safely, you'll need to use an Iterator for the list. Here is a little summary of using iterators. Instead of your for loop, create an iterator and then use a while loop, with the condition that the iterator hasNext. Then to get the next item from the list, instead of your get(i), use next on the iterator. That'll return an element of the list (an ItemStack) in the way you expect, and you can check its conditions in the way you currently are, and remove it form the list using remove on the iterator.

     

    Edit: Checking the length in that way unfortunately won't work reliably, because of counting through the list at the same time as changing its length. Here is a stackoverflow question addressing the same problem.

    Yup, I was just thinking that. It's a band-aid not a solution. The iterator sounds much more reliable. 

  16. 17 minutes ago, Jay Avery said:

    You can't compare ItemStacks using the == operator, it checks for object identity - so a newly created stack will never be == to an existing stack. Instead you need to check the item that's within the stack (using stack#getItem) and compare it to the block's ItemBlock (which you can obtain from Item.getItemFromBlock).

    Ooooooooooooo

    	if (event.getState().getBlock() == Blocks.GOLD_ORE){
    		 Utils.getLogger().info("IronBlock Accessed. This method is Working");
    			
    			event.getDrops().add(new ItemStack(Blocks.DIAMOND_BLOCK, 1));
    			
    			for(int i=0; i<= event.getDrops().size(); i++){
    			
    				
    			if(event.getDrops().get(i).getItem() == Item.getItemFromBlock(Blocks.GOLD_ORE)){
    			event.getDrops().remove(i);
    			
    			Utils.getLogger().info("Was Gold Ore Removed?");
    			}
    			}


    I'm still getting a error. I'm not sure what I am doing wrong now... The only thing I can think of is an issue in the for loop. Because removing the i means that the number that was 2 becomes 1 it has an issue when it goes to check for 2 and it's no longer there...
    So I did remove "Blocks.GOLD_ORE"
    and I still get an error. 

    Seriously, thank you so much for helping me. It's no often a community helps a noob with out being a jerk to him. You guys are awesome, this must be cake walk for a lot of you! 
    If it's any consolation I am learning a TON!

    One huge key here is that it says, IndexOutofBoundsException. I think it's removing the item and then checking for it again. 

  17. 	@SubscribeEvent
    	public void overrideBlocksDrops(HarvestDropsEvent event){
    		
    		
    		if (event.getState().getBlock() == Blocks.GOLD_ORE){
    		 Utils.getLogger().info("IronBlock Accessed. This method is Working");
    			
    			event.getDrops().add(new ItemStack(Blocks.DIAMOND_BLOCK, 1));
    			
    			for(int i=0; i<= event.getDrops().size(); i++){
    			if(event.getDrops().get(i) == new ItemStack(Blocks.GOLD_ORE)){
    			event.getDrops().remove(i);
    			
    			Utils.getLogger().info("Was Gold Ore Removed?");
    			}
    		}
       }

    I'm getting somewhere! Right now I got an error and I have some idea of why.
    I think there is a parsing error perhaps, or again I'm trying to create something new where something already exsists.

     

    Here my issue. Get is looking for an itemstack, so I'm trying to parse blocks into an item stack, but in order to do that I need new. Item.getblockfromitem wouldn't work because that makes it an item not a itemstack. 

    I'm not sure where to go from here... :/

     

    This is my error but I feel that the problem is probably obvious to those more experienced.
    https://pastebin.com/Bd6KKTKK

     

     

  18. Hmm..
    So I'm having an issue now where I can't REMOVE the block, but I can add. 

    event.getDrops().remove(new ItemStack(Blocks.GOLD_ORE));

    I think what I'm needing here is an addition check to check if the block dropped would be gold ore right? I'm just not sure where to go. I've told it to remove that drop but it wont. 

    Looking at the other methods I'm not sure how to use remove if this isn't how one uses it? 

  19. I've got one issue right now,

    This is my code:

    @Mod.EventBusSubscriber
    public class OverrideBlocksEvents{
     
    	 
    	@SubscribeEvent
    	public static void overrideBlocksDrops(HarvestDropsEvent e){
    		
    		 if(!e.getWorld().isRemote)
    	        {
    	            if(e.getWorld().getBlockState(e.getPos()).getBlock() instanceof BlockOre)
    	            {
    	                e.getDrops().add(new ItemStack(Items.DIAMOND));
    	            }
    	        }
    
    	}
    
    		

    I admittedly found this code from someone else, but from what I've read and understood. This should work. I'm checking what the block state is, and in the instance of a Ore Block it should add a diamond to the drops... right? 

     

    Edit: I just used a code I personally had made and it now works because I hadn't initialized it before... jeez goes to show you someone else's code isn't always better.
    here it is for those wondering:

    	@SubscribeEvent
    	public void overrideBlocksDrops(HarvestDropsEvent event){
    		
    		
    				
    		if (event.getState().getBlock() == Blocks.IRON_ORE){
    		 Utils.getLogger().info("IronBlock Accessed. This method is Working");
    			event.getDrops().add(new ItemStack(Blocks.DIAMOND_BLOCK, 1));
    		}
    
    	}


    Just as a sidenote I'd still like to know why the other code doesn't work?

  20. 7 minutes ago, Jay Avery said:

    The docs have a basic overview of using events. To edit the drops from a block, you can use HarvestDropsEvent. In the event, you can check for your chosen block(s) and then edit the list of drops (from event#getDrops()) however you like.

    Ooooo I like that!
    I'll have to check it out and utilize it!
    Side note: I tested somethings further and just broke my IronOre. Buggy is an understatement. I'm thinking it has something to do with Cache/memory. I'm going to try a restart and see if that clears things up a bit. That being said I'll probably use the events for a cleaner code. 

  21. Just now, Jay Avery said:

    I don't know the exact cause of the error, but the substitution system is generally extremely buggy. It would be much easier to achieve what you're trying to do using events.

    To me it looks like there something it doesn't like about the model. 
    I'm a bit confused as to how I can use events to achieve that effect. I don't know much about how to use events to be honest. :/
    Thanks for taking a look!

  22. I wanted to change the way the in game minerals work as far as how they drop. IE: I want gold_ore to drop a piece of gold ore rather then the whole block. I also want to add a slight chance of getting a gem like Diamond. 

    Heres whats super bizzaroworld. Iron works, Diamond works, but Coal and Gold don't. I haven't tried redstone yet because that has issues of its own. Also interesting it's crashing at the initialization portion of the game.  Anyone know whats wrong? 

    Here my current code
    https://pastebin.com/W7tTNY8C

     

    And the error:
    https://pastebin.com/net807Nd

     

    As soon as I comment out substitute(Blocks.GOLD_ORE, new ModBlockOre2("oreGold")); everything magically works. (I've also tried commenting out everything BUT gold ore and it still doesn't work.) 

×
×
  • Create New...

Important Information

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