diff --git a/src/api/java/morph/api/Ability.java b/src/api/java/morph/api/Ability.java new file mode 100644 index 00000000..5120ddbd --- /dev/null +++ b/src/api/java/morph/api/Ability.java @@ -0,0 +1,274 @@ +package morph.api; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * + * Abstract ability class. + * Think of it like the Entity class, extend it to make your own types. + * Some abilities may seem more like traits, but let's just call it an ability for simplicity's sake. + * Please take note that entities inherit their superclass' abilities. + * @author iChun + * + */ +public abstract class Ability +{ + /** + * Ability parent field. Will be null for instances used in registration. Ability is then cloned and parent assigned later on. + */ + private EntityLivingBase parent; + + /** + * Flag for Ability activity. If true, tick/postRender/kill will notbe called. + */ + public boolean inactive; + + /** + * Basic constructor (but you didn't really need me to tell you that ;D ) + */ + public Ability() + { + parent = null; + } + + /** + * Function for mod mob support, with args. + */ + public Ability parse(String[] args) { return this; } + + /** + * Since parent is private it needs a setter. + * @param newParent + */ + public void setParent(EntityLivingBase ent) + { + parent = ent; + } + + /** + * Get's the parent entity for this ability + * @return Entity the ability takes effect on + */ + public EntityLivingBase getParent() + { + return parent; + } + + /** + * Each ability has to return a String type. + * This is used for comparison, saving, as well as construction/loading of Ability. + * Think of it like the way Minecraft registers entities. + * @return Ability type + */ + public abstract String getType(); + + /** + * Ticks every world tick, basically an ability onUpdate, similar to Entity's onUpdate. + * Will only tick if getParent() is not null. + * Please remember that getParent is not necessarily a player. + */ + public abstract void tick(); + + /** + * Called when the ability is finally removed when the parent demorphs or morphs into a state that does not have this ability type. + * This will NOT be called if the parent morphs into another morph that has this type of ability. + */ + public abstract void kill(); + + /** + * Creates a copy of this ability for use with parents. + * As previously stated before the ability instance used during registration is a base so it needs to be cloned for use with parents. + */ + public abstract Ability clone(); + + /** + * Return true for this if you need an inactive copy of this morph in-between morph states (abilities of the next morph are only swapped over when morph is complete) + * Currently used for AbilitySwim to adjust the fog render. + * @return requiresInactiveClone + */ + public boolean requiresInactiveClone() + { + return false; + } + + /** + * Saving of ability to NBTTagCompound. + * Mainly used for synching Abilities between the client-server for mod mobs which do not use the API to add abilities. + * The ability type (getType()) is appended to nbt before function is called. + * Not actually used. + * @param NBTTagCompound saveData + */ + public abstract void save(NBTTagCompound tag); + + /** + * Loading of ability from NBTTagCompound. + * Mainly used to load custom fields from NBT. + * Not actually used. + * @param NBTTagCompound saveData + */ + public abstract void load(NBTTagCompound tag); + + /** + * Rendering to be done post-render. + * EG: Used by AbilitySwim to render air bubbles whilst on land. + */ + @SideOnly(Side.CLIENT) + public abstract void postRender(); + + /** + * Icon location for ability. Can be null. + * Mod's default icons are 32x32. Can be any resolution though. + * @return resourcelocation for icon + */ + @SideOnly(Side.CLIENT) + public abstract ResourceLocation getIcon(); + + @SideOnly(Side.CLIENT) + public boolean entityHasAbility(EntityLivingBase living) + { + return true; + } + + /** + * Registers the ability so the mod can look up the class when attempting to load Ability save data. + * Call this no later than PostInit. + * @param ability type + * @param AbilityClass + */ + public static void registerAbility(String name, Class clz) + { + try { + Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("registerAbility", String.class, Class.class).invoke(null, name, clz); + } catch (Exception e) { + } + } + + /** + * Maps abilities to an Entity. + * Adds on to the previous ability list, so this allows you to add abilities to Entity classes which already have abilities mapped. + * However, only one ability of the same type is allowed for each entity. This method will overwrite abilities of the same type that were already mapped. + * This will also register new abilities which were not registered before (just in case). + * Call this no later than PostInit. + * @param entClass + * @param abilities + */ + public static void mapAbilities(Class entClass, Ability...abilities) + { + try { + Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("mapAbilities", Class.class, Ability[].class).invoke(null, entClass, abilities); + } catch (Exception e) { + } + } + + /** + * Superman's kryptonite. + * @param Entity class to remove ability from + * @param Ability type + */ + public static void removeAbility(Class entClass, String type) + { + try { + Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("removeAbility", Class.class, String.class).invoke(null, entClass, type); + } catch (Exception e) { + } + } + + /** + * Checks to see if the entity class has a mapped ability type. + * @param entClass + * @param Ability type + * @return Entity class has ability type + */ + public static boolean hasAbility(Class entClass, String type) + { + try { + return (Boolean)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("hasAbility", Class.class, String.class).invoke(null, entClass, type); + } catch (Exception e) { + return false; + } + } + + /** + * The following are helper functions to create abilities packaged with Morph. + * Use these to ability instances for mapping vanilla abilities to mobs. + * Self explanatory. + * @return + */ + public static Ability getNewAbilityClimb() + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityClimb").invoke(null); + } catch (Exception e) { + return null; + } + }//TODO add new abilities + public static Ability getNewAbilityFireImmunity() + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityFireImmunity").invoke(null); + } catch (Exception e) { + return null; + } + } + public static Ability getNewAbilityFloat(float terminalVelocity, boolean negateFallDamage) + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityFloat", float.class, boolean.class).invoke(null, terminalVelocity, negateFallDamage); + } catch (Exception e) { + return null; + } + } + public static Ability getNewAbilityFly(boolean slowdownInWater) + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityFly", boolean.class).invoke(null, slowdownInWater); + } catch (Exception e) { + return null; + } + } + public static Ability getNewAbilityFly() + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityFly", boolean.class).invoke(null, true); + } catch (Exception e) { + return null; + } + } + public static Ability getNewAbilityHostile() + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityHostile").invoke(null); + } catch (Exception e) { + return null; + } + } + public static Ability getNewAbilitySunburn() + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilitySunburn").invoke(null); + } catch (Exception e) { + return null; + } + } + public static Ability getNewAbilitySwim(boolean canBreatheOnLand) + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilitySwim", boolean.class).invoke(null, canBreatheOnLand); + } catch (Exception e) { + return null; + } + } + public static Ability getNewAbilityWaterAllergy() + { + try { + return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityWaterAllergy").invoke(null); + } catch (Exception e) { + return null; + } + } + +} diff --git a/src/api/java/morph/api/Api.java b/src/api/java/morph/api/Api.java new file mode 100644 index 00000000..1cfb49d4 --- /dev/null +++ b/src/api/java/morph/api/Api.java @@ -0,0 +1,170 @@ +package morph.api; + +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ResourceLocation; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public final class Api +{ + /** + * Returns if a player is has a morph. If morph progress < 1.0F, player is mid-morphing. + * Players demorphing are considered as a player with a morph until the demorph is complete. + * @param Player Username + * @param Clientside (false for Serverside) + */ + public static boolean hasMorph(String playerName, boolean isClient) + { + try { + return (Boolean)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("hasMorph", String.class, boolean.class).invoke(null, playerName, isClient); + } catch (Exception e) { + return false; + } + } + + /** + * Returns morph progression of a player. Time per morph is 80 ticks. + * If player does not have a morph, 1.0F will be returned. + * @param Player Username + * @param Clientside (false for Serverside) + */ + public static float morphProgress(String playerName, boolean isClient) + { + try { + return (Float)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("morphProgress", String.class, boolean.class).invoke(null, playerName, isClient); + } catch (Exception e) { + return 1.0F; + } + } + + /** + * Returns previous entity instance used to render the morph. + * If player does not have a previous morph state, null will be returned. + * @param Player Username + * @param Clientside (false for Serverside) + */ + public static EntityLivingBase getPrevMorphEntity(String playerName, boolean isClient) + { + try { + return (EntityLivingBase)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getPrevMorphEntity", String.class, boolean.class).invoke(null, playerName, isClient); + } catch (Exception e) { + return null; + } + } + + /** + * Returns entity instance used to render the morph. + * If player does not have a morph, null will be returned. + * @param Player Username + * @param Clientside (false for Serverside) + */ + public static EntityLivingBase getMorphEntity(String playerName, boolean isClient) + { + try { + return (EntityLivingBase)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getMorphEntity", String.class, boolean.class).invoke(null, playerName, isClient); + } catch (Exception e) { + return null; + } + } + + /** + * Blacklists an entity from being morphed into. + * Previously saved morphs of the classtype will not be removed. + * @param Class (extends EntityLivingBase) + */ + public static void blacklistEntity(Class clz) + { + try { + Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("blacklistEntity", Class.class).invoke(null, clz); + } catch (Exception e) { + } + } + + /** + * Forces a player to morph into an EntityLivingBase, also adds said entity to the morph list. + * Called Serverside only. + * @param player + * @param living + * @return morphSuccessful + */ + public static boolean forceMorph(EntityPlayerMP player, EntityLivingBase living) + { + try { + return (Boolean)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("forceMorph", EntityPlayerMP.class, EntityLivingBase.class).invoke(null, player, living); + } catch (Exception e) { + return false; + } + } + + /** + * Forces a player to demorph. + * Called Serverside only. + * @param player + */ + public static void forceDemorph(EntityPlayerMP player) + { + try { + Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("forceDemorph", EntityPlayerMP.class).invoke(null, player); + } catch (Exception e) { + } + } + + /** + * Checks if the entity passed on is a Morph. + * If it is, the player name will be passed, else null. + * @param EntityLivingBase instance + * @param Clientside (false for Serverside) + */ + public static String isEntityAMorph(EntityLivingBase living, boolean isClient) + { + try { + return (String)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("isEntityAMorph", EntityLivingBase.class, boolean.class).invoke(null, living, isClient); + } catch (Exception e) { + return null; + } + } + + /** + * Allows the rendering of the next player rendered. + * Prevents Morph from cancelling the player render event to render the morphed entity. + */ + public static void allowNextPlayerRender() + { + try { + Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("allowNextPlayerRender").invoke(null); + } catch (Exception e) { + } + } + + /** + * Returns the black grainy morph skin that overlays the player when the player is morphing + * @return Morph Skin Resource Location + */ + @SideOnly(Side.CLIENT) + public static ResourceLocation getMorphSkinTexture() + { + try { + return (ResourceLocation)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getMorphSkinTexture").invoke(null); + } catch (Exception e) { + return AbstractClientPlayer.locationStevePng; + } + } + + /** + * Assign a specific arm to a model for rendering in First Person. + * @param model Model which arm you are registering for + * @param arm The arm in a ModelRenderer form. + */ + @SideOnly(Side.CLIENT) + public static void registerArmForModel(ModelBase model, ModelRenderer arm) + { + try { + Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("registerArmForModel", ModelBase.class, ModelRenderer.class).invoke(null, model, arm); + } catch (Exception e) { + } + } +} diff --git a/src/main/java/tconstruct/armor/ArmorProxyClient.java b/src/main/java/tconstruct/armor/ArmorProxyClient.java index 0b3c48c0..cc29dfc3 100644 --- a/src/main/java/tconstruct/armor/ArmorProxyClient.java +++ b/src/main/java/tconstruct/armor/ArmorProxyClient.java @@ -15,6 +15,8 @@ import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.IAttributeInstance; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.MathHelper; @@ -25,7 +27,7 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.common.MinecraftForge; -import tconstruct.TConstruct; +import tconstruct.armor.items.TravelGear; import tconstruct.armor.model.BeltModel; import tconstruct.armor.model.BootBump; import tconstruct.armor.model.HiddenPlayerModel; @@ -41,13 +43,16 @@ import tconstruct.client.tabs.InventoryTabVanilla; import tconstruct.client.tabs.TabRegistry; import tconstruct.common.TProxyCommon; import tconstruct.library.accessory.IAccessoryModel; +import tconstruct.library.modifier.IModifyable; import tconstruct.util.player.TPlayerStats; import com.google.common.collect.Lists; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; public class ArmorProxyClient extends ArmorProxyCommon { @@ -56,23 +61,24 @@ public class ArmorProxyClient extends ArmorProxyCommon public static HiddenPlayerModel glove = new HiddenPlayerModel(0.25F, 4); public static HiddenPlayerModel vest = new HiddenPlayerModel(0.25f, 1); public static BeltModel belt = new BeltModel(); - + @Override - public void initialize() + public void initialize () { registerGuiHandler(); MinecraftForge.EVENT_BUS.register(this); + FMLCommonHandler.instance().bus().register(this); } - + @Override - protected void registerGuiHandler() + protected void registerGuiHandler () { super.registerGuiHandler(); TProxyCommon.registerClientGuiHandler(inventoryGui, this); TProxyCommon.registerClientGuiHandler(armorGuiID, this); TProxyCommon.registerClientGuiHandler(knapsackGuiID, this); } - + @Override public Object getClientGuiElement (int ID, EntityPlayer player, World world, int x, int y, int z) { @@ -101,7 +107,7 @@ public class ArmorProxyClient extends ArmorProxyCommon FMLCommonHandler.instance().bus().register(new ArmorTickHandler()); new ArmorTickHandler(); } - + /* Keybindings */ public static TControls controlInstance; @@ -131,7 +137,6 @@ public class ArmorProxyClient extends ArmorProxyCommon settings.keyBindings = allKeys; settings.loadOptions(); } - Minecraft mc = Minecraft.getMinecraft(); @@ -292,7 +297,8 @@ public class ArmorProxyClient extends ArmorProxyCommon } double zLevel = 0; - + + /* Armor rendering */ @SubscribeEvent public void adjustArmor (RenderPlayerEvent.SetArmorModel event) { @@ -315,14 +321,14 @@ public class ArmorProxyClient extends ArmorProxyCommon ArmorProxyClient.glove.isSneak = event.renderer.modelBipedMain.isSneak; ArmorProxyClient.glove.heldItemLeft = event.renderer.modelBipedMain.heldItemLeft; ArmorProxyClient.glove.heldItemRight = event.renderer.modelBipedMain.heldItemRight; - + ArmorProxyClient.belt.onGround = event.renderer.modelBipedMain.onGround; ArmorProxyClient.belt.isRiding = event.renderer.modelBipedMain.isRiding; ArmorProxyClient.belt.isChild = event.renderer.modelBipedMain.isChild; ArmorProxyClient.belt.isSneak = event.renderer.modelBipedMain.isSneak; - + renderArmorExtras(event); - + break; case 3: ArmorProxyClient.bootbump.onGround = event.renderer.modelBipedMain.onGround; @@ -332,8 +338,8 @@ public class ArmorProxyClient extends ArmorProxyCommon break; } } - - void renderArmorExtras(RenderPlayerEvent.SetArmorModel event) + + void renderArmorExtras (RenderPlayerEvent.SetArmorModel event) { float partialTick = event.partialRenderTick; @@ -375,7 +381,7 @@ public class ArmorProxyClient extends ArmorProxyCommon float bodyRotation = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTick; float limbSwing = player.prevLimbSwingAmount + (player.limbSwingAmount - player.prevLimbSwingAmount) * partialTick; float limbSwingMod = player.limbSwing - player.limbSwingAmount * (1.0F - partialTick); - TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.getPersistentID()); + TPlayerStats stats = TPlayerStats.get(player); if (stats.armor.inventory[1] != null) { Item item = stats.armor.inventory[1].getItem(); @@ -402,7 +408,7 @@ public class ArmorProxyClient extends ArmorProxyCommon } } } - + private float interpolateRotation (float par1, float par2, float par3) { float f3; @@ -419,9 +425,110 @@ public class ArmorProxyClient extends ArmorProxyCommon return par1 + par3 * f3; } - + protected float handleRotationFloat (EntityLivingBase par1EntityLivingBase, float par2) { return (float) par1EntityLivingBase.ticksExisted + par2; } + + /* Abilities */ + + ItemStack prevFeet; + double prevMotionY; + boolean morphed; + float prevMouseSensitivity; + boolean sprint; + + @EventHandler + public void playerTick (TickEvent.PlayerTickEvent event) + { + System.out.println("Client Tick!"); + EntityPlayer player = event.player; + TPlayerStats stats = TPlayerStats.get(player); + if (mc.thePlayer.onGround) + { + controlInstance.landOnGround(); + } + if (stats.climbWalls && player.isCollidedHorizontally && !player.isSneaking()) + { + player.motionY = 0.1176D; + player.fallDistance = 0.0f; + } + + //Feet changes + ItemStack feet = player.getCurrentArmor(0); + if (feet != null) + { + if (feet.getItem() instanceof TravelGear && player.stepHeight < 1.0f) + { + player.stepHeight += 0.6f; + } + if (feet.getItem() instanceof IModifyable && !player.isSneaking()) + { + NBTTagCompound tag = feet.getTagCompound().getCompoundTag(((IModifyable) feet.getItem()).getBaseTagName()); + int sole = tag.getInteger("Slimy Soles"); + if (sole > 0) + { + if (!player.isSneaking() && player.onGround && prevMotionY < -0.4) + player.motionY = -prevMotionY * (Math.min(0.99, sole * 0.2)); + } + } + prevMotionY = player.motionY; + } + if (feet != prevFeet) + { + if (prevFeet != null && prevFeet.getItem() instanceof TravelGear) + player.stepHeight -= 0.6f; + if (feet != null && feet.getItem() instanceof TravelGear) + player.stepHeight += 0.6f; + prevFeet = feet; + } + + //Legs or wing changes + /*ItemStack legs = player.getCurrentArmor(1); + if (legs != null && legs.getItem() instanceof IModifyable) + { + NBTTagCompound tag = legs.getTagCompound().getCompoundTag(((IModifyable) legs.getItem()).getBaseTagName()); + if (player.isSprinting()) + { + if (!sprint) + { + sprint = true; + int sprintboost = tag.getInteger("Sprint Assist"); + if (player.isSprinting() && sprintboost > 0) + { + prevMouseSensitivity = gs.mouseSensitivity; + gs.mouseSensitivity *= 1 - (0.15 * sprintboost); + } + } + } + else if (sprint) + { + sprint = false; + gs.mouseSensitivity = prevMouseSensitivity; + } + }*/ + if (!player.isPlayerSleeping() && !morphed) + { + ItemStack chest = player.getCurrentArmor(2); + if (chest == null || !(chest.getItem() instanceof IModifyable)) + { + PlayerAbilityHelper.setEntitySize(player, 0.6F, 1.8F); + } + else + { + NBTTagCompound tag = chest.getTagCompound().getCompoundTag(((IModifyable) chest.getItem()).getBaseTagName()); + int dodge = tag.getInteger("Perfect Dodge"); + if (dodge > 0) + { + PlayerAbilityHelper.setEntitySize(player, Math.max(0.15F, 0.6F - (dodge * 0.09f)), 1.8F - (dodge * 0.04f)); + } + } + } + } + + EntityPlayer getPlayer () + { + return mc.thePlayer; + } } diff --git a/src/main/java/tconstruct/armor/PlayerAbilityHelper.java b/src/main/java/tconstruct/armor/PlayerAbilityHelper.java new file mode 100644 index 00000000..e8690487 --- /dev/null +++ b/src/main/java/tconstruct/armor/PlayerAbilityHelper.java @@ -0,0 +1,114 @@ +package tconstruct.armor; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.*; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.*; +import net.minecraft.potion.*; +import tconstruct.TConstruct; +import tconstruct.util.player.TPlayerStats; + +public class PlayerAbilityHelper +{ + + public static void toggleGoggles (EntityPlayer player) + { + TPlayerStats stats = TPlayerStats.get(player); + stats.activeGoggles = !stats.activeGoggles; + if (!stats.activeGoggles) + { + player.removePotionEffect(Potion.nightVision.id); + } + else + { + player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 15 * 20, 0, true)); + } + } + + public static void swapBelt (EntityPlayer player, TPlayerStats stats) + { + NBTTagList slots = new NBTTagList(); + InventoryPlayer hotbar = player.inventory; + + NBTTagCompound itemTag; + + for (int i = 0; i < 9; ++i) + { + if (hotbar.mainInventory[i] != null) + { + itemTag = new NBTTagCompound(); + itemTag.setByte("Slot", (byte) i); + hotbar.mainInventory[i].writeToNBT(itemTag); + slots.appendTag(itemTag); + } + hotbar.mainInventory[i] = null; + } + + ItemStack belt = stats.armor.inventory[3]; + NBTTagList replaceSlots = belt.getTagCompound().getTagList("Inventory", 10); + for (int i = 0; i < replaceSlots.tagCount(); ++i) + { + NBTTagCompound nbttagcompound = replaceSlots.getCompoundTagAt(i); + int j = nbttagcompound.getByte("Slot") & 255; + ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound); + + if (itemstack != null) + { + if (j >= 0 && j < hotbar.mainInventory.length) + { + hotbar.mainInventory[j] = itemstack; + } + } + } + belt.getTagCompound().setTag("Inventory", slots); + } + + + + public static void setEntitySize(Entity entity, float width, float height) + { + float f2; + + if (width != entity.width || height != entity.height) + { + f2 = entity.width; + entity.width = width; + entity.height = height; + entity.boundingBox.maxX = entity.boundingBox.minX + (double)entity.width; + entity.boundingBox.maxZ = entity.boundingBox.minZ + (double)entity.width; + entity.boundingBox.maxY = entity.boundingBox.minY + (double)entity.height; + + if (entity.width > f2 && !entity.worldObj.isRemote) + { + entity.moveEntity((double)(f2 - entity.width), 0.0D, (double)(f2 - entity.width)); + } + } + + f2 = width % 2.0F; + + if ((double)f2 < 0.375D) + { + entity.myEntitySize = Entity.EnumEntitySize.SIZE_1; + } + else if ((double)f2 < 0.75D) + { + entity.myEntitySize = Entity.EnumEntitySize.SIZE_2; + } + else if ((double)f2 < 1.0D) + { + entity.myEntitySize = Entity.EnumEntitySize.SIZE_3; + } + else if ((double)f2 < 1.375D) + { + entity.myEntitySize = Entity.EnumEntitySize.SIZE_4; + } + else if ((double)f2 < 1.75D) + { + entity.myEntitySize = Entity.EnumEntitySize.SIZE_5; + } + else + { + entity.myEntitySize = Entity.EnumEntitySize.SIZE_6; + } + } +} diff --git a/src/main/java/tconstruct/armor/TinkerArmor.java b/src/main/java/tconstruct/armor/TinkerArmor.java index a185cd98..2d56d36f 100644 --- a/src/main/java/tconstruct/armor/TinkerArmor.java +++ b/src/main/java/tconstruct/armor/TinkerArmor.java @@ -32,6 +32,7 @@ import tconstruct.library.crafting.LiquidCasting; import tconstruct.tools.TinkerTools; import tconstruct.world.TinkerWorld; import tconstruct.world.items.GoldenHead; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; @@ -40,7 +41,7 @@ import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder; @ObjectHolder(TConstruct.modID) -@Pulse(id = "Tinkers' Armor", description = "Modifyable armors, such as the traveller's gear.") +@Pulse(id = "Tinkers' Armory", description = "Modifyable armors, such as the traveller's gear.") public class TinkerArmor { @PulseProxy(clientSide = "tconstruct.armor.ArmorProxyClient", serverSide = "tconstruct.armor.ArmorProxyCommon") @@ -73,15 +74,14 @@ public class TinkerArmor public static TravelGear travelBoots; public static AccessoryCore travelGlove; public static AccessoryCore travelBelt; - - public TinkerArmor() - { - MinecraftForge.EVENT_BUS.register(new TinkerArmorEvents()); - } - + @Handler public void preInit (FMLPreInitializationEvent event) { + TinkerArmorEvents events = new TinkerArmorEvents(); + MinecraftForge.EVENT_BUS.register(events); + FMLCommonHandler.instance().bus().register(events); + TinkerArmor.dryingRack = new DryingRack().setBlockName("Armor.DryingRack"); GameRegistry.registerBlock(TinkerArmor.dryingRack, "Armor.DryingRack"); GameRegistry.registerTileEntity(DryingRackLogic.class, "Armor.DryingRack"); diff --git a/src/main/java/tconstruct/armor/TinkerArmorEvents.java b/src/main/java/tconstruct/armor/TinkerArmorEvents.java index abd19839..a1f729d6 100644 --- a/src/main/java/tconstruct/armor/TinkerArmorEvents.java +++ b/src/main/java/tconstruct/armor/TinkerArmorEvents.java @@ -3,23 +3,22 @@ package tconstruct.armor; import net.minecraft.entity.boss.EntityDragon; import net.minecraft.entity.boss.IBossDisplayData; import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.monster.EntityCreeper; -import net.minecraft.entity.monster.EntityGhast; -import net.minecraft.entity.monster.EntitySkeleton; -import net.minecraft.entity.monster.EntityZombie; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.event.entity.living.LivingDropsEvent; +import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent; +import net.minecraftforge.event.entity.living.LivingFallEvent; import tconstruct.TConstruct; -import tconstruct.library.tools.ToolCore; -import tconstruct.tools.TinkerTools; -import tconstruct.util.ItemHelper; -import tconstruct.util.config.PHConstruct; +import tconstruct.armor.items.TravelWings; +import tconstruct.library.modifier.IModifyable; +import tconstruct.util.player.TPlayerStats; import tconstruct.world.entity.BlueSlime; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; public class TinkerArmorEvents { @@ -56,4 +55,87 @@ public class TinkerArmorEvents event.drops.add(entityitem); } } + + //Abilities + boolean morphed; + boolean morphLoaded = Loader.isModLoaded("Morph"); + + @EventHandler + public void playerTick (TickEvent.PlayerTickEvent event) + { + System.out.println("Server Tick!"); + EntityPlayer player = event.player; + TPlayerStats stats = TPlayerStats.get(player); + if (stats.climbWalls) + { + double motionX = player.posX - player.lastTickPosX; + double motionZ = player.posZ - player.lastTickPosZ; + double motionY = player.posY - player.lastTickPosY - 0.762; + if (motionY > 0.0D && (motionX == 0D || motionZ == 0D)) + { + player.fallDistance = 0.0F; + } + } + //TODO: Proper minimap support + /*ItemStack stack = player.inventory.getStackInSlot(8); + if (stack != null && stack.getItem() instanceof ItemMap) + { + stack.getItem().onUpdate(stack, player.worldObj, player, 8, true); + }*/ + if (!player.isPlayerSleeping()) + { + ItemStack chest = player.getCurrentArmor(2); + if (chest == null || !(chest.getItem() instanceof IModifyable)) + { + if (!morphLoaded || !morphed) + PlayerAbilityHelper.setEntitySize(player, 0.6F, 1.8F); + } + else + { + NBTTagCompound tag = chest.getTagCompound().getCompoundTag(((IModifyable) chest.getItem()).getBaseTagName()); + int dodge = tag.getInteger("Perfect Dodge"); + if (dodge > 0) + { + if (!morphLoaded || !morphed) + PlayerAbilityHelper.setEntitySize(player, Math.max(0.15F, 0.6F - (dodge * 0.09f)), 1.8F - (dodge * 0.04f)); + } + } + } + } + + /* Abilities */ + @EventHandler + public void armorMineSpeed (net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed event) + { + TPlayerStats stats = TPlayerStats.get(event.entityPlayer); + float modifier = 1f + stats.mineSpeed / 1000f; + float base = stats.mineSpeed / 250f; + event.newSpeed = (event.newSpeed + base) * modifier; + } + + @EventHandler + public void jumpHeight (LivingJumpEvent event) + { + ItemStack stack = event.entityLiving.getEquipmentInSlot(2); + if (stack != null && stack.getItem() instanceof TravelWings) + { + event.entityLiving.motionY += 0.2; + } + } + + @EventHandler + public void slimefall (LivingFallEvent event) + { + ItemStack boots = event.entityLiving.getEquipmentInSlot(1); + if (boots != null && boots.getItem() instanceof IModifyable) + { + NBTTagCompound tag = boots.getTagCompound().getCompoundTag(((IModifyable) boots.getItem()).getBaseTagName()); + int sole = tag.getInteger("Slimy Soles"); + if (sole > 0) + { + event.distance /= (1 + sole); + event.entityLiving.fallDistance /= (1 + sole); + } + } + } } diff --git a/src/main/java/tconstruct/client/TControls.java b/src/main/java/tconstruct/client/TControls.java index e2db4c5f..d04e3748 100644 --- a/src/main/java/tconstruct/client/TControls.java +++ b/src/main/java/tconstruct/client/TControls.java @@ -14,11 +14,12 @@ import tconstruct.client.event.EventCloakRender; import tconstruct.client.tabs.TabRegistry; import tconstruct.util.network.packet.PacketDoubleJump; import tconstruct.util.network.packet.PacketExtendedInventory; +import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.gameevent.TickEvent.Type; public class TControls extends TKeyHandler { - public static final String keybindCategory = "key.tconstruct.category"; + public static final String keybindCategory = "tconstruct.keybindings"; public static KeyBinding armorKey = new KeyBinding("key.tarmor", 24, keybindCategory); public static KeyBinding refreshCapes = new KeyBinding("key.tcapes.reload", 88, keybindCategory); public static KeyBinding toggleGoggles = new KeyBinding("key.tgoggles", 34, keybindCategory); @@ -42,7 +43,11 @@ public class TControls extends TKeyHandler public TControls() { super(new KeyBinding[] { armorKey, refreshCapes, toggleGoggles, beltSwap, zoomKey }, new boolean[] { false, false, false, false, false }, getVanillaKeyBindings(), new boolean[] { false, false }); - // TConstruct.logger.info("Controls registered"); + ClientRegistry.registerKeyBinding(armorKey); + ClientRegistry.registerKeyBinding(refreshCapes); + ClientRegistry.registerKeyBinding(toggleGoggles); + ClientRegistry.registerKeyBinding(beltSwap); + ClientRegistry.registerKeyBinding(zoomKey); } private static KeyBinding[] getVanillaKeyBindings () diff --git a/src/main/java/tconstruct/mechworks/TinkerMechworks.java b/src/main/java/tconstruct/mechworks/TinkerMechworks.java index 9cabbbfd..b22f2eb7 100644 --- a/src/main/java/tconstruct/mechworks/TinkerMechworks.java +++ b/src/main/java/tconstruct/mechworks/TinkerMechworks.java @@ -31,16 +31,13 @@ public class TinkerMechworks { @PulseProxy(clientSide = "tconstruct.mechworks.MechworksProxyClient", serverSide = "tconstruct.mechworks.MechworksProxyCommon") public static MechworksProxyCommon proxy; - public TinkerMechworks() - { - NetworkRegistry.INSTANCE.registerGuiHandler(TConstruct.instance, proxy); - } // Traps public static Block landmine; @Handler public void preInit (FMLPreInitializationEvent event) { + //NetworkRegistry.INSTANCE.registerGuiHandler(TConstruct.instance, proxy); // Traps TinkerMechworks.landmine = new BlockLandmine().setHardness(0.5F).setResistance(0F).setStepSound(Block.soundTypeMetal).setCreativeTab(CreativeTabs.tabRedstone).setBlockName("landmine"); GameRegistry.registerBlock(TinkerMechworks.landmine, ItemBlockLandmine.class, "Redstone.Landmine"); diff --git a/src/main/java/tconstruct/modifiers/armor/ActiveTinkerArmor.java b/src/main/java/tconstruct/modifiers/armor/ActiveTinkerArmor.java index c856b7b2..118b56d0 100644 --- a/src/main/java/tconstruct/modifiers/armor/ActiveTinkerArmor.java +++ b/src/main/java/tconstruct/modifiers/armor/ActiveTinkerArmor.java @@ -38,7 +38,7 @@ public class ActiveTinkerArmor extends ActiveArmorMod } if (type == ArmorPart.Head) { - TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.getPersistentID()); + TPlayerStats stats = TPlayerStats.get(player); if (stats.activeGoggles) { if (tag.getBoolean("Night Vision")) diff --git a/src/main/java/tconstruct/smeltery/TinkerSmeltery.java b/src/main/java/tconstruct/smeltery/TinkerSmeltery.java index 03bba7ae..ba5c1bf0 100644 --- a/src/main/java/tconstruct/smeltery/TinkerSmeltery.java +++ b/src/main/java/tconstruct/smeltery/TinkerSmeltery.java @@ -173,14 +173,10 @@ public class TinkerSmeltery public static Fluid bloodFluid; public static Block blood; - public TinkerSmeltery() - { - MinecraftForge.EVENT_BUS.register(new TinkerSmelteryEvents()); - } - @Handler public void preInit (FMLPreInitializationEvent event) { + MinecraftForge.EVENT_BUS.register(new TinkerSmelteryEvents()); TinkerSmeltery.buckets = new FilledBucket(BlockUtils.getBlockFromItem(TinkerSmeltery.buckets)); GameRegistry.registerItem(TinkerSmeltery.buckets, "buckets"); @@ -463,7 +459,7 @@ public class TinkerSmeltery TinkerSmeltery.moltenObsidian, TinkerSmeltery.moltenSteel, TinkerSmeltery.moltenGlass, TinkerSmeltery.moltenStone, TinkerSmeltery.moltenEmerald, TinkerSmeltery.blood, TinkerSmeltery.moltenNickel, TinkerSmeltery.moltenLead, TinkerSmeltery.moltenSilver, TinkerSmeltery.moltenShiny, TinkerSmeltery.moltenInvar, TinkerSmeltery.moltenElectrum, TinkerSmeltery.moltenEnder, TinkerSmeltery.glueFluidBlock }; - + FluidType.registerFluidType("Water", Blocks.snow, 0, 20, FluidRegistry.getFluid("water"), false); //TODO: Too much reliance on World. FluidType.registerFluidType("Iron", Blocks.iron_block, 0, 600, TinkerSmeltery.moltenIronFluid, true); FluidType.registerFluidType("Gold", Blocks.gold_block, 0, 400, TinkerSmeltery.moltenGoldFluid, false); @@ -686,7 +682,6 @@ public class TinkerSmeltery // Obsidian, different dust amount { FluidType ft = FluidType.getFluidType("Obsidian"); - System.out.println("Obsidian fluid? "+ft); String fluidTypeName = "Obsidian"; Smeltery.addDictionaryMelting("nugget" + fluidTypeName, ft, -100, TConstruct.nuggetLiquidValue); @@ -701,6 +696,9 @@ public class TinkerSmeltery // Ores Smeltery.addDictionaryMelting("ore" + fluidTypeName, ft, 0, ((int) TConstruct.ingotLiquidValue * (int) PHConstruct.ingotsPerOre)); + // Poor ores + Smeltery.addDictionaryMelting("orePoor" + fluidTypeName, ft, 0, (int) (TConstruct.nuggetLiquidValue * PHConstruct.ingotsPerOre * 1.5f)); + // NetherOres support Smeltery.addDictionaryMelting("oreNether" + fluidTypeName, ft, 75, ((int) TConstruct.ingotLiquidValue * (int) PHConstruct.ingotsPerOre * 2)); @@ -873,8 +871,8 @@ public class TinkerSmeltery protected static void addRecipesForSmeltery () { // Alloy Smelting - Smeltery.addAlloyMixing(new FluidStack(TinkerSmeltery.moltenBronzeFluid, (int) (TConstruct.nuggetLiquidValue * PHConstruct.ingotsBronzeAlloy)), new FluidStack(TinkerSmeltery.moltenCopperFluid, - TConstruct.nuggetLiquidValue * 3), new FluidStack(TinkerSmeltery.moltenTinFluid, TConstruct.nuggetLiquidValue)); // Bronze + Smeltery.addAlloyMixing(new FluidStack(TinkerSmeltery.moltenBronzeFluid, (int) (TConstruct.nuggetLiquidValue * PHConstruct.ingotsBronzeAlloy)), new FluidStack( + TinkerSmeltery.moltenCopperFluid, TConstruct.nuggetLiquidValue * 3), new FluidStack(TinkerSmeltery.moltenTinFluid, TConstruct.nuggetLiquidValue)); // Bronze Smeltery.addAlloyMixing(new FluidStack(TinkerSmeltery.moltenAlubrassFluid, (int) (TConstruct.nuggetLiquidValue * PHConstruct.ingotsAluminumBrassAlloy)), new FluidStack( TinkerSmeltery.moltenAluminumFluid, TConstruct.nuggetLiquidValue * 3), new FluidStack(TinkerSmeltery.moltenCopperFluid, TConstruct.nuggetLiquidValue * 1)); // Aluminum Brass Smeltery.addAlloyMixing(new FluidStack(TinkerSmeltery.moltenAlumiteFluid, (int) (TConstruct.nuggetLiquidValue * PHConstruct.ingotsAlumiteAlloy)), new FluidStack( @@ -894,12 +892,12 @@ public class TinkerSmeltery Smeltery.addMelting(stone, new ItemStack(TinkerTools.patternOutputs[sc], 1, 1), 1, (8 * ((IPattern) TinkerTools.woodPattern).getPatternCost(new ItemStack(TinkerTools.woodPattern, 1, sc + 1))) / 2); } - } + } FluidType iron = FluidType.getFluidType("Iron"); FluidType gold = FluidType.getFluidType("Gold"); FluidType steel = FluidType.getFluidType("Steel"); - + // Chunks Smeltery.addMelting(FluidType.getFluidType("Stone"), new ItemStack(TinkerTools.toolShard, 1, 1), 0, 4); Smeltery.addMelting(iron, new ItemStack(TinkerTools.toolShard, 1, 2), 0, TConstruct.chunkLiquidValue); diff --git a/src/main/java/tconstruct/tools/TinkerTools.java b/src/main/java/tconstruct/tools/TinkerTools.java index 91c40b3a..98c33b42 100644 --- a/src/main/java/tconstruct/tools/TinkerTools.java +++ b/src/main/java/tconstruct/tools/TinkerTools.java @@ -196,14 +196,11 @@ public class TinkerTools // recipe stuff public static boolean thaumcraftAvailable; - public TinkerTools() - { - MinecraftForge.EVENT_BUS.register(new TinkerToolEvents()); - } - @Handler public void preInit (FMLPreInitializationEvent event) { + MinecraftForge.EVENT_BUS.register(new TinkerToolEvents()); + //Blocks TinkerTools.toolStationWood = new ToolStationBlock(Material.wood).setBlockName("ToolStation"); TinkerTools.toolForge = new ToolForgeBlock(Material.iron).setBlockName("ToolForge"); diff --git a/src/main/java/tconstruct/util/player/TPlayerHandler.java b/src/main/java/tconstruct/util/player/TPlayerHandler.java index a88d649e..c4ac9179 100644 --- a/src/main/java/tconstruct/util/player/TPlayerHandler.java +++ b/src/main/java/tconstruct/util/player/TPlayerHandler.java @@ -34,7 +34,7 @@ public class TPlayerHandler /* Player */ // public int hunger; - public ConcurrentHashMap playerStats = new ConcurrentHashMap(); + private ConcurrentHashMap playerStats = new ConcurrentHashMap(); @SubscribeEvent public void PlayerLoggedInEvent (PlayerLoggedInEvent event) @@ -297,18 +297,5 @@ public class TPlayerHandler } Random rand = new Random(); - - - public TPlayerStats getPlayerStats (UUID playerID) - { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) - { - return playerStats.get(playerID); - } - else - { - return playerStats.get(playerID); - } - } } diff --git a/src/main/java/tconstruct/world/TinkerWorld.java b/src/main/java/tconstruct/world/TinkerWorld.java index 0aa64b0a..c4ecacd5 100644 --- a/src/main/java/tconstruct/world/TinkerWorld.java +++ b/src/main/java/tconstruct/world/TinkerWorld.java @@ -135,14 +135,11 @@ public class TinkerWorld public static Block punji; public static Block metalBlock; - public TinkerWorld() - { - MinecraftForge.EVENT_BUS.register(new TinkerWorldEvents()); - } - @Handler public void preInit (FMLPreInitializationEvent event) { + MinecraftForge.EVENT_BUS.register(new TinkerWorldEvents()); + //Blocks TinkerWorld.meatBlock = new MeatBlock().setBlockName("tconstruct.meatblock"); TinkerWorld.woolSlab1 = new SlabBase(Material.cloth, Blocks.wool, 0, 8).setBlockName("cloth");