public EntityBlockFallingRenderer(Entity entity, ICoreClientAPI api) : base(entity, api) { this.blockFallingEntity = (EntityBlockFalling)entity; this.block = blockFallingEntity.Block; entity.PhysicsUpdateWatcher = OnPhysicsTick; if (!blockFallingEntity.InitialBlockRemoved) { BlockEntity be = api.World.BlockAccessor.GetBlockEntity(blockFallingEntity.initialPos); be?.OnTesselation(this, capi.Tesselator); if (mesh.VerticesCount > 0) { mesh.CustomBytes = null; mesh.CustomFloats = null; mesh.CustomInts = null; this.meshRef = capi.Render.UploadMesh(mesh); } } if (this.meshRef == null) { MeshData mesh = api.TesselatorManager.GetDefaultBlockMesh(block); this.meshRef = api.Render.UploadMesh(mesh); } int textureSubId = block.FirstTextureInventory.Baked.TextureSubId; this.atlasTextureId = api.BlockTextureAtlas.Positions[textureSubId].atlasTextureId; prevPos.Set(entity.Pos.X + entity.CollisionBox.X1, entity.Pos.Y + entity.CollisionBox.Y1, entity.Pos.Z + entity.CollisionBox.Z1); }
private bool TryFalling(IWorldAccessor world, BlockPos pos) { if (world.Side == EnumAppSide.Client) { return(false); } ICoreServerAPI sapi = (world as IServerWorldAccessor).Api as ICoreServerAPI; if (!sapi.Server.Config.AllowFallingBlocks) { return(false); } if (IsReplacableBeneath(world, pos)) { // Prevents duplication Entity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 3, (e) => { return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos)); } ); if (entity == null) { EntityBlockFalling entityblock = new EntityBlockFalling(block, world.BlockAccessor.GetBlockEntity(pos), pos); world.SpawnEntity(entityblock); } return(true); } return(false); }
private bool TryFalling(IWorldAccessor world, BlockPos pos, ref EnumHandling handling, ref string failureCode) { if (world.Side != EnumAppSide.Server) { return(false); } if (!fallSideways && IsAttached(world.BlockAccessor, pos)) { return(false); } ICoreServerAPI sapi = (world as IServerWorldAccessor).Api as ICoreServerAPI; if (!sapi.Server.Config.AllowFallingBlocks) { return(false); } if (IsReplacableBeneath(world, pos) || (fallSideways && world.Rand.NextDouble() < fallSidewaysChance && IsReplacableBeneathAndSideways(world, pos))) { // Prevents duplication Entity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 1.5f, (e) => { return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos)); }); if (entity == null) { EntityBlockFalling entityblock = new EntityBlockFalling(block, world.BlockAccessor.GetBlockEntity(pos), pos, fallSound, impactDamageMul, true, dustIntensity); world.SpawnEntity(entityblock); } else { handling = EnumHandling.PreventDefault; failureCode = "entityintersecting"; return(false); } handling = EnumHandling.PreventSubsequent; return(true); } handling = EnumHandling.PassThrough; return(false); }
private bool TryPartialCollapse(BlockPos pos, int quantity) { if (inventory[0].Empty) { return(false); } IWorldAccessor world = Api.World; if (world.Side == EnumAppSide.Server) { ICoreServerAPI sapi = (world as IServerWorldAccessor).Api as ICoreServerAPI; if (!sapi.Server.Config.AllowFallingBlocks) { return(false); } } if (IsReplacableBeneath(world, pos) || IsReplacableBeneathAndSideways(world, pos)) { // Prevents duplication Entity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 1.5f, (e) => { return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos)); }); if (entity == null) { int prevstacksize = inventory[0].StackSize; inventory[0].Itemstack.StackSize = quantity; EntityBlockFalling entityblock = new EntityBlockFalling(Block, this, pos, null, 1, true, 0.05f); entityblock.DoRemoveBlock = false; // We want to split the pile, not remove it world.SpawnEntity(entityblock); entityblock.ServerPos.Y -= 0.25f; entityblock.Pos.Y -= 0.25f; inventory[0].Itemstack.StackSize = prevstacksize - quantity; return(true); } } return(false); }
public EntityBlockFallingRenderer(Entity entity, ICoreClientAPI api) : base(entity, api) { this.blockFallingEntity = (EntityBlockFalling)entity; this.block = blockFallingEntity.Block; if (blockFallingEntity.removedBlockentity is IBlockShapeSupplier) { (blockFallingEntity.removedBlockentity as IBlockShapeSupplier).OnTesselation(this, capi.Tesselator); } if (this.meshRef == null) { this.meshRef = api.Render.UploadMesh(api.TesselatorManager.GetDefaultBlockMesh(block)); } int textureSubId = block.FirstTextureInventory.Baked.TextureSubId; this.atlasTextureId = api.BlockTextureAtlas.Positions[textureSubId].atlasTextureId; }
private bool TryFalling(IWorldAccessor world, BlockPos pos) { if (IsReplacableBeneath(world, pos)) { // Prevents duplication IEntity entity = world.GetNearestEntity(pos.ToVec3d().Add(0.5, 0.5, 0.5), 1, 3, (e) => { return(e is EntityBlockFalling && ((EntityBlockFalling)e).initialPos.Equals(pos)); } ); if (entity == null) { EntityBlockFalling entityblock = new EntityBlockFalling(block, world.BlockAccessor.GetBlockEntity(pos), pos); world.SpawnEntity(entityblock); } return(true); } return(false); }
public void Unregister(EntityBlockFalling entity) { toRemove.Enqueue(entity); }
public void Register(EntityBlockFalling entity) { toRegister.Enqueue(entity); }