You should do one on custom tile entities, like a leveling table for your mana bar
I thought about this, but it seems unnecessary. There is already a method 'setMaxMana' that can be accessed from anywhere you can access the player, such as 'onBlockActivated', from wherein you could easily write a little code to check the player's current mana level, experience level, or other traits and adjust them as needed. You wouldn't even need a tile entity.
What exactly were you thinking this new tutorial would entail? Perhaps if I understood better specifically what you need, I could write something up on it
I would guess that's because Tile Entities and Gui's are all so very unique. If you have something specific in mind that's not covered in the following tutorials, explain it in some more detail and I'll see if I can cover it.
Added section 3.4: Using DataWatcher to Synchronize. Pretty easy to convert to DataWatcher, a very useful tool for keeping constantly changing data, such as health or mana, in sync between server and client without sending custom packets.
the extended properties stuff now crashes when loaded on a server in 1,6,4. something about hating the gui
Did you try it with the updated code? I specifically put notes at the top of each section on how to update to the latest version. You will need to update your Forge as well for it to work.
... my bad. I forgot to mention that since Gui is client side only, you have to register it only on the client side.
Register your gui within an 'if (FMLCommonHandler.instance().getSide().isClient())' statement and your code should work fine.
Err, that should be 'getEffectiveSide', though 'getSide' might work in this case, sometimes it doesn't work correctly because you are not, in fact, on the server side, even though that might be the 'effective' side. See what I mean? Anyway, anytime you want to check which side you're on and you don't have access to a world object, you can use the following:
Na it worked good lol and now you know how to fix that part of the tutorial
Yep, already did I know getSide works from the main mod methods, but if you ever want to get the side you're on in other classes, it doesn't seem to work as intended. I put 'if (FMLCommonHandler.instance().getSide().isServer()) print on server, else print on client' in some methods and it only ever printed the client side! Switching to 'getEffectiveSide()' printed both. Just an FYI. And since getEffectiveSide also works in the main mod class, I recommend using it everywhere instead of getSide. That's just been my experience with it, anyway, not coming from true knowledge of how the two methods differ in implementation...
This worked perfectly for me, thanks, I even got a Mana Regeneration system to work
You're welcome. It's nice to see someone take it to the next level
I updated the Mana Gui Overlay with some notes on how to get transparency. There's also an accompanying texture file on my github if needed. It looks pretty nice as you run out of mana the background is sort of see through, like the hotbar slots.
Can you do a quick bit on how to do decent timer functions like for mana regen
I used a system like this in my Event Handler
@ForgeSubscribe
public void regenerateMana(LivingEvent event) {
if (event.entity instanceof EntityPlayer) {
EntityPlayer ent = (EntityPlayer) event.entityLiving;
ExtendedPlayer props = ExtendedPlayer.get(ent);
int mana = props.getCurrentMana();
int maxmana = props.getMaxMana();
if (mana < maxmana) {
int timer = props.getManaTimer();
timer++;
if (timer >= 100) {
props.consumeMana(-1);
}
props.setManaTimer(timer);
if (timer == 100) {
props.setManaTimer(0);
}
}
}
}
Where it says 100 it is the time in ticks, so 20 ticks = 5 seconds, in my case it regenerates 1 mana every 5 seconds, but I am currently working on adding a system so the player can have multipliers to increase it at a faster rate.
I also added a mana timer to the ExtendedPlayer.class in the sae way that maxMana and currentMana are made.
That looks fine, in my opinion. The only thing I would do differently is move all the timer and regen stuff into the ExtendedProperties directly so you only have to make a single method call from on LivingUpdate.
// create a generic onUpdate method in your ExtendedPlayer that handles everything you need during an update tick
public void onUpdate()
{
if (timer > 0) { --timer; }
if (timer == 0) {
replenishMana(-1);
timer = 100 +/- modifiers you want; create a method to determine mana regeneration rate
}
// other stuff you want to update, like active spell effects
}
This way you only need to call 'ExtendedPlayer.get(player).onUpdate()' from your onLivingUpdate method; everything else is hidden, as it should be
Of course, the above method will only update the regen timer with new rates after the last timer expires, so it's not very dynamic in that regard. A way to be more dynamic would be to keep the timer the same every time, but subtract more or less depending on certain factors:
// let's say that the base timer is 500, but our base regen rate is '5' so it still takes only 100 ticks
if (timer > 0) {
int amount = 5;
if (player is wearing my awesome armor) amount += 15;
if (player is affected by slowness) amount /= get potion amplifier +1;
if (player is hungry) amount = 0;
etc.
timer -= amount;
}
I'd suggest putting all of that outside the onUpdate method in it's own method such as 'updateManaTimer'. Also, you could make a method to 'addMana(amount)' or 'regenMana(amount)' that simply calls consumeMana(-amount) to make your update method more intuitive (why is this guy consuming a negative amount of mana??? lol). Consider making your updateManaTimer method return a boolean and see what you can do with that
Keep in mind that consumeMana also does some unnecessary calculations for regeneration, so you really would be better off just making a dedicated method to regen mana rather than using that method.
There are lots of ways you can improve the basic methods I wrote in the tutorial that will make your life easier and code simpler. Take the setCurrentMana method, for example. This is the code that I use:
Note how writing it in this way allows me to simplify the consumeMana method:
public final boolean consumeMana(int amount)
{
boolean sufficient = amount <= getCurrentMana();
setCurrentMana(getCurrentMana() - amount);
return sufficient;
}
All of the checks I did earlier are now handled automatically by the setCurrentMana method. Similarly, your regenMana method can now be a single line, because setCurrentMana will never set current mana as more than the max mana:
public final void regenMana(int amount) {
setCurrentMana(getCurrentMana() + amount);
}
Keep in mind that just because it's in a tutorial doesn't make it the best method - they are only demonstrations of basic concepts, and it's up to you to improve them. Half the fun is trying to find the most elegant / simplest solution to your particular problem.
Being that your the event master, what would an event for an auto smelting enchantment look like?
Btw its at the point where your gonna get a credit mention on my page lol
I did an event on wearing armor, that is when I wear armor, then the rain, it's killing me, when I write:
event.entityLiving.attackEntityFrom (DamageSource.cactus, 1);
I start at the world the game crashes ....
Rollback Post to RevisionRollBack
Make high-quality models in the Techne. And do the model in Blender.
I thought about this, but it seems unnecessary. There is already a method 'setMaxMana' that can be accessed from anywhere you can access the player, such as 'onBlockActivated', from wherein you could easily write a little code to check the player's current mana level, experience level, or other traits and adjust them as needed. You wouldn't even need a tile entity.
What exactly were you thinking this new tutorial would entail? Perhaps if I understood better specifically what you need, I could write something up on it
Tile Entities: Basic TileEntity Setup, Furnace-type Tile Entities, TileEntity Special Renderer
Packets: Packet Handler Basics, Basic Keybinding, Advanced Keybinding with Packets, also see examples in this tutorial. For a 'real-life' example, check the source for my mod linked in my signature.
Gui: Basic HUD-style Gui Overlay, Gui Text Input Field
Also, check Mazetar's Tutorial List for high quality tutorials on a wide variety of topics. All of the above can be found there
Did you try it with the updated code? I specifically put notes at the top of each section on how to update to the latest version. You will need to update your Forge as well for it to work.
https://bitbucket.org/Lithial/enchantmentoverhaul heres my code if you wanna look
... my bad. I forgot to mention that since Gui is client side only, you have to register it only on the client side.
Register your gui within an 'if (FMLCommonHandler.instance().getSide().isClient())' statement and your code should work fine.
Err, that should be 'getEffectiveSide', though 'getSide' might work in this case, sometimes it doesn't work correctly because you are not, in fact, on the server side, even though that might be the 'effective' side. See what I mean? Anyway, anytime you want to check which side you're on and you don't have access to a world object, you can use the following:
Sorry again - all sorts of mistakes today :-[
Yep, already did I know getSide works from the main mod methods, but if you ever want to get the side you're on in other classes, it doesn't seem to work as intended. I put 'if (FMLCommonHandler.instance().getSide().isServer()) print on server, else print on client' in some methods and it only ever printed the client side! Switching to 'getEffectiveSide()' printed both. Just an FYI. And since getEffectiveSide also works in the main mod class, I recommend using it everywhere instead of getSide. That's just been my experience with it, anyway, not coming from true knowledge of how the two methods differ in implementation...
You're welcome. It's nice to see someone take it to the next level
I updated the Mana Gui Overlay with some notes on how to get transparency. There's also an accompanying texture file on my github if needed. It looks pretty nice as you run out of mana the background is sort of see through, like the hotbar slots.
I used a system like this in my Event Handler
Where it says 100 it is the time in ticks, so 20 ticks = 5 seconds, in my case it regenerates 1 mana every 5 seconds, but I am currently working on adding a system so the player can have multipliers to increase it at a faster rate.
I also added a mana timer to the ExtendedPlayer.class in the sae way that maxMana and currentMana are made.
That looks fine, in my opinion. The only thing I would do differently is move all the timer and regen stuff into the ExtendedProperties directly so you only have to make a single method call from on LivingUpdate.
This way you only need to call 'ExtendedPlayer.get(player).onUpdate()' from your onLivingUpdate method; everything else is hidden, as it should be
Of course, the above method will only update the regen timer with new rates after the last timer expires, so it's not very dynamic in that regard. A way to be more dynamic would be to keep the timer the same every time, but subtract more or less depending on certain factors:
I'd suggest putting all of that outside the onUpdate method in it's own method such as 'updateManaTimer'. Also, you could make a method to 'addMana(amount)' or 'regenMana(amount)' that simply calls consumeMana(-amount) to make your update method more intuitive (why is this guy consuming a negative amount of mana??? lol). Consider making your updateManaTimer method return a boolean and see what you can do with that
Keep in mind that consumeMana also does some unnecessary calculations for regeneration, so you really would be better off just making a dedicated method to regen mana rather than using that method.
There are lots of ways you can improve the basic methods I wrote in the tutorial that will make your life easier and code simpler. Take the setCurrentMana method, for example. This is the code that I use:
Note how writing it in this way allows me to simplify the consumeMana method:
All of the checks I did earlier are now handled automatically by the setCurrentMana method. Similarly, your regenMana method can now be a single line, because setCurrentMana will never set current mana as more than the max mana:
Keep in mind that just because it's in a tutorial doesn't make it the best method - they are only demonstrations of basic concepts, and it's up to you to improve them. Half the fun is trying to find the most elegant / simplest solution to your particular problem.
Btw its at the point where your gonna get a credit mention on my page lol
event.entityLiving.attackEntityFrom (DamageSource.cactus, 1);
I start at the world the game crashes ....
Make high-quality models in the Techne. And do the model in Blender.