|
1 | 1 | package com.solegendary.reignofnether.resources;
|
2 | 2 |
|
3 | 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | +import com.mojang.brigadier.arguments.IntegerArgumentType; |
| 5 | +import com.mojang.brigadier.context.CommandContext; |
| 6 | +import com.mojang.brigadier.exceptions.CommandSyntaxException; |
4 | 7 | import com.mojang.math.Axis;
|
5 |
| -import net.minecraft.network.chat.Style; |
6 |
| -import org.joml.Vector3f; |
7 | 8 | import com.solegendary.reignofnether.hud.HudClientEvents;
|
8 | 9 | import com.solegendary.reignofnether.keybinds.Keybindings;
|
9 | 10 | import com.solegendary.reignofnether.orthoview.OrthoviewClientEvents;
|
|
13 | 14 | import net.minecraft.client.Minecraft;
|
14 | 15 | import net.minecraft.client.gui.Font;
|
15 | 16 | import net.minecraft.client.resources.language.I18n;
|
| 17 | +import net.minecraft.commands.CommandSourceStack; |
| 18 | +import net.minecraft.commands.arguments.EntityArgument; |
16 | 19 | import net.minecraft.core.BlockPos;
|
17 | 20 | import net.minecraft.network.chat.Component;
|
18 | 21 | import net.minecraft.network.chat.MutableComponent;
|
@@ -87,7 +90,7 @@ public static void showWarning(String ownerName, String msg) {
|
87 | 90 | HudClientEvents.showTemporaryMessage(loc);
|
88 | 91 |
|
89 | 92 | // remove checkpoints from a failed building placement since the client has no knowledge of resource costs
|
90 |
| - if (loc.contains("You don't have enough")) { |
| 93 | + if (msg.contains("not_enough")) { |
91 | 94 | for (LivingEntity entity : getSelectedUnits())
|
92 | 95 | if (entity instanceof Unit unit)
|
93 | 96 | if (((Entity) unit).level().isClientSide() && !Keybindings.shiftMod.isDown())
|
@@ -196,4 +199,37 @@ public static void onRenderLevel(RenderLevelStageEvent evt) {
|
196 | 199 | }
|
197 | 200 | floatingTexts.removeIf(t -> t.tickAge > FLOATING_TEXT_MAX_AGE);
|
198 | 201 | }
|
| 202 | + |
| 203 | + public static int trySendingResources(CommandContext<CommandSourceStack> context, ResourceName resourceName) throws CommandSyntaxException { |
| 204 | + Player thisPlayer = context.getSource().getPlayer(); |
| 205 | + Player sendToPlayer = EntityArgument.getPlayer(context, "player"); |
| 206 | + int amount = IntegerArgumentType.getInteger(context, "amount"); |
| 207 | + |
| 208 | + Resources res = getOwnResources(); |
| 209 | + if (res == null || thisPlayer == null) |
| 210 | + return 0; |
| 211 | + |
| 212 | + switch (resourceName) { |
| 213 | + case FOOD -> { |
| 214 | + if (res.food < amount) { |
| 215 | + thisPlayer.sendSystemMessage(Component.translatable(I18n.get("server.resources.reignofnether.not_enough_food"))); |
| 216 | + return 0; |
| 217 | + } |
| 218 | + } |
| 219 | + case WOOD -> { |
| 220 | + if (res.wood < amount) { |
| 221 | + thisPlayer.sendSystemMessage(Component.translatable(I18n.get("server.resources.reignofnether.not_enough_food"))); |
| 222 | + return 0; |
| 223 | + } |
| 224 | + } |
| 225 | + case ORE -> { |
| 226 | + if (res.ore < amount) { |
| 227 | + thisPlayer.sendSystemMessage(Component.translatable(I18n.get("server.resources.reignofnether.not_enough_food"))); |
| 228 | + return 0; |
| 229 | + } |
| 230 | + } |
| 231 | + } |
| 232 | + ResourcesServerboundPacket.sendResources(thisPlayer.getName().getString(), sendToPlayer.getName().getString(), resourceName, amount); |
| 233 | + return 1; |
| 234 | + } |
199 | 235 | }
|
0 commit comments