Jump to content

[1.8] have different unlocalized names for different blockstates, yet same block


sigurd4

Recommended Posts

like with stone, graphite, andesite etc.

i found the code that does it in vanilla in net.minecraft.item.Item.registerItems(). it seems to be in the registration of the item of the block that you can choose to use a different unlocalized name based on itemstack, which again makes it possible to check for blockstate properties.

        registerItemBlock(Blocks.stone, (new ItemMultiTexture(Blocks.stone, Blocks.stone, new Function()
        {
            private static final String __OBFID = "CL_00002178";
            public String apply(ItemStack stack)
            {
                return BlockStone.EnumType.byMetadata(stack.getMetadata()).getUnlocalizedName();
            }
            public Object apply(Object p_apply_1_)
            {
                return this.apply((ItemStack)p_apply_1_);
            }
        })).setUnlocalizedName("stone"));

however, this is impossible to do this way since forge's block registration thing seemingly won't allow this (i've looked in net.minecraftforge.fml.common.registry.GameRegistry). i might just be bad at searching, but i seriously have no idea what to do. or is there a much simpler way that i've overlooked?

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

Link to comment
Share on other sites

If your block variants, you need to add each one to the ModelBakery using the unlocalized name by which you plan to retrieve it.

 

Then, make a custom ItemBlock to return the correct unlocalized names for each damage value, or set up your names to use a standardized format that can take advantage of the naming function from ItemMultiTexture, e.g. either using your Block's EnumType or as 'tile.your_block_base_unlocalized_name.specific_type'.

Link to comment
Share on other sites

I think the first thing to ask is whether you really want to control variants using block states at all, versus just creating different custom blocks for each type (they can all extend a common type to share most of their code). While block states aren't that hard, it means that you need to process them in many cases (for the models, for the drops, for any other difference in behavior).

 

I personally would suggest using block states mostly for things that can actually change during the game (i.e. an actual "state"). If it will always stay the same for that block during the game, I would suggest that it may be easier to manage them as separate extended classes. For example, if I were making wooden chairs I might make a BlockChair class and then extend it into BlockChairAcacia, BlockChairOak, etc. For those latter classes, you'd only have a little bit of code to write. Since an acacia chair never turns into an oak chair, I personally think it is more logical to do it this way, it saves metadata space for other needed block state information, and probably will lead to less bugs for beginning programmers.

 

But if you're confident in your understanding of block states and metadata you can certainly do it that way too. To further explain the general idea, you need to understand that what you're registering is an instance of the class. So for each instance you can set (either using methods in your class or making a constructor to apply them) the value of the block state. Then you can create all the various instances you want with different block state values, and then just use the GameRegistry.registerBlock() method to assign each unlocalized names.

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

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

    • Hello, im kind of a newbie on creating mods, and i been trying to make simples mods so far, Right now, i'm creating a mod which detect an specific type of mob and kill it if reach a certain number, by far the mod is detecting the mob and counting them but at the time it reach the limit number, it don't do anything. The Game don't tweak, don't crash, just i't don't run the method i call, which is kill().   public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { final var TotalCows = pLevel.getNearbyEntities(Cow.class, TargetingConditions.forNonCombat(), pPlayer, pPlayer.getBoundingBox().inflate(5)); if(pLevel.isClientSide){ if(pPlayer.getItemInHand(InteractionHand.MAIN_HAND).getItem() == this.asItem()){ if(!TotalCows.isEmpty()){ if(TotalCows.get(0).isAlive()){ TotalCows.get(0).kill(); } }else{ pPlayer.sendSystemMessage(Component.literal("No hay vacas")); } } } The sendSystemMessage is get triggered, and when i change the method .kill() by any other like send a message it got called, can i get some tips, and a clue of what i'm missing
    • UPD: I DID IT   @Override public void applyEffectTick(LivingEntity livingEntity, int pAmplifier) { Level level = livingEntity.level(); if (!level.isClientSide()) { Holder<DamageType> entropyHolder = level .registryAccess() .registryOrThrow(Registries.DAMAGE_TYPE) .getHolderOrThrow(GTDamageTypes.ENTROPY_KEY); livingEntity.hurt(new DamageSource(entropyHolder), 1); } super.applyEffectTick(livingEntity, pAmplifier); }  
    • So I came to this public class ModDamageTypes{ public static void bootstrap(BootstapContext<DamageType> context) { context.register(GTDamageTypes.ENTROPY_KEY, new DamageType(GrimTales.MOD_ID + "_entropy", 0.1f)); } } public class GTDamageTypes implements DamageTypes { public static final ResourceKey<DamageType> ENTROPY_KEY = register("entropy"); private static ResourceKey<DamageType> register(String name) { return ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(GrimTales.MOD_ID, name)); } } public class ModWorldGenProvider extends DatapackBuiltinEntriesProvider { public static final RegistrySetBuilder BUILDER = new RegistrySetBuilder() .add(Registries.DAMAGE_TYPE, ModDamageTypes::bootstrap); public ModWorldGenProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) { super(output, registries, BUILDER, Set.of(GrimTales.MOD_ID)); } But! I still have an issue that, I cannot just use Holder.direct, due to it will create error that "Required type:  Holder<DamageType>  Provided : Holder<ResourceKey<DamageType>>" And I still have no clue how to fix it
    • Yea, unless someone else sees this and has a solution in the next 4 or 5 hours, I’m just gonna reinstall the modpack. Thanks for trying to help me out.
    • Sadly, no it didn't work, although the window for minecraft startup stayed longer. do you have anymore recommendations?
  • Topics

×
×
  • Create New...

Important Information

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