Hello!
I'm Maz and I have been modding for a while now.
I haven't released any mods and I don't plan to either. I'm modding mostly to learn and I do love learning more of this wonderful art of programming! Now with 1.6 hitting I found a question getting asked a few times and I got the chance to learn the answer so then I'll put it up here for others to learn as well
Please remember the golden rule of all tutorials I ever will create:
"First and before all, learn the basics of programming." This will save you time and tears, trust me!
If you want to learn java, then this is a great place to start and I would say that this is the pre-req. for modding. http://see.stanford....aa-866adcae1111
A few words about errors:
[spoiler]
If you find my code to be wrong, outdated or unclear please post a comment saying so.
I'll try to fix my errors when my work and social life allows me to
If you get errors / crashes and need help then please:
- Provide the full error log pasted at www.pastebin.com or a similar paste site.
- Provide the source of all relevant classes on a paste site(with syntax highlighting set to Java), github or similar.
- Describe what you try to do, and what happens instead.
- If you post code inn the forum use CODE and SPOILER tags, else the thread becomes a mess and you're chance of getting help reduced!
Also I'm only one person, and this thread may not be the most active at a given time.
So to get help as fast as possible then remember the things mentioned above and go to
MinecraftForge - Modding Support Forum and ask there, at least if it's not directly related to my tutorials!
[/spoiler]
My plans:
[spoiler]
I don't plan on releasing any of the "common" tutorials, there probably won't be a lot of basic block tutorials and the like here. I'd like to write on subjects which are not already well documented.
Unless one can really make an improved version of the tutorial, I'd see no need to create a new text tutorial on the subject when there's already a good one out there!
My next subject will probably be another one related to Java and Eclipse more than Minecraft directly, but I'm pretty sure most of the folks here will enjoy it If you have suggestions feel free to voice them, I won't promise anything but if it's good I may do it or mention it for some of the other (and better) writers
I do have an active AFK life, just like most of the other modder/writer/human/alien's here.
So while I do want to get tutorials and information out here, I got to juggle my other stuff as well.
I will update this thread whenever I get the time and feel like it, not before! Sorry that's just how it is being adult like and all that. It sucks but that's how it is
[/spoiler]
Eclipse Keyboard Shortcuts!
Speed up you're workflow by using shortcuts, saved me a ton of time!
[spoiler]
In this text I will talk about a few things that will speed you up while using eclipse.
As with most other computer programs, eclipse got keyboard shortcuts. In fact it got tons of them so I wont even try to start covering them here!
Instead I will show you a few very usefull ones which I find myself using quite often.
So with that let's get started.
Renaming - Refactoring.
Mark any name, be it a method name or a variable name or even a class name.
Press Shift+Alt+R to start renaming. A small box will tell you to enter the new name so do it and press enter.
Eclipse will try to rename it everywhere inside you're project!
Go to decleration.
Mark any methodname, variable name or the like and press F3.
This will take you to the place where it's decleared.
I find it super useful when navigating minecraft's code!
Switch between open files.
Press Ctrl+E and you get a small box listing all the currently opened files,
use the arrow keys to select one from the list and tap enter to view that file.
PS: If you type when browsing the list, you filter the list to match you're input!
Open a Type like a class.
Instead of looking trough all the packages of net.minecraft.entity to look into the new EntityLivingBase,
you can hit a simple shortcut and open the "Open type" window.
Press Ctrl+Shift+T and start typing the type name.
It supports the use of * if you want all types with "fluid" in the name, then type
"*fluid" and you will get a list of all of them!
Open a file / resource.
You can open any file just as quickly as you could with any type above.
Just press Ctrl+Shift+R and it opens up the "Open Resource" window.
Which functions just like the one above except it searches for file names.
Quickly find variable or method inside a huge class.
If you are inside one of the larger classes like the World class and you want to find a method quickly, what do you do?
Do you ctrl+F and try to find it? Look at the Outline view and try to find it there?
Well there's an easier way, press Ctrl + O and a small box appers.
It contains a list of all the variables and methods of the class, and when you start typing it starts filtering the list.
So if I where to look for "SetBlock()" I'd just type "set" and it's right there, one click more and there we are!
Really useful! Also pressing Ctrl+O again shows the inherited members.
PS: To browse up and down the members of the list, just press Ctrl+Shift + Arrow (up or down).
Go to Line number #? Press Ctrl+L and enter the # of the line you want top, tap enter and there you are. Organize Imports? Press Ctrl + Shift + O to make eclipse try to cleanup and fix imports for you.
Go to last edit location.
I must admit I accidently tapped this quite a few times and had no idea WHY I suddently jumped to the other side of the file!
But after learning of this shortcut I realised how useful it is.
Instead of browsing around to find where you last edited the damn file you only need to press Ctrl+Q to jump there.
Go top super/sub type quickly.
Instead of scrolling to the top of the file and clicking the extended classes name,
you can press Ctrl+T to show a dialogue where you can select super types of the class.
Pressing Ctrl+T again while the dialogue box is open will make it show Sub types instead!
Find ALL references to selected method/variable.
If you press Ctrl+Shift+G while having a method/variable marked, eclipse will search the entire workspace for references to it!
And shows you everywhere it's being used!
Some Text editing shortcuts.
Select to Line Start/End (Shift + Home/End)
Insert Line Above (Shift+Ctrl+Enter)
Insert Line Below (Shift + Enter)
Delete Line (Ctrl + D)
Move Line up/down (Alt + Up/Down)
Convert to Lower/Upper case (Shift + Ctrl + Y/X)
Toggle Comment (Shift + Ctrl + C)
Eclipse Shortcuts - Cheat sheet!
Michael Pellaton has created a nice two pages cheat sheet for guys like us
Just print it out and have it close by, and use shortcuts for everything!
After a while you won't need it anymore, you're hands will know them by reflex
Sheet can be downloaded from here: http://code.google.c...pse-cheatsheet/
Do you have any shortcuts you use constantly which aren't mentioned here?
Let me know by posting below and I will try to get it added to this list!
[/spoiler]
Adding custom sounds
Just a little info dump on how to add sounds for 1.6.X+
[spoiler]
Sound files should be placed into the following location:
"assets/{modID}/sound"
So for my mod which has a modID="mazmod" it would be:
"assets/mazmod/sound"
NB: Keep in mind all modid's MUST be all lowercase!
i.e. mazMod will result in an error when exporting the mod!
Sounds are loaded with the SoundLoadEvent, if you are unfamiliar with events you may want to look into them. The class name is irrelevant but you will need to reference it later.
public class TutSoundEvents {
@ForgeSubscribe
public void onSound(SoundLoadEvent event) {
// You add them the same way as you add blocks.
event.manager.addSound("mod_id:hit.ogg");
}
As with all events you need to register the event subscription, so forge knows to notify the class of events.
So add this to Client Proxy (or at least make sure to call it on client side only),
and call it during the setup.
MinecraftForge.EVENT_BUS.register(new TutSoundEvents()); // Name of the class containing the ForgeSubscribe above
Then you can play the sound at anytime by using the playSound.. methods of World such as:
// Args: entity, sound, volume (relative to 1.0), and frequency (or pitch, also relative to 1.0)
WorldObject.playSoundAtEntity(EntityPlayerObject, "mod_id:hit", 1.0F, 1.0F);
// if you have file names which ends with an number, exclude the number when using playSound!
Randomness to sounds
Minecraft has a simple and nice system for having variations in your sounds.
If I used just the "hit" for every onHit with my sword it would be rather static and boring.
So to fix that let's add two sound files like this:
These will be grouped as variations of the same sound, called "hit".
So by referring to the "hit" sound you will get one of the two at random!
You can of course have many many more different files than just two
To play them simply as it to play the sound name without the number:
NB!: asking it to play "hit1" or anyother sound name which ends in a number will fail even if it's the only sound in the group!
I hope this helped
[/spoiler]
Creating a new simple Fluid:
[spoiler]
While creating my own fluid I found a post on the forge forums where Homletmoo explained it to another user.
So I got it to work after a while and since then I have seen other questions about the fluid system, so I decided to use a few minutes to tell how to add a simple fluid.
We start by creating the Fluid, so create a class which extends Fluid.
Pass a fluid name to the super constructor.
Then we can set the Density and Vicosity of the fluid.
Lastly we want to make the FluidRegistry register the fluid.
Heres how my fluid looks like:
public class TutFluid extends Fluid {
public TutFluid() {
super("TutorialFluid");
setDensity(10); // How tick the fluid is, affects movement inside the liquid.
setViscosity(1000); // How fast the fluid flows.
FluidRegistry.registerFluid(this); // Registering inside it self, keeps things neat
}}
We initialize the Fluid in the same way as with items and blocks.
It handles registration of itself inside the class so we only need to intialize it.
Because FluidBlocks need access to their fluids we must initalize fluids BEFORE blocks!
public static Fluid tutFluid;
// and before blocks are initialized:
tutFluid = new TutFluid();
Now on to the block. I will not cover how it's initialized as it's the same as any other block.
Just make sure it's after the respective fluid is initialized.
public class BlockTutFluid extends BlockFluidClassic {
public BlockTutFluid(int Id) {
super(id, ModTutorial.tutFluid, Material.water);
ModTutorial.tutFluid.setBlockID(id); // Set the fluids block ID to this block.
}
// Use Register Icon as usual to get the block's icon.
// If you want you can reuse the water texture and change the color of it by doing as I have below:
@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta) {
return Block.waterMoving.getIcon(side, meta);
}
@Override
public int colorMultiplier(IBlockAccess iblockaccess, int x, int y, int z)
{
return 0x66FF00; // HEX color code as indicated by the 0x infront. This is a greenish color.
}
That's it! You should now have a working fluid block!
If you want to be able to use a bucket to pick up the fluid keep reading.
Okay let's start by creating an item which will act as our bucket item, this will be the filled bucket.
If the player uses an empty bucket on our fluid we want him to get a bucket full of that fluid, and that's the item we are creating now.
So create a class which extends ItemFluidContainer, the super constructor wants the itemID.
No need to show you that code, the interesting part is the onItemRightClick method.
You need to override that and inside it do the following (code based upon ItemBucket):
[spoiler]
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true);
if (movingobjectposition == null)
{
return item;
}
else
{
FillBucketEvent event = new FillBucketEvent(player, item, world, movingobjectposition);
if (MinecraftForge.EVENT_BUS.post(event))
{
return item;
}
if (event.getResult() == Event.Result.ALLOW)
{
if (player.capabilities.isCreativeMode)
{
return item;
}
if (--item.stackSize <= 0)
{
return event.result;
}
if (!player.inventory.addItemStackToInventory(event.result))
{
player.dropPlayerItem(event.result);
}
return item;
}
if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
{
int x = movingobjectposition.blockX;
int y = movingobjectposition.blockY;
int z = movingobjectposition.blockZ;
if (!world.canMineBlock(player, x, y, z))
{
return item;
}
if (movingobjectposition.sideHit == 0)
{
--y;
}
if (movingobjectposition.sideHit == 1)
{
++y;
}
if (movingobjectposition.sideHit == 2)
{
--z;
}
if (movingobjectposition.sideHit == 3)
{
++z;
}
if (movingobjectposition.sideHit == 4)
{
--x;
}
if (movingobjectposition.sideHit == 5)
{
++x;
}
if (!player.canPlayerEdit(x, y, z, movingobjectposition.sideHit, item))
{
return item;
}
if (this.tryPlaceContainedLiquid(world, x, y, z) && !player.capabilities.isCreativeMode)
{
return new ItemStack(Item.bucketEmpty);
}
}
return item;
[spoiler]
This checks if you can place the fluid at that location and if you can then it places the fluid there and repalces the item with an empty bucket.
If you are using you're own empty fluid container then return it here instead.
If you are using a different item than the empty bucket to pickup the fluid you will have to modify the onRightClick method for that item.
It's of course possible to use the same item for the empty and full container, it shouldn't be hard for you to figure it out if you want to.
But if you are going to use the regular empty bucket then read on
So for the bucket to work we need to know when the player is using the bucket on our fluid.
NB: This means using events, if you aren't familiar with events go read up on them before you continue as this tutorial does NOT cover events.
That means we will need to listen for a bucket event like this:
@ForgeSubscribe(priority = EventPriority.NORMAL)
public void FillBucket(FillBucketEvent event) {
ItemStack result = attemptFill(event.world, event.target);
if (result != null) {
event.result = result;
event.setResult(Result.ALLOW);
}
}
private ItemStack attemptFill( World world, MovingObjectPosition p )
{
int id = world.getBlockId( p.blockX, p.blockY, p.blockZ );
if ( id == ModTutorial.tutorialFluidBlock.blockID )
{
if ( world.getBlockMetadata( p.blockX, p.blockY, p.blockZ ) == 0 ) // Check that it is a source block
{
world.setBlock( p.blockX, p.blockY, p.blockZ, 0 ); // Remove the fluid block
return new ItemStack( ModItems.bucketTutFluid ); // Return the filled bucked item here.
}
}
return null;
}
That's it, we now have our very own fluid!
You can of course custemize it however you would like! you could for example make it hurt on contact(by using onEntityCollidedWithBlock) or whatever you'd like.
[/spoiler]
That's it for now folks!
I hope you found some useful information within my posts
Here's something I want to share with you, a Java cheat sheet like the eclipse one above.
It can be a nice sheet to look at when you are unfamiliar with Java's basic syntax Dream in Code - Java Cheat Sheet
Looks good, but could you go in depth a little bit more for custom mobs? Is there any way to have it so if you have sound1, sound2, (just like mc mob sounds) that it will play it randomly?
What about music and records for music in 1.5 I used event.manager.soundPoolMuisc.addSound then it just added the music to the sound pool but now does it need a specific location or something? Thanks
I believe that you use .addStreaming and the folder "records" instead of sounds. for records,
So I guess .addMusic and using a folder "music" would be the case for music but I haven't tested or seen anyone do this yet so sadly I can't be sure.
Added a tutorial, or well more of a text than a tutorial really.
But anyways added a some information on Shortcuts in eclipse.
I found these to be quite nifty and recommend using them while working!
Some of them will make you're life a lot easier so if you aren't aware or aren't using them, there might me time to start now
Thanks for the tutorials Mazetar! I've been trying to add custom sounds by following your tutorial, but not having any luck. Perhaps you could shed some light on it for me. I've got my sound files in <assets/coolaliassimplewands/sound/>, they are .ogg format.
In the log, it prints the debug message twice in a row, so this class appears to be called twice. Ah, fixed that, I was loading the sounds in PreInit as well as in the ClientProxy. Still not getting sound though.
Here's my ClientProxy:
public class ClientProxy extends CommonProxy
{
@Override
public void registerRenderers() {
MinecraftForge.EVENT_BUS.register(new SimpleWandSounds());
}
}
If I play the "random.bow" sound, it works fine; my custom sound? no sound.
I've tried adding ".ogg" to the filename when I call it and writing the ModID by hand within the " ". I'm stumped. The sound file plays fine in an audio program, it's less than 1 second in length and 17.1 KB, if that info is relevant.
coolAlias: This is totally my fault and not yours!
When I created the tutorial I seem to have ed things up a bit as I was reading my code, I'm not sure if I looked at the wrong project or if I was just being a retard
I'm fixing the errors in the tutorial now and I will post an updated post below here to explain what needs to be changed. It's not much but it's important
Minecraft has a cool feature which lets you give it several sounds with similar names and let it choose one at random whenever it's called for. This is simply done by having numbers in the end of the sounds name.
Quite nice when you want to have variations on the sound effects in your mod.
NB: This means that calling for a sound which ends with a number directly will not work!
// Does NOT work!!!
world.playSoundAtEntity(player, "modid:hit1", 1F, 1F);
// since hit1 is grouped as a possible file to play for "hit" it's not found when minecraft looks for the group "hit1" since it's not there!
Thanks for all the replies Mazetar! I added ":sound/" when I addSound, then removed the numerals from my sound files and arranged it so there is only one of each in the folder /sound/. Also fixed where I play the sound, but I still don't get any sound :-/
Just for reference, here's the new code:
public class SimpleWandSounds
{
@ForgeSubscribe
public void onSound(SoundLoadEvent event)
{
String [] soundFiles = {
"wand_charging.ogg",
"wand_discharge.ogg",
"wand_impact.ogg"
};
for (int i = 0; i < soundFiles.length; i++)
{
System.out.println("[SIMPLE WANDS] Loading sound " + ModInfo.ID + ":sound/" + soundFiles[i]);
event.manager.addSound(ModInfo.ID + ":sound/" + soundFiles[i]);
}
}
}
// in the Item's onPlayerStoppedUsing function:
par2World.playSoundAtEntity(par3EntityPlayer, ModInfo.ID + ":wand_discharge", 1.0F, 1.0F);
// also tried with ".ogg" appended
That's pretty cool about the randomized sounds, though. I'll have to look into that once I get this working
EDIT: I also tried directly adding each sound, like so:
event.manager.addSound("coolaliassimplewands:sound/wand_discharge.ogg");
etc.
The sound tutorial worked well for me. The ogg files were found on the first client run once I fixed a couple of my errors related to using the Client Proxy. The random sound feature is pretty sweet. Thank you for sharing this information. Now to try out the Fluid tutorial.
You managed to decompile and continue without me giving source code? O_O Bro, you are a god. Of course do whatever the [REDACTED] you want!!!! Good luck on it
package lom.LotsOMobsCore;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.common.MinecraftForge;
public class LotsOMobs_EventSounds {
@ForgeSubscribe
public void onSound(SoundLoadEvent event)
{
event.manager.soundPoolSounds.addSound("lom:sound/deer.ogg");
}
}
And I use the sound in my Entity file like this:
/**
* Returns the sound this mob makes while it's alive.
*/
protected String getLivingSound()
{
return "lom:deer";
}
Im not sure about what Im doing wrong here so I hope you can help since its a important part of the mod and my previous way of adding sounds got deleted
I'm Maz and I have been modding for a while now.
I haven't released any mods and I don't plan to either. I'm modding mostly to learn and I do love learning more of this wonderful art of programming! Now with 1.6 hitting I found a question getting asked a few times and I got the chance to learn the answer so then I'll put it up here for others to learn as well
Please remember the golden rule of all tutorials I ever will create:
"First and before all, learn the basics of programming." This will save you time and tears, trust me!
If you want to learn java, then this is a great place to start and I would say that this is the pre-req. for modding.
http://see.stanford....aa-866adcae1111
A few words about errors:
[spoiler]
If you find my code to be wrong, outdated or unclear please post a comment saying so.
I'll try to fix my errors when my work and social life allows me to
If you get errors / crashes and need help then please:
- Provide the full error log pasted at www.pastebin.com or a similar paste site.
- Provide the source of all relevant classes on a paste site(with syntax highlighting set to Java), github or similar.
- Describe what you try to do, and what happens instead.
- If you post code inn the forum use CODE and SPOILER tags, else the thread becomes a mess and you're chance of getting help reduced!
Also I'm only one person, and this thread may not be the most active at a given time.
So to get help as fast as possible then remember the things mentioned above and go to
MinecraftForge - Modding Support Forum and ask there, at least if it's not directly related to my tutorials!
[/spoiler]
My plans:
[spoiler]
I don't plan on releasing any of the "common" tutorials, there probably won't be a lot of basic block tutorials and the like here. I'd like to write on subjects which are not already well documented.
Unless one can really make an improved version of the tutorial, I'd see no need to create a new text tutorial on the subject when there's already a good one out there!
My next subject will probably be another one related to Java and Eclipse more than Minecraft directly, but I'm pretty sure most of the folks here will enjoy it If you have suggestions feel free to voice them, I won't promise anything but if it's good I may do it or mention it for some of the other (and better) writers
I do have an active AFK life, just like most of the other modder/writer/human/alien's here.
So while I do want to get tutorials and information out here, I got to juggle my other stuff as well.
I will update this thread whenever I get the time and feel like it, not before! Sorry that's just how it is being adult like and all that. It sucks but that's how it is
[/spoiler]
Eclipse Keyboard Shortcuts!
Speed up you're workflow by using shortcuts, saved me a ton of time!
[spoiler]
In this text I will talk about a few things that will speed you up while using eclipse.
As with most other computer programs, eclipse got keyboard shortcuts. In fact it got tons of them so I wont even try to start covering them here!
Instead I will show you a few very usefull ones which I find myself using quite often.
So with that let's get started.
Renaming - Refactoring.
Mark any name, be it a method name or a variable name or even a class name.
Press Shift+Alt+R to start renaming. A small box will tell you to enter the new name so do it and press enter.
Eclipse will try to rename it everywhere inside you're project!
Go to decleration.
Mark any methodname, variable name or the like and press F3.
This will take you to the place where it's decleared.
I find it super useful when navigating minecraft's code!
Switch between open files.
Press Ctrl+E and you get a small box listing all the currently opened files,
use the arrow keys to select one from the list and tap enter to view that file.
PS: If you type when browsing the list, you filter the list to match you're input!
Open a Type like a class.
Instead of looking trough all the packages of net.minecraft.entity to look into the new EntityLivingBase,
you can hit a simple shortcut and open the "Open type" window.
Press Ctrl+Shift+T and start typing the type name.
It supports the use of * if you want all types with "fluid" in the name, then type
"*fluid" and you will get a list of all of them!
Open a file / resource.
You can open any file just as quickly as you could with any type above.
Just press Ctrl+Shift+R and it opens up the "Open Resource" window.
Which functions just like the one above except it searches for file names.
Quickly find variable or method inside a huge class.
If you are inside one of the larger classes like the World class and you want to find a method quickly, what do you do?
Do you ctrl+F and try to find it? Look at the Outline view and try to find it there?
Well there's an easier way, press Ctrl + O and a small box appers.
It contains a list of all the variables and methods of the class, and when you start typing it starts filtering the list.
So if I where to look for "SetBlock()" I'd just type "set" and it's right there, one click more and there we are!
Really useful! Also pressing Ctrl+O again shows the inherited members.
PS: To browse up and down the members of the list, just press Ctrl+Shift + Arrow (up or down).
Go to Line number #? Press Ctrl+L and enter the # of the line you want top, tap enter and there you are.
Organize Imports? Press Ctrl + Shift + O to make eclipse try to cleanup and fix imports for you.
Go to last edit location.
I must admit I accidently tapped this quite a few times and had no idea WHY I suddently jumped to the other side of the file!
But after learning of this shortcut I realised how useful it is.
Instead of browsing around to find where you last edited the damn file you only need to press Ctrl+Q to jump there.
Go top super/sub type quickly.
Instead of scrolling to the top of the file and clicking the extended classes name,
you can press Ctrl+T to show a dialogue where you can select super types of the class.
Pressing Ctrl+T again while the dialogue box is open will make it show Sub types instead!
Find ALL references to selected method/variable.
If you press Ctrl+Shift+G while having a method/variable marked, eclipse will search the entire workspace for references to it!
And shows you everywhere it's being used!
Some Text editing shortcuts.
Select to Line Start/End (Shift + Home/End)
Insert Line Above (Shift+Ctrl+Enter)
Insert Line Below (Shift + Enter)
Delete Line (Ctrl + D)
Move Line up/down (Alt + Up/Down)
Convert to Lower/Upper case (Shift + Ctrl + Y/X)
Toggle Comment (Shift + Ctrl + C)
Eclipse Shortcuts - Cheat sheet!
Michael Pellaton has created a nice two pages cheat sheet for guys like us
Just print it out and have it close by, and use shortcuts for everything!
After a while you won't need it anymore, you're hands will know them by reflex
Sheet can be downloaded from here: http://code.google.c...pse-cheatsheet/
Do you have any shortcuts you use constantly which aren't mentioned here?
Let me know by posting below and I will try to get it added to this list!
[/spoiler]
Adding custom sounds
Just a little info dump on how to add sounds for 1.6.X+
[spoiler]
Sound files should be placed into the following location:
"assets/{modID}/sound"
So for my mod which has a modID="mazmod" it would be:
"assets/mazmod/sound"
NB: Keep in mind all modid's MUST be all lowercase!
i.e. mazMod will result in an error when exporting the mod!
Sounds are loaded with the SoundLoadEvent, if you are unfamiliar with events you may want to look into them. The class name is irrelevant but you will need to reference it later.
As with all events you need to register the event subscription, so forge knows to notify the class of events.
So add this to Client Proxy (or at least make sure to call it on client side only),
and call it during the setup.
Then you can play the sound at anytime by using the playSound.. methods of World such as:
Randomness to sounds
Minecraft has a simple and nice system for having variations in your sounds.
If I used just the "hit" for every onHit with my sword it would be rather static and boring.
So to fix that let's add two sound files like this:
These will be grouped as variations of the same sound, called "hit".
So by referring to the "hit" sound you will get one of the two at random!
You can of course have many many more different files than just two
To play them simply as it to play the sound name without the number:
NB!: asking it to play "hit1" or anyother sound name which ends in a number will fail even if it's the only sound in the group!
I hope this helped
[/spoiler]
Creating a new simple Fluid:
[spoiler]
While creating my own fluid I found a post on the forge forums where Homletmoo explained it to another user.
So I got it to work after a while and since then I have seen other questions about the fluid system, so I decided to use a few minutes to tell how to add a simple fluid.
We start by creating the Fluid, so create a class which extends Fluid.
Pass a fluid name to the super constructor.
Then we can set the Density and Vicosity of the fluid.
Lastly we want to make the FluidRegistry register the fluid.
Heres how my fluid looks like:
We initialize the Fluid in the same way as with items and blocks.
It handles registration of itself inside the class so we only need to intialize it.
Because FluidBlocks need access to their fluids we must initalize fluids BEFORE blocks!
Now on to the block. I will not cover how it's initialized as it's the same as any other block.
Just make sure it's after the respective fluid is initialized.
That's it! You should now have a working fluid block!
If you want to be able to use a bucket to pick up the fluid keep reading.
Okay let's start by creating an item which will act as our bucket item, this will be the filled bucket.
If the player uses an empty bucket on our fluid we want him to get a bucket full of that fluid, and that's the item we are creating now.
So create a class which extends ItemFluidContainer, the super constructor wants the itemID.
No need to show you that code, the interesting part is the onItemRightClick method.
You need to override that and inside it do the following (code based upon ItemBucket):
[spoiler]
[spoiler]
This checks if you can place the fluid at that location and if you can then it places the fluid there and repalces the item with an empty bucket.
If you are using you're own empty fluid container then return it here instead.
If you are using a different item than the empty bucket to pickup the fluid you will have to modify the onRightClick method for that item.
It's of course possible to use the same item for the empty and full container, it shouldn't be hard for you to figure it out if you want to.
But if you are going to use the regular empty bucket then read on
So for the bucket to work we need to know when the player is using the bucket on our fluid.
NB: This means using events, if you aren't familiar with events go read up on them before you continue as this tutorial does NOT cover events.
That means we will need to listen for a bucket event like this:
That's it, we now have our very own fluid!
You can of course custemize it however you would like! you could for example make it hurt on contact(by using onEntityCollidedWithBlock) or whatever you'd like.
[/spoiler]
That's it for now folks!
I hope you found some useful information within my posts
Here's something I want to share with you, a Java cheat sheet like the eclipse one above.
It can be a nice sheet to look at when you are unfamiliar with Java's basic syntax
Dream in Code - Java Cheat Sheet
Find out how I generate....coolAlias...world structure generation and rotation tool...
Make sure you have both of these imports:
I believe that you use .addStreaming and the folder "records" instead of sounds. for records,
So I guess .addMusic and using a folder "music" would be the case for music but I haven't tested or seen anyone do this yet so sadly I can't be sure.
Comic Sans is the best
But anyways added a some information on Shortcuts in eclipse.
I found these to be quite nifty and recommend using them while working!
Some of them will make you're life a lot easier so if you aren't aware or aren't using them, there might me time to start now
May be expanding to to tank containers and such laters.
Here's my code:
The Sounds class for my mod:
In the log, it prints the debug message twice in a row, so this class appears to be called twice. Ah, fixed that, I was loading the sounds in PreInit as well as in the ClientProxy. Still not getting sound though.
If I play the "random.bow" sound, it works fine; my custom sound? no sound.
Thanks for any help!
When I created the tutorial I seem to have ed things up a bit as I was reading my code, I'm not sure if I looked at the wrong project or if I was just being a retard
I'm fixing the errors in the tutorial now and I will post an updated post below here to explain what needs to be changed. It's not much but it's important
And then when you call the sound just use the string "modid:hit" and it will randomly choose between the sounds named hit[#].
Quite nice when you want to have variations on the sound effects in your mod.
NB: This means that calling for a sound which ends with a number directly will not work!
Thanks for all the replies Mazetar! I added ":sound/" when I addSound, then removed the numerals from my sound files and arranged it so there is only one of each in the folder /sound/. Also fixed where I play the sound, but I still don't get any sound :-/
Just for reference, here's the new code:
EDIT: I also tried directly adding each sound, like so:
Still no luck...
Patreon
My .ogg files are in /assets/lom/sound/
I register the class in my PreInit:
My Sound class looks like this:
And I use the sound in my Entity file like this:
Im not sure about what Im doing wrong here so I hope you can help since its a important part of the mod and my previous way of adding sounds got deleted
Into this:
example
protected String getLivingSound()
{
return "mob.ghast.moan";// < how do i do my custom sound??
}
http://www.minecraftforum.net/topic/1506682-132modloader-and-forge-i-herd-u-liek-mudkipz-mod-shiny-mudkipz-update/
http://www.minecraftforum.net/topic/1506682-132modloader-and-forge-i-herd-u-liek-mudkipz-mod-shiny-mudkipz-update/