ForgePatch/fml/bukkit/net/minecraft/server/BaseMod.java

410 lines
10 KiB
Java
Raw Normal View History

2012-04-15 03:01:03 +00:00
/*
* The FML Forge Mod Loader suite. Copyright (C) 2012 cpw
*
* 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
* Software Foundation; either version 2.1 of the License, or any later version.
*
* 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
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* 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
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraft.server;
2012-06-01 04:27:46 +00:00
import java.util.Map;
2012-04-15 03:01:03 +00:00
import java.util.Random;
2012-04-16 02:42:06 +00:00
import org.bukkit.craftbukkit.generator.NetherChunkGenerator;
import org.bukkit.craftbukkit.generator.NormalChunkGenerator;
2012-06-07 18:03:42 +00:00
import cpw.mods.fml.common.TickType;
2012-04-15 03:01:03 +00:00
public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseMod
2012-04-15 03:01:03 +00:00
{
// CALLBACK MECHANISMS
2012-06-01 04:27:46 +00:00
/**
* @param minecraftInstance
* @return
*/
public final boolean doTickInGame(TickType tick, boolean tickEnd, Object minecraftInstance, Object... data)
{
2012-06-07 18:03:42 +00:00
if (tick==TickType.GAME && tickEnd) {
2012-06-01 04:27:46 +00:00
return onTickInGame((MinecraftServer)minecraftInstance);
} else {
2012-06-01 15:08:15 +00:00
return true;
2012-06-01 04:27:46 +00:00
}
}
2012-04-15 03:01:03 +00:00
@Override
public final void onCrafting(Object... craftingParameters)
{
takenFromCrafting((EntityHuman)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]);
2012-04-15 03:01:03 +00:00
}
@Override
public final void onSmelting(Object... smeltingParameters)
{
takenFromFurnace((EntityHuman)smeltingParameters[0], (ItemStack)smeltingParameters[1]);
2012-04-15 03:01:03 +00:00
}
2012-06-01 04:27:46 +00:00
2012-04-15 03:01:03 +00:00
@Override
public final boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data)
{
return dispenseEntity((World)data[0], x, y, z, xVelocity, zVelocity, (ItemStack)data[1]);
}
@Override
public final boolean onChat(Object... data)
{
return onChatMessageReceived((EntityHuman)data[1], (Packet3Chat)data[0]);
2012-04-15 03:01:03 +00:00
}
2012-06-01 04:27:46 +00:00
@Override
public final void onServerLogin(Object handler) {
// NOOP
}
2012-06-01 04:27:46 +00:00
public final void onServerLogout() {
// NOOP
}
2012-04-15 03:01:03 +00:00
@Override
public final void onPlayerLogin(Object player)
{
onClientLogin((EntityHuman) player);
2012-04-15 03:01:03 +00:00
}
@Override
2012-06-01 04:27:46 +00:00
public final void onPlayerLogout(Object player)
2012-04-15 03:01:03 +00:00
{
onClientLogout((EntityHuman)player);
2012-04-15 03:01:03 +00:00
}
2012-04-15 03:01:03 +00:00
@Override
2012-06-01 04:27:46 +00:00
public final void onPlayerChangedDimension(Object player)
2012-04-15 03:01:03 +00:00
{
onClientDimensionChanged((EntityHuman)player);
2012-04-15 03:01:03 +00:00
}
@Override
public final void onPacket250Packet(Object... data)
{
onPacket250Received((EntityHuman)data[1], (Packet250CustomPayload)data[0]);
2012-04-15 03:01:03 +00:00
}
@Override
public final void notifyPickup(Object... pickupData)
{
EntityItem item = (EntityItem) pickupData[0];
EntityHuman player = (EntityHuman) pickupData[1];
2012-04-15 03:01:03 +00:00
onItemPickup(player, item.itemStack);
}
@Override
public final void generate(Random random, int chunkX, int chunkZ, Object... additionalData)
{
World w = (World) additionalData[0];
IChunkProvider cp = (IChunkProvider) additionalData[1];
2012-04-16 02:42:06 +00:00
if (cp instanceof ChunkProviderHell || cp instanceof NetherChunkGenerator)
2012-04-15 03:01:03 +00:00
{
2012-04-16 02:42:06 +00:00
generateNether(w, random, chunkX << 4, chunkZ << 4);
2012-04-15 03:01:03 +00:00
}
2012-04-16 02:42:06 +00:00
else if (cp instanceof ChunkProviderGenerate || cp instanceof NormalChunkGenerator)
2012-04-15 03:01:03 +00:00
{
2012-04-16 02:42:06 +00:00
generateSurface(w, random, chunkX << 4, chunkZ << 4);
2012-04-15 03:01:03 +00:00
}
}
2012-06-01 04:27:46 +00:00
/**
* NO-OP on client side
*/
2012-04-15 03:01:03 +00:00
@Override
public final boolean handleCommand(String command, Object... data)
{
return onServerCommand(command, (String)data[0], (ICommandListener)data[1]);
}
2012-06-01 04:27:46 +00:00
@Override
public void onRegisterAnimations() {
// NOOP on servers
}
2012-06-01 04:27:46 +00:00
@Override
public void onRenderHarvest(@SuppressWarnings("rawtypes") Map renderers) {
2012-06-01 04:27:46 +00:00
// NOOP on servers
}
2012-04-15 03:01:03 +00:00
// BASEMOD API
/**
* Override if you wish to provide a fuel item for the furnace and return the fuel value of the item
*
2012-04-15 03:01:03 +00:00
* @param id
* @param metadata
* @return
*/
public int addFuel(int id, int metadata)
{
return 0;
}
2012-06-01 04:27:46 +00:00
public void addRenderer(Map<Class<? extends Entity>, Object> renderers)
{
}
2012-04-15 03:01:03 +00:00
/**
* Override if you wish to perform some action other than just dispensing the item from the dispenser
*
2012-04-15 03:01:03 +00:00
* @param world
* @param x
* @param y
* @param z
* @param xVel
* @param zVel
* @param item
* @return
*/
public boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item)
{
return false;
}
/**
* Override if you wish to generate Nether (Hell biome) blocks
*
2012-04-15 03:01:03 +00:00
* @param world
* @param random
* @param chunkX
* @param chunkZ
*/
public void generateNether(World world, Random random, int chunkX, int chunkZ)
{
}
/**
* Override if you wish to generate Overworld (not hell or the end) blocks
*
2012-04-15 03:01:03 +00:00
* @param world
* @param random
* @param chunkX
* @param chunkZ
*/
public void generateSurface(World world, Random random, int chunkX, int chunkZ)
{
}
/**
* Return the name of your mod. Defaults to the class name
*
2012-04-15 03:01:03 +00:00
* @return
*/
public String getName()
{
return getClass().getSimpleName();
}
/**
* Get your mod priorities
*
2012-04-15 03:01:03 +00:00
* @return
*/
public String getPriorities()
{
2012-06-01 04:27:46 +00:00
return "";
2012-04-15 03:01:03 +00:00
}
/**
* Return the version of your mod
*
2012-04-15 03:01:03 +00:00
* @return
*/
public abstract String getVersion();
2012-06-01 04:27:46 +00:00
public void keyboardEvent(Object event)
{
}
2012-04-15 03:01:03 +00:00
/**
* Load your mod
*/
public abstract void load();
/**
* Finish loading your mod
*/
public void modsLoaded()
{
}
/**
* Handle item pickup
*
2012-04-15 03:01:03 +00:00
* @param player
* @param item
*/
public void onItemPickup(EntityHuman player, ItemStack item)
2012-04-15 03:01:03 +00:00
{
}
/**
* Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)}
*
2012-04-15 03:01:03 +00:00
* @param minecraftServer the server
* @return true to continue receiving ticks
*/
public boolean onTickInGame(MinecraftServer minecraftServer)
{
return false;
}
2012-06-01 04:27:46 +00:00
public boolean onTickInGUI(float tick, Object game, Object gui)
{
return false;
}
2012-04-15 03:01:03 +00:00
/**
2012-06-01 04:27:46 +00:00
* Only implemented on the client side
* {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)}
*
2012-04-15 03:01:03 +00:00
* @param text
*/
public void receiveChatPacket(String text)
{
2012-04-15 03:01:03 +00:00
}
/**
2012-06-01 04:27:46 +00:00
* Only called on the client side
* {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)}
*
2012-04-15 03:01:03 +00:00
* @param packet
*/
public void receiveCustomPacket(Packet250CustomPayload packet)
{
2012-06-01 04:27:46 +00:00
}
public void registerAnimation(Object game)
{
}
public void renderInvBlock(Object renderer, Block block, int metadata, int modelID)
{
}
public boolean renderWorldBlock(Object renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID)
{
return false;
2012-04-15 03:01:03 +00:00
}
/**
* Called when someone crafts an item from a crafting table
*
2012-04-15 03:01:03 +00:00
* @param player
* @param item
* @param matrix
*/
public void takenFromCrafting(EntityHuman player, ItemStack item, IInventory matrix)
2012-04-15 03:01:03 +00:00
{
}
/**
* Called when someone takes a smelted item from a furnace
*
* @param player
* @param item
*/
public void takenFromFurnace(EntityHuman player, ItemStack item)
2012-04-15 03:01:03 +00:00
{
}
/**
* The identifier string for the mod- used in client<->server negotiation
*/
@Override
public String toString()
{
return getName() + " " + getVersion();
}
/**
* Called when a 250 packet is received on a channel registered to this mod
*
* @param source
* @param payload
*/
public void onPacket250Received(EntityHuman source, Packet250CustomPayload payload)
2012-04-15 03:01:03 +00:00
{
}
/**
* Called when a chat message is received. Return true to stop further processing
*
2012-04-15 03:01:03 +00:00
* @param source
* @param chat
* @return true if you want to consume the message so it is not available for further processing
*/
public boolean onChatMessageReceived(EntityHuman source, Packet3Chat chat)
2012-04-15 03:01:03 +00:00
{
return false;
}
/**
* Called when a server command is received
* @param command
* @return true if you want to consume the message so it is not available for further processing
*/
public boolean onServerCommand(String command, String sender, ICommandListener listener)
{
return false;
}
/**
* Called when a new client logs in.
*
* @param player
2012-04-15 03:01:03 +00:00
*/
public void onClientLogin(EntityHuman player)
2012-04-15 03:01:03 +00:00
{
}
/**
* Called when a client logs out of the server.
*
2012-04-15 03:01:03 +00:00
* @param player
*/
public void onClientLogout(EntityHuman player)
2012-04-15 03:01:03 +00:00
{
2012-04-15 03:01:03 +00:00
}
/**
*
2012-04-15 03:01:03 +00:00
* Called when a client changes dimensions on the server.
*
2012-04-15 03:01:03 +00:00
* @param player
*/
public void onClientDimensionChanged(EntityHuman player)
2012-04-15 03:01:03 +00:00
{
2012-04-15 03:01:03 +00:00
}
// Spare client junk
// -------
// void addRenderer(Map<Class<? extends Entity>, Render> renderers);
// void registerAnimation(Minecraft game);
// void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID);
// boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID);
// boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui);
// void keyboardEvent(KeyBinding event);
2012-06-07 18:03:42 +00:00
@Override
public void keyBindingEvent(Object keybinding) {
// NOOP on server
}
2012-04-15 03:01:03 +00:00
}