Skip to content

Commit

Permalink
将药壶的槽位与GUI对齐。
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyceryl6 committed Aug 20, 2024
1 parent 1d6449d commit 7ff55d1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.hiedacamellia.whispergrove;

import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import org.hiedacamellia.whispergrove.registers.*;

import java.util.Locale;

@Mod(WhisperGrove.MODID)
public class WhisperGrove {

Expand All @@ -25,4 +28,8 @@ public WhisperGrove(IEventBus modEventBus, ModContainer modContainer) {
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
}

public static ResourceLocation prefix(String name) {
return ResourceLocation.fromNamespaceAndPath(MODID, name.toLowerCase(Locale.ROOT));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

public class SpringingMenu extends AbstractContainerMenu implements Supplier<Map<Integer, Slot>> {

public final static HashMap<String, Object> guistate = new HashMap<>();
public final Level world;
public final Player entity;
public int x, y, z;
Expand All @@ -46,19 +45,19 @@ public SpringingMenu(int containerId, Inventory inventory, ContainerLevelAccess
this.world = inventory.player.level();
for (int ni = 0 ; ni < 3; ++ni) {
for (int nj = 0; nj < 3; ++nj) {
this.customSlots.put(ni * 3 + nj, this.addSlot(new SlotItemHandler(itemHandler, ni * 3 + nj, 20 + nj * 18, 30 + ni * 18)));
this.customSlots.put(ni * 3 + nj, this.addSlot(new SlotItemHandler(itemHandler, ni * 3 + nj, 97 + nj * 18, 24 + ni * 18)));
}
}

this.customSlots.put(9, this.addSlot(new SlotItemHandler(itemHandler, 9, 132, 41)));
this.customSlots.put(9, this.addSlot(new SlotItemHandler(itemHandler, 9, 209, 42)));
for (int si = 0; si < 3; ++si) {
for (int sj = 0; sj < 9; ++sj) {
this.addSlot(new Slot(inventory, sj + (si + 1) * 9, 7 + sj * 18, 99 + si * 18));
this.addSlot(new Slot(inventory, sj + (si + 1) * 9, 84 + sj * 18, 100 + si * 18));
}
}

for (int si = 0; si < 9; ++si) {
this.addSlot(new Slot(inventory, si, 7 + si * 18, 158));
this.addSlot(new Slot(inventory, si, 84 + si * 18, 159));
}

this.addDataSlots(containerData);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@FieldsAreNonnullByDefault
package org.hiedacamellia.whispergrove.content.client.menu;

import net.minecraft.FieldsAreNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.hiedacamellia.whispergrove.content.client.screen;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
Expand All @@ -15,22 +11,17 @@
import net.minecraft.world.level.Level;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.network.PacketDistributor;
import org.hiedacamellia.whispergrove.WhisperGrove;
import org.hiedacamellia.whispergrove.content.client.menu.SpringingMenu;

import java.util.HashMap;

@OnlyIn(Dist.CLIENT)
public class SpringingScreen extends AbstractContainerScreen<SpringingMenu> {

private static final HashMap<String, Object> guistate = SpringingMenu.guistate;
private static final ResourceLocation TEXTURE = WhisperGrove.prefix("textures/screens/springing_background.png");
private final Level world;
private final int x,y,z;
private final int x, y, z;
private final BlockPos pos;
private final Player entity;
//Button button_confirm;
Button button_confirm;

public SpringingScreen(SpringingMenu container, Inventory inventory, Component title) {
super(container, inventory, title);
Expand All @@ -40,11 +31,14 @@ public SpringingScreen(SpringingMenu container, Inventory inventory, Component t
this.z = container.z;
this.pos = container.pos;
this.entity = container.entity;
this.imageWidth = 280;
this.imageHeight = 166;
this.imageWidth = 252;
this.imageHeight = 183;
}

private static final ResourceLocation texture =ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID, "textures/screens/springing_background.png");
@Override
public void init() {
super.init();
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
Expand All @@ -57,17 +51,18 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int gx, int gy) {
PoseStack poseStack = guiGraphics.pose();
poseStack.pushPose();
guiGraphics.blit(texture, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight);
guiGraphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight);
poseStack.popPose();
}

@Override
public boolean keyPressed(int key, int b, int c) {
if (key == 256) {
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256) {
this.minecraft.player.closeContainer();
return true;
}
return super.keyPressed(key, b, c);

return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
Expand All @@ -85,24 +80,4 @@ public void onClose() {
super.onClose();
}

@Override
public void init() {
super.init();
button_confirm = new ImageButton(220,23,234-220,37-23,
new WidgetSprites(ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID,"textures/screens/springing_conform_button.png"),
ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID,"textures/screens/springing_conform_button_pressed.png")),
e -> {
// PacketDistributor.sendToServer(new CookingRangeUiButton(0, pos));
// CookingRangeUiButton.handleButtonAction(entity, 0, pos);
}){
@Override
public void renderWidget(GuiGraphics guiGraphics, int gx, int gy, float ticks) {
if (true)
super.renderWidget(guiGraphics, gx, gy, ticks);
}
};

guistate.put("button:button_confirm", button_confirm);
this.addRenderableWidget(button_confirm);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit 7ff55d1

Please sign in to comment.