Skip to content

Commit

Permalink
继续大修
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi154 committed Jun 10, 2024
1 parent 88d383f commit e25d403
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.touhou.mystiasizakaya.client.gui;

import net.touhou.mystiasizakaya.world.inventory.BankUiMenu;
import net.touhou.mystiasizakaya.network.BankUiButtonMessage;
import net.touhou.mystiasizakaya.network.BankUiButton;
import net.touhou.mystiasizakaya.MystiasIzakayaMod;

import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -113,8 +113,8 @@ public void moveCursorTo(int pos) {
this.addWidget(this.input);
button_take_out = Button.builder(Component.translatable("gui.mystias_izakaya.bank_ui.button_take_out"), e -> {
if (true) {
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new BankUiButtonMessage(0, x, y, z));
BankUiButtonMessage.handleButtonAction(entity, 0, x, y, z);
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new BankUiButton(0, x, y, z));
BankUiButton.handleButtonAction(entity, 0, x, y, z);
}
}).bounds(this.leftPos + 31, this.topPos + 100, 110, 20).build();
guistate.put("button:button_take_out", button_take_out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.touhou.mystiasizakaya.util.ButtunShow;
import net.touhou.mystiasizakaya.cooking.ui.Status;
import net.touhou.mystiasizakaya.cooking.ui.Lefttime;
import net.touhou.mystiasizakaya.network.CookingRangeUiButtonMessage;
import net.touhou.mystiasizakaya.network.CookingRangeUiButton;
import net.touhou.mystiasizakaya.MystiasIzakayaMod;

import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -100,16 +100,16 @@ public void init() {
button_confirm = Button
.builder(Component.translatable("gui.mystias_izakaya.cooking_range_ui.button_confirm"), e -> {
if (true) {
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButtonMessage(0, x, y, z));
CookingRangeUiButtonMessage.handleButtonAction(entity, 0, x, y, z);
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButton(0, x, y, z));
CookingRangeUiButton.handleButtonAction(entity, 0, x, y, z);
}
}).bounds(this.leftPos + 94, this.topPos + 60, 90, 20).build();
guistate.put("button:button_confirm", button_confirm);
this.addRenderableWidget(button_confirm);
button_select = Button.builder(Component.literal(""), e -> {
if (ButtunShow.get(entity, 7)) {
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButtonMessage(1, x, y, z));
CookingRangeUiButtonMessage.handleButtonAction(entity, 1, x, y, z);
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButton(1, x, y, z));
CookingRangeUiButton.handleButtonAction(entity, 1, x, y, z);
}
}).bounds(this.leftPos + 40, this.topPos + 24, 45, 20).build(builder -> new Button(builder) {
@Override
Expand All @@ -122,8 +122,8 @@ public void render(GuiGraphics guiGraphics, int gx, int gy, float ticks) {
this.addRenderableWidget(button_select);
button_select1 = Button.builder(Component.literal(""), e -> {
if (ButtunShow.get(entity, 8)) {
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButtonMessage(2, x, y, z));
CookingRangeUiButtonMessage.handleButtonAction(entity, 2, x, y, z);
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButton(2, x, y, z));
CookingRangeUiButton.handleButtonAction(entity, 2, x, y, z);
}
}).bounds(this.leftPos + 40, this.topPos + 51, 45, 20).build(builder -> new Button(builder) {
@Override
Expand All @@ -136,8 +136,8 @@ public void render(GuiGraphics guiGraphics, int gx, int gy, float ticks) {
this.addRenderableWidget(button_select1);
button_select2 = Button.builder(Component.literal(""), e -> {
if (ButtunShow.get(entity, 9)) {
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButtonMessage(3, x, y, z));
CookingRangeUiButtonMessage.handleButtonAction(entity, 3, x, y, z);
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButton(3, x, y, z));
CookingRangeUiButton.handleButtonAction(entity, 3, x, y, z);
}
}).bounds(this.leftPos + 40, this.topPos + 78, 45, 20).build(builder -> new Button(builder) {
@Override
Expand All @@ -150,8 +150,8 @@ public void render(GuiGraphics guiGraphics, int gx, int gy, float ticks) {
this.addRenderableWidget(button_select2);
button_select3 = Button.builder(Component.literal(""), e -> {
if (ButtunShow.get(entity, 10)) {
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButtonMessage(4, x, y, z));
CookingRangeUiButtonMessage.handleButtonAction(entity, 4, x, y, z);
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButton(4, x, y, z));
CookingRangeUiButton.handleButtonAction(entity, 4, x, y, z);
}
}).bounds(this.leftPos + 40, this.topPos + 105, 45, 20).build(builder -> new Button(builder) {
@Override
Expand All @@ -164,8 +164,8 @@ public void render(GuiGraphics guiGraphics, int gx, int gy, float ticks) {
this.addRenderableWidget(button_select3);
button_select4 = Button.builder(Component.literal(""), e -> {
if (ButtunShow.get(entity, 11)) {
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButtonMessage(5, x, y, z));
CookingRangeUiButtonMessage.handleButtonAction(entity, 5, x, y, z);
MystiasIzakayaMod.PACKET_HANDLER.sendToServer(new CookingRangeUiButton(5, x, y, z));
CookingRangeUiButton.handleButtonAction(entity, 5, x, y, z);
}
}).bounds(this.leftPos + 40, this.topPos + 132, 45, 20).build(builder -> new Button(builder) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,14 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.platform.GlStateManager;
import net.touhou.mystiasizakaya.orders.Initorders;

@Mod.EventBusSubscriber({ Dist.CLIENT })
public class OrdersOverlay {
@SubscribeEvent(priority = EventPriority.NORMAL)
public static void eventHandler(RenderGuiEvent.Pre event) {
int w = event.getWindow().getGuiScaledWidth();
int h = event.getWindow().getGuiScaledHeight();
Level world = null;
double x = 0;
double y = 0;
double z = 0;
Player entity = Minecraft.getInstance().player;
if (entity != null) {
world = entity.level();
x = entity.getX();
y = entity.getY();
z = entity.getZ();
}
RenderSystem.disableDepthTest();
RenderSystem.depthMask(false);
RenderSystem.enableBlend();
Expand All @@ -47,6 +37,7 @@ public static void eventHandler(RenderGuiEvent.Pre event) {
String fm = "";
String fmb = "";
int reali = 0;
Initorders.init(entity);
for (int i = 0; i < 7; i++) {
fm = GetCuisinesTexture.execute(i, entity);
fmb = GetBeveragesTexture.execute(i, entity);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/touhou/mystiasizakaya/command/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void registerCommand(RegisterCommandsEvent event) {
int id = (int) DoubleArgumentType.getDouble(arguments, "id");
Player player = arguments.getSource().getPlayer();
List<String> orders_list = player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new Variables.PlayerVariables()).orders;
orders_list.set(id, "");
orders_list.set(id, "minecraft:air");
player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.orders = orders_list;
capability.syncPlayerVariables(player);
Expand All @@ -59,7 +59,7 @@ public static void registerCommand(RegisterCommandsEvent event) {
int id = (int) DoubleArgumentType.getDouble(arguments, "id");
Player player = arguments.getSource().getPlayer();
List<String> ordersbeverages_list = player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new Variables.PlayerVariables()).ordersbeverages;
ordersbeverages_list.set(id, "");
ordersbeverages_list.set(id, "minecraft:air");
player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.ordersbeverages = ordersbeverages_list;
capability.syncPlayerVariables(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@
import java.util.HashMap;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class BankUiButtonMessage {
public class BankUiButton {
private final int buttonID, x, y, z;

public BankUiButtonMessage(FriendlyByteBuf buffer) {
public BankUiButton(FriendlyByteBuf buffer) {
this.buttonID = buffer.readInt();
this.x = buffer.readInt();
this.y = buffer.readInt();
this.z = buffer.readInt();
}

public BankUiButtonMessage(int buttonID, int x, int y, int z) {
public BankUiButton(int buttonID, int x, int y, int z) {
this.buttonID = buttonID;
this.x = x;
this.y = y;
this.z = z;
}

public static void buffer(BankUiButtonMessage message, FriendlyByteBuf buffer) {
public static void buffer(BankUiButton message, FriendlyByteBuf buffer) {
buffer.writeInt(message.buttonID);
buffer.writeInt(message.x);
buffer.writeInt(message.y);
buffer.writeInt(message.z);
}

public static void handler(BankUiButtonMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
public static void handler(BankUiButton message, Supplier<NetworkEvent.Context> contextSupplier) {
NetworkEvent.Context context = contextSupplier.get();
context.enqueueWork(() -> {
Player entity = context.getSender();
Expand All @@ -70,6 +70,6 @@ public static void handleButtonAction(Player entity, int buttonID, int x, int y,

@SubscribeEvent
public static void registerMessage(FMLCommonSetupEvent event) {
MystiasIzakayaMod.addNetworkMessage(BankUiButtonMessage.class, BankUiButtonMessage::buffer, BankUiButtonMessage::new, BankUiButtonMessage::handler);
MystiasIzakayaMod.addNetworkMessage(BankUiButton.class, BankUiButton::buffer, BankUiButton::new, BankUiButton::handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@
import java.util.HashMap;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class CookingRangeUiButtonMessage {
public class CookingRangeUiButton {
private final int buttonID, x, y, z;

public CookingRangeUiButtonMessage(FriendlyByteBuf buffer) {
public CookingRangeUiButton(FriendlyByteBuf buffer) {
this.buttonID = buffer.readInt();
this.x = buffer.readInt();
this.y = buffer.readInt();
this.z = buffer.readInt();
}

public CookingRangeUiButtonMessage(int buttonID, int x, int y, int z) {
public CookingRangeUiButton(int buttonID, int x, int y, int z) {
this.buttonID = buttonID;
this.x = x;
this.y = y;
this.z = z;
}

public static void buffer(CookingRangeUiButtonMessage message, FriendlyByteBuf buffer) {
public static void buffer(CookingRangeUiButton message, FriendlyByteBuf buffer) {
buffer.writeInt(message.buttonID);
buffer.writeInt(message.x);
buffer.writeInt(message.y);
buffer.writeInt(message.z);
}

public static void handler(CookingRangeUiButtonMessage message, Supplier<NetworkEvent.Context> contextSupplier) {
public static void handler(CookingRangeUiButton message, Supplier<NetworkEvent.Context> contextSupplier) {
NetworkEvent.Context context = contextSupplier.get();
context.enqueueWork(() -> {
Player entity = context.getSender();
Expand Down Expand Up @@ -90,7 +90,7 @@ public static void handleButtonAction(Player entity, int buttonID, int x, int y,

@SubscribeEvent
public static void registerMessage(FMLCommonSetupEvent event) {
MystiasIzakayaMod.addNetworkMessage(CookingRangeUiButtonMessage.class, CookingRangeUiButtonMessage::buffer,
CookingRangeUiButtonMessage::new, CookingRangeUiButtonMessage::handler);
MystiasIzakayaMod.addNetworkMessage(CookingRangeUiButton.class, CookingRangeUiButton::buffer,
CookingRangeUiButton::new, CookingRangeUiButton::handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@
import net.minecraft.core.Direction;
import net.minecraft.client.Minecraft;

import java.util.Arrays;
import java.util.function.Supplier;
import java.util.List;
import java.util.ArrayList;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class Variables {
public static List<Object> orders = new ArrayList<>();
public static List<Object> ordersbeverages = new ArrayList<>();

@SubscribeEvent
public static void init(FMLCommonSetupEvent event) {
Expand Down Expand Up @@ -113,8 +112,8 @@ public void deserializeNBT(Tag nbt) {
public static class PlayerVariables {
public double balance = 0;
public boolean showbalance = true;
public List<String> orders = new ArrayList<>();
public List<String> ordersbeverages = new ArrayList<>();
public List<String> orders = Arrays.asList("minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air","minecraft:air");
public List<String> ordersbeverages = Arrays.asList("minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air", "minecraft:air","minecraft:air");

public void syncPlayerVariables(Entity entity) {
if (entity instanceof ServerPlayer serverPlayer)
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/touhou/mystiasizakaya/orders/Addorder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.touhou.mystiasizakaya.orders;

import net.minecraft.world.entity.player.Player;
import net.minecraftforge.registries.ForgeRegistries;
import net.touhou.mystiasizakaya.network.Variables;

import net.minecraft.world.item.ItemStack;

import java.util.List;

public class Addorder {
public static void execute(ItemStack beverages, ItemStack cuisines, double id, Player player) {
List<String> orders_list = player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new Variables.PlayerVariables()).orders;
List<String> ordersbeverages_list = player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new Variables.PlayerVariables()).ordersbeverages;
String cuisines_str = ForgeRegistries.ITEMS.getKey(cuisines.getItem()).toString();
String beverages_str = ForgeRegistries.ITEMS.getKey(beverages.getItem()).toString();
orders_list.set((int) id, cuisines_str);
ordersbeverages_list.set((int) id, beverages_str);
player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.orders = orders_list;
capability.ordersbeverages = ordersbeverages_list;
capability.syncPlayerVariables(player);
});
}
}
22 changes: 22 additions & 0 deletions src/main/java/net/touhou/mystiasizakaya/orders/Deleteorder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.touhou.mystiasizakaya.orders;

import net.minecraft.world.entity.player.Player;
import net.touhou.mystiasizakaya.network.Variables;

import java.util.List;

public class Deleteorder {
public static void execute(double id, Player player) {
List<String> orders_list = player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new Variables.PlayerVariables()).orders;
List<String> ordersbeverages_list = player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new Variables.PlayerVariables()).ordersbeverages;
String cuisines_str = "minecraft:air";
String beverages_str = "minecraft:air";
orders_list.set((int) id, cuisines_str);
ordersbeverages_list.set((int) id, beverages_str);
player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.orders = orders_list;
capability.ordersbeverages = ordersbeverages_list;
capability.syncPlayerVariables(player);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.tags.ItemTags;
import net.minecraft.resources.ResourceLocation;
import net.touhou.mystiasizakaya.procedures.GetTextureProcedure;

import java.util.List;

Expand All @@ -23,6 +22,6 @@ public static String execute(double id, Player player) {
if (!new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(order))).is(tag)) {
return "";
}
return GetTextureProcedure.get(order);
return order.split(":")[1]+ "_";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.tags.ItemTags;
import net.minecraft.resources.ResourceLocation;
import net.touhou.mystiasizakaya.procedures.GetTextureProcedure;

import java.util.List;

Expand All @@ -24,6 +23,6 @@ public static String execute(double id, Player player) {
if (!new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(order))).is(tag)) {
return "";
}
return GetTextureProcedure.get(order);
return order.split(":")[1]+ "_";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class Initorders {
public static void init(Player player) {
List<String> orders_list = player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new Variables.PlayerVariables()).orders;
List<String> ordersbeverages_list = player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new Variables.PlayerVariables()).ordersbeverages;
if (orders_list.size() == 0) {
if (orders_list.size() < 8) {
for (int i = 0; i < 10; i++) {
orders_list.add("");
orders_list.add("minecraft:air");
}
}
if (ordersbeverages_list.size() == 0) {
if (ordersbeverages_list.size() < 8) {
for (int i = 0; i < 10; i++) {
ordersbeverages_list.add("");
ordersbeverages_list.add("minecraft:air");
}
}
player.getCapability(Variables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit e25d403

Please sign in to comment.