Jump to content

Recommended Posts

Posted

Hello,

I checked the BlockWall class and made my own.

How would i check for other walls that have metadata?

For example i have made walls based on the minecraft clayblocks. so 16 colors.

 

I have this now:

@Override
public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4)
    {
	Block block = par1.getBlock(par2, par3, par4);
	if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall ||
	   block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || 
	   block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall ||
	   block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall ||
	   block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall ||
	   block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall ){
		return true;
	}
        return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true;
    }

This works exactly how it should, but i wonder how i check for a block with metadata!

I really have no clue how to do that.

I have tried TemBlocks.claywall but that doesn't work

Posted

what do you mean with update? update what?

 

I have also no idea how to use this: IBlockAccess#getBlockMetadata

I know getBlockMetadata, but ....

I'll try some stuff

 

Edit:

I understand you don't want us to present chewed code. I do not ask for that either.

But some vague words do not help me at all, i'm sorry.

I'm 32 years old and i like programming, but i'm not that good skilled.

I came to this forum desperately searching for help for things i really can't figure out!

I know how to look into the minecraft classes and make my own extending them etc etc.

I almost did everything by myself, except by following tutorials

I hope you understand this

 

thank you

Posted

I'm using 1.7.10 because i like to have my own modded Cauldron server.

Just because cauldron support both mods and plugins.

Because there aren't any good enough (my opinion) antigriefing mods for 1.8 and higher, i'm

forced to use GriefPrevention (plugin).

I have already looked into how to mod in 1.8. I have set up a workspace for that.

Now i'm being offtopic, so back to the topic:

 

I know this is a method :getBlockMetadata

I know it returns the meta when called.

I also know how to use it.

It returns an integer and that's my problem. I just don't know how the pieces fit together

 

block==TemBlocks.claywalls

for example an itemstack is much easier then you would do this:

block == new ItemStack(TemBlocks.claywalls,1,0)

But since i can't use itemstacks(ofc not) i can't check specific for that block with metadata 0 (in this example it's 0)

Posted
  On 4/9/2016 at 3:46 PM, winnetrie said:

for example an itemstack is much easier then you would do this:

block == new ItemStack(TemBlocks.claywalls,1,0)

That wouldn't work. For one, I assume 'block' is an instance of Block, which you are trying to test equality against an ItemStack. Totally different things. For another, ItemStack equality does not compare will with the '==' operator - that actually checks identity (Google it).

 

If you want to test equality of a block + metadata, that is exactly what you do:

// let's assume 'World world', 'Block block', int 'x', 'y', and 'z' are given as method parameters
int meta = world.getBlockMetadata(x, y, z);
if (block == TemBlocks.claywalls && meta == 0) {
  // there you go
}

Posted

Well first of all, what i said about that ItemStack stuff was just an example. I know you can't use that in there.

I thought i made that clear. Sorry but my english isn't that good, wich results is bad explanations sometimes.

 

ok so second i tried this already before and it doesn't work:

@Override
public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4)
    {
	Block block = par1.getBlock(par2, par3, par4);
	int meta = par1.getBlockMetadata(par2, par3, par4);
	//int meta = par1.getBlockMetadata(par2, par3, par4);
	if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall ||
	   block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || 
	   block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall ||
	   block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall ||
	   block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall ||
	   block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall 
	   ){
		return true;
	}
	if ((block==TemBlocks.claywalls && meta ==0) || (block==TemBlocks.claywalls && meta ==1) || (block==TemBlocks.claywalls && meta ==2) ||
		(block==TemBlocks.claywalls && meta ==3) || (block==TemBlocks.claywalls && meta ==4) || (block==TemBlocks.claywalls && meta ==5)){
			return true;
		}


        return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true;
    }

I haven't provided a World parameter because i'm overriding the method. It doesn't ask me for a world. So i used the first parameter.

For me it seems like it doesn't do anything.

This code was what i came up by myself, but since it didn't worked i came asking help here

Posted

IBlockAccess is roughly equivalent to a World object.

 

