Posted August 9, 20196 yr Hello, I am trying to prevent a player from opening the trade screen with a villager if they have previously removed the villager's nose with a pair of shears. The trade screen should never open, and the player should be told "Leave me alone! I miss my nose". I have stored whether the villager has a nose by attaching a capability to all instances of VillagerEntity. But I am having difficulty obtaining the VillagerEntity instance before I open the trade screen. I tried casting the IMerchant from the MerchantContainer to an AbstractVillagerEntity (which implements IMerchant) as well as VillagerEntity, but all I get are ClassCastExceptions. I must be overlooking something. This is what I have so far (throws ClassCastException): @SubscribeEvent public static void guiOpenEvent(GuiScreenEvent event){ if (event.getGui() instanceof MerchantScreen){ IMerchant merchant = ObfuscationReflectionHelper.getPrivateValue(MerchantContainer.class, ((MerchantScreen) event.getGui()).getContainer(), "merchant"); if (merchant instanceof VillagerEntity){ VillagerEntity villager = (VillagerEntity) merchant; INose noseCapability = villager.getCapability(NOSE_CAP).orElseThrow(() -> new RuntimeException("No inventory!")); if (!noseCapability.getHasNose()){ event.setCanceled(true); event.getGui().getMinecraft().player.sendChatMessage(String.valueOf(new TranslationTextComponent("translation.villagersnose.trade_refusal", (Object) null))); } } } } How can I determine which VillagerEntity instance the player is attempting to trade with? Edited August 9, 20196 yr by eafooe clarification
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.