Jump to content

[1.7.2] How to place a torch or door on a generated structure

Recommended Posts

Hi.  I think I just ran into a very similar problem -- I was trying to place vines as part of a structure generation (instead of being placed as an item or during world generation).  I'm not sure if your problem has the same cause, but here is how I solved my problem.


Basically, there are block types (such as torches, doors, vines, etc.) that have a direction -- they get placed such that they seem to be attached to other blocks around them.  I believe in most of these cases (at least it was true with vines) that you need to assign metadata to the block to indicate the direction.  If you don't assign metadata then it will default to 0 and won't render (I'm not sure if it is actually placed, but certainly wasn't visible).


There are actually two different setBlock() methods.  One only takes the position and another takes metadata as well.  So for me the solution was to use the right method, and furthermore assign the right metadata.  Here is my code for creating vines that surround a pillar.  Basically it checks in each direction to ensure the space is free, and then places the vines but does it with different metadata depending on which side I want it to display attached to.

   	        // add vines all around
    	    if(worldObj.isAirBlock(xCoord+1, yCoord , zCoord))
    	        worldObj.setBlock(xCoord+1, yCoord, zCoord, MagicBeans.blockMagicBeansVine, 2, 2);	    	        
    	    if(worldObj.isAirBlock(xCoord-1, yCoord , zCoord))
    	        worldObj.setBlock(xCoord-1, yCoord, zCoord, MagicBeans.blockMagicBeansVine, 8, 2);	    	        
    	    if(worldObj.isAirBlock(xCoord, yCoord , zCoord+1))
    	        worldObj.setBlock(xCoord, yCoord, zCoord+1, MagicBeans.blockMagicBeansVine, 4, 2);	    	        
    	    if(worldObj.isAirBlock(xCoord, yCoord , zCoord-1))
    	        worldObj.setBlock(xCoord, yCoord, zCoord-1, MagicBeans.blockMagicBeansVine, 1, 2);	


So I'm wondering if you are using the wrong setBlock() method, or maybe you're using right method but setting wrong metadata.


If that is not your problem, then I suggest you look at the code for village generation and see how they place the doors in the buildings that are generated.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites



I faced this problem before, and it has two facets: the first, jabelar already explained, the other is that you must make sure that there is a block to which the torch or door can attach, or it will 'break' and fall as an item.


In my case, I solved it by generating the structure in two steps, one to place all regular 'solid' blocks, and a second pass to place things like torches, paintings, and other things that might rely on the structure already being in place. You could think of it as 'building' and 'decorating' ;)




Link to comment
Share on other sites

Yeah, really good point CoolAlias.  My code example above was called after I made the pillar that I was "decorating", so yes it is important to do these in the right order.


Furthermore, you should know that the setBlock() methods do a LOT of checking of conditions before allowing placing.  One of them is whether there is something to attach to, there is also checking if whatever is there to attach to is considered a valid thing to place on, the block below is checked (I think) to confirm you can place on, and so forth.  Because of all this, you need to make sure any custom blocks you create will pass all these checks.  For example, in my case I'm attaching the vines to a custom pillar so I had to make sure that the canPlaceBlockOnSide() method in the custom vine class returned true for that pillar block.  If you're making custom blocks in your structure you may need to clear out some of those such issues as well.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I'll add one more thing to the discussion.  It doesn't matter for torches and doors, but some blocks like pistons decide after they are set orientation, so even if you use those methods with the right metadata, it will overwrite it and always point the same direction since no player is involved as the object sees it.


To  fix this, create a delay block action list.  Basically setup a list (of block object actions - anotehr class) that a tick call activates once per tick.  Put in this list directions to set the metadata 1 to 2 seconds later.  1 usually works, but found a couple where i needed 2.  Still don't understand why.  Them BAM, you have your piston the right way.



Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

For the pistons/torches/chests/furnaces/other metadata blocks -- to alleviate the problem that delpi is describing, you can also just re-set the meta after setting it the first time.




