mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Clean up formatting of Forge Test mods and disable noisy ones (#3908)
This commit is contained in:
1 parent
4ea73399de
commit
e6dcfde214
75 files changed
+1378
-820
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.entity.passive.EntityWolf;
|
||||
import net.minecraftforge.event.entity.living.AnimalTameEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = AnimalTameEventTest.MOD_ID, name = "AnimalTameEvent test mod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod.EventBusSubscriber
|
||||
public class AnimalTameEventTest
|
||||
{
|
||||
static final String MOD_ID = "animal_tame_event_test";
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onAnimalTame(AnimalTameEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAnimal() instanceof EntityWolf)
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.pathfinding.PathNodeType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = "ainodetypetest", name = "AiNodeTypeTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod.EventBusSubscriber
|
||||
public class BlockAiNodeTypeTest
|
||||
{
|
||||
public static final boolean ENABLED = false;
|
||||
private static final Block TEST_BLOCK = new TestBlock();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
event.getRegistry().register(TEST_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TestBlock extends Block
|
||||
{
|
||||
|
||||
TestBlock()
|
||||
{
|
||||
super(Material.ROCK);
|
||||
setRegistryName("testblock");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathNodeType getAiPathNodeType(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
return PathNodeType.DOOR_OPEN;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = BlockPlaceEventTest.MOD_ID, name = "BlockPlaceEvent test mod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod.EventBusSubscriber
|
||||
public class BlockPlaceEventTest
|
||||
{
|
||||
static final String MOD_ID = "block_place_event_test";
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockPlaced(BlockEvent.PlaceEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getPlacedBlock().getBlock() == Blocks.CHEST
|
||||
&& event.getPlacedAgainst().getBlock() != Blocks.DIAMOND_BLOCK)
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = BonemealEventTest.MODID, version = "1.0")
|
||||
@Mod(modid = BonemealEventTest.MODID, name = "Bonemeal Event Test", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class BonemealEventTest
|
||||
{
|
||||
public static final String MODID = "bonemealeventtest";
|
||||
|
||||
@@ -10,15 +10,17 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
@Mod(modid = BreedingTest.MODID, name = "BreedingTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class BreedingTest
|
||||
{
|
||||
public static final String MODID = "breedingtest";
|
||||
public static final String MODID = "breedingtest";
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBabyBorn(BabyEntitySpawnEvent event) {
|
||||
event.setChild(new EntityCow(event.getParentA().world));
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onBabyBorn(BabyEntitySpawnEvent event)
|
||||
{
|
||||
event.setChild(new EntityCow(event.getParentA().world));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.brewing.BrewingRecipeRegistry;
|
||||
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.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = "brewingreciperegistrytest", name = "BrewingRecipeRegistryTest", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class BrewingRecipeRegistryTest
|
||||
{
|
||||
public static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (!ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// The following adds a recipe that brews a piece of rotten flesh "into" a diamond sword resulting in a diamond hoe
|
||||
BrewingRecipeRegistry.addRecipe(new ItemStack(Items.DIAMOND_SWORD), new ItemStack(Items.ROTTEN_FLESH), new ItemStack(Items.DIAMOND_HOE));
|
||||
|
||||
ItemStack output0 = BrewingRecipeRegistry.getOutput(new ItemStack(Items.DIAMOND_SWORD), new ItemStack(Items.ROTTEN_FLESH));
|
||||
if (output0.getItem() == Items.DIAMOND_HOE)
|
||||
{
|
||||
logger.info("Recipe successfully registered and working. Diamond Hoe obtained.");
|
||||
}
|
||||
|
||||
// Testing if OreDictionary support is working. Register a recipe that brews a gemDiamond into a gold sword resulting in a diamond sword
|
||||
BrewingRecipeRegistry.addRecipe(new ItemStack(Items.GOLDEN_SWORD), "gemDiamond", new ItemStack(Items.DIAMOND_SWORD));
|
||||
|
||||
ItemStack output1 = BrewingRecipeRegistry.getOutput(new ItemStack(Items.GOLDEN_SWORD), new ItemStack(Items.DIAMOND));
|
||||
if (output1.getItem() == Items.DIAMOND_SWORD)
|
||||
{
|
||||
logger.info("Recipe successfully registered and working. Diamond Sword obtained.");
|
||||
}
|
||||
|
||||
// In vanilla, brewing netherwart into a water bottle results in an awkward potion (with metadata 16). The following tests if that still happens
|
||||
ItemStack output2 = BrewingRecipeRegistry.getOutput(new ItemStack(Items.POTIONITEM, 1, 0), new ItemStack(Items.NETHER_WART));
|
||||
if (output2 != null && output2.getItem() == Items.POTIONITEM && output2.getItemDamage() == 16)
|
||||
{
|
||||
logger.info("Vanilla behaviour still in place. Brewed Water Bottle with Nether Wart and got Awkward Potion");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.init.Enchantments;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
@Mod(modid = "canapplyatenchantingtabletest", name = "CanApplyAtEnchantingTableTest", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class CanApplyAtEnchantingTableTest
|
||||
{
|
||||
public static final boolean ENABLE = false;
|
||||
|
||||
public static final Item testItem = new Item()
|
||||
{
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment)
|
||||
{
|
||||
return super.canApplyAtEnchantingTable(stack, enchantment) || enchantment == Enchantments.FORTUNE;
|
||||
}
|
||||
};
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
GameRegistry.register(testItem.setRegistryName("test_item").setUnlocalizedName("FortuneEnchantableOnly").setMaxStackSize(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
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,73 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
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.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, GameData.getBlockRegistry().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,133 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +1,51 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
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.common.config.Config.*;
|
||||
import net.minecraftforge.fml.client.IModGuiFactory;
|
||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||
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.Map;
|
||||
|
||||
@Mod(modid = ConfigTest.MODID, name = "ConfigTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class ConfigTest
|
||||
{
|
||||
public static final String MODID = "config_test";
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
System.out.println("Old: " + CONFIG_TYPES.bool);
|
||||
CONFIG_TYPES.bool = !CONFIG_TYPES.bool;
|
||||
System.out.println("New: " + CONFIG_TYPES.bool);
|
||||
ConfigManager.sync(MODID, Type.INSTANCE);
|
||||
System.out.println("After sync: " + CONFIG_TYPES.bool);
|
||||
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) {
|
||||
public void onConfigChangedEvent(OnConfigChangedEvent event)
|
||||
{
|
||||
if (event.getModID().equals(MODID))
|
||||
{
|
||||
ConfigManager.sync(MODID, Type.INSTANCE);
|
||||
@@ -91,6 +95,7 @@ public class ConfigTest
|
||||
public String HeyLook = "I'm Inside!";
|
||||
}
|
||||
}
|
||||
|
||||
@LangKey("config_test.config.annotations")
|
||||
@Config(modid = MODID)
|
||||
public static class CONFIG_ANNOTATIONS
|
||||
@@ -113,6 +118,7 @@ public class ConfigTest
|
||||
public String HeyLook = "Go in!";
|
||||
}
|
||||
}
|
||||
|
||||
@LangKey("config_test.config.subcats")
|
||||
@Config(modid = MODID, name = MODID + "_subcats", category = "")
|
||||
public static class CONFIG_SUBCATS
|
||||
@@ -128,6 +134,7 @@ public class ConfigTest
|
||||
{
|
||||
@Name("i_say")
|
||||
public String value;
|
||||
|
||||
public SubCat(String value)
|
||||
{
|
||||
this.value = value;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = "createfluidsourcetest", name = "CreateFluidSourceTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class CreateFluidSourceTest
|
||||
{
|
||||
public static final boolean ENABLE = false;
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(CreateFluidSourceTest.class);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onCreateFluidSource(CreateFluidSourceEvent event)
|
||||
{
|
||||
// make it work exactly the opposite of how it works by default
|
||||
if (event.getState().getBlock() == Blocks.FLOWING_WATER)
|
||||
{
|
||||
event.setResult(Result.DENY);
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setResult(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
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 CustomEntitySelectorTest
|
||||
{
|
||||
|
||||
@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,41 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = CustomSpawnDimensionTest.MODID, name = "CustomSpawnDimensionTest", version = "0.1", acceptableRemoteVersions = "*")
|
||||
public class CustomSpawnDimensionTest
|
||||
{
|
||||
public static final String MODID = "customspawndimensiontest";
|
||||
|
||||
private static final boolean ENABLE = false;
|
||||
|
||||
public CustomSpawnDimensionTest()
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void enterDimension(EntityJoinWorldEvent event)
|
||||
{
|
||||
Entity e = event.getEntity();
|
||||
if (!(e instanceof EntityPlayer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BlockPos pos = e.getPosition();
|
||||
int dim = e.dimension;
|
||||
|
||||
((EntityPlayer) e).setSpawnDimension(dim);
|
||||
((EntityPlayer) e).setSpawnChunk(pos, true, dim);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
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.registry.GameRegistry;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Test for {@link TextureStitchEvent.Pre}.
|
||||
*/
|
||||
@Mod(modid = CustomSpriteTest.MOD_ID, name = CustomSpriteTest.NAME, version = "1.0", clientSideOnly = true)
|
||||
public class CustomSpriteTest
|
||||
{
|
||||
static final String MOD_ID = "custom_sprite_test";
|
||||
static final String NAME = "Custom sprite test";
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
Block block = new Block(Material.WOOD).setRegistryName(MOD_ID, "custom_sprite_block").setCreativeTab(CreativeTabs.MISC);
|
||||
GameRegistry.register(block);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void textureStitch(TextureStitchEvent.Pre event)
|
||||
{
|
||||
DelegateSprite bottom = DelegateSprite.make("bottom", new ResourceLocation("textures/blocks/diamond_block.png"));
|
||||
DelegateSprite top = DelegateSprite.make("top", new ResourceLocation("textures/blocks/tnt_side.png"));
|
||||
|
||||
TextureMap textureMap = event.getMap();
|
||||
textureMap.setTextureEntry(bottom);
|
||||
textureMap.setTextureEntry(top);
|
||||
}
|
||||
|
||||
static final class DelegateSprite extends TextureAtlasSprite
|
||||
{
|
||||
final ResourceLocation delegate;
|
||||
|
||||
private DelegateSprite(ResourceLocation loc, ResourceLocation delegate)
|
||||
{
|
||||
super(loc.toString());
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
static DelegateSprite make(String name, ResourceLocation delegate)
|
||||
{
|
||||
return new DelegateSprite(new ResourceLocation(MOD_ID, name), delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomLoader(@Nonnull IResourceManager manager, @Nonnull ResourceLocation location)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean load(@Nonnull IResourceManager manager, @Nonnull ResourceLocation location)
|
||||
{
|
||||
BufferedImage image;
|
||||
try
|
||||
{
|
||||
IResource resource = manager.getResource(delegate);
|
||||
image = ImageIO.read(resource.getInputStream());
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
logger.error("Could not find resource", ioe);
|
||||
return true;
|
||||
}
|
||||
this.width = image.getWidth();
|
||||
this.height = image.getHeight();
|
||||
int[][] pixels = new int[Minecraft.getMinecraft().gameSettings.mipmapLevels + 1][];
|
||||
pixels[0] = new int[image.getWidth() * image.getHeight()];
|
||||
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels[0], 0, image.getWidth());
|
||||
this.clearFramesTextureData();
|
||||
this.framesTextureData.add(pixels);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@ public class DecorateEventDebug
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
MinecraftForge.TERRAIN_GEN_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.DifficultyChangeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = "difficultychangeeventtest", name = "DifficultyChangeEventTest", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class DifficultyChangeEventTest
|
||||
{
|
||||
private static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDifficultyChange(DifficultyChangeEvent event)
|
||||
{
|
||||
logger.info("Difficulty changed from " + event.getOldDifficulty() + " to " + event.getDifficulty());
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,13 @@ import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
@@ -57,6 +56,7 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -71,6 +71,7 @@ public class DynBucketTest
|
||||
private static final ResourceLocation testItemName = new ResourceLocation(MODID, "testitem");
|
||||
|
||||
private static final boolean ENABLE = true;
|
||||
private static Logger logger;
|
||||
|
||||
static
|
||||
{
|
||||
@@ -101,7 +102,9 @@ public class DynBucketTest
|
||||
void setupModels()
|
||||
{
|
||||
if (!ENABLE || !ModelFluidDebug.ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ModelLoader.setBucketModelDefinition(dynBucket);
|
||||
|
||||
@@ -125,8 +128,11 @@ public class DynBucketTest
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (!ENABLE || !ModelFluidDebug.ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger = event.getModLog();
|
||||
GameRegistry.register(new TestItem(), testItemName);
|
||||
Block tank = new BlockSimpleTank();
|
||||
GameRegistry.register(tank, simpleTankName);
|
||||
@@ -173,13 +179,16 @@ public class DynBucketTest
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestItem extends Item {
|
||||
public static class TestItem extends Item
|
||||
{
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand)
|
||||
{
|
||||
ItemStack itemStackIn = playerIn.getHeldItem(hand);
|
||||
if(worldIn.isRemote)
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn);
|
||||
}
|
||||
|
||||
ItemStackHandler handler = new ItemStackHandler(5);
|
||||
ItemStackHandler handler2 = new ItemStackHandler(5);
|
||||
@@ -197,16 +206,19 @@ public class DynBucketTest
|
||||
handler2.setStackInSlot(3, new ItemStack(Blocks.LOG));
|
||||
handler2.setStackInSlot(4, new ItemStack(Blocks.DIAMOND_BLOCK));
|
||||
|
||||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
System.out.println("Expected 1: " + handler.getStackInSlot(i));
|
||||
for (int i = 0; i < handler.getSlots(); i++)
|
||||
{
|
||||
logger.info("Expected 1: " + handler.getStackInSlot(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < handler2.getSlots(); i++) {
|
||||
System.out.println("Expected 2: " + handler2.getStackInSlot(i));
|
||||
for (int i = 0; i < handler2.getSlots(); i++)
|
||||
{
|
||||
logger.info("Expected 2: " + handler2.getStackInSlot(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < joined.getSlots(); i++) {
|
||||
System.out.println("Joined: " + joined.getStackInSlot(i));
|
||||
for (int i = 0; i < joined.getSlots(); i++)
|
||||
{
|
||||
logger.info("Joined: " + joined.getStackInSlot(i));
|
||||
}
|
||||
|
||||
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
|
||||
@@ -230,7 +242,9 @@ public class DynBucketTest
|
||||
{
|
||||
ItemStack bucket = new ItemStack(this, 1, i);
|
||||
if (FluidUtil.getFluidContained(bucket) != null)
|
||||
{
|
||||
subItems.add(bucket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,7 +283,8 @@ public class DynBucketTest
|
||||
{
|
||||
ItemStack heldItem = playerIn.getHeldItem(hand);
|
||||
IFluidHandler tank = FluidUtil.getFluidHandler(worldIn, pos, side.getOpposite());
|
||||
if (tank == null) {
|
||||
if (tank == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -302,7 +317,8 @@ public class DynBucketTest
|
||||
if (tankProperties.length > 0 && tankProperties[0] != null && tankProperties[0].getContents() != null)
|
||||
{
|
||||
text = tankProperties[0].getContents().amount + "x " + tankProperties[0].getContents().getLocalizedName();
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
text = "empty";
|
||||
}
|
||||
@@ -331,14 +347,16 @@ public class DynBucketTest
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPacketUpdateTileEntity getUpdatePacket() {
|
||||
public SPacketUpdateTileEntity getUpdatePacket()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag = writeToNBT(tag);
|
||||
return new SPacketUpdateTileEntity(this.getPos(), this.getBlockMetadata(), tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
|
||||
{
|
||||
super.onDataPacket(net, pkt);
|
||||
readFromNBT(pkt.getNbtCompound());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = "enchantmentlevelsettest", name = "EnchantmentLevelSetTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class EnchantmentLevelSetTest
|
||||
{
|
||||
public static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
logger.info("Wiring up enchantment level set test");
|
||||
MinecraftForge.EVENT_BUS.register(EnchantmentLevelSetTest.class);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onEnchantmentLevelSet(EnchantmentLevelSetEvent event)
|
||||
{
|
||||
// invert enchantment level, just for fun
|
||||
logger.info("Enchantment row: " + event.getEnchantRow() + ", level: " + event.getLevel());
|
||||
event.setLevel(30 - event.getLevel());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = "entitytraveltodimensioneventtest", name = "EntityTravelToDimensionEventTest", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class EntityTravelToDimensionEventTest
|
||||
{
|
||||
public static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDimensionTravel(EntityTravelToDimensionEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger.info("Travelling to Dimension " + event.getDimension() + " Entity: " + event.getEntity());
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
|
||||
@Mod(modid = "entityupdateblockedtest", name = "Entity Update Blocked Test", version = "1.0.0", acceptableRemoteVersions = "*")
|
||||
public class EntityUpdateBlockedTest
|
||||
{
|
||||
@Mod.EventHandler
|
||||
public void init(FMLServerStartingEvent event)
|
||||
{
|
||||
event.registerServerCommand(new BlockEntityUpdateCommand());
|
||||
}
|
||||
|
||||
private class BlockEntityUpdateCommand extends CommandBase
|
||||
{
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "blockEntityUpdate";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
return "blockEntityUpdate <value>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
boolean value = Boolean.parseBoolean(args[0]);
|
||||
for (Entity ent : sender.getEntityWorld().loadedEntityList)
|
||||
{
|
||||
if (!(ent instanceof EntityPlayer))
|
||||
{
|
||||
ent.updateBlocked = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,19 @@ import net.minecraftforge.common.BiomeManager.BiomeType;
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
@Mod(modid = "enumplanttypetest", name = "EnumPlantTypeTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class EnumPlantTypeTest
|
||||
{
|
||||
private static Logger LOGGER = LogManager.getLogger();
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onPreInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onInit(FMLInitializationEvent event)
|
||||
@@ -22,28 +28,30 @@ public class EnumPlantTypeTest
|
||||
}
|
||||
catch (NullPointerException npe)
|
||||
{
|
||||
LOGGER.warn("EnumHelper in BiomeType is working incorrectly!", npe);
|
||||
logger.warn("EnumHelper in BiomeType is working incorrectly!", npe);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (biomeType == null || !biomeType.name().equals("FAKE"))
|
||||
LOGGER.warn("EnumHelper in BiomeType is working incorrectly!");
|
||||
{
|
||||
logger.warn("EnumHelper in BiomeType is working incorrectly!");
|
||||
}
|
||||
}
|
||||
EnumPlantType plantType = null;
|
||||
if (plantType == null || !plantType.name().equals("FAKE"))
|
||||
;
|
||||
try
|
||||
{
|
||||
plantType = EnumPlantType.getPlantType("FAKE");
|
||||
}
|
||||
catch (NullPointerException npe)
|
||||
{
|
||||
LOGGER.warn("EnumHelper in EnumPlantType is working incorrectly!", npe);
|
||||
logger.warn("EnumHelper in EnumPlantType is working incorrectly!", npe);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (plantType == null || !plantType.name().equals("FAKE"))
|
||||
LOGGER.warn("EnumHelper in EnumPlantType is working incorrectly!");
|
||||
{
|
||||
logger.warn("EnumHelper in EnumPlantType is working incorrectly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,20 +21,25 @@ package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
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;
|
||||
|
||||
@Mod(modid = "equipment_change_test", version = "1.0.0")
|
||||
public class EquipmentChangeTest
|
||||
@Mod(modid = "equipment_change_test", name = "Equipment Change Test", version = "1.0.0", acceptableRemoteVersions = "*")
|
||||
public class EquipmentChangeTest
|
||||
{
|
||||
private static final boolean ENABLED = false;
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onInit(FMLInitializationEvent event)
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
//register the eventhandler
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
if (ENABLED)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,10 +47,10 @@ public class EquipmentChangeTest
|
||||
* Serverside only!
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public void onEquipmentChange(LivingEquipmentChangeEvent event)
|
||||
public void onEquipmentChange(LivingEquipmentChangeEvent event)
|
||||
{
|
||||
//a debug console print
|
||||
FMLLog.info("[Equipment-Change] " + event.getEntity() + " changed his Equipment in "
|
||||
logger.info("[Equipment-Change] " + event.getEntity() + " changed his Equipment in "
|
||||
+ event.getSlot() + " from " + event.getFrom() + " to " + event.getTo());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraftforge.client.event.EntityViewRenderEvent;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Simple mod to test fov modifier.
|
||||
*/
|
||||
@Mod(modid = "fovmodifiertest", name = "FOV Modifier Test", version = "0.0.0", clientSideOnly = true)
|
||||
public class FOVModifierTest
|
||||
{
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void getFOVModifier(EntityViewRenderEvent.FOVModifier event)
|
||||
{
|
||||
if (event.getState().getMaterial() == Material.WATER)
|
||||
{
|
||||
event.setFOV(event.getFOV() / 60.0f * 50.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
@Mod(modid = "fluidhandlertest", name = "FluidHandlerTest", version = "0.0.0", clientSideOnly = true)
|
||||
public class FluidHandlerTest
|
||||
{
|
||||
public static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void loadComplete(FMLLoadCompleteEvent event)
|
||||
{
|
||||
if (!ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack stack : getAllItems())
|
||||
{
|
||||
testFluidContainer(stack);
|
||||
}
|
||||
}
|
||||
|
||||
private static void testFluidContainer(ItemStack stack)
|
||||
{
|
||||
ItemStack originalStack = stack.copy();
|
||||
|
||||
ItemStack preDrainStack = stack.copy();
|
||||
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(preDrainStack);
|
||||
if (fluidHandler != null)
|
||||
{
|
||||
FluidStack drain = fluidHandler.drain(Integer.MAX_VALUE, true);
|
||||
ItemStack drainedStack = fluidHandler.getContainer();
|
||||
logger.info("Draining " + stackString(stack) + " gives " + fluidString(drain) + " and " + stackString(drainedStack));
|
||||
|
||||
if (drain == null && !ItemStack.areItemStacksEqual(originalStack, preDrainStack))
|
||||
{
|
||||
throw new RuntimeException("ItemStack was altered by its fluid handler when drain did nothing.");
|
||||
}
|
||||
|
||||
for (Fluid fluid : FluidRegistry.getRegisteredFluids().values())
|
||||
{
|
||||
ItemStack preFillStack = stack.copy();
|
||||
fluidHandler = FluidUtil.getFluidHandler(preFillStack);
|
||||
if (fluidHandler != null)
|
||||
{
|
||||
int filled = fluidHandler.fill(new FluidStack(fluid, Integer.MAX_VALUE), true);
|
||||
ItemStack filledStack = fluidHandler.getContainer();
|
||||
|
||||
if (filled > 0)
|
||||
{
|
||||
logger.info("Filling " + stackString(stack) + " with " + fluidString(new FluidStack(fluid, filled)) + " gives " + stackString(filledStack));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ItemStack.areItemStacksEqual(originalStack, preFillStack))
|
||||
{
|
||||
throw new RuntimeException("ItemStack was altered by its fluid handler when fill did nothing.");
|
||||
}
|
||||
if (!ItemStack.areItemStacksEqual(preFillStack, filledStack))
|
||||
{
|
||||
throw new RuntimeException("ItemStack was altered by its fluid handler when fill did nothing.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String fluidString(@Nullable FluidStack stack)
|
||||
{
|
||||
if (stack == null)
|
||||
{
|
||||
return "no fluid";
|
||||
}
|
||||
else
|
||||
{
|
||||
return stack.amount + "mB " + stack.getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
private static String stackString(@Nonnull ItemStack stack)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
return "no item";
|
||||
}
|
||||
else
|
||||
{
|
||||
String resourceDomain;
|
||||
if (stack.getItem().getRegistryName() == null)
|
||||
{
|
||||
resourceDomain = "unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
resourceDomain = stack.getItem().getRegistryName().getResourceDomain();
|
||||
}
|
||||
return stack.getCount() + " " + stack.getDisplayName() + " (" + resourceDomain + ")";
|
||||
}
|
||||
}
|
||||
|
||||
private static List<ItemStack> getAllItems()
|
||||
{
|
||||
NonNullList<ItemStack> list = NonNullList.create();
|
||||
for (Item item : ForgeRegistries.ITEMS.getValues())
|
||||
{
|
||||
for (CreativeTabs tab : item.getCreativeTabs())
|
||||
{
|
||||
item.getSubItems(item, tab, list);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,22 @@ import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemBucket;
|
||||
import net.minecraft.item.ItemBucketMilk;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.fluids.*;
|
||||
import net.minecraftforge.fluids.BlockFluidFinite;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.UniversalBucket;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;
|
||||
import net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -33,7 +41,7 @@ import java.util.List;
|
||||
|
||||
import static net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack.FLUID_NBT_KEY;
|
||||
|
||||
@Mod(modid = FluidPlacementTest.MODID, name = "ForgeDebugFluidPlacement", version = FluidPlacementTest.VERSION)
|
||||
@Mod(modid = FluidPlacementTest.MODID, name = "ForgeDebugFluidPlacement", version = FluidPlacementTest.VERSION, acceptableRemoteVersions = "*")
|
||||
public class FluidPlacementTest
|
||||
{
|
||||
public static final String MODID = "forgedebugfluidplacement";
|
||||
@@ -168,7 +176,7 @@ public class FluidPlacementTest
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (container.getCount() != 1 || resource == null || resource.amount > Fluid.BUCKET_VOLUME || container
|
||||
.getItem() instanceof ItemBucketMilk || getFluid() != null || !canFillFluidType(resource))
|
||||
.getItem() instanceof ItemBucketMilk || getFluid() != null || !canFillFluidType(resource))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -219,7 +227,9 @@ public class FluidPlacementTest
|
||||
{
|
||||
container = container.copy();
|
||||
if (container.getTagCompound() != null)
|
||||
{
|
||||
container.setTagCompound(container.getTagCompound().getCompoundTag(FLUID_NBT_KEY));
|
||||
}
|
||||
return super.getFluid(container);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockWall;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMap;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemMultiTexture;
|
||||
@@ -23,22 +21,25 @@ import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@Mod(modid = ForgeBlockStatesLoaderDebug.MODID, name = "ForgeBlockStatesLoader", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod.EventBusSubscriber
|
||||
public class ForgeBlockStatesLoaderDebug {
|
||||
public class ForgeBlockStatesLoaderDebug
|
||||
{
|
||||
public static final String MODID = "forgeblockstatesloader";
|
||||
public static final String ASSETS = "forgeblockstatesloader:";
|
||||
|
||||
@ObjectHolder(MODID)
|
||||
public static class BLOCKS {
|
||||
public static class BLOCKS
|
||||
{
|
||||
public static final BlockWall custom_wall = null;
|
||||
}
|
||||
|
||||
@ObjectHolder(MODID)
|
||||
public static class ITEMS {
|
||||
public static class ITEMS
|
||||
{
|
||||
public static final ItemMultiTexture custom_wall = null;
|
||||
}
|
||||
|
||||
@@ -46,7 +47,7 @@ public class ForgeBlockStatesLoaderDebug {
|
||||
public static void registerBlocks(RegistryEvent.Register<Block> event)
|
||||
{
|
||||
event.getRegistry().registerAll(
|
||||
new BlockWall(Blocks.COBBLESTONE).setUnlocalizedName(MODID + ".customWall").setRegistryName(MODID, "custom_wall")
|
||||
new BlockWall(Blocks.COBBLESTONE).setUnlocalizedName(MODID + ".customWall").setRegistryName(MODID, "custom_wall")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,14 +55,14 @@ public class ForgeBlockStatesLoaderDebug {
|
||||
public static void registerItems(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
event.getRegistry().registerAll(
|
||||
new ItemMultiTexture(BLOCKS.custom_wall, BLOCKS.custom_wall, new ItemMultiTexture.Mapper()
|
||||
{
|
||||
@Override
|
||||
public String apply(ItemStack stack)
|
||||
new ItemMultiTexture(BLOCKS.custom_wall, BLOCKS.custom_wall, new ItemMultiTexture.Mapper()
|
||||
{
|
||||
return BlockWall.EnumType.byMetadata(stack.getMetadata()).getUnlocalizedName();
|
||||
}
|
||||
}).setRegistryName(BLOCKS.custom_wall.getRegistryName())
|
||||
@Override
|
||||
public String apply(ItemStack stack)
|
||||
{
|
||||
return BlockWall.EnumType.byMetadata(stack.getMetadata()).getUnlocalizedName();
|
||||
}
|
||||
}).setRegistryName(BLOCKS.custom_wall.getRegistryName())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,7 +75,9 @@ public class ForgeBlockStatesLoaderDebug {
|
||||
//GameRegistry.registerBlock(blockCustom);
|
||||
|
||||
if (event.getSide() == Side.CLIENT)
|
||||
{
|
||||
preInitClient(event);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -85,10 +88,11 @@ public class ForgeBlockStatesLoaderDebug {
|
||||
ModelLoader.setCustomStateMapper(BLOCKS.custom_wall, new IStateMapper()
|
||||
{
|
||||
StateMap stateMap = new StateMap.Builder().withName(BlockWall.VARIANT).withSuffix("_wall").build();
|
||||
|
||||
@Override
|
||||
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block)
|
||||
{
|
||||
Map<IBlockState, ModelResourceLocation> map = (Map<IBlockState, ModelResourceLocation>) stateMap.putStateModelLocations(block);
|
||||
Map<IBlockState, ModelResourceLocation> map = stateMap.putStateModelLocations(block);
|
||||
Map<IBlockState, ModelResourceLocation> newMap = Maps.newHashMap();
|
||||
|
||||
for (Entry<IBlockState, ModelResourceLocation> e : map.entrySet())
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = IsBookEnchantableTest.MOD_ID, name = "Test for isBookEnchantable", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod.EventBusSubscriber
|
||||
public class IsBookEnchantableTest
|
||||
{
|
||||
public static final boolean ENABLED = false;
|
||||
static final String MOD_ID = "is_book_enchantable_test";
|
||||
|
||||
private static final Item TEST_ITEM = new TestItem();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItem(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
event.getRegistry().register(TEST_ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestItem extends Item
|
||||
{
|
||||
private static final String NAME = "test_item";
|
||||
|
||||
private TestItem()
|
||||
{
|
||||
maxStackSize = 1;
|
||||
setUnlocalizedName(MOD_ID + "." + NAME);
|
||||
setRegistryName(NAME);
|
||||
setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBookEnchantable(ItemStack stack, ItemStack book)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
@Mod(modid = ItemCanDestroyBlocksInCreativeTest.MODID, name = "Item.canDestroyBlockInCreative() Test", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class ItemCanDestroyBlocksInCreativeTest
|
||||
{
|
||||
public static final boolean ENABLE = true;
|
||||
public static final String MODID = "item_can_destroy_blocks_in_creative_test";
|
||||
|
||||
public static Item testItem = new Item()
|
||||
{
|
||||
@Override
|
||||
public boolean canDestroyBlockInCreative(World world, BlockPos pos, ItemStack stack, EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}.setRegistryName(MODID, "item_test")
|
||||
.setUnlocalizedName(MODID + ".item_test")
|
||||
.setCreativeTab(CreativeTabs.TOOLS);
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
GameRegistry.register(testItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.entity.projectile.EntityFishHook;
|
||||
import net.minecraft.init.Biomes;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.ItemFishedEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = "itemfishtest", name = "ItemFishTest", version = "1.0.0", acceptableRemoteVersions = "*")
|
||||
public class ItemFishedTest
|
||||
{
|
||||
|
||||
private static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
logger.info("Enabling Fishing Test mod");
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemFished(ItemFishedEvent event)
|
||||
{
|
||||
EntityFishHook hook = event.getHookEntity();
|
||||
BlockPos bobberPos = hook.getPosition();
|
||||
Biome biomeFishedAt = hook.getEntityWorld().getBiome(bobberPos);
|
||||
logger.info("Item fished in Biome " + biomeFishedAt.getBiomeName());
|
||||
if (biomeFishedAt.equals(Biomes.OCEAN))
|
||||
{
|
||||
logger.info("Canceling the event because biome is ocean");
|
||||
event.setCanceled(true);
|
||||
}
|
||||
event.damageRodBy(50);
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,8 @@ import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
@Mod(modid = ItemLayerModelDebug.MODID, name = "ForgeDebugItemLayerModel", version = ItemLayerModelDebug.VERSION, acceptableRemoteVersions = "*")
|
||||
public class ItemLayerModelDebug
|
||||
@@ -33,7 +31,10 @@ public class ItemLayerModelDebug
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); }
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
public static class CommonProxy
|
||||
{
|
||||
@@ -43,11 +44,14 @@ public class ItemLayerModelDebug
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerProxy extends CommonProxy {}
|
||||
public static class ServerProxy extends CommonProxy
|
||||
{
|
||||
}
|
||||
|
||||
public static class ClientProxy extends CommonProxy
|
||||
{
|
||||
private static ModelResourceLocation modelLocation = new ModelResourceLocation(MODID.toLowerCase() + ":" + TestItem.name, "inventory");
|
||||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
@@ -94,16 +98,19 @@ public class ItemLayerModelDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHarvestLevel(ItemStack stack, String toolClass, @Nullable EntityPlayer player, @Nullable IBlockState blockState) {
|
||||
public int getHarvestLevel(ItemStack stack, String toolClass, @Nullable EntityPlayer player, @Nullable IBlockState blockState)
|
||||
{
|
||||
// This tool is a super pickaxe if the player is wearing a helment
|
||||
if("pickaxe".equals(toolClass) && player != null && !player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty()) {
|
||||
if ("pickaxe".equals(toolClass) && player != null && !player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty())
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
return super.getHarvestLevel(stack, toolClass, player, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStrVsBlock(ItemStack stack, IBlockState state) {
|
||||
public float getStrVsBlock(ItemStack stack, IBlockState state)
|
||||
{
|
||||
return 10f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
@@ -24,6 +24,7 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
@Mod(modid = ItemTileDebug.MODID, name = "ForgeDebugItemTile", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@@ -37,10 +38,16 @@ public class ItemTileDebug
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); }
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) { proxy.init(event); }
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
proxy.init(event);
|
||||
}
|
||||
|
||||
public static class CommonProxy
|
||||
{
|
||||
@@ -51,10 +58,14 @@ public class ItemTileDebug
|
||||
GameRegistry.registerTileEntity(CustomTileEntity.class, MODID.toLowerCase() + ":custom_tile_entity");
|
||||
}
|
||||
|
||||
public void init(FMLInitializationEvent event) {}
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerProxy extends CommonProxy {}
|
||||
public static class ServerProxy extends CommonProxy
|
||||
{
|
||||
}
|
||||
|
||||
public static class ClientProxy extends CommonProxy
|
||||
{
|
||||
@@ -72,7 +83,8 @@ public class ItemTileDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(CustomTileEntity.class, TestTESR.instance);
|
||||
}
|
||||
}
|
||||
@@ -81,7 +93,9 @@ public class ItemTileDebug
|
||||
{
|
||||
public static final BakeEventHandler instance = new BakeEventHandler();
|
||||
|
||||
private BakeEventHandler() {};
|
||||
private BakeEventHandler()
|
||||
{
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBakeEvent(ModelBakeEvent event)
|
||||
@@ -94,7 +108,9 @@ public class ItemTileDebug
|
||||
{
|
||||
private static final TestTESR instance = new TestTESR();
|
||||
|
||||
private TestTESR() {}
|
||||
private TestTESR()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(CustomTileEntity p_180535_1_, double x, double y, double z, float p_180535_8_, int p_180535_9_)
|
||||
@@ -130,13 +146,22 @@ public class ItemTileDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean causesSuffocation(IBlockState state) { return false; }
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta)
|
||||
@@ -145,5 +170,7 @@ public class ItemTileDebug
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomTileEntity extends TileEntity {}
|
||||
public static class CustomTileEntity extends TileEntity
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.LootTable;
|
||||
import net.minecraft.world.storage.loot.LootTableList;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.LootTableLoadEvent;
|
||||
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 = LootTableLoadEventTest.MODID, name = "LootTableLoadEventTest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class LootTableLoadEventTest
|
||||
{
|
||||
public static final boolean ENABLED = false;
|
||||
public static final String MODID = "loottable_load_event_test";
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLootTableLoadEvent(LootTableLoadEvent event)
|
||||
{
|
||||
if (LootTableList.CHESTS_SPAWN_BONUS_CHEST.equals(event.getName()))
|
||||
{
|
||||
ResourceLocation loc = new ResourceLocation(MODID, "chests/custom_spawn_bonus_chest");
|
||||
LootTable customLootTable = event.getLootTableManager().getLootTableFromLocation(loc);
|
||||
event.setTable(customLootTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.projectile.EntityArrow;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.LootEntryItem;
|
||||
import net.minecraft.world.storage.loot.LootPool;
|
||||
import net.minecraft.world.storage.loot.LootTableList;
|
||||
@@ -18,21 +17,23 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = LootTablesDebug.MODID, name = "Loot Table Debug", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class LootTablesDebug {
|
||||
public class LootTablesDebug
|
||||
{
|
||||
public static final String MODID = "loot_table_debug";
|
||||
private static final ResourceLocation CUSTOM_LOOT = LootTableList.register(new ResourceLocation(MODID, "custom_loot"));
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void lootLoad(LootTableLoadEvent event)
|
||||
{
|
||||
if (!event.getName().equals(LootTableList.CHESTS_SPAWN_BONUS_CHEST))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove axes and replace with chestpeice, First vanilla entry is always called "main"
|
||||
LootPool main = event.getTable().getPool("main"); //Note: This CAN NPE if another mod removes things
|
||||
@@ -45,10 +46,12 @@ public class LootTablesDebug {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void lootingEvent(LootingLevelEvent event) {
|
||||
public void lootingEvent(LootingLevelEvent event)
|
||||
{
|
||||
// if the player shoots something with a projectile, use looting 3
|
||||
DamageSource damageSource = event.getDamageSource();
|
||||
if(damageSource.isProjectile() && damageSource.getEntity() instanceof EntityPlayer && damageSource.getSourceOfDamage() instanceof EntityArrow) {
|
||||
if (damageSource.isProjectile() && damageSource.getEntity() instanceof EntityPlayer && damageSource.getSourceOfDamage() instanceof EntityArrow)
|
||||
{
|
||||
event.setLootingLevel(3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockPistonBase;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
@@ -54,8 +54,7 @@ import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -75,6 +74,7 @@ public class ModelAnimationDebug
|
||||
|
||||
@SidedProxy
|
||||
public static CommonProxy proxy;
|
||||
private static Logger logger;
|
||||
|
||||
public static abstract class CommonProxy
|
||||
{
|
||||
@@ -91,14 +91,20 @@ public class ModelAnimationDebug
|
||||
@Override
|
||||
public ExtendedBlockState createBlockState()
|
||||
{
|
||||
return new ExtendedBlockState(this, new IProperty[]{ FACING, Properties.StaticProperty }, new IUnlistedProperty[]{ Properties.AnimationProperty });
|
||||
return new ExtendedBlockState(this, new IProperty[]{FACING, Properties.StaticProperty}, new IUnlistedProperty[]{Properties.AnimationProperty});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
||||
@@ -107,27 +113,32 @@ public class ModelAnimationDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
public IBlockState getStateFromMeta(int meta)
|
||||
{
|
||||
return getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return ((EnumFacing)state.getValue(FACING)).getIndex();
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return state.getValue(FACING).getIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state) {
|
||||
public boolean hasTileEntity(IBlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||
public TileEntity createTileEntity(World world, IBlockState state)
|
||||
{
|
||||
return new Chest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
return state.withProperty(Properties.StaticProperty, true);
|
||||
}
|
||||
|
||||
@@ -144,12 +155,12 @@ public class ModelAnimationDebug
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if(world.isRemote)
|
||||
if (world.isRemote)
|
||||
{
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if(te instanceof Chest)
|
||||
if (te instanceof Chest)
|
||||
{
|
||||
((Chest)te).click(player.isSneaking());
|
||||
((Chest) te).click(player.isSneaking());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -214,13 +225,13 @@ public class ModelAnimationDebug
|
||||
}*/
|
||||
ResourceLocation location = new ModelResourceLocation(new ResourceLocation(MODID, blockName), "entity");
|
||||
return new RenderLiving<EntityChest>(manager, new net.minecraftforge.client.model.animation.AnimationModelBase<EntityChest>(location, new VertexLighterSmoothAo(Minecraft.getMinecraft().getBlockColors()))
|
||||
{
|
||||
@Override
|
||||
public void handleEvents(EntityChest chest, float time, Iterable<Event> pastEvents)
|
||||
{
|
||||
@Override
|
||||
public void handleEvents(EntityChest chest, float time, Iterable<Event> pastEvents)
|
||||
{
|
||||
chest.handleEvents(time, pastEvents);
|
||||
}
|
||||
}, 0.5f)
|
||||
chest.handleEvents(time, pastEvents);
|
||||
}
|
||||
}, 0.5f)
|
||||
{
|
||||
protected ResourceLocation getEntityTexture(EntityChest entity)
|
||||
{
|
||||
@@ -243,7 +254,7 @@ public class ModelAnimationDebug
|
||||
private final VariableValue cycleLength = new VariableValue(4);
|
||||
|
||||
private final IAnimationStateMachine asm = proxy.load(new ResourceLocation(MODID.toLowerCase(), "asms/block/engine.json"), ImmutableMap.<String, ITimeValue>of(
|
||||
"cycle_length", cycleLength
|
||||
"cycle_length", cycleLength
|
||||
));
|
||||
|
||||
@Override
|
||||
@@ -256,7 +267,7 @@ public class ModelAnimationDebug
|
||||
@Nullable
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
@@ -265,7 +276,11 @@ public class ModelAnimationDebug
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); }
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
public static class Chest extends TileEntity
|
||||
{
|
||||
@@ -275,22 +290,23 @@ public class ModelAnimationDebug
|
||||
private final VariableValue clickTime = new VariableValue(Float.NEGATIVE_INFINITY);
|
||||
//private final VariableValue offset = new VariableValue(0);
|
||||
|
||||
public Chest() {
|
||||
public Chest()
|
||||
{
|
||||
/*asm = proxy.load(new ResourceLocation(MODID.toLowerCase(), "asms/block/chest.json"), ImmutableMap.<String, ITimeValue>of(
|
||||
"click_time", clickTime
|
||||
));*/
|
||||
asm = proxy.load(new ResourceLocation(MODID.toLowerCase(), "asms/block/engine.json"), ImmutableMap.<String, ITimeValue>of(
|
||||
"cycle_length", cycleLength,
|
||||
"click_time", clickTime
|
||||
//"offset", offset
|
||||
"cycle_length", cycleLength,
|
||||
"click_time", clickTime
|
||||
//"offset", offset
|
||||
));
|
||||
}
|
||||
|
||||
public void handleEvents(float time, Iterable<Event> pastEvents)
|
||||
{
|
||||
for(Event event : pastEvents)
|
||||
for (Event event : pastEvents)
|
||||
{
|
||||
System.out.println("Event: " + event.event() + " " + event.offset() + " " + getPos() + " " + time);
|
||||
logger.info("Event: " + event.event() + " " + event.offset() + " " + getPos() + " " + time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,9 +322,9 @@ public class ModelAnimationDebug
|
||||
|
||||
public void click(boolean sneaking)
|
||||
{
|
||||
if(asm != null)
|
||||
if (asm != null)
|
||||
{
|
||||
if(sneaking)
|
||||
if (sneaking)
|
||||
{
|
||||
cycleLength.setValue(6 - cycleLength.apply(0));
|
||||
}
|
||||
@@ -322,7 +338,7 @@ public class ModelAnimationDebug
|
||||
clickTime.setValue(Animation.getWorldTime(getWorld()));
|
||||
asm.transition("closing");
|
||||
}*/
|
||||
else if(asm.currentState().equals("default"))
|
||||
else if (asm.currentState().equals("default"))
|
||||
{
|
||||
float time = Animation.getWorldTime(getWorld(), Animation.getPartialTickTime());
|
||||
clickTime.setValue(time);
|
||||
@@ -330,7 +346,7 @@ public class ModelAnimationDebug
|
||||
//asm.transition("moving");
|
||||
asm.transition("starting");
|
||||
}
|
||||
else if(asm.currentState().equals("moving"))
|
||||
else if (asm.currentState().equals("moving"))
|
||||
{
|
||||
clickTime.setValue(Animation.getWorldTime(getWorld(), Animation.getPartialTickTime()));
|
||||
asm.transition("stopping");
|
||||
@@ -341,7 +357,7 @@ public class ModelAnimationDebug
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing side)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -352,7 +368,7 @@ public class ModelAnimationDebug
|
||||
@Nullable
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing side)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
@@ -370,7 +386,7 @@ public class ModelAnimationDebug
|
||||
super(world);
|
||||
setSize(1, 1);
|
||||
asm = proxy.load(new ResourceLocation(MODID.toLowerCase(), "asms/block/engine.json"), ImmutableMap.<String, ITimeValue>of(
|
||||
"cycle_length", cycleLength
|
||||
"cycle_length", cycleLength
|
||||
));
|
||||
}
|
||||
|
||||
@@ -399,7 +415,7 @@ public class ModelAnimationDebug
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing side)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -410,7 +426,7 @@ public class ModelAnimationDebug
|
||||
@Nullable
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing side)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.primitives.Ints;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
@@ -45,10 +44,9 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mod(modid = ModelBakeEventDebug.MODID, name = "ForgeDebugModelBakeEvent", version = ModelBakeEventDebug.VERSION, acceptableRemoteVersions = "*")
|
||||
public class ModelBakeEventDebug
|
||||
@@ -64,7 +62,7 @@ public class ModelBakeEventDebug
|
||||
|
||||
static
|
||||
{
|
||||
for(EnumFacing f : EnumFacing.values())
|
||||
for (EnumFacing f : EnumFacing.values())
|
||||
{
|
||||
properties[f.ordinal()] = Properties.toUnlisted(PropertyInteger.create(f.getName(), 0, (1 << (cubeSize * cubeSize)) - 1));
|
||||
}
|
||||
@@ -74,7 +72,10 @@ public class ModelBakeEventDebug
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); }
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
public static class CommonProxy
|
||||
{
|
||||
@@ -86,7 +87,9 @@ public class ModelBakeEventDebug
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerProxy extends CommonProxy {}
|
||||
public static class ServerProxy extends CommonProxy
|
||||
{
|
||||
}
|
||||
|
||||
public static class ClientProxy extends CommonProxy
|
||||
{
|
||||
@@ -99,7 +102,8 @@ public class ModelBakeEventDebug
|
||||
super.preInit(event);
|
||||
Item item = Item.getItemFromBlock(CustomModelBlock.instance);
|
||||
ModelLoader.setCustomModelResourceLocation(item, 0, itemLocation);
|
||||
ModelLoader.setCustomStateMapper(CustomModelBlock.instance, new StateMapperBase(){
|
||||
ModelLoader.setCustomStateMapper(CustomModelBlock.instance, new StateMapperBase()
|
||||
{
|
||||
protected ModelResourceLocation getModelResourceLocation(IBlockState p_178132_1_)
|
||||
{
|
||||
return blockLocation;
|
||||
@@ -113,7 +117,9 @@ public class ModelBakeEventDebug
|
||||
{
|
||||
public static final BakeEventHandler instance = new BakeEventHandler();
|
||||
|
||||
private BakeEventHandler() {};
|
||||
private BakeEventHandler()
|
||||
{
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onModelBakeEvent(ModelBakeEvent event)
|
||||
@@ -140,16 +146,28 @@ public class ModelBakeEventDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; }
|
||||
public EnumBlockRenderType getRenderType(IBlockState state)
|
||||
{
|
||||
return EnumBlockRenderType.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean causesSuffocation(IBlockState state) { return false; }
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta)
|
||||
@@ -161,14 +179,17 @@ public class ModelBakeEventDebug
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if(te instanceof CustomTileEntity)
|
||||
if (te instanceof CustomTileEntity)
|
||||
{
|
||||
CustomTileEntity cte = (CustomTileEntity) te;
|
||||
Vec3d vec = revRotate(new Vec3d(hitX - .5, hitY - .5, hitZ - .5), side).addVector(.5, .5, .5);
|
||||
IUnlistedProperty<Integer> property = properties[side.ordinal()];
|
||||
Integer value = cte.getState().getValue(property);
|
||||
if(value == null) value = 0;
|
||||
value ^= (1 << ( cubeSize * ((int)(vec.xCoord * (cubeSize - .0001))) + ((int)(vec.zCoord * (cubeSize - .0001))) ));
|
||||
if (value == null)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
value ^= (1 << (cubeSize * ((int) (vec.xCoord * (cubeSize - .0001))) + ((int) (vec.zCoord * (cubeSize - .0001)))));
|
||||
cte.setState(cte.getState().withProperty(property, value));
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
}
|
||||
@@ -179,7 +200,7 @@ public class ModelBakeEventDebug
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if(te instanceof CustomTileEntity)
|
||||
if (te instanceof CustomTileEntity)
|
||||
{
|
||||
CustomTileEntity cte = (CustomTileEntity) te;
|
||||
return cte.getState();
|
||||
@@ -197,13 +218,16 @@ public class ModelBakeEventDebug
|
||||
public static class CustomTileEntity extends TileEntity
|
||||
{
|
||||
private IExtendedBlockState state;
|
||||
public CustomTileEntity() {}
|
||||
|
||||
public CustomTileEntity()
|
||||
{
|
||||
}
|
||||
|
||||
public IExtendedBlockState getState()
|
||||
{
|
||||
if(state == null)
|
||||
if (state == null)
|
||||
{
|
||||
state = (IExtendedBlockState)getBlockType().getDefaultState();
|
||||
state = (IExtendedBlockState) getBlockType().getDefaultState();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
@@ -228,14 +252,14 @@ public class ModelBakeEventDebug
|
||||
// TODO update to builder
|
||||
private int[] vertexToInts(float x, float y, float z, int color, TextureAtlasSprite texture, float u, float v)
|
||||
{
|
||||
return new int[] {
|
||||
Float.floatToRawIntBits(x),
|
||||
Float.floatToRawIntBits(y),
|
||||
Float.floatToRawIntBits(z),
|
||||
color,
|
||||
Float.floatToRawIntBits(texture.getInterpolatedU(u)),
|
||||
Float.floatToRawIntBits(texture.getInterpolatedV(v)),
|
||||
0
|
||||
return new int[]{
|
||||
Float.floatToRawIntBits(x),
|
||||
Float.floatToRawIntBits(y),
|
||||
Float.floatToRawIntBits(z),
|
||||
color,
|
||||
Float.floatToRawIntBits(texture.getInterpolatedU(u)),
|
||||
Float.floatToRawIntBits(texture.getInterpolatedV(v)),
|
||||
0
|
||||
};
|
||||
}
|
||||
|
||||
@@ -246,33 +270,36 @@ public class ModelBakeEventDebug
|
||||
Vec3d v3 = rotate(new Vec3d(x2 - .5, y - .5, z2 - .5), side).addVector(.5, .5, .5);
|
||||
Vec3d v4 = rotate(new Vec3d(x2 - .5, y - .5, z1 - .5), side).addVector(.5, .5, .5);
|
||||
return new BakedQuad(Ints.concat(
|
||||
vertexToInts((float)v1.xCoord, (float)v1.yCoord, (float)v1.zCoord, -1, texture, 0, 0),
|
||||
vertexToInts((float)v2.xCoord, (float)v2.yCoord, (float)v2.zCoord, -1, texture, 0, 16),
|
||||
vertexToInts((float)v3.xCoord, (float)v3.yCoord, (float)v3.zCoord, -1, texture, 16, 16),
|
||||
vertexToInts((float)v4.xCoord, (float)v4.yCoord, (float)v4.zCoord, -1, texture, 16, 0)
|
||||
vertexToInts((float) v1.xCoord, (float) v1.yCoord, (float) v1.zCoord, -1, texture, 0, 0),
|
||||
vertexToInts((float) v2.xCoord, (float) v2.yCoord, (float) v2.zCoord, -1, texture, 0, 16),
|
||||
vertexToInts((float) v3.xCoord, (float) v3.yCoord, (float) v3.zCoord, -1, texture, 16, 16),
|
||||
vertexToInts((float) v4.xCoord, (float) v4.yCoord, (float) v4.zCoord, -1, texture, 16, 0)
|
||||
), -1, side, texture, true, DefaultVertexFormats.BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand)
|
||||
{
|
||||
if(side != null) return ImmutableList.of();
|
||||
IExtendedBlockState exState = (IExtendedBlockState)state;
|
||||
if (side != null)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
IExtendedBlockState exState = (IExtendedBlockState) state;
|
||||
int len = cubeSize * 5 + 1;
|
||||
List<BakedQuad> ret = new ArrayList<BakedQuad>();
|
||||
for(EnumFacing f : EnumFacing.values())
|
||||
for (EnumFacing f : EnumFacing.values())
|
||||
{
|
||||
ret.add(createSidedBakedQuad(0, 1, 0, 1, 1, base, f));
|
||||
if(state != null)
|
||||
if (state != null)
|
||||
{
|
||||
for(int i = 0; i < cubeSize; i++)
|
||||
for (int i = 0; i < cubeSize; i++)
|
||||
{
|
||||
for(int j = 0; j < cubeSize; j++)
|
||||
for (int j = 0; j < cubeSize; j++)
|
||||
{
|
||||
Integer value = exState.getValue(properties[f.ordinal()]);
|
||||
if(value != null && (value & (1 << (i * cubeSize + j))) != 0)
|
||||
if (value != null && (value & (1 << (i * cubeSize + j))) != 0)
|
||||
{
|
||||
ret.add(createSidedBakedQuad((float)(1 + i * 5) / len, (float)(5 + i * 5) / len, (float)(1 + j * 5) / len, (float)(5 + j * 5) / len, 1.0001f, overlay, f));
|
||||
ret.add(createSidedBakedQuad((float) (1 + i * 5) / len, (float) (5 + i * 5) / len, (float) (1 + j * 5) / len, (float) (5 + j * 5) / len, 1.0001f, overlay, f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,48 +309,78 @@ public class ModelBakeEventDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d() { return true; }
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() { return true; }
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer() { return false; }
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture() { return this.base; }
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return this.base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms() { return ItemCameraTransforms.DEFAULT; }
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides() { return ItemOverrideList.NONE; }
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
private static Vec3d rotate(Vec3d vec, EnumFacing side)
|
||||
{
|
||||
switch(side)
|
||||
switch (side)
|
||||
{
|
||||
case DOWN: return new Vec3d( vec.xCoord, -vec.yCoord, -vec.zCoord);
|
||||
case UP: return new Vec3d( vec.xCoord, vec.yCoord, vec.zCoord);
|
||||
case NORTH: return new Vec3d( vec.xCoord, vec.zCoord, -vec.yCoord);
|
||||
case SOUTH: return new Vec3d( vec.xCoord, -vec.zCoord, vec.yCoord);
|
||||
case WEST: return new Vec3d(-vec.yCoord, vec.xCoord, vec.zCoord);
|
||||
case EAST: return new Vec3d( vec.yCoord, -vec.xCoord, vec.zCoord);
|
||||
case DOWN:
|
||||
return new Vec3d(vec.xCoord, -vec.yCoord, -vec.zCoord);
|
||||
case UP:
|
||||
return new Vec3d(vec.xCoord, vec.yCoord, vec.zCoord);
|
||||
case NORTH:
|
||||
return new Vec3d(vec.xCoord, vec.zCoord, -vec.yCoord);
|
||||
case SOUTH:
|
||||
return new Vec3d(vec.xCoord, -vec.zCoord, vec.yCoord);
|
||||
case WEST:
|
||||
return new Vec3d(-vec.yCoord, vec.xCoord, vec.zCoord);
|
||||
case EAST:
|
||||
return new Vec3d(vec.yCoord, -vec.xCoord, vec.zCoord);
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown Side " + side);
|
||||
}
|
||||
|
||||
private static Vec3d revRotate(Vec3d vec, EnumFacing side)
|
||||
{
|
||||
switch(side)
|
||||
switch (side)
|
||||
{
|
||||
case DOWN: return new Vec3d( vec.xCoord, -vec.yCoord, -vec.zCoord);
|
||||
case UP: return new Vec3d( vec.xCoord, vec.yCoord, vec.zCoord);
|
||||
case NORTH: return new Vec3d( vec.xCoord, -vec.zCoord, vec.yCoord);
|
||||
case SOUTH: return new Vec3d( vec.xCoord, vec.zCoord, -vec.yCoord);
|
||||
case WEST: return new Vec3d( vec.yCoord, -vec.xCoord, vec.zCoord);
|
||||
case EAST: return new Vec3d(-vec.yCoord, vec.xCoord, vec.zCoord);
|
||||
case DOWN:
|
||||
return new Vec3d(vec.xCoord, -vec.yCoord, -vec.zCoord);
|
||||
case UP:
|
||||
return new Vec3d(vec.xCoord, vec.yCoord, vec.zCoord);
|
||||
case NORTH:
|
||||
return new Vec3d(vec.xCoord, -vec.zCoord, vec.yCoord);
|
||||
case SOUTH:
|
||||
return new Vec3d(vec.xCoord, vec.zCoord, -vec.yCoord);
|
||||
case WEST:
|
||||
return new Vec3d(vec.yCoord, -vec.xCoord, vec.zCoord);
|
||||
case EAST:
|
||||
return new Vec3d(-vec.yCoord, vec.xCoord, vec.zCoord);
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown Side " + side);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package net.minecraftforge.debug;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
@@ -62,7 +62,9 @@ public class ModelFluidDebug
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerProxy extends CommonProxy {}
|
||||
public static class ServerProxy extends CommonProxy
|
||||
{
|
||||
}
|
||||
|
||||
public static class ClientProxy extends CommonProxy
|
||||
{
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.vecmath.AxisAngle4d;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.Vector3d;
|
||||
import javax.vecmath.Vector4f;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.UnmodifiableIterator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
@@ -26,7 +18,6 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
@@ -48,24 +39,38 @@ import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import javax.vecmath.AxisAngle4d;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import javax.vecmath.Quat4f;
|
||||
import javax.vecmath.Vector3d;
|
||||
import javax.vecmath.Vector4f;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mod(modid = ModelLoaderRegistryDebug.MODID, name = "ForgeDebugModelLoaderRegistry", version = ModelLoaderRegistryDebug.VERSION, acceptableRemoteVersions = "*")
|
||||
public class ModelLoaderRegistryDebug
|
||||
{
|
||||
public static final boolean ENABLED = false;
|
||||
public static final String MODID = "forgedebugmodelloaderregistry";
|
||||
public static final String VERSION = "1.0";
|
||||
private static Logger logger;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger = event.getModLog();
|
||||
List<Block> blocks = Lists.newArrayList();
|
||||
blocks.add(CustomModelBlock.instance);
|
||||
blocks.add(OBJTesseractBlock.instance);
|
||||
@@ -75,7 +80,7 @@ public class ModelLoaderRegistryDebug
|
||||
blocks.add(OBJDirectionBlock.instance);
|
||||
blocks.add(OBJCustomDataBlock.instance);
|
||||
//blocks.add(OBJDynamicEye.instance);
|
||||
for(Block block : blocks)
|
||||
for (Block block : blocks)
|
||||
{
|
||||
GameRegistry.register(block);
|
||||
GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
|
||||
@@ -84,7 +89,9 @@ public class ModelLoaderRegistryDebug
|
||||
GameRegistry.registerTileEntity(OBJVertexColoring2TileEntity.class, OBJVertexColoring2.name);
|
||||
//GameRegistry.registerTileEntity(OBJDynamicEyeTileEntity.class, OBJDynamicEye.name);
|
||||
if (event.getSide() == Side.CLIENT)
|
||||
{
|
||||
clientPreInit();
|
||||
}
|
||||
}
|
||||
|
||||
private void clientPreInit()
|
||||
@@ -133,13 +140,22 @@ public class ModelLoaderRegistryDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean causesSuffocation(IBlockState state) { return false; }
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
||||
@@ -156,7 +172,7 @@ public class ModelLoaderRegistryDebug
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return ((EnumFacing) state.getValue(FACING)).getIndex();
|
||||
return state.getValue(FACING).getIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,11 +186,17 @@ public class ModelLoaderRegistryDebug
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if(world.isRemote)
|
||||
if (world.isRemote)
|
||||
{
|
||||
System.out.println("click " + counter);
|
||||
if(player.isSneaking()) counter--;
|
||||
else counter++;
|
||||
logger.info("click " + counter);
|
||||
if (player.isSneaking())
|
||||
{
|
||||
counter--;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
//if(counter >= model.getNode().getKeys().size()) counter = 0;
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
}
|
||||
@@ -189,16 +211,16 @@ public class ModelLoaderRegistryDebug
|
||||
|
||||
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
|
||||
{
|
||||
if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
|
||||
if (MathHelper.abs((float) entityIn.posX - (float) clickedBlock.getX()) < 2.0F && MathHelper.abs((float) entityIn.posZ - (float) clickedBlock.getZ()) < 2.0F)
|
||||
{
|
||||
double d0 = entityIn.posY + (double)entityIn.getEyeHeight();
|
||||
double d0 = entityIn.posY + (double) entityIn.getEyeHeight();
|
||||
|
||||
if (d0 - (double)clickedBlock.getY() > 2.0D)
|
||||
if (d0 - (double) clickedBlock.getY() > 2.0D)
|
||||
{
|
||||
return EnumFacing.UP;
|
||||
}
|
||||
|
||||
if ((double)clickedBlock.getY() - d0 > 0.0D)
|
||||
if ((double) clickedBlock.getY() - d0 > 0.0D)
|
||||
{
|
||||
return EnumFacing.DOWN;
|
||||
}
|
||||
@@ -207,6 +229,7 @@ public class ModelLoaderRegistryDebug
|
||||
return entityIn.getHorizontalFacing().getOpposite();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This block is intended to demonstrate how to change the visibility of a group(s)
|
||||
* from within the block's class.
|
||||
@@ -238,18 +261,30 @@ public class ModelLoaderRegistryDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean causesSuffocation(IBlockState state) { return false; }
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (world.getTileEntity(pos) == null) world.setTileEntity(pos, new OBJTesseractTileEntity());
|
||||
if (world.getTileEntity(pos) == null)
|
||||
{
|
||||
world.setTileEntity(pos, new OBJTesseractTileEntity());
|
||||
}
|
||||
OBJTesseractTileEntity tileEntity = (OBJTesseractTileEntity) world.getTileEntity(pos);
|
||||
|
||||
if (player.isSneaking())
|
||||
@@ -285,7 +320,7 @@ public class ModelLoaderRegistryDebug
|
||||
@Override
|
||||
public BlockStateContainer createBlockState()
|
||||
{
|
||||
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] {Properties.AnimationProperty});
|
||||
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{Properties.AnimationProperty});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,15 +336,15 @@ public class ModelLoaderRegistryDebug
|
||||
@Override
|
||||
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
|
||||
{
|
||||
if(part.isPresent())
|
||||
if (part.isPresent())
|
||||
{
|
||||
// This whole thing is subject to change, but should do for now.
|
||||
UnmodifiableIterator<String> parts = Models.getParts(part.get());
|
||||
if(parts.hasNext())
|
||||
if (parts.hasNext())
|
||||
{
|
||||
String name = parts.next();
|
||||
// only interested in the root level
|
||||
if(!parts.hasNext() && hidden.contains(name))
|
||||
if (!parts.hasNext() && hidden.contains(name))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@@ -329,7 +364,10 @@ public class ModelLoaderRegistryDebug
|
||||
this.counter++;
|
||||
this.hidden.add(Integer.toString(this.counter));
|
||||
TextComponentString text = new TextComponentString("" + this.counter);
|
||||
if (this.world.isRemote) Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(text);
|
||||
if (this.world.isRemote)
|
||||
{
|
||||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void decrement()
|
||||
@@ -342,7 +380,10 @@ public class ModelLoaderRegistryDebug
|
||||
this.hidden.remove(Integer.toString(this.counter));
|
||||
this.counter--;
|
||||
TextComponentString text = new TextComponentString("" + this.counter);
|
||||
if (this.world.isRemote) Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(text);
|
||||
if (this.world.isRemote)
|
||||
{
|
||||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMax(int max)
|
||||
@@ -375,13 +416,22 @@ public class ModelLoaderRegistryDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean causesSuffocation(IBlockState state) { return false; }
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,7 +472,7 @@ public class ModelLoaderRegistryDebug
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return ((EnumFacing) state.getValue(FACING)).getIndex();
|
||||
return state.getValue(FACING).getIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -432,26 +482,35 @@ public class ModelLoaderRegistryDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean causesSuffocation(IBlockState state) { return false; }
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
|
||||
{
|
||||
if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
|
||||
if (MathHelper.abs((float) entityIn.posX - (float) clickedBlock.getX()) < 2.0F && MathHelper.abs((float) entityIn.posZ - (float) clickedBlock.getZ()) < 2.0F)
|
||||
{
|
||||
double d0 = entityIn.posY + (double)entityIn.getEyeHeight();
|
||||
double d0 = entityIn.posY + (double) entityIn.getEyeHeight();
|
||||
|
||||
if (d0 - (double)clickedBlock.getY() > 2.0D)
|
||||
if (d0 - (double) clickedBlock.getY() > 2.0D)
|
||||
{
|
||||
return EnumFacing.DOWN;
|
||||
}
|
||||
|
||||
if ((double)clickedBlock.getY() - d0 > 0.0D)
|
||||
if ((double) clickedBlock.getY() - d0 > 0.0D)
|
||||
{
|
||||
return EnumFacing.UP;
|
||||
}
|
||||
@@ -507,13 +566,15 @@ public class ModelLoaderRegistryDebug
|
||||
private boolean hasFilledList = false;
|
||||
private boolean shouldIncrement = true;
|
||||
|
||||
public OBJVertexColoring2TileEntity() {}
|
||||
public OBJVertexColoring2TileEntity()
|
||||
{
|
||||
}
|
||||
|
||||
public void cycleColors()
|
||||
{
|
||||
if (this.world.isRemote)
|
||||
{
|
||||
FMLLog.info("%b", shouldIncrement);
|
||||
logger.info("%b", shouldIncrement);
|
||||
/*
|
||||
IBakedModel bakedModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelFromBlockState(this.world.getBlockState(this.pos), this.world, this.pos);
|
||||
if (bakedModel != null && bakedModel instanceof OBJBakedModel)
|
||||
@@ -585,13 +646,22 @@ public class ModelLoaderRegistryDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean causesSuffocation(IBlockState state) { return false; }
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
||||
@@ -608,7 +678,7 @@ public class ModelLoaderRegistryDebug
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state)
|
||||
{
|
||||
return ((EnumFacing) state.getValue(FACING)).getIndex();
|
||||
return state.getValue(FACING).getIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -619,16 +689,16 @@ public class ModelLoaderRegistryDebug
|
||||
|
||||
public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn)
|
||||
{
|
||||
if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 2.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 2.0F)
|
||||
if (MathHelper.abs((float) entityIn.posX - (float) clickedBlock.getX()) < 2.0F && MathHelper.abs((float) entityIn.posZ - (float) clickedBlock.getZ()) < 2.0F)
|
||||
{
|
||||
double d0 = entityIn.posY + (double)entityIn.getEyeHeight();
|
||||
double d0 = entityIn.posY + (double) entityIn.getEyeHeight();
|
||||
|
||||
if (d0 - (double)clickedBlock.getY() > 2.0D)
|
||||
if (d0 - (double) clickedBlock.getY() > 2.0D)
|
||||
{
|
||||
return EnumFacing.UP;
|
||||
}
|
||||
|
||||
if ((double)clickedBlock.getY() - d0 > 0.0D)
|
||||
if ((double) clickedBlock.getY() - d0 > 0.0D)
|
||||
{
|
||||
return EnumFacing.DOWN;
|
||||
}
|
||||
@@ -695,7 +765,7 @@ public class ModelLoaderRegistryDebug
|
||||
@Override
|
||||
public BlockStateContainer createBlockState()
|
||||
{
|
||||
return new BlockStateContainer(this, new IProperty[]{NORTH, SOUTH, WEST, EAST});
|
||||
return new BlockStateContainer(this, NORTH, SOUTH, WEST, EAST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,6 +779,7 @@ public class ModelLoaderRegistryDebug
|
||||
{
|
||||
public static final OBJDynamicEye instance = new OBJDynamicEye();
|
||||
public static final String name = "obj_dynamic_eye";
|
||||
|
||||
private OBJDynamicEye()
|
||||
{
|
||||
super(Material.IRON);
|
||||
@@ -758,7 +829,7 @@ public class ModelLoaderRegistryDebug
|
||||
@Override
|
||||
public BlockStateContainer createBlockState()
|
||||
{
|
||||
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] {Properties.AnimationProperty});
|
||||
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{Properties.AnimationProperty});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,7 +849,7 @@ public class ModelLoaderRegistryDebug
|
||||
playerLoc.setY(player.posY + player.getEyeHeight());
|
||||
playerLoc.setZ(player.posZ);
|
||||
Vector3d lookVec = new Vector3d(playerLoc.getX() - teLoc.getX(), playerLoc.getY() - teLoc.getY(), playerLoc.getZ() - teLoc.getZ());
|
||||
double angleYaw = Math.atan2(lookVec.getZ(), lookVec.getX()) - Math.PI/2d;
|
||||
double angleYaw = Math.atan2(lookVec.getZ(), lookVec.getX()) - Math.PI / 2d;
|
||||
double anglePitch = Math.atan2(lookVec.getY(), Math.sqrt(lookVec.getX() * lookVec.getX() + lookVec.getZ() * lookVec.getZ()));
|
||||
AxisAngle4d yaw = new AxisAngle4d(0, 1, 0, -angleYaw);
|
||||
AxisAngle4d pitch = new AxisAngle4d(1, 0, 0, -anglePitch);
|
||||
|
||||
@@ -41,10 +41,16 @@ public class MultiLayerModelDebug
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) { return false; }
|
||||
public boolean isOpaqueCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) { return false; }
|
||||
public boolean isFullCube(IBlockState state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer)
|
||||
@@ -56,7 +62,9 @@ public class MultiLayerModelDebug
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerProxy extends CommonProxy {}
|
||||
public static class ServerProxy extends CommonProxy
|
||||
{
|
||||
}
|
||||
|
||||
public static class ClientProxy extends CommonProxy
|
||||
{
|
||||
@@ -69,5 +77,8 @@ public class MultiLayerModelDebug
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); }
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
proxy.preInit(event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = "neighbornotifyeventtest", name = "NeighborNotifyEventTest", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class NeighborNotifyEventTest
|
||||
{
|
||||
|
||||
public static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onNeighborNotify(NeighborNotifyEvent event)
|
||||
{
|
||||
logger.info(event.getPos().toString() + " with face information: " + event.getNotifiedSides());
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayer.SleepResult;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTPrimitive;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
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.PlayerWakeUpEvent;
|
||||
import net.minecraftforge.event.entity.player.SleepingLocationCheckEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Mod(modid = NoBedSleepingTest.MODID, name = "ForgeDebugNoBedSleeping", version = NoBedSleepingTest.VERSION, acceptableRemoteVersions = "*")
|
||||
public class NoBedSleepingTest
|
||||
{
|
||||
public static final String MODID = "forgedebugnobedsleeping";
|
||||
public static final String VERSION = "1.0";
|
||||
@CapabilityInject(IExtraSleeping.class)
|
||||
private static final Capability<IExtraSleeping> SLEEP_CAP = null;
|
||||
|
||||
@SidedProxy
|
||||
public static CommonProxy proxy = null;
|
||||
|
||||
public static abstract class CommonProxy
|
||||
{
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
GameRegistry.register(ItemSleepingPill.instance);
|
||||
CapabilityManager.INSTANCE.register(IExtraSleeping.class, new Storage(), DefaultImpl.class);
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ServerProxy extends CommonProxy
|
||||
{
|
||||
}
|
||||
|
||||
public static final class ClientProxy extends CommonProxy
|
||||
{
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
super.preInit(event);
|
||||
ModelLoader.setCustomModelResourceLocation(ItemSleepingPill.instance, 0, new ModelResourceLocation(new ResourceLocation(MODID, ItemSleepingPill.name), "inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
public static class EventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void onEntityConstruct(AttachCapabilitiesEvent.Entity evt)
|
||||
{
|
||||
if (!(evt.getEntity() instanceof EntityPlayer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
evt.addCapability(new ResourceLocation(MODID, "IExtraSleeping"), new ICapabilitySerializable<NBTPrimitive>()
|
||||
{
|
||||
IExtraSleeping inst = SLEEP_CAP.getDefaultInstance();
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
return capability == SLEEP_CAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
return capability == SLEEP_CAP ? SLEEP_CAP.<T>cast(inst) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTPrimitive serializeNBT()
|
||||
{
|
||||
return (NBTPrimitive) SLEEP_CAP.getStorage().writeNBT(SLEEP_CAP, inst, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTPrimitive nbt)
|
||||
{
|
||||
SLEEP_CAP.getStorage().readNBT(SLEEP_CAP, inst, null, nbt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onBedCheck(SleepingLocationCheckEvent evt)
|
||||
{
|
||||
final IExtraSleeping sleep = evt.getEntityPlayer().getCapability(SLEEP_CAP, null);
|
||||
if (sleep != null && sleep.isSleeping())
|
||||
{
|
||||
evt.setResult(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWakeUp(PlayerWakeUpEvent evt)
|
||||
{
|
||||
final IExtraSleeping sleep = evt.getEntityPlayer().getCapability(SLEEP_CAP, null);
|
||||
if (sleep != null)
|
||||
{
|
||||
sleep.setSleeping(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IExtraSleeping
|
||||
{
|
||||
boolean isSleeping();
|
||||
|
||||
void setSleeping(boolean value);
|
||||
}
|
||||
|
||||
public static class Storage implements IStorage<IExtraSleeping>
|
||||
{
|
||||
@Override
|
||||
public NBTBase writeNBT(Capability<IExtraSleeping> capability, IExtraSleeping instance, EnumFacing side)
|
||||
{
|
||||
return new NBTTagByte((byte) (instance.isSleeping() ? 1 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<IExtraSleeping> capability, IExtraSleeping instance, EnumFacing side, NBTBase nbt)
|
||||
{
|
||||
instance.setSleeping(((NBTPrimitive) nbt).getByte() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DefaultImpl implements IExtraSleeping
|
||||
{
|
||||
private boolean isSleeping = false;
|
||||
|
||||
@Override
|
||||
public boolean isSleeping()
|
||||
{
|
||||
return isSleeping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSleeping(boolean value)
|
||||
{
|
||||
this.isSleeping = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemSleepingPill extends Item
|
||||
{
|
||||
public static final ItemSleepingPill instance = new ItemSleepingPill();
|
||||
public static final String name = "sleeping_pill";
|
||||
|
||||
private ItemSleepingPill()
|
||||
{
|
||||
setCreativeTab(CreativeTabs.MISC);
|
||||
setUnlocalizedName(MODID + ":" + name);
|
||||
setRegistryName(new ResourceLocation(MODID, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand)
|
||||
{
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
if (!world.isRemote)
|
||||
{
|
||||
final SleepResult result = player.trySleep(player.getPosition());
|
||||
if (result == SleepResult.OK)
|
||||
{
|
||||
final IExtraSleeping sleep = player.getCapability(SLEEP_CAP, null);
|
||||
if (sleep != null)
|
||||
{
|
||||
sleep.setSleeping(true);
|
||||
}
|
||||
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
||||
}
|
||||
}
|
||||
return ActionResult.newResult(EnumActionResult.PASS, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,25 +7,30 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
|
||||
@Mod( modid = NoPotionEffectRenderTest.modID, name = "No Potion Effect Render Test", version = "0.0.0", acceptableRemoteVersions = "*" )
|
||||
public class NoPotionEffectRenderTest {
|
||||
public static final String modID = "nopotioneffect";
|
||||
@Mod(modid = NoPotionEffectRenderTest.modID, name = "No Potion Effect Render Test", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class NoPotionEffectRenderTest
|
||||
{
|
||||
public static final String modID = "nopotioneffect";
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
TestPotion INSTANCE = new TestPotion(new ResourceLocation(modID, "test_potion"), false, 0xff00ff);
|
||||
GameData.getPotionRegistry().register(-1, new ResourceLocation(modID, "test_potion"), INSTANCE);
|
||||
}
|
||||
|
||||
public static class TestPotion extends Potion {
|
||||
|
||||
public TestPotion(ResourceLocation location, boolean badEffect, int potionColor) {
|
||||
super(badEffect, potionColor);
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
TestPotion INSTANCE = new TestPotion(new ResourceLocation(modID, "test_potion"), false, 0xff00ff);
|
||||
GameData.getPotionRegistry().register(-1, new ResourceLocation(modID, "test_potion"), INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(PotionEffect effect) {
|
||||
return false;
|
||||
public static class TestPotion extends Potion
|
||||
{
|
||||
|
||||
public TestPotion(ResourceLocation location, boolean badEffect, int potionColor)
|
||||
{
|
||||
super(badEffect, potionColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(PotionEffect effect)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,15 @@ import net.minecraftforge.fml.common.registry.IForgeRegistry;
|
||||
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;
|
||||
import net.minecraftforge.fml.common.registry.RegistryBuilder;
|
||||
|
||||
@Mod(modid= ObjectHolderTest.MODID, name = "ObjectHolderTests", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod(modid = ObjectHolderTest.MODID, name = "ObjectHolderTests", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class ObjectHolderTest
|
||||
{
|
||||
public static final String MODID = "objectholdertest";
|
||||
public static IForgeRegistry registry;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
//verifies @ObjectHolder with custom id
|
||||
assert VanillaObjectHolder.uiButtonClick != null;
|
||||
//verifies modded items work
|
||||
@@ -36,8 +37,10 @@ public class ObjectHolderTest
|
||||
|
||||
}
|
||||
|
||||
protected static class PotionForge extends Potion {
|
||||
protected PotionForge(ResourceLocation location, boolean badEffect, int potionColor) {
|
||||
protected static class PotionForge extends Potion
|
||||
{
|
||||
protected PotionForge(ResourceLocation location, boolean badEffect, int potionColor)
|
||||
{
|
||||
super(badEffect, potionColor);
|
||||
setPotionName("potion." + location.getResourcePath());
|
||||
setRegistryName(location);
|
||||
@@ -45,10 +48,12 @@ public class ObjectHolderTest
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MODID)
|
||||
public static class Registration {
|
||||
public static class Registration
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void newRegistry(RegistryEvent.NewRegistry event) {
|
||||
new RegistryBuilder()
|
||||
public static void newRegistry(RegistryEvent.NewRegistry event)
|
||||
{
|
||||
new RegistryBuilder<ICustomRegistryEntry>()
|
||||
.setType(ICustomRegistryEntry.class)
|
||||
.setName(new ResourceLocation("object_holder_test_custom_registry"))
|
||||
.setIDRange(0, 255)
|
||||
@@ -56,14 +61,16 @@ public class ObjectHolderTest
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerPotions(RegistryEvent.Register<Potion> event) {
|
||||
public static void registerPotions(RegistryEvent.Register<Potion> event)
|
||||
{
|
||||
event.getRegistry().register(
|
||||
new ObjectHolderTest.PotionForge(new ResourceLocation(ObjectHolderTest.MODID, "forge_potion"), false, 0xff00ff) // test automatic id distribution
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerInterfaceRegistryForge(RegistryEvent.Register<ICustomRegistryEntry> event) {
|
||||
public static void registerInterfaceRegistryForge(RegistryEvent.Register<ICustomRegistryEntry> event)
|
||||
{
|
||||
event.getRegistry().register(
|
||||
new CustomRegistryEntry().setRegistryName(new ResourceLocation(MODID, "custom_entry_by_interface"))
|
||||
);
|
||||
@@ -99,7 +106,8 @@ class CustomRegistryEntry implements ICustomRegistryEntry
|
||||
}
|
||||
}
|
||||
|
||||
interface ICustomRegistryEntry extends IForgeRegistryEntry<ICustomRegistryEntry> {
|
||||
interface ICustomRegistryEntry extends IForgeRegistryEntry<ICustomRegistryEntry>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
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,47 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
||||
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 = "playerdamagereworktest", name = "PlayerDamageReworkTest", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class PlayerDamageReworkTest
|
||||
{
|
||||
private static final boolean ENABLE = false;
|
||||
private static final UUID ARMOR_MODIFIER_UUID = UUID.fromString("23373DC8-1F3D-11E7-93AE-92361F002671");
|
||||
private static final AttributeModifier mod = new AttributeModifier(ARMOR_MODIFIER_UUID, "Player Damage Rework Test", 20, 0);
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (ENABLE) MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void checkForSneakEvent(LivingUpdateEvent event)
|
||||
{
|
||||
if (event.getEntityLiving() instanceof EntityPlayer)
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
|
||||
if (player.isSneaking())
|
||||
{
|
||||
if (!player.getEntityAttribute(SharedMonsterAttributes.ARMOR).hasModifier(mod))
|
||||
{
|
||||
player.getEntityAttribute(SharedMonsterAttributes.ARMOR).applyModifier(mod);
|
||||
}
|
||||
}
|
||||
else if (player.getEntityAttribute(SharedMonsterAttributes.ARMOR).hasModifier(mod))
|
||||
{
|
||||
player.getEntityAttribute(SharedMonsterAttributes.ARMOR).removeModifier(ARMOR_MODIFIER_UUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.entity.item.EntityArmorStand;
|
||||
import net.minecraft.entity.monster.EntitySkeleton;
|
||||
import net.minecraft.entity.passive.EntityHorse;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.tileentity.TileEntityDropper;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = "playerinteracteventtest", name = "PlayerInteractEventTest", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class PlayerInteractEventTest
|
||||
{
|
||||
// NOTE: Test with both this ON and OFF - ensure none of the test behaviours show when this is off!
|
||||
private static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@EventHandler
|
||||
public void preinit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(PlayerInteractEventTest.class); // Test Static event listeners
|
||||
}
|
||||
|
||||
@SubscribeEvent(receiveCanceled = true) // this triggers after the subclasses below, and we'd like to log them all
|
||||
public void global(PlayerInteractEvent evt)
|
||||
{
|
||||
if (!ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
logger.info("{} | {}", evt.getClass().getSimpleName(), evt.getSide().name());
|
||||
logger.info("{} | stack: {}", evt.getHand(), evt.getItemStack());
|
||||
logger.info("{} | face: {}", evt.getPos(), evt.getFace());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void leftClickBlock(PlayerInteractEvent.LeftClickBlock evt)
|
||||
{
|
||||
if (!ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
logger.info("HIT VEC: {}", evt.getHitVec());
|
||||
|
||||
if (!evt.getItemStack().isEmpty())
|
||||
{
|
||||
if (evt.getItemStack().getItem() == Items.GOLDEN_PICKAXE)
|
||||
{
|
||||
evt.setCanceled(true); // Redstone should not activate and pick should not be able to dig anything
|
||||
}
|
||||
if (evt.getItemStack().getItem() == Items.DIAMOND_PICKAXE)
|
||||
{
|
||||
evt.setUseBlock(Event.Result.DENY); // Redstone should not activate, pick should still dig
|
||||
}
|
||||
if (evt.getItemStack().getItem() == Items.IRON_PICKAXE)
|
||||
{
|
||||
evt.setUseItem(Event.Result.DENY); // Pick should not dig, Redstone should still activate
|
||||
}
|
||||
}
|
||||
|
||||
// When item use denied, the event will keep firing as long as the left click button is held.
|
||||
// This is due to how vanilla calls the left click handling methods to let people not lift their button when mining multiple blocks.
|
||||
// Note that when item use is denied, the cool down for the item does not occur. This is good!
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void rightClickBlock(PlayerInteractEvent.RightClickBlock evt)
|
||||
{
|
||||
if (!ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
logger.info("HIT VEC: {}", evt.getHitVec());
|
||||
|
||||
// Shift right clicking dropper with an item in hand should still open the dropper contrary to normal mechanics
|
||||
// The item in hand is used as well (not specifying anything would not use the item)
|
||||
TileEntity te = evt.getWorld().getTileEntity(evt.getPos());
|
||||
if (te instanceof TileEntityDropper)
|
||||
{
|
||||
evt.setUseBlock(Event.Result.ALLOW);
|
||||
evt.setUseItem(Event.Result.ALLOW);
|
||||
}
|
||||
|
||||
// Same as above, except the item should no longer be used
|
||||
if (te instanceof TileEntityChest)
|
||||
{
|
||||
evt.setUseBlock(Event.Result.ALLOW);
|
||||
evt.setUseItem(Event.Result.DENY); // could be left out as well
|
||||
}
|
||||
|
||||
// Case: Flint and steel in main hand on top of a TE will light a fire, not open the TE.
|
||||
// Note that if you do this on a chest, the f+s will fail, but then your off hand will open the chest
|
||||
// If you dual wield flints and steels and right click a chest nothing should happen
|
||||
if (!evt.getItemStack().isEmpty() && evt.getItemStack().getItem() == Items.FLINT_AND_STEEL)
|
||||
{
|
||||
evt.setUseBlock(Event.Result.DENY);
|
||||
}
|
||||
|
||||
// Case: Painting in main hand
|
||||
// Opening a TE will also place a painting on the TE if possible
|
||||
if (evt.getHand() == EnumHand.MAIN_HAND && !evt.getItemStack().isEmpty() && evt.getItemStack().getItem() == Items.PAINTING)
|
||||
{
|
||||
evt.setUseItem(Event.Result.ALLOW);
|
||||
}
|
||||
|
||||
// Spawn egg in main hand, block in offhand -> block should be placed
|
||||
if (!evt.getItemStack().isEmpty()
|
||||
&& evt.getItemStack().getItem() == Items.SPAWN_EGG
|
||||
&& evt.getHand() == EnumHand.MAIN_HAND
|
||||
&& !evt.getEntityPlayer().getHeldItemOffhand().isEmpty()
|
||||
&& evt.getEntityPlayer().getHeldItemOffhand().getItem() instanceof ItemBlock)
|
||||
{
|
||||
evt.setCanceled(true);
|
||||
}
|
||||
|
||||
// Spawn egg in main hand, potion in offhand -> potion should NOT be thrown
|
||||
if (!evt.getItemStack().isEmpty()
|
||||
&& evt.getItemStack().getItem() == Items.SPAWN_EGG
|
||||
&& evt.getHand() == EnumHand.MAIN_HAND
|
||||
&& !evt.getEntityPlayer().getHeldItemOffhand().isEmpty()
|
||||
&& evt.getEntityPlayer().getHeldItemOffhand().getItem() == Items.SPLASH_POTION)
|
||||
{
|
||||
evt.setCanceled(true);
|
||||
// Fake spawn egg success so splash potion does not trigger
|
||||
evt.setCancellationResult(EnumActionResult.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void rightClickItem(PlayerInteractEvent.RightClickItem evt)
|
||||
{
|
||||
if (!ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Case: Ender pearl in main hand, block in offhand -> Block is NOT placed
|
||||
if (!evt.getItemStack().isEmpty()
|
||||
&& evt.getItemStack().getItem() == Items.ENDER_PEARL
|
||||
&& evt.getHand() == EnumHand.MAIN_HAND
|
||||
&& !evt.getEntityPlayer().getHeldItemOffhand().isEmpty()
|
||||
&& evt.getEntityPlayer().getHeldItemOffhand().getItem() instanceof ItemBlock)
|
||||
{
|
||||
evt.setCanceled(true);
|
||||
evt.setCancellationResult(EnumActionResult.SUCCESS); // We fake success on the ender pearl so block is not placed
|
||||
return;
|
||||
}
|
||||
|
||||
// Case: Ender pearl in main hand, bow in offhand with arrows in inv -> Bow should trigger
|
||||
// Case: Sword in main hand, ender pearl in offhand -> Nothing should happen
|
||||
if (!evt.getItemStack().isEmpty() && evt.getItemStack().getItem() == Items.ENDER_PEARL)
|
||||
{
|
||||
evt.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void interactSpecific(PlayerInteractEvent.EntityInteractSpecific evt)
|
||||
{
|
||||
if (!ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
logger.info("LOCAL POS: {}", evt.getLocalPos());
|
||||
|
||||
if (!evt.getItemStack().isEmpty()
|
||||
&& evt.getTarget() instanceof EntityArmorStand
|
||||
&& evt.getItemStack().getItem() == Items.IRON_HELMET)
|
||||
{
|
||||
evt.setCanceled(true); // Should not be able to place iron helmet onto armor stand (you will put it on instead)
|
||||
}
|
||||
|
||||
if (!evt.getItemStack().isEmpty()
|
||||
&& evt.getTarget() instanceof EntityArmorStand
|
||||
&& evt.getItemStack().getItem() == Items.GOLDEN_HELMET)
|
||||
{
|
||||
evt.setCanceled(true);
|
||||
evt.setCancellationResult(EnumActionResult.SUCCESS);
|
||||
// Should not be able to place golden helmet onto armor stand
|
||||
// However you will NOT put it on because we fake success on the armorstand.
|
||||
}
|
||||
|
||||
if (!evt.getWorld().isRemote
|
||||
&& evt.getTarget() instanceof EntitySkeleton
|
||||
&& evt.getLocalPos().yCoord > evt.getTarget().height / 2.0)
|
||||
{
|
||||
// If we right click the upper half of a skeleton it dies.
|
||||
evt.getTarget().setDead();
|
||||
evt.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void interactNormal(PlayerInteractEvent.EntityInteract evt)
|
||||
{
|
||||
if (!ENABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!evt.getItemStack().isEmpty() && evt.getTarget() instanceof EntityHorse)
|
||||
{
|
||||
// Should not be able to feed wild horses with golden apple (you will start eating it in survival)
|
||||
if (evt.getItemStack().getItem() == Items.GOLDEN_APPLE
|
||||
&& evt.getItemStack().getItemDamage() == 0)
|
||||
{
|
||||
evt.setCanceled(true);
|
||||
}
|
||||
// Should not be able to feed wild horses with notch apple but you will NOT eat it
|
||||
if (evt.getItemStack().getItem() == Items.GOLDEN_APPLE
|
||||
&& evt.getItemStack().getItemDamage() == 1)
|
||||
{
|
||||
evt.setCanceled(true);
|
||||
evt.setCancellationResult(EnumActionResult.SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerSetSpawnEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = "playersetspawntest", name = "Player Set Spawn Test", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class PlayerSetSpawnTest
|
||||
{
|
||||
private static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerSetSpawn(PlayerSetSpawnEvent event)
|
||||
{
|
||||
logger.info(event.isForced() + " " + event.getNewSpawn().toString());
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemFood;
|
||||
@@ -24,14 +23,20 @@ import java.util.List;
|
||||
* 3. Drink incurable_potion from Brewing creative tab
|
||||
* 4. Relog to test that changes to curative items persist, then try drinking milk and eating medicine: they should have no effect
|
||||
*/
|
||||
@Mod(modid = PotionCurativeItemDebug.MOD_ID)
|
||||
@Mod(modid = PotionCurativeItemDebug.MOD_ID, name = "Potion Curative Item Debug", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class PotionCurativeItemDebug
|
||||
{
|
||||
public static final boolean ENABLED = false;
|
||||
public static final String MOD_ID = "potion_curative_item_debug";
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent evt)
|
||||
{
|
||||
if (!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Item medicine = new Medicine().setRegistryName(MOD_ID, "medicine");
|
||||
GameRegistry.register(medicine);
|
||||
|
||||
|
||||
@@ -2,9 +2,6 @@ package net.minecraftforge.debug;
|
||||
|
||||
import gnu.trove.set.TIntSet;
|
||||
import gnu.trove.set.hash.TIntHashSet;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
@@ -20,98 +17,107 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mod(modid = PotionRegistryDebug.MODID, name = "ForgePotionRegistry", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class PotionRegistryDebug {
|
||||
public static final String MODID = "forgepotionregistry";
|
||||
public class PotionRegistryDebug
|
||||
{
|
||||
public static final String MODID = "forgepotionregistry";
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
Potion forge = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forge"), false, 0xff00ff); // test automatic id distribution
|
||||
Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00); // test that ids above 127 work
|
||||
GameData.getPotionRegistry().register(-1, new ResourceLocation(ForgeVersion.MOD_ID, "forge"), forge); //TODo: Generic this out in GameRegistry, 'RegistryEntry' base type?
|
||||
GameData.getPotionRegistry().register(200, new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), forgy);
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
Potion forge = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forge"), false, 0xff00ff); // test automatic id distribution
|
||||
Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00); // test that ids above 127 work
|
||||
GameData.getPotionRegistry().register(-1, new ResourceLocation(ForgeVersion.MOD_ID, "forge"), forge); //TODo: Generic this out in GameRegistry, 'RegistryEntry' base type?
|
||||
GameData.getPotionRegistry().register(200, new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), forgy);
|
||||
|
||||
Random rand = new Random();
|
||||
TIntSet taken = new TIntHashSet(100);
|
||||
int ra = rand.nextInt(100) + 100;
|
||||
taken.add(ra);
|
||||
Random rand = new Random();
|
||||
TIntSet taken = new TIntHashSet(100);
|
||||
int ra = rand.nextInt(100) + 100;
|
||||
taken.add(ra);
|
||||
|
||||
// a new potion with a random id so that forge has to remap it
|
||||
//new PotionForge(ra, new ResourceLocation(ForgeModContainer.MOD_ID, "realRandomPotion"), false, 0x0000ff);
|
||||
// a new potion with a random id so that forge has to remap it
|
||||
//new PotionForge(ra, new ResourceLocation(ForgeModContainer.MOD_ID, "realRandomPotion"), false, 0x0000ff);
|
||||
|
||||
for(int i = 0; i < 20; i++) {
|
||||
int r = rand.nextInt(200) + 35;
|
||||
while(taken.contains(r))
|
||||
r = rand.nextInt(200) + 35;
|
||||
//r = 32+i;
|
||||
taken.add(r);
|
||||
// this potions will most likely not have the same IDs between server and client.
|
||||
// The forge handshake on connect should fix this.
|
||||
//new PotionForge(new ResourceLocation(ForgeModContainer.MOD_ID, "randomPotion" + r), false, 0xff00ff);
|
||||
}
|
||||
}
|
||||
|
||||
protected class PotionForge extends Potion {
|
||||
protected PotionForge(ResourceLocation location, boolean badEffect, int potionColor) {
|
||||
super(badEffect, potionColor);
|
||||
setPotionName("potion." + location.getResourcePath());
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
int r = rand.nextInt(200) + 35;
|
||||
while (taken.contains(r))
|
||||
r = rand.nextInt(200) + 35;
|
||||
//r = 32+i;
|
||||
taken.add(r);
|
||||
// this potions will most likely not have the same IDs between server and client.
|
||||
// The forge handshake on connect should fix this.
|
||||
//new PotionForge(new ResourceLocation(ForgeModContainer.MOD_ID, "randomPotion" + r), false, 0xff00ff);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryEffect(int x, int y, PotionEffect effect, Minecraft mc) {
|
||||
Potion potion = effect.getPotion();
|
||||
protected class PotionForge extends Potion
|
||||
{
|
||||
protected PotionForge(ResourceLocation location, boolean badEffect, int potionColor)
|
||||
{
|
||||
super(badEffect, potionColor);
|
||||
setPotionName("potion." + location.getResourcePath());
|
||||
}
|
||||
|
||||
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_0");
|
||||
@Override
|
||||
public void renderInventoryEffect(int x, int y, PotionEffect effect, Minecraft mc)
|
||||
{
|
||||
Potion potion = effect.getPotion();
|
||||
|
||||
x += 6;
|
||||
y += 7;
|
||||
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_0");
|
||||
|
||||
int width = 18;
|
||||
int height = width;
|
||||
x += 6;
|
||||
y += 7;
|
||||
|
||||
float r = (float)(potion.getLiquidColor() >> 24 & 255) / 255.0F;
|
||||
float g = (float)(potion.getLiquidColor() >> 16 & 255) / 255.0F;
|
||||
float b = (float)(potion.getLiquidColor() >> 8 & 255) / 255.0F;
|
||||
float a = (float)(potion.getLiquidColor() & 255) / 255.0F;
|
||||
int width = 18;
|
||||
int height = width;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
VertexBuffer buf = tessellator.getBuffer();
|
||||
buf.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||
GlStateManager.color(r, g, b, a);
|
||||
buf.pos((double) x, (double)(y + height), 0.0D).tex(sprite.getMinU(), sprite.getMaxV()).endVertex();
|
||||
buf.pos((double)(x + width), (double)(y + height), 0.0D).tex(sprite.getMaxU(), sprite.getMaxV()).endVertex();
|
||||
buf.pos((double)(x + width), (double) y, 0.0D).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
|
||||
buf.pos((double) x, (double) y, 0.0D).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
|
||||
tessellator.draw();
|
||||
float r = (float) (potion.getLiquidColor() >> 24 & 255) / 255.0F;
|
||||
float g = (float) (potion.getLiquidColor() >> 16 & 255) / 255.0F;
|
||||
float b = (float) (potion.getLiquidColor() >> 8 & 255) / 255.0F;
|
||||
float a = (float) (potion.getLiquidColor() & 255) / 255.0F;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
VertexBuffer buf = tessellator.getBuffer();
|
||||
buf.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||
GlStateManager.color(r, g, b, a);
|
||||
buf.pos((double) x, (double) (y + height), 0.0D).tex(sprite.getMinU(), sprite.getMaxV()).endVertex();
|
||||
buf.pos((double) (x + width), (double) (y + height), 0.0D).tex(sprite.getMaxU(), sprite.getMaxV()).endVertex();
|
||||
buf.pos((double) (x + width), (double) y, 0.0D).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
|
||||
buf.pos((double) x, (double) y, 0.0D).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHUDEffect(int x, int y, PotionEffect effect, Minecraft mc, float alpha)
|
||||
{
|
||||
Potion potion = effect.getPotion();
|
||||
|
||||
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/tnt_side");
|
||||
|
||||
x += 3;
|
||||
y += 3;
|
||||
|
||||
int width = 18;
|
||||
int height = width;
|
||||
|
||||
float r = (float) (potion.getLiquidColor() >> 24 & 255) / 255.0F;
|
||||
float g = (float) (potion.getLiquidColor() >> 16 & 255) / 255.0F;
|
||||
float b = (float) (potion.getLiquidColor() >> 8 & 255) / 255.0F;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
VertexBuffer buf = tessellator.getBuffer();
|
||||
buf.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||
GlStateManager.color(r, g, b, alpha);
|
||||
buf.pos((double) x, (double) (y + height), 0.0D).tex(sprite.getMinU(), sprite.getMaxV()).endVertex();
|
||||
buf.pos((double) (x + width), (double) (y + height), 0.0D).tex(sprite.getMaxU(), sprite.getMaxV()).endVertex();
|
||||
buf.pos((double) (x + width), (double) y, 0.0D).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
|
||||
buf.pos((double) x, (double) y, 0.0D).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHUDEffect(int x, int y, PotionEffect effect, Minecraft mc, float alpha) {
|
||||
Potion potion = effect.getPotion();
|
||||
|
||||
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/tnt_side");
|
||||
|
||||
x += 3;
|
||||
y += 3;
|
||||
|
||||
int width = 18;
|
||||
int height = width;
|
||||
|
||||
float r = (float)(potion.getLiquidColor() >> 24 & 255) / 255.0F;
|
||||
float g = (float)(potion.getLiquidColor() >> 16 & 255) / 255.0F;
|
||||
float b = (float)(potion.getLiquidColor() >> 8 & 255) / 255.0F;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
VertexBuffer buf = tessellator.getBuffer();
|
||||
buf.begin(7, DefaultVertexFormats.POSITION_TEX);
|
||||
GlStateManager.color(r, g, b, alpha);
|
||||
buf.pos((double) x, (double)(y + height), 0.0D).tex(sprite.getMinU(), sprite.getMaxV()).endVertex();
|
||||
buf.pos((double)(x + width), (double)(y + height), 0.0D).tex(sprite.getMaxU(), sprite.getMaxV()).endVertex();
|
||||
buf.pos((double)(x + width), (double) y, 0.0D).tex(sprite.getMaxU(), sprite.getMinV()).endVertex();
|
||||
buf.pos((double) x, (double) y, 0.0D).tex(sprite.getMinU(), sprite.getMinV()).endVertex();
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
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 TestCapabilityMod
|
||||
{
|
||||
// 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;
|
||||
|
||||
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.class);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onInteract(PlayerInteractEvent.LeftClickBlock event)
|
||||
{
|
||||
if (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 (!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()));
|
||||
}
|
||||
}
|
||||
|
||||
// these can be removed if we remove these legacy events
|
||||
@SubscribeEvent
|
||||
public void onItemLoadLegacy(AttachCapabilitiesEvent<Item> event)
|
||||
{
|
||||
if (event.getObject() == Items.APPLE)
|
||||
{
|
||||
event.addCapability(new ResourceLocation("forge.testcapmod:dummy_cap"), new Provider<Item>(event.getObject()));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemLoadLegacy(AttachCapabilitiesEvent.Item event)
|
||||
{
|
||||
if (event.getObject() == Items.ARROW)
|
||||
{
|
||||
event.addCapability(new ResourceLocation("forge.testcapmod:dummy_cap"), new Provider<Item>(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 (!event.world.isRemote)
|
||||
{
|
||||
List<EntityPlayer> players = event.world.playerEntities;
|
||||
int i = 0;
|
||||
for (Village village : event.world.villageCollectionObj.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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,37 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
@Mod(modid = TextureDump.MODID, name = "Forge Texture Atlas Dump", version = TextureDump.VERSION, clientSideOnly = true, acceptableRemoteVersions = "*")
|
||||
@Mod(modid = TextureDump.MODID, name = "Forge Texture Atlas Dump", version = TextureDump.VERSION, clientSideOnly = true)
|
||||
public class TextureDump
|
||||
{
|
||||
public static final String MODID = "forge_texture_dump";
|
||||
public static final String VERSION = "1.0";
|
||||
|
||||
public static final boolean ENABLE = true;
|
||||
public static final boolean ENABLE = false;
|
||||
private static Logger logger;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
@@ -71,11 +71,11 @@ public class TextureDump
|
||||
try
|
||||
{
|
||||
ImageIO.write(bufferedimage, "png", output);
|
||||
FMLLog.info("[TextureDump] Exported png to: %s", output.getAbsolutePath());
|
||||
logger.info("Exported png to: %s", output.getAbsolutePath());
|
||||
}
|
||||
catch (IOException ioexception)
|
||||
{
|
||||
FMLLog.info("[TextureDump] Unable to write: ", ioexception);
|
||||
logger.info("Unable to write: ", ioexception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Mod(modid = TileEntityLoadingTest.MOD_ID, name = "TileEntity#onLoad() test mod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class TileEntityLoadingTest
|
||||
{
|
||||
public static final boolean ENABLED = false;
|
||||
static final String MOD_ID = "te_loading_test";
|
||||
static final boolean DEBUG = false;
|
||||
|
||||
private static Logger logger;
|
||||
private static final Block testBlock = new TestBlock();
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
if (ENABLED)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
GameRegistry.register(testBlock);
|
||||
GameRegistry.register(new ItemBlock(testBlock).setRegistryName(testBlock.getRegistryName()));
|
||||
GameRegistry.registerTileEntity(TestTE.class, testBlock.getRegistryName().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestBlock extends Block
|
||||
{
|
||||
static final String NAME = "test_block";
|
||||
|
||||
TestBlock()
|
||||
{
|
||||
super(Material.ANVIL);
|
||||
setRegistryName(NAME);
|
||||
setUnlocalizedName(MOD_ID + "." + NAME);
|
||||
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state)
|
||||
{
|
||||
return new TestTE();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestTE extends TileEntity
|
||||
{
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
logger.info("World: " + world + ", Pos: " + pos + ", State: " + world.getBlockState(pos));
|
||||
if (DEBUG)
|
||||
{
|
||||
logger.trace("Stack trace:", new Exception());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerCareer;
|
||||
import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession;
|
||||
|
||||
@Mod(modid = "professiontest", name = "ProfessionTest2000", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@EventBusSubscriber
|
||||
public class VillagerProfessionTest
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerVillagers(RegistryEvent.Register<VillagerProfession> event)
|
||||
{
|
||||
VillagerProfession profession = new VillagerProfession("professiontest:test_villager", "professiontest:textures/entity/test_villager.png", "professiontest:textures/entity/zombie_test_villager.png");
|
||||
new VillagerCareer(profession, "professiontest:test_villager");
|
||||
event.getRegistry().register(profession);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.client.renderer.entity.RenderLivingBase;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityArmorStand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.client.registry.IRenderFactory;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
||||
|
||||
@Mod(modid = "wrnormal", name = "WRNormal", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class WRNormalMod
|
||||
{
|
||||
@Instance("wrnormal")
|
||||
public static WRNormalMod instance;
|
||||
|
||||
@SidedProxy
|
||||
public static ServerProxy proxy;
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLPreInitializationEvent event)
|
||||
{
|
||||
EntityRegistry.registerModEntity(new ResourceLocation("wrnormal", "scale_test"), EntityScaleTest.class, "scale_test", 0, instance, 60, 3, true);
|
||||
proxy.registerRenders();
|
||||
}
|
||||
|
||||
public static class ServerProxy
|
||||
{
|
||||
public void registerRenders()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClientProxy extends ServerProxy
|
||||
{
|
||||
@Override
|
||||
public void registerRenders()
|
||||
{
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityScaleTest.class, new RenderScaleTestFactory());
|
||||
}
|
||||
}
|
||||
|
||||
public static class RenderScaleTestFactory implements IRenderFactory<EntityScaleTest>
|
||||
{
|
||||
@Override
|
||||
public RenderScaleTest createRenderFor(RenderManager manager)
|
||||
{
|
||||
return new RenderScaleTest(manager);
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityScaleTest extends EntityArmorStand
|
||||
{
|
||||
public EntityScaleTest(World world)
|
||||
{
|
||||
super(world);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RenderScaleTest extends RenderLivingBase<EntityScaleTest>
|
||||
{
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation("textures/blocks/stone.png");
|
||||
|
||||
public RenderScaleTest(RenderManager manager)
|
||||
{
|
||||
super(manager, new ModelScaleTest(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderName(EntityScaleTest entity, double x, double y, double z)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceLocation getEntityTexture(EntityScaleTest entity)
|
||||
{
|
||||
return TEXTURE;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ModelScaleTest extends ModelBase
|
||||
{
|
||||
private ModelRenderer component;
|
||||
|
||||
public ModelScaleTest()
|
||||
{
|
||||
textureWidth = textureHeight = 16;
|
||||
component = new ModelRenderer(this);
|
||||
int size = 10;
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
for (int z = 0; z < size; z++)
|
||||
{
|
||||
component.addBox((x - size / 2) * 3, 0, (z - size / 2) * 3, 2, 2, 2, -(x + z * size) / (float) (size * size) * 0.5F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Entity entity, float p1, float p2, float p3, float p4, float p5, float scale)
|
||||
{
|
||||
component.render(scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
package net.minecraftforge.debug;
|
||||
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
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.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Simple mod to test world capability, by adding timer logic and check for raining time.
|
||||
*/
|
||||
@Mod(modid = WorldCapabilityRainTimerTest.MODID, name = "World Periodic Rain Check Test", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class WorldCapabilityRainTimerTest
|
||||
{
|
||||
public static final String MODID = "worldperiodicrainchecktest";
|
||||
|
||||
@CapabilityInject(IRainTimer.class)
|
||||
public static final Capability<IRainTimer> TIMER_CAP = null;
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
CapabilityManager.INSTANCE.register(IRainTimer.class, new TimerStorage(), DefaultTimer.class);
|
||||
MinecraftForge.EVENT_BUS.register(new NormalEventHandler());
|
||||
}
|
||||
|
||||
public static class NormalEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void attatchTimer(AttachCapabilitiesEvent.World event)
|
||||
{
|
||||
if (!event.getWorld().isRemote && !event.getWorld().provider.hasNoSky())
|
||||
{
|
||||
event.addCapability(new ResourceLocation(MODID, "rainTimer"), new RainTimerProvider());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent.WorldTickEvent event)
|
||||
{
|
||||
if (event.world.isRemote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IRainTimer timer = event.world.getCapability(TIMER_CAP, null);
|
||||
|
||||
if (timer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.phase == TickEvent.Phase.END)
|
||||
{
|
||||
timer.onTick();
|
||||
}
|
||||
|
||||
if (event.phase == TickEvent.Phase.START)
|
||||
{
|
||||
if (event.world.isRaining())
|
||||
{
|
||||
if (timer.getDuration() == 0)
|
||||
{
|
||||
timer.refreshTimer(1000, 0);
|
||||
}
|
||||
else if (timer.isTimerReachedDuration())
|
||||
{
|
||||
event.world.provider.resetRainAndThunder();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
timer.refreshTimer(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IRainTimer
|
||||
{
|
||||
public int getCurrentTime();
|
||||
|
||||
public int getDuration();
|
||||
|
||||
public void refreshTimer(int duration, int initial);
|
||||
|
||||
public void resetTimer();
|
||||
|
||||
public boolean isTimerReachedDuration();
|
||||
|
||||
public void onTick();
|
||||
}
|
||||
|
||||
public static class TimerStorage implements IStorage<IRainTimer>
|
||||
{
|
||||
@Override
|
||||
public NBTBase writeNBT(Capability<IRainTimer> capability, IRainTimer instance, EnumFacing side)
|
||||
{
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("current", instance.getCurrentTime());
|
||||
compound.setInteger("duration", instance.getDuration());
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<IRainTimer> capability, IRainTimer instance, EnumFacing side, NBTBase nbt)
|
||||
{
|
||||
NBTTagCompound data = (NBTTagCompound) nbt;
|
||||
instance.refreshTimer(data.getInteger("duration"), data.getInteger("current"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class DefaultTimer implements IRainTimer
|
||||
{
|
||||
private int duration, current;
|
||||
|
||||
@Override
|
||||
public int getCurrentTime()
|
||||
{
|
||||
return this.current;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDuration()
|
||||
{
|
||||
return this.duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshTimer(int duration, int initial)
|
||||
{
|
||||
this.duration = duration;
|
||||
this.current = initial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTimer()
|
||||
{
|
||||
this.current = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTimerReachedDuration()
|
||||
{
|
||||
return this.current >= this.duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
if (this.current < this.duration)
|
||||
{
|
||||
this.current++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RainTimerProvider implements ICapabilitySerializable<NBTTagCompound>
|
||||
{
|
||||
private IRainTimer timer = TIMER_CAP.getDefaultInstance();
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
return capability == TIMER_CAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
|
||||
{
|
||||
return capability == TIMER_CAP ? TIMER_CAP.<T>cast(this.timer) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeNBT()
|
||||
{
|
||||
return (NBTTagCompound) TIMER_CAP.writeNBT(this.timer, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTTagCompound nbt)
|
||||
{
|
||||
TIMER_CAP.readNBT(this.timer, null, nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
@Mod(modid = WrenchRotateDebug.modID, name = "Wrench Rotate Debug", version = "0.0.0")
|
||||
@Mod(modid = WrenchRotateDebug.modID, name = "Wrench Rotate Debug", version = "0.0.0", acceptableRemoteVersions = "*")
|
||||
public class WrenchRotateDebug
|
||||
{
|
||||
public static final String modID = "wrenchrotatedebug";
|
||||
|
||||
Reference in new issue
Block a user