Finished wing exhaustion mechanic

This commit is contained in:
Ellpeck 2016-11-22 19:35:52 +01:00
parent 2671cad420
commit 6f90197087
7 changed files with 52 additions and 20 deletions

View file

@ -27,6 +27,7 @@ import de.ellpeck.actuallyadditions.mod.crafting.*;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.gen.OreGen;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.ItemWingsOfTheBats;
import de.ellpeck.actuallyadditions.mod.items.lens.LensDisenchanting;
import de.ellpeck.actuallyadditions.mod.items.lens.LensMining;
import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler;
@ -209,7 +210,7 @@ public final class InitBooklet{
//No RF Using Items
new BookletChapter("bags", ActuallyAdditionsAPI.entryItemsNonRF, new ItemStack(InitItems.itemBag), new PageTextOnly(1), new PageCrafting(2, ItemCrafting.recipeBag), new PageCrafting(3, ItemCrafting.recipeVoidBag).setNoText()).setImportant();
new BookletChapter("wings", ActuallyAdditionsAPI.entryItemsNonRF, new ItemStack(InitItems.itemWingsOfTheBats), new PageTextOnly(1).addItemToPage(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.BAT_WING.ordinal())), new PageCrafting(2, ItemCrafting.recipeWings).setNoText()).setSpecial();
new BookletChapter("wings", ActuallyAdditionsAPI.entryItemsNonRF, new ItemStack(InitItems.itemWingsOfTheBats), new PageTextOnly(1).addItemToPage(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.BAT_WING.ordinal())).addTextReplacement("<secs>", ItemWingsOfTheBats.MAX_FLY_TIME/20), new PageCrafting(2, ItemCrafting.recipeWings).setNoText()).setSpecial();
new BookletChapter("foods", ActuallyAdditionsAPI.entryItemsNonRF, new ItemStack(InitItems.itemFoods, 1, TheFoods.HAMBURGER.ordinal()), new PageCrafting(1, FoodCrafting.recipeBacon).setNoText(), new PageFurnace(2, new ItemStack(InitItems.itemFoods, 1, TheFoods.RICE_BREAD.ordinal())).setNoText(), new PageCrafting(3, FoodCrafting.recipeHamburger).setNoText(), new PageCrafting(4, FoodCrafting.recipeBigCookie).setNoText(), new PageCrafting(5, FoodCrafting.recipeSubSandwich).setNoText(), new PageCrafting(6, FoodCrafting.recipeFrenchFry).setNoText(), new PageCrafting(7, FoodCrafting.recipeFrenchFries).setNoText(), new PageCrafting(8, FoodCrafting.recipeFishNChips).setNoText(), new PageCrafting(9, FoodCrafting.recipeCheese).setNoText(), new PageCrafting(10, FoodCrafting.recipePumpkinStew).setNoText(), new PageCrafting(11, FoodCrafting.recipeCarrotJuice).setNoText(), new PageCrafting(12, FoodCrafting.recipeSpaghetti).setNoText(), new PageCrafting(13, FoodCrafting.recipeNoodle).setNoText(), new PageCrafting(14, FoodCrafting.recipeChocolate).setNoText(), new PageCrafting(15, FoodCrafting.recipeChocolateCake).setNoText(), new PageCrafting(16, FoodCrafting.recipeToast).setNoText(), new PageFurnace(17, new ItemStack(InitItems.itemFoods, 1, TheFoods.BAGUETTE.ordinal())).setNoText(), new PageCrafting(18, FoodCrafting.recipeChocolateToast).setNoText(), new PageCrafting(1, FoodCrafting.recipePizza).setNoText());
new BookletChapter("leafBlower", ActuallyAdditionsAPI.entryItemsNonRF, new ItemStack(InitItems.itemLeafBlowerAdvanced), new PageTextOnly(1), new PageCrafting(2, ItemCrafting.recipeLeafBlower).setNoText(), new PageCrafting(3, ItemCrafting.recipeLeafBlowerAdvanced).setNoText()).setImportant();
new BookletChapter("playerProbe", ActuallyAdditionsAPI.entryItemsNonRF, new ItemStack(InitItems.itemPlayerProbe), new PageTextOnly(1), new PageCrafting(2, ItemCrafting.recipePlayerProbe).setNoText()).setSpecial();

