Everything posted by Klarks
-
[1.16.4] How i can open a container by clicking on my mob
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); }
-
[1.16.4] How i can open a container by clicking on my mob
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; } }
-
[1.16.4] How i can spawn a full grown sweet berry bush
I have this code for now. What should i do world.setBlockState(pos.add(x,0,z),Blocks.SWEET_BERRY_BUSH.getDefaultState());
-
[1.16.4] How i can spawn an item
how i can spawn it like it drops out of the player
-
[1.16.4] How i can spawn an item
How to spawn an Item like player drops it.
-
[1.16.4] How i can detect mouse cliking
Thanks that's working
-
[1.16.4] How i can detect mouse cliking
My event is static and GameSetting.keyBindAttack not
-
[1.16.4] How i can detect mouse cliking
if (GameSettings.keyBindAttack.isKeyDown()) { System.out.println(g); }
-
[1.16.4] How i can detect mouse cliking
I already tried to get it from gamesetting but for some reason i cant
-
[1.16.4] How i can detect mouse cliking
I cant find them. Where i can get them
-
[1.16.4] How i can detect mouse cliking
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"); } } }
-
[1.16.4] gui only open for host player
Thanks its working now
-
[1.16.4] gui only open for host player
public static void open() { Minecraft.getInstance().displayGuiScreen(new MobScreen()); }
-
[1.16.4] gui only open for host player
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); }
-
[1.16.4] How can I spawn a mob with the name of the player who spawned
like this? Entity e = entityType.spawn(spawnWorld,null,null,pos, SpawnReason.SPAWN_EGG,true,true); e.setCustomName(new TranslationTextComponent(ctx.get().getSender().getScoreboardName()));
-
[1.16.4] How can I spawn a mob with the name of the player who spawned
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);
-
[1.16.4] How can I spawn a mob with the name of the player who spawned
I spawned the mod with this code. Is this count as spawn eggs? entityType.spawn(spawnWorld,null,null,pos, SpawnReason.SPAWN_EGG,true,true);
-
[1.16.4] How can I spawn a mob with the name of the player who spawned
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); }
-
[1.16.4] How i can make a own inventory
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); }
-
[1.16.4] How i can make a own inventory
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
-
[1.16.4] How i can make a own inventory
Yes I have the method but I dont know how to use it properly and what i should sent to the server.
-
[1.16.4] How i can make a own inventory
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); } }
-
[1.16.4] How i can make a own inventory
Thanks, ill try to do it
-
[1.16.4] How i can make a own inventory
How can i fiend any tips in vanila code or somewhere else to understend how to do it
-
[1.16.4] How i can make a own inventory
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) ); } } } }
IPS spam blocked by CleanTalk.