Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Klarks

Members
  • Joined

Everything posted by Klarks

  1. How i can get my container here public ActionResultType func_230254_b_(PlayerEntity playerEntity, Hand hand) { if (!this.world.isRemote) { String en = getOwner(); String pl = playerEntity.getScoreboardName(); if(en.equals(pl)) { NetworkHooks.openGui((ServerPlayerEntity) playerEntity,*container*); } else playerEntity.sendMessage(new TranslationTextComponent("You are not "+en),Util.DUMMY_UUID); } return ActionResultType.func_233537_a_(this.world.isRemote); }
  2. I know that i have to somehow open gui on server but i dont know what exactly i need to do Container public class MyModContainer extends Container implements INamedContainerProvider { private IItemHandler playerInventory; protected MyModContainer(int id, PlayerInventory playerInventory) { super(RegObj.MOD_CONTAINER.get(), id); this.playerInventory = new InvWrapper(playerInventory); playerInventory.player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h -> { addSlot(new SlotItemHandler(h,0,79,18)); }); layoutPlayerInventory(7,54); } private int addSlotRange(IItemHandler handler, int index, int x, int y, int amount, int dx) { for(int i = 0; i < amount;i++) { addSlot(new SlotItemHandler(handler,index,x,y)); x+=dx; index++; } return index; } private int addSlotBox(IItemHandler handler,int index,int x,int y,int horAmount,int dx,int verAmount,int dy) { for (int j = 0;j<verAmount;j++) { index = addSlotRange(handler,index,x,y,horAmount,dx); y+=dy; } return index; } private void layoutPlayerInventory(int leftCol, int topRow) { addSlotBox(playerInventory,9,leftCol,topRow,9,18,3,18); topRow += 58; addSlotRange(playerInventory,0,leftCol,topRow,9,18); } @Override public boolean canInteractWith(PlayerEntity playerIn) { return true; } @Override public ITextComponent getDisplayName() { return new StringTextComponent("MY_INV"); } @Nullable @Override public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_) { return null; } } Screen public class MyModInv extends ContainerScreen<MyModContainer> { private static final int WIDTH =179; private static final int HEIGHT =151; private ResourceLocation GUI = new ResourceLocation(Main.MODID,"textures/gui/my_inv.png"); public MyModInv(MyModContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { super(screenContainer, inv, titleIn); } @Override public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderBackground(matrixStack); this.renderHoveredTooltip(matrixStack, mouseX, mouseY); } @Override protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int x, int y) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.minecraft.getTextureManager().bindTexture(GUI); int i = (this.width - WIDTH) / 2; int j = (this.height - HEIGHT) / 2; this.blit(matrixStack, i, j, 0, 0, WIDTH, HEIGHT); } @Override public boolean isPauseScreen() { return false; } }
  3. I have this code for now. What should i do world.setBlockState(pos.add(x,0,z),Blocks.SWEET_BERRY_BUSH.getDefaultState());
  4. how i can spawn it like it drops out of the player
  5. How to spawn an Item like player drops it.
  6. Thanks that's working
  7. My event is static and GameSetting.keyBindAttack not
  8. if (GameSettings.keyBindAttack.isKeyDown()) { System.out.println(g); }
  9. I already tried to get it from gamesetting but for some reason i cant
  10. I cant find them. Where i can get them
  11. i have tried to use this but it doesnt work public static final KeyBinding LMB = new KeyBinding("key.structure.left", GLFW.GLFW_MOUSE_BUTTON_LEFT, "key.hentai.category.left"); @SubscribeEvent (priority = EventPriority.LOWEST) public static void onClientTick(TickEvent.ClientTickEvent event) throws Exception { if(event.phase.equals(TickEvent.Phase.END)){ if(LMB.isKeyDown()) { System.out.println("Hello"); } } }
  12. Thanks its working now
  13. public static void open() { Minecraft.getInstance().displayGuiScreen(new MobScreen()); }
  14. here i want to player can open a gui only by clicking on the mob with same name but the gui only open for host player. What i did wrong? public ActionResultType func_230254_b_(PlayerEntity playerEntity, Hand hand) { if (!this.world.isRemote) { String en = this.getCustomName().getString(); String pl = playerEntity.getScoreboardName(); if(en.equals(pl)) { MobScreen.open(); } else playerEntity.sendMessage(new TranslationTextComponent("You are not "+en),Util.DUMMY_UUID); } return ActionResultType.func_233537_a_(this.world.isRemote); }
  15. like this? Entity e = entityType.spawn(spawnWorld,null,null,pos, SpawnReason.SPAWN_EGG,true,true); e.setCustomName(new TranslationTextComponent(ctx.get().getSender().getScoreboardName()));
  16. Like this ? ItemStack is = new ItemStack(null); is.setDisplayName(new TranslationTextComponent(ctx.get().getSender().getScoreboardName())); entityType.spawn(spawnWorld,is,null,pos, SpawnReason.SPAWN_EGG,true,true);
  17. I spawned the mod with this code. Is this count as spawn eggs? entityType.spawn(spawnWorld,null,null,pos, SpawnReason.SPAWN_EGG,true,true);
  18. How can i get the player who spawned the mob. Is it would be correct to find a player by distance like this. it is wotking but is it correct? @Override public ILivingEntityData onInitialSpawn(IServerWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, @Nullable ILivingEntityData spawnDataIn, @Nullable CompoundNBT dataTag) { float dist = 999999999; int pl = 0; if (reason == SpawnReason.COMMAND || reason == SpawnReason.SPAWN_EGG || reason == SpawnReason.SPAWNER || reason == SpawnReason.DISPENSER) { List<ServerPlayerEntity> players = worldIn.getWorld().getPlayers(); for(int i = 0;i < players.size();i++) { if ( dist > this.getDistance(players.get(i))) { dist = this.getDistance(players.get(i)); pl = i; } } this.setCustomName(new TranslationTextComponent(players.get(pl).getScoreboardName())); } return super.onInitialSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag); }
  19. So if i would use container-based GUIs my open method should be like public static void open(Supplier<NetworkEvent.Context> ctx, INamedContainerProvider containerProvider) { NetworkHooks.openGui(ctx.get().getSender(),containerProvider); }
  20. its working but did i do this right? Send the packet to the server if key r is pressed. @Mod.EventBusSubscriber(modid = Main.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ForgeHelperMod { public static final KeyBinding TEST = new KeyBinding("key.structure.desc", GLFW.GLFW_KEY_R, "key.magicbeans.category"); private static Field KEYBIND_ARRAY = null; @SubscribeEvent public static void serverLoad(RegisterCommandsEvent event) { ModCommands.register(event.getDispatcher()); } @SubscribeEvent (priority = EventPriority.LOWEST) public static void onClientTick(TickEvent.ClientTickEvent event) throws Exception { if(event.phase.equals(TickEvent.Phase.END)){ World world = Minecraft.getInstance().world; PlayerEntity player = Minecraft.getInstance().player; if(TEST.isKeyDown()){ System.out.println("R"); Networking.sendToServer(new IfKeyPresed()); } } } } Packet itself. It sends the packet to the client for gui open. public class IfKeyPresed { public void handle (Supplier<NetworkEvent.Context> ctx) { ServerPlayerEntity player = ctx.get().getSender(); ctx.get().enqueueWork(() -> { Networking.sendToClient(new PacketOpenGui(), player); }); ctx.get().setPacketHandled(true); } } Gui open packet public class PacketOpenGui { public void handle (Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(NewInvScreen::open); ctx.get().setPacketHandled(true); } } And open method from Screen public static void open() { Minecraft.getInstance().displayGuiScreen(new NewInvScreen()); } Is it correct? And also in single player when i press r to open the gui, it opens but for some reason it pause the game but on server it didn't
  21. Yes I have the method but I dont know how to use it properly and what i should sent to the server.
  22. i made what i needed but only as a command. But i cant understand how i can open it on key press. What i should send to the server for it to open @Override public int run(CommandContext<CommandSource> context) throws CommandSyntaxException { ServerPlayerEntity player = context.getSource().asPlayer(); Networking.sendToClient(new PacketOpenGui(), player); return 0; } My Networking class public class Networking { public static SimpleChannel INSTANCE; private static int ID; public static int nextID() {return ID++;} public static void RegMes() { INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(Main.MODID,"netw"),() -> "1",s -> true,s -> true); INSTANCE.messageBuilder(PacketOpenGui.class, nextID()) .encoder((packetOpenGui, packetBuffer) -> {}) .decoder(buf -> new PacketOpenGui()) .consumer(PacketOpenGui::handle) .add(); INSTANCE.messageBuilder(PacketSpawn.class, nextID()) .encoder(PacketSpawn::toBytes) .decoder(PacketSpawn::new) .consumer(PacketSpawn::handle) .add(); } public static void sendToClient(Object packet, ServerPlayerEntity player) { INSTANCE.sendTo(packet, player.connection.netManager, NetworkDirection.PLAY_TO_CLIENT); } public static void sendToServer(Object packet) { INSTANCE.sendToServer(packet); } }
  23. Thanks, ill try to do it
  24. How can i fiend any tips in vanila code or somewhere else to understend how to do it
  25. Should i use it like this? @SubscribeEvent (priority = EventPriority.LOWEST) public static void onClientTick(TickEvent.ClientTickEvent event) throws Exception { if(event.phase.equals(TickEvent.Phase.END)){ World world = Minecraft.getInstance().world; PlayerEntity player = Minecraft.getInstance().player; if(TEST.isKeyDown()){ if(!world.isRemote) { NetworkHooks.openGui((ServerPlayerEntity) player,(INamedContainerProvider) ); } } } }

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.