Jump to content

[1.8] Get Minecraft block by unlocalized name


LordMastodon

Recommended Posts

So, I'm trying to implement a customizable crafting recipe system (going pretty well) but I've hit one hitch. I've included this in the config system as string formatted like this: "<modid (would be minecraft for a vanilla item)>:<unlocalized name>" which means that the user has an easy way to configure crafting recipes in the event of a recipe conflict or the user simply wants to change it around. However, as of yet I've not found a way with which I can search the blockRegistry for a block using an unlocalized name. I imagine it wouldn't be that hard, and I've implemented a system for searching this way in my mod:

 

List<Item> itemList = new ArrayList<Item>();

public Item getItemByUnlocalizedName(String unlocalizedName) {
    for (int i = 0; i < itemList.size(); i++) {
        if (itemList.get(i).getUnlocalizedName().substring(5).equals(unlocalizedName) {
            return itemList.get(i);
        }
    }

    return "";
}

 

And I think that works pretty well. Any help would be greatly appreciated, thanks in advance!

Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*.

 

Also this. Check it out.

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

Link to comment
Share on other sites

Thank you very much. That has helped tremendously, but are you sure that applies to vanilla items as well? The class GameRegistry seems to have been registered by Forge, and unless Forge has included vanilla items in it, I'm not sure that would work. However, I'd also like to know if it can encompass items and blocks as well, because I wouldn't want it to only support items or only blocks.

Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*.

 

Also this. Check it out.

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

Link to comment
Share on other sites

Got it. Thank you very much, but I'd still like to know if there's a way in which I can include both

GameRegistry#findItem

and

GameRegistry#findBlock

.

 

Also, the string that users will have to use will be item id instead of unlocalized name... Those are different...

 

What's the difference? How do I switch over to that? There doesn't appear to be any

setItemId

in the Block or Item class...

Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*.

 

Also this. Check it out.

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

Link to comment
Share on other sites

Got it. Thank you very much, but I'd still like to know if there's a way in which I can include both

GameRegistry#findItem

and

GameRegistry#findBlock

.

 

Also, the string that users will have to use will be item id instead of unlocalized name... Those are different...

 

What's the difference? How do I switch over to that? There doesn't appear to be any

setItemId

in the Block or Item class...

1) findItem also gives you blocks, because those are items too (while in your inventory, aren't they items?)

2) Item id is modid + : + string that you register your item with GameRegistry.registerItem.

Link to comment
Share on other sites

So what's the point of adding modid to the findItem method if it already includes it?

 

You don't. Just pass the mod ID and item name as separate arguments.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

OK, thanks!

 

EDIT 1

 

Minecraft's unlocalized names are the same as its item names, right? I can't speak about any items from other mods, and I suppose users will have to use those at their own discretion, but Minecraft and my own mod are what I'm hoping to target here.

Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*.

 

Also this. Check it out.

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

Link to comment
Share on other sites

OK, thanks!

 

EDIT 1

 

Minecraft's unlocalized names are the same as its item names, right? I can't speak about any items from other mods, and I suppose users will have to use those at their own discretion, but Minecraft and my own mod are what I'm hoping to target here.

 

They're usually similar, but not always the same. The wiki does have a list of all vanilla block and item names here, though.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I suppose it doesn't really matter what the unlocalized name is if I make all of mine the same, and I can simply refer the user to the wiki entry. Thank you everyone!

Who are you? Why have you brought me here? And why are there so many PewDiePie fanboys surrounding meeeeeeeee....... *falls into pit and dies*.

 

Also this. Check it out.

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

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.

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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