mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-20 03:44:23 +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.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||||
|
import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
@ -46,6 +47,17 @@ public class FBS {
|
||||||
clone.getPlayer().copyFrom(original.getPlayer());
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Entity> ICapabilitiesProxyContainer<T> of(T entity) {
|
public static <T extends Entity> ICapabilitiesProxyContainer<T> of(T entity) {
|
||||||
if (entity.hasCapability(DefaultEntityCapabilitiesProxyContainer.CAPABILITY, EnumFacing.DOWN)) {
|
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 setPlayerSpecies(Race race);
|
||||||
|
|
||||||
|
void onDimensionalTravel(int destinationDimension);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,11 @@ class ItemCapabilities implements IRaceContainer<EntityItem>, IOwned<EntityItem>
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDimensionalTravel(int destinationDimension) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityItem getOwner() {
|
public EntityItem getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
|
|
|
@ -67,6 +67,8 @@ class PlayerCapabilities implements IPlayer {
|
||||||
|
|
||||||
private EntityPlayer entity;
|
private EntityPlayer entity;
|
||||||
|
|
||||||
|
private boolean dirty = false;
|
||||||
|
|
||||||
PlayerCapabilities(EntityPlayer player) {
|
PlayerCapabilities(EntityPlayer player) {
|
||||||
setOwner(player);
|
setOwner(player);
|
||||||
|
|
||||||
|
@ -133,7 +135,9 @@ class PlayerCapabilities implements IPlayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendCapabilities(boolean full) {
|
public void sendCapabilities(boolean full) {
|
||||||
if (!getOwner().getEntityWorld().isRemote) {
|
dirty = false;
|
||||||
|
|
||||||
|
if (!getWorld().isRemote) {
|
||||||
if (full) {
|
if (full) {
|
||||||
Unicopia.channel.broadcast(new MsgPlayerCapabilities(this));
|
Unicopia.channel.broadcast(new MsgPlayerCapabilities(this));
|
||||||
} else {
|
} else {
|
||||||
|
@ -142,6 +146,13 @@ class PlayerCapabilities implements IPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDimensionalTravel(int destinationDimension) {
|
||||||
|
if (!getWorld().isRemote) {
|
||||||
|
dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IAbilityReceiver getAbilities() {
|
public IAbilityReceiver getAbilities() {
|
||||||
return powers;
|
return powers;
|
||||||
|
@ -201,11 +212,15 @@ class PlayerCapabilities implements IPlayer {
|
||||||
addEnergy(-1);
|
addEnergy(-1);
|
||||||
|
|
||||||
attributes.applyAttributes(entity, getPlayerSpecies());
|
attributes.applyAttributes(entity, getPlayerSpecies());
|
||||||
|
|
||||||
|
if (dirty) {
|
||||||
|
sendCapabilities(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFall(float distance, float damageMultiplier) {
|
public void onFall(float distance, float damageMultiplier) {
|
||||||
if (!entity.getEntityWorld().isRemote) {
|
if (!getWorld().isRemote) {
|
||||||
if (getPlayerSpecies().canFly()) {
|
if (getPlayerSpecies().canFly()) {
|
||||||
if (entity.fallDistance > 2) {
|
if (entity.fallDistance > 2) {
|
||||||
entity.addStat(StatList.FALL_ONE_CM, (int)Math.round(distance * 100));
|
entity.addStat(StatList.FALL_ONE_CM, (int)Math.round(distance * 100));
|
||||||
|
@ -298,6 +313,7 @@ class PlayerCapabilities implements IPlayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void copyFrom(IPlayer oldPlayer) {
|
public void copyFrom(IPlayer oldPlayer) {
|
||||||
|
pages.addAll(oldPlayer.getUnlockedPages());
|
||||||
setEffect(oldPlayer.getEffect());
|
setEffect(oldPlayer.getEffect());
|
||||||
setPlayerSpecies(oldPlayer.getPlayerSpecies());
|
setPlayerSpecies(oldPlayer.getPlayerSpecies());
|
||||||
}
|
}
|
||||||
|
@ -337,5 +353,4 @@ class PlayerCapabilities implements IPlayer {
|
||||||
public List<Integer> getUnlockedPages() {
|
public List<Integer> getUnlockedPages() {
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue