Fixed changelings being able to disguise themselves as various weather effects

This commit is contained in:
Sollace 2019-02-12 16:33:51 +02:00
parent c02c72cc60
commit 38daa43291
5 changed files with 44 additions and 6 deletions

View file

@ -58,7 +58,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.DifficultyInstance; import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World; import net.minecraft.world.World;
public class EntityCloud extends EntityFlying implements IAnimals { public class EntityCloud extends EntityFlying implements IAnimals, IInAnimate {
private static final DataParameter<Integer> RAINTIMER = EntityDataManager.createKey(EntityCloud.class, DataSerializers.VARINT); private static final DataParameter<Integer> RAINTIMER = EntityDataManager.createKey(EntityCloud.class, DataSerializers.VARINT);
private static final DataParameter<Boolean> THUNDERING = EntityDataManager.createKey(EntityCloud.class, DataSerializers.BOOLEAN); private static final DataParameter<Boolean> THUNDERING = EntityDataManager.createKey(EntityCloud.class, DataSerializers.BOOLEAN);
@ -145,6 +145,11 @@ public class EntityCloud extends EntityFlying implements IAnimals {
return 6; return 6;
} }
@Override
public boolean canInteract(Race race) {
return race.canInteractWithClouds();
}
@Override @Override
public void onStruckByLightning(EntityLightningBolt lightningBolt) { public void onStruckByLightning(EntityLightningBolt lightningBolt) {

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia.entity; package com.minelittlepony.unicopia.entity;
import com.minelittlepony.unicopia.Race;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.effect.EntityWeatherEffect; import net.minecraft.entity.effect.EntityWeatherEffect;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -9,7 +11,7 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.Biome.SpawnListEntry; import net.minecraft.world.biome.Biome.SpawnListEntry;
public class EntityRainbow extends EntityWeatherEffect { public class EntityRainbow extends EntityWeatherEffect implements IInAnimate {
public static final SpawnListEntry SPAWN_ENTRY = new SpawnListEntry(EntityRainbow.Spawner.class, 1, 1, 1); public static final SpawnListEntry SPAWN_ENTRY = new SpawnListEntry(EntityRainbow.Spawner.class, 1, 1, 1);
@ -45,6 +47,11 @@ public class EntityRainbow extends EntityWeatherEffect {
return pass == 1; return pass == 1;
} }
@Override
public boolean canInteract(Race race) {
return false;
}
@Override @Override
public void setPosition(double x, double y, double z) { public void setPosition(double x, double y, double z) {
posX = x; posX = x;

View file

@ -5,6 +5,7 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.Predicates;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.UItems;
import com.minelittlepony.unicopia.item.ICastable; import com.minelittlepony.unicopia.item.ICastable;
import com.minelittlepony.unicopia.network.EffectSync; import com.minelittlepony.unicopia.network.EffectSync;
@ -34,7 +35,7 @@ import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
public class EntitySpell extends EntityLiving implements IMagicals, ICaster<EntityLivingBase> { public class EntitySpell extends EntityLiving implements IMagicals, ICaster<EntityLivingBase>, IInAnimate {
private EntityLivingBase owner = null; private EntityLivingBase owner = null;
@ -89,6 +90,11 @@ public class EntitySpell extends EntityLiving implements IMagicals, ICaster<Enti
} }
} }
@Override
public boolean canInteract(Race race) {
return race.canCast();
}
@Nullable @Nullable
@Override @Override
public IMagicEffect getEffect(boolean update) { public IMagicEffect getEffect(boolean update) {

View file

@ -0,0 +1,14 @@
package com.minelittlepony.unicopia.entity;
import com.minelittlepony.unicopia.Race;
/**
* This interface is for any entities that are categorised as inanimated,
* or part of a terrain effect.
*
* These typically can't be interacted with by players unless under certain cirumstances.
*
*/
public interface IInAnimate {
boolean canInteract(Race race);
}

View file

@ -5,7 +5,9 @@ import javax.annotation.Nullable;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.entity.IInAnimate;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.power.data.Hit; import com.minelittlepony.unicopia.power.data.Hit;
@ -15,6 +17,7 @@ import com.minelittlepony.util.vector.VecHelper;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityWeatherEffect;
import net.minecraft.entity.item.EntityFallingBlock; import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents; import net.minecraft.init.SoundEvents;
@ -43,7 +46,8 @@ public class PowerDisguise extends PowerFeed {
public void apply(IPlayer iplayer, Hit data) { public void apply(IPlayer iplayer, Hit data) {
EntityPlayer player = iplayer.getOwner(); EntityPlayer player = iplayer.getOwner();
RayTraceResult trace = VecHelper.getObjectMouseOver(player, 10, 1); RayTraceResult trace = VecHelper.getObjectMouseOver(player, 10, 1);
Entity looked = null;
Entity looked = trace.entityHit;
if (trace.typeOfHit == RayTraceResult.Type.BLOCK) { if (trace.typeOfHit == RayTraceResult.Type.BLOCK) {
IBlockState state = player.getEntityWorld().getBlockState(trace.getBlockPos()); IBlockState state = player.getEntityWorld().getBlockState(trace.getBlockPos());
@ -51,8 +55,10 @@ public class PowerDisguise extends PowerFeed {
if (!state.getBlock().isAir(state, player.getEntityWorld(), trace.getBlockPos())) { if (!state.getBlock().isAir(state, player.getEntityWorld(), trace.getBlockPos())) {
looked = new EntityFallingBlock(player.getEntityWorld(), 0, 0, 0, state); looked = new EntityFallingBlock(player.getEntityWorld(), 0, 0, 0, state);
} }
} else { }
looked = trace.entityHit;
if (looked instanceof EntityWeatherEffect || (looked instanceof IInAnimate && !((IInAnimate)looked).canInteract(Race.CHANGELING))) {
looked = null;
} }
if (looked instanceof EntityPlayer) { if (looked instanceof EntityPlayer) {