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