Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.15.2] Get block instance or it's id from registry name


Forix
 Share

Recommended Posts

ForgeRegistries.BLOCKS.get(...)

Might have the function name wrong, could be "getFromName" or similar. Should be easy to work out.

Items are in ForgeRegistries.ITEMS, etc.

 

You can also use @ObjectHolder annotations. See the docs.

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.

Link to comment
Share on other sites

3 hours ago, CAS_ual_TY said:

Blocks.COAL_BLOCK

Would probably be better for your example

Depends on what they're doing. But for the given code, yes, this is better.

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.

Link to comment
Share on other sites

4 minutes ago, Forix said:

I know i can do that but i wanted to read registries names who were written on a file

Why..?

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

1 hour ago, Novârch said:

Why..?

All sorts of data reasons. Recipes and loot tables deal with this sort of lookup too.

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.

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • im stupid it's (Tier, ResourceLocation, List, List) parameters: your Tier a ResourceLocation the name combined with your mod id a List of Tiers (the Vanilla) which should be lesser than your Tier a List of Tiers (the Vanilla) which should be better than your Tier example
    • I am doing this so players can't cheat. 
    • I have no idea whether this code would work, but it would go in your mob's renderer class. See one of mine here: https://github.com/GenElectrovise/MagiksMostEvile/blob/1.16.5/src/main/java/genelectrovise/magiksmostevile/entity/boss/kitty_the_kraken/KittyTheKrakenRenderer.java   I also have little idea of which method in which to put that code, though the parameters nearly match those of  protected void applyRotations(SquidEntity entityLiving, MatrixStack matrixStackIn, float ageInTicks, float rotationYaw, float partialTicks) ... so that might be a reasonable place to start? (I know the method name doesn't match - there may be another one which is a better match but I do not have an IDE right now). Unless someone with more knowledge can come along and enlighten us, you may need to solve this issue with trial-and-error and vanilla-code-browsing.
    • Hello everyone. I create my capability for stats and should save it after player death, but if i try to get my values i took 0! For example    @SubscribeEvent public void playerStatsEvent(TickEvent.PlayerTickEvent event) { // HERE I WILL GET WRONG STATS System.out.println(player.getCapability(StatCapability.CAPABILITY_STAT, null)); if(!player.world.isRemote()){ // HERE I WILL GET GOOD STATS System.out.println(player.getCapability(StatCapability.CAPABILITY_STAT, null)); } } Cappa and Death event iclude Interface public interface IStat extends Callable{ int getStr(); void setStr(int stat); void setStatsByAnotherStats(IStat stats); void increaseStr(int statAdd); void clearAll(); } Class stats public class Stat implements IStat{ private int str = 0; @Override public int getStr() { return str; } @Override public void setStr(int stat) { this.str = stat; } @Override public void setStatsByAnotherStats(IStat stats) { Stat stat = (Stat) stats; this.str = stat.str; } @Override public void increaseStr(int statAdd) { this.str += statAdd; } @Override public void clearAll() { this.str = 0; } @Override public String toString(){ return "STR ->" + str; } @Override public Object call() throws Exception { return this; } } Capa  public class StatCapability implements ICapabilitySerializable<NBTTagCompound> { @CapabilityInject(IStat.class) public static Capability<IStat> CAPABILITY_STAT; private IStat instance = CAPABILITY_STAT.getDefaultInstance(); @Override public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) { return capability == CAPABILITY_STAT; } @Nullable @Override @SuppressWarnings("unchecked") public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CAPABILITY_STAT) return (T) this.instance; return null; } @Override public NBTTagCompound serializeNBT() { return (NBTTagCompound) CAPABILITY_STAT.getStorage().writeNBT(CAPABILITY_STAT, this.instance, null); } @Override public void deserializeNBT(NBTTagCompound nbt) { CAPABILITY_STAT.getStorage().readNBT(CAPABILITY_STAT, this.instance, null, nbt); } Storage  public class StatStorage implements Capability.IStorage<IStat> { @Nullable @Override public NBTBase writeNBT(Capability<IStat> capability, IStat instance, EnumFacing side) { NBTTagCompound nbt = new NBTTagCompound(); nbt.setInteger("strength", instance.getStr()); return nbt; } @Override public void readNBT(Capability<IStat> capability, IStat instance, EnumFacing side, NBTBase nbt) { NBTTagCompound tag = (NBTTagCompound) nbt; instance.setStr(tag.getInteger("strength")); } } PlayerDeath event @SubscribeEvent public void playerClone(PlayerEvent.Clone e) { IStat newStat = e.getEntityPlayer().getCapability(StatCapability.CAPABILITY_STAT,null); IStat oldStat = e.getOriginal().getCapability(StatCapability.CAPABILITY_STAT,null); newStat.setStatsByAnotherStats(oldStat); } Attach private static final ResourceLocation STATS = new ResourceLocation(Reference.MODID, "stats"); @SubscribeEvent public void attachCapability(AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof EntityPlayer) event.addCapability(STATS, new StatCapability()); }  
    • Oh Thank you! Now that I think about it I remember it gave me an issue the last time I updated it.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.