Jump to content

Recommended Posts

Posted

I have walked through the Sandblock, which is part of the Falling block..

 

though there is one question I can't seem to figure out what it does.. or why exactly it's important.

dustColorIn --  IT passes an int into ' getDustColor '... but I can't seem to grasp as to what numbers are imporant or what they mean.

Posted
16 hours ago, ChampionAsh5357 said:

It's just the color of the particle to render for the falling block. If you want, you can translate the colors into hex and put them into a color editor to view what colors they are.

Just a quick follow up on that..

 

if hex is 16 base 0-f,  how exactly is a - f represented?    or is the range 0-9 where what    

Do is use the 0xffffff  for say.. white.   or 999999 ??  
--  honestly I am unsure where the hex input came from in my head into an int slot.

Posted

The number you see is in decimal. If you convert it to hexidecimal you will get a familiar 0xAARRGGBB

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
34 minutes ago, Draco18s said:

The number you see is in decimal. If you convert it to hexidecimal you will get a familiar 0xAARRGGBB

Ummm  So it accepts an 'alpha' value?   X.x I swear some things are obtuse to be obtuse.
--(also it seems to have accepted 0xffffff just fine.. though it took a while to suspend meh block as it's got all the same properties of sand.)
-- I still would have had questions, though the first one would have made 100x more sense.

I had not seen the value, and I had only backtraced from 'SandBlock' to 'FallingBlock' to 'Block',  for the proper overrides & inclusions for tooltips, and was unsure of the 'valid' input range as I know that some like light level can accept greater than 15, but creates a weird visual effect  past 15.
--- also,  thanks for the prodding  I found an something I think might be an interesting way to enable/disable falling on blocks of sand.  it was always a real shame that sand & gravel have such nice particles & no real way to suspend them.
 

I apparently did not find the 'blocks' java class for minecraft til just now.  
--  followed the extends back... but I apparently didn't think to follow them forward again to see where it was used to view the official uses as an example [Honestly I didn't think it would be in there]

--------------------------------------------------------------------

 also, so I'm not unclear this is what my 'sand' constructor looks like.  {Use to look like}

package com.dephoegon.reclaim.aid.block;

import com.dephoegon.reclaim.aid.util.kb;
import net.minecraft.block.SandBlock;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.IBlockReader;

import javax.annotation.Nullable;
import java.util.List;

public class sand extends SandBlock {
    private static String tip0;
    private static String tip1;
    private static String tip2;
    public sand(int dustColorIn, Properties properties, String normtoolTip, String shiftToolTip, String ctrlToolTip) {
        super(dustColorIn, properties);
        if (normtoolTip != "") { tip0 = normtoolTip; } else { tip0 = null; }
        if (shiftToolTip != "") { tip1 = shiftToolTip; } else { tip1 = null; }
        if (ctrlToolTip != "") { tip2 = ctrlToolTip; } else { tip2 = null; }
    }

    @Override
    public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn)
    {
    -- snipped -- LongStory Short, logic to display tooltip & avoidance of null values and problems for blocks that don't get assigned a tooltip  
    }
}

& this is what 'for now my sand block(s) look like [also the 2,2 was just a holder till I looked it up for sure..  though I found where they are.. and I can do that easier now]

package com.dephoegon.reclaim.block.sand;

import com.dephoegon.reclaim.aid.block.sand;
import com.dephoegon.reclaim.aid.util.registration;
import com.dephoegon.reclaim.reclaim;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.fml.RegistryObject;

import java.util.function.Supplier;

public class altcolor {
    public static final RegistryObject<Block> WHITE_SAND = register("white_sand",
            () -> new sand(0xffffff, AbstractBlock.Properties.create(Material.SAND)
                    .hardnessAndResistance(2,2)
                    .harvestLevel(1).harvestTool(ToolType.SHOVEL),"","",""));

    public static void register() { }

    public static <T extends Block> RegistryObject<T> register(String name, Supplier<T> block) {
        RegistryObject<T> exit = registration.BLOCKS.register(name, block);
        registration.ITEMS.register(name, () -> new BlockItem(exit.get(),
                new Item.Properties().group(reclaim.RECLAIM_COMPRESSION)));
        return exit;
    }
}

 

