示例#1
0
        public override bool OnPlayerInteractStart(IPlayer player, BlockSelection bs)
        {
            ItemSlot hotbarSlot = player.InventoryManager.ActiveHotbarSlot;

            if (hotbarSlot.Empty)
            {
                return(false);
            }

            if (currentBuildStage < buildStages.Length)
            {
                BuildStage           stage = buildStages[currentBuildStage];
                BuildStageMaterial[] mats  = stage.Materials;

                for (int i = 0; i < mats.Length; i++)
                {
                    var stack = mats[i].ItemStack;

                    if (stack.Equals(Api.World, hotbarSlot.Itemstack, GlobalConstants.IgnoredStackAttributes) && stack.StackSize <= hotbarSlot.StackSize)
                    {
                        if (!isSameMatAsPreviouslyAdded(stack))
                        {
                            continue;
                        }

                        int toMove = stack.StackSize;
                        for (int j = 4; j < invSlotCount && toMove > 0; j++)
                        {
                            toMove -= hotbarSlot.TryPutInto(Api.World, inventory[j], toMove);
                        }

                        hotbarSlot.MarkDirty();

                        currentBuildStage++;
                        mesh = null;
                        MarkDirty(true);
                        updateSelectiveElements();
                        (player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);

                        if (stack.Collectible.Attributes?["placeSound"].Exists == true)
                        {
                            AssetLocation sound = AssetLocation.Create(stack.Collectible.Attributes["placeSound"].AsString(), stack.Collectible.Code.Domain);
                            if (sound != null)
                            {
                                Api.World.PlaySoundAt(sound.WithPathPrefixOnce("sounds/"), Pos.X + 0.5, Pos.Y + 0.1, Pos.Z + 0.5, player, true, 12);
                            }
                        }
                    }
                }
            }


            DetermineStorageProperties(null);

            return(true);
        }
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            if (removedBlockentity != null)
            {
                this.blockEntityAttributes = new TreeAttribute();
                removedBlockentity.ToTreeAttributes(blockEntityAttributes);
                blockEntityClass = api.World.ClassRegistry.GetBlockEntityClass(removedBlockentity.GetType());
            }

            SimulationRange = (int)(0.75f * GlobalConstants.DefaultTrackingRange);
            base.Initialize(properties, api, InChunkIndex3d);

            // Need to capture this now before we remove the block and start to fall
            drops = Block.GetDrops(api.World, initialPos, null);

            lightHsv = Block.GetLightHsv(World.BlockAccessor, initialPos);

            SidedPos.Motion.Y = -0.02;
            blockAsStack      = new ItemStack(Block);


            if (api.Side == EnumAppSide.Client && fallSound != null && fallingNow.Count < 100)
            {
                fallingNow.Add(EntityId);
                ICoreClientAPI capi = api as ICoreClientAPI;
                sound = capi.World.LoadSound(new SoundParams()
                {
                    Location  = fallSound.WithPathPrefixOnce("sounds/").WithPathAppendixOnce(".ogg"),
                    Position  = new Vec3f((float)Pos.X, (float)Pos.Y, (float)Pos.Z),
                    Range     = 32,
                    Pitch     = 0.8f + (float)capi.World.Rand.NextDouble() * 0.3f,
                    Volume    = 1,
                    SoundType = EnumSoundType.Ambient
                });
                sound.Start();
                soundStartDelay = 0.05f + (float)capi.World.Rand.NextDouble() / 3f;
            }

            canFallSideways = WatchedAttributes.GetBool("canFallSideways");
            dustIntensity   = WatchedAttributes.GetFloat("dustIntensity");


            if (WatchedAttributes.HasAttribute("fallSound"))
            {
                fallSound = new AssetLocation(WatchedAttributes.GetString("fallSound"));
            }

            if (api.World.Side == EnumAppSide.Client)
            {
                particleSys = api.ModLoader.GetModSystem <FallingBlockParticlesModSystem>();
                particleSys.Register(this);
                physicsBh = GetBehavior <EntityBehaviorPassivePhysics>();
            }
        }
示例#3
0
 /// <summary>
 /// Initialize the track.
 /// </summary>
 /// <param name="assetManager">the global Asset Manager</param>
 /// <param name="capi">The Core Client API</param>
 /// <param name="musicEngine"></param>
 public virtual void Initialize(IAssetManager assetManager, ICoreClientAPI capi, IMusicEngine musicEngine)
 {
     this.capi        = capi;
     this.musicEngine = musicEngine;
     Location.Path    = Location.Path.ToLowerInvariant();
     if (!Location.Path.StartsWith("sounds"))
     {
         Location.WithPathPrefixOnce("music/");
     }
     Location.WithPathAppendixOnce(".ogg");
 }
        public override void OnJsonTesselation(ref MeshData sourceMesh, ref int[] lightRgbsByCorner, BlockPos pos, Block[] chunkExtBlocks, int extIndex3d)
        {
            Block upBlock = chunkExtBlocks[extIndex3d + TileSideEnum.MoveIndex[TileSideEnum.Up]];

            if (upBlock is BlockFence)
            {
                int var = (GameMath.MurmurHash3Mod(pos.X, pos.Y, pos.Z, 8) + 1);

                MeshData mesh;
                if (!continousFenceMeches.TryGetValue(cntCode + var, out mesh))
                {
                    AssetLocation loc = Shape.Base.Clone();
                    loc.Path = loc.Path.Replace("-top", "");
                    loc.WithPathAppendixOnce(".json");
                    loc.WithPathPrefixOnce("shapes/");
                    Shape shape = capi.Assets.TryGet(loc).ToObject <Shape>();

                    CompositeTexture ct = Textures["wall"];
                    int prevSubid       = ct.Baked.TextureSubId;
                    ct.Baked.TextureSubId = ct.Baked.BakedVariants[GameMath.MurmurHash3Mod(pos.X, pos.Y, pos.Z, ct.Alternates.Length)].TextureSubId;

                    capi.Tesselator.TesselateShape(this, shape, out mesh, new Vec3f(Shape.rotateX, Shape.rotateY, Shape.rotateZ), Shape.QuantityElements, Shape.SelectiveElements);

                    ct.Baked.TextureSubId = prevSubid;

                    continousFenceMeches[cntCode] = mesh;
                }

                sourceMesh = mesh;
            }


            // Todo: make this work

            /*            int nBlockId = chunkExtIds[extIndex3d + TileSideEnum.MoveIndex[TileSideEnum.Up]];
             *          Block upblock = api.World.Blocks[nBlockId];
             *
             *          if (upblock.snowLevel >= 1 && snowLayerBlock != null)
             *          {
             *              sourceMesh = sourceMesh.Clone();
             *              sourceMesh.AddMeshData(capi.TesselatorManager.GetDefaultBlockMesh(snowLayerBlock));
             *              return;
             *          }*/

            return;  // no windwave for solid fences!

            //base.OnJsonTesselation(ref sourceMesh, ref lightRgbsByCorner, pos, chunkExtIds, chunkLightExt, extIndex3d);
        }
示例#5
0
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            if (removedBlockentity != null)
            {
                this.blockEntityAttributes = new TreeAttribute();
                removedBlockentity.ToTreeAttributes(blockEntityAttributes);
                blockEntityClass = api.World.ClassRegistry.GetBlockEntityClass(removedBlockentity.GetType());
            }

            SimulationRange = 3 * api.World.BlockAccessor.ChunkSize;
            base.Initialize(properties, api, InChunkIndex3d);

            // Need to capture this now before we remove the block and start to fall
            drops = Block.GetDrops(api.World, initialPos, null);

            lightHsv = Block.GetLightHsv(World.BlockAccessor, initialPos);

            LocalPos.Motion.Y = -0.02;
            blockAsStack      = new ItemStack(Block);


            if (api.Side == EnumAppSide.Client && fallSound != null)
            {
                ICoreClientAPI capi = api as ICoreClientAPI;
                sound = capi.World.LoadSound(new SoundParams()
                {
                    Location  = fallSound.WithPathPrefixOnce("sounds/").WithPathAppendixOnce(".ogg"),
                    Position  = new Vec3f((float)Pos.X, (float)Pos.Y, (float)Pos.Z),
                    Range     = 32,
                    Pitch     = 0.8f + (float)capi.World.Rand.NextDouble() * 0.3f,
                    Volume    = 1,
                    SoundType = EnumSoundType.Ambient
                });
                soundStartDelay = 0.05f + (float)capi.World.Rand.NextDouble() / 3f;
            }

            canFallSideways = WatchedAttributes.GetBool("canFallSideways");
            dustyFall       = WatchedAttributes.GetBool("dustyFall");


            if (WatchedAttributes.HasAttribute("fallSound"))
            {
                fallSound = new AssetLocation(WatchedAttributes.GetString("fallSound"));
            }
        }
示例#6
0
        public void OnCreated(IPlayer byPlayer)
        {
            StorageProps = null;
            mesh         = null;
            DetermineBuildStages();
            DetermineStorageProperties(null);

            var stack = inventory[4].Itemstack = byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(buildStages[0].Materials[0].ItemStack.StackSize);

            currentBuildStage++;

            if (stack.Collectible.Attributes?["placeSound"].Exists == true)
            {
                AssetLocation sound = AssetLocation.Create(stack.Collectible.Attributes["placeSound"].AsString(), stack.Collectible.Code.Domain);
                if (sound != null)
                {
                    Api.World.PlaySoundAt(sound.WithPathPrefixOnce("sounds/"), Pos.X + 0.5, Pos.Y + 0.1, Pos.Z + 0.5, byPlayer, true, 12);
                }
            }

            byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty();

            updateSelectiveElements();
        }