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 perform some action other than just dispensing the item from the dispenser 174 * 175 * @param world 176 * @param x 177 * @param y 178 * @param z 179 * @param xVel 180 * @param zVel 181 * @param item 182 */ 183 @Override 184 public int dispenseEntity(World world, ItemStack item, Random rnd, int x, int y, int z, int xVel, int zVel, double entX, double entY, double entZ) 185 { 186 return -1; 187 } 188 189 /** 190 * Override if you wish to generate Nether (Hell biome) blocks 191 * 192 * @param world 193 * @param random 194 * @param chunkX 195 * @param chunkZ 196 */ 197 public void generateNether(World world, Random random, int chunkX, int chunkZ) 198 { 199 } 200 201 /** 202 * Override if you wish to generate Overworld (not hell or the end) blocks 203 * 204 * @param world 205 * @param random 206 * @param chunkX 207 * @param chunkZ 208 */ 209 public void generateSurface(World world, Random random, int chunkX, int chunkZ) 210 { 211 } 212 213 /** 214 * Callback to return a gui screen to display 215 * @param player 216 * @param containerID 217 * @param x 218 * @param y 219 * @param z 220 */ 221 @SideOnly(CLIENT) 222 public GuiContainer getContainerGUI(EntityClientPlayerMP player, int containerID, int x, int y, int z) 223 { 224 return null; 225 } 226 227 /** 228 * Return the name of your mod. Defaults to the class name 229 */ 230 public String getName() 231 { 232 return getClass().getSimpleName(); 233 } 234 235 /** 236 * Get your mod priorities 237 */ 238 public String getPriorities() 239 { 240 return ""; 241 } 242 243 /** 244 * Return the version of your mod 245 */ 246 public abstract String getVersion(); 247 248 @SideOnly(CLIENT) 249 public void keyboardEvent(KeyBinding event) 250 { 251 252 } 253 254 /** 255 * Load your mod 256 */ 257 public abstract void load(); 258 259 /** 260 * Finish loading your mod 261 */ 262 public void modsLoaded() 263 { 264 } 265 266 /** 267 * Handle item pickup 268 * 269 * @param player 270 * @param item 271 */ 272 public void onItemPickup(EntityPlayer player, ItemStack item) 273 { 274 } 275 276 /** 277 * Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)} 278 * 279 * @param time the rendering subtick time (0.0-1.0) 280 * @param minecraftInstance the client 281 * @return true to continue receiving ticks 282 */ 283 @SideOnly(CLIENT) 284 public boolean onTickInGame(float time, Minecraft minecraftInstance) 285 { 286 return false; 287 } 288 289 public boolean onTickInGame(MinecraftServer minecraftServer) 290 { 291 return false; 292 } 293 294 @SideOnly(CLIENT) 295 public boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui) 296 { 297 return false; 298 } 299 300 /** 301 * Only implemented on the client side 302 * {@link #serverChat(EntityPlayer, Packet3Chat)} 303 * 304 * @param text 305 */ 306 @Override 307 public void clientChat(String text) 308 { 309 } 310 311 /** 312 * Called when a client connects 313 * @param handler 314 */ 315 @SideOnly(CLIENT) 316 public void clientConnect(NetClientHandler handler) 317 { 318 319 } 320 321 /** 322 * Called when the client disconnects 323 * @param handler 324 */ 325 @SideOnly(CLIENT) 326 public void clientDisconnect(NetClientHandler handler) 327 { 328 329 } 330 /** 331 * Called client side to receive a custom payload for this mod 332 * 333 * @param packet 334 */ 335 @Override 336 public void receiveCustomPacket(Packet250CustomPayload packet) 337 { 338 } 339 340 @SideOnly(CLIENT) 341 public void registerAnimation(Minecraft game) 342 { 343 344 } 345 346 @SideOnly(CLIENT) 347 public void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID) 348 { 349 350 } 351 352 @SideOnly(CLIENT) 353 public boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID) 354 { 355 return false; 356 357 } 358 359 @Override 360 public void serverConnect(NetHandler handler) { 361 362 } 363 364 @Override 365 public void serverCustomPayload(NetServerHandler handler, Packet250CustomPayload packet) 366 { 367 368 } 369 370 @Override 371 public void serverDisconnect() { 372 373 } 374 /** 375 * Called when someone crafts an item from a crafting table 376 * 377 * @param player 378 * @param item 379 * @param matrix 380 */ 381 public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) 382 { 383 } 384 385 /** 386 * Called when someone takes a smelted item from a furnace 387 * 388 * @param player 389 * @param item 390 */ 391 public void takenFromFurnace(EntityPlayer player, ItemStack item) 392 { 393 } 394 395 /** 396 * The identifier string for the mod- used in client<->server negotiation 397 */ 398 @Override 399 public String toString() 400 { 401 return getName() + " " + getVersion(); 402 } 403 404 /** 405 * Called when a chat message is received. Return true to stop further processing 406 */ 407 @Override 408 public void serverChat(NetServerHandler source, String message) 409 { 410 } 411 /** 412 * Called when a new client logs in. 413 * 414 * @param player 415 */ 416 @Override 417 public void onClientLogin(EntityPlayer player) 418 { 419 } 420 421 /** 422 * Called when a client logs out of the server. 423 */ 424 @Override 425 public void onClientLogout(NetworkManager mgr) 426 { 427 428 } 429 430 /** 431 * Spawn the entity of the supplied type, if it is your mod's 432 */ 433 @SideOnly(CLIENT) 434 public Entity spawnEntity(int entityId, World world, double scaledX, double scaledY, double scaledZ) 435 { 436 return null; 437 } 438 439 public void clientCustomPayload(NetClientHandler handler, Packet250CustomPayload packet) 440 { 441 442 } 443 444 }