Explorar el Código

Cheating on servers

Unknown hace 6 años
padre
commit
e7046d4be8

+ 9 - 2
build.gradle

@@ -8,13 +8,20 @@ targetCompatibility = 1.8
 archivesBaseName = "RoughlyEnoughItems"
 version = "2.0.0.39"
 
-def minecraftVersion = "19w03b"
-def yarnVersion = "19w03b.2"
+def minecraftVersion = "19w03c"
+def yarnVersion = "19w03c.4"
 def fabricVersion = "0.1.4.76"
 
 minecraft {
 }
 
+processResources {
+	filesMatching('fabric.mod.json') {
+		expand 'version': project.version
+	}
+	inputs.property "version", project.version
+}
+
 dependencies {
 	minecraft "com.mojang:minecraft:${minecraftVersion}"
 	mappings "net.fabricmc:yarn:${yarnVersion}"

+ 11 - 4
src/main/java/me/shedaniel/rei/api/IRecipeCategory.java

@@ -3,17 +3,15 @@ package me.shedaniel.rei.api;
 import com.mojang.blaze3d.platform.GlStateManager;
 import me.shedaniel.rei.gui.widget.IWidget;
 import me.shedaniel.rei.gui.widget.RecipeBaseWidget;
+import me.shedaniel.rei.gui.widget.RecipeViewingWidget;
 import me.shedaniel.rei.listeners.IMixinContainerGui;
+import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.Drawable;
-import net.minecraft.client.render.BufferBuilder;
 import net.minecraft.client.render.GuiLighting;
-import net.minecraft.client.render.Tessellator;
-import net.minecraft.client.render.VertexFormats;
 import net.minecraft.item.ItemStack;
 import net.minecraft.util.Identifier;
 
 import java.awt.*;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -34,4 +32,13 @@ public interface IRecipeCategory<T extends IRecipeDisplay> {
         return Arrays.asList(new RecipeBaseWidget(bounds));
     }
     
+    default public void drawCategoryBackground(Rectangle bounds) {
+        GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
+        GuiLighting.disable();
+        MinecraftClient.getInstance().getTextureManager().bindTexture(RecipeViewingWidget.CHEST_GUI_TEXTURE);
+        new Drawable() {
+        
+        }.drawTexturedRect((int) bounds.getX(), (int) bounds.getY(), 0, 0, (int) bounds.getWidth(), (int) bounds.getHeight());
+    }
+    
 }

+ 18 - 6
src/main/java/me/shedaniel/rei/client/ClientHelper.java

@@ -96,13 +96,25 @@ public class ClientHelper implements ClientLoaded, ClientModInitializer {
     }
     
     public static boolean tryCheatingStack(ItemStack cheatedStack) {
-        try {
-            PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
-            buf.writeItemStack(cheatedStack.copy());
-            MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CustomPayloadServerPacket(RoughlyEnoughItemsCore.CREATE_ITEMS_PACKET, buf));
+        if (MinecraftClient.getInstance().isInSingleplayer()) {
+            try {
+                PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
+                buf.writeItemStack(cheatedStack.copy());
+                MinecraftClient.getInstance().getNetworkHandler().sendPacket(new CustomPayloadServerPacket(RoughlyEnoughItemsCore.CREATE_ITEMS_PACKET, buf));
+                return true;
+            } catch (Exception e) {
+                return false;
+            }
+        } else {
+            Identifier location = Registry.ITEM.getId(cheatedStack.getItem());
+            String tagMessage = cheatedStack.copy().getTag() != null && !cheatedStack.copy().getTag().isEmpty() ? cheatedStack.copy().getTag().asString() : "";
+            String madeUpCommand = RoughlyEnoughItemsCore.getConfigHelper().getGiveCommandPrefix() + " " + MinecraftClient.getInstance().player.getEntityName() + " " +
+                    location.toString() + tagMessage + (cheatedStack.getAmount() != 1 ? " " + cheatedStack.getAmount() : "");
+            if (madeUpCommand.length() > 256)
+                madeUpCommand = RoughlyEnoughItemsCore.getConfigHelper().getGiveCommandPrefix() + " " + MinecraftClient.getInstance().player.getEntityName() + " " +
+                        location.toString() + (cheatedStack.getAmount() != 1 ? " " + cheatedStack.getAmount() : "");
+            MinecraftClient.getInstance().player.sendChatMessage(madeUpCommand);
             return true;
-        } catch (Exception e) {
-            return false;
         }
     }
     

