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

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?

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?

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
					);
				}
			}
		}
	}
}