Added Advanced Wings that let you fly much faster

This commit is contained in:
Ellpeck 2015-07-17 12:08:13 +02:00
parent 8636a92df0
commit e3dd81e11f
3 changed files with 44 additions and 17 deletions

View file

@ -1,13 +1,16 @@
package ellpeck.actuallyadditions.event;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.ReflectionHelper;
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.items.ItemWingsOfTheBats;
import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerCapabilities;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
@ -33,7 +36,8 @@ public class EntityLivingEvent{
//Wings allowing Flight
if(event.entityLiving instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)event.entityLiving;
boolean wingsEquipped = ItemWingsOfTheBats.hasWingItem(player);
ItemStack wings = ItemWingsOfTheBats.getWingItem(player);
boolean wingsEquipped = wings != null;
//If Player isn't (really) winged
if(!ItemWingsOfTheBats.isPlayerWinged(player)){
@ -45,11 +49,17 @@ public class EntityLivingEvent{
//If Player is (or should be) winged
else{
if(wingsEquipped){
//Allow the Player to fly when he has Wings equipped every tick
//It appears to be reset somewhere if you don't update it every tick
//but I haven't found the place where it gets reset which is slightly odd
//Maybe I just haven't searched enough or I am really stupid :D
//Allow the Player to fly when he has Wings equipped
player.capabilities.allowFlying = true;
if(((ItemWingsOfTheBats)wings.getItem()).isHastily){
//Speed Upgrade with hastily Wings
this.setFlySpeed(player, ItemWingsOfTheBats.FLY_SPEED);
}
else{
//When switching from Hastily to not Hastily immediately, still remove the Speed!
this.setFlySpeed(player, ItemWingsOfTheBats.STANDARD_FLY_SPEED);
}
}
else{
//Make the Player not winged
@ -61,9 +71,19 @@ public class EntityLivingEvent{
//Enables Fall Damage again (Automatically gets disabled for some reason)
player.capabilities.disableDamage = false;
}
//Remove the Speed Effect
this.setFlySpeed(player, ItemWingsOfTheBats.STANDARD_FLY_SPEED);
}
}
}
}
private void setFlySpeed(EntityPlayer player, float speed){
try{
ReflectionHelper.setPrivateValue(PlayerCapabilities.class, player.capabilities, speed, 5);
}
catch(Exception e){
ModUtil.LOGGER.fatal("Something went wrong here!", e);
}
}
}

View file

@ -97,6 +97,7 @@ public class InitItems{
public static Item itemTeleStaff;
public static Item itemWingsOfTheBats;
public static Item itemWingsOfTheBatsHastily;
public static void init(){
ModUtil.LOGGER.info("Initializing Items...");
@ -116,8 +117,10 @@ public class InitItems{
itemTeleStaff = new ItemTeleStaff();
ItemUtil.register(itemTeleStaff);
itemWingsOfTheBats = new ItemWingsOfTheBats();
itemWingsOfTheBats = new ItemWingsOfTheBats(false);
ItemUtil.register(itemWingsOfTheBats);
itemWingsOfTheBatsHastily = new ItemWingsOfTheBats(true);
ItemUtil.register(itemWingsOfTheBatsHastily);
itemDrill = new ItemDrill();
ItemUtil.register(itemDrill);

View file

@ -22,15 +22,19 @@ public class ItemWingsOfTheBats extends Item implements INameableItem{
* Used so that Flight from other Mods' Items doesn't get broken when
* these Wings aren't worn
*
* Saves Remote Players specially to make Damage Display not bug
* when taking off the Wings
* (Because Client and Server LivingUpdateEvent get called kind of irregularly
* and not both at the same time (That's at least what I worked out when testing :D))
* Saves Remote Players separately to make de-synced Event Calling
* not bug out Capabilities when taking off the Wings
*/
public static ArrayList<String> wingedPlayers = new ArrayList<>();
public ItemWingsOfTheBats(){
public static final float FLY_SPEED = 0.125F;
public static final float STANDARD_FLY_SPEED = 0.05F;
public boolean isHastily;
public ItemWingsOfTheBats(boolean isHastily){
this.setMaxStackSize(1);
this.isHastily = isHastily;
}
/**
@ -68,7 +72,7 @@ public class ItemWingsOfTheBats extends Item implements INameableItem{
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.epic;
return this.isHastily ? EnumRarity.epic : EnumRarity.rare;
}
@Override
@ -91,21 +95,21 @@ public class ItemWingsOfTheBats extends Item implements INameableItem{
@Override
public String getName(){
return "itemWingsOfTheBats";
return this.isHastily ? "itemWingOfTheBatsHastily" : "itemWingsOfTheBats";
}
/**
* Checks if the Player has Wings in its Inventory
*
* @param player The Player
* @return If the Player has Wings
* @return The Wings
*/
public static boolean hasWingItem(EntityPlayer player){
public static ItemStack getWingItem(EntityPlayer player){
for(int i = 0; i < player.inventory.getSizeInventory(); i++){
if(player.inventory.getStackInSlot(i) != null && player.inventory.getStackInSlot(i).getItem() instanceof ItemWingsOfTheBats){
return true;
return player.inventory.getStackInSlot(i);
}
}
return false;
return null;
}
}