Jump to content

Random Entity Id


jcranky

Recommended Posts

The ID value is yours, it will never clash with another mod's.  Just make it a fixed value, there's no reason for it to be random.

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

Thanks guys. In my case a clash could happen because I'm creating some support classes that brings a couple of mobs "pre-configured". So if the modder creates a new mob, and use the same id, ka-boom. A random id also doesn't really solve the problem, only makes it less likely to happen. I'll think about something else.

just you wait! ;)

Link to comment
Share on other sites

To be clear, you set the ID when you use the EntityRegistry.registerModEntity() method. The third parameter is the ID. They are unique per mod. Most people simply increment the ID but as long as they are unique within your mod you can do what you want with the ID. The ID will be the same every time you run the game and will be the same for anyone who runs the game. Again you are the one setting it.

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

Link to comment
Share on other sites

@lex I understood that. The clash would be inside a single mod, because what I'm doing is supposed to be re-used from other mods - it is basically a library.

If your 'library' includes registering mobs for other mods then your 'library' is doing it wrong.

Anyways the numerical ID is used for networking, that is all. Mobs are stored as their string keys in the world so that part isnt a issue. This is purely networking.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

The ID will be the same every time you run the game and will be the same for anyone who runs the game.

 

It will not be the same for every game run, if it is random. On the second run, the game would load the mod and call registerModEntity again with a new value.

just you wait! ;)

Link to comment
Share on other sites

If your 'library' includes registering mobs for other mods then your 'library' is doing it wrong.

Anyways the numerical ID is used for networking, that is all. Mobs are stored as their string keys in the world so that part isnt a issue. This is purely networking.

 

Why? Part of the point would be abstracting away the actual choosing of an ID. Is it that bad? Also, in the network case, if I use a random number, then each player would have a different id for the same mob, I guess this would be bad?

 

thanks !

just you wait! ;)

Link to comment
Share on other sites

If your 'library' includes registering mobs for other mods then your 'library' is doing it wrong.

Anyways the numerical ID is used for networking, that is all. Mobs are stored as their string keys in the world so that part isnt a issue. This is purely networking.

 

Why? Part of the point would be abstracting away the actual choosing of an ID. Is it that bad? Also, in the network case, if I use a random number, then each player would have a different id for the same mob, I guess this would be bad?

 

thanks !

Yes, using unsynced ids would cause the whole system to not work at all.

The entire point is that the ids are the same for everyone.

What you're doing is stupid, stop doing it..

Please understand a system before you try and make it 'better'

As it sits you have no business writing this type of 'api' that's Forge's job and its doing it just fine.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Yes, using unsynced ids would cause the whole system to not work at all.

The entire point is that the ids are the same for everyone.

 

This is exactly what I wanted to understand, thanks.

 

What you're doing is stupid, stop doing it..

 

Perhaps it is, but you don't really know it ;)

 

Please understand a system before you try and make it 'better'

As it sits you have no business writing this type of 'api' that's Forge's job and its doing it just fine.

 

The point is not making anything 'better'. I'm basically playing around with some ideas, and I obviously need to understand stuff better before doing anything with it, isn't this the point of asking questions in the first place?

just you wait! ;)

Link to comment
Share on other sites

The ID will be the same every time you run the game and will be the same for anyone who runs the game.

 

It will not be the same for every game run, if it is random. On the second run, the game would load the mod and call registerModEntity again with a new value.

 

It is only random if you make it random purposefully. And it would be a bit of work to make the IDs both random and unique. Pretty much every mod I've ever seen or written, I simply start at 0 and increment by 1 for each mod ID as I register the mod. I can't imagine any reason you would randomize it.

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

Link to comment
Share on other sites

It is only random if you make it random purposefully. And it would be a bit of work to make the IDs both random and unique. Pretty much every mod I've ever seen or written, I simply start at 0 and increment by 1 for each mod ID as I register the mod. I can't imagine any reason you would randomize it.

 

Yes, I think I was over-complicating this matter, thanks :)

just you wait! ;)

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 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;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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