Added glider module and fixed another crash

This commit is contained in:
Claire 2013-01-09 12:18:40 -07:00
parent 76dd94c03d
commit 10a72b97e3
7 changed files with 105 additions and 43 deletions

View file

@ -1,6 +1,11 @@
package net.machinemuse.general.gui.frame;
import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.machinemuse.general.MuseStringUtils;
import net.machinemuse.general.geometry.Colour;
@ -29,7 +34,7 @@ public class ModuleTweakFrame extends ScrollableFrame {
protected Map<String, Double> propertyStrings;
protected ClickableSlider selectedSlider;
protected EntityClientPlayerMP player;
public ModuleTweakFrame(
EntityClientPlayerMP player,
Point2D topleft, Point2D bottomright,
@ -40,7 +45,7 @@ public class ModuleTweakFrame extends ScrollableFrame {
this.moduleTarget = moduleTarget;
this.player = player;
}
@Override public void update(double mousex, double mousey) {
mousex /= SCALERATIO;
mousey /= SCALERATIO;
@ -53,13 +58,16 @@ public class ModuleTweakFrame extends ScrollableFrame {
sliders = null;
propertyStrings = null;
}
} else {
sliders = null;
propertyStrings = null;
}
if (selectedSlider != null) {
selectedSlider.moveSlider(mousex, mousey);
}
}
@Override public void draw() {
if (sliders != null) {
MuseRenderer.drawFrameRect(topleft.times(SCALERATIO), bottomright.times(SCALERATIO), borderColour, insideColour, 0, 2);
@ -74,17 +82,18 @@ public class ModuleTweakFrame extends ScrollableFrame {
nexty += 8;
String[] str = { property.getKey() + ":", MuseStringUtils.formatNumberShort(property.getValue()) };
MuseRenderer.drawStringsJustified(Arrays.asList(str), topleft.x() + 4, bottomright.x() - 4, nexty);
}
GL11.glPopMatrix();
}
}
private void loadTweaks(ItemStack stack, GenericModule module) {
NBTTagCompound itemTag = ItemUtils.getMuseItemTag(stack);
NBTTagCompound moduleTag = itemTag.getCompoundTag(module.getName());
propertyStrings = new HashMap();
Set<IModuleProperty> propertyCalcs = module.getPropertyComputers();
for (IModuleProperty property : propertyCalcs) {
double currValue = 0;
@ -94,7 +103,7 @@ public class ModuleTweakFrame extends ScrollableFrame {
currValue += property.computeProperty(moduleTag);
propertyStrings.put(property.getName(), currValue);
}
Set<String> tweaks = module.getTweaks();
sliders = new LinkedList();
int y = 0;
@ -107,6 +116,7 @@ public class ModuleTweakFrame extends ScrollableFrame {
sliders.add(slider);
}
}
@Override public void onMouseDown(double x, double y, int button) {
x /= SCALERATIO;
y /= SCALERATIO;
@ -120,7 +130,7 @@ public class ModuleTweakFrame extends ScrollableFrame {
}
}
}
@Override public void onMouseUp(double x, double y, int button) {
if (selectedSlider != null && itemTarget.getSelectedItem() != null && moduleTarget.getSelectedModule() != null) {
ClickableItem item = itemTarget.getSelectedItem();

View file

@ -290,6 +290,11 @@ public class Config extends Configuration {
ModularCommon.SHOCK_ABSORB_ENERGY_CONSUMPTION, "J", 0, 10,
ModularCommon.SHOCK_ABSORB_MULTIPLIER, "x", 0, 1);
addModule(module);
module = new GenericModule(ModularCommon.MODULE_GLIDER, TORSOONLY, MuseIcon.GLIDER, ModularCommon.CATEGORY_MOVEMENT)
.setDescription("Tack on some wings so you can slow your fall and maybe fly a bit if you jump from a decent height.")
.addInstallCost(new ItemStack(BasicComponents.itemSteelPlate, 2));
addModule(module);
}
/**

View file

@ -5,7 +5,13 @@ import java.util.List;
import net.machinemuse.powersuits.block.BlockTinkerTable;
import net.machinemuse.powersuits.event.EventHandler;
import net.machinemuse.powersuits.item.*;
import net.machinemuse.powersuits.event.FallManager;
import net.machinemuse.powersuits.item.ItemPowerArmor;
import net.machinemuse.powersuits.item.ItemPowerArmorFeet;
import net.machinemuse.powersuits.item.ItemPowerArmorHead;
import net.machinemuse.powersuits.item.ItemPowerArmorLegs;
import net.machinemuse.powersuits.item.ItemPowerArmorTorso;
import net.machinemuse.powersuits.item.ItemPowerTool;
import net.machinemuse.powersuits.network.MusePacketHandler;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
@ -13,11 +19,12 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import basiccomponents.common.BasicComponents;
import cpw.mods.fml.common.*;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@ -82,6 +89,7 @@ public class PowersuitsMod {
Config.init(new Configuration(
event.getSuggestedConfigurationFile()));
MinecraftForge.EVENT_BUS.register(new EventHandler());
MinecraftForge.EVENT_BUS.register(new FallManager());
}
public static Config config;

View file

@ -10,7 +10,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
public class EventHandler {
@ -18,11 +17,11 @@ public class EventHandler {
EntityPlayer player = event.entityPlayer;
Block block = event.block;
ItemStack stack = player.inventory.getCurrentItem();
if (stack.getItem() instanceof ItemPowerTool && ItemPowerTool.canHarvestBlock(stack, block, 0)) {
if (stack != null && stack.getItem() instanceof ItemPowerTool && ItemPowerTool.canHarvestBlock(stack, block, 0)) {
event.success = true;
}
}
@ForgeSubscribe public void handleLivingJumpEvent(LivingJumpEvent event) {
if (event.entityLiving instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.entityLiving;
@ -36,27 +35,7 @@ public class EventHandler {
player.motionY *= jumpAssist;
}
}
}
}
@ForgeSubscribe public void handleFallEvent(LivingFallEvent event) {
if (event.entityLiving instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.entityLiving;
ItemStack boots = player.getCurrentArmor(0);
if (boots != null) {
if (ItemUtils.itemHasModule(boots, ModularCommon.MODULE_SHOCK_ABSORBER)) {
double distanceAbsorb = event.distance * Config.computeModularProperty(boots, ModularCommon.SHOCK_ABSORB_MULTIPLIER);
double drain = distanceAbsorb * distanceAbsorb * 0.05
* Config.computeModularProperty(boots, ModularCommon.SHOCK_ABSORB_ENERGY_CONSUMPTION);
double avail = ItemUtils.getPlayerEnergy(player);
if (drain < avail) {
ItemUtils.drainPlayerEnergy(player, drain);
event.distance -= distanceAbsorb;
}
}
}
}
}
}

View file

@ -0,0 +1,43 @@
package net.machinemuse.powersuits.event;
import net.machinemuse.powersuits.common.Config;
import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.item.ModularCommon;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingFallEvent;
public class FallManager {
@ForgeSubscribe public void handleFallEvent(LivingFallEvent event) {
event.distance = (float) computeFallHeightFromVelocity(event.entity.motionY);
if (event.entityLiving instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.entityLiving;
ItemStack boots = player.getCurrentArmor(0);
if (boots != null) {
if (ItemUtils.itemHasModule(boots, ModularCommon.MODULE_SHOCK_ABSORBER)) {
double distanceAbsorb = event.distance * Config.computeModularProperty(boots, ModularCommon.SHOCK_ABSORB_MULTIPLIER);
double drain = distanceAbsorb * distanceAbsorb * 0.05
* Config.computeModularProperty(boots, ModularCommon.SHOCK_ABSORB_ENERGY_CONSUMPTION);
double avail = ItemUtils.getPlayerEnergy(player);
if (drain < avail) {
ItemUtils.drainPlayerEnergy(player, drain);
event.distance -= distanceAbsorb;
}
}
}
}
}
/**
* Gravity, in meters per tick per tick.
*/
public static double DEFAULT_GRAVITY = -0.0784000015258789;
public static double computeFallHeightFromVelocity(double velocity) {
double ticks = velocity / DEFAULT_GRAVITY;
double distance = 0.5 * velocity * ticks * ticks;
return distance;
}
}

View file

@ -49,6 +49,7 @@ public abstract class ModularCommon {
public static final String MODULE_JUMP_ASSIST = "Jump Assist";
public static final String MODULE_SHOCK_ABSORBER = "Shock Absorber";
public static final String MODULE_TRANSPARENT_ARMOR = "Transparent Armor";
public static final String MODULE_GLIDER = "Glider";
/**
* Categories for modules

View file

@ -11,6 +11,7 @@ import net.machinemuse.powersuits.common.MuseLogger;
import net.machinemuse.powersuits.item.IModularItem;
import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.item.ModularCommon;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@ -36,7 +37,7 @@ public class PlayerTickHandler implements ITickHandler {
double totalWeight = 0;
double weightCapacity = 25000;
Side side = FMLCommonHandler.instance().getEffectiveSide();
for (ItemStack stack : ItemUtils.getModularItemsInInventory(player)) {
totalWeight += ModularCommon.getTotalWeight(stack);
}
@ -57,18 +58,33 @@ public class PlayerTickHandler implements ITickHandler {
}
}
}
if (player instanceof EntityClientPlayerMP) {
EntityClientPlayerMP clientplayer = (EntityClientPlayerMP) player;
boolean jumpkey = clientplayer.movementInput.jump;
ItemStack torso = player.getCurrentArmor(2);
if (jumpkey && torso != null) {
if (ItemUtils.itemHasModule(torso, ModularCommon.MODULE_GLIDER)) {
if (player.motionY < -0.1) {
player.motionY = Math.min(player.motionY + 0.1, -0.1);
player.jumpMovementFactor += 0.3;
}
}
}
}
if (totalWeight > weightCapacity) {
player.motionX *= weightCapacity / totalWeight;
player.motionZ *= weightCapacity / totalWeight;
}
}
@Override public void tickEnd(EnumSet<TickType> type, Object... tickData) {
EntityPlayer player = toPlayer(tickData[0]);
List<ItemStack> stacks = ItemUtils
.getModularItemsInInventory(player.inventory);
}
public static World toWorld(Object data) {
World world = null;
try {
@ -80,7 +96,7 @@ public class PlayerTickHandler implements ITickHandler {
}
return world;
}
public static EntityPlayer toPlayer(Object data) {
EntityPlayer player = null;
try {
@ -93,19 +109,19 @@ public class PlayerTickHandler implements ITickHandler {
}
return player;
}
/**
* Type of tick handled by this handler
*/
@Override public EnumSet<TickType> ticks() {
return EnumSet.of(TickType.PLAYER);
}
/**
* Profiling label for this handler
*/
@Override public String getLabel() {
return "MMMPS: Player Tick";
}
}