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 */
013package net.minecraft.src;
014
015import static cpw.mods.fml.relauncher.Side.CLIENT;
016
017import java.util.Map;
018import java.util.Random;
019
020import net.minecraft.block.Block;
021import net.minecraft.client.*;
022import net.minecraft.client.entity.EntityClientPlayerMP;
023import net.minecraft.client.gui.GuiScreen;
024import net.minecraft.client.gui.inventory.GuiContainer;
025import net.minecraft.client.multiplayer.NetClientHandler;
026import net.minecraft.client.renderer.RenderBlocks;
027import net.minecraft.client.renderer.entity.Render;
028import net.minecraft.client.settings.KeyBinding;
029import net.minecraft.entity.Entity;
030import net.minecraft.entity.player.EntityPlayer;
031import net.minecraft.inventory.IInventory;
032import net.minecraft.item.ItemStack;
033import net.minecraft.network.INetworkManager;
034import net.minecraft.network.NetServerHandler;
035import net.minecraft.network.packet.NetHandler;
036import net.minecraft.network.packet.Packet250CustomPayload;
037import net.minecraft.server.MinecraftServer;
038import net.minecraft.world.IBlockAccess;
039import net.minecraft.world.World;
040import cpw.mods.fml.client.FMLClientHandler;
041import cpw.mods.fml.common.FMLLog;
042import cpw.mods.fml.common.TickType;
043import cpw.mods.fml.relauncher.SideOnly;
044
045public 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.field_70294_a);
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     * NOTE: this method is not provided in Risugami's implementation of BaseMod!
335     *
336     * @param packet
337     */
338    @Override
339    public void receiveCustomPacket(Packet250CustomPayload packet)
340    {
341    }
342
343    @SideOnly(CLIENT)
344    public void registerAnimation(Minecraft game)
345    {
346
347    }
348
349    @SideOnly(CLIENT)
350    public void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID)
351    {
352
353    }
354
355    @SideOnly(CLIENT)
356    public boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID)
357    {
358        return false;
359
360    }
361    /*
362     * NOTE: this method is not provided in Risugami's implementation of BaseMod!
363     */
364    @Override
365    public void serverConnect(NetHandler handler) {
366
367    }
368
369    @Override
370    public void serverCustomPayload(NetServerHandler handler, Packet250CustomPayload packet)
371    {
372
373    }
374
375    /*
376     * NOTE: this method is not provided in Risugami's implementation of BaseMod!
377     */
378    @Override
379    public void serverDisconnect() {
380
381    }
382    /**
383     * Called when someone crafts an item from a crafting table
384     *
385     * @param player
386     * @param item
387     * @param matrix
388     */
389    public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix)
390    {
391    }
392
393    /**
394     * Called when someone takes a smelted item from a furnace
395     *
396     * @param player
397     * @param item
398     */
399    public void takenFromFurnace(EntityPlayer player, ItemStack item)
400    {
401    }
402
403    /**
404     * The identifier string for the mod- used in client<->server negotiation
405     */
406    @Override
407    public String toString()
408    {
409        return getName() + " " + getVersion();
410    }
411
412    /**
413     * Called when a chat message is received. Return true to stop further processing
414     */
415    @Override
416    public void serverChat(NetServerHandler source, String message)
417    {
418    }
419    /**
420     * Called when a new client logs in.
421     * 
422     * NOTE: this method is not provided in Risugami's implementation of BaseMod!
423     *
424     * @param player
425     */
426    @Override
427    public void onClientLogin(EntityPlayer player)
428    {
429    }
430
431    /**
432     * Called when a client logs out of the server.
433     * 
434     * NOTE: this method is not provided in Risugami's implementation of BaseMod!
435     */
436    @Override
437    public void onClientLogout(INetworkManager mgr)
438    {
439
440    }
441
442    /**
443     * Spawn the entity of the supplied type, if it is your mod's
444     */
445    @SideOnly(CLIENT)
446    public Entity spawnEntity(int entityId, World world, double scaledX, double scaledY, double scaledZ)
447    {
448        return null;
449    }
450
451    public void clientCustomPayload(NetClientHandler handler, Packet250CustomPayload packet)
452    {
453
454    }
455
456}