Command blocks now execute commands at the player
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.util.EnumHelper;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class BuilderExecute extends CommandBuilder
|
||||
{
|
||||
public void setMode1(EnumMode mode)
|
||||
{
|
||||
this.setNode(0, mode.toString());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public EnumMode getMode1()
|
||||
{
|
||||
return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class);
|
||||
}
|
||||
|
||||
public void setTarget(String target)
|
||||
{
|
||||
this.setNode(1, target);
|
||||
}
|
||||
|
||||
public String getTarget()
|
||||
{
|
||||
return this.getNodeAsString(1);
|
||||
}
|
||||
|
||||
public void setMode2(EnumMode mode)
|
||||
{
|
||||
this.setNode(2, mode.toString());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public EnumMode getMode2()
|
||||
{
|
||||
return EnumHelper.valueOf(this.getNodeAsString(2), EnumMode.class);
|
||||
}
|
||||
|
||||
public void setCommand(String command)
|
||||
{
|
||||
if(command != null && command.startsWith("/"))
|
||||
{
|
||||
this.setNode(3, command.substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setNode(3, command);
|
||||
}
|
||||
}
|
||||
|
||||
public String getCommand()
|
||||
{
|
||||
return this.getNodeAsString(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName()
|
||||
{
|
||||
return "execute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("modifier", ArgumentType.STRING);
|
||||
syntax.addRequired("targets", ArgumentType.STRING);
|
||||
syntax.addRequired("action", ArgumentType.STRING);
|
||||
syntax.addRequired("command", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static enum EnumMode
|
||||
{
|
||||
ALIGN,
|
||||
ANCHORED,
|
||||
AS,
|
||||
AT,
|
||||
IN,
|
||||
RUN;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import exopandora.worldhandler.builder.impl.BuilderExecute;
|
||||
import exopandora.worldhandler.builder.impl.BuilderExecute.EnumMode;
|
||||
import exopandora.worldhandler.builder.impl.BuilderFill;
|
||||
import exopandora.worldhandler.builder.impl.BuilderSetBlock;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
@@ -165,7 +167,14 @@ public class BlockHelper
|
||||
removeFill.setBlock1(new BlockResourceLocation(Blocks.AIR.getRegistryName()));
|
||||
|
||||
Minecraft.getInstance().player.sendChatMessage(placeFill.toActualCommand());
|
||||
Minecraft.getInstance().getConnection().sendPacket(new CUpdateCommandBlockPacket(pos, command, CommandBlockTileEntity.Mode.REDSTONE, true, false, true));
|
||||
|
||||
BuilderExecute wrapped = new BuilderExecute();
|
||||
wrapped.setMode1(EnumMode.AT);
|
||||
wrapped.setTarget(Minecraft.getInstance().player.getGameProfile().getName());
|
||||
wrapped.setMode2(EnumMode.RUN);
|
||||
wrapped.setCommand(command);
|
||||
|
||||
Minecraft.getInstance().getConnection().sendPacket(new CUpdateCommandBlockPacket(pos, wrapped.toActualCommand(), CommandBlockTileEntity.Mode.REDSTONE, true, false, true));
|
||||
Minecraft.getInstance().getConnection().sendPacket(new CUpdateCommandBlockPacket(pos.up(), removeFill.toActualCommand(), CommandBlockTileEntity.Mode.REDSTONE, true, false, true));
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user