Fixed executeCommand() function for scripting API on the server-side.

This commit is contained in:
luisc committed 2021-10-19 19:49:43 -05:00
1 parent 8b710ed520
commit 5515f5ef83
6 files changed
+25 -20

No files matched your search

@@ -7,6 +7,7 @@ import net.minecraft.inventory.Container;
import net.minecraft.item.Item;
import net.minecraft.stats.Achievement;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
import noppes.npcs.blocks.tiles.TileNpcContainer;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.containers.ContainerCarpentryBench;
@@ -30,8 +31,10 @@ import noppes.npcs.containers.ContainerNpcItemGiver;
import noppes.npcs.containers.ContainerNpcQuestReward;
import noppes.npcs.containers.ContainerNpcQuestTypeItem;
import noppes.npcs.controllers.PlayerData;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import cpw.mods.fml.common.network.IGuiHandler;
import noppes.npcs.scripted.interfaces.IWorld;
public class CommonProxy implements IGuiHandler {
@@ -148,6 +151,8 @@ public class CommonProxy implements IGuiHandler {
}
public FakePlayer getCommandPlayer(IWorld world) { return null; }
public boolean hasClient() {
return false;
}
@@ -221,23 +221,17 @@ public class NoppesUtilServer {
logic.func_145755_a(executer.worldObj);
}
public static String runCommand(final World world, final BlockPos pos, final String name, String command, EntityPlayer player, final ICommandSender executer) {
if (player != null) {
command = command.replace("@dp", player.getDisplayName());
}
public static void runCommand(World world, String name, String command) {
TileEntityCommandBlock tile = new TileEntityCommandBlock();
tile.setWorldObj(world);
tile.xCoord = MathHelper.floor_double(pos.getX());
tile.yCoord = MathHelper.floor_double(pos.getY());
tile.zCoord = MathHelper.floor_double(pos.getZ());
tile.setWorldObj(world.provider.worldObj);
tile.xCoord = 0;
tile.yCoord = 0;
tile.zCoord = 0;
CommandBlockLogic logic = tile.func_145993_a();
logic.func_145752_a(command);
logic.func_145754_b("@"+name);
logic.func_145755_a(world);
return logic.func_145749_h().getUnformattedText();
}
public static void consumeItemStack(int i, EntityPlayer player){
@@ -28,6 +28,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import noppes.npcs.CommonProxy;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
@@ -146,6 +147,7 @@ import noppes.npcs.containers.ContainerNpcQuestTypeItem;
import noppes.npcs.controllers.PlayerData;
import noppes.npcs.entity.*;
import noppes.npcs.scripted.interfaces.IWorld;
import org.lwjgl.input.Keyboard;
import tconstruct.client.tabs.InventoryTabFactions;
@@ -239,6 +241,10 @@ public class ClientProxy extends CommonProxy {
}
}
public FakePlayer getCommandPlayer(IWorld world) {
return (FakePlayer)(new EntityCustomNpc(world.getMCWorld())).getFakePlayer();
}
private void createFolders() {
File file = new File(CustomNpcs.Dir,"assets/customnpcs");
if(!file.exists())
@@ -105,8 +105,9 @@ import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
public abstract class EntityNPCInterface extends EntityCreature implements IEntityAdditionalSpawnData, ICommandSender, IRangedAttackMob, IBossDisplayData{
public ICustomNpc wrappedNPC;
private static final GameProfileAlt chateventProfile = new GameProfileAlt();
public static final GameProfileAlt chateventProfile = new GameProfileAlt();
public static FakePlayer chateventPlayer;
public static FakePlayer CommandPlayer;
public DataDisplay display;
public DataStats stats;
public DataAI ai;
@@ -131,8 +132,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
private int taskCount = 1;
public int lastInteract = 0;
public static FakePlayer CommandPlayer;
public Faction faction; //should only be used server side
private EntityAIRangedAttack aiRange;
@@ -10,6 +10,7 @@ import java.io.File;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.EventBus;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
@@ -19,6 +20,7 @@ import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import noppes.npcs.scripted.entity.ScriptPlayer;
import noppes.npcs.scripted.interfaces.*;
public abstract class NpcAPI {
@@ -80,7 +82,7 @@ public abstract class NpcAPI {
}
}
public abstract String executeCommand(IWorld var1, String var2);
public abstract void executeCommand(IWorld var1, String var2);
public abstract String getRandomName(int var1, int var2);
@@ -26,6 +26,7 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.client.EntityUtil;
import noppes.npcs.scripted.*;
import noppes.npcs.containers.ContainerNpcInterface;
import noppes.npcs.entity.EntityCustomNpc;
@@ -174,11 +175,9 @@ public class WrapperNpcAPI extends NpcAPI {
return new ScriptDamageSource(damagesource);
}
public String executeCommand(IWorld world, String command) {
FakePlayer player = new FakePlayer(world.getMCWorld(), new GameProfile(new UUID(0L,0L), "CommandPlayer"));
player.setWorld(world.getMCWorld());
player.setPosition(0.0D, 0.0D, 0.0D);
return NoppesUtilServer.runCommand(world.getMCWorld(), BlockPos.ORIGIN, "API", command, (EntityPlayer)null, player);
public void executeCommand(IWorld world, String command) {
//if(!world.getMCWorld().isRemote)
NoppesUtilServer.runCommand(world.getMCWorld(), "API", command);
}
public String getRandomName(int dictionary, int gender) {
return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender);