Reorganise test mods into packages (#4706)

This commit is contained in:
Marvin Rösch authored and mezz committed 2018-03-27 22:09:10 -07:00
1 parent cfa3337884
commit 297a1eb766
119 files changed
+2577 -426

No files matched your search

@@ -0,0 +1,55 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.chat;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod(modid = "clientchateventtest", name = "Client Chat Event Test", version = "0.0.0", clientSideOnly = true)
public class ClientChatEventTest
{
static final boolean ENABLED = false;
@EventHandler
public void init(FMLInitializationEvent event)
{
if (ENABLED)
{
MinecraftForge.EVENT_BUS.register(this);
}
}
@SubscribeEvent
public void onPlayerAttemptChat(ClientChatEvent event)
{
if (event.getMessage().equals("Cancel"))
{
event.setCanceled(true);
}
else if (event.getMessage().equals("Replace this text"))
{
event.setMessage("Text replaced.");
}
}
}
@@ -0,0 +1,93 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.chat;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.registries.GameData;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Mod(modid = "clientcommandtest", name = "Client Command Test", version = "0.0.0", clientSideOnly = true)
public class ClientCommandTest
{
@EventHandler
public void init(FMLInitializationEvent event)
{
ClientCommandHandler.instance.registerCommand(new TestCommand());
}
private class TestCommand extends CommandBase
{
@Override
public String getName()
{
return "clientCommandTest";
}
@Override
public String getUsage(ICommandSender sender)
{
return "clientCommandTest <block>";
}
@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
{
return true;
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos)
{
if (args.length > 0)
{
return getListOfStringsMatchingLastWord(args, ForgeRegistries.BLOCKS.getKeys());
}
return Collections.emptyList();
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length > 0)
{
sender.sendMessage(new TextComponentString("Input: " + Arrays.toString(args)));
}
else
{
sender.sendMessage(new TextComponentString("No arguments."));
}
}
}
}
@@ -0,0 +1,152 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.chat;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.server.command.CommandTreeBase;
@Mod(modid = CommandTreeBaseTest.MOD_ID, name = "CommandTreeBaseTest", version = "1.0.0", acceptableRemoteVersions = "*")
public class CommandTreeBaseTest
{
public static final String MOD_ID = "command_tree_base_test";
@Mod.Instance(CommandTreeBaseTest.MOD_ID)
public static CommandTreeBaseTest inst;
@Mod.EventHandler
public void onServerStarted(FMLServerStartingEvent event)
{
event.registerServerCommand(new CommandTreeTest());
}
public static class CommandTreeTest extends CommandTreeBase
{
public CommandTreeTest()
{
addSubcommand(new CommandPing());
addSubcommand(new CommandValue());
}
@Override
public String getName()
{
return "treecommand_test";
}
@Override
public String getUsage(ICommandSender sender)
{
return "commands.treecommand_test.usage";
}
public static class CommandPing extends CommandBase
{
@Override
public String getName()
{
return "ping";
}
@Override
public String getUsage(ICommandSender sender)
{
return "commands.treecommand_test.ping.usage";
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
sender.sendMessage(new TextComponentString("Pong!"));
}
}
public static class CommandValue extends CommandTreeBase
{
private static int value = 0;
public CommandValue()
{
addSubcommand(new CommandSet());
addSubcommand(new CommandGet());
}
@Override
public String getName()
{
return "value";
}
@Override
public String getUsage(ICommandSender sender)
{
return "commands.treecommand_test.value.usage";
}
public static class CommandSet extends CommandBase
{
@Override
public String getName()
{
return "set";
}
@Override
public String getUsage(ICommandSender sender)
{
return "commands.treecommand_test.value.set.usage";
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
value = CommandTreeTest.parseInt(args[0]);
sender.sendMessage(new TextComponentString("Test value set to: " + value));
}
}
public static class CommandGet extends CommandBase
{
@Override
public String getName()
{
return "get";
}
@Override
public String getUsage(ICommandSender sender)
{
return "commands.treecommand_test.value.get.usage";
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
sender.sendMessage(new TextComponentString("Test value: " + value));
}
}
}
}
}
@@ -0,0 +1,99 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.chat;
import com.google.common.base.Predicate;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.IEntitySelectorFactory;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* You can verify that this test is working fine by following these steps.
* Spawn a few cows and a few sheep and then use "/kill @e[forge:min_health=!10]"
* All entities with less than 10 health points (current, not max) should die.
* This should include the sheep, but not the (healthy) cows.
*/
@Mod(modid = "customentityselectortest", name = "Custom Entity Selector Test", version = "1.0", acceptableRemoteVersions = "*")
public class EntitySelectorFactoryTest
{
@Mod.EventHandler
public void init(FMLInitializationEvent event)
{
GameRegistry.registerEntitySelector(new EntitySelectorFactory(), "forge:min_health");
}
private class EntitySelectorFactory implements IEntitySelectorFactory
{
@Nonnull
@Override
public List<Predicate<Entity>> createPredicates(Map<String, String> arguments, String mainSelector, ICommandSender sender, Vec3d position)
{
String health = arguments.get("forge:min_health");
//If our selector is used in this command create a Predicate otherwise return an empty list.
if (health != null)
{
final boolean invert = health.startsWith("!");
if (invert)
{
health = health.substring(1);
}
try
{
final int value = Integer.parseInt(health);
//Return a list of predicates. All these predicates have to apply for any entity to be selected.
return Collections.<Predicate<Entity>>singletonList(new Predicate<Entity>()
{
@Override
public boolean apply(@Nullable Entity input)
{
if (!(input instanceof EntityLivingBase))
{
return false;
}
return (((EntityLivingBase) input).getHealth() >= value) != invert;
}
});
}
catch (NumberFormatException e)
{
sender.sendMessage(new TextComponentString("Entity selector 'forge:min_health' has to be an integer"));
}
}
return Collections.emptyList();
}
}
}
@@ -0,0 +1,25 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraftforge.debug.chat;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;