mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed player abilities not being synchronised when switching dimensions
This commit is contained in:
parent
5495d75260
commit
08aacefc26
4 changed files with 36 additions and 3 deletions
|
@ -9,6 +9,7 @@ import net.minecraft.util.EnumFacing;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
@ -46,6 +47,17 @@ public class FBS {
|
|||
clone.getPlayer().copyFrom(original.getPlayer());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onDimensionalTravel(EntityTravelToDimensionEvent event) {
|
||||
final ICapabilitiesProxyContainer<?> original = of(event.getEntity());
|
||||
|
||||
if (original == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
original.getRaceContainer().onDimensionalTravel(event.getDimension());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Entity> ICapabilitiesProxyContainer<T> of(T entity) {
|
||||
if (entity.hasCapability(DefaultEntityCapabilitiesProxyContainer.CAPABILITY, EnumFacing.DOWN)) {
|
||||
|
|
|
@ -10,4 +10,5 @@ public interface IRaceContainer<T extends Entity> extends InbtSerialisable, IUpd
|
|||
|
||||
void setPlayerSpecies(Race race);
|
||||
|
||||
void onDimensionalTravel(int destinationDimension);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,11 @@ class ItemCapabilities implements IRaceContainer<EntityItem>, IOwned<EntityItem>
|
|||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDimensionalTravel(int destinationDimension) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityItem getOwner() {
|
||||
return owner;
|
||||
|
|
|
@ -67,6 +67,8 @@ class PlayerCapabilities implements IPlayer {
|
|||
|
||||
private EntityPlayer entity;
|
||||
|
||||
private boolean dirty = false;
|
||||
|
||||
PlayerCapabilities(EntityPlayer player) {
|
||||
setOwner(player);
|
||||
|
||||
|
@ -133,7 +135,9 @@ class PlayerCapabilities implements IPlayer {
|
|||
|
||||
@Override
|
||||
public void sendCapabilities(boolean full) {
|
||||
if (!getOwner().getEntityWorld().isRemote) {
|
||||
dirty = false;
|
||||
|
||||
if (!getWorld().isRemote) {
|
||||
if (full) {
|
||||
Unicopia.channel.broadcast(new MsgPlayerCapabilities(this));
|
||||
} else {
|
||||
|
@ -142,6 +146,13 @@ class PlayerCapabilities implements IPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDimensionalTravel(int destinationDimension) {
|
||||
if (!getWorld().isRemote) {
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbilityReceiver getAbilities() {
|
||||
return powers;
|
||||
|
@ -201,11 +212,15 @@ class PlayerCapabilities implements IPlayer {
|
|||
addEnergy(-1);
|
||||
|
||||
attributes.applyAttributes(entity, getPlayerSpecies());
|
||||
|
||||
if (dirty) {
|
||||
sendCapabilities(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFall(float distance, float damageMultiplier) {
|
||||
if (!entity.getEntityWorld().isRemote) {
|
||||
if (!getWorld().isRemote) {
|
||||
if (getPlayerSpecies().canFly()) {
|
||||
if (entity.fallDistance > 2) {
|
||||
entity.addStat(StatList.FALL_ONE_CM, (int)Math.round(distance * 100));
|
||||
|
@ -298,6 +313,7 @@ class PlayerCapabilities implements IPlayer {
|
|||
|
||||
@Override
|
||||
public void copyFrom(IPlayer oldPlayer) {
|
||||
pages.addAll(oldPlayer.getUnlockedPages());
|
||||
setEffect(oldPlayer.getEffect());
|
||||
setPlayerSpecies(oldPlayer.getPlayerSpecies());
|
||||
}
|
||||
|
@ -337,5 +353,4 @@ class PlayerCapabilities implements IPlayer {
|
|||
public List<Integer> getUnlockedPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue