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