Jump to content

[1.8] MinecraftByExample sample code project


TheGreyGhost

Recommended Posts

Hi All

 

I'd like to ask for some help from you experienced modders out there.

 

I'm putting together a sample code project to give simple working examples of the important concepts in Minecraft and Forge, to show new modders how the key parts are put together and give them a base to start experimenting from. 

 

I have made a modest start (https://github.com/TheGreyGhost/MinecraftByExample) and I'd like to make it much more comprehensive, so I am hoping some of you will help out.

 

What I'm looking for:

- ideas for topics / samples

- pointers to good examples which already exist in other projects

- snippets of self-contained code to illustrate a key concept.

- feedback

 

The key features of the samples are that

* they must be self-contained, a handful of short classes at most

* must be well documented in the source code itself

* they must be simple and readable; clarity is much more than important than flexibility, extensibility, or "efficiency"

 

FYI currently I'm planning on adding the following topics over time.  It's a long list and half of it I've got no idea about, so it's going to take forever without help...

Blocks -

  simple block modelling

  more-complicated block modelling

  blocks with properties / metadata

  block with display tick

  block with scheduled update

  animated texture

Items -

  simple item

  item with sub-types

  item with NBT

  how to control rendering in the different views (1st person, 3rd person, inventory, etc)

Recipes

  variety of recipe types

TileEntity

  simple tile entity with NBT, no renderer

  simple TileEntitySpecialRenderer

Containers

  furnace-like

  chest-like

Entities

  basic entity that can be spawned and disappears after a certain time

  missile entity

  entity rendering / techne -based / animation

  entity with basic AI

EntityFX

  simple effect generator

Events

  show some events on different busses

GUI

  customise the standard HUD render elements (crosshairs, etc)

  create a custom GUI

Terrain generation

 

Generate a new dimension

 

Miscellaneous

  best practice error logging (I could sure use some help on that one!)

 

Thoughts, feedback, suggestions very welcome...

 

-TGG

 

 

 

 

  • Like 1
Link to comment
Share on other sites

Hello TGG,

 

Here's a pretty useful snippet of code that lets you move elements in the overlay to arbitrary locations. I think it's a very clean way of modifying the overlay, and it demonstrates how events can be used in very few lines of code.

 

@SubscribeEvent(receiveCanceled=true)
public void onEvent(RenderGameOverlayEvent.Pre event) {
  if (event.type == ElementType.FOOD) {
    /* This call saves the current "state" of transformations. */
    GL11.glPushMatrix();
    
    /* Move the food bar to some location. */
    GL11.glTranslatef(0, -10, 0);
  }
  /* etc. */
}

@SubscribeEvent(receiveCanceled=true)
public void onEvent(RenderGameOverlayEvent.Post event) {
  if (event.type == ElementType.FOOD) {
  
    /* This call reverts to the previous "state" of transformations,
     * effectively undoing anything that you have done above. Do not
     * forget to pop the matrix.
     */
    GL11.glPopMatrix();
  }
  /* etc. */
}

 

In the client side init method, register the above class:

MinecraftForge.EVENT_BUS.register(new SomeEventHandler());

 

Here's an example of what the above code does to the food bar:

 

 

e92b8fba56.jpg

 

Of course, it's possible to do all sorts of crazy things to the overlay.

01a4994a87.jpg

 

(The above images are from an unpublished mod that I worked on in the past, which is why there's a different health bar and an extra gold colored bar. )

 

 

Link to comment
Share on other sites

Hi TGG,

 

This sounds like a great idea! My only concern is that noobs will just copy paste this into their mod and then tweak a minor thing then claim it as their own. I have some nifty tricks and I'll contribute and help ya ;D. Im really glad someone has started something like this.

 

-Asweez

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Hi

 

This sounds like a great idea! My only concern is that noobs will just copy paste this into their mod and then tweak a minor thing then claim it as their own.

-Asweez

Well to be honest I was noob once (and still am in plenty of areas) so that doesn't really bother me much :P  Best way for a noob to ascend to coder god is to start by imitating the experts, I reckon...

 

I have some nifty tricks and I'll contribute and help ya ;D. Im really glad someone has started something like this.

Awesome, thanks!

 

Any particular areas you're thinking of?

 

-TGG

Link to comment
Share on other sites

  • 1 month later...

Hi TGG,

 

This sounds like a great idea! My only concern is that noobs will just copy paste this into their mod and then tweak a minor thing then claim it as their own. I have some nifty tricks and I'll contribute and help ya ;D. Im really glad someone has started something like this.

 

-Asweez

 

So, what you are saying is that if you give me a blueberry muffin recipe made with regular all-purpose flour and I change the blueberries to cranberries, that the resulting new recipe isn't mine to claim?

Link to comment
Share on other sites

  • 3 weeks later...

How much level do you planning to introduce on "Generate a new dimension"?

Tutorial like 'Changing Sunlight Strength' can be included? If so, I'd do that using PR.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Dimensions? Count me in!

 

What exactly do you want?

Server only (multiworld)

Full dimension with custom biomes?

dynamically generated dimensions? (Thats a bit harder, I still haven't got it working 100%)

 

Should we also post little helper classes? (1.8 display title, easier Potions, auto-updater, donator particles (why did I create donator particles if I never publish any of m mods?),...)

 

 

 

I think there is nothing wrong with copying code. I taught myself java by reading the decompiled Minecraft source and changing parts of it. I didn't even realize that I could google some stuff... I was such an idiot.

 

 

EDIT: I can also post 5 to 6 different all-around Teleporter classes. They are always usefull.

Here could be your advertisement!

Link to comment
Share on other sites

  • 4 weeks later...

I have a lot of expertise with items and nbt stuff. I have some with entities and GUIs and almost nothing with blocks. If you ever need anything with those areas mentioned then I will try to help.

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Thanks TGG for continuing to blaze ahead to help the rest of us.

 

In my tutorials I personally have taken the approach of not sharing fully working examples because I feel that a person only learns by struggling through the details of tying the concepts together, plus I expect you'll take on a lot of support requests as people copy and paste.  But I'm also sure an example mod will be greatly appreciated.

 

As an aside, I encourage all modders to develop a default starting code base for their mods, with all their favorite hooks and organization.  When I start a new mod I can just copy my codebase and with a couple quick edits am up and running with working packets, event handling, etc.  What TGG is developing here might work well for a lot of you.

 

Anyway, my suggestions:

- it is probably implied in your other topics, but custom network messages is good topic.

- I personally like configurations.  Not sure how many people use them though.  I've even been getting into providing an in-game options GUI to control the configuration.

- You mentioned terrain generation and dimensions, but specifically biomes, structures, trees, oregen are all pretty popular topics.

- Villages would be interesting topic.

- Achievements and stats.

- Enchantments and potions.

- Entities that are mountable is a popular topic.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I have a lot of expertise with items and nbt stuff. I have some with entities and GUIs and almost nothing with blocks. If you ever need anything with those areas mentioned then I will try to help.

Hi Asweez

 

Keen, thanks.  If you would be willing to code up an example or two (or more) on Entities, it would be very helpful because the example project currently has nothing on Entities at all.

 

The rough thought I had was for four examples:

Entities

  basic entity that can be spawned and disappears after a certain time

  missile entity (always people trying to code their own guns & bullets, bows & arrows, etc)

  entity rendering / techne -based / animation

  entity with basic AI

 

Perhaps a fifth for mountable entity like Jabelar suggested

 

Any contribution would be very helpful.

The existing project is at https://github.com/TheGreyGhost/MinecraftByExample

If you like, you could fork and PR; alternatively if you want to do a completely separate project that's fine too, I could integrate myself.

It would help a lot if you follow the package structure, class, notes, and commenting style used by the rest of the project because that will save me having to refactor it.

 

Cheers

  TGG

 

PS @Jabelar thanks for the suggestions, I'll add them to the wish list.  Will need to up my skills for some of those :) The project has a fair few examples, including network messages which are a minefield for the unwary.

 

 

 

 

 

 

 

Link to comment
Share on other sites

  • 4 weeks later...

PS @Jabelar thanks for the suggestions, I'll add them to the wish list.  Will need to up my skills for some of those :)

 

One of the reasons I like answering questions and making tutorials is to get me into new topics. Sometimes the simplest question ("why isn't my custom slime entity transparent") can make you really go back and review what you know.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

  • 2 weeks later...

Do you by any change have a tutorial on ISmartItemModel? Or are you going to do one in the future? I'm making an Item with about 130 different variants, and I would like not having to make 130 model files only to change the texture. Or do you have another solution to this?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Hi

 

Funnily enough I'm working on this right now... it's very similar to MBE04 - uses ModelBakeEvent to inject itself into the model registry.  I am just figuring out how to generate the BakedQuads algorithmically; based on this code

  https://github.com/MinecraftForge/MinecraftForge/blob/master/src/test/java/net/minecraftforge/debug/ModelBakeEventDebug.java

 

(The test code is a pretty good example to learn from, too)

 

If your 130 variants are made up of a few simple components, ISmartItemModel is probably the best way I reckon.  Alternatively, if you are just (say) changing colours like eggs or potions you could use the item layers instead.

 

-TGG

Link to comment
Share on other sites

If I go the route for the different model files, every model file looks like this:

{
    "parent":"dwarffortress:item/standard_item",
    "textures": {
        "layer0": "minecraft:blocks/stone"
    }
}

The only difference per-JSON is the layer0 line, so only the texture. So I guess the ISmartItemModel is the way go here, right?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Can you update the Camera transforms item, it doesn't actually move the item in your hand any more, I had to go get the code from the separate github page for it to work.

Ah that's annoying, a regression bug perhaps...

What version did you try that didn't work?  (where did you get it from?)

Link to comment
Share on other sites

I got the latest version yesterday, the current latest 11.14.1.1402, and I know that I used 11.14.1.1400 or higher. Also half the classes were declared deprecated. The other github repo did work though, but many classes were deprecated. Awsome item btw.

 

EDIT: I got it from the official files.minecraftforge.net

Link to comment
Share on other sites

If I go the route for the different model files, every model file looks like this:

{
    "parent":"dwarffortress:item/standard_item",
    "textures": {
        "layer0": "minecraft:blocks/stone"
    }
}

The only difference per-JSON is the layer0 line, so only the texture. So I guess the ISmartItemModel is the way go here, right?

If your items are all identical except each one has a different texture, then yeah I would use the ISmartItemModel.  Create one model file with 130 defined textures, then your ISmartItemModel tweaks its bakedquad list to choose the correct texture coordinates

 

-TGG

Link to comment
Share on other sites

I got the latest version yesterday, the current latest 11.14.1.1402, and I know that I used 11.14.1.1400 or higher. Also half the classes were declared deprecated. The other github repo did work though, but many classes were deprecated. Awsome item btw.

 

EDIT: I got it from the official files.minecraftforge.net

Oh, you mean- when you use the camera item after updating forge to 11.14.1.1402, it no longer works?  But it did work before?

I updated it with a couple of bugfixes recently but perhaps I broke something.  I will test again...

 

And you're talking about the camera item in MinecraftByExample, not the standalone GitHub ItemTransformHelper (or PlanetMinecraft d/load)?

 

-TGG

 

Link to comment
Share on other sites

Ok so I just started modding 1.8 and I chose to grab the latest forge edition, i was going through your MinecraftByExample tutorial (random parts) and I saw the camera item and decided to try it because one of the biggest push factors for 1.8 modding for me was json models (as great as they are they are a pain) and it didn't actually modify the item translation/scale/rotation so I looked around and found the other repo and took all the code from there, it worked after that. Also as I said before a large number of the classes were deprecated.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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