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, int x, int y, int 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 #serverChat(EntityPlayer, Packet3Chat)} 325 * 326 * @param text 327 */ 328 @Override 329 public void clientChat(String text) 330 { 331 // TODO 332 } 333 334 /** 335 * Called client side to receive a custom payload for this mod 336 * 337 * @param packet 338 */ 339 @Override 340 public void receiveCustomPacket(Packet250CustomPayload packet) 341 { 342 // TODO 343 } 344 345 @SideOnly(CLIENT) 346 public void registerAnimation(Minecraft game) 347 { 348 349 } 350 351 @SideOnly(CLIENT) 352 public void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID) 353 { 354 355 } 356 357 @SideOnly(CLIENT) 358 public boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID) 359 { 360 return false; 361 362 } 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 @Override 376 public void serverDisconnect() { 377 378 } 379 /** 380 * Called when someone crafts an item from a crafting table 381 * 382 * @param player 383 * @param item 384 * @param matrix 385 */ 386 public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) 387 { 388 } 389 390 /** 391 * Called when someone takes a smelted item from a furnace 392 * 393 * @param player 394 * @param item 395 */ 396 public void takenFromFurnace(EntityPlayer player, ItemStack item) 397 { 398 } 399 400 /** 401 * The identifier string for the mod- used in client<->server negotiation 402 */ 403 @Override 404 public String toString() 405 { 406 return getName() + " " + getVersion(); 407 } 408 409 /** 410 * Called when a chat message is received. Return true to stop further processing 411 * 412 * @param source 413 * @param chat 414 * @return true if you want to consume the message so it is not available for further processing 415 */ 416 @Override 417 public void serverChat(NetServerHandler source, String message) 418 { 419 } 420 /** 421 * Called when a new client logs in. 422 * 423 * @param player 424 */ 425 @Override 426 public void onClientLogin(EntityPlayer player) 427 { 428 } 429 430 /** 431 * Called when a client logs out of the server. 432 * 433 * @param player 434 */ 435 @Override 436 public void onClientLogout(NetworkManager mgr) 437 { 438 439 } 440 441 /** 442 * 443 * Spawn the entity of the supplied type, if it is your mod's 444 * @param entityId 445 * @param world 446 * @param scaledX 447 * @param scaledY 448 * @param scaledZ 449 * @return 450 */ 451 @SideOnly(CLIENT) 452 public Entity spawnEntity(int entityId, World world, double scaledX, double scaledY, double scaledZ) 453 { 454 return null; 455 } 456 457 public void clientCustomPayload(NetClientHandler handler, Packet250CustomPayload packet) 458 { 459 460 } 461 462 }