+ 4 - 0
src/main/java/me/shedaniel/rei/client/ConfigHelper.java

@@ -91,6 +91,10 @@ public class ConfigHelper {
         config.enableCraftableOnlyButton = enableCraftableOnlyButton;
     }
     
+    public String getGiveCommandPrefix() {
+        return config.giveCommandPrefix;
+    }
+    
     public boolean sideSearchField() {
         return config.sideSearchField;
     }

+ 1 - 0
src/main/java/me/shedaniel/rei/client/REIConfig.java

@@ -15,5 +15,6 @@ public class REIConfig {
     public boolean isAscending = true;
     public boolean enableCraftableOnlyButton = true;
     public boolean sideSearchField = false;
+    public String giveCommandPrefix = "/give";
     
 }

+ 2 - 2
src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java

@@ -212,11 +212,11 @@ public class ItemListOverlay extends Drawable implements IWidget {
     public boolean mouseClicked(double double_1, double double_2, int int_1) {
         ClientPlayerEntity player = MinecraftClient.getInstance().player;
         if (rectangle.contains(double_1, double_2))
-            if (ClientHelper.isCheating() && !player.inventory.getCursorStack().isEmpty()) {
+            if (ClientHelper.isCheating() && !player.inventory.getCursorStack().isEmpty() && MinecraftClient.getInstance().isInSingleplayer()) {
                 ClientHelper.sendDeletePacket();
                 return true;
             }
-        if (!player.inventory.getCursorStack().isEmpty())
+        if (!player.inventory.getCursorStack().isEmpty() && MinecraftClient.getInstance().isInSingleplayer())
             return false;
         if (onMouseClick(int_1, double_1, double_2))
             return true;

+ 9 - 5
src/main/java/me/shedaniel/rei/gui/widget/RecipeViewingWidget.java

@@ -30,7 +30,7 @@ import java.util.Map;
 public class RecipeViewingWidget extends Gui {
     
     private static final Identifier CREATIVE_INVENTORY_TABS = new Identifier("textures/gui/container/creative_inventory/tabs.png");
-    private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
+    public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
     public final int guiWidth = 176;
     public final int guiHeight = 186;
     
@@ -272,10 +272,14 @@ public class RecipeViewingWidget extends Gui {
     @Override
     public void drawBackground() {
         drawBackground(0);
-        GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
-        GuiLighting.disable();
-        this.client.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
-        this.drawTexturedRect((int) bounds.getX(), (int) bounds.getY(), 0, 0, (int) bounds.getWidth(), (int) bounds.getHeight());
+        if (selectedCategory != null)
+            selectedCategory.drawCategoryBackground(bounds);
+        else {
+            GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
+            GuiLighting.disable();
+            this.client.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
+            this.drawTexturedRect((int) bounds.getX(), (int) bounds.getY(), 0, 0, (int) bounds.getWidth(), (int) bounds.getHeight());
+        }
     }
     
     public int getTotalPages(IRecipeCategory category) {

+ 2 - 2
src/main/resources/fabric.mod.json

@@ -2,7 +2,7 @@
   "id": "roughlyenoughitems",
   "name": "RoughlyEnoughItems",
   "description": "To allow players to view items and recipes.",
-  "version": "2.0.0.39",
+  "version": "${version}",
   "side": "client",
   "authors": [
     "Danielshe"
@@ -12,7 +12,7 @@
     "me.shedaniel.rei.client.ClientHelper"
   ],
   "requires": {
-    "fabric": "0.1.4.71"
+    "fabric": "0.1.4.76"
   },
   "mixins": {
     "client": "roughlyenoughitems.client.json"