mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
Reorganise test mods into packages (#4706)
This commit is contained in:
1 parent
cfa3337884
commit
297a1eb766
119 files changed
+2577
-426
No files matched your search
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* 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.mod;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.village.Village;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.Capability.IStorage;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@Mod(modid = "forge.testcapmod", name = "Forge TestCapMod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class CapabilityTest
|
||||
{
|
||||
// A Holder/Marker for if this capability is installed.
|
||||
// MUST be Static final doesn't matter but is suggested to prevent
|
||||
// you from overriding it elsewhere.
|
||||
// As Annotations and generic's are erased/unload at runtime this
|
||||
// does NOT create a hard dependency on the class.
|
||||
@CapabilityInject(IExampleCapability.class)
|
||||
private static final Capability<IExampleCapability> TEST_CAP = null;
|
||||
|
||||
static final boolean ENABLED = false;
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preinit(FMLPreInitializationEvent evt)
|
||||
{
|
||||
logger = evt.getModLog();
|
||||
// If you are a API, provide register your capability ASAP.
|
||||
// You MUST supply a default save handler and a default implementation
|
||||
// If you are a CONSUMER of the capability DO NOT register it. Only APIs should.
|
||||
CapabilityManager.INSTANCE.register(IExampleCapability.class, new Storage(), DefaultImpl::new);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onInteract(PlayerInteractEvent.LeftClickBlock event)
|
||||
{
|
||||
if (!ENABLED || event.getItemStack().getItem() != Items.STICK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// This is just a example of how to interact with the TE, note the strong type binding that getCapability has
|
||||
TileEntity te = event.getWorld().getTileEntity(event.getPos());
|
||||
if (te != null && te.hasCapability(TEST_CAP, event.getFace()))
|
||||
{
|
||||
event.setCanceled(true);
|
||||
IExampleCapability inv = te.getCapability(TEST_CAP, event.getFace());
|
||||
logger.info("Hi I'm a {}", inv.getOwnerType());
|
||||
}
|
||||
if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.DIRT && event.getItemStack().hasCapability(TEST_CAP, null))
|
||||
{
|
||||
IExampleCapability cap = event.getItemStack().getCapability(TEST_CAP, null);
|
||||
event.getEntityPlayer().sendMessage(new TextComponentString((cap.getVal() ? TextFormatting.GREEN : TextFormatting.RED) + "" + TextFormatting.ITALIC + "TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST"));
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onInteractItem(PlayerInteractEvent.RightClickItem event)
|
||||
{
|
||||
if (!ENABLED || !event.getEntityPlayer().isSneaking())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getItemStack().hasCapability(TEST_CAP, null))
|
||||
{
|
||||
IExampleCapability cap = event.getItemStack().getCapability(TEST_CAP, null);
|
||||
cap.toggleVal();
|
||||
logger.info("Test value is now: {}", cap.getVal() ? "TRUE" : "FALSE");
|
||||
}
|
||||
}
|
||||
|
||||
// Example of having this annotation on a method, this will be called when the capability is present.
|
||||
// You could do something like register event handlers to attach these capabilities to objects, or
|
||||
// setup your factory, who knows. Just figured i'd give you the power.
|
||||
@CapabilityInject(IExampleCapability.class)
|
||||
private static void capRegistered(Capability<IExampleCapability> cap)
|
||||
{
|
||||
logger.info("IExampleCapability was registered wheeeeee!");
|
||||
}
|
||||
|
||||
// Having the Provider implement the cap is not recommended as this creates a hard dep on the cap interface.
|
||||
// And does not allow for sidedness.
|
||||
// But as this is a example and we do not care about that here we go.
|
||||
class Provider<V> implements ICapabilitySerializable<NBTTagCompound>, IExampleCapability
|
||||
{
|
||||
private V obj;
|
||||
private boolean value;
|
||||
|
||||
Provider(V obj)
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
return TEST_CAP != null && capability == TEST_CAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
if (TEST_CAP != null && capability == TEST_CAP)
|
||||
{
|
||||
return TEST_CAP.cast(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeNBT()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setBoolean("CapTestVal", this.value);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTTagCompound tag)
|
||||
{
|
||||
this.value = tag.getBoolean("CapTestVal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwnerType()
|
||||
{
|
||||
return obj.getClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVal()
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleVal()
|
||||
{
|
||||
this.value = !this.value;
|
||||
}
|
||||
}
|
||||
|
||||
// An example of how to attach a capability to an arbitrary Tile entity.
|
||||
// Note: Doing this IS NOT recommended for normal implementations.
|
||||
// If you control the TE it is HIGHLY recommend that you implement a fast
|
||||
// version of the has/getCapability functions yourself. So you have control
|
||||
// over everything yours being called first.
|
||||
@SubscribeEvent
|
||||
public void onTELoad(AttachCapabilitiesEvent<TileEntity> event)
|
||||
{
|
||||
//Attach it! The resource location MUST be unique it's recommended that you tag it with your modid and what the cap is.
|
||||
event.addCapability(new ResourceLocation("forge.testcapmod:dummy_cap"), new Provider<TileEntity>(event.getObject()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemLoad(AttachCapabilitiesEvent<ItemStack> event)
|
||||
{
|
||||
if (event.getObject().getItem() == Items.STICK)
|
||||
{
|
||||
event.addCapability(new ResourceLocation("forge.testcapmod:dummy_cap"), new Provider<ItemStack>(event.getObject()));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SubscribeEvent
|
||||
public void attachEvent(AttachCapabilitiesEvent event) //Test Raw type gets everything still.
|
||||
{
|
||||
System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void attachTileEntity(AttachCapabilitiesEvent<TileEntity> event)
|
||||
{
|
||||
if (!(event.getObject() instanceof TileEntity))
|
||||
{
|
||||
throw new IllegalArgumentException("Generic event handler failed! Expected Tile Entity got " + event.getObject());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void attachVillage(AttachCapabilitiesEvent<Village> event)
|
||||
{
|
||||
System.out.println(event.getObject());
|
||||
event.addCapability(new ResourceLocation("forge.testcapmod:dummy_cap"), new Provider(event.getObject()));
|
||||
}
|
||||
|
||||
//Detects if a player has entered the radius of a village
|
||||
@SubscribeEvent
|
||||
public void tick(TickEvent.WorldTickEvent event)
|
||||
{
|
||||
if (ENABLED && !event.world.isRemote)
|
||||
{
|
||||
List<EntityPlayer> players = event.world.playerEntities;
|
||||
int i = 0;
|
||||
for (Village village : event.world.villageCollection.getVillageList())
|
||||
{
|
||||
if (village.hasCapability(TEST_CAP, null))
|
||||
{
|
||||
boolean playerInRadius = false;
|
||||
for (EntityPlayer player : players)
|
||||
{
|
||||
if (new Vec3d(player.posX, 0, player.posZ).squareDistanceTo(new Vec3d(village.getCenter().getX(), 0, village.getCenter().getZ())) <= village.getVillageRadius() * village.getVillageRadius())
|
||||
{
|
||||
playerInRadius = playerInRadius || true;
|
||||
}
|
||||
}
|
||||
//If the test cap is true but no players are in radius
|
||||
if (village.getCapability(TEST_CAP, null).getVal() && !playerInRadius)
|
||||
{
|
||||
village.getCapability(TEST_CAP, null).toggleVal();
|
||||
for (EntityPlayer player : players)
|
||||
player.sendMessage(new TextComponentString(TextFormatting.RED + "All Players Have Exited Village " + i));
|
||||
}
|
||||
//If the test cap is false but there are players in radius
|
||||
else if (!village.getCapability(TEST_CAP, null).getVal() && playerInRadius)
|
||||
{
|
||||
village.getCapability(TEST_CAP, null).toggleVal();
|
||||
for (EntityPlayer player : players)
|
||||
player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Some Players Have Entered Village " + i));
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Capabilities SHOULD be interfaces, NOT concrete classes, this allows for
|
||||
// the most flexibility for the implementors.
|
||||
public interface IExampleCapability
|
||||
{
|
||||
String getOwnerType();
|
||||
|
||||
boolean getVal();
|
||||
|
||||
void toggleVal();
|
||||
}
|
||||
|
||||
// Storage implementations are required, tho there is some flexibility here.
|
||||
// If you are the API provider you can also say that in order to use the default storage
|
||||
// the consumer MUST use the default impl, to allow you to access innards.
|
||||
// This is just a contract you will have to stipulate in the documentation of your cap.
|
||||
public static class Storage implements IStorage<IExampleCapability>
|
||||
{
|
||||
@Override
|
||||
public NBTBase writeNBT(Capability<IExampleCapability> capability, IExampleCapability instance, EnumFacing side)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<IExampleCapability> capability, IExampleCapability instance, EnumFacing side, NBTBase nbt)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// You MUST also supply a default implementation.
|
||||
// This is to make life easier on consumers.
|
||||
public static class DefaultImpl implements IExampleCapability
|
||||
{
|
||||
@Override
|
||||
public String getOwnerType()
|
||||
{
|
||||
return "Default Implementation!";
|
||||
}
|
||||
|
||||
public boolean getVal()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleVal()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.mod;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.client.CustomModLoadingErrorDisplayException;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = "clientexceptiontest", version = "1.0", name = "Client Exception Test", clientSideOnly = true)
|
||||
public class ClientLoadingExceptionTest
|
||||
{
|
||||
|
||||
// Disabled so other test mods can still work.
|
||||
public static boolean ENABLE_PREINIT = false;
|
||||
public static boolean ENABLE_INIT = false;
|
||||
public static boolean ENABLE_LOAD_COMPLETE = false;
|
||||
public static boolean ENABLE_SERVER_STARTED = false;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onPreInit(FMLPreInitializationEvent e)
|
||||
{
|
||||
if (ENABLE_PREINIT)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
throwException("Thrown in Pre-Init");
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerItems(RegistryEvent<Item> itemRegistryEvent)
|
||||
{
|
||||
throw new RuntimeException("This should not be called because the mod threw an exception earlier in Pre-Init and is in a broken state.");
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onInit(FMLInitializationEvent e)
|
||||
{
|
||||
if (ENABLE_INIT)
|
||||
{
|
||||
throwException("Thrown in Init");
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onLoadComplete(FMLLoadCompleteEvent e)
|
||||
{
|
||||
if (ENABLE_LOAD_COMPLETE)
|
||||
{
|
||||
throwException("Thrown in load complete");
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStarted(FMLServerStartedEvent e)
|
||||
{
|
||||
if (ENABLE_SERVER_STARTED)
|
||||
{
|
||||
throw new RuntimeException("Server thread exception - should stop client");
|
||||
}
|
||||
}
|
||||
|
||||
private void throwException(String runtimeMessage)
|
||||
{
|
||||
throw new CustomModLoadingErrorDisplayException("Custom Test Exception", new RuntimeException(runtimeMessage))
|
||||
{
|
||||
@Override
|
||||
public void initGui(GuiErrorScreen parent, FontRenderer fontRenderer) {}
|
||||
|
||||
@Override
|
||||
public void drawScreen(GuiErrorScreen parent, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime)
|
||||
{
|
||||
parent.drawCenteredString(parent.mc.fontRenderer, "Custom Test Exception", parent.width / 2, 90, 16777215);
|
||||
parent.drawCenteredString(parent.mc.fontRenderer, runtimeMessage, parent.width / 2, 110, 16777215);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* 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.mod;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Config;
|
||||
import net.minecraftforge.common.config.Config.Comment;
|
||||
import net.minecraftforge.common.config.Config.LangKey;
|
||||
import net.minecraftforge.common.config.Config.Name;
|
||||
import net.minecraftforge.common.config.Config.RangeDouble;
|
||||
import net.minecraftforge.common.config.Config.RangeInt;
|
||||
import net.minecraftforge.common.config.Config.RequiresMcRestart;
|
||||
import net.minecraftforge.common.config.Config.Type;
|
||||
import net.minecraftforge.common.config.ConfigManager;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mod(modid = ConfigAnnotationTest.MODID, name = "ConfigTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class ConfigAnnotationTest
|
||||
{
|
||||
public static final String MODID = "config_test";
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
logger.debug("Old: {}", CONFIG_TYPES.bool);
|
||||
CONFIG_TYPES.bool = !CONFIG_TYPES.bool;
|
||||
logger.debug("New: {}", CONFIG_TYPES.bool);
|
||||
ConfigManager.sync(MODID, Type.INSTANCE);
|
||||
logger.debug("After sync: {}", CONFIG_TYPES.bool);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConfigChangedEvent(OnConfigChangedEvent event)
|
||||
{
|
||||
if (event.getModID().equals(MODID))
|
||||
{
|
||||
ConfigManager.sync(MODID, Type.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@LangKey("config_test.config.types")
|
||||
@Config(modid = MODID, type = Type.INSTANCE, name = MODID + "_types")
|
||||
public static class CONFIG_TYPES
|
||||
{
|
||||
public static boolean bool = false;
|
||||
public static boolean[] boolA = {false, true};
|
||||
public static Boolean Bool = false;
|
||||
public static Boolean[] BoolA = {false, true};
|
||||
public static float flt = 1.0f;
|
||||
public static float[] fltA = {1.0f, 2.0f};
|
||||
public static Float Flt = 1.0f;
|
||||
public static Float[] FltA = {1.0f, 2.0f};
|
||||
public static double dbl = 1.0d;
|
||||
public static double[] dblA = {1.0d, 2.0d};
|
||||
public static Double Dbl = 1.0D;
|
||||
public static Double[] DblA = {1.0D, 2.0D};
|
||||
public static byte byt = 1;
|
||||
public static byte[] bytA = {1, 2};
|
||||
public static Byte Byt = 1;
|
||||
public static Byte[] BytA = {1, 2};
|
||||
public static char chr = 'a';
|
||||
public static char[] chrA = {'a', 'b'};
|
||||
public static Character Chr = 'A';
|
||||
public static Character[] ChrA = {'A', 'B'};
|
||||
public static short srt = 1;
|
||||
public static short[] srtA = {1, 2};
|
||||
public static Short Srt = 1;
|
||||
public static Short[] SrtA = {1, 2};
|
||||
public static int int_ = 1;
|
||||
public static int[] intA = {1, 2};
|
||||
public static Integer Int = 1;
|
||||
public static Integer[] IntA = {1, 2};
|
||||
public static String Str = "STRING!";
|
||||
public static String[] StrA = {"STR", "ING!"};
|
||||
public static TEST enu = TEST.BIG;
|
||||
public static NestedType Inner = new NestedType();
|
||||
|
||||
public enum TEST { BIG, BAD, WOLF; }
|
||||
public static class NestedType
|
||||
{
|
||||
public String HeyLook = "I'm Inside!";
|
||||
}
|
||||
}
|
||||
|
||||
@LangKey("config_test.config.annotations")
|
||||
@Config(modid = MODID)
|
||||
public static class CONFIG_ANNOTATIONS
|
||||
{
|
||||
@RangeDouble(min = -10.5, max = 100.5)
|
||||
public static double DoubleRange = 10.0;
|
||||
|
||||
@RangeInt(min = -10, max = 100)
|
||||
public static double IntRange = 10;
|
||||
|
||||
@LangKey("this.is.not.a.good.key")
|
||||
@Comment({"This is a really long", "Multi-line comment"})
|
||||
public static String Comments = "Hi Tv!";
|
||||
|
||||
@Comment("Category Comment Test")
|
||||
public static NestedType Inner = new NestedType();
|
||||
|
||||
public static class NestedType
|
||||
{
|
||||
public String HeyLook = "Go in!";
|
||||
}
|
||||
}
|
||||
|
||||
@LangKey("config_test.config.subcats")
|
||||
@Config(modid = MODID, name = MODID + "_subcats", category = "")
|
||||
public static class CONFIG_SUBCATS
|
||||
{
|
||||
//public static String THIS_WILL_ERROR = "DUH";
|
||||
|
||||
@Name("test_a")
|
||||
public static SubCat sub1 = new SubCat("Hello");
|
||||
@Name("test_b")
|
||||
public static SubCat sub2 = new SubCat("Goodbye");
|
||||
@Name("test_c")
|
||||
public static SubCat2 sub3 = new SubCat2("Hi");
|
||||
|
||||
public static class SubCat
|
||||
{
|
||||
@Name("i_say")
|
||||
public String value;
|
||||
|
||||
public SubCat(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SubCat2
|
||||
{
|
||||
@Name("child_cat")
|
||||
public SubCat child;
|
||||
|
||||
public SubCat2(String value)
|
||||
{
|
||||
this.child = new SubCat(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@LangKey("config_test.config.maps")
|
||||
@Config(modid = MODID, name = MODID + "_map")
|
||||
public static class CONFIG_MAP
|
||||
{
|
||||
@Name("map")
|
||||
@Comment("This comment belongs to the \"map\" category, not the \"general\" category")
|
||||
@RequiresMcRestart
|
||||
public static Map<String, Integer[]> theMap;
|
||||
|
||||
@Name("regex(test]")
|
||||
public static Map<String, String> regexText = new HashMap<>();
|
||||
|
||||
static
|
||||
{
|
||||
theMap = Maps.newHashMap();
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
Integer[] array = new Integer[6];
|
||||
for (int x = 0; x < array.length; x++)
|
||||
{
|
||||
array[x] = i + x;
|
||||
}
|
||||
theMap.put("" + i, array);
|
||||
regexText.put("" + i, "" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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.mod;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.RegistryBuilder;
|
||||
|
||||
@Mod(modid = ObjectHolderAnnotationTest.MODID, name = "ObjectHolderTests", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class ObjectHolderAnnotationTest
|
||||
{
|
||||
public static final String MODID = "objectholdertest";
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
//verifies @ObjectHolder with custom id
|
||||
assert VanillaObjectHolder.uiButtonClick != null;
|
||||
//verifies modded items work
|
||||
assert ForgeObjectHolder.forge_potion != null;
|
||||
//verifies minecraft:air is now resolvable
|
||||
assert VanillaObjectHolder.air != null;
|
||||
//verifies unexpected name should not have defaulted to AIR.
|
||||
assert VanillaObjectHolder.nonExistentBlock == null;
|
||||
//verifies custom registries
|
||||
assert CustomRegistryObjectHolder.custom_entry != null;
|
||||
//verifies interfaces are supported
|
||||
assert CustomRegistryObjectHolder.custom_entry_by_interface != null;
|
||||
|
||||
}
|
||||
|
||||
protected static class PotionForge extends Potion
|
||||
{
|
||||
protected PotionForge(ResourceLocation location, boolean badEffect, int potionColor)
|
||||
{
|
||||
super(badEffect, potionColor);
|
||||
setPotionName("potion." + location.getResourcePath());
|
||||
setRegistryName(location);
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MODID)
|
||||
public static class Registration
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void newRegistry(RegistryEvent.NewRegistry event)
|
||||
{
|
||||
new RegistryBuilder<ICustomRegistryEntry>()
|
||||
.setType(ICustomRegistryEntry.class)
|
||||
.setName(new ResourceLocation("object_holder_test_custom_registry"))
|
||||
.setIDRange(0, 255)
|
||||
.create();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerPotions(RegistryEvent.Register<Potion> event)
|
||||
{
|
||||
event.getRegistry().register(
|
||||
new ObjectHolderAnnotationTest.PotionForge(new ResourceLocation(ObjectHolderAnnotationTest.MODID, "forge_potion"), false, 0xff00ff) // test automatic id distribution
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerInterfaceRegistryForge(RegistryEvent.Register<ICustomRegistryEntry> event)
|
||||
{
|
||||
event.getRegistry().register(
|
||||
new CustomRegistryEntry().setRegistryName(new ResourceLocation(MODID, "custom_entry_by_interface"))
|
||||
);
|
||||
|
||||
event.getRegistry().register(
|
||||
new CustomRegistryEntry().setRegistryName(new ResourceLocation(MODID, "custom_entry"))
|
||||
);
|
||||
}
|
||||
}
|
||||
interface ICustomRegistryEntry extends IForgeRegistryEntry<ICustomRegistryEntry>{}
|
||||
|
||||
|
||||
static class CustomRegistryEntry implements ICustomRegistryEntry
|
||||
{
|
||||
private ResourceLocation name;
|
||||
|
||||
@Override
|
||||
public ICustomRegistryEntry setRegistryName(ResourceLocation name)
|
||||
{
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getRegistryName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ICustomRegistryEntry> getRegistryType()
|
||||
{
|
||||
return ICustomRegistryEntry.class;
|
||||
}
|
||||
}
|
||||
|
||||
@GameRegistry.ObjectHolder("minecraft")
|
||||
static class VanillaObjectHolder
|
||||
{
|
||||
//Tests importing vanilla objects that need the @ObjectHolder annotation to get a valid ResourceLocation
|
||||
@GameRegistry.ObjectHolder("ui.button.click")
|
||||
public static final SoundEvent uiButtonClick = null;
|
||||
public static final Block air = null;
|
||||
public static final Block nonExistentBlock = null;
|
||||
}
|
||||
|
||||
@GameRegistry.ObjectHolder(ObjectHolderAnnotationTest.MODID)
|
||||
static class ForgeObjectHolder
|
||||
{
|
||||
//Tests using subclasses for injections
|
||||
public static final ObjectHolderAnnotationTest.PotionForge forge_potion = null;
|
||||
}
|
||||
|
||||
@GameRegistry.ObjectHolder(ObjectHolderAnnotationTest.MODID)
|
||||
static class CustomRegistryObjectHolder
|
||||
{
|
||||
//Tests whether custom registries can be used
|
||||
public static final ICustomRegistryEntry custom_entry = null;
|
||||
|
||||
//Tests whether interfaces can be used
|
||||
public static final ICustomRegistryEntry custom_entry_by_interface = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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.mod;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraftforge.server.permission.DefaultPermissionLevel;
|
||||
import net.minecraftforge.server.permission.PermissionAPI;
|
||||
import net.minecraftforge.server.permission.context.BlockPosContext;
|
||||
import net.minecraftforge.server.permission.context.ContextKey;
|
||||
|
||||
@Mod(modid = PermissionTest.MOD_ID, name = "PermissionTest", version = "1.0.0", acceptableRemoteVersions = "*")
|
||||
public class PermissionTest
|
||||
{
|
||||
public static final String MOD_ID = "permission_test";
|
||||
|
||||
@Mod.Instance(PermissionTest.MOD_ID)
|
||||
public static PermissionTest inst;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onInit(FMLInitializationEvent event)
|
||||
{
|
||||
Permissions.init();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStarted(FMLServerStartingEvent event)
|
||||
{
|
||||
event.registerServerCommand(new CommandPermissionTest());
|
||||
}
|
||||
|
||||
public static class Permissions
|
||||
{
|
||||
public static final String CLAIM_CHUNK = "testmod.chunk.claim";
|
||||
public static final String UNCLAIM_CHUNK = "testmod.chunk.unclaim";
|
||||
public static final String SET_BLOCK = "testmod.block.set";
|
||||
public static final String READ_TILE = "testmod.tileentity.read";
|
||||
|
||||
public static void init()
|
||||
{
|
||||
PermissionAPI.registerNode(CLAIM_CHUNK, DefaultPermissionLevel.ALL, "Node for claiming chunks");
|
||||
PermissionAPI.registerNode(UNCLAIM_CHUNK, DefaultPermissionLevel.ALL, "Node for unclaiming chunks");
|
||||
PermissionAPI.registerNode(SET_BLOCK, DefaultPermissionLevel.OP, "Node for setting blocks with a command");
|
||||
PermissionAPI.registerNode(READ_TILE, DefaultPermissionLevel.NONE, "Node for reading and printing TileEntity data");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ContextKeys
|
||||
{
|
||||
public static final ContextKey<TileEntity> TILE_ENTITY = ContextKey.create("tile_entity", TileEntity.class);
|
||||
}
|
||||
|
||||
public static class CommandPermissionTest extends CommandBase
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "permission_test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "commands.permission_test.usage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
sender.sendMessage(new TextComponentString("claim, unclaim, setblock, read_tile"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Example using BlockPosContext with ChunkPos and permission available to players by default
|
||||
boolean b = args[0].equals("claim");
|
||||
if (b || args[0].equals("unclaim"))
|
||||
{
|
||||
ChunkPos chunkPos = new ChunkPos(parseInt(args[1]), parseInt(args[2]));
|
||||
|
||||
if (PermissionAPI.hasPermission(player.getGameProfile(), b ? Permissions.CLAIM_CHUNK : Permissions.UNCLAIM_CHUNK, new BlockPosContext(player, chunkPos)))
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
//claim chunk
|
||||
sender.sendMessage(new TextComponentString("Chunk claimed!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
//unclaim chunk
|
||||
sender.sendMessage(new TextComponentString("Chunk unclaimed!"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.generic.permission");
|
||||
}
|
||||
}
|
||||
//Example using BlockPosContext and permission available to only OPs by default
|
||||
else if (args[0].equals("setblock"))
|
||||
{
|
||||
if (args.length < 5)
|
||||
{
|
||||
throw new WrongUsageException("commands.setblock.usage");
|
||||
}
|
||||
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 1, false);
|
||||
Block block = CommandBase.getBlockByText(sender, args[4]);
|
||||
int i = 0;
|
||||
|
||||
if (args.length >= 6)
|
||||
{
|
||||
i = parseInt(args[5], 0, 15);
|
||||
}
|
||||
|
||||
if (!player.world.isBlockLoaded(blockpos))
|
||||
{
|
||||
throw new CommandException("commands.setblock.outOfWorld");
|
||||
}
|
||||
else
|
||||
{
|
||||
IBlockState state = block.getStateFromMeta(i);
|
||||
|
||||
if (!PermissionAPI.hasPermission(player.getGameProfile(), Permissions.SET_BLOCK, new BlockPosContext(player, blockpos, state, null)))
|
||||
{
|
||||
throw new CommandException("commands.generic.permission");
|
||||
}
|
||||
else if (!player.world.setBlockState(blockpos, state, 2))
|
||||
{
|
||||
throw new CommandException("commands.setblock.noChange");
|
||||
}
|
||||
}
|
||||
}
|
||||
//Example using custom ContextKey and permission available to only OPs by default
|
||||
else if (args[0].equals("read_tile"))
|
||||
{
|
||||
BlockPos blockpos = parseBlockPos(sender, args, 1, false);
|
||||
TileEntity tileEntity = player.world.getTileEntity(blockpos);
|
||||
|
||||
if (PermissionAPI.hasPermission(player.getGameProfile(), Permissions.READ_TILE, new BlockPosContext(player, blockpos, null, null).set(ContextKeys.TILE_ENTITY, tileEntity)))
|
||||
{
|
||||
NBTTagCompound tag = tileEntity == null ? null : tileEntity.serializeNBT();
|
||||
sender.sendMessage(new TextComponentString(String.valueOf(tag)));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.generic.permission");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CommandException("commands.generic.permission");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.mod;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = RegistryOverrideTest.MODID, name = "Registry override test mod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod.EventBusSubscriber
|
||||
public class RegistryOverrideTest
|
||||
{
|
||||
public static final String MODID = "registry_override_test";
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
event.getRegistry().register(new BlockReplacement());
|
||||
}
|
||||
}
|
||||
|
||||
private static class BlockReplacement extends Block
|
||||
{
|
||||
AxisAlignedBB BB = FULL_BLOCK_AABB.contract(0.1, 0, 0.1);
|
||||
|
||||
private BlockReplacement()
|
||||
{
|
||||
super(Material.ROCK);
|
||||
setRegistryName("minecraft", "bookshelf");
|
||||
this.setHardness(1.5F);
|
||||
this.setSoundType(SoundType.STONE).setUnlocalizedName("bookshelf");
|
||||
this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "BlockReplacement{" + this.getRegistryName() + "}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (hand == EnumHand.MAIN_HAND)
|
||||
{
|
||||
playerIn.sendMessage(new TextComponentString(worldIn.isRemote ? "Client" : "Server"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.mod;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
Reference in new issue
Block a user