Instead of that mess of conditions, you could greatly simplify it:

if (block instanceof BlockWall) {
   return true; // this should cover almost that entire wall of text
}

// this one:
if ((block==TemBlocks.claywalls && meta ==0) || (block==TemBlocks.claywalls && meta ==1) || (block==TemBlocks.claywalls && meta ==2) ||
		(block==TemBlocks.claywalls && meta ==3) || (block==TemBlocks.claywalls && meta ==4) || (block==TemBlocks.claywalls && meta ==5)){
			return true;
		}

// can be changed to:
if (block==TemBlocks.claywalls && meta < 6) {
  return true;
}
// you'll want to check that one before the instanceof BlockWall check, however, or meta will be ignored

// and this part:
block != this
// do you not want your wall blocks to be able to connect to themselves? Seems weird, but okay

If it's not working as you expect, try something simpler at first: always return true. Does your block connect to everything? Good, at least you know that part is working, and now you can start introducing some logic into it one piece at a time.

 

If it didn't work, then you can rule out your #canConnectWallTo implementation as the problem and begin looking elsewhere for issues.

Posted

Using "instanceof" means that your walls will connect to any other mod's walls that extend BlockWall. That would mean that yours would connect to mine (see Uncle Jeff's Anystone Walls at CurseForge), and mine would connect to yours.

 

Also: Don't forget gates (using the same "instanceof" so you connect to my iron gate etc).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
  On 4/9/2016 at 4:31 PM, jeffryfisher said:

Using "instanceof" means that your walls will connect to any other mod's walls that extend BlockWall. That would mean that yours would connect to mine (see Uncle Jeff's Anystone Walls at CurseForge), and mine would connect to yours.

 

Also: Don't forget gates (using the same "instanceof" so you connect to my iron gate etc).

'instanceof BlockWall' means that yes, but not 'instanceof' - he can use 'instanceof CustomBlockWall' or whatever his Block class is and restrict the connections to his custom wall blocks instead of allowing all, if that's what he wants, but I assumed he would want them to connect to other walls as well (the logical thing to allow in most cases).

Posted

Ok i found the problem....

For some reason i made my metawalls having each a different id, so i remade my CustomWallsColored.class so it has metadata. Really i facepalmed when i figured that out lol.

 

So now it works perfectly and it looks like this:

@Override
public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4)
    {

	Block block = par1.getBlock(par2, par3, par4);
	int meta = par1.getBlockMetadata(par2, par3, par4);
	//int meta = par1.getBlockMetadata(par2, par3, par4);
	if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall ||
	   block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || 
	   block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall ||
	   block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall ||
	   block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall ||
	   block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall){
		return true;
	}
	for(int i=0; i<16; i++){
		if ((block==TemBlocks.claywalls && meta ==i) || (block==TemBlocks.claybrickwalls && meta ==i) || (block==TemBlocks.brickswalls && meta ==i) ){
				return true;
			}
		}
        return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true;
    }

I also made a for loop to shorten the code.

 

I will take a look at that "instanceof", it would be much better if it can connect to any wall of any mod.

Posted

Your for loop is kinda... pointless.

for(int i=0; i<16; i++){
if ((block==TemBlocks.claywalls && meta ==i) || (block==TemBlocks.claybrickwalls && meta ==i) || (block==TemBlocks.brickswalls && meta ==i) ){
	return true;
}
}

If you think about what that is doing, i starts at 0 and goes all the way to 15, so every value less than 16, which is every possible metadata value for a Block... why even check?

 

And if you DO want to check meta for some reason, why do it in a for loop when you can just check it like this:

if (meta < 16 && (block==TemBlocks.claywalls || block==TemBlocks.claybrickwalls || block==TemBlocks.brickswalls)) {
   // the block is one of the ones you want and the meta is from 0 to 15...
   // same exact logic as your for loop, but far more efficient and succinct
}

Posted

I don't think my for loop is pointless, because it cycles trough all the metadata.

