    001    /*
    002     * The FML Forge Mod Loader suite. Copyright (C) 2012 cpw
    003     *
    004     * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
    005     * Software Foundation; either version 2.1 of the License, or any later version.
    006     *
    007     * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
    008     * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    009     *
    010     * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
    011     * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
    012     */
    013    package net.minecraft.src;
    014
    015    import static cpw.mods.fml.common.Side.CLIENT;
    016
    017    import java.util.Map;
    018    import java.util.Random;
    019
    020    import net.minecraft.block.Block;
    021    import net.minecraft.client.*;
    022    import net.minecraft.client.entity.EntityClientPlayerMP;
    023    import net.minecraft.client.gui.GuiScreen;
    024    import net.minecraft.client.gui.inventory.GuiContainer;
    025    import net.minecraft.client.multiplayer.NetClientHandler;
    026    import net.minecraft.client.renderer.RenderBlocks;
    027    import net.minecraft.client.renderer.entity.Render;
    028    import net.minecraft.client.settings.KeyBinding;
    029    import net.minecraft.entity.Entity;
    030    import net.minecraft.entity.player.EntityPlayer;
    031    import net.minecraft.inventory.IInventory;
    032    import net.minecraft.item.ItemStack;
    033    import net.minecraft.network.INetworkManager;
    034    import net.minecraft.network.NetServerHandler;
    035    import net.minecraft.network.packet.NetHandler;
    036    import net.minecraft.network.packet.Packet250CustomPayload;
    037    import net.minecraft.server.MinecraftServer;
    038    import net.minecraft.world.IBlockAccess;
    039    import net.minecraft.world.World;
    040    import cpw.mods.fml.client.FMLClientHandler;
    041    import cpw.mods.fml.common.FMLLog;
    042    import cpw.mods.fml.common.TickType;
    043    import cpw.mods.fml.common.asm.SideOnly;
    044
    045    public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModProxy
    046    {
    047        // CALLBACK MECHANISMS
    048
    049        public final boolean doTickInGame(TickType tick, boolean tickEnd, Object... data)
    050        {
    051            Minecraft mc = FMLClientHandler.instance().getClient();
    052            boolean hasWorld = mc.theWorld != null;
    053            // World and render ticks
    054            if (tickEnd && ( tick==TickType.RENDER || tick==TickType.CLIENT ) && hasWorld) {
    055                return onTickInGame((Float) data[0], mc);
    056            }
    057            return true;
    058        }
    059
    060        public final boolean doTickInGUI(TickType tick, boolean tickEnd, Object... data)
    061        {
    062            Minecraft mc = FMLClientHandler.instance().getClient();
    063
    064            boolean hasWorld = mc.theWorld != null;
    065
    066            if (tickEnd && ( tick==TickType.RENDER || ( tick==TickType.CLIENT && hasWorld))) {
    067                return onTickInGUI((Float) data[0], mc, mc.currentScreen);
    068            }
    069            return true;
    070        }
    071
    072       /*
    073        public final void onRenderHarvest(Map renderers)
    074        {
    075            addRenderer((Map<Class<? extends Entity>,Render>)renderers);
    076        }
    077
    078        public final void onRegisterAnimations()
    079        {
    080            registerAnimation(FMLClientHandler.instance().getClient());
    081        }
    082
    083        @Override
    084        public final void onCrafting(Object... craftingParameters)
    085        {
    086            takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]);
    087        }
    088
    089        @Override
    090        public final void onSmelting(Object... smeltingParameters)
    091        {
    092            takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]);
    093        }
    094
    095        @Override
    096        public final boolean dispense(double x, double y, double z, int xVelocity, int zVelocity, Object... data)
    097        {
    098            return dispenseEntity((World)data[0], x, y, z, xVelocity, zVelocity, (ItemStack)data[1]);
    099        }
    100
    101        @Override
    102        public final boolean onChat(Object... data)
    103        {
    104            receiveChatPacket(((Packet3Chat)data[0]).message);
    105            return true;
    106        }
    107
    108
    109        @Override
    110        public final void onServerLogin(Object handler) {
    111            serverConnect((NetClientHandler) handler);
    112        }
    113
    114        public final void onServerLogout() {
    115            serverDisconnect();
    116        }
    117
    118        @Override
    119        public final void onPlayerLogin(Object player)
    120        {
    121            onClientLogin((EntityPlayer) player);
    122        }
    123
    124        @Override
    125        public final void onPlayerLogout(Object player)
    126        {
    127            onClientLogout((EntityPlayer)player);
    128        }
    129
    130        @Override
    131        public final void onPlayerChangedDimension(Object player)
    132        {
    133            onClientDimensionChanged((EntityPlayer)player);
    134        }
    135
    136        @Override
    137        public final void onPacket250Packet(Object... data)
    138        {
    139            receiveCustomPacket((Packet250CustomPayload)data[0]);
    140        }
    141
    142        @Override
    143        public final void notifyPickup(Object... pickupData)
    144        {
    145            EntityItem item = (EntityItem) pickupData[0];
    146            EntityPlayer player = (EntityPlayer) pickupData[1];
    147            onItemPickup(player, item.item);
    148        }
    149
    150        @Override
    151        public final void generate(Random random, int chunkX, int chunkZ, Object... additionalData)
    152        {
    153            World w = (World) additionalData[0];
    154            IChunkProvider cp = (IChunkProvider) additionalData[1];
    155
    156            if (cp instanceof ChunkProviderGenerate)
    157            {
    158                generateSurface(w, random, chunkX << 4, chunkZ << 4);
    159            }
    160            else if (cp instanceof ChunkProviderHell)
    161            {
    162                generateNether(w, random, chunkX << 4, chunkZ << 4);
    163            }
    164        }
    165
    166        @Override
    167        public final boolean handleCommand(String command, Object... data)
    168        {
    169            return false;
    170        }
    171
    172        */
    173        // BASEMOD API
    174        /**
    175         * Override if you wish to provide a fuel item for the furnace and return the fuel value of the item
    176         *
    177         * @param id
    178         * @param metadata
    179         */
    180        public int addFuel(int id, int metadata)
    181        {
    182            return 0;
    183        }
    184
    185        @SideOnly(CLIENT)
    186        public void addRenderer(Map<Class<? extends Entity>, Render> renderers)
    187        {
    188        }
    189
    190        /**
    191         * Override if you wish to generate Nether (Hell biome) blocks
    192         *
    193         * @param world
    194         * @param random
    195         * @param chunkX
    196         * @param chunkZ
    197         */
    198        public void generateNether(World world, Random random, int chunkX, int chunkZ)
    199        {
    200        }
    201
    202        /**
    203         * Override if you wish to generate Overworld (not hell or the end) blocks
    204         *
    205         * @param world
    206         * @param random
    207         * @param chunkX
    208         * @param chunkZ
    209         */
    210        public void generateSurface(World world, Random random, int chunkX, int chunkZ)
    211        {
    212        }
    213
    214        /**
    215         * Callback to return a gui screen to display
    216         * @param player
    217         * @param containerID
    218         * @param x
    219         * @param y
    220         * @param z
    221         */
    222        @SideOnly(CLIENT)
    223        public GuiContainer getContainerGUI(EntityClientPlayerMP player, int containerID, int x, int y, int z)
    224        {
    225            return null;
    226        }
    227
    228        /**
    229         * Return the name of your mod. Defaults to the class name
    230         */
    231        public String getName()
    232        {
    233            return getClass().getSimpleName();
    234        }
    235
    236        /**
    237         * Get your mod priorities
    238         */
    239        public String getPriorities()
    240        {
    241            return "";
    242        }
    243
    244        /**
    245         * Return the version of your mod
    246         */
    247        public abstract String getVersion();
    248
    249        @SideOnly(CLIENT)
    250        public void keyboardEvent(KeyBinding event)
    251        {
    252
    253        }
    254
    255        /**
    256         * Load your mod
    257         */
    258        public abstract void load();
    259
    260        /**
    261         * Finish loading your mod
    262         */
    263        public void modsLoaded()
    264        {
    265        }
    266
    267        /**
    268         * Handle item pickup
    269         *
    270         * @param player
    271         * @param item
    272         */
    273        public void onItemPickup(EntityPlayer player, ItemStack item)
    274        {
    275        }
    276
    277        /**
    278         * Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)}
    279         *
    280         * @param time the rendering subtick time (0.0-1.0)
    281         * @param minecraftInstance the client
    282         * @return true to continue receiving ticks
    283         */
    284        @SideOnly(CLIENT)
    285        public boolean onTickInGame(float time, Minecraft minecraftInstance)
    286        {
    287            return false;
    288        }
    289
    290        public boolean onTickInGame(MinecraftServer minecraftServer)
    291        {
    292            return false;
    293        }
    294
    295        @SideOnly(CLIENT)
    296        public boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui)
    297        {
    298            return false;
    299        }
    300
    301        /**
    302         * Only implemented on the client side
    303         * {@link #serverChat(NetServerHandler, String)}
    304         *
    305         * @param text
    306         */
    307        @Override
    308        public void clientChat(String text)
    309        {
    310        }
    311
    312        /**
    313         * Called when a client connects
    314         * @param handler
    315         */
    316        @SideOnly(CLIENT)
    317        public void clientConnect(NetClientHandler handler)
    318        {
    319
    320        }
    321
    322        /**
    323         * Called when the client disconnects
    324         * @param handler
    325         */
    326        @SideOnly(CLIENT)
    327        public void clientDisconnect(NetClientHandler handler)
    328        {
    329
    330        }
    331        /**
    332         * Called client side to receive a custom payload for this mod
    333         *
    334         * @param packet
    335         */
    336        @Override
    337        public void receiveCustomPacket(Packet250CustomPayload packet)
    338        {
    339        }
    340
    341        @SideOnly(CLIENT)
    342        public void registerAnimation(Minecraft game)
    343        {
    344
    345        }
    346
    347        @SideOnly(CLIENT)
    348        public void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID)
    349        {
    350
    351        }
    352
    353        @SideOnly(CLIENT)
    354        public boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID)
    355        {
    356            return false;
    357
    358        }
    359
    360        @Override
    361        public void serverConnect(NetHandler handler) {
    362
    363        }
    364
    365        @Override
    366        public void serverCustomPayload(NetServerHandler handler, Packet250CustomPayload packet)
    367        {
    368
    369        }
    370
    371        @Override
    372        public void serverDisconnect() {
    373
    374        }
    375        /**
    376         * Called when someone crafts an item from a crafting table
    377         *
    378         * @param player
    379         * @param item
    380         * @param matrix
    381         */
    382        public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix)
    383        {
    384        }
    385
    386        /**
    387         * Called when someone takes a smelted item from a furnace
    388         *
    389         * @param player
    390         * @param item
    391         */
    392        public void takenFromFurnace(EntityPlayer player, ItemStack item)
    393        {
    394        }
    395
    396        /**
    397         * The identifier string for the mod- used in client<->server negotiation
    398         */
    399        @Override
    400        public String toString()
    401        {
    402            return getName() + " " + getVersion();
    403        }
    404
    405        /**
    406         * Called when a chat message is received. Return true to stop further processing
    407         */
    408        @Override
    409        public void serverChat(NetServerHandler source, String message)
    410        {
    411        }
    412        /**
    413         * Called when a new client logs in.
    414         *
    415         * @param player
    416         */
    417        @Override
    418        public void onClientLogin(EntityPlayer player)
    419        {
    420        }
    421
    422        /**
    423         * Called when a client logs out of the server.
    424         */
    425        @Override
    426        public void onClientLogout(INetworkManager mgr)
    427        {
    428
    429        }
    430
    431        /**
    432         * Spawn the entity of the supplied type, if it is your mod's
    433         */
    434        @SideOnly(CLIENT)
    435        public Entity spawnEntity(int entityId, World world, double scaledX, double scaledY, double scaledZ)
    436        {
    437            return null;
    438        }
    439
    440        public void clientCustomPayload(NetClientHandler handler, Packet250CustomPayload packet)
    441        {
    442
    443        }
    444
    445    }