Jump to content

sFXprt

Members
  • Posts

    68
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by sFXprt

  1. idk, PlayerTickEvent. Minecraft.getInstance().player returns client-side only player(LocalPlayer) I think(im unsure, hence ghost items) whether or not something is in your Inventory is client side but the logic to do other things is on server side
  2. I am on version 40.2.0 still no class def, ill try to update to the latest
  3. As the title states I am trying to subscribe to LivingChangeTargetEvent but it cant find the definition, I tried different annotations and that didnt work. My current annotation is @Mod.EventBusSubscriber(modid = Main.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) And this is the method I'm using @SubscribeEvent public static void onTarget(LivingChangeTargetEvent e){ LivingEntity entity = e.getEntityLiving(); if(entity.getPersistentData().contains(XprtData.GALAXUS_SLAVE)){ if(!entity.getLevel().isClientSide()){ ServerLevel lvl = (ServerLevel) entity.getLevel(); UUID id = entity.getPersistentData().getUUID(XprtData.GALAXUS_SLAVE_OWNER); if(lvl.getPlayerByUUID(id)!=null){ Player p = lvl.getPlayerByUUID(id); if(e.getNewTarget().equals(p) || e.getNewTarget().getId() == p.getId()){ e.setCanceled(true); } } } } } this is just a simple turn any entity to do ur bidding code and I remember in past projects using LivingChangeTargetEvent and it worked. Do I have to rebuild the entire project and run mappings updates or something?? By the way I am only using my mod and optifine(removing optifine doesnt change anything) and the debug.log just says what the title says.
  4. [SOLVED] - Yep I feel stupid, after looking over this post I saw I called the shop_menu on both classes like an idiot and I also called playerInv.player instead of just this.p on Knight class... I have two containers, one that is a Vault container for a player and one that is for my Knight entity. They both are designed to store player items in it and have the same code(with one alteration). Except if I put items in my Vault and try to open up my Knight entities container it completely removes my CompoundTag that holds all the itemstacks in the Vault container. The really weird thing is I am not accessing the Players persistent data at all in the Knight's container. And the item in the Knight's container will still stay even if I open up other Knight's container and my Vault container will not store of the knights containers items. Knight Container public class KnightInventoryMenu extends AbstractContainerMenu { private final Knight p; public KnightInventoryMenu(int pContainerId, Inventory playerInv){ this(pContainerId, playerInv, null, new ItemStackHandler(27)); } public KnightInventoryMenu(int pContainerId, Inventory playerInv,Knight k, ItemStackHandler itemStackHandler) { super(ContainerInit.SHOP_MENU.get(), pContainerId); this.p = k; final int slotSizePlus2 = 18, startX = 8, startY = 86, hotbarY = 144, inventoryY = 18; for (int row = 0; row < 3; row++) { for (int column = 0; column < 9; column++) { addSlot(new SlotItemHandler(itemStackHandler, row * 9 + column, startX + column * slotSizePlus2, inventoryY + row * slotSizePlus2)); } } for (int row = 0; row < 3; row++) { for (int column = 0; column < 9; column++) { addSlot(new Slot(playerInv, 9 + row * 9 + column, startX + column * slotSizePlus2, startY + row * slotSizePlus2)); } } for (int column = 0; column < 9; column++) { addSlot(new Slot(playerInv, column, startX + column * slotSizePlus2, hotbarY)); } if(!this.p.getPersistentData().contains("container.items")){ CompoundTag tag = new CompoundTag(); playerInv.player.getPersistentData().put("container.items", tag); } else { CompoundTag tag = this.p.getPersistentData().getCompound("container.items"); for(String key : tag.getAllKeys()){ int index = Integer.valueOf(key); this.getSlot(index).set(ItemStack.of(tag.getCompound(key))); } } } @Override public void broadcastChanges() { CompoundTag tag = new CompoundTag(); int i = 0; for(ItemStack item : this.getItems()){ if(i > 27) break; CompoundTag itemTag = new CompoundTag(); tag.put(String.valueOf(i), item.save(itemTag)); i++; } p.getPersistentData().put("container.items", tag); } @Override protected boolean moveItemStackTo(ItemStack pStack, int pStartIndex, int pEndIndex, boolean pReverseDirection) { return super.moveItemStackTo(pStack, pStartIndex, pEndIndex, pReverseDirection); } @Override public ItemStack quickMoveStack(Player player, int index) { var retStack = ItemStack.EMPTY; final Slot slot = getSlot(index); if (slot.hasItem()) { final ItemStack item = slot.getItem(); retStack = item.copy(); if (index < 27) { if (!moveItemStackTo(item, 27, this.slots.size(), true)) { return ItemStack.EMPTY; } } else if (!moveItemStackTo(item, 0, 27, false)){ return ItemStack.EMPTY; } if (item.isEmpty()) { slot.set(ItemStack.EMPTY); } else { slot.setChanged(); } } return retStack; } @Override public boolean stillValid(Player pPlayer) { return true; } } Player's Vault Container public class VaultMenu extends AbstractContainerMenu{ private final Player p; public VaultMenu(int pContainerId, Inventory playerInv){ this(pContainerId, playerInv, new ItemStackHandler(27)); } public VaultMenu(int pContainerId, Inventory playerInv, ItemStackHandler itemStackHandler) { super(ContainerInit.SHOP_MENU.get(), pContainerId); this.p = playerInv.player; final int slotSizePlus2 = 18, startX = 8, startY = 86, hotbarY = 144, inventoryY = 18; for (int row = 0; row < 3; row++) { for (int column = 0; column < 9; column++) { addSlot(new SlotItemHandler(itemStackHandler, row * 9 + column, startX + column * slotSizePlus2, inventoryY + row * slotSizePlus2)); } } for (int row = 0; row < 3; row++) { for (int column = 0; column < 9; column++) { addSlot(new Slot(playerInv, 9 + row * 9 + column, startX + column * slotSizePlus2, startY + row * slotSizePlus2)); } } for (int column = 0; column < 9; column++) { addSlot(new Slot(playerInv, column, startX + column * slotSizePlus2, hotbarY)); } if(!this.p.getPersistentData().contains("container.items")){ CompoundTag tag = new CompoundTag(); playerInv.player.getPersistentData().put("container.items", tag); } else { CompoundTag tag = this.p.getPersistentData().getCompound("container.items"); for(String key : tag.getAllKeys()){ int index = Integer.valueOf(key); this.getSlot(index).set(ItemStack.of(tag.getCompound(key))); } } } @Override public void broadcastChanges() { CompoundTag tag = new CompoundTag(); int i = 0; for(ItemStack item : this.getItems()){ if(i > 27) break; CompoundTag itemTag = new CompoundTag(); tag.put(String.valueOf(i), item.save(itemTag)); i++; } p.getPersistentData().put("container.items", tag); } @Override protected boolean moveItemStackTo(ItemStack pStack, int pStartIndex, int pEndIndex, boolean pReverseDirection) { return super.moveItemStackTo(pStack, pStartIndex, pEndIndex, pReverseDirection); } @Override public ItemStack quickMoveStack(Player player, int index) { var retStack = ItemStack.EMPTY; final Slot slot = getSlot(index); if (slot.hasItem()) { final ItemStack item = slot.getItem(); retStack = item.copy(); if (index < 27) { if (!moveItemStackTo(item, 27, this.slots.size(), true)) { return ItemStack.EMPTY; } } else if (!moveItemStackTo(item, 0, 27, false)){ return ItemStack.EMPTY; } if (item.isEmpty()) { slot.set(ItemStack.EMPTY); } else { slot.setChanged(); } } return retStack; } @Override public boolean stillValid(Player pPlayer) { return true; } public static MenuConstructor getServerContainer() { return (id, playerInv, player) -> new ShopMenu(id, playerInv, new ItemStackHandler(27)); } } Like I said the code is the exact same except in the Vault container I am modifying player persistent data to hold all the current items in the container from index 0-27, and on the Knights container its only affecting the Knight's persistent data. I am extremely confused, the only explanations I can come up with is somehow on the first instance of the knights container, it copys all the data to my players persistent data(but yet I am not calling it at all) or upon opening the knights container its deleting my persistent data tag that holds all the items.
  5. you should use EntityItemPickupEvent instead and cancel that, and set result if you want to process acheivements
  6. got it, fixed up and looking good. Thanks
  7. I have this screen which I like However since I am forced to use AbstractContainerScreen, it now looks like this Here is my Screen Class public ArcherGuardScreen(ArcherMenu pMenu, Inventory pPlayerInventory, Component pTitle) { super(pMenu, pPlayerInventory, pTitle); init(); } @Override protected void init() { this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 24, 70, 20, Component.nullToEmpty("Stay"), (p_96278_) -> { ModMessages.sendToServer(new ArcherUpdateC2S(1)); this.minecraft.setScreen(null); })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 60, 70, 20, Component.nullToEmpty("Move Freely"), (p_96278_) -> { ModMessages.sendToServer(new ArcherUpdateC2S(2)); this.minecraft.setScreen(null); })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 96 , 70, 20, Component.nullToEmpty("Ignore Nearby"), (p_96278_) -> { ModMessages.sendToServer(new ArcherUpdateC2S(3)); this.minecraft.setScreen(null); })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 132 , 70, 20, Component.nullToEmpty("Hire Guard"), (p_96278_) -> { ModMessages.sendToServer(new ArcherUpdateC2S(4)); this.minecraft.setScreen(null); })); super.init(); } @Override public boolean shouldCloseOnEsc() { return true; } @Override public boolean isPauseScreen() { return true; } @Override protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) { } @Override public void onClose() { this.minecraft.setScreen(null); } Please note my old Screen class was identical to this one except it did most of the backend there however since I am forced to use containers for an actual server I had to revamp the entire thing so only init() is changed everything else is the same as last class except the new method renderBg() which I am sure its causing this but I am so so bad and PoseStacks I have no idea how to set the text to where it needs to be, for now ill just mess with the Button widget values
  8. Im trying to pass an reference to my custom Knight entity to my screen so I can process things
  9. @warjort //Calling if(!pPlayer.getLevel().isClientSide()) NetworkHooks.openGui((ServerPlayer) pPlayer, new SimpleMenuProvider(this.getContainer(), Component.nullToEmpty("Container"))); //Register public static final RegistryObject<MenuType<GuardMenu>> GUARD_MENU = CONTAINERS.register("guard_menu", () -> new MenuType(GuardMenu::new));
  10. I have a working container that displays a screen, however if I try to interact with that screen it causes the error in the title, the container is called from entity#mobInteract using the networkhooks.opengui method. Like I mentioned the screen displays perfectly its just when I click a button it throws this exception SOLVED - I wasn't properly invoking FriendlyByteBuf in my packets on the screen class, infact I didnt call packets at all like an idiot knowing damn well its client side only. Log [02:14:52] [Render thread/FATAL]: Error executing task on Client java.lang.NullPointerException: Cannot invoke "net.minecraft.network.FriendlyByteBuf.m_130135_()" because "extraData" is null at TRANSFORMER/[email protected]/net.xprt.knights.Containers.Container.GuardMenu.<init>(GuardMenu.java:21) at TRANSFORMER/[email protected]/net.minecraftforge.network.IContainerFactory.m_39994_(IContainerFactory.java:20) at TRANSFORMER/[email protected]/net.minecraft.world.inventory.MenuType.m_39985_(MenuType.java:44) at TRANSFORMER/[email protected]/net.minecraft.client.gui.screens.MenuScreens$ScreenConstructor.m_96209_(MenuScreens.java:115) at TRANSFORMER/[email protected]/net.minecraft.client.gui.screens.MenuScreens.lambda$create$0(MenuScreens.java:43) at java.base/java.util.Optional.ifPresent(Optional.java:178) at TRANSFORMER/[email protected]/net.minecraft.client.gui.screens.MenuScreens.m_96201_(MenuScreens.java:43) at TRANSFORMER/[email protected]/net.minecraft.client.multiplayer.ClientPacketListener.m_5980_(ClientPacketListener.java:941) at TRANSFORMER/[email protected]/net.minecraft.network.protocol.game.ClientboundOpenScreenPacket.m_5797_(ClientboundOpenScreenPacket.java:37) at TRANSFORMER/[email protected]/net.minecraft.network.protocol.game.ClientboundOpenScreenPacket.m_5797_(ClientboundOpenScreenPacket.java:11) at TRANSFORMER/[email protected]/net.minecraft.network.protocol.PacketUtils.lambda$checkThreadAndEnqueue$0(PacketUtils.java:40) at TRANSFORMER/net.optifine/net.optifine.util.PacketRunnable.run(PacketRunnable.java:28) at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.m_6367_(BlockableEventLoop.java:198) at TRANSFORMER/[email protected]/net.minecraft.util.thread.ReentrantBlockableEventLoop.m_6367_(ReentrantBlockableEventLoop.java:23) at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.m_7245_(BlockableEventLoop.java:163) at TRANSFORMER/[email protected]/net.minecraft.util.thread.BlockableEventLoop.m_18699_(BlockableEventLoop.java:140) at TRANSFORMER/[email protected]/net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1015) at TRANSFORMER/[email protected]/net.minecraft.client.Minecraft.m_91374_(Minecraft.java:665) at TRANSFORMER/[email protected]/net.minecraft.client.main.Main.main(Main.java:205) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:31) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:106) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:77) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) at [email protected]/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) Container public class GuardMenu extends AbstractContainerMenu { private Knight knight; private Player p; public GuardMenu(int pContainerId, Inventory inv, Knight k, Player player) { this(pContainerId, inv); this.knight = k; this.p = player; } public GuardMenu(int pContainerId, Inventory inv) { super(ContainerInit.GUARD_MENU.get(), pContainerId); } public Player getPlayer(){ return this.p; } public Knight getKnight(){ return this.knight; } @Override public boolean stillValid(Player pPlayer) { return true; } } Screen public class GuardScreen extends AbstractContainerScreen<GuardMenu> { private Knight knight; private Player p; public GuardScreen(GuardMenu pMenu, Inventory pPlayerInventory, Component pTitle) { super(pMenu, pPlayerInventory, pTitle); this.knight = pMenu.getKnight(); this.p = pMenu.getPlayer(); this.init(); } @Override public void init() { this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 24, 70, 20, Component.nullToEmpty("Stay"), (p_96278_) -> { if(knight.getOwner() != null) { if (knight.getOwner().equals(p) || knight.getOwner().getId() == p.getId()) { knight.setStay(); knight.getPersistentData().putBoolean(XprtData.KNIGHT_STAYING, true); Utils.MessageEx(p, ChatFormatting.GREEN + "Knight will now stay", true); } else { Utils.MessageEx(p, ChatFormatting.RED + "You have not hired this Knight", true); } } else { Utils.MessageEx(p, ChatFormatting.RED + "Knight has not yet been hired", true); } })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 60, 70, 20, Component.nullToEmpty("Move Freely"), (p_96278_) -> { if(knight.getOwner() != null) { if (knight.getOwner().equals(p) || knight.getOwner().getId() == p.getId()) { knight.moveFreely(); knight.getPersistentData().putBoolean(XprtData.KNIGHT_STAYING, false); Utils.MessageEx(p, ChatFormatting.GREEN + "Knight will now move freely", true); } else { Utils.MessageEx(p, ChatFormatting.RED + "You have not hired this Knight", true); } } else { Utils.MessageEx(p, ChatFormatting.RED + "Knight has not yet been hired", true); } })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 96 , 70, 20, Component.nullToEmpty("Ignore Nearby"), (p_96278_) -> { if(knight.getOwner() != null) { if (knight.getOwner().equals(p) || knight.getOwner().getId() == p.getId()) { if(!knight.getPersistentData().contains(XprtData.KNIGHT_IGNORE_NEARBY) || !knight.getIgnoreNearby()){ knight.setIgnoreNearby(true); knight.getPersistentData().putBoolean(XprtData.KNIGHT_IGNORE_NEARBY, true); Utils.MessageEx(p, ChatFormatting.GREEN + "Knight will now ignore nearby enemies", true); } else{ if(knight.getPersistentData().getBoolean(XprtData.KNIGHT_IGNORE_NEARBY) || knight.getIgnoreNearby()){ knight.setIgnoreNearby(false); knight.getPersistentData().remove(XprtData.KNIGHT_IGNORE_NEARBY); Utils.MessageEx(p, ChatFormatting.RED + "Knight will no longer ignore nearby enemies", true); } } } else { Utils.MessageEx(p, ChatFormatting.RED + "You have not hired this Knight", true); } } else { Utils.MessageEx(p, ChatFormatting.RED + "Knight has not been hired", true); } })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 132 , 70, 20, Component.nullToEmpty("Hire Guard"), (p_96278_) -> { boolean hasItem = false; if(knight.getOwner() == null){ for(ItemStack items : p.getInventory().items){ if(items.getItem().equals(ModItems.GOLD_COIN.get())){ hasItem = true; items.setCount(items.getCount()-1); } } if(hasItem){ knight.setOwner(p); Utils.MessageEx(p, ChatFormatting.GREEN + "You have hired a Knight!", true); } else{ Utils.MessageEx(p, ChatFormatting.RED + "You do not have any gold coins!", true); } } else { Utils.MessageEx(p, ChatFormatting.RED + "This Guard is already hired!", true); } this.minecraft.setScreen(null); })); super.init(); } @Override public boolean shouldCloseOnEsc() { return true; } @Override public void render(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) { this.renderBackground(pPoseStack); super.render(pPoseStack, pMouseX, pMouseY, pPartialTick); } @Override protected void renderBg(PoseStack pPoseStack, float pPartialTick, int pMouseX, int pMouseY) { } @Override public boolean isPauseScreen() { return true; } @Override public void onClose() { this.minecraft.setScreen(null); } } Attaching Screen @Mod.EventBusSubscriber(modid = Main.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public class ClientSetup { @SubscribeEvent public static void doSetup(FMLClientSetupEvent event) { event.enqueueWork( () -> { MenuScreens.register(ContainerInit.GUARD_MENU.get(), GuardScreen::new); }); EntityRenderers.register(EntityInit.KNIGHT.get(), KnightRenderer::new); EntityRenderers.register(EntityInit.ARCHER.get(), ArcherRenderer::new); } } I followed a tutorial perfectly except they are using BlockEntity and im using entity mobInteract and calling player.openMenu
  11. regarding exit code 1 @clemin_ found a solution which was to complete delete and re-install the .minecraft folder
  12. this is really weird, try to remove some mods that might be trying to call it. Just remove mods one by one till the error goes away
  13. above you mentioned that you are using mods correct? Where are the mods stored in?
  14. run task manager and hover over Minecraft and try to get that error to occur again, check if the RAM is overloaded. My PC is pretty good but its not good enough to run as much mods as you have without it taking a performance hit. I didn't see optifine in ur mod list maybe try to run it? And I'm also assuming your running the game on ur local world and not creating and connecting to your own private server right? This could even be a mod confliction with the option screen coming up, maybe an unresolved field I am super unsure what it could be. I didnt get much from that log
  15. I dont think you can count ticks using that event so maybe have two separate event's. First use leftClickEmpty to set an int persistent data(label this whatever) and then check in PlayerTick if you have this data tag and that Minecraft.getInstance().mouseHandler.isLeftPressed(). If so add 1 to the overall value of that tag and then in playertick check if the player has the tag but is not pressing down LMB then thats when you shoot the gun. Note 1 Second in ticks is 20 I think or 22 i'm unsure just use a static method to convert to ticks and convert ticks to seconds
  16. quick question does the game window no longer respond? does the background of the game still render?
  17. Cant find a fix, I found a weird fix tho if I have a custom item that overrides interactLivingEntity and I try to open the screen it works perfectly and once I do that I can open the screen with any or no item perfectly. Its only when I try to open the screen without that item in my hand in the first place The Interaction Method will be posted in the original topic
  18. are all the mods in the .minecraft mods folder or the versions mod folder?
  19. you need to be more specific what icon does not load, is there any logs you can provide?
  20. the official site to download forge is https://files.minecraftforge.net/net/minecraftforge/forge/, if this is the same URL you are downloading from I would highly recommend you scan your computer for viruses and check if any extensions to your browser are redirecting you to malware sites or malware downloads. Please note the download file should be an executable .jar and yes initially it sends you to an AdFoc.us link so all you have to do is wait till the timer is done on the top right and click "Skip" do not click or download anything else
  21. SOLVED: My custom item that overrides livingInteract method conflicted with my custom entitys mobInteract method causing weird stuff to happen Ok I have a weird glitch, whenever I first call my screen it works fine and the mouse is stuck to the screen and I cant move my player at all but once I reload the world and try to interact with an entity and call the screen it glitches out and I cant click any of the buttons because whenever I move my keyboard or mouse its moving my player and my camera and whenever I click escape the screen pops up over and over and over and when the screen actually closes for good and I look at an entity it pops up the screen again. I think this is an issue with the interaction method im using, how do I specify on rightClick only? GuardScreen public GuardScreen(Knight knight, Player p) { super(Component.nullToEmpty("Guard")); this.minecraft = Minecraft.getInstance(); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 24, 70, 20, Component.nullToEmpty("Stay"), (p_96278_) -> { knight.setStay(); Utils.MessageEx(p, ChatFormatting.GREEN + "Knight will now stay", true); })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 60, 70, 20, Component.nullToEmpty("Move Freely"), (p_96278_) -> { knight.moveFreely(); Utils.MessageEx(p, ChatFormatting.GREEN + "Knight will now move freely", true); })); } public GuardScreen(Archer archer, Player p) { super(Component.nullToEmpty("Archer")); this.minecraft = Minecraft.getInstance(); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 24, 70, 20, Component.nullToEmpty("Stay"), (p_96278_) -> { archer.setStay(); Utils.MessageEx(p, ChatFormatting.GREEN + "Archer will now stay", true); })); this.addRenderableWidget(new Button(this.width / 2 + 5, this.height / 6 - 12 + 60, 70, 20, Component.nullToEmpty("Move Freely"), (p_96278_) -> { archer.moveFreely(); Utils.MessageEx(p, ChatFormatting.GREEN + "Archer will now move freely", true); })); } @Override public boolean shouldCloseOnEsc() { return true; } @Override public void onClose() { this.minecraft.setScreen(null); } Calling Method public void interactedWith(Player pPlayer){ if(this.getOwner() != null){ if(this.getOwner().equals(pPlayer) || this.getOwner().getId() == pPlayer.getId()){ LocalPlayer lPlayer = Minecraft.getInstance().player; if(lPlayer.equals(pPlayer) || lPlayer.getId() == pPlayer.getId() || lPlayer.getUUID().equals(pPlayer.getUUID())){ Minecraft.getInstance().setScreen(new GuardScreen(this, pPlayer)); } } } } Item interactionMethod(referring to the comment below) public InteractionResult interactLivingEntity(ItemStack pStack, Player pPlayer, LivingEntity pInteractionTarget, InteractionHand pUsedHand) { if(pInteractionTarget instanceof Knight k){ if(k.getOwner() == null){ k.setOwner(pPlayer); if(pPlayer.getMainHandItem() != null){ if(pPlayer.getMainHandItem().getItem().equals(ModItems.GOLD_COIN.get())){ pPlayer.getMainHandItem().setCount(pPlayer.getMainHandItem().getCount()-1); } } Utils.MessageEx(pPlayer, ChatFormatting.GREEN + "You have hired a Knight", true); } } else if(pInteractionTarget instanceof Archer a){ if(a.getOwner() == null){ a.setOwner(pPlayer); if(pPlayer.getMainHandItem() != null){ if(pPlayer.getMainHandItem().getItem().equals(ModItems.GOLD_COIN.get())){ pPlayer.getMainHandItem().setCount(pPlayer.getMainHandItem().getCount()-1); } } Utils.MessageEx(pPlayer, ChatFormatting.GREEN + "You have hired an Archer", true); } } return super.interactLivingEntity(pStack, pPlayer, pInteractionTarget, pUsedHand); }
  22. nevermind figured it out, its because I had to re initialize this.minecraft field
  23. As title states minecraft.client.popguilayer() throws NullPointerException because some private field is returning null, thing is I cant tell what the field is because its labeled as this.f_92133
  24. Iterate through player.getInventory and check the items list and see if the itemstack is there or if you specifically want an item then do ItemStack$getItem().equals() or ItemStack$getItem() instance of
  25. One thing you could do is set a persistent data tag and check in LivingKnockbackEvent if that entity has that tag if so do whatever and remove that tag
×
×
  • Create New...

Important Information

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