That's the point of it. If i don't make that check the walls do not connect to eachother. I tried that before!

Ofc your stuff works also.

Mine code checks every metadata and your checks is it's smaller than 16.

I agree to the "same exact logic" but not the far more efficient. Perhaps yours is a bit more efficient.

I learned to use for loops in c++ because they are very powerfull and fast. So why would that be different in java?

Besides that i like to use for loops and my code works.

Even more important is knowing what the code does and so i do!

 

Anyway i thank you for posting your variant

Posted
  On 4/9/2016 at 10:34 PM, winnetrie said:

I don't think my for loop is pointless, because it cycles trough all the metadata.

 

And then doesn't give a shit what the actual value of the metadata was, because it performed the same check on all of them:

meta == i

It doesn't matter what value

meta

was from the world (because it can only be 0 to 15), at some point during that loop that check will be true.

 

Following that, because you are doing

return true

in the block-check, as soon as it determines that yes, one of these blocks is what we're looking for it never even fucking checks your loop.

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

To be fair, the blocks in the for loop are not included in the preceding if statement, but that does not mean the for loop has a point.

 

Just think about it step by step:

for loop breaks down to this, basically:
if (block correct and 0 == meta) return true;
if (block correct and 1 == meta) return true;
if (block correct and 2 == meta) return true;
// and on up to 15

So, if at any point the metadata value is the same as i, you return true. The metadata value can only be a value from 0 to 15, and you check ALL of those values, so by very nature of the code, at some point i has to equal the metadata value, making the metadata value and thus your for loop completely unnecessary.

 

It literally does nothing different than simply checking if (block == clayWall) for those 3 blocks.

Posted

Just use the elegant block instanceof BlockWall expression already so you won't need this discussion of loops and meta values. And don't forget what I said about gates. For that matter, you might want to think about fences too.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

I removed the for loop and changed it to this:

block==TemBlocks.claywalls || block==TemBlocks.claybrickwalls || block==TemBlocks.brickswalls

 

So apparently i do not need to check metadata.

I tried this before and it didn't worked, but that's because i created the walls wrong (they had no metadata at all, and now they do)

 

Thanks for those who helped me out, i really appreciate it.

 

@Draco18s : I think you "shit" and "fucks" to much. You can talk to me like a normal person. I would appreciate that.

I'm just a normal guy 32 years old who likes to learn something new. If you want to talk to me like a 12 year old wannebecoolboy, srry i don't have time for this.

If you wanne help me out like an adult or (if you aren't an adult) like a child with good manners, i will be very happy to hear from you.

thank you for understanding.

Posted
  On 4/10/2016 at 9:48 PM, winnetrie said:

@Draco18s : I think you "shit" and "fucks" to much. You can talk to me like a normal person. I would appreciate that.

I'm just a normal guy 32 years old who likes to learn something new. If you want to talk to me like a 12 year old wannebecoolboy, srry i don't have time for this.

 

And we don't have time to have you ignore what we tell you three times. :)

 

You know, like this bit:

 

  Quote

So apparently i do not need to check metadata.

 

That was pointed out to you at least twice, this is not a surprise revelation.

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

Your expression does not address gates. Shouldn't your walls connect to gates?

 

And what about other mods? Don't you want to connect to other extensions of BlockWall?

 

And what about torches? Can you put a torch on top of your wall?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

  • 3 weeks later...
Posted
  On 4/11/2016 at 7:24 PM, jeffryfisher said:

Your expression does not address gates. Shouldn't your walls connect to gates?

 

And what about other mods? Don't you want to connect to other extensions of BlockWall?

 

And what about torches? Can you put a torch on top of your wall?

Srry, i didn't saw your post untill now.

Even when it's fixed now, i can still post what i have.

You'll never know if someone could find his answers here.

So here it is:

 

  Reveal hidden contents

 

 

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

    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • I removed yetanotherchance booster and now it says Invalid player identity
    • Cracked Launchers are not supported
    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
  • Topics

×
×
  • Create New...

Important Information

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