Initial commit

This commit is contained in:
2024-06-02 19:56:48 +03:00
commit 3defa42b39
21 changed files with 1380 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
package com.lumijiez.cacheduper;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import java.util.UUID;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
public class CacheDupeCommand extends CommandBase {
@Override
public String getCommandName() {
return "cachedp";
}
@Override
public int getRequiredPermissionLevel() {
return 0;
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
return true;
}
@Override
public String getCommandUsage(ICommandSender sender) {
return "/cachedp <block_id> <number>";
}
@Override
public void processCommand(ICommandSender sender, String[] args) {
if (args.length != 2) {
sender.addChatMessage(new ChatComponentText("Invalid arguments. Usage: " + getCommandUsage(sender)));
return;
}
String itemId = args[0];
int number;
try {
number = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
sender.addChatMessage(new ChatComponentText("The number parameter must be an integer."));
return;
}
Utils utils = new Utils();
ItemStack stack = Utils.getItemStackFromId(itemId, number);
TileEntity checkTile = utils.tile();
try {
if (Class.forName("cofh.thermalexpansion.block.cache.TileCache").isInstance(checkTile)) {
Object packet = Class.forName("cofh.core.network.PacketTile").getConstructor(TileEntity.class).newInstance(checkTile);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addString", String.class).invoke(packet, "");
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addByte", byte.class).invoke(packet, (byte) 0);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addUUID", UUID.class).invoke(packet, UUID.randomUUID());
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addString", String.class).invoke(packet, "");
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addBool", boolean.class).invoke(packet, true);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addByte", byte.class).invoke(packet, (byte) 0);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addBool", boolean.class).invoke(packet, true);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addInt", int.class).invoke(packet, 0);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addByteArray", byte[].class).invoke(packet, new byte[6]);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addByte", byte.class).invoke(packet, (byte) 0);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addBool", boolean.class).invoke(packet, false);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addItemStack", ItemStack.class).invoke(packet, stack);
Class.forName("cofh.core.network.PacketCoFHBase").getMethod("addInt", int.class).invoke(packet, number);
Class.forName("cofh.core.network.PacketHandler").getMethod("sendToServer", Class.forName("cofh.core.network.PacketBase")).invoke(null, packet);
}
} catch(Exception ignored) {}
}
}

View File

@@ -0,0 +1,14 @@
package com.lumijiez.cacheduper;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
public class CacheDuper {
@Mod.EventHandler
public void onServerStarting(FMLServerStartingEvent event) {
event.registerServerCommand(new CacheDupeCommand());
}
}

View File

@@ -0,0 +1,12 @@
package com.lumijiez.cacheduper;
// Use this class for Strings only. Do not import any classes here. It will lead to issues with Mixins if in use!
public class Tags {
// GRADLETOKEN_* will be replaced by your configuration values at build time
public static final String MODID = "GRADLETOKEN_MODID";
public static final String MODNAME = "GRADLETOKEN_MODNAME";
public static final String VERSION = "GRADLETOKEN_VERSION";
public static final String GROUPNAME = "GRADLETOKEN_GROUPNAME";
}

View File

@@ -0,0 +1,62 @@
package com.lumijiez.cacheduper;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
public class Utils {
public Minecraft mc() {
return Minecraft.getMinecraft();
}
public int[] mop() {
MovingObjectPosition mop = mc().renderViewEntity.rayTrace(200, 1.0F);
Entity ent = pointedEntity();
return new int[] { mop.blockX, mop.blockY, mop.blockZ, mop.sideHit, (ent != null) ? ent.getEntityId() : -1 };
}
public static ItemStack getItemStackFromId(String itemId, int quantity) {
String[] parts = itemId.split(":");
if (parts.length != 2) {
System.out.println("Invalid item ID format. Expected modid:itemname");
return null;
}
String modId = parts[0];
String itemName = parts[1];
Item item = GameRegistry.findItem(modId, itemName);
if (item == null) {
System.out.println("Item not found: " + itemId);
return null;
}
return new ItemStack(item, quantity);
}
public WorldClient world() {
return mc().theWorld;
}
public TileEntity tile() {
return tile(mop());
}
public TileEntity tile(int[] mop) {
return tile(mop[0], mop[1], mop[2]);
}
public TileEntity tile(int x, int y, int z) {
return world().getTileEntity(x, y, z);
}
public Entity pointedEntity() {
return mc().objectMouseOver.entityHit;
}
}

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,16 @@
[
{
"modid": "${modId}",
"name": "${modName}",
"description": "An example mod for Minecraft 1.7.10 with Forge focussed on a stable setup.",
"version": "${modVersion}",
"mcversion": "${minecraftVersion}",
"url": "https://github.com/SinTh0r4s/MyMod",
"updateUrl": "",
"authorList": ["SinTho0r4s"],
"credits": "",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]