Posted

Whether or not it actually uses the alpha value depends on various other factors.

(And of course it accepts 0xffffff: that's a valid integer literal)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
15 minutes ago, Draco18s said:

Whether or not it actually uses the alpha value depends on various other factors.

(And of course it accepts 0xffffff: that's a valid integer literal)

Hey....  xD. I'm not use to hex values being used directly. Maybe it maybe me..... but i think dec when i see int....  (my failure i know)

 

Though...  one last question.   How do you get a vanilla block yo use a custom class.

To clarify i got my sand class setup to allow/disallow 'falling', by checking for a certain block above it (and will check through a tower of the same block)..

I would like to include the vanilla minecraft sands, without replacing them.

I'm not exactly sure how to start looking, might need to just do another block... but I'd rather use the vanilla block if possible. 

Posted

Look at the Blocks class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
10 hours ago, Draco18s said:

Look at the Blocks class.

I'm going to be upfront..  I didn't understand what you wanted me to see in it.  (Unless you mean how MC did their registries)     I think I got a grasp on 'what' it kinda expects ... I'm just going to post a relevant question to what I'm trying to understand now.

Posted

Ignore the operational code and think about what the class exposes to other classes.

What fields and properties does it have?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
28 minutes ago, Draco18s said:

Ignore the operational code and think about what the class exposes to other classes.

What fields and properties does it have?

From what I can .. gather, and I'm sure this is my confusion going on..        It has public Objects that are effectively the block registry calls.

Wait?  Would it be possible to actually override a public object, and have it use it? ---   

 

I'm not sure I understand,   though the only bit I can honestly gather from that is a string name key, & the block object calling a new instance of a block (sand, log, etc) with properties defined in those block classes, which are often calling abstractblocks for properties, and extending special classes (like fallingblock) which tend to fall onto blocks, then abstract blocks themselves.

 

perhaps I'm missing the forest for the trees (or missing the trees for the forest), but  I'm not getting how you meant that.

Posted
5 hours ago, DePhoegon said:

 though the only bit I can honestly gather from that is a string name key, & the block object calling a new instance of a block (sand, log, etc) with properties defined in those block classes, which are often calling abstractblocks for properties, and extending special classes (like fallingblock) which tend to fall onto blocks, then abstract blocks themselves.

Ignore that stuff. It's not relevant.

5 hours ago, DePhoegon said:

public Objects

This. These are accessible from your code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
19 minutes ago, Draco18s said:

..

This. These are accessible from your code.

Ok, I 'think' i get the angle. 
-- I also, have gotten some .. idea of how other special classes are .. structured from that same page. 

I feel as if there is an 'answer' in front of my face, and I'm not exactly connecting the dots.

I am left wondering,   'Accessible from' my code, which implies a possibility of changing/overriding it and having the native code take it.
-- or it just means I could use that object in my own registry, but I am confused as to what is & isn't useful .

I can register those objects, but I am left with the requirements (assuming, basic override/injecting a subclass w/ behavior overrides)
- That it still work & registered to the same namespace for the item & modid (minecraft & sand, in this case)for compatibility of all other aspects & interactions calling it else where.
- That it clearly behaves with the additional override (this case, literally sticking to it self if a certain slab is sitting above it & it's all the same block to it)

I feel actually kind of stupid, I can hold the object in a manner of speaking.. but I don't know what it'll take get it in there. [I have a 'solution' working, but I genuinely don't understand why it works exactly]

Thank you for your time.  I just have the feeling, I'm not looking at the pieces correctly and my way of thinking is ignoring an aspect that could lead to a far better understanding & solution. >.>   i should let this roll around in my head like the sphere of an object it is,  perhaps I am missing something extensively obvious .. but it'll show it self in time. 

Posted
//your code
Block b = Blocks.SAND;

:|

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
31 minutes ago, Draco18s said:

//your code
Block b = Blocks.SAND;

:|

Ok...  i got to admit, I am both thoroughly  unsure and confused.   I think we need a common understanding of where  I am on my code & thinking..   I'll just share the github link of it.
-- in aid/util/registration.java   is where I am atm, and i currently have the overrides in ./block/sand/altcolor.java  
-- Mod Code

I don't think I achieved the same spot, but perhaps this can help show 'how' I'm thinking about things, as I may not be grasping how you are phrasing things, or as easily I didn't communicate well enough and we don't aren't understanding the same intent, though I am grateful for your attempts at helping to say the least.

Posted (edited)

Oh dear god.

All of these do fucking nothing. Every single one of those methods is empty.

Also, class names start with an UpperCaseLetter.

Why the fuck is this Object?

You really like Pokemon Exceptions. You don't even need try-catch. That's what instanceof is for.

This can't even throw an exception.

And apparently you have something against != as well.

You aren't even using this value.

Do not do pointless logging.

fall = falls is too hard?

This entire method is a fucking nightmare. Also str.isEmpty().

 

And I still don't know where you are trying to check the block above, per your original post.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 hours ago, diesieben07 said:

They force the class to load, so the registry objects get registered. Which is a TERRIBLE way to do this. Just put the deferred register and its objects in the same class.

Ok that's fair.
But it's still terrible.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
3 hours ago, Draco18s said:

Oh dear god.

All of these do fucking nothing. Every single one of those methods is empty.

Also, class names start with an UpperCaseLetter.

Why the fuck is this Object?

You really like Pokemon Exceptions. You don't even need try-catch. That's what instanceof is for.

This can't even throw an exception.

And apparently you have something against != as well.

You aren't even using this value.

Do not do pointless logging.

fall = falls is too hard?

This entire method is a fucking nightmare. Also str.isEmpty().

 

And I still don't know where you are trying to check the block above, per your original post.

In order, X}  

1.  (Force class to load, as was explained)  and was how it was shown.. I am up for 'changing it up' & optimizing it later,     That's  just the method that was shown.  I want to optimize it later for sure.

2.o_hand  ->   is offhand   I got sick to death of doing typos, and used it & m_hand for main hand ...   (offhand is the shield slot typically)

2. .... actually [ target = (LivingEntity)event.getTarget(); ]  inside of  (AttackEntityEvent event) is 100% capable of causing an error.
-- Try setting it up & smacking with any melee attack (fist or weapon) the following
a.  Any Minecart
b. Any End Crystal
c. Any Item Frame.
d. Any Boat   
----  it literally causes the game to close with an exception.   All those things can both 'trigger the attackEntity event'  and be inside the target of the player, which will cause an exception when cast into a (Living Entity), which was used to apply the potion effects...
~~ Strangely enough,  a armor stand  not only is uneffected by it, but can accept potions applied to it as well.

3.  It does do something,  It fails & does nothing, which means 'target' is null still, and no potion effects get applied to the target that was hit.
--- which means, it prevents the game from being shut down from an unintended casting of a target into a living entity object (which is needed to apply potion effects on)

4.  That's just nitpicking really,  That's an old logic habit....    Some reason it slipped my mind,  either way,     (!(thing == thing)) same effect of (thing != thing)  
---likely I honestly fell back into an old habit when inverse of true statement was my thought on that.

5. I know...  It's not complete (i've not  finished the blocks, as I'm working towards combat centric things, and I'm debating what I want to do with it)
--- also,  to note, I remember why I put try { atker = (LivingEntity)livi.getAttackingEntity(); } catch (Exception e) { }  (for future use)      things like minecarts & end crystals can harm the player & other entities, and that event fires when an entity get hurt.... and given I just got off of just randomly finding out that casting the target of my hit into a (living entity) object can cause fatal exceptions, it's there to 'do NOTHING' if that happens, and an prevent fatal exceptions from going off because of a weird entity causing damage that isn't a livingentity for some reason.
~~~  Yes I plan to use it later..    that was for an armor thing.

6. meh...   Again   alot of the primary page is tutorial code....   I left what was shown,  and I'm learning what does what.. .and pruning what doesn't work.   
-- yes, it annoys me as well but that's not on the short list atm.

7. as for 'fall = falls'  . I don't like doing that, as i prefer the geniune fallback if some unknown reason happens  a valid variable gets assign (right or wrong) and prevents weird unknown errors.

8.  The method is 100% straight forward    It's just a nested if loop that of course tests each string once (effectively) and doesn't attempt to assign an empty tooltip.
_NormToolTip Is on it w/ no shift or cntl held down (either one)
_When shift or cntrl is held down,  it shows the correct one.
_When Shift & Cntrl are held down.. it shows Cntrl over Shift.
---- to be fair I actually didn't think to check for a method that checks if  a string is empty.
~~~  It uses Exclusionary logic, but if you can think of a faster way of doing 
-normal tooltip (no keys held)
-Shift Tooltip (either shift held)
-Cntl ToolTip (either Cntrl held)
-Cntl tooltip over  Shift tooltip (when a Cntrl & Shift is held, either side)
 I'm all ears if you think you can do that faster and prevent it from using a null value.

Edited by DePhoegon
clarifications & reasons for 'seemingly useless' things.
Posted
2 hours ago, diesieben07 said:

And this is why you don't blindly cast something but use instanceof.

very true...    something to consider. 

 

Now the question,  which one is is better, speed wise.   (i know it's far better not produce errors or exceptions if you can help it, and this is more a  thought experiment)
 { target = (LivingEntity)event.getTarget(); } catch (Exception e) { } 
if (event.getTarget() instanceof (LivingEntity)) { target = (LivingEntity)event.getTarget(); }
---  don't roast me on the instance of syntax,    I've not actually written it out yet

Posted
14 minutes ago, diesieben07 said:

Premature optimization is the root of all evil. Do not write code in a particular way because it is "faster".

The way to do this is to use instanceof. Blindly casting and catching any and all exceptions is just terrible.

Well I figured, about the blind casting, just comes across as a potential problem, even if caught as it self still doesn't exactly solve the issue persay is just the logic of relying on the fail safe with known faults, rather then attempting to not use the faults.
-- I had honestly not thought of instanceof (despite using it in the same file elsewhere, no excuse just likely exhausted when I did it)

I was going to use instanceof, and hopefully test it in a variety pack near the end (checking to see if false players that smack things would trigger it, and how to avoid such things)
--  this for later I suppose.

proper methods trump shortcuts..  

 

gotta work to see if i can figure out how to put stairs in, or what i'm not getting there. (got walls/fences/glass panes next... then of course all the supporting json for models, and teh textures.. but  that's not done yet x})

Posted
14 hours ago, DePhoegon said:

2.o_hand  ->   is offhand   I got sick to death of doing typos, and used it & m_hand for main hand ...   (offhand is the shield slot typically)

No, why is it's Type Object and not Item?

14 hours ago, DePhoegon said:

2. .... actually [ target = (LivingEntity)event.getTarget(); ]  inside of  (AttackEntityEvent event) is 100% capable of causing an error.

This is why you use instanceof.

14 hours ago, DePhoegon said:

3.  It does do something,  It fails & does nothing, which means 'target' is null still, and no potion effects get applied to the target that was hit.
--- which means, it prevents the game from being shut down from an unintended casting of a target into a living entity object (which is needed to apply potion effects on)

Sorry, a couple of the links got messed up. And I noticed the forum screwing up my post writing this one (I'll be at the end of a line, make a typo, hit backspace, and the cursor jumps to the middle of the line and deletes a character. I meant this section.

You've fixed it, but now you have two checks for null where you could just combine the two blocks and do it once. No sense checking to see if there's a valid object to assign with and then separately checking to see if you assigned anything to it...

14 hours ago, DePhoegon said:

7. as for 'fall = falls'  . I don't like doing that, as i prefer the geniune fallback if some unknown reason happens  a valid variable gets assign (right or wrong) and prevents weird unknown errors.

The two variables are the same type. It's literally pointless. It can never fail in an unexpected way, and if it does, let the program crash, it's not your problem.

14 hours ago, DePhoegon said:

8.  The method is 100% straight forward    It's just a nested if loop that of course tests each string once (effectively) and doesn't attempt to assign an empty tooltip.

And I made it simpler and easier to read.

public void addInformation(ItemStack stack, IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
	if(!kb.HShift() && !kb.HCtrl() && !tip0.isEmpty()) tooltip.add(new StringTextComponent(tip0)); //if neither pressed, show tip0 (if not empty)
	if(kb.HCtrl() && !tip2.isEmpty()) tooltip.add(new StringTextComponent(tip2)); //if ctrl, show tip2 (if not empty), do first
	if(kb.HShift() && !tip1.isEmpty()) tooltip.add(new StringTextComponent(tip1)); //if shift, show tip1 (if not empty)
}

 

3 hours ago, DePhoegon said:

Now the question,  which one is is better, speed wise.

instanceof. Try-catch is monumentally slow. I've actually tested this. Inadvertently, but I did (that's what happens when you're doing reflection inside bytecode manipulation and discover that the game is running at 20 SPT instead of 20 TPS and fix it by removing the try-catch and just letting your injected method throw an error you know will never actually be thrown and bypass the compiler check for unhandled exceptions).

But if course, if you had to ask that question after implementing one over the other because, in your own words, "it was faster" you obviously didn't even bother doing a test to find out if it was actually true.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 hour ago, Draco18s said:

instanceof. Try-catch is monumentally slow. I've actually tested this. Inadvertently, but I did (that's what happens when you're doing reflection inside bytecode manipulation and discover that the game is running at 20 SPT instead of 20 TPS and fix it by removing the try-catch and just letting your injected method throw an error you know will never actually be thrown and bypass the compiler check for unhandled exceptions).

But if course, if you had to ask that question after implementing one over the other because, in your own words, "it was faster" you obviously didn't even bother doing a test to find out if it was actually true.

Umm  I didn't do it 'because it was faster'  I asked it as an after thought, a curiosity ...  nothing more.    would you kindly not assume why I used the method.
---  psst...  I used try Catch when I was dead tired & to give feedback..  it wasn't meant as the end goal, though I should have noted to find the proper method later.

 

1 hour ago, Draco18s said:

 


public void addInformation(ItemStack stack, IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
	if(!kb.HShift() && !kb.HCtrl() && !tip0.isEmpty()) tooltip.add(new StringTextComponent(tip0)); //if neither pressed, show tip0 (if not empty)
	if(kb.HCtrl() && !tip2.isEmpty()) tooltip.add(new StringTextComponent(tip2)); //if ctrl, show tip2 (if not empty), do first
	if(kb.HShift() && !tip1.isEmpty()) tooltip.add(new StringTextComponent(tip1)); //if shift, show tip1 (if not empty)
}

 

Easier to read, maybe... but it's checking for KB inputs each game tick for that item... which isn't something I believe is helpful.  
--  This is likely a point of ...  personal thought, I'd rather not have 4 kb checks a tick per item hovered over.  (2 each for Shift & Cntrl) 
~~ I prefer to minimize keyboard checking, though I will keep that in mind.

also,  I'm more the fan of null checks, but ... that's a preference thing honestly.

 

1 hour ago, Draco18s said:

You've fixed it, but now you have two checks for null where you could just combine the two blocks and do it once. No sense checking to see if there's a valid object to assign with and then separately checking to see if you assigned anything to it...

The two variables are the same type. It's literally pointless. It can never fail in an unexpected way, and if it does, let the program crash, it's not your problem.

Because ..  This mod is made with intents of being with other mods, and I will fully admit I do not trust other mods and 'fake players',  I don't know what will happen & haven't gotten my mod to a stage where I can viably test it in a variety pack with matters I'm worried about.
-- what if a fake player is null, & a player entity, so it doesn't fail or cause MC issues, but will cause issues if it's used improperly.
~~~ I understand with vanilla, regular ol minecraft    It's overkill & one check would be enough, or exclusion from a fake player I made (if I made one, which I am not the biggest fans of myself)

"It would never fail in an unexpected way"  ....   Minecraft literally can crash because an event built for it will trigger  on entities that can't be cast into the event for what it was intended for.  A tiny bit of caution wouldn't go amis.
-- also, I left room to a dynamic change to the logic.  I know it's not final, and it's verbose at worst.

1 hour ago, Draco18s said:

No, why is it's Type Object and not Item?

eh, first thing I thought of if I where to be honest...  use null object that can become the item compare to a specific thing.
_-  as well, object work straight out of the gate so I didn't bother to look for better.

Changed it, as I'd rather keep logic sane enough X]
--  still learning 'java' and dealing with mc moding,  I honestly am relying on feed back from the IDE ALOT, ontop of research of things.

-------------------------------

Oh, ya, going to x.x new post about ....  stairs  I need to figure out the 'other method' for them  I can't seem to get it right.
-atm I am using the Deprecated method.... but I barely understand it. [it's in the code, I'm working on altcolor sand textures.... then I'm going to give them the models in game & then the stairs.

Posted (edited)
1 hour ago, DePhoegon said:

Easier to read, maybe... but it's checking for KB inputs each game tick for that item... which isn't something I believe is helpful.  

Your original code was doing that anyway. And again, premature optimization.

1 hour ago, DePhoegon said:

I'd rather not have 4 kb checks a tick per item hovered over.  (2 each for Shift & Cntrl) 

So instead of 2 checks per key, you have...6 for shift and 8 for control. The two methods do the same thing, except that mine uses a minimum number of checks to arrive at the desired result.

1 hour ago, DePhoegon said:

Because ..  This mod is made with intents of being with other mods, and I will fully admit I do not trust other mods and 'fake players',  I don't know what will happen & haven't gotten my mod to a stage where I can viably test it in a variety pack with matters I'm worried about.

If the object isn't null and conforms to a given type, then you can assign it to a local variable of that type and operate on it as if it was that type.

If any of that is not true, crash and die, because it wasn't valid Java code or a cosmic ray corrupted RAM. You don't design your code to fail safely in this situation because the situation is not safe. FakePlayers are still Players.

1 hour ago, DePhoegon said:

eh, first thing I thought of if I where to be honest...  use null object that can become the item compare to a specific thing.
_-  as well, object work straight out of the gate so I didn't bother to look for better.

Item is still a nullable Type...There's almost no reason to use ever Object as a declared type. The only time it really gets used is when the actual Type doesn't matter and could be anything. You aren't dealing with an anything, you're dealing with ItemStacks and Items.

1 hour ago, DePhoegon said:

"It would never fail in an unexpected way"  ....   Minecraft literally can crash because an event built for it will trigger  on entities that can't be cast into the event for what it was intended for.  A tiny bit of caution wouldn't go amis.

(1) Vanilla doesn't use events, it's a Forge syste.
(2) Forge code won't crash in that case, the modder that Did a Bad causes the crash. Forge does proper type checking and enforces it.
(3) It is not your job to save the game from a modder that Did a Bad.

Quote

 

Don’t catch fatal exceptions; nothing you can do about them anyway, and trying to generally makes it worse.

Fix your code so that it never triggers a boneheaded exception – an “index out of range” exception should never happen in production code.

Always handle exceptions that indicate unexpected exogenous conditions; generally it is not worthwhile or practical to anticipate every possible failure. Just try the operation and be prepared to handle the exception.

 

https://ericlippert.com/2008/09/10/vexing-exceptions/

Other modders doing bad things do not count as exogenous conditions, exogenous is your code checks to see if a file exists, then before it can read it, another program or system deletes it (disc ejected from drive, internet disconnects, system goes into read-only mode). Other modders doing bad things is fatal.

(And Java lacks the non-vexing try-versions of functions the article talks about (eg. int.Parse vs. int.TryToParse), so I removed that point).

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

Just going to reply in order, snip bits..   snip bits drive me bitty.

1. perhaps a bit of premature optimization...  though truth be told, I am done with that 'tooltip section' so I'd not want to leave it loose.

2. perhaps I don't understand the deeper methods of the keyboard hooks, and I assumed things that weren't true.. 
-- worth looking at, but honestly  alot more so for understanding and curiosity sake.

3.  You're just being nit picky and bitchy on the 'Item' object.    I swapped it as soon as you brought it up (and tested it, I've just not had it commited yet, still on altcolor sand texture work atm)
-  to be frank i just didn't know about it or if I did wasn't on my mind.

4.  I wasn't aware it was a 'forge' only thing,  
- Eh...   It wasn't a 'crash', so much as a sudden 'controlled' shutdown of the game.  ( I went to fix that as soon as I found out what did it)
- Not my job to save other moders (in bad code), but it is mine to not leave an odd vulnerability up in the air.

5. Point taken on 'exogenous'  code, It's something I have to work on & is why I'm doing what I'm doing... even if it doesn't seem like it is.

 

I've actually done what I can to ensure the code I write is stable and functional X.x  though  That new method for blockstates for 'stairs'   is still beating me around I need to look into it after I get this texture stuff done. 

 

also.. pretty stairs X}  (heavy decoration theme with mine)  https://1drv.ms/u/s!AhaK1Af-119XnsFu2cYGq670HI4APQ?e=MPQ4If  (Left side is 'sand' & 'red sand' stairs,  and the right is the minecraft smooth sandstone stairs for comparison)   I'm a huge fan of how it looks and underwater build ideas for it.

---------

Also I KNOW,   there are unfinished textures..  that's what I'm working on atm.. X} 

