mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-23 11:49:23 +01:00
Added flight limit to wings of the bats
This commit is contained in:
parent
c7912a01d7
commit
2671cad420
4 changed files with 113 additions and 82 deletions
|
@ -20,24 +20,24 @@ import net.minecraft.nbt.NBTTagString;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public final class PlayerData{
|
public final class PlayerData{
|
||||||
|
|
||||||
public static PlayerSave getDataFromPlayer(UUID id){
|
public static PlayerSave getDataFromPlayer(UUID id){
|
||||||
List<PlayerSave> data = WorldData.getWorldUnspecificData().playerSaveData;
|
ConcurrentHashMap<UUID, PlayerSave> data = WorldData.getWorldUnspecificData().playerSaveData;
|
||||||
//Get Data from existing data
|
if(data.containsKey(id)){
|
||||||
for(PlayerSave save : data){
|
PlayerSave save = data.get(id);
|
||||||
if(save.id != null && save.id.equals(id)){
|
if(save != null && save.id != null && save.id.equals(id)){
|
||||||
return save;
|
return save;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add Data if none is existant
|
//Add Data if none is existant
|
||||||
PlayerSave aSave = new PlayerSave(id);
|
PlayerSave save = new PlayerSave(id);
|
||||||
data.add(aSave);
|
data.put(id, save);
|
||||||
return aSave;
|
return save;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerSave getDataFromPlayer(EntityPlayer player){
|
public static PlayerSave getDataFromPlayer(EntityPlayer player){
|
||||||
|
@ -51,6 +51,8 @@ public final class PlayerData{
|
||||||
public boolean displayTesla;
|
public boolean displayTesla;
|
||||||
public boolean bookGottenAlready;
|
public boolean bookGottenAlready;
|
||||||
public boolean didBookTutorial;
|
public boolean didBookTutorial;
|
||||||
|
public boolean hasBatWings;
|
||||||
|
public int batWingsFlyTime;
|
||||||
|
|
||||||
public IBookletPage[] bookmarks = new IBookletPage[12];
|
public IBookletPage[] bookmarks = new IBookletPage[12];
|
||||||
|
|
||||||
|
@ -65,6 +67,8 @@ public final class PlayerData{
|
||||||
this.displayTesla = compound.getBoolean("DisplayTesla");
|
this.displayTesla = compound.getBoolean("DisplayTesla");
|
||||||
this.bookGottenAlready = compound.getBoolean("BookGotten");
|
this.bookGottenAlready = compound.getBoolean("BookGotten");
|
||||||
this.didBookTutorial = compound.getBoolean("DidTutorial");
|
this.didBookTutorial = compound.getBoolean("DidTutorial");
|
||||||
|
this.hasBatWings = compound.getBoolean("HasBatWings");
|
||||||
|
this.batWingsFlyTime = compound.getInteger("BatWingsFlyTime");
|
||||||
|
|
||||||
NBTTagList bookmarks = compound.getTagList("Bookmarks", 8);
|
NBTTagList bookmarks = compound.getTagList("Bookmarks", 8);
|
||||||
for(int i = 0; i < bookmarks.tagCount(); i++){
|
for(int i = 0; i < bookmarks.tagCount(); i++){
|
||||||
|
@ -80,6 +84,8 @@ public final class PlayerData{
|
||||||
compound.setBoolean("DisplayTesla", this.displayTesla);
|
compound.setBoolean("DisplayTesla", this.displayTesla);
|
||||||
compound.setBoolean("BookGotten", this.bookGottenAlready);
|
compound.setBoolean("BookGotten", this.bookGottenAlready);
|
||||||
compound.setBoolean("DidTutorial", this.didBookTutorial);
|
compound.setBoolean("DidTutorial", this.didBookTutorial);
|
||||||
|
compound.setBoolean("HasBatWings", this.hasBatWings);
|
||||||
|
compound.setInteger("BatWingsFlyTime", this.batWingsFlyTime);
|
||||||
|
|
||||||
NBTTagList bookmarks = new NBTTagList();
|
NBTTagList bookmarks = new NBTTagList();
|
||||||
for(IBookletPage bookmark : this.bookmarks){
|
for(IBookletPage bookmark : this.bookmarks){
|
||||||
|
|
|
@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.data.PlayerData.PlayerSave;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||||
import io.netty.util.internal.ConcurrentSet;
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
@ -36,7 +37,7 @@ public class WorldData{
|
||||||
public static final String DATA_TAG = ModUtil.MOD_ID+"data";
|
public static final String DATA_TAG = ModUtil.MOD_ID+"data";
|
||||||
private static final ConcurrentHashMap<Integer, WorldData> WORLD_DATA = new ConcurrentHashMap<Integer, WorldData>();
|
private static final ConcurrentHashMap<Integer, WorldData> WORLD_DATA = new ConcurrentHashMap<Integer, WorldData>();
|
||||||
public final ConcurrentSet<Network> laserRelayNetworks = new ConcurrentSet<Network>();
|
public final ConcurrentSet<Network> laserRelayNetworks = new ConcurrentSet<Network>();
|
||||||
public final ArrayList<PlayerSave> playerSaveData = new ArrayList<PlayerSave>();
|
public final ConcurrentHashMap<UUID, PlayerSave> playerSaveData = new ConcurrentHashMap<UUID, PlayerSave>();
|
||||||
private final ISaveHandler handler;
|
private final ISaveHandler handler;
|
||||||
private final int dimension;
|
private final int dimension;
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ public class WorldData{
|
||||||
|
|
||||||
PlayerSave save = new PlayerSave(id);
|
PlayerSave save = new PlayerSave(id);
|
||||||
save.readFromNBT(data);
|
save.readFromNBT(data);
|
||||||
this.playerSaveData.add(save);
|
this.playerSaveData.put(id, save);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +164,7 @@ public class WorldData{
|
||||||
|
|
||||||
//Player Data
|
//Player Data
|
||||||
NBTTagList playerList = new NBTTagList();
|
NBTTagList playerList = new NBTTagList();
|
||||||
for(PlayerSave save : this.playerSaveData){
|
for(PlayerSave save : this.playerSaveData.values()){
|
||||||
NBTTagCompound player = new NBTTagCompound();
|
NBTTagCompound player = new NBTTagCompound();
|
||||||
player.setUniqueId("UUID", save.id);
|
player.setUniqueId("UUID", save.id);
|
||||||
|
|
||||||
|
|
|
@ -60,13 +60,13 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getDurabilityForDisplay(ItemStack stack){
|
public double getDurabilityForDisplay(ItemStack stack){
|
||||||
double diff = MAX_BLAZE-this.getStoredBlaze(stack);
|
double diff = MAX_BLAZE-getStoredBlaze(stack);
|
||||||
return diff/MAX_BLAZE;
|
return diff/MAX_BLAZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRGBDurabilityForDisplay(ItemStack stack){
|
public int getRGBDurabilityForDisplay(ItemStack stack){
|
||||||
int curr = this.getStoredBlaze(stack);
|
int curr = getStoredBlaze(stack);
|
||||||
return MathHelper.hsvToRGB(Math.max(0.0F, (float)curr/MAX_BLAZE)/3.0F, 1.0F, 1.0F);
|
return MathHelper.hsvToRGB(Math.max(0.0F, (float)curr/MAX_BLAZE)/3.0F, 1.0F, 1.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,34 +11,27 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.items;
|
package de.ellpeck.actuallyadditions.mod.items;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.passive.EntityBat;
|
import net.minecraft.entity.passive.EntityBat;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.EnumRarity;
|
import net.minecraft.item.EnumRarity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class ItemWingsOfTheBats extends ItemBase{
|
public class ItemWingsOfTheBats extends ItemBase{
|
||||||
|
|
||||||
/**
|
private static final int MAX_FLY_TIME = 800;
|
||||||
* A List containing all of the Players that can currently fly
|
|
||||||
* Used so that Flight from other Mods' Items doesn't get broken when
|
|
||||||
* these Wings aren't worn
|
|
||||||
* <p>
|
|
||||||
* Saves Remote Players separately to make de-synced Event Calling
|
|
||||||
* not bug out Capabilities when taking off the Wings
|
|
||||||
* <p>
|
|
||||||
* (Partially excerpted from Botania's Wing System by Vazkii (as I had fiddled around with the system and couldn't make it work) with permission, thanks!)
|
|
||||||
*/
|
|
||||||
public static final ArrayList<String> WINGED_PLAYERS = new ArrayList<String>();
|
|
||||||
|
|
||||||
public ItemWingsOfTheBats(String name){
|
public ItemWingsOfTheBats(String name){
|
||||||
super(name);
|
super(name);
|
||||||
|
@ -47,40 +40,35 @@ public class ItemWingsOfTheBats extends ItemBase{
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Checks if the Player is winged
|
public boolean showDurabilityBar(ItemStack stack){
|
||||||
*
|
return true;
|
||||||
* @param player The Player
|
|
||||||
* @return Winged?
|
|
||||||
*/
|
|
||||||
public static boolean isPlayerWinged(EntityPlayer player){
|
|
||||||
return WINGED_PLAYERS.contains(player.getUniqueID()+(player.worldObj.isRemote ? "-Remote" : ""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Same as above, but Remote Checking is done automatically
|
@SideOnly(Side.CLIENT)
|
||||||
*/
|
public double getDurabilityForDisplay(ItemStack stack){
|
||||||
public static void removeWingsFromPlayer(EntityPlayer player){
|
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().thePlayer);
|
||||||
removeWingsFromPlayer(player, player.worldObj.isRemote);
|
if(data != null){
|
||||||
|
double diff = MAX_FLY_TIME-data.batWingsFlyTime;
|
||||||
|
return 1-(diff/MAX_FLY_TIME);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return super.getDurabilityForDisplay(stack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Removes the Player from the List of Players that have Wings
|
@SideOnly(Side.CLIENT)
|
||||||
*
|
public int getRGBDurabilityForDisplay(ItemStack stack){
|
||||||
* @param player The Player
|
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().thePlayer);
|
||||||
* @param worldRemote If the World the Player is in is remote
|
if(data != null){
|
||||||
*/
|
int curr = data.batWingsFlyTime;
|
||||||
public static void removeWingsFromPlayer(EntityPlayer player, boolean worldRemote){
|
return MathHelper.hsvToRGB(Math.max(0.0F, 1-(float)curr/MAX_FLY_TIME)/3.0F, 1.0F, 1.0F);
|
||||||
WINGED_PLAYERS.remove(player.getUniqueID()+(worldRemote ? "-Remote" : ""));
|
}
|
||||||
|
else{
|
||||||
|
return super.getRGBDurabilityForDisplay(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the Player to the List of Players that have Wings
|
|
||||||
*
|
|
||||||
* @param player The Player
|
|
||||||
*/
|
|
||||||
public static void addWingsToPlayer(EntityPlayer player){
|
|
||||||
WINGED_PLAYERS.add(player.getUniqueID()+(player.worldObj.isRemote ? "-Remote" : ""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,13 +86,6 @@ public class ItemWingsOfTheBats extends ItemBase{
|
||||||
return StackUtil.getNull();
|
return StackUtil.getNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onLogOutEvent(PlayerEvent.PlayerLoggedOutEvent event){
|
|
||||||
//Remove Player from Wings' Fly Permission List
|
|
||||||
ItemWingsOfTheBats.removeWingsFromPlayer(event.player, true);
|
|
||||||
ItemWingsOfTheBats.removeWingsFromPlayer(event.player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onEntityDropEvent(LivingDropsEvent event){
|
public void onEntityDropEvent(LivingDropsEvent event){
|
||||||
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer){
|
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer){
|
||||||
|
@ -121,29 +102,72 @@ public class ItemWingsOfTheBats extends ItemBase{
|
||||||
public void livingUpdateEvent(LivingEvent.LivingUpdateEvent event){
|
public void livingUpdateEvent(LivingEvent.LivingUpdateEvent event){
|
||||||
if(event.getEntityLiving() instanceof EntityPlayer){
|
if(event.getEntityLiving() instanceof EntityPlayer){
|
||||||
EntityPlayer player = (EntityPlayer)event.getEntityLiving();
|
EntityPlayer player = (EntityPlayer)event.getEntityLiving();
|
||||||
boolean wingsEquipped = StackUtil.isValid(ItemWingsOfTheBats.getWingItem(player));
|
|
||||||
|
|
||||||
//If Player isn't (really) winged
|
if(!player.capabilities.isCreativeMode){
|
||||||
if(!ItemWingsOfTheBats.isPlayerWinged(player)){
|
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
|
||||||
|
|
||||||
|
if(!player.worldObj.isRemote){
|
||||||
|
boolean shouldDeduct = false;
|
||||||
|
boolean shouldSend = false;
|
||||||
|
|
||||||
|
boolean wingsEquipped = StackUtil.isValid(ItemWingsOfTheBats.getWingItem(player));
|
||||||
|
if(!data.hasBatWings){
|
||||||
|
if(data.batWingsFlyTime <= 0){
|
||||||
if(wingsEquipped){
|
if(wingsEquipped){
|
||||||
//Make the Player actually winged
|
data.hasBatWings = true;
|
||||||
ItemWingsOfTheBats.addWingsToPlayer(player);
|
shouldSend = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//If Player is (or should be) winged
|
|
||||||
else{
|
else{
|
||||||
if(wingsEquipped){
|
shouldDeduct = true;
|
||||||
//Allow the Player to fly when he has Wings equipped
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(wingsEquipped && data.batWingsFlyTime < MAX_FLY_TIME){
|
||||||
|
player.capabilities.allowFlying = true;
|
||||||
|
|
||||||
|
if(player.capabilities.isFlying){
|
||||||
|
data.batWingsFlyTime++;
|
||||||
|
|
||||||
|
if(player.worldObj.getTotalWorldTime()%10 == 0){
|
||||||
|
shouldSend = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
shouldDeduct = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
data.hasBatWings = false;
|
||||||
|
shouldSend = true;
|
||||||
|
|
||||||
|
player.capabilities.allowFlying = false;
|
||||||
|
player.capabilities.isFlying = false;
|
||||||
|
player.capabilities.disableDamage = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shouldDeduct){
|
||||||
|
if(data.batWingsFlyTime >= 0){
|
||||||
|
data.batWingsFlyTime = Math.max(0, data.batWingsFlyTime-5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(player.worldObj.getTotalWorldTime()%10 == 0){
|
||||||
|
shouldSend = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(shouldSend){
|
||||||
|
PacketHandlerHelper.sendPlayerDataPacket(player, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(data.hasBatWings){
|
||||||
player.capabilities.allowFlying = true;
|
player.capabilities.allowFlying = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//Make the Player not winged
|
|
||||||
ItemWingsOfTheBats.removeWingsFromPlayer(player);
|
|
||||||
//Reset Player's Values
|
|
||||||
if(!player.capabilities.isCreativeMode){
|
|
||||||
player.capabilities.allowFlying = false;
|
player.capabilities.allowFlying = false;
|
||||||
player.capabilities.isFlying = false;
|
player.capabilities.isFlying = false;
|
||||||
//Enables Fall Damage again (Automatically gets disabled for some reason)
|
|
||||||
player.capabilities.disableDamage = false;
|
player.capabilities.disableDamage = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue