Mimic entities will spawn when the player can see their block and they are within 5 blocks (mimics with inventories only spawn on interacting with them).
This commit is contained in:
parent
421aa77c02
commit
8a94dd8acd
|
@ -29,11 +29,9 @@ import net.minecraft.pathfinding.PathNavigateClimber;
|
|||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import WayofTime.bloodmagic.block.BlockMimic;
|
||||
import WayofTime.bloodmagic.registry.ModBlocks;
|
||||
import WayofTime.bloodmagic.tile.TileMimic;
|
||||
|
@ -44,18 +42,15 @@ public class EntityMimic extends EntityMob
|
|||
* Copy of EntitySpider's AI (should be pretty evident...)
|
||||
*/
|
||||
private static final DataParameter<Byte> CLIMBING = EntityDataManager.<Byte>createKey(EntityMimic.class, DataSerializers.BYTE);
|
||||
// private static final DataParameter<Optional<ItemStack>> ITEMSTACK = EntityDataManager.<Optional<ItemStack>>createKey(EntityMimic.class, DataSerializers.OPTIONAL_ITEM_STACK);
|
||||
|
||||
public boolean dropItemsOnBreak = true;
|
||||
public NBTTagCompound tileTag = new NBTTagCompound();
|
||||
public int metaOfReplacedBlock = 0;
|
||||
|
||||
// public ItemStack heldStack = null;
|
||||
|
||||
public EntityMimic(World worldIn)
|
||||
{
|
||||
super(worldIn);
|
||||
this.setSize(1.4F, 0.9F);
|
||||
this.setSize(0.9F, 0.9F);
|
||||
}
|
||||
|
||||
protected void initEntityAI()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package WayofTime.bloodmagic.tile;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
|
@ -14,6 +15,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
|
@ -22,7 +25,7 @@ import WayofTime.bloodmagic.entity.mob.EntityMimic;
|
|||
import WayofTime.bloodmagic.registry.ModBlocks;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
|
||||
public class TileMimic extends TileInventory
|
||||
public class TileMimic extends TileInventory implements ITickable
|
||||
{
|
||||
private static Field _blockMetadata = ReflectionHelper.findField(TileEntity.class, "blockMetadata", "field_145847_g");
|
||||
|
||||
|
@ -31,14 +34,36 @@ public class TileMimic extends TileInventory
|
|||
public TileEntity mimicedTile = null;
|
||||
public int metaOfReplacedBlock = 0;
|
||||
|
||||
public int spawnRadius = 5;
|
||||
|
||||
public TileMimic()
|
||||
{
|
||||
super(1, "mimic");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if (this.getBlockMetadata() == BlockMimic.sentientMimicMeta && !(mimicedTile instanceof IInventory))
|
||||
{
|
||||
AxisAlignedBB bb = new AxisAlignedBB(this.getPos()).expand(spawnRadius, spawnRadius, spawnRadius);
|
||||
List<EntityPlayer> playerList = worldObj.getEntitiesWithinAABB(EntityPlayer.class, bb);
|
||||
|
||||
for (EntityPlayer player : playerList)
|
||||
{
|
||||
if (!player.capabilities.isCreativeMode && Utils.canEntitySeeBlock(worldObj, player, getPos()))
|
||||
{
|
||||
spawnMimicEntity(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side)
|
||||
{
|
||||
if (performSpecialAbility())
|
||||
if (performSpecialAbility(player))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -67,11 +92,18 @@ public class TileMimic extends TileInventory
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean performSpecialAbility()
|
||||
public boolean performSpecialAbility(EntityPlayer player)
|
||||
{
|
||||
switch (this.getBlockMetadata())
|
||||
{
|
||||
case BlockMimic.sentientMimicMeta:
|
||||
return spawnMimicEntity(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean spawnMimicEntity(EntityPlayer target)
|
||||
{
|
||||
if (this.getStackInSlot(0) == null || worldObj.isRemote)
|
||||
{
|
||||
return false;
|
||||
|
@ -86,13 +118,15 @@ public class TileMimic extends TileInventory
|
|||
this.setInventorySlotContents(0, null);
|
||||
|
||||
worldObj.spawnEntityInWorld(mimicEntity);
|
||||
if (target != null)
|
||||
{
|
||||
mimicEntity.setAttackTarget(target);
|
||||
}
|
||||
|
||||
worldObj.setBlockToAir(pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void refreshTileEntity()
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.block.BlockLiquid;
|
|||
import net.minecraft.block.BlockPortal;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -33,6 +34,8 @@ import net.minecraft.util.EnumFacing;
|
|||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.ISpecialArmor;
|
||||
|
@ -82,6 +85,19 @@ public class Utils
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean canEntitySeeBlock(World world, Entity entity, BlockPos pos)
|
||||
{
|
||||
Vec3d relativePosition = new Vec3d(entity.posX - pos.getX() - 0.5, entity.posY + (double) entity.getEyeHeight() - pos.getY() - 0.5, entity.posZ - pos.getZ() - 0.5);
|
||||
EnumFacing dir = EnumFacing.getFacingFromVector((float) relativePosition.xCoord, (float) relativePosition.yCoord, (float) relativePosition.zCoord);
|
||||
RayTraceResult result = world.rayTraceBlocks(new Vec3d(entity.posX, entity.posY + (double) entity.getEyeHeight(), entity.posZ), new Vec3d(pos.getX() + 0.5 + dir.getFrontOffsetX() * 0.4, pos.getY() + 0.5 + dir.getFrontOffsetY() * 0.4, pos.getZ() + 0.5 + dir.getFrontOffsetZ() * 0.4), false, true, true);
|
||||
if (result != null)
|
||||
{
|
||||
return pos.equals(result.getBlockPos());
|
||||
}
|
||||
|
||||
return result != null;
|
||||
}
|
||||
|
||||
public static int plantSeedsInArea(World world, AxisAlignedBB aabb, int horizontalRadius, int verticalRadius)
|
||||
{
|
||||
int placedBlocks = 0;
|
||||
|
|
|
@ -589,6 +589,7 @@ chat.BloodMagic.altar.nextTier=The next tier of blood altar is missing %s at %s.
|
|||
|
||||
# entity
|
||||
entity.BloodMagic.SentientSpecter.name=Sentient Specter
|
||||
entity.BloodMagic.Mimic.name=Mimic
|
||||
|
||||
# sekrit
|
||||
|
||||
|
|
Loading…
Reference in a new issue