Edited by DePhoegon
Cutting off the Purple/Black box coments.
Posted
29 minutes ago, DePhoegon said:

2. perhaps I don't understand the deeper methods of the keyboard hooks, and I assumed things that weren't true.. 
-- worth looking at, but honestly  alot more so for understanding and curiosity sake.

Uh, dude. This has nothing to do with the deeper methods.

Your code had 8 instances of kb.HCtrl and 6 of kb.HShift.image.png.ec5abdb535699be336791fecfa47397b.png

image.png.4f861d7baebff0b6e1c470e025176312.png

There's only 3 scenarios your code needs to consider:

  • No keys pressed
  • Control pressed
  • Shift pressed

Checking control before shift insures that tip2 appears above tip1 and each scenario has two states that have no bearing on the other scenarios: whether or not the given string is present. If the string is empty, draw nothing, it doesn't matter if tip0 is empty and the user is pressing shift, we aren't displaying tip0.

That's literally it.

The only other check you might consider is if you added no tips (i.e. even though shift is pressed, tip1 is empty) then display tip0. But that's just a matter of removing the if(no keys) and replacing it with int oriignalSize = tooltip.size; and then a new last line of if(tooltip.size == oriignalSize && !tip0.isEmpty()) tooltip.add(tip0).

29 minutes ago, DePhoegon said:

- Eh...   It wasn't a 'crash', so much as a sudden 'controlled' shutdown of the game.  ( I went to fix that as soon as I found out what did it)

That is a crash.

Just because Minecraft did some processing before it actually exited doesn't matter. The game still encountered a fatal error and terminated. It was just writing log files, closing streams, and shutting down network channels.

30 minutes ago, DePhoegon said:

5. Point taken on 'exogenous'  code, It's something I have to work on & is why I'm doing what I'm doing... even if it doesn't seem like it is.

No. Exogenous exceptions are external to the program (in this case, Minecraft + all mods).

Quote

Exogenous exceptions are the result of untidy external realities impinging upon your beautiful, crisp program logic.

Any issues that crop up as the result of your code and another mod somehow not playing nice is almost certainly Boneheaded. Who's at fault depends on who made an assumption that wasn't true. If the method you are calling says it returns an object of a given type, you can be assured that it is of that type and has the methods it says it has.

If it doesn't, then someone else made a boneheaded decision to violate the Type contract. Do not assume that someone else might do this, because it isn't your problem to clean up after their mistake if they do. It's a bug, they need to fix it.

If your IDE and compiler aren't telling you to surround code with a try-catch, then do not surround code with a try-catch. Do not assume that variables mysteriously become null between one line and another. Use the most specific type you can when you can.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.