Kuri_pa Posted September 30, 2022 Share Posted September 30, 2022 my ForgeSlider can't drag , it can only be click ,I'm not sure if I'm doing something wrong this is my Screen code public class MannequinScreen extends AbstractContainerScreen<MannequinMenu> { private EditBox NameBox; private final MannequinEntity mannequin; public final MannequinMenu menu; private ForgeSlider xRotationSlider; private ForgeSlider yRotationSlider; private ForgeSlider zRotationSlider; private ForgeSlider scaleSlider; private CycleButton<Part> partButton; private Part nowPart; private Rotations rotations; private float xMouse; private float yMouse; private static final ResourceLocation TEXTURE = new ResourceLocation(KpRandomThing.MODID, "textures/gui/mannequin.png"); public MannequinScreen(MannequinMenu container, Inventory inventory, Component text) { super(container, inventory, text); this.imageWidth = 176; this.imageHeight = 210; this.mannequin = container.mannequin; this.menu = container; } @Override public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderTooltip(matrixStack, mouseX, mouseY); this.xMouse = mouseX; this.yMouse = mouseY; } @Override protected void renderBg(PoseStack matrixStack, float partialTicks, int gx, int gy) { RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShaderTexture(0, TEXTURE); GuiComponent.blit(matrixStack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight); RenderSystem.disableBlend(); int width = (this.width - this.imageWidth) / 2; int height = (this.height - this.imageHeight) / 2; InventoryScreen.renderEntityInInventory(width + 46, height + 106, 30, (float) (width + 51) - this.xMouse, (float) (height + 75 - 50) - this.yMouse, this.mannequin); } @Override public void init() { super.init(); this.minecraft.keyboardHandler.setSendRepeatsToGui(true); NameBox = new EditBox(this.font, this.leftPos + 6, this.topPos + 4, 99, 20, new TextComponent("name")); NameBox.setMaxLength(60); this.addRenderableWidget(NameBox); Button rename = new Button(this.leftPos + 114, this.topPos + 4, 54, 20, new TextComponent("Rename"), onPress -> { if (!NameBox.getValue().isEmpty()) { KpRandomThing.INSTANCE.sendToServer( new MessagePacket(1, new TextComponent(NameBox.getValue()))); } }); this.addRenderableWidget(rename); int sliderX = this.leftPos + 92; int sliderY = this.topPos + 5; this.partButton = createPartButton(sliderX, sliderY + 80); this.addRenderableWidget(partButton); rotations = this.partButton.getValue().getPose(mannequin); this.xRotationSlider = createAngleSlider(sliderX, sliderY + 20, 74, 20, "X:", rotations.getX()); this.yRotationSlider = createAngleSlider(sliderX, sliderY + 40, 74, 20, "Y:", rotations.getY()); this.zRotationSlider = createAngleSlider(sliderX, sliderY + 60, 74, 20, "Z:", rotations.getZ()); this.scaleSlider = new ForgeSlider(sliderX, sliderY + 100, 74, 20, new TranslatableComponent("button.kp_random_thing.scale"), TextComponent.EMPTY, 0.1, 2, mannequin.getScale(), 0, 2, true); this.addRenderableWidget(xRotationSlider); this.addRenderableWidget(yRotationSlider); this.addRenderableWidget(zRotationSlider); this.addRenderableWidget(scaleSlider); } @Override protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) { } @Override public boolean mouseReleased(double xMouse, double yMouse, int id) { updata(); return super.mouseReleased(xMouse, yMouse, id); } @Override public boolean keyPressed(int key, int b, int c) { if (key == 256) { this.minecraft.player.closeContainer(); return true; } return super.keyPressed(key, b, c); } private void updata() { if (nowPart != partButton.getValue()) switchPart(); String name = partButton.getValue().name; double x = xRotationSlider.getValue(); double y = yRotationSlider.getValue(); double z = zRotationSlider.getValue(); double scale = scaleSlider.getValue(); KpRandomThing.INSTANCE.sendToServer(new MessagePacket(0, x, y, z, scale, new TextComponent(name))); } private void switchPart() { Rotations rotations = partButton.getValue().getPose(mannequin); this.xRotationSlider.setValue(rotations.getX()); this.yRotationSlider.setValue(rotations.getY()); this.zRotationSlider.setValue(rotations.getZ()); this.nowPart = partButton.getValue(); } private CycleButton<Part> createPartButton(int width, int height) { CycleButton<Part> button = CycleButton.builder(Part::getName).withValues(Part.values()).create(width, height, 80, 20, new TranslatableComponent("button.kp_random_thing.part")); return button; } private ForgeSlider createAngleSlider(int x, int y, int width, int height, String prefix, double currentValue) { return new ForgeSlider(x, y, width, height, new TextComponent(prefix), TextComponent.EMPTY, -180D, 180D, currentValue, 0, 2, true); } public enum Part { HEAD(MannequinEntity.DATA_HEAD_POSE, MannequinEntity.HEAD), BODY(MannequinEntity.DATA_BODY_POSE, MannequinEntity.BODY), LEFT_ARM(MannequinEntity.DATA_LEFT_ARM_POSE, MannequinEntity.LEFT_ARM), RIGHT_ARM(MannequinEntity.DATA_RIGHT_ARM_POSE, MannequinEntity.RIGHT_ARM), LEFT_LEG(MannequinEntity.DATA_LEFT_LEG_POSE, MannequinEntity.LEFT_LEG), RIGHT_LEG(MannequinEntity.DATA_RIGHT_LEG_POSE, MannequinEntity.RIGHT_LEG); final EntityDataAccessor<Rotations> dataPose; final String name; Part(EntityDataAccessor<Rotations> dataPose, String name) { this.dataPose = dataPose; this.name = name; } public Rotations getPose(ArmorStand entity) { if (entity == null) { return new Rotations(0, 0, 0); } return entity.getEntityData().get(dataPose); } public Component getName() { return new TranslatableComponent("button.kp_random_thing.part." + name); } } } Quote Link to comment Share on other sites More sharing options...
warjort Posted September 30, 2022 Share Posted September 30, 2022 Looks like your issue is because you are in a container screen. If you look at "normal" processing ContainerEventHandler.mouseDragged() It sends the mouse dragged event to the focused widget (if there is one). However, AbstractContainerScreen overrides this method and only considers slots. You are going to have to override it again to put back the processing for your sliders and then call super() if there is no focused slider. 1 Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
Kuri_pa Posted October 1, 2022 Author Share Posted October 1, 2022 On 9/30/2022 at 4:44 PM, warjort said: Looks like your issue is because you are in a container screen. If you look at "normal" processing ContainerEventHandler.mouseDragged() It sends the mouse dragged event to the focused widget (if there is one). However, AbstractContainerScreen overrides this method and only considers slots. You are going to have to override it again to put back the processing for your sliders and then call super() if there is no focused slider. Thank you! It works now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.