View file

@ -52,6 +52,7 @@ public final class PlayerData{
public boolean bookGottenAlready;
public boolean didBookTutorial;
public boolean hasBatWings;
public boolean shouldDisableBatWings;
public int batWingsFlyTime;
public IBookletPage[] bookmarks = new IBookletPage[12];
@ -63,10 +64,11 @@ public final class PlayerData{
this.id = id;
}
public void readFromNBT(NBTTagCompound compound){
public void readFromNBT(NBTTagCompound compound, boolean savingToFile){
this.displayTesla = compound.getBoolean("DisplayTesla");
this.bookGottenAlready = compound.getBoolean("BookGotten");
this.didBookTutorial = compound.getBoolean("DidTutorial");
this.hasBatWings = compound.getBoolean("HasBatWings");
this.batWingsFlyTime = compound.getInteger("BatWingsFlyTime");
@ -78,12 +80,17 @@ public final class PlayerData{
this.bookmarks[i] = page;
}
}
if(!savingToFile){
this.shouldDisableBatWings = compound.getBoolean("ShouldDisableWings");
}
}
public void writeToNBT(NBTTagCompound compound){
public void writeToNBT(NBTTagCompound compound, boolean savingToFile){
compound.setBoolean("DisplayTesla", this.displayTesla);
compound.setBoolean("BookGotten", this.bookGottenAlready);
compound.setBoolean("DidTutorial", this.didBookTutorial);
compound.setBoolean("HasBatWings", this.hasBatWings);
compound.setInteger("BatWingsFlyTime", this.batWingsFlyTime);
@ -92,6 +99,10 @@ public final class PlayerData{
bookmarks.appendTag(new NBTTagString(bookmark == null ? "" : bookmark.getIdentifier()));
}
compound.setTag("Bookmarks", bookmarks);
if(!savingToFile){
compound.setBoolean("ShouldDisableWings", this.shouldDisableBatWings);
}
}
}

View file

@ -149,7 +149,7 @@ public class WorldData{
NBTTagCompound data = player.getCompoundTag("Data");
PlayerSave save = new PlayerSave(id);
save.readFromNBT(data);
save.readFromNBT(data, true);
this.playerSaveData.put(id, save);
}
}
@ -169,7 +169,7 @@ public class WorldData{
player.setUniqueId("UUID", save.id);
NBTTagCompound data = new NBTTagCompound();
save.writeToNBT(data);
save.writeToNBT(data, true);
player.setTag("Data", data);
playerList.appendTag(player);

View file

@ -16,11 +16,15 @@ import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.passive.EntityBat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
@ -31,7 +35,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemWingsOfTheBats extends ItemBase{
private static final int MAX_FLY_TIME = 800;
public static final int MAX_FLY_TIME = 800;
public ItemWingsOfTheBats(String name){
super(name);
@ -107,7 +111,7 @@ public class ItemWingsOfTheBats extends ItemBase{
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
if(!player.worldObj.isRemote){
boolean shouldDeduct = false;
boolean tryDeduct = false;
boolean shouldSend = false;
boolean wingsEquipped = StackUtil.isValid(ItemWingsOfTheBats.getWingItem(player));
@ -119,7 +123,7 @@ public class ItemWingsOfTheBats extends ItemBase{
}
}
else{
shouldDeduct = true;
tryDeduct = true;
}
}
else{
@ -133,12 +137,12 @@ public class ItemWingsOfTheBats extends ItemBase{
shouldSend = true;
}
}
else{
shouldDeduct = true;
}
tryDeduct = true;
}
else{
data.hasBatWings = false;
data.shouldDisableBatWings = true;
shouldSend = true;
player.capabilities.allowFlying = false;
@ -147,25 +151,41 @@ public class ItemWingsOfTheBats extends ItemBase{
}
}
if(shouldDeduct){
if(data.batWingsFlyTime >= 0){
data.batWingsFlyTime = Math.max(0, data.batWingsFlyTime-5);
if(tryDeduct && data.batWingsFlyTime > 0){
int deductTime = 0;
if(!player.capabilities.isFlying){
deductTime = 2;
}
else{
BlockPos pos = new BlockPos(player.posX, player.posY+player.height, player.posZ);
IBlockState state = player.worldObj.getBlockState(pos);
if(state != null && state.isSideSolid(player.worldObj, pos, EnumFacing.DOWN)){
deductTime = 10;
}
}
if(deductTime > 0){
data.batWingsFlyTime = Math.max(0, data.batWingsFlyTime-deductTime);
if(player.worldObj.getTotalWorldTime()%10 == 0){
shouldSend = true;
}
}
}
if(shouldSend){
PacketHandlerHelper.sendPlayerDataPacket(player, false, true);
data.shouldDisableBatWings = false; //was set only temporarily to send it
}
}
else{
if(data.hasBatWings){
player.capabilities.allowFlying = true;
}
else{
else if(data.shouldDisableBatWings){ //so that other modded flying won't be disabled
data.shouldDisableBatWings = false;
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false;
player.capabilities.disableDamage = false;

View file

@ -115,7 +115,7 @@ public final class PacketHandler{
public void handleData(NBTTagCompound compound){
NBTTagCompound data = compound.getCompoundTag("Data");
UUID id = compound.getUniqueId("UUID");
PlayerData.getDataFromPlayer(id).readFromNBT(data);
PlayerData.getDataFromPlayer(id).readFromNBT(data, false);
if(compound.getBoolean("Log")){
ModUtil.LOGGER.info("Receiving (new or changed) Player Data for player with UUID "+id+".");
}

View file

@ -38,7 +38,7 @@ public final class PacketHandlerHelper{
compound.setBoolean("Log", log);
NBTTagCompound data = new NBTTagCompound();
PlayerData.getDataFromPlayer(player).writeToNBT(data);
PlayerData.getDataFromPlayer(player).writeToNBT(data, false);
compound.setTag("Data", data);
if(toClient){

View file

@ -887,7 +887,7 @@ booklet.actuallyadditions.chapter.canola.text.2=For starters, you can use a <ite
booklet.actuallyadditions.chapter.canola.text.5=If you break the <item>Oil Generator<r>, it will keep the liquid inside. <n>If you want to empty it out, just <imp>place it in the crafting grid<r> and all of the fluid will be drained.
booklet.actuallyadditions.chapter.wings.name=Wings Of The Bats
booklet.actuallyadditions.chapter.wings.text.1=Sometimes, bats will drop <item>Wings<r>. These wings can't really be used to fly, but that's just because they're not powerful enough. <n>To make them more powerful, you can craft <item>Wings Of The Bats<r>. When you have these in your inventory, they will allow you to <imp>fly like in creative mode<r>.
booklet.actuallyadditions.chapter.wings.text.1=Sometimes, bats will drop <item>Wings<r>. These wings can be used to make <item>Wings Of The Bats<r>, which allow you to <imp>fly<r> in a <imp>creative way<r>. <n>However, after about <secs> seconds, your weight won't be <imp>supported anymore<r> and you will <imp>drop to the ground<r>. <n>To remove exhaustion from your wings, either <imp>stand on the ground<r> to remove exhaustion <imp>slowly<r>, or hang on to the ceiling by <imp>flying up below a solid block<r> like a bat while the wings aren't fully exhausted to remove exhaustion <imp>fast<r>.
booklet.actuallyadditions.chapter.foods.name=Foodstuffs