how do I make an item that can open trial vaults? [solved]

Started by personhuman on

Topic category: Help with Minecraft modding (Java Edition)

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how do I make an item that can open trial vaults? [solved]
Sat, 10/11/2025 - 17:23 (edited)

exactly what the title says. i'm trying to make an item that can open any kind of lock or door, including vaults and ominous vaults. i've managed to make the vault open consistently, but i can't get it to dispense items or prevent the player from reusing the vault. any ideas?

Edited by personhuman on Sat, 10/11/2025 - 17:23
Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is a bit big but it…
Fri, 10/10/2025 - 18:17

This is a bit big but it does work,

BlockPos blockPos = BlockPos.containing(x, y, z);
BlockState blockState = world.getBlockState(blockPos);
if(entity instanceof Player player) {
	if(blockState.getValue(VaultBlock.STATE) == VaultState.ACTIVE) {
		if(world instanceof ServerLevel serverLevel) {
			BlockEntity blockEntity = serverLevel.getBlockEntity(blockPos);
			if(blockEntity instanceof VaultBlockEntity vaultBlockEntity) {
				List<ItemStack> keys = List.of(Items.TRIAL_KEY.getDefaultInstance(), Items.OMINOUS_TRIAL_KEY.getDefaultInstance());
				for(ItemStack itemStack : keys) {
					VaultBlockEntity.Server.tryInsertKey(serverLevel,
							blockPos, blockState,
							vaultBlockEntity.getConfig(),
							vaultBlockEntity.getServerData(),
							vaultBlockEntity.getSharedData(),
							player, itemStack
					);
				}
			}
		}
	}
}
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
thanks! it works exactly…
Sat, 10/11/2025 - 17:13

thanks! it works exactly like a trial key! now i just have to make it so that it'll only run when you have the key in hand and the block is a vault, but i can do that myself. again, thanks!

👍

Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
actually, when i was working…
Sat, 10/11/2025 - 17:25

actually, when i was working on putting the code into the procedure for the key, i noticed that the game crashed because the block was replaced with air, and it seemed to work just fine without the block replacement, but idk, maybe it's there for a reason. just felt that i should've mentioned that, though. still works great nonetheless!