From 41f1a60f3272a38d07983546177aead1f165472c Mon Sep 17 00:00:00 2001 From: LexManos Date: Tue, 7 Aug 2012 01:24:06 -0700 Subject: [PATCH] More conversions, added all the entity living events. --- .../client/ForgeHooksClient.java | 175 +++++++++++ .../client/MinecraftForgeClient.java | 33 +- .../client/event/ClientChatReceivedEvent.java | 14 + .../client/event/DrawBlockHighlightEvent.java | 30 ++ .../client/event/RenderWorldLastEvent.java | 15 + .../client/event/TextureLoadEvent.java | 17 ++ .../client/event/sound/SoundEvent.java | 122 ++++++++ .../common/AchievementPage.java | 108 +++++++ .../minecraftforge/common/DungeonHooks.java | 285 ++++++++++++++++++ .../net/minecraftforge/common/ForgeHooks.java | 6 + .../common/MinecartRegistry.java | 215 +++++++++++++ .../minecraftforge/common/MinecraftForge.java | 2 - .../net/minecraftforge/event/Cancelable.java | 11 + common/net/minecraftforge/event/Event.java | 14 +- common/net/minecraftforge/event/EventBus.java | 3 +- .../event/entity/UseHoeEvent.java | 8 +- .../entity/living/LivingAttackEvent.java | 18 ++ .../event/entity/living/LivingDeathEvent.java | 17 ++ .../event/entity/living/LivingDropsEvent.java | 28 ++ .../event/entity/living/LivingEvent.java | 12 + .../event/entity/living/LivingFallEvent.java | 15 + .../event/entity/living/LivingHurtEvent.java | 19 ++ .../living/LivingSetAttackTargetEvent.java | 15 + .../event/entity/player/ArrowLooseEvent.java | 8 +- .../event/entity/player/ArrowNockEvent.java | 8 +- .../event/entity/player/BonemealEvent.java | 8 +- .../entity/player/EntityItemPickupEvent.java | 8 +- .../event/entity/player/FillBucketEvent.java | 8 +- .../entity/player/PlayerDestroyItemEvent.java | 15 + .../entity/player/PlayerSleepInBedEvent.java | 21 ++ .../packets/PacketHandlerBase.java | 1 - .../minecraft/src/WorldGenDungeons.java.patch | 18 +- .../net/minecraft/src/Block.java.patch | 14 +- .../net/minecraft/src/EntityLiving.java.patch | 52 ++-- .../net/minecraft/src/EntityPlayer.java.patch | 52 ++-- .../minecraft/src/EntityRenderer.java.patch | 23 +- .../minecraft/src/GuiAchievements.java.patch | 38 +-- .../net/minecraft/src/Item.java.patch | 16 +- .../net/minecraft/src/ItemRenderer.java.patch | 3 +- .../minecraft/src/NetClientHandler.java.patch | 22 +- .../src/PlayerControllerMP.java.patch | 18 +- .../net/minecraft/src/SoundManager.java.patch | 33 +- .../minecraft/src/WorldRenderer.java.patch | 2 +- 43 files changed, 1343 insertions(+), 207 deletions(-) create mode 100644 client/net/minecraftforge/client/event/ClientChatReceivedEvent.java create mode 100644 client/net/minecraftforge/client/event/DrawBlockHighlightEvent.java create mode 100644 client/net/minecraftforge/client/event/RenderWorldLastEvent.java create mode 100644 client/net/minecraftforge/client/event/TextureLoadEvent.java create mode 100644 client/net/minecraftforge/client/event/sound/SoundEvent.java create mode 100644 common/net/minecraftforge/common/AchievementPage.java create mode 100644 common/net/minecraftforge/common/DungeonHooks.java create mode 100644 common/net/minecraftforge/common/MinecartRegistry.java create mode 100644 common/net/minecraftforge/event/Cancelable.java create mode 100644 common/net/minecraftforge/event/entity/living/LivingAttackEvent.java create mode 100644 common/net/minecraftforge/event/entity/living/LivingDeathEvent.java create mode 100644 common/net/minecraftforge/event/entity/living/LivingDropsEvent.java create mode 100644 common/net/minecraftforge/event/entity/living/LivingFallEvent.java create mode 100644 common/net/minecraftforge/event/entity/living/LivingHurtEvent.java create mode 100644 common/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java create mode 100644 common/net/minecraftforge/event/entity/player/PlayerDestroyItemEvent.java create mode 100644 common/net/minecraftforge/event/entity/player/PlayerSleepInBedEvent.java diff --git a/client/net/minecraftforge/client/ForgeHooksClient.java b/client/net/minecraftforge/client/ForgeHooksClient.java index 4b6e8fa571..38d1a1e60f 100644 --- a/client/net/minecraftforge/client/ForgeHooksClient.java +++ b/client/net/minecraftforge/client/ForgeHooksClient.java @@ -1,16 +1,29 @@ package net.minecraftforge.client; import java.util.HashMap; +import java.util.Random; import java.util.TreeSet; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; +import net.minecraft.client.Minecraft; import net.minecraft.src.Block; +import net.minecraft.src.EntityItem; +import net.minecraft.src.EntityLiving; +import net.minecraft.src.Item; +import net.minecraft.src.ItemBlock; import net.minecraft.src.ItemStack; import net.minecraft.src.ModLoader; import net.minecraft.src.RenderBlocks; +import net.minecraft.src.RenderEngine; import net.minecraft.src.Tessellator; +import net.minecraft.src.TexturePackBase; +import net.minecraftforge.client.event.TextureLoadEvent; import net.minecraftforge.common.IArmorTextureProvider; +import net.minecraftforge.common.MinecraftForge; +import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*; +import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*; public class ForgeHooksClient { @@ -201,4 +214,166 @@ public class ForgeHooksClient } return _default; } + + /** + * This is added for Optifine's convenience. And to explode if a ModMaker is developing. + * @param texture + */ + public static void onTextureLoadPre(String texture) + { + if (Tessellator.renderingWorldRenderer) + { + String msg = String.format("Warning: Texture %s not preloaded, will cause render glitches!", texture); + System.out.println(msg); + if (Tessellator.class.getPackage() != null) + { + if (Tessellator.class.getPackage().equals("net.minecraft.src")) + { + Minecraft mc = ModLoader.getMinecraftInstance(); + if (mc.ingameGUI != null) + { + mc.ingameGUI.func_73827_b().func_73765_a(msg); + } + } + } + } + } + + public static void onTextureLoad(String texture, TexturePackBase pack) + { + MinecraftForge.EVENT_BUS.post(new TextureLoadEvent(texture, pack)); + } + + public static boolean renderEntityItem(EntityItem entity, ItemStack item, float bobing, float rotation, Random random, RenderEngine engine, RenderBlocks renderBlocks) + { + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, ENTITY); + + if (customRenderer == null) + { + return false; + } + + if (customRenderer.shouldUseRenderHelper(ENTITY, item, ENTITY_ROTATION)) + { + GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F); + } + if (!customRenderer.shouldUseRenderHelper(ENTITY, item, ENTITY_BOBBING)) + { + GL11.glTranslatef(0.0F, -bobing, 0.0F); + } + boolean is3D = customRenderer.shouldUseRenderHelper(ENTITY, item, BLOCK_3D); + + if (item.getItem() instanceof ItemBlock && (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType()))) + { + engine.bindTexture(engine.getTexture(item.getItem().getTextureFile())); + int renderType = Block.blocksList[item.itemID].getRenderType(); + float scale = (renderType == 1 || renderType == 19 || renderType == 12 || renderType == 2 ? 0.5F : 0.25F); + + GL11.glScalef(scale, scale, scale); + int size = entity.item.stackSize; + int count = (size > 20 ? 4 : (size > 5 ? 3 : (size > 1 ? 2 : 1))); + + for(int j = 0; j < size; j++) + { + GL11.glPushMatrix(); + if (j > 0) + { + GL11.glTranslatef( + ((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F, + ((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F, + ((random.nextFloat() * 2.0F - 1.0F) * 0.2F) / 0.5F); + } + customRenderer.renderItem(ENTITY, item, renderBlocks, entity); + GL11.glPopMatrix(); + } + } + else + { + engine.bindTexture(engine.getTexture(item.getItem().getTextureFile())); + GL11.glScalef(0.5F, 0.5F, 0.5F); + customRenderer.renderItem(ENTITY, item, renderBlocks, entity); + } + return true; + } + + public static boolean renderInventoryItem(RenderBlocks renderBlocks, RenderEngine engine, ItemStack item, boolean inColor, float zLevel, float x, float y) + { + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, INVENTORY); + if (customRenderer == null) + { + return false; + } + + engine.bindTexture(engine.getTexture(Item.itemsList[item.itemID].getTextureFile())); + if (customRenderer.shouldUseRenderHelper(INVENTORY, item, INVENTORY_BLOCK)) + { + GL11.glPushMatrix(); + GL11.glTranslatef(x - 2, y + 3, -3.0F + zLevel); + GL11.glScalef(10F, 10F, 10F); + GL11.glTranslatef(1.0F, 0.5F, 1.0F); + GL11.glScalef(1.0F, 1.0F, -1F); + GL11.glRotatef(210F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F); + + + if(inColor) + { + int color = Item.itemsList[item.itemID].getColorFromDamage(item.getItemDamage(), 0); + float r = (float)(color >> 16 & 0xff) / 255F; + float g = (float)(color >> 8 & 0xff) / 255F; + float b = (float)(color & 0xff) / 255F; + GL11.glColor4f(r, g, b, 1.0F); + } + + GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F); + renderBlocks.useInventoryTint = inColor; + customRenderer.renderItem(INVENTORY, item, renderBlocks); + renderBlocks.useInventoryTint = true; + GL11.glPopMatrix(); + } + else + { + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, -3.0F + zLevel); + + if (inColor) + { + int color = Item.itemsList[item.itemID].getColorFromDamage(item.getItemDamage(), 0); + float r = (float)(color >> 16 & 255) / 255.0F; + float g = (float)(color >> 8 & 255) / 255.0F; + float b = (float)(color & 255) / 255.0F; + GL11.glColor4f(r, g, b, 1.0F); + } + + customRenderer.renderItem(INVENTORY, item, renderBlocks); + GL11.glPopMatrix(); + GL11.glEnable(GL11.GL_LIGHTING); + } + return true; + } + + public static void renderEquippedItem(IItemRenderer customRenderer, RenderBlocks renderBlocks, EntityLiving entity, ItemStack item) + { + if (customRenderer.shouldUseRenderHelper(EQUIPPED, item, EQUIPPED_BLOCK)) + { + GL11.glPushMatrix(); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + customRenderer.renderItem(EQUIPPED, item, renderBlocks, entity); + GL11.glPopMatrix(); + } + else + { + GL11.glPushMatrix(); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glTranslatef(0.0F, -0.3F, 0.0F); + GL11.glScalef(1.5F, 1.5F, 1.5F); + GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F); + GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F); + customRenderer.renderItem(EQUIPPED, item, renderBlocks, entity); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + GL11.glPopMatrix(); + } + } } diff --git a/client/net/minecraftforge/client/MinecraftForgeClient.java b/client/net/minecraftforge/client/MinecraftForgeClient.java index 9de9f48d23..35f66ebfbb 100644 --- a/client/net/minecraftforge/client/MinecraftForgeClient.java +++ b/client/net/minecraftforge/client/MinecraftForgeClient.java @@ -15,6 +15,7 @@ import net.minecraft.src.ModLoader; import net.minecraft.src.RenderBlocks; import net.minecraft.src.World; import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.common.MinecraftForge; public class MinecraftForgeClient { @@ -82,36 +83,4 @@ public class MinecraftForgeClient } return null; } - - private static boolean hasInit = false; - public static void init() - { - if (hasInit) - { - return; - } - hasInit = true; - ForgeHooks.setPacketHandler(new PacketHandlerClient()); - } - - static - { - init(); - } - - /*** - * This is a function that is used to enforce deprecation of code. - * It checks the current Display's title against the passed in argument. - * If they do not match (such is the case in different versionf of MC) it exits the process with a error - * - * @param version The version to find, usually "Minecraft Minecraft 1.2.3" - * @param message The error message to display in the crash log - */ - public static void checkMinecraftVersion(String version, String message) - { - if (!Display.getTitle().equals(version)) - { - MinecraftForge.killMinecraft("Minecraft Forge", message.replaceAll("%version%", Display.getTitle())); - } - } } diff --git a/client/net/minecraftforge/client/event/ClientChatReceivedEvent.java b/client/net/minecraftforge/client/event/ClientChatReceivedEvent.java new file mode 100644 index 0000000000..431261639d --- /dev/null +++ b/client/net/minecraftforge/client/event/ClientChatReceivedEvent.java @@ -0,0 +1,14 @@ +package net.minecraftforge.client.event; + +import net.minecraftforge.event.Cancelable; +import net.minecraftforge.event.Event; + +@Cancelable +public class ClientChatReceivedEvent extends Event +{ + public String message; + public ClientChatReceivedEvent(String message) + { + this.message = message; + } +} diff --git a/client/net/minecraftforge/client/event/DrawBlockHighlightEvent.java b/client/net/minecraftforge/client/event/DrawBlockHighlightEvent.java new file mode 100644 index 0000000000..fe15fcb0f4 --- /dev/null +++ b/client/net/minecraftforge/client/event/DrawBlockHighlightEvent.java @@ -0,0 +1,30 @@ +package net.minecraftforge.client.event; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.ItemStack; +import net.minecraft.src.MovingObjectPosition; +import net.minecraft.src.RenderGlobal; +import net.minecraftforge.event.Cancelable; +import net.minecraftforge.event.Event; + +@Cancelable +public class DrawBlockHighlightEvent extends Event +{ + public final RenderGlobal context; + public final EntityPlayer player; + public final MovingObjectPosition target; + public final int subID; + public final ItemStack currentItem; + public final float partialTicks; + + public DrawBlockHighlightEvent(RenderGlobal context, EntityPlayer player, MovingObjectPosition target, int subID, ItemStack currentItem, float partialTicks) + { + this.context = context; + this.player = player; + this.target = target; + this.subID = subID; + this.currentItem = currentItem; + this.partialTicks= partialTicks; + } + +} diff --git a/client/net/minecraftforge/client/event/RenderWorldLastEvent.java b/client/net/minecraftforge/client/event/RenderWorldLastEvent.java new file mode 100644 index 0000000000..7e541d3d97 --- /dev/null +++ b/client/net/minecraftforge/client/event/RenderWorldLastEvent.java @@ -0,0 +1,15 @@ +package net.minecraftforge.client.event; + +import net.minecraft.src.RenderGlobal; +import net.minecraftforge.event.Event; + +public class RenderWorldLastEvent extends Event +{ + public final RenderGlobal context; + public final float partialTicks; + public RenderWorldLastEvent(RenderGlobal context, float partialTicks) + { + this.context = context; + this.partialTicks = partialTicks; + } +} diff --git a/client/net/minecraftforge/client/event/TextureLoadEvent.java b/client/net/minecraftforge/client/event/TextureLoadEvent.java new file mode 100644 index 0000000000..06e31b58c3 --- /dev/null +++ b/client/net/minecraftforge/client/event/TextureLoadEvent.java @@ -0,0 +1,17 @@ +package net.minecraftforge.client.event; + +import net.minecraft.src.TexturePackBase; +import net.minecraftforge.event.Event; + +public class TextureLoadEvent extends Event +{ + + public final String texture; + public final TexturePackBase pack; + + public TextureLoadEvent(String texture, TexturePackBase pack) + { + this.texture = texture; + this.pack = pack; + } +} diff --git a/client/net/minecraftforge/client/event/sound/SoundEvent.java b/client/net/minecraftforge/client/event/sound/SoundEvent.java new file mode 100644 index 0000000000..3b8ec127d6 --- /dev/null +++ b/client/net/minecraftforge/client/event/sound/SoundEvent.java @@ -0,0 +1,122 @@ +package net.minecraftforge.client.event.sound; + +import net.minecraft.src.SoundManager; +import net.minecraft.src.SoundPoolEntry; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.Event; + +public class SoundEvent extends Event +{ + public SoundEvent(){} + + public static SoundPoolEntry getResult(SoundResultEvent event) + { + MinecraftForge.EVENT_BUS.post(event); + return event.result; + } + + public static abstract class SoundResultEvent extends SoundEvent + { + public final SoundManager manager; + public final SoundPoolEntry source; + public final String name; + public final float volume; + public final float pitch; + public SoundPoolEntry result; + + public SoundResultEvent(SoundManager manager, SoundPoolEntry source, String name, float volume, float pitch) + { + this.manager = manager; + this.source = source; + this.name = name; + this.volume = volume; + this.pitch = pitch; + this.result = source; + } + } + + /** + * Raised by the SoundManager.loadSoundSettings, this would be a good place for + * adding your custom sounds to the SoundPool. + */ + public static class SoundLoadEvent extends SoundEvent + { + public final SoundManager manager; + public SoundLoadEvent(SoundManager manager) + { + this.manager = manager; + } + } + + /** + * This event is raised by the SoundManager when it does its first setup of the + * SoundSystemConfig's codecs, use this function to add your own codecs. + */ + public static class SoundSetupEvent extends SoundEvent + { + public final SoundManager manager; + public SoundSetupEvent(SoundManager manager) + { + this.manager = manager; + } + } + + /** + * Raised when the SoundManager tries to play a Background Music file, + * If you return null from this function it will prevent the sound from being played, + * you can return a different entry if you want to change the sound being played. + */ + public static class PlayBackgroundMusicEvent extends SoundResultEvent + { + public PlayBackgroundMusicEvent(SoundManager manager, SoundPoolEntry entry) + { super(manager, entry, null, 0.0f, 0.0f); } + } + + /** + * Raised when the SoundManager tries to play a 'Streaming' file, + * in vanilla it is only the Jukebox that uses this function. + * + * If you return null from this function it will prevent the sound from being played, + * you can return a different entry if you want to change the sound being played. + * + */ + public static class PlayStreamingEvent extends SoundResultEvent + { + public final float x; + public final float y; + public final float z; + public PlayStreamingEvent(SoundManager manager, SoundPoolEntry source, String name, float x, float y, float z) + { + super(manager, source, name, 0.0f, 0.0f); + this.x = x; + this.y = y; + this.z = z; + } + } + + /*** + * Raised when the SoundManager tries to play a normal sound, + * dogs barking, footsteps, etc. THe majority of all sounds during normal game play. + * + * If you return null from this function it will prevent the sound from being played, + * you can return a different entry if you want to change the sound being played. + */ + public static class PlaySoundEvent extends SoundResultEvent + { + public final float x; + public final float y; + public final float z; + public PlaySoundEvent(SoundManager manager, SoundPoolEntry source, String name, float x, float y, float z, float volume, float pitch) + { + super(manager, source, name, volume, pitch); + this.x = x; + this.y = y; + this.z = z; + } + } + public static class PlaySoundEffectEvent extends SoundResultEvent + { + public PlaySoundEffectEvent(SoundManager manager, SoundPoolEntry source, String name, float volume, float pitch) + { super(manager, source, name, volume, pitch); } + } +} \ No newline at end of file diff --git a/common/net/minecraftforge/common/AchievementPage.java b/common/net/minecraftforge/common/AchievementPage.java new file mode 100644 index 0000000000..6799959618 --- /dev/null +++ b/common/net/minecraftforge/common/AchievementPage.java @@ -0,0 +1,108 @@ +/** + * This software is provided under the terms of the Minecraft Forge Public + * License v1.0. + */ + +package net.minecraftforge.common; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import net.minecraft.src.Achievement; + +public class AchievementPage +{ + private String name; + private LinkedList achievements; + + public AchievementPage(String name, Achievement... achievements) + { + this.name = name; + this.achievements = new LinkedList(Arrays.asList(achievements)); + } + + public String getName() + { + return name; + } + + public List getAchievements() + { + return achievements; + } + + private static LinkedList achievementPages = new LinkedList(); + + /** + * Registers an achievement page. + * @param page The page. + */ + public static void registerAchievementPage(AchievementPage page) + { + if (getAchievementPage(page.getName()) != null) + { + throw new RuntimeException("Duplicate achievement page name \"" + page.getName() + "\"!"); + } + achievementPages.add(page); + } + + /** + * Will return an achievement page by its index on the list. + * @param index The page's index. + * @return the achievement page corresponding to the index or null if invalid index + */ + public static AchievementPage getAchievementPage(int index) + { + return achievementPages.get(index); + } + + /** + * Will return an achievement page by its name. + * @param name The page's name. + * @return the achievement page with the given name or null if no such page + */ + public static AchievementPage getAchievementPage(String name) + { + for (AchievementPage page : achievementPages) + { + if (page.getName().equals(name)) + { + return page; + } + } + return null; + } + + /** + * Will return the list of achievement pages. + * @return the list's size + */ + public static Set getAchievementPages() + { + return new HashSet(achievementPages); + } + + /** + * Will return whether an achievement is in any page or not. + * @param achievement The achievement. + */ + public static boolean isAchievementInPages(Achievement achievement) + { + for (AchievementPage page : achievementPages) + { + if (page.getAchievements().contains(achievement)) + { + return true; + } + } + return false; + } + + public static String getTitle(int index) + { + return index == -1 ? "Minecraft" : getAchievementPage(index).getName(); + } +} \ No newline at end of file diff --git a/common/net/minecraftforge/common/DungeonHooks.java b/common/net/minecraftforge/common/DungeonHooks.java new file mode 100644 index 0000000000..29771cbd66 --- /dev/null +++ b/common/net/minecraftforge/common/DungeonHooks.java @@ -0,0 +1,285 @@ +package net.minecraftforge.common; + +import java.util.ArrayList; +import java.util.Random; + +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; +import net.minecraft.src.WeightedRandom; +import net.minecraft.src.WeightedRandomItem; + +public class DungeonHooks +{ + private static int dungeonLootAttempts = 8; + private static ArrayList dungeonMobs = new ArrayList(); + private static ArrayList dungeonLoot = new ArrayList(); + /** + * Set the number of item stacks that will be attempted to be added to each Dungeon chest. + * Note: Due to random number generation, you will not always get this amount per chest. + * @param number The maximum number of item stacks to add to a chest. + */ + public static void setDungeonLootTries(int number) + { + dungeonLootAttempts = number; + } + + /** + * @return The max number of item stacks found in each dungeon chest. + */ + public static int getDungeonLootTries() + { + return dungeonLootAttempts; + } + + /** + * Adds a mob to the possible list of creatures the spawner will create. + * If the mob is already in the spawn list, the rarity will be added to the existing one, + * causing the mob to be more common. + * + * @param name The name of the monster, use the same name used when registering the entity. + * @param rarity The rarity of selecting this mob over others. Must be greater then 0. + * Vanilla Minecraft has the following mobs: + * Spider 100 + * Skeleton 100 + * Zombie 200 + * Meaning, Zombies are twice as common as spiders or skeletons. + * @return The new rarity of the monster, + */ + public static float addDungeonMob(String name, int rarity) + { + if (rarity <= 0) + { + throw new IllegalArgumentException("Rarity must be greater then zero"); + } + + for (DungeonMob mob : dungeonMobs) + { + if (name.equals(mob.type)) + { + return mob.itemWeight += rarity; + } + } + + dungeonMobs.add(new DungeonMob(rarity, name)); + return rarity; + } + + /** + * Will completely remove a Mob from the dungeon spawn list. + * + * @param name The name of the mob to remove + * @return The rarity of the removed mob, prior to being removed. + */ + public static int removeDungeonMob(String name) + { + for (DungeonMob mob : dungeonMobs) + { + if (name.equals(mob.type)) + { + dungeonMobs.remove(mob); + return mob.itemWeight; + } + } + return 0; + } + + /** + * Gets a random mob name from the list. + * @param rand World generation random number generator + * @return The mob name + */ + public static String getRandomDungeonMob(Random rand) + { + DungeonMob mob = (DungeonMob)WeightedRandom.getRandomItem(rand, dungeonMobs); + if (mob == null) + { + return ""; + } + return mob.type; + } + + /** + * Adds a item stack to the dungeon loot list with a stack size + * of 1. + * + * @param item The ItemStack to be added to the loot list + * @param rarity The relative chance that this item will spawn, Vanilla has + * most of its items set to 1. Like the saddle, bread, silk, wheat, etc.. + * Rarer items are set to lower values, EXA: Golden Apple 0.01 + */ + public static void addDungeonLoot(ItemStack item, int rarity) + { + addDungeonLoot(item, rarity, 1, 1); + } + + /** + * Adds a item stack, with a range of sizes, to the dungeon loot list. + * If a stack matching the same item, and size range, is already in the list + * the rarities will be added together making the item more common. + * + * @param item The ItemStack to be added to the loot list + * @param rarity The relative chance that this item will spawn, Vanilla has + * most of its items set to 1. Like the saddle, bread, silk, wheat, etc.. + * Rarer items are set to lower values, EXA: Golden Apple 0.01 + * @param minCount When this item does generate, the minimum number that is in the stack + * @param maxCount When this item does generate, the maximum number that can bein the stack + * @return The new rarity of the loot. + */ + public static float addDungeonLoot(ItemStack item, int rarity, int minCount, int maxCount) + { + for (DungeonLoot loot : dungeonLoot) + { + if (loot.equals(item, minCount, maxCount)) + { + return loot.itemWeight += rarity; + } + } + + dungeonLoot.add(new DungeonLoot(rarity, item, minCount, maxCount)); + return rarity; + } + /** + * Removes a item stack from the dungeon loot list, this will remove all items + * as long as the item stack matches, it will not care about matching the stack + * size ranges perfectly. + * + * @param item The item stack to remove + */ + public static void removeDungeonLoot(ItemStack item) + { + removeDungeonLoot(item, -1, 0); + } + + /** + * Removes a item stack from the dungeon loot list. If 'minCount' parameter + * is greater then 0, it will only remove loot items that have the same exact + * stack size range as passed in by parameters. + * + * @param item The item stack to remove + * @param minCount The minimum count for the match check, if less then 0, + * the size check is skipped + * @param maxCount The max count used in match check when 'minCount' is >= 0 + */ + public static void removeDungeonLoot(ItemStack item, int minCount, int maxCount) + { + ArrayList lootTmp = (ArrayList)dungeonLoot.clone(); + if (minCount < 0) + { + for (DungeonLoot loot : lootTmp) + { + if (loot.equals(item)) + { + dungeonLoot.remove(loot); + } + } + } + else + { + for (DungeonLoot loot : lootTmp) + { + if (loot.equals(item, minCount, maxCount)) + { + dungeonLoot.remove(loot); + } + } + } + } + + /** + * Gets a random item stack to place in a dungeon chest during world generation + * @param rand World generation random number generator + * @return The item stack + */ + public static ItemStack getRandomDungeonLoot(Random rand) + { + DungeonLoot ret = (DungeonLoot)WeightedRandom.getRandomItem(rand, dungeonLoot); + if (ret != null) + { + return ret.generateStack(rand); + } + return null; + } + + public static class DungeonLoot extends WeightedRandomItem + { + private ItemStack itemStack; + private int minCount = 1; + private int maxCount = 1; + + /** + * @param item A item stack + * @param min Minimum stack size when randomly generating + * @param max Maximum stack size when randomly generating + */ + public DungeonLoot(int weight, ItemStack item, int min, int max) + { + super(weight); + this.itemStack = item; + minCount = min; + maxCount = max; + } + + /** + * Grabs a ItemStack ready to be added to the dungeon chest, + * the stack size will be between minCount and maxCount + * @param rand World gen random number generator + * @return The ItemStack to be added to the chest + */ + public ItemStack generateStack(Random rand) + { + ItemStack ret = this.itemStack.copy(); + ret.stackSize = minCount + (rand.nextInt(maxCount - minCount + 1)); + return ret; + } + + public boolean equals(ItemStack item, int min, int max) + { + return (min == minCount && max == maxCount && item.isItemEqual(this.itemStack)); + } + + public boolean equals(ItemStack item) + { + return item.isItemEqual(this.itemStack); + } + } + + public static class DungeonMob extends WeightedRandomItem + { + public String type; + public DungeonMob(int weight, String type) + { + super(weight); + this.type = type; + } + + @Override + public boolean equals(Object target) + { + if (target instanceof DungeonMob) + { + return this.type.equals(((DungeonMob)target).type); + } + return false; + } + } + + static + { + addDungeonMob("Skeleton", 100); + addDungeonMob("Zombie", 200); + addDungeonMob("Spider", 100); + + addDungeonLoot(new ItemStack(Item.saddle), 100 ); + addDungeonLoot(new ItemStack(Item.ingotIron), 100, 1, 4); + addDungeonLoot(new ItemStack(Item.bread), 100 ); + addDungeonLoot(new ItemStack(Item.wheat), 100, 1, 4); + addDungeonLoot(new ItemStack(Item.gunpowder), 100, 1, 4); + addDungeonLoot(new ItemStack(Item.silk), 100, 1, 4); + addDungeonLoot(new ItemStack(Item.bucketEmpty), 100 ); + addDungeonLoot(new ItemStack(Item.appleGold), 001 ); + addDungeonLoot(new ItemStack(Item.redstone), 050, 1, 4); + addDungeonLoot(new ItemStack(Item.record13), 005 ); + addDungeonLoot(new ItemStack(Item.recordCat), 005 ); + addDungeonLoot(new ItemStack(Item.dyePowder, 1, 3), 100 ); + } +} diff --git a/common/net/minecraftforge/common/ForgeHooks.java b/common/net/minecraftforge/common/ForgeHooks.java index ed0616d3ce..c2a745bd9e 100644 --- a/common/net/minecraftforge/common/ForgeHooks.java +++ b/common/net/minecraftforge/common/ForgeHooks.java @@ -218,4 +218,10 @@ public class ForgeHooks System.out.printf("MinecraftForge v%s Initialized\n", ForgeVersion.getVersion()); ModLoader.getLogger().info(String.format("MinecraftForge v%s Initialized", ForgeVersion.getVersion())); } + + public static boolean onEntityInteract(EntityPlayer entityPlayer, Entity par1Entity, boolean b) + { + + return false; + } } diff --git a/common/net/minecraftforge/common/MinecartRegistry.java b/common/net/minecraftforge/common/MinecartRegistry.java new file mode 100644 index 0000000000..5a3867338a --- /dev/null +++ b/common/net/minecraftforge/common/MinecartRegistry.java @@ -0,0 +1,215 @@ +package net.minecraftforge.common; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import net.minecraft.src.EntityMinecart; +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; + +public class MinecartRegistry +{ + private static Map itemForMinecart = new HashMap(); + private static Map minecartForItem = new HashMap(); + /** + * Registers a custom minecart and its corresponding item. + * This should be the item used to place the minecart by the user, + * not the item dropped by the cart. + * @param cart The minecart. + * @param item The item used to place the cart. + */ + public static void registerMinecart(Class cart, ItemStack item) + { + registerMinecart(cart, 0, item); + } + + /** + * Registers a minecart and its corresponding item. + * This should be the item used to place the minecart by the user, + * not the item dropped by the cart. + * @param minecart The minecart. + * @param type The minecart type, used to differentiate carts that have the same class. + * @param item The item used to place the cart. + */ + public static void registerMinecart(Class minecart, int type, ItemStack item) + { + MinecartKey key = new MinecartKey(minecart, type); + itemForMinecart.put(key, item); + minecartForItem.put(item, key); + } + + /** + * Removes a previously registered Minecart. Useful for replacing the vanilla minecarts. + * @param minecart + * @param type + */ + public static void removeMinecart(Class minecart, int type) + { + MinecartKey key = new MinecartKey(minecart, type); + ItemStack item = itemForMinecart.remove(key); + if (item != null) + { + minecartForItem.remove(item); + } + } + + /** + * This function returns an ItemStack that represents this cart. + * The player should be able to use this item to place the minecart. + * This is the item that was registered with the cart via the registerMinecart function, + * but is not necessary the item the cart drops when destroyed. + * @param minecart The cart class + * @return An ItemStack that can be used to place the cart. + */ + public static ItemStack getItemForCart(Class minecart) + { + return getItemForCart(minecart, 0); + } + + /** + * This function returns an ItemStack that represents this cart. + * The player should be able to use this item to place the minecart. + * This is the item that was registered with the cart via the registerMinecart function, + * but is not necessary the item the cart drops when destroyed. + * @param minecart The cart class + * @param type The minecartType value + * @return An ItemStack that can be used to place the cart. + */ + public static ItemStack getItemForCart(Class minecart, int type) + { + ItemStack item = itemForMinecart.get(new MinecartKey(minecart, type)); + if (item == null) + { + return null; + } + return item.copy(); + } + + /** + * This function returns an ItemStack that represents this cart. + * The player should be able to use this item to place the minecart. + * This is the item that was registered with the cart via the registerMinecart function, + * but is not necessary the item the cart drops when destroyed. + * @param cart The cart entity + * @return An ItemStack that can be used to place the cart. + */ + public static ItemStack getItemForCart(EntityMinecart cart) + { + return getItemForCart(cart.getClass(), cart.getMinecartType()); + } + + /** + * The function will return the cart class for a given item. + * If the item was not registered via the registerMinecart function it will return null. + * @param item The item to test. + * @return Cart if mapping exists, null if not. + */ + public static Class getCartClassForItem(ItemStack item) + { + MinecartKey key = null; + for (Map.Entry entry : minecartForItem.entrySet()) + { + if (entry.getKey().isItemEqual(item)) + { + key = entry.getValue(); + break; + } + } + if (key != null) + { + return key.minecart; + } + return null; + } + + /** + * The function will return the cart type for a given item. + * Will return -1 if the mapping doesn't exist. + * If the item was not registered via the registerMinecart function it will return null. + * @param item The item to test. + * @return the cart minecartType value. + */ + public static int getCartTypeForItem(ItemStack item) + { + MinecartKey key = null; + for (Map.Entry entry : minecartForItem.entrySet()) + { + if (entry.getKey().isItemEqual(item)) + { + key = entry.getValue(); + break; + } + } + if (key != null) + { + return key.type; + } + return -1; + } + + /** + * Will return a set of all registered minecart items. + * @return a copy of the set of all minecart items + */ + public static Set getAllCartItems() + { + Set ret = new HashSet(); + for (ItemStack item : minecartForItem.keySet()) + { + ret.add(item.copy()); + } + return ret; + } + + static + { + registerMinecart(EntityMinecart.class, 0, new ItemStack(Item.minecartEmpty)); + registerMinecart(EntityMinecart.class, 1, new ItemStack(Item.minecartCrate)); + registerMinecart(EntityMinecart.class, 2, new ItemStack(Item.minecartPowered)); + } + + public static class MinecartKey + { + public final Class minecart; + public final int type; + + public MinecartKey(Class cls, int typtID) + { + minecart = cls; + type = typtID; + } + + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + + if (getClass() != obj.getClass()) + { + return false; + } + + final MinecartKey other = (MinecartKey)obj; + if (this.minecart != other.minecart && (this.minecart == null || !this.minecart.equals(other.minecart))) + { + return false; + } + + return (this.type == other.type); + } + + @Override + public int hashCode() + { + int hash = 7; + hash = 59 * hash + (this.minecart != null ? this.minecart.hashCode() : 0); + hash = 59 * hash + this.type; + return hash; + } + } +} diff --git a/common/net/minecraftforge/common/MinecraftForge.java b/common/net/minecraftforge/common/MinecraftForge.java index ba913431b2..d6b533c7ef 100644 --- a/common/net/minecraftforge/common/MinecraftForge.java +++ b/common/net/minecraftforge/common/MinecraftForge.java @@ -192,7 +192,5 @@ public class MinecraftForge temp[x] = EntityEnderman.carriableBlocks[x]; } EntityEnderman.carriableBlocks = temp; - - } } diff --git a/common/net/minecraftforge/event/Cancelable.java b/common/net/minecraftforge/event/Cancelable.java new file mode 100644 index 0000000000..2d30ca9a75 --- /dev/null +++ b/common/net/minecraftforge/event/Cancelable.java @@ -0,0 +1,11 @@ +package net.minecraftforge.event; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(value = RUNTIME) +@Target(value = TYPE) +public @interface Cancelable{} diff --git a/common/net/minecraftforge/event/Event.java b/common/net/minecraftforge/event/Event.java index ca41c22fad..ceb2929ce8 100644 --- a/common/net/minecraftforge/event/Event.java +++ b/common/net/minecraftforge/event/Event.java @@ -7,11 +7,23 @@ package net.minecraftforge.event; public class Event { private boolean isCanceled = false; + private final boolean isCancelable; private static ListenerList listeners = new ListenerList(); public Event() { setup(); + Class cls = this.getClass(); + boolean found = false; + while (cls != Event.class) + { + if (cls.isAnnotationPresent(Cancelable.class)) + { + found = true; + break; + } + } + isCancelable = found; } /** @@ -20,7 +32,7 @@ public class Event */ public boolean isCancelable() { - return false; + return isCancelable; } /** diff --git a/common/net/minecraftforge/event/EventBus.java b/common/net/minecraftforge/event/EventBus.java index 2855a8372f..a516f37fcd 100644 --- a/common/net/minecraftforge/event/EventBus.java +++ b/common/net/minecraftforge/event/EventBus.java @@ -92,12 +92,13 @@ public class EventBus } } - public void post(Event event) + public boolean post(Event event) { IEventListener[] listeners = event.getListenerList().getListeners(busID); for (IEventListener listener : listeners) { listener.invoke(event); } + return (event.isCancelable() ? event.isCanceled() : false); } } diff --git a/common/net/minecraftforge/event/entity/UseHoeEvent.java b/common/net/minecraftforge/event/entity/UseHoeEvent.java index 0db75edaa2..c012c9108c 100644 --- a/common/net/minecraftforge/event/entity/UseHoeEvent.java +++ b/common/net/minecraftforge/event/entity/UseHoeEvent.java @@ -3,8 +3,10 @@ package net.minecraftforge.event.entity; import net.minecraft.src.EntityPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.World; +import net.minecraftforge.event.Cancelable; import net.minecraftforge.event.entity.player.PlayerEvent; +@Cancelable public class UseHoeEvent extends PlayerEvent { @@ -25,12 +27,6 @@ public class UseHoeEvent extends PlayerEvent this.y = y; this.z = z; } - - @Override - public boolean isCancelable() - { - return true; - } public boolean isHandeled() { diff --git a/common/net/minecraftforge/event/entity/living/LivingAttackEvent.java b/common/net/minecraftforge/event/entity/living/LivingAttackEvent.java new file mode 100644 index 0000000000..b8c05967dc --- /dev/null +++ b/common/net/minecraftforge/event/entity/living/LivingAttackEvent.java @@ -0,0 +1,18 @@ +package net.minecraftforge.event.entity.living; + +import net.minecraft.src.DamageSource; +import net.minecraft.src.EntityLiving; +import net.minecraftforge.event.Cancelable; + +@Cancelable +public class LivingAttackEvent extends LivingEvent +{ + public final DamageSource source; + public final int ammount; + public LivingAttackEvent(EntityLiving entity, DamageSource source, int ammount) + { + super(entity); + this.source = source; + this.ammount = ammount; + } +} diff --git a/common/net/minecraftforge/event/entity/living/LivingDeathEvent.java b/common/net/minecraftforge/event/entity/living/LivingDeathEvent.java new file mode 100644 index 0000000000..0c0d374bcf --- /dev/null +++ b/common/net/minecraftforge/event/entity/living/LivingDeathEvent.java @@ -0,0 +1,17 @@ +package net.minecraftforge.event.entity.living; + +import net.minecraft.src.DamageSource; +import net.minecraft.src.EntityLiving; +import net.minecraftforge.event.Cancelable; + +@Cancelable +public class LivingDeathEvent extends LivingEvent +{ + public final DamageSource source; + public LivingDeathEvent(EntityLiving entity, DamageSource source) + { + super(entity); + this.source = source; + } + +} diff --git a/common/net/minecraftforge/event/entity/living/LivingDropsEvent.java b/common/net/minecraftforge/event/entity/living/LivingDropsEvent.java new file mode 100644 index 0000000000..c2eb9dd3c9 --- /dev/null +++ b/common/net/minecraftforge/event/entity/living/LivingDropsEvent.java @@ -0,0 +1,28 @@ +package net.minecraftforge.event.entity.living; + +import java.util.ArrayList; + +import net.minecraft.src.DamageSource; +import net.minecraft.src.EntityItem; +import net.minecraft.src.EntityLiving; +import net.minecraftforge.event.Cancelable; + +@Cancelable +public class LivingDropsEvent extends LivingEvent +{ + public final DamageSource source; + public final ArrayList drops; + public final int lootingLevel; + public final boolean recentlyHit; + public final int specialDropValue; + + public LivingDropsEvent(EntityLiving entity, DamageSource source, ArrayList drops, int lootingLevel, boolean recentlyHit, int specialDropValue) + { + super(entity); + this.source = source; + this.drops = drops; + this.lootingLevel = lootingLevel; + this.recentlyHit = recentlyHit; + this.specialDropValue = specialDropValue; + } +} diff --git a/common/net/minecraftforge/event/entity/living/LivingEvent.java b/common/net/minecraftforge/event/entity/living/LivingEvent.java index 9c9fa1d916..7035f46b0f 100644 --- a/common/net/minecraftforge/event/entity/living/LivingEvent.java +++ b/common/net/minecraftforge/event/entity/living/LivingEvent.java @@ -1,6 +1,7 @@ package net.minecraftforge.event.entity.living; import net.minecraft.src.EntityLiving; +import net.minecraftforge.event.Cancelable; import net.minecraftforge.event.entity.EntityEvent; public class LivingEvent extends EntityEvent @@ -11,4 +12,15 @@ public class LivingEvent extends EntityEvent super(entity); entityLiving = entity; } + + @Cancelable + public static class LivingUpdateEvent extends LivingEvent + { + public LivingUpdateEvent(EntityLiving e){ super(e); } + } + + public static class LivingJumpEvent extends LivingEvent + { + public LivingJumpEvent(EntityLiving e){ super(e); } + } } diff --git a/common/net/minecraftforge/event/entity/living/LivingFallEvent.java b/common/net/minecraftforge/event/entity/living/LivingFallEvent.java new file mode 100644 index 0000000000..b03fa0ad0e --- /dev/null +++ b/common/net/minecraftforge/event/entity/living/LivingFallEvent.java @@ -0,0 +1,15 @@ +package net.minecraftforge.event.entity.living; + +import net.minecraft.src.EntityLiving; +import net.minecraftforge.event.Cancelable; + +@Cancelable +public class LivingFallEvent extends LivingEvent +{ + public float distance; + public LivingFallEvent(EntityLiving entity, float distance) + { + super(entity); + this.distance = distance; + } +} diff --git a/common/net/minecraftforge/event/entity/living/LivingHurtEvent.java b/common/net/minecraftforge/event/entity/living/LivingHurtEvent.java new file mode 100644 index 0000000000..d5e2a0ba06 --- /dev/null +++ b/common/net/minecraftforge/event/entity/living/LivingHurtEvent.java @@ -0,0 +1,19 @@ +package net.minecraftforge.event.entity.living; + +import net.minecraft.src.DamageSource; +import net.minecraft.src.EntityLiving; +import net.minecraftforge.event.Cancelable; + +@Cancelable +public class LivingHurtEvent extends LivingEvent +{ + public final DamageSource source; + public int ammount; + public LivingHurtEvent(EntityLiving entity, DamageSource source, int ammount) + { + super(entity); + this.source = source; + this.ammount = ammount; + } + +} diff --git a/common/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java b/common/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java new file mode 100644 index 0000000000..bb51b59062 --- /dev/null +++ b/common/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java @@ -0,0 +1,15 @@ +package net.minecraftforge.event.entity.living; + +import net.minecraft.src.EntityLiving; + +public class LivingSetAttackTargetEvent extends LivingEvent +{ + + public final EntityLiving target; + public LivingSetAttackTargetEvent(EntityLiving entity, EntityLiving target) + { + super(entity); + this.target = target; + } + +} diff --git a/common/net/minecraftforge/event/entity/player/ArrowLooseEvent.java b/common/net/minecraftforge/event/entity/player/ArrowLooseEvent.java index 13b4032057..5113c3e049 100644 --- a/common/net/minecraftforge/event/entity/player/ArrowLooseEvent.java +++ b/common/net/minecraftforge/event/entity/player/ArrowLooseEvent.java @@ -2,7 +2,9 @@ package net.minecraftforge.event.entity.player; import net.minecraft.src.EntityPlayer; import net.minecraft.src.ItemStack; +import net.minecraftforge.event.Cancelable; +@Cancelable public class ArrowLooseEvent extends PlayerEvent { public final ItemStack bow; @@ -14,10 +16,4 @@ public class ArrowLooseEvent extends PlayerEvent this.bow = bow; this.charge = charge; } - - @Override - public boolean isCancelable() - { - return true; - } } diff --git a/common/net/minecraftforge/event/entity/player/ArrowNockEvent.java b/common/net/minecraftforge/event/entity/player/ArrowNockEvent.java index bd9d5896c9..b784a977b6 100644 --- a/common/net/minecraftforge/event/entity/player/ArrowNockEvent.java +++ b/common/net/minecraftforge/event/entity/player/ArrowNockEvent.java @@ -2,7 +2,9 @@ package net.minecraftforge.event.entity.player; import net.minecraft.src.EntityPlayer; import net.minecraft.src.ItemStack; +import net.minecraftforge.event.Cancelable; +@Cancelable public class ArrowNockEvent extends PlayerEvent { public ItemStack result; @@ -12,10 +14,4 @@ public class ArrowNockEvent extends PlayerEvent super(player); this.result = result; } - - @Override - public boolean isCancelable() - { - return true; - } } diff --git a/common/net/minecraftforge/event/entity/player/BonemealEvent.java b/common/net/minecraftforge/event/entity/player/BonemealEvent.java index de8ab33ba5..8126d7175f 100644 --- a/common/net/minecraftforge/event/entity/player/BonemealEvent.java +++ b/common/net/minecraftforge/event/entity/player/BonemealEvent.java @@ -2,7 +2,9 @@ package net.minecraftforge.event.entity.player; import net.minecraft.src.EntityPlayer; import net.minecraft.src.World; +import net.minecraftforge.event.Cancelable; +@Cancelable public class BonemealEvent extends PlayerEvent { public final World world; @@ -22,12 +24,6 @@ public class BonemealEvent extends PlayerEvent this.Z = z; } - @Override - public boolean isCancelable() - { - return true; - } - public void setHandeled() { handeled = true; diff --git a/common/net/minecraftforge/event/entity/player/EntityItemPickupEvent.java b/common/net/minecraftforge/event/entity/player/EntityItemPickupEvent.java index 1300663a54..f7b5731bfe 100644 --- a/common/net/minecraftforge/event/entity/player/EntityItemPickupEvent.java +++ b/common/net/minecraftforge/event/entity/player/EntityItemPickupEvent.java @@ -3,7 +3,9 @@ package net.minecraftforge.event.entity.player; import net.minecraft.src.Entity; import net.minecraft.src.EntityItem; import net.minecraft.src.EntityPlayer; +import net.minecraftforge.event.Cancelable; +@Cancelable public class EntityItemPickupEvent extends PlayerEvent { public final EntityItem item; @@ -13,10 +15,4 @@ public class EntityItemPickupEvent extends PlayerEvent super(player); this.item = item; } - - @Override - public boolean isCancelable() - { - return true; - } } diff --git a/common/net/minecraftforge/event/entity/player/FillBucketEvent.java b/common/net/minecraftforge/event/entity/player/FillBucketEvent.java index 7f4c6c1221..c110fba248 100644 --- a/common/net/minecraftforge/event/entity/player/FillBucketEvent.java +++ b/common/net/minecraftforge/event/entity/player/FillBucketEvent.java @@ -4,7 +4,9 @@ import net.minecraft.src.EntityPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.MovingObjectPosition; import net.minecraft.src.World; +import net.minecraftforge.event.Cancelable; +@Cancelable public class FillBucketEvent extends PlayerEvent { public final ItemStack current; @@ -21,12 +23,6 @@ public class FillBucketEvent extends PlayerEvent this.world = world; this.target = target; } - - @Override - public boolean isCancelable() - { - return true; - } public boolean isHandeled() { diff --git a/common/net/minecraftforge/event/entity/player/PlayerDestroyItemEvent.java b/common/net/minecraftforge/event/entity/player/PlayerDestroyItemEvent.java new file mode 100644 index 0000000000..1a3d49c321 --- /dev/null +++ b/common/net/minecraftforge/event/entity/player/PlayerDestroyItemEvent.java @@ -0,0 +1,15 @@ +package net.minecraftforge.event.entity.player; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.ItemStack; + +public class PlayerDestroyItemEvent extends PlayerEvent +{ + public final ItemStack original; + public PlayerDestroyItemEvent(EntityPlayer player, ItemStack original) + { + super(player); + this.original = original; + } + +} diff --git a/common/net/minecraftforge/event/entity/player/PlayerSleepInBedEvent.java b/common/net/minecraftforge/event/entity/player/PlayerSleepInBedEvent.java new file mode 100644 index 0000000000..b57795ddcb --- /dev/null +++ b/common/net/minecraftforge/event/entity/player/PlayerSleepInBedEvent.java @@ -0,0 +1,21 @@ +package net.minecraftforge.event.entity.player; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.EnumStatus; + +public class PlayerSleepInBedEvent extends PlayerEvent +{ + public EnumStatus result = null; + public final int x; + public final int y; + public final int z; + + public PlayerSleepInBedEvent(EntityPlayer player, int x, int y, int z) + { + super(player); + this.x = x; + this.y = y; + this.z = z; + } + +} diff --git a/common/net/minecraftforge/packets/PacketHandlerBase.java b/common/net/minecraftforge/packets/PacketHandlerBase.java index fdfd32b602..b9e59e9e2a 100644 --- a/common/net/minecraftforge/packets/PacketHandlerBase.java +++ b/common/net/minecraftforge/packets/PacketHandlerBase.java @@ -2,7 +2,6 @@ package net.minecraftforge.packets; import net.minecraft.src.NetworkManager; import net.minecraft.src.Packet; -import net.minecraft.src.forge.IPacketHandler; /** * A helper class used to make a shared interface for sending packets, diff --git a/patches/common/net/minecraft/src/WorldGenDungeons.java.patch b/patches/common/net/minecraft/src/WorldGenDungeons.java.patch index d78321d6eb..518249dbdb 100644 --- a/patches/common/net/minecraft/src/WorldGenDungeons.java.patch +++ b/patches/common/net/minecraft/src/WorldGenDungeons.java.patch @@ -1,23 +1,33 @@ --- ../src_base/common/net/minecraft/src/WorldGenDungeons.java +++ ../src_work/common/net/minecraft/src/WorldGenDungeons.java -@@ -1,6 +1,8 @@ +@@ -1,6 +1,9 @@ package net.minecraft.src; import java.util.Random; + ++import net.minecraftforge.common.DungeonHooks; +import net.minecraftforge.common.MinecraftForge; public class WorldGenDungeons extends WorldGenerator { -@@ -117,9 +119,9 @@ +@@ -117,9 +120,9 @@ if (var16 != null) { - for (int var17 = 0; var17 < 8; ++var17) -+ for (int var17 = 0; var17 < MinecraftForge.getDungeonLootTries(); ++var17) ++ for (int var17 = 0; var17 < DungeonHooks.getDungeonLootTries(); ++var17) { - ItemStack var18 = this.pickCheckLootItem(par2Random); -+ ItemStack var18 = MinecraftForge.getRandomDungeonLoot(par2Random); ++ ItemStack var18 = DungeonHooks.getRandomDungeonLoot(par2Random); if (var18 != null) { +@@ -147,7 +150,7 @@ + + if (var19 != null) + { +- var19.setMobID(this.pickMobSpawner(par2Random)); ++ var19.setMobID(DungeonHooks.getRandomDungeonMob(par2Random)); + } + else + { diff --git a/patches/minecraft/net/minecraft/src/Block.java.patch b/patches/minecraft/net/minecraft/src/Block.java.patch index 2dde4109b1..a4082ee967 100644 --- a/patches/minecraft/net/minecraft/src/Block.java.patch +++ b/patches/minecraft/net/minecraft/src/Block.java.patch @@ -94,7 +94,7 @@ { ItemStack var8 = this.createStackedBlock(par6); -@@ -1218,4 +1220,638 @@ +@@ -1218,4 +1220,650 @@ canBlockGrass[0] = true; StatList.initBreakableStats(); } @@ -731,5 +731,17 @@ + int id = world.getBlockId(x, y, z); + return id == Block.fence.blockID || id == Block.netherFence.blockID || id == Block.glass.blockID; + } ++ } ++ ++ ++ /** ++ * Determines if this block should render in this pass. ++ * ++ * @param pass The pass in question ++ * @return True to render ++ */ ++ public boolean canRenderInPass(int pass) ++ { ++ return pass == getRenderBlockPass(); + } } diff --git a/patches/minecraft/net/minecraft/src/EntityLiving.java.patch b/patches/minecraft/net/minecraft/src/EntityLiving.java.patch index b1cbfff36f..addfab7fdd 100644 --- a/patches/minecraft/net/minecraft/src/EntityLiving.java.patch +++ b/patches/minecraft/net/minecraft/src/EntityLiving.java.patch @@ -1,16 +1,18 @@ --- ../src_base/minecraft/net/minecraft/src/EntityLiving.java +++ ../src_work/minecraft/net/minecraft/src/EntityLiving.java -@@ -5,6 +5,9 @@ +@@ -5,6 +5,11 @@ import java.util.Iterator; import java.util.List; import java.util.Random; + +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.MinecraftForge; ++import net.minecraftforge.event.entity.living.*; ++import static net.minecraftforge.event.entity.living.LivingEvent.*; public abstract class EntityLiving extends Entity { -@@ -310,6 +313,7 @@ +@@ -310,6 +315,7 @@ public void setAttackTarget(EntityLiving par1EntityLiving) { this.attackTarget = par1EntityLiving; @@ -18,7 +20,7 @@ } public boolean isExplosiveMob(Class par1Class) -@@ -366,6 +370,7 @@ +@@ -366,6 +372,7 @@ { this.entityLivingToAttack = par1EntityLiving; this.revengeTimer = this.entityLivingToAttack != null ? 60 : 0; @@ -26,11 +28,11 @@ } protected void entityInit() -@@ -648,6 +653,11 @@ +@@ -648,6 +655,11 @@ */ public void onUpdate() { -+ if (ForgeHooks.onEntityLivingUpdate(this)) ++ if (MinecraftForge.EVENT_BUS.post(new LivingUpdateEvent(this))) + { + return; + } @@ -38,11 +40,11 @@ super.onUpdate(); if (this.arrowHitTempCounter > 0) -@@ -815,6 +825,11 @@ +@@ -815,6 +827,11 @@ */ public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) { -+ if (ForgeHooks.onEntityLivingAttacked(this, par1DamageSource, par2)) ++ if (MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(this, par1DamageSource, par2))) + { + return false; + } @@ -50,24 +52,25 @@ if (this.worldObj.isRemote) { return false; -@@ -997,6 +1012,12 @@ +@@ -997,6 +1014,13 @@ */ protected void damageEntity(DamageSource par1DamageSource, int par2) { -+ par2 = ForgeHooks.onEntityLivingHurt(this, par1DamageSource, par2); -+ if (par2 == 0) ++ LivingHurtEvent event = new LivingHurtEvent(this, par1DamageSource, par2); ++ if (MinecraftForge.EVENT_BUS.post(event) || event.ammount== 0) + { + return; + } ++ par2 = event.ammount; + par2 = this.applyArmorCalculations(par1DamageSource, par2); par2 = this.applyPotionDamageCalculations(par1DamageSource, par2); this.health -= par2; -@@ -1060,6 +1081,11 @@ +@@ -1060,6 +1084,11 @@ */ public void onDeath(DamageSource par1DamageSource) { -+ if (ForgeHooks.onEntityLivingDeath(this, par1DamageSource)) ++ if (MinecraftForge.EVENT_BUS.post(new LivingDeathEvent(this, par1DamageSource))) + { + return; + } @@ -75,7 +78,7 @@ Entity var2 = par1DamageSource.getEntity(); if (this.scoreValue >= 0 && var2 != null) -@@ -1083,13 +1109,17 @@ +@@ -1083,13 +1112,17 @@ var3 = EnchantmentHelper.getLootingModifier(((EntityPlayer)var2).inventory); } @@ -94,33 +97,38 @@ if (var4 < 5) { -@@ -1097,6 +1127,13 @@ +@@ -1097,6 +1130,16 @@ } } } + + captureDrops = false; -+ ForgeHooks.onEntityLivingDrops(this, par1DamageSource, capturedDrops, var3, recentlyHit > 0, var4); -+ for (EntityItem item : capturedDrops) ++ ++ if (!MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(this, par1DamageSource, capturedDrops, var3, recentlyHit > 0, var4))) + { -+ worldObj.spawnEntityInWorld(item); ++ for (EntityItem item : capturedDrops) ++ { ++ worldObj.spawnEntityInWorld(item); ++ } + } } this.worldObj.setEntityState(this, (byte)3); -@@ -1140,6 +1177,11 @@ +@@ -1140,6 +1183,13 @@ */ protected void fall(float par1) { -+ if (ForgeHooks.onEntityLivingFall(this, par1)) ++ LivingFallEvent event = new LivingFallEvent(this, par1); ++ if (MinecraftForge.EVENT_BUS.post(event)) + { + return; + } ++ par1 = event.distance; + super.fall(par1); int var2 = MathHelper.ceiling_float_int(par1 - 3.0F); -@@ -1327,7 +1369,7 @@ +@@ -1327,7 +1377,7 @@ int var2 = MathHelper.floor_double(this.boundingBox.minY); int var3 = MathHelper.floor_double(this.posZ); int var4 = this.worldObj.getBlockId(var1, var2, var3); @@ -129,11 +137,11 @@ } /** -@@ -1590,6 +1632,7 @@ +@@ -1590,6 +1640,7 @@ } this.isAirBorne = true; -+ ForgeHooks.onEntityLivingJump(this); ++ MinecraftForge.EVENT_BUS.post(new LivingJumpEvent(this)); } /** diff --git a/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch b/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch index c48915aff8..f9c4fb52e6 100644 --- a/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch +++ b/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch @@ -1,6 +1,6 @@ --- ../src_base/minecraft/net/minecraft/src/EntityPlayer.java +++ ../src_work/minecraft/net/minecraft/src/EntityPlayer.java -@@ -2,6 +2,11 @@ +@@ -2,6 +2,15 @@ import java.util.Iterator; import java.util.List; @@ -9,10 +9,14 @@ +import net.minecraftforge.common.IGuiHandler; +import net.minecraftforge.common.ISpecialArmor.ArmorProperties; +import net.minecraftforge.common.MinecraftForge; ++import net.minecraftforge.event.entity.living.LivingHurtEvent; ++import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; ++import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent; ++import net.minecraftforge.packets.PacketOpenGUI; public abstract class EntityPlayer extends EntityLiving implements ICommandSender { -@@ -207,6 +212,7 @@ +@@ -207,6 +216,7 @@ if (var1 == this.itemInUse) { @@ -20,7 +24,7 @@ if (this.itemInUseCount <= 25 && this.itemInUseCount % 4 == 0) { this.updateItemUse(var1, 5); -@@ -607,7 +613,16 @@ +@@ -607,7 +617,16 @@ */ public EntityItem dropOneItem() { @@ -38,7 +42,7 @@ } /** -@@ -673,13 +688,21 @@ +@@ -673,13 +692,21 @@ /** * Returns how strong the player is against the specified block at this moment @@ -63,15 +67,16 @@ { var2 += (float)(var3 * var3 + 1); } -@@ -972,12 +995,22 @@ +@@ -972,12 +999,23 @@ */ protected void damageEntity(DamageSource par1DamageSource, int par2) { -+ par2 = ForgeHooks.onEntityLivingHurt(this, par1DamageSource, par2); -+ if (par2 == 0) ++ LivingHurtEvent event = new LivingHurtEvent(this, par1DamageSource, par2); ++ if (MinecraftForge.EVENT_BUS.post(event) || event.ammount == 0) + { + return; + } ++ par2 = event.ammount; + if (!par1DamageSource.isUnblockable() && this.isBlocking()) { @@ -87,7 +92,7 @@ par2 = this.applyPotionDamageCalculations(par1DamageSource, par2); this.addExhaustion(par1DamageSource.getHungerDamage()); this.health -= par2; -@@ -1012,6 +1045,10 @@ +@@ -1012,6 +1050,10 @@ public boolean interactWith(Entity par1Entity) { @@ -98,17 +103,17 @@ if (par1Entity.interact(this)) { return true; -@@ -1055,7 +1092,9 @@ +@@ -1055,7 +1097,9 @@ */ public void destroyCurrentEquippedItem() { -+ ItemStack oldItem = getCurrentEquippedItem(); ++ ItemStack orig = getCurrentEquippedItem(); this.inventory.setInventorySlotContents(this.inventory.currentItem, (ItemStack)null); -+ ForgeHooks.onDestroyCurrentItem(this, oldItem); ++ MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(this, orig)); } /** -@@ -1084,6 +1123,15 @@ +@@ -1084,6 +1128,15 @@ */ public void attackTargetEntityWithCurrentItem(Entity par1Entity) { @@ -124,19 +129,20 @@ if (par1Entity.canAttackWithItem()) { int var2 = this.inventory.getDamageVsEntity(par1Entity); -@@ -1226,6 +1274,11 @@ +@@ -1226,6 +1279,12 @@ */ public EnumStatus sleepInBedAt(int par1, int par2, int par3) { -+ EnumStatus customSleep = ForgeHooks.sleepInBedAt(this, par1, par2, par3); -+ if (customSleep != null) ++ PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(this, par1, par2, par3); ++ MinecraftForge.EVENT_BUS.post(event); ++ if (event.result != null) + { -+ return customSleep; ++ return event.result; + } if (!this.worldObj.isRemote) { if (this.isPlayerSleeping() || !this.isEntityAlive()) -@@ -1265,6 +1318,11 @@ +@@ -1265,6 +1324,11 @@ { int var9 = this.worldObj.getBlockMetadata(par1, par2, par3); int var5 = BlockBed.getDirection(var9); @@ -148,7 +154,7 @@ float var10 = 0.5F; float var7 = 0.5F; -@@ -1334,11 +1392,12 @@ +@@ -1334,11 +1398,12 @@ this.resetHeight(); ChunkCoordinates var4 = this.playerLocation; ChunkCoordinates var5 = this.playerLocation; @@ -166,7 +172,7 @@ if (var5 == null) { -@@ -1375,7 +1434,9 @@ +@@ -1375,7 +1440,9 @@ */ private boolean isInBed() { @@ -177,7 +183,7 @@ } /** -@@ -1389,14 +1450,15 @@ +@@ -1389,14 +1456,15 @@ var2.loadChunk(par1ChunkCoordinates.posX + 3 >> 4, par1ChunkCoordinates.posZ - 3 >> 4); var2.loadChunk(par1ChunkCoordinates.posX - 3 >> 4, par1ChunkCoordinates.posZ + 3 >> 4); var2.loadChunk(par1ChunkCoordinates.posX + 3 >> 4, par1ChunkCoordinates.posZ + 3 >> 4); @@ -196,7 +202,7 @@ return var3; } } -@@ -1408,8 +1470,11 @@ +@@ -1408,8 +1476,11 @@ { if (this.playerLocation != null) { @@ -210,7 +216,7 @@ switch (var2) { -@@ -1699,6 +1764,7 @@ +@@ -1699,6 +1770,7 @@ return 101; } } @@ -218,7 +224,7 @@ } return var3; -@@ -1919,4 +1985,50 @@ +@@ -1919,4 +1991,50 @@ { return this.theInventoryEnderChest; } diff --git a/patches/minecraft/net/minecraft/src/EntityRenderer.java.patch b/patches/minecraft/net/minecraft/src/EntityRenderer.java.patch index 54e932dae3..d072849117 100644 --- a/patches/minecraft/net/minecraft/src/EntityRenderer.java.patch +++ b/patches/minecraft/net/minecraft/src/EntityRenderer.java.patch @@ -1,15 +1,18 @@ --- ../src_base/minecraft/net/minecraft/src/EntityRenderer.java +++ ../src_work/minecraft/net/minecraft/src/EntityRenderer.java -@@ -6,6 +6,8 @@ +@@ -6,6 +6,11 @@ import java.util.List; import java.util.Random; import net.minecraft.client.Minecraft; +import net.minecraftforge.client.ForgeHooksClient; ++import net.minecraftforge.client.event.DrawBlockHighlightEvent; ++import net.minecraftforge.client.event.RenderWorldLastEvent; ++import net.minecraftforge.common.MinecraftForge; + import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.GL11; -@@ -289,8 +291,15 @@ +@@ -289,8 +294,15 @@ */ private void updateFovModifierHand() { @@ -27,7 +30,7 @@ this.fovModifierHandPrev = this.fovModifierHand; this.fovModifierHand += (this.fovMultiplierTemp - this.fovModifierHand) * 0.5F; } -@@ -306,7 +315,7 @@ +@@ -306,7 +318,7 @@ } else { @@ -36,7 +39,7 @@ float var4 = 70.0F; if (par2) -@@ -394,11 +403,14 @@ +@@ -394,11 +406,14 @@ if (!this.mc.gameSettings.debugCamEnable) { int var10 = this.mc.theWorld.getBlockId(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posY), MathHelper.floor_double(var2.posZ)); @@ -56,13 +59,13 @@ GL11.glRotatef((float)(var12 * 90), 0.0F, 1.0F, 0.0F); } -@@ -1034,8 +1046,11 @@ +@@ -1034,8 +1049,11 @@ var17 = (EntityPlayer)var4; GL11.glDisable(GL11.GL_ALPHA_TEST); this.mc.mcProfiler.endStartSection("outline"); - var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1); - var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1); -+ if (!ForgeHooksClient.onBlockHighlight(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1)) ++ if (!MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1))) + { + var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1); + var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1); @@ -70,13 +73,13 @@ GL11.glEnable(GL11.GL_ALPHA_TEST); } } -@@ -1099,8 +1114,11 @@ +@@ -1099,8 +1117,11 @@ var17 = (EntityPlayer)var4; GL11.glDisable(GL11.GL_ALPHA_TEST); this.mc.mcProfiler.endStartSection("outline"); - var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1); - var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1); -+ if (!ForgeHooksClient.onBlockHighlight(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1)) ++ if (!MinecraftForge.EVENT_BUS.post(new DrawBlockHighlightEvent(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1))) + { + var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1); + var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1); @@ -84,13 +87,13 @@ GL11.glEnable(GL11.GL_ALPHA_TEST); } -@@ -1124,6 +1142,9 @@ +@@ -1124,6 +1145,9 @@ this.setupFog(1, par1); GL11.glPopMatrix(); } + + this.mc.mcProfiler.endStartSection("fhooks"); -+ ForgeHooksClient.onRenderWorldLast(var5, par1); ++ MinecraftForge.EVENT_BUS.post(new RenderWorldLastEvent(var5, par1)); this.mc.mcProfiler.endStartSection("hand"); diff --git a/patches/minecraft/net/minecraft/src/GuiAchievements.java.patch b/patches/minecraft/net/minecraft/src/GuiAchievements.java.patch index 27649b20e8..6bfc96e766 100644 --- a/patches/minecraft/net/minecraft/src/GuiAchievements.java.patch +++ b/patches/minecraft/net/minecraft/src/GuiAchievements.java.patch @@ -1,18 +1,19 @@ --- ../src_base/minecraft/net/minecraft/src/GuiAchievements.java +++ ../src_work/minecraft/net/minecraft/src/GuiAchievements.java -@@ -1,7 +1,11 @@ +@@ -1,7 +1,12 @@ package net.minecraft.src; +import java.util.LinkedList; +import java.util.List; import java.util.Random; import net.minecraft.client.Minecraft; ++import net.minecraftforge.common.AchievementPage; +import net.minecraftforge.common.MinecraftForge; + import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; -@@ -41,6 +45,10 @@ +@@ -41,6 +46,10 @@ /** Whether the Mouse Button is down or not */ private int isMouseButtonDown = 0; private StatFileWriter statFileWriter; @@ -23,14 +24,14 @@ public GuiAchievements(StatFileWriter par1StatFileWriter) { -@@ -49,6 +57,14 @@ +@@ -49,6 +58,14 @@ short var3 = 141; this.field_74117_m = this.guiMapX = this.field_74124_q = (double)(AchievementList.openInventory.displayColumn * 24 - var2 / 2 - 12); this.field_74115_n = this.guiMapY = this.field_74123_r = (double)(AchievementList.openInventory.displayRow * 24 - var3 / 2); + minecraftAchievements.clear(); + for (Object achievement : AchievementList.achievementList) + { -+ if (!MinecraftForge.isAchievementInPages((Achievement)achievement)) ++ if (!AchievementPage.isAchievementInPages((Achievement)achievement)) + { + minecraftAchievements.add((Achievement)achievement); + } @@ -38,15 +39,15 @@ } /** -@@ -58,6 +74,7 @@ +@@ -58,6 +75,7 @@ { this.controlList.clear(); this.controlList.add(new GuiSmallButton(1, this.width / 2 + 24, this.height / 2 + 74, 80, 20, StatCollector.translateToLocal("gui.done"))); -+ this.controlList.add(button = new GuiSmallButton(2, (width - achievementsPaneWidth) / 2 + 24, height / 2 + 74, 125, 20, getAchievementPageTitle(currentPage))); ++ this.controlList.add(button = new GuiSmallButton(2, (width - achievementsPaneWidth) / 2 + 24, height / 2 + 74, 125, 20, AchievementPage.getTitle(currentPage))); } /** -@@ -69,6 +86,16 @@ +@@ -69,6 +87,16 @@ { this.mc.displayGuiScreen((GuiScreen)null); this.mc.setIngameFocus(); @@ -55,15 +56,15 @@ + if (par1GuiButton.id == 2) + { + currentPage++; -+ if (currentPage >= MinecraftForge.getAchievementPages().size()) ++ if (currentPage >= AchievementPage.getAchievementPages().size()) + { + currentPage = -1; + } -+ button.displayString = getAchievementPageTitle(currentPage); ++ button.displayString = AchievementPage.getTitle(currentPage); } super.actionPerformed(par1GuiButton); -@@ -293,11 +320,12 @@ +@@ -293,11 +321,12 @@ int var27; int var30; @@ -72,7 +73,7 @@ - Achievement var33 = (Achievement)AchievementList.achievementList.get(var22); - - if (var33.parentAchievement != null) -+ List achievementList = (currentPage == -1 ? minecraftAchievements : MinecraftForge.getAchievementPage(currentPage).getAchievements()); ++ List achievementList = (currentPage == -1 ? minecraftAchievements : AchievementPage.getAchievementPage(currentPage).getAchievements()); + for (var22 = 0; var22 < achievementList.size(); ++var22) + { + Achievement var33 = achievementList.get(var22); @@ -81,7 +82,7 @@ { var24 = var33.displayColumn * 24 - var4 + 11 + var10; var25 = var33.displayRow * 24 - var5 + 11 + var11; -@@ -331,9 +359,9 @@ +@@ -331,9 +360,9 @@ int var42; int var41; @@ -94,16 +95,3 @@ var26 = var35.displayColumn * 24 - var4; var27 = var35.displayRow * 24 - var5; -@@ -457,4 +485,12 @@ - { - return true; - } -+ -+ /** -+ * FORGE: Gets the name for an achievement page by its index -+ */ -+ public static String getAchievementPageTitle(int index) -+ { -+ return index == -1 ? "Minecraft" : MinecraftForge.getAchievementPage(index).getName(); -+ } - } diff --git a/patches/minecraft/net/minecraft/src/Item.java.patch b/patches/minecraft/net/minecraft/src/Item.java.patch index f479cde0cd..f52d3d2cb9 100644 --- a/patches/minecraft/net/minecraft/src/Item.java.patch +++ b/patches/minecraft/net/minecraft/src/Item.java.patch @@ -27,7 +27,7 @@ Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21); return par1World.rayTraceBlocks_do_do(var13, var23, par3, !par3); } -@@ -625,4 +628,201 @@ +@@ -625,4 +628,187 @@ { StatList.initStats(); } @@ -37,20 +37,6 @@ + /* =========================================================== FORGE START ===============================================================*/ + public boolean isDefaultTexture = true; + private String currentTexture = "/gui/items.png"; -+ /** -+ * Called when a new CreativeContainer is opened, populate the list -+ * with all of the items for this item you want a player in creative mode -+ * to have access to. -+ * -+ * @param itemList The list of items currently in the creative inventory -+ */ -+ public void addCreativeItems(ArrayList itemList) -+ { -+ if (this.shiftedIndex != Item.potion.shiftedIndex && this.shiftedIndex != Item.monsterPlacer.shiftedIndex) -+ { -+ itemList.add(new ItemStack(this, 1)); -+ } -+ } + + /** + * Called when a player drops the item into the world, diff --git a/patches/minecraft/net/minecraft/src/ItemRenderer.java.patch b/patches/minecraft/net/minecraft/src/ItemRenderer.java.patch index 4c3a3453ee..1f4e49729d 100644 --- a/patches/minecraft/net/minecraft/src/ItemRenderer.java.patch +++ b/patches/minecraft/net/minecraft/src/ItemRenderer.java.patch @@ -30,7 +30,8 @@ + else if (par2ItemStack.getItem() instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.blocksList[par2ItemStack.itemID].getRenderType())) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/terrain.png")); - this.renderBlocksInstance.renderBlockAsItem(var4, par2ItemStack.getItemDamage(), 1.0F); +- this.renderBlocksInstance.renderBlockAsItem(var4, par2ItemStack.getItemDamage(), 1.0F); ++ this.renderBlocksInstance.renderBlockAsItem(Block.blocksList[par2ItemStack.itemID], par2ItemStack.getItemDamage(), 1.0F); } else { diff --git a/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch b/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch index 32d4f5b25c..f12f5079cf 100644 --- a/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch +++ b/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch @@ -1,16 +1,18 @@ --- ../src_base/minecraft/net/minecraft/src/NetClientHandler.java +++ ../src_work/minecraft/net/minecraft/src/NetClientHandler.java -@@ -18,6 +18,9 @@ +@@ -18,6 +18,11 @@ import java.util.Random; import javax.crypto.SecretKey; import net.minecraft.client.Minecraft; +import net.minecraftforge.client.ForgeHooksClient; ++import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.common.ForgeHooks; ++import net.minecraftforge.common.MinecraftForge; + import org.lwjgl.input.Keyboard; import cpw.mods.fml.common.LoaderException; -@@ -59,6 +62,8 @@ +@@ -59,6 +64,8 @@ this.mc = par1Minecraft; Socket var4 = new Socket(InetAddress.getByName(par2Str), par3); this.netManager = new TcpConnection(var4, "Client", this); @@ -19,7 +21,7 @@ } public NetClientHandler(Minecraft par1Minecraft, IntegratedServer par2IntegratedServer) throws IOException -@@ -159,6 +164,7 @@ +@@ -159,6 +166,7 @@ this.currentServerMaxPlayers = par1Packet1Login.maxPlayers; this.mc.playerController.setGameType(par1Packet1Login.gameType); this.addToSendQueue(new Packet204ClientInfo(this.mc.gameSettings.language, this.mc.gameSettings.renderDistance, this.mc.gameSettings.chatVisibility, this.mc.gameSettings.chatColours, this.mc.gameSettings.difficulty)); @@ -27,7 +29,7 @@ } public void handlePickupSpawn(Packet21PickupSpawn par1Packet21PickupSpawn) -@@ -586,7 +592,7 @@ +@@ -586,7 +594,7 @@ public void handleKickDisconnect(Packet255KickDisconnect par1Packet255KickDisconnect) { @@ -36,20 +38,20 @@ this.field_72554_f = true; this.mc.loadWorld((WorldClient)null); this.mc.displayGuiScreen(new GuiDisconnected("disconnect.disconnected", "disconnect.genericReason", new Object[] {par1Packet255KickDisconnect.reason})); -@@ -650,7 +656,11 @@ +@@ -650,7 +658,11 @@ public void handleChat(Packet3Chat par1Packet3Chat) { - this.mc.ingameGUI.func_73827_b().func_73765_a(par1Packet3Chat.message); -+ par1Packet3Chat.message = ForgeHooks.onClientChatRecv(par1Packet3Chat.message); -+ if (par1Packet3Chat.message != null) ++ ClientChatReceivedEvent event = new ClientChatReceivedEvent(par1Packet3Chat.message); ++ if (!MinecraftForge.EVENT_BUS.post(event) && event.message != null) + { -+ this.mc.ingameGUI.func_73827_b().func_73765_a(par1Packet3Chat.message); ++ this.mc.ingameGUI.func_73827_b().func_73765_a(event.message); + } } public void handleAnimation(Packet18Animation par1Packet18Animation) -@@ -1005,6 +1015,19 @@ +@@ -1005,6 +1017,19 @@ { ((TileEntityMobSpawner)var2).readFromNBT(par1Packet132TileEntityData.customParam1); } @@ -69,7 +71,7 @@ } } -@@ -1141,6 +1164,10 @@ +@@ -1141,6 +1166,10 @@ if (par1Packet131MapData.itemID == Item.map.shiftedIndex) { ItemMap.getMPMapData(par1Packet131MapData.uniqueID, this.mc.theWorld).updateMPMapData(par1Packet131MapData.itemData); diff --git a/patches/minecraft/net/minecraft/src/PlayerControllerMP.java.patch b/patches/minecraft/net/minecraft/src/PlayerControllerMP.java.patch index 85f3970dae..66ec4288e8 100644 --- a/patches/minecraft/net/minecraft/src/PlayerControllerMP.java.patch +++ b/patches/minecraft/net/minecraft/src/PlayerControllerMP.java.patch @@ -1,14 +1,16 @@ --- ../src_base/minecraft/net/minecraft/src/PlayerControllerMP.java +++ ../src_work/minecraft/net/minecraft/src/PlayerControllerMP.java -@@ -1,6 +1,7 @@ +@@ -1,6 +1,9 @@ package net.minecraft.src; import net.minecraft.client.Minecraft; +import net.minecraftforge.common.ForgeHooks; ++import net.minecraftforge.common.MinecraftForge; ++import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; public class PlayerControllerMP { -@@ -95,6 +96,11 @@ +@@ -95,6 +98,11 @@ */ public boolean onPlayerDestroyBlock(int par1, int par2, int par3, int par4) { @@ -20,7 +22,7 @@ if (this.currentGameType.isAdventure()) { return false; -@@ -112,7 +118,7 @@ +@@ -112,7 +120,7 @@ { var5.playAuxSFX(2001, par1, par2, par3, var6.blockID + (var5.getBlockMetadata(par1, par2, par3) << 12)); int var7 = var5.getBlockMetadata(par1, par2, par3); @@ -29,7 +31,7 @@ if (var8) { -@@ -290,6 +296,12 @@ +@@ -290,6 +298,12 @@ public boolean onPlayerRightClick(EntityPlayer par1EntityPlayer, World par2World, ItemStack par3ItemStack, int par4, int par5, int par6, int par7, Vec3 par8Vec3) { this.syncCurrentPlayItem(); @@ -42,18 +44,18 @@ float var9 = (float)par8Vec3.xCoord - (float)par4; float var10 = (float)par8Vec3.yCoord - (float)par5; float var11 = (float)par8Vec3.zCoord - (float)par6; -@@ -333,6 +345,16 @@ +@@ -332,7 +346,15 @@ + } else { - return par3ItemStack.tryPlaceItemIntoWorld(par1EntityPlayer, par2World, par4, par5, par6, par7, var9, var10, var11); -+ +- return par3ItemStack.tryPlaceItemIntoWorld(par1EntityPlayer, par2World, par4, par5, par6, par7, var9, var10, var11); + if (!par3ItemStack.tryPlaceItemIntoWorld(par1EntityPlayer, par2World, par4, par5, par6, par7, var9, var10, var11)) + { + return false; + } + if (par3ItemStack.stackSize <= 0) + { -+ ForgeHooks.onDestroyCurrentItem(par1EntityPlayer, par3ItemStack); ++ MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(par1EntityPlayer, par3ItemStack)); + } + return true; } diff --git a/patches/minecraft/net/minecraft/src/SoundManager.java.patch b/patches/minecraft/net/minecraft/src/SoundManager.java.patch index 3a9ab7368d..bd7aed7654 100644 --- a/patches/minecraft/net/minecraft/src/SoundManager.java.patch +++ b/patches/minecraft/net/minecraft/src/SoundManager.java.patch @@ -1,15 +1,20 @@ --- ../src_base/minecraft/net/minecraft/src/SoundManager.java +++ ../src_work/minecraft/net/minecraft/src/SoundManager.java -@@ -2,6 +2,8 @@ +@@ -2,6 +2,13 @@ import java.io.File; import java.util.Random; + +import net.minecraftforge.client.ForgeHooksClient; ++import net.minecraftforge.client.ModCompatibilityClient; ++import net.minecraftforge.client.event.sound.SoundEvent; ++import net.minecraftforge.client.event.sound.SoundEvent.PlayBackgroundMusicEvent; ++import net.minecraftforge.common.MinecraftForge; ++import static net.minecraftforge.client.event.sound.SoundEvent.*; import paulscode.sound.SoundSystem; import paulscode.sound.SoundSystemConfig; import paulscode.sound.codecs.CodecJOrbis; -@@ -37,9 +39,11 @@ +@@ -37,9 +44,11 @@ private Random rand = new Random(); private int ticksBeforeMusic; @@ -22,30 +27,30 @@ } /** -@@ -54,6 +58,8 @@ +@@ -54,6 +63,8 @@ { this.tryToSetLibraryAndCodecs(); } + ModCompatibilityClient.audioModLoad(this); -+ ForgeHooksClient.onLoadSoundSettings(this); ++ MinecraftForge.EVENT_BUS.post(new SoundLoadEvent(this)); } /** -@@ -73,6 +79,8 @@ +@@ -73,6 +84,8 @@ SoundSystemConfig.setCodec("ogg", CodecJOrbis.class); SoundSystemConfig.setCodec("mus", CodecMus.class); SoundSystemConfig.setCodec("wav", CodecWav.class); + ModCompatibilityClient.audioModAddCodecs(); -+ ForgeHooksClient.onSetupAudio(this); ++ MinecraftForge.EVENT_BUS.post(new SoundSetupEvent(this)); sndSystem = new SoundSystem(); this.options.soundVolume = var1; this.options.musicVolume = var2; -@@ -161,10 +169,12 @@ +@@ -161,10 +174,12 @@ } SoundPoolEntry var1 = this.soundPoolMusic.getRandomSound(); + var1 = ModCompatibilityClient.audioModPickBackgroundMusic(this, var1); -+ var1 = ForgeHooksClient.onPlayBackgroundMusic(this, var1); ++ var1 = SoundEvent.getResult(new PlayBackgroundMusicEvent(this, var1)); if (var1 != null) { @@ -54,27 +59,27 @@ sndSystem.backgroundMusic("BgMusic", var1.soundUrl, var1.soundName, false); sndSystem.setVolume("BgMusic", this.options.musicVolume); sndSystem.play("BgMusic"); -@@ -214,6 +224,7 @@ +@@ -214,6 +229,7 @@ if (par1Str != null) { SoundPoolEntry var8 = this.soundPoolStreaming.getRandomSoundFromSoundPool(par1Str); -+ var8 = ForgeHooksClient.onPlayStreaming(this, var8, par1Str, par2, par3, par4); ++ var8 = SoundEvent.getResult(new PlayStreamingEvent(this, var8, par1Str, par2, par3, par4)); if (var8 != null && par5 > 0.0F) { -@@ -239,6 +250,7 @@ +@@ -239,6 +255,7 @@ if (loaded && this.options.soundVolume != 0.0F) { SoundPoolEntry var7 = this.soundPoolSounds.getRandomSoundFromSoundPool(par1Str); -+ var7 = ForgeHooksClient.onPlaySound(this, var7, par1Str, par2, par3, par4, par5, par6); ++ var7 = SoundEvent.getResult(new PlaySoundEvent(this, var7, par1Str, par2, par3, par4, par5, par6)); if (var7 != null && par5 > 0.0F) { -@@ -274,6 +286,7 @@ +@@ -274,6 +291,7 @@ if (loaded && this.options.soundVolume != 0.0F) { SoundPoolEntry var4 = this.soundPoolSounds.getRandomSoundFromSoundPool(par1Str); -+ var4 = ForgeHooksClient.onPlaySoundEffect(this, var4, par1Str, par2, par3); ++ var4 = SoundEvent.getResult(new PlaySoundEffectEvent(this, var4, par1Str, par2, par3)); if (var4 != null) { diff --git a/patches/minecraft/net/minecraft/src/WorldRenderer.java.patch b/patches/minecraft/net/minecraft/src/WorldRenderer.java.patch index fd958abd6f..cc786ef9e6 100644 --- a/patches/minecraft/net/minecraft/src/WorldRenderer.java.patch +++ b/patches/minecraft/net/minecraft/src/WorldRenderer.java.patch @@ -49,7 +49,7 @@ var12 = true; } - else if (var24 == var11) -+ if (!ForgeHooksClient.canRenderInPass(var23, var11)) ++ if (!var23.canRenderInPass(var11)) { - var13 |= var10.renderBlockByRenderType(var23, var17, var15, var16); + continue;