world.setBlock(x,y,z,block,meta,flag);//initial assignment, meta is often overriden by blocks' onPlaced methods

world.setBlockMetadataWithNotify(x, y, z, meta);//force-set the meta to your desired meta, this one should stick

world.markBlockForUpdate(x,y,z);//make sure clients will receive the new/updated metadata, generally optional during world-gen as the entire chunk will be sent when client goes in range



Another way that I found works well (and better performance) is to manipulate the data directly in the chunks.  This bypasses many of the world/block methods..so you have to be careful on what/where you do things, but will allow you to manually set the block / metadata / tile entity without worrying about the vanilla methods overriding them.  I actually do this during my structure generation stuff so that I can generate redstone contraptions with full state-data -- normally the wire/etc would get a neighbor update when placing the next block, and revert its power state / etc -- going through the chunk bypassed the vanilla 'update neighbor blocks on change' code, and allowed me to generate fully active redstone contraptions with the precise state they were scanned in as.


Link to comment
Share on other sites

Further edit:


Doors are probably the trickiest to get correct, because they come in two halves that must BOTH be set properly, AND be set using the right method.


Check out the static method of ItemDoor.placeDoorBlock -- should be able to feed it one of 4 values(for each closed door orientation, 0-3).  It will properly set both the top and bottom of the door.  From there you only need to figure out what orientation number is correct for the doors in your structure (+rotation if generating your structure with multiple rotations).

Link to comment
Share on other sites

To avoid further block updates like shadowmage4513 mentioned (e.g. for redstone), my solution was to use flag '2' when setting all my blocks, as this flag notifies the client without updating neighbors.


For doors, if I remember correctly, the top half has the same metadata value as the bottom half plus 8. The Minecraft wiki "Data Values" section will have more precise information on metadata values for all the blocks, so I would double-check there.

Link to comment
Share on other sites

I got it to work using the .placeDoorBlock method! I used metadata 3 and got it to work, with the pressure plates. Thanks everyone!




ItemDoor.placeDoorBlock(world, i + 5, j + 1, k + 10, 3, Blocks.iron_door);
ItemDoor.placeDoorBlock(world, i + 6, j + 1, k + 10, 3, Blocks.iron_door);



Link to comment
Share on other sites

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.

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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am working on a modpack. When I try to access my server, Minecraft suddenly stops responding for no apparent reason, but I tested the same modpack on my friend's PC and it functions flawlessly there. One thing I have noticed is that the message "[Render thread/WARN] [io.gi.ap.ap.Apoli/]: Received unknown attacker" appears in the log each time my game crashes. My frame rate is high, about 100, and I do not have any mods called Apoli. 9000 MB of the 16000 MB of RAM are allotted to me. Almost everything I could do has been done (updating drivers, removing some mods, lowering the graphic settings, testing singleplayer, etc.) I will leave the moderator list and the latest.log down here.   https://mclo.gs/pYqKP15 (Cannot upload due to file size on pastebin.) Mods: [✔] [1.18.2]-Medieval-Siege-Machines-v1.17 [✔] [1.18.2-forge]-Epic-Knights-8.2 [✔] AchievementOptimizer-1.18.2-1.0.2 [✔] AdvancementPlaques-1.18.2- [✔] alexsmobs-1.18.6 [✔] antiqueatlas-7.1.1-forge-mc1.18.2 [✔] Apotheosis-1.18.2-5.8.1 [✔] appleskin-forge-mc1.18.2-2.5.1 [✔] Aquaculture-1.18.2-2.3.12 [✔] aquamirae-5.api10 [✔] archbows-1.0.9-1.18.2 [✔] architectury-4.12.94-forge [✔] armorunder-mc1.18.2-3.0.1 [✔] astikorcarts-1.18.2-1.1.2 [✔] Atlas-Lib-1.18.2-1.1.8 [✔] BetterAdvancements-1.18.2- [✔] betteranimalsplus-1.18.2-11.0.10-forge [✔] betterbiomeblend-1.18.2-1.3.5-forge [✔] BetterCompatibilityChecker-1.1.21-build.48+mc1.18.2 [✔] betterfpsdist-1.18.2-1.5 [✔] BetterPingDisplay-1.18.2-1.1 [✔] blockui-1.18.2-0.0.71-ALPHA [✔] BloodAndMadness-Forge1.18.2-v2.1.4 [✔] blueprint-1.18.2-5.5.0 [✔] BOMD-Forge-1.18.2-1.0.6 [✔] Bonfires-1.18.2-1.2.18-2062213 [✔] Bookshelf-Forge-1.18.2-13.3.56 [✔] born_in_chaos_[Forge]1.18.2_1.17 [✔] BrassAmberBattleTowers-1.18.2-2.3.12 [✔] caelus-forge-1.18.1- [✔] callablehorses-1.18.2- [✔] cameraoverhaul-1.0-1.18.2 [✔] carrotslib-mc1.18.2-4.0 [✔] catalogue-1.6.2-1.18.2 [✔] champions-forge-1.18.2- [✔] citadel-1.11.3-1.18.2 [✔] cloth-config-6.5.116-forge [✔] ColdSweat-2.3-b04f [✔] collective-1.18.2-7.7 [✔] configured-2.0.1-1.18.2 [✔] connectedness-1.18.2-2.0.1a [✔] Controlling-forge-1.18.2-9.0+23 [✔] corpse-1.18.2-1.0.2 [✔] CosmeticArmorReworked-1.18.2-v2a [✔] create-1.18.2-0.5.1.f [✔] Croptopia-1.18.2-FORGE-2.1.0 [✔] ctov-2.9.4 [✔] CullLessLeaves-Reforged-1.18.2-1.0.5 [✔] curios-forge-1.18.2- [✔] DarkerSouls1.18.2Forgev1.3.1 [✔] Divine Weaponry v1.4 1.18.2 [✔] DoggyTalentsNext-1.18.2-1.18.18 [✔] domum_ornamentum-1.18.2-1.0.77-ALPHA-universal [✔] dragonmagicandrelics-1.18.2-2.1.38 [✔] dragonseeker-1.1.1-1.18.2 [✔] dungeons_enhanced-1.18.2-3.2.1 [✔] DungeonsArise-1.18.2-2.1.52-release [✔] dungeonsweaponry-1.12.2-1.18.2 [✔] EFMCompat 18.2.0 [✔] EnchantmentDescriptions-Forge-1.18.2-10.0.17 [✔] EnigmaticLegacy-2.25.0 [✔] Entity_Collision_FPS_Fix-forge-1.18.2-1.0.0 [✔] entity_model_features_forge_1.18.2-2.0.2 [✔] entity_texture_features_forge_1.18.2-6.0.1 [✔] entityculling-forge-1.6.1-mc1.18.2 [✔] epic_fight_battle_styles-1.0.2 [✔] EpicFight-18.5.24 [✔] falchionmoveset-18.5.0 [✔] FarmersDelight-1.18.2-1.2.3 [✔] Fastload-Reforged-mc1.18.2-3.4.0 [✔] ferritecore-4.2.2-forge [✔] finsandtails-1.18.2-1.1.1 [✔] fish_of_thieves-mc1.18.2-v1.1.1-forge [✔] Forge 1.18.2 Minecraft Middle Ages 0.0.4 [✔] francium-1.18.2-1.0.1 [✔] ftb-essentials-1802.2.2-build.83 [✔] ftb-library-forge-1802.3.11-build.177 [✔] geckolib-forge-1.18-3.0.57 [✔] getittogetherdrops-forge-1.18.2-1.3 [✔] Gobber2-Forge-1.18.2-2.6.37 [✔] goblintraders-1.8.0-1.18.2 [✔] goodall-1.0.2-forge [✔] gpumemleakfix-1.18.2-1.6 [✔] guardvillagers- [✔] healingcampfire-1.18.2-5.2 [✔] hexerei-0.2.2 [✔] horsecombatcontrols-1.18.2-1.0.1 [✔] iceandfire-2.1.13-1.18.2-beta-3 [✔] Iceberg-1.18.2-forge-1.0.49 [✔] ImmediatelyFastReforged-1.18.2-1.1.10 [✔] immersive_melodies-0.1.2+1.18.2-forge [✔] ironchest-1.18.2-13.2.11 [✔] ironfurnaces-1.18.2-3.3.3 [✔] irons_spellbooks-1.18.2- [✔] ItemBorders-1.18.1-1.1.5 [✔] ItShallNotTick-1.0.22-build.34 [✔] Jade-1.18.2-forge-5.3.2 [✔] JadeAddons-1.18.2-forge-2.5.0 [✔] jecalculation-forge-1.18.2-4.0.4 [✔] jeed-1.18.2-1.11 [✔] jei-1.18.2-forge- [✔] jepp-1.18-1.0.0 [✔] JustEnoughAdvancements-1.18.2-3.2.0 [✔] justenoughbreeding-forge-1.18.2-1.2.1 [✔] JustEnoughProfessions-1.18.2-1.3.0 [✔] JustEnoughResources-1.18.2- [✔] Kobolds-2.9.3-1.18.2-final [✔] kotlinforforge-3.12.0-all [✔] L_Enders Cataclysm-0.51-changed Them -1.18.2 [✔] lazydfu-1.0-1.18+ [✔] leaky-1.18.2-1.3 [✔] LegendaryTooltips-1.18.2-1.3.1 [✔] letmedespawn-1.18.x-1.19.x-forge-1.0.3 [✔] LibX-1.18.2-3.2.19 [✔] lightspeed-1.18.2-1.0.5 [✔] lodestone-1.18.2-1.4.2 [✔] loot_journal-1.1.0-1.18 [✔] lootr-forge-1.18.2- [✔] malum-1.18.2- [✔] medieval_paintings-1.18.2-7.0 [✔] memoryleakfix-forge-1.17+-1.1.2 [✔] MerchantMarkers-1.18.2-forge-1.3.1 [✔] minecolonies-1.18.2-1.1.148-BETA [✔] MmmMmmMmmMmm-1.18.2-1.5.2 [✔] mna- [✔] modernfix-forge-5.18.0+mc1.18.2 [✔] modonomicon-1.18.2-1.33.1 [✔] mowziesmobs-1.6.3 [✔] multi-piston-1.18.2-1.2.15-ALPHA [✔] mythicmounts-18.2-7.2-forge [✔] NefsFarmDecoExpGear+v0.3(1.18.2) [✔] nutritionalbalance-1.18.2-3.2.4 [✔] obscure_api-10 [✔] occultism-1.18.2-1.84.0 [✔] octolib-1.18.2-0.3 [✔] oculus-mc1.18.2-1.6.4 [✔] OfflineSkins-1.18.2-v2 [✔] Orcz_0.83_1.18.2 [AI FIXES] [✔] origins-classes-forge-1.1.6 [✔] origins-forge-1.18.2- [✔] Paraglider-1.18.2- [✔] Patchouli-1.18.2-71.1 [✔] physics-mod-pro-v153-forge-1.18.2 [✔] Placebo-1.18.2-6.6.7 [✔] player-animation-lib-forge-1.0.2+1.18 [✔] pluto-mc1.18.2-0.0.6 [✔] polymorph-forge-1.18.2-0.50 [✔] Prism-1.18.2-1.0.1 [✔] projectvibrantjourneys-1.18.2-4.1.1 [✔] puffish_attributes-0.5.0-1.18.2-forge [✔] puffish_skills-0.13.1-1.18.2-forge [✔] realmrpg_imps_and_demons_0.9.0_forge_1.18.2 [✔] recruits-1.18.2- [✔] reforgium-1.18.2-1.0.12a [✔] Reldas+Medieval+Armor+1.18.2(2.0) [✔] relics-1.18.2- [✔] reputation-1.18.2-1.0.0 [✔] RPG_style_more_weapons_4.9.6R [✔] Rrls-1.18.2-3.1.0-forge [✔] rubidium-0.5.6 [✔] rubidium-extra-0.4.18+mc1.18.2-build.86 [✔] saturn-mc1.18.2-0.1.5 [✔] savage_and_ravage-1.18.2-4.0.1 [✔] seaborgium-mc1.18.2-0.1.3b [✔] SereneSeasons-1.18.2- [✔] ShoulderSurfing-Forge-1.18.2-4.2.1 [✔] SimpleLogin-1.18.2-1.0.0 [✔] simplyswords-forge-1.40-1.18.2 [✔] SleepingOverhaul-2.0.2-Forge-1.18.2 [✔] smallships-forge-1.18.2-2.0.0-b1.3.1 [✔] SmartBrainLib-forge-1.18.2-1.9 [✔] smoothboot(reloaded)-mc1.18.2-0.0.4 [✔] sophisticatedbackpacks-1.18.2- [✔] sophisticatedcore-1.18.2- [✔] soul_like_armors_reworked_1.18.2_(v138) [✔] SpartanShields-1.18.2-3.0.1 [✔] SpartanWeaponry-1.18.2-3.0.5-all [✔] SpitItOut-1.18.2-1.0.1 [✔] starterkit-1.18.2-5.3 [✔] Structory-1.18.2-1.0.2 [✔] structure_gel-1.18.2-2.4.8 [✔] structurize-1.18.2-1.0.424-ALPHA [✔] swem-forge-1.18.2-1.4.6 [✔] takesapillage-1.0.3-1.18.2 [✔] TerraForged-1.18.2-0.3.1-alpha-2 [✔] TextruesRubidiumOptions-1.0.8-mc1.18.2 [✔] theimpossiblelibrary-1.18.2-0.3.1 [✔] torchmaster-18.2.1 [✔] Totemic-forge-1.18.2- [✔] tov-0.1(ALPHA) [✔] towns_and_towers_forge- [✔] TravelersTitles-1.18.2-Forge-2.1.1 [✔] unoriginal-datapack [✔] untamedwilds-1.18.2-2.4.3 [✔] upgrade_aquatic-1.18.2-4.0.0 [✔] valhelsia_core-forge-1.18.2-0.4.0 [✔] valhelsia_structures-1.18.2-0.1.1 [✔] Vampirism-1.18.2-1.8.8 [✔] WeaponsOfMiracles- [✔] Werewolves-1.18.2- [✔] workers-1.18.2-1.7.8 [✔] YouDied-1.18.1- [✔] YungsApi-1.18.2-Forge-2.2.9 [✔] YungsBetterMineshafts-1.18.2-Forge-2.2 [✔] YungsBetterStrongholds-1.18.2-Forge-2.1.1 [✔] zoomerzoom-1.4
    • Turn casual moments into unforgettable dates – choose the best casual dating site! Sexy Womans from your town
    • I am trying to make a Modpack for me and my friend and the buddycard expansion mod keeps crashing is there anything I can do, I'll copy and paste the crash message and the attack a link to the crash log below: Buddycards Expainsion (buddycardsexp) encountered an error during the common_setup event phase java.lang.NoSuchMethodError: 'void com.wildcard.buddycards.item.BuddycardBinderItem.<init>(com.wildcard.buddycards.registries.BuddycardsItems$BuddycardRequirement, net.minedcraft.world.item.Item$Properties, com.wildcard.buddycards.core.BuddycardSet)'   https://drive.google.com/file/d/1XlEYKVi2uUyS_UxRKByqCKlfnVswvHbb/view?usp=sharing
    • So, my friend and I are playing modpack on version 1.20.1. Sometimes, when a friend dies, he crashes from the server and cant rejoin anymore, so I have to load backup of the world. After loading the backup, everything goes well, but then sometimes it crashes again after death. Here is lof file: https://pastebin.com/KaZTmvhc The lines where the friend crashes start at line 2471 
    • The Minecraft launcher is now "preparing" the game but is taking forever. Any suggestions?
  • Topics

  • Create New...

Important Information

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