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
  On 4/19/2021 at 8:19 PM, 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.

Expand  

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
  On 4/20/2021 at 1:43 PM, Draco18s said:

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

Expand  

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
  On 4/20/2021 at 5:48 PM, 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)

Expand  

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
  On 4/20/2021 at 6:49 PM, Draco18s said:

Look at the Blocks class.

Expand  

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
  On 4/21/2021 at 2:14 PM, Draco18s said:

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

What fields and properties does it have?

Expand  

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
  On 4/21/2021 at 3:25 PM, 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.

Expand  

Ignore that stuff. It's not relevant.

  On 4/21/2021 at 3:25 PM, DePhoegon said:

public Objects

Expand  

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
  On 4/21/2021 at 9:00 PM, Draco18s said:

..

This. These are accessible from your code.

Expand  

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
  On 4/22/2021 at 1:45 PM, Draco18s said:
//your code
Block b = Blocks.SAND;

:|

Expand  

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
  On 4/22/2021 at 8:52 PM, 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.

Expand  

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)
  On 4/22/2021 at 8:42 PM, 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.

Expand  

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
  On 4/23/2021 at 7:56 AM, diesieben07 said:

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

Expand  

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
  On 4/23/2021 at 12:57 PM, 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.

Expand  

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
  On 4/23/2021 at 12:12 AM, 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)

Expand  

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

  On 4/23/2021 at 12:12 AM, DePhoegon said:

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

Expand  

This is why you use instanceof.

  On 4/23/2021 at 12:12 AM, 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)

Expand  

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...

  On 4/23/2021 at 12:12 AM, 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.

Expand  

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.

  On 4/23/2021 at 12:12 AM, 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.

Expand  

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)
}

 

  On 4/23/2021 at 10:46 AM, DePhoegon said:

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

Expand  

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
  On 4/23/2021 at 3:09 PM, 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.

Expand  

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.

 

  On 4/23/2021 at 3:09 PM, 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)
}

 

Expand  

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.

 

  On 4/23/2021 at 3:09 PM, 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.

Expand  

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.

  On 4/23/2021 at 3:09 PM, Draco18s said:

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

Expand  

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)
  On 4/23/2021 at 5:15 PM, 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.  

Expand  

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

  On 4/23/2021 at 5:15 PM, DePhoegon said:

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

Expand  

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.

  On 4/23/2021 at 5:15 PM, 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.

Expand  

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.

  On 4/23/2021 at 5:15 PM, 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.

Expand  

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.

  On 4/23/2021 at 5:15 PM, 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.

Expand  

(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.

 

Expand  

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
  On 4/23/2021 at 7:28 PM, 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.

Expand  

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).

  On 4/23/2021 at 7:28 PM, 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)

Expand  

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.

  On 4/23/2021 at 7:28 PM, 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.

Expand  

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.

Expand  

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

×
×
  • Create New...

Important Information

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