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 * @param minecraftInstance 056 * @return 057 *//* 058 059 *//** 060 * @param renderers 061 *//* 062 public final void onRenderHarvest(Map renderers) 063 { 064 addRenderer((Map<Class<? extends Entity>,Render>)renderers); 065 066 } 067 068 *//** 069 * 070 *//* 071 public final void onRegisterAnimations() 072 { 073 registerAnimation(FMLClientHandler.instance().getClient()); 074 } 075 076 @Override 077 public final void onCrafting(Object... craftingParameters) 078 { 079 takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]); 080 } 081 082 @Override 083 public final void onSmelting(Object... smeltingParameters) 084 { 085 takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]); 086 } 087 088 @Override 089 public final boolean dispense(double x, double y, double z, int xVelocity, int zVelocity, Object... data) 090 { 091 return dispenseEntity((World)data[0], x, y, z, xVelocity, zVelocity, (ItemStack)data[1]); 092 } 093 094 @Override 095 public final boolean onChat(Object... data) 096 { 097 receiveChatPacket(((Packet3Chat)data[0]).message); 098 return true; 099 } 100 101 102 @Override 103 public final void onServerLogin(Object handler) { 104 serverConnect((NetClientHandler) handler); 105 } 106 107 public final void onServerLogout() { 108 serverDisconnect(); 109 } 110 111 @Override 112 public final void onPlayerLogin(Object player) 113 { 114 onClientLogin((EntityPlayer) player); 115 } 116 117 @Override 118 public final void onPlayerLogout(Object player) 119 { 120 onClientLogout((EntityPlayer)player); 121 } 122 123 @Override 124 public final void onPlayerChangedDimension(Object player) 125 { 126 onClientDimensionChanged((EntityPlayer)player); 127 } 128 129 @Override 130 public final void onPacket250Packet(Object... data) 131 { 132 receiveCustomPacket((Packet250CustomPayload)data[0]); 133 } 134 135 @Override 136 public final void notifyPickup(Object... pickupData) 137 { 138 EntityItem item = (EntityItem) pickupData[0]; 139 EntityPlayer player = (EntityPlayer) pickupData[1]; 140 onItemPickup(player, item.item); 141 } 142 143 @Override 144 public final void generate(Random random, int chunkX, int chunkZ, Object... additionalData) 145 { 146 World w = (World) additionalData[0]; 147 IChunkProvider cp = (IChunkProvider) additionalData[1]; 148 149 if (cp instanceof ChunkProviderGenerate) 150 { 151 generateSurface(w, random, chunkX << 4, chunkZ << 4); 152 } 153 else if (cp instanceof ChunkProviderHell) 154 { 155 generateNether(w, random, chunkX << 4, chunkZ << 4); 156 } 157 } 158 159 *//** 160 * NO-OP on client side 161 *//* 162 @Override 163 public final boolean handleCommand(String command, Object... data) 164 { 165 return false; 166 } 167 168 */ // BASEMOD API 169 /** 170 * Override if you wish to provide a fuel item for the furnace and return the fuel value of the item 171 * 172 * @param id 173 * @param metadata 174 * @return 175 */ 176 public int addFuel(int id, int metadata) 177 { 178 return 0; 179 } 180 181 @SideOnly(CLIENT) 182 public void addRenderer(Map<Class<? extends Entity>, Render> renderers) 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 }