示例#1
0
        public void OpenDialog(IClientWorldAccessor world, BlockPos pos, ItemStack ingredient)
        {
            if (ingredient.Collectible is ItemWorkItem)
            {
                ingredient = new ItemStack(world.GetItem(new AssetLocation("clay-" + ingredient.Collectible.LastCodePart())));
            }

            List <ClayFormingRecipe> recipes = Api.GetClayformingRecipes()
                                               .Where(r => r.Ingredient.SatisfiesAsIngredient(ingredient))
                                               .OrderBy(r => r.Output.ResolvedItemstack.Collectible.Code) // Cannot sort by name, thats language dependent!
                                               .ToList();

            ;


            List <ItemStack> stacks = recipes
                                      .Select(r => r.Output.ResolvedItemstack)
                                      .ToList()
            ;

            ICoreClientAPI capi = Api as ICoreClientAPI;

            dlg = new GuiDialogBlockEntityRecipeSelector(
                Lang.Get("Select recipe"),
                stacks.ToArray(),
                (selectedIndex) => {
                capi.Logger.VerboseDebug("Select clay from recipe {0}, have {1} recipes.", selectedIndex, recipes.Count);

                selectedRecipeId = recipes[selectedIndex].RecipeId;
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.SelectRecipe, SerializerUtil.Serialize(recipes[selectedIndex].RecipeId));
            },
                () => {
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.CancelSelect);
            },
                pos,
                Api as ICoreClientAPI
                );

            dlg.OnClosed += dlg.Dispose;
            dlg.TryOpen();
        }
示例#2
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            if (packetid == (int)EnumBlockStovePacket.OpenGUI)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

                    string dialogClassName = reader.ReadString();
                    string dialogTitle     = reader.ReadString();

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);
                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();

                    IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;

                    SyncedTreeAttribute dtree = new SyncedTreeAttribute();
                    SetDialogValues(dtree);

                    if (clientDialog != null)
                    {
                        clientDialog.TryClose();
                        clientDialog = null;
                    }
                    else
                    {
                        clientDialog           = new GuiDialogBlockEntityFirepit(dialogTitle, Inventory, Pos, dtree, Api as ICoreClientAPI);
                        clientDialog.OnClosed += () => { clientDialog?.Dispose(); clientDialog = null; };
                        clientDialog.TryOpen();
                    }
                }
            }

            if (packetid == (int)EnumBlockEntityPacketId.Close)
            {
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);
            }
        }
示例#3
0
        public override bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            secondsPassed *= 1.25f;

            float backwards = -Math.Min(0.35f, 2 * secondsPassed);
            float stab      = Math.Min(1.2f, 20 * Math.Max(0, secondsPassed - 0.35f));

            if (byEntity.World.Side == EnumAppSide.Client)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ModelTransform       tf    = new ModelTransform();
                tf.EnsureDefaultValues();

                float sum     = stab + backwards;
                float easeout = Math.Max(0, 2 * (secondsPassed - 1));

                if (secondsPassed > 0.4f)
                {
                    sum = Math.Max(0, sum - easeout);
                }

                tf.Translation.Set(-1.4f * sum, 0, -sum * 0.8f * 2.6f);
                tf.Rotation.Set(-sum * 90, 0, sum * 10);

                byEntity.Controls.UsingHeldItemTransformAfter = tf;


                if (stab > 1.15f && byEntity.Attributes.GetInt("didattack") == 0)
                {
                    world.TryAttackEntity(entitySel);
                    byEntity.Attributes.SetInt("didattack", 1);
                    world.AddCameraShake(0.25f);
                }
            }



            return(secondsPassed < 1.2f);
        }
示例#4
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;

            if (packetid == (int)EnumBlockContainerPacketId.OpenInventory)
            {
                if (invDialog != null)
                {
                    invDialog.TryClose();
                    invDialog = null;
                    return;
                }

                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

                    string dialogClassName = reader.ReadString();
                    string dialogTitle     = reader.ReadString();
                    int    cols            = reader.ReadByte();

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);
                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();

                    invDialog = new GuiDialogBlockEntityInventory(dialogTitle, Inventory, pos, cols, api as ICoreClientAPI);
                    invDialog.TryOpen();
                }
            }

            if (packetid == (int)EnumBlockContainerPacketId.CloseInventory)
            {
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);

                invDialog?.TryClose();
                invDialog = null;
            }
        }
        public override void OnHeldIdle(IItemSlot slot, IEntityAgent byEntity)
        {
            if (byEntity.World.Side == EnumAppSide.Client && GetTemperature(byEntity.World, slot.Itemstack) > 50 && byEntity.World.Rand.NextDouble() < 0.07)
            {
                float sideWays             = 0.35f;
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;

                if (world.Player.Entity == byEntity && world.Player.CameraMode != EnumCameraMode.FirstPerson)
                {
                    sideWays = 0f;
                }

                Vec3d pos =
                    byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight - 0.5f, 0)
                    .Ahead(0.33f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                    .Ahead(sideWays, 0, byEntity.Pos.Yaw + GameMath.PIHALF)
                ;

                smokeHeld.minPos = pos.AddCopy(-0.05, 0.1, -0.05);
                byEntity.World.SpawnParticles(smokeHeld);
            }
        }
        private void RenderRecipeOutLine()
        {
            if (recipeOutlineMeshRef == null || api.HideGuis)
            {
                return;
            }
            IRenderAPI           rpi         = api.Render;
            IClientWorldAccessor worldAccess = api.World;
            EntityPos            plrPos      = worldAccess.Player.Entity.Pos;
            Vec3d camPos = worldAccess.Player.Entity.CameraPos;

            IShaderProgram prog = rpi.GetEngineShader(EnumShaderProgram.Wireframe);

            prog.Use();
            rpi.GlMatrixModeModelView();

            rpi.GLEnableDepthTest();
            rpi.GlToggleBlend(true);



            rpi.GlPushMatrix();
            rpi.GlLoadMatrix(rpi.CameraMatrixOrigin);

            rpi.GlTranslate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z);

            outLineColorMul.A = 1 - GameMath.Clamp((float)Math.Sqrt(plrPos.SquareDistanceTo(pos.X, pos.Y, pos.Z)) / 5 - 1f, 0, 1);

            prog.Uniform("colorIn", outLineColorMul);
            prog.UniformMatrix("projectionMatrix", rpi.CurrentProjectionMatrix);
            prog.UniformMatrix("modelViewMatrix", rpi.CurrentModelviewMatrix);

            rpi.RenderMesh(recipeOutlineMeshRef);

            rpi.GlPopMatrix();

            prog.Stop();
        }
示例#7
0
        public override bool OnHeldAttackStep(float secondsPassed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            float backwards = -Math.Min(0.35f, 2 * secondsPassed);
            float stab      = Math.Min(1.2f, 20 * Math.Max(0, secondsPassed - 0.35f)); // + Math.Max(0, 5*(secondsPassed - 0.5f));

            if (byEntity.World.Side == EnumAppSide.Client)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ModelTransform       tf    = new ModelTransform();
                tf.EnsureDefaultValues();

                float sum          = stab + backwards;
                float ztranslation = Math.Min(0.2f, 1.5f * secondsPassed);
                float easeout      = Math.Max(0, 10 * (secondsPassed - 1));

                if (secondsPassed > 0.4f)
                {
                    sum = Math.Max(0, sum - easeout);
                }
                ztranslation = Math.Max(0, ztranslation - easeout);

                tf.Translation.Set(sum * 0.8f, 2.5f * sum / 3, -ztranslation);
                tf.Rotation.Set(sum * 10, sum * 2, sum * 25);

                byEntity.Controls.UsingHeldItemTransformBefore = tf;

                if (stab > 1.15f && byEntity.Attributes.GetInt("didattack") == 0)
                {
                    world.TryAttackEntity(entitySel);
                    byEntity.Attributes.SetInt("didattack", 1);
                    world.ShakeCamera(0.125f);
                }
            }



            return(secondsPassed < 1.2f);
        }
示例#8
0
        public override Vec3d GetPosition(IClientWorldAccessor world, float dt)
        {
            if (!(_player is null))
            {
                return(new Vec3d(_player.Pos.X, _player.LocalEyePos.Y, _player.Pos.Z));
            }

            foreach (var player in world.AllOnlinePlayers)
            {
                if (player.PlayerName == _playerName)
                {
                    _player = player.Entity;
                }
            }

            if (_player is null)
            {
                throw new CamStudioException("The specified target player is not currently online.");
            }


            return(GetPosition());
        }
        public override string GetStackDescription(IClientWorldAccessor world, bool extendedDebugInfo)
        {
            if (TradeItem == null)
            {
                return(base.GetStackDescription(world, extendedDebugInfo));
            }

            if (IsBuyingSlot)
            {
                if (itemstack.Collectible.GetDurability(itemstack) > 1)
                {
                    return(Lang.Get("tradeitem-demand-withdurability", TradeItem.Price, TradeItem.Stock) + "\n\n" + base.GetStackDescription(world, extendedDebugInfo));
                }
                else
                {
                    return(Lang.Get("tradeitem-demand", TradeItem.Price, TradeItem.Stock) + "\n\n" + base.GetStackDescription(world, extendedDebugInfo));
                }
            }
            else
            {
                return(Lang.Get("tradeitem-supply", TradeItem.Price, TradeItem.Stock) + "\n\n" + base.GetStackDescription(world, extendedDebugInfo));
            }
        }
示例#10
0
        private int GetMealHashCode(IClientWorldAccessor world, Block block, ItemStack[] contentStacks, Vec3f foodTranslate)
        {
            string shapestring = block.Shape.ToString() + block.Code.ToShortString();

            if (foodTranslate != null)
            {
                shapestring += foodTranslate.X + "/" + foodTranslate.Y + "/" + foodTranslate.Z;
            }

            string contentstring = "";

            for (int i = 0; i < contentStacks.Length; i++)
            {
                if (contentStacks[i].Collectible.Code.Path == "rot")
                {
                    return((shapestring + "rotten").GetHashCode());
                }

                contentstring += contentStacks[i].Collectible.Code.ToShortString();
            }

            return((shapestring + contentstring).GetHashCode());
        }
        public static void InjectClientThread(this IClientWorldAccessor world, string name,
                                              params ClientSystem[] systems)
        {
            var instance       = CreateClientThread(world, name, systems);
            var clientThreads  = world.GetClientThreads();
            var vanillaSystems = world.GetVanillaSystems();

            foreach (var system in systems)
            {
                vanillaSystems.Push(system);
            }

            (world as ClientMain).SetField("clientSystems", vanillaSystems.ToArray());

            var thread = new Thread(() => instance.CallMethod("Process"))
            {
                IsBackground = true
            };

            thread.Start();
            thread.Name = name;
            clientThreads.Add(thread);
        }
示例#12
0
        internal void OpenDialog(ItemStack ingredient)
        {
            if (ingredient.Collectible is ItemWorkItem)
            {
                ingredient = new ItemStack(api.World.GetItem(new AssetLocation("ingot-" + ingredient.Collectible.LastCodePart())));
            }

            List <SmithingRecipe> recipes = api.World.SmithingRecipes
                                            .Where(r => r.Ingredient.SatisfiesAsIngredient(ingredient))
                                            .OrderBy(r => r.Output.ResolvedItemstack.Collectible.Code) // Cannot sort by name, thats language dependent!
                                            .ToList()
            ;

            List <ItemStack> stacks = recipes
                                      .Select(r => r.Output.ResolvedItemstack)
                                      .ToList()
            ;

            IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;
            ICoreClientAPI       capi        = api as ICoreClientAPI;

            GuiDialog dlg = new GuiDialogBlockEntityRecipeSelector(
                Lang.Get("Select smithing recipe"),
                stacks.ToArray(),
                (selectedIndex) => {
                selectedRecipeId = recipes[selectedIndex].RecipeId;
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.SelectRecipe, SerializerUtil.Serialize(recipes[selectedIndex].RecipeId));
            },
                () => {
                capi.Network.SendBlockEntityPacket(pos.X, pos.Y, pos.Z, (int)EnumClayFormingPacket.CancelSelect);
            },
                pos,
                api as ICoreClientAPI
                );

            dlg.TryOpen();
        }
示例#13
0
        public void Talk(EnumTalkType talkType)
        {
            IClientWorldAccessor world = capi.World as IClientWorldAccessor;

            this.talkType       = talkType;
            totalLettersTalked  = 0;
            currentLetterInWord = 0;

            chordDelay = TalkSpeed[talkType];

            if (talkType == EnumTalkType.Meet)
            {
                lettersLeftToTalk = 2 + world.Rand.Next(10);
            }

            if (talkType == EnumTalkType.Hurt)
            {
                lettersLeftToTalk = 3 + world.Rand.Next(6);
            }

            if (talkType == EnumTalkType.Idle)
            {
                lettersLeftToTalk = 3 + world.Rand.Next(12);
            }

            if (talkType == EnumTalkType.Complain)
            {
                lettersLeftToTalk = 3 + world.Rand.Next(5);
            }

            if (talkType == EnumTalkType.Goodbye)
            {
                lettersLeftToTalk = 2 + world.Rand.Next(2);
            }

            totalLettersToTalk = lettersLeftToTalk;
        }
示例#14
0
        public void Start(IClientWorldAccessor world)
        {
            HasFinished = false;
            IsRunning   = true;

            _timeStarted = DateTime.Now;
            _currentLoop = 0;
            TempNodes    = new List <CamNode>(Nodes);
            if (_loop != 0)
            {
                TempNodes.Add(TempNodes[TempNodes.Count - 1].Clone());
            }


            var parser = CamMode.GetMode();

            _cachedMode = parser.Initialise(this);
            _cachedMode.OnPathStart();

            CachedInterpolation = CamMotionFactory.CreateInstance(_interpolation);
            CachedInterpolation.Initialise(TempNodes, _loop, Target);

            _hideGui = (world as ClientMain).GetField <bool>("ShouldRender2DOverlays");
        }
示例#15
0
        private void OnGameTick(float dt)
        {
            IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;

            if (!clientWorld.Player.Entity.Pos.InRangeOf(Pos, 128 * 128))
            {
                return;
            }
            if (block == null || block.ParticleProperties == null)
            {
                return;
            }

            for (int i = 0; i < block.ParticleProperties.Length; i++)
            {
                AdvancedParticleProperties bps = block.ParticleProperties[i];

                bps.basePos.X = Pos.X + block.TopMiddlePos.X;
                bps.basePos.Y = Pos.Y + block.TopMiddlePos.Y;
                bps.basePos.Z = Pos.Z + block.TopMiddlePos.Z;

                Api.World.SpawnParticles(bps);
            }
        }
示例#16
0
    public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
    {
        IRenderAPI           rpi         = capi.Render;
        IClientWorldAccessor worldAccess = capi.World;
        Vec3d camPos = worldAccess.Player.Entity.CameraPos;

        rpi.GlDisableCullFace();
        IStandardShaderProgram prog = rpi.StandardShader;

        prog.Use();
        prog.RgbaAmbientIn    = rpi.AmbientColor;
        prog.RgbaFogIn        = rpi.FogColor;
        prog.FogMinIn         = rpi.FogMin;
        prog.FogDensityIn     = rpi.FogDensity;
        prog.RgbaTint         = ColorUtil.WhiteArgbVec;
        prog.DontWarpVertices = 0;
        prog.AddRenderFlags   = 0;
        prog.ExtraGodray      = 0;
        prog.OverlayOpacity   = 0;

        Vec4f lightrgbs = capi.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);

        if (stack != null && workItemMeshRef != null)
        {
            int temp = (int)stack.Collectible.GetTemperature(capi.World, stack);

            //Vec4f lightrgbs = capi.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);
            float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f(temp);
            int     extraGlow = GameMath.Clamp((temp - 550) / 2, 0, 255);

            prog.NormalShaded = 1;
            prog.RgbaLightIn  = lightrgbs;
            prog.RgbaGlowIn   = new Vec4f(glowColor[0], glowColor[1], glowColor[2], extraGlow / 255f);

            prog.ExtraGlow        = extraGlow;
            prog.Tex2D            = textureId;
            prog.ModelMatrix      = ModelMat.Identity().Translate(pos.X - camPos.X, pos.Y - camPos.Y + 10 / 16f, pos.Z - camPos.Z).Values;
            prog.ViewMatrix       = rpi.CameraMatrixOriginf;
            prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;

            rpi.RenderMesh(workItemMeshRef);
        }

        if (burning)
        {
            float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f(1200);
            prog.RgbaGlowIn = new Vec4f(glowColor[0], glowColor[1], glowColor[2], 1);
        }
        else
        {
            prog.RgbaGlowIn = new Vec4f(0, 0, 0, 0);
        }

        prog.NormalShaded = 1;
        prog.RgbaLightIn  = lightrgbs;

        prog.ExtraGlow = burning ? 255 : 0;


        rpi.BindTexture2d(hetexpos.atlasTextureId);

        prog.ModelMatrix      = ModelMat.Identity().Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z).Values;
        prog.ViewMatrix       = rpi.CameraMatrixOriginf;
        prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;

        rpi.RenderMesh(heQuadRef);

        prog.Stop();
    }
示例#17
0
 public override Vec3d GetPosition(IClientWorldAccessor world, float dt)
 {
     return(GetPosition());
 }
 public abstract Vec3d GetPosition(IClientWorldAccessor world, float dt);
示例#19
0
 public static ClientMain ClientMain(this IClientWorldAccessor world)
 {
     return(world as ClientMain);
 }
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (needleMeshRef == null || discMeshRef == null)
            {
                return;
            }

            long ellapsedMs = api.World.ElapsedMilliseconds;

            IRenderAPI           rpi         = api.Render;
            IClientWorldAccessor worldAccess = api.World;
            Vec3d camPos    = worldAccess.Player.Entity.CameraPos;
            Vec4f lightrgbs = api.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);

            rpi.GlDisableCullFace();

            IStandardShaderProgram prog = rpi.StandardShader;

            prog.Use();
            prog.ExtraGlow     = 0;
            prog.RgbaAmbientIn = rpi.AmbientColor;
            prog.RgbaFogIn     = rpi.FogColor;
            prog.FogMinIn      = rpi.FogMin;
            prog.FogDensityIn  = rpi.FogDensity;
            prog.RgbaTint      = ColorUtil.WhiteArgbVec;
            prog.RgbaLightIn   = lightrgbs;

            prog.DontWarpVertices = 0;
            prog.AddRenderFlags   = 0;
            prog.ExtraGodray      = 0;
            prog.NormalShaded     = 1;

            rpi.BindTexture2d(api.BlockTextureAtlas.AtlasTextureIds[0]);

            float origx = -0.5f;
            float origz = -0.5f;

            needlePos.X = 3.5f / 16f;
            needlePos.Y = 10.8f / 16f;
            needlePos.Z = -3.5f / 16f;

            // because i'm a noob and lazy
            switch (blockRotation)
            {
            case 90: needlePos.X -= 7 / 16f; break;

            case 180: needlePos.X -= 7 / 16f; needlePos.Z += 7 / 16f; break;

            case 270: needlePos.Z += 7 / 16f; break;
            }

            float wobble = GameMath.Sin(Math.Max(0, ellapsedMs - updatedTotalMs) / 50f - 0.5f) / 80f;

            needleRotRad.Y = -GameMath.PIHALF + Math.Min(0.4f, (ellapsedMs - updatedTotalMs) / 700f) + wobble + blockRotation * GameMath.DEG2RAD;
            needleRotRad.X = wobble;

            prog.ModelMatrix = ModelMat
                               .Identity()
                               .Translate(pos.X - camPos.X + needlePos.X, pos.Y - camPos.Y + needlePos.Y, pos.Z - camPos.Z + needlePos.Z)
                               .Translate(-origx, 0, -origz)
                               .Rotate(needleRotRad)
                               .Translate(origx, 0, origz)
                               .Values
            ;

            prog.ViewMatrix       = rpi.CameraMatrixOriginf;
            prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;

            rpi.RenderMesh(needleMeshRef);



            rpi.BindTexture2d(api.ItemTextureAtlas.AtlasTextureIds[0]);

            origx = -9.25f / 16f;
            float origy = -9.5f / 16f;

            origz = -0.5f;

            discPos.X = -1.25f / 16f;
            discPos.Y = 11.2f / 16f;
            discPos.Z = 0f / 16f;

            discRotRad.X = GameMath.PIHALF;
            discRotRad.Z = -Math.Max(0, (ellapsedMs - updatedTotalMs) / 500f - 0.5f);

            prog.NormalShaded = 0;
            prog.ModelMatrix  = ModelMat
                                .Identity()
                                .Translate(pos.X - camPos.X + discPos.X, pos.Y - camPos.Y + discPos.Y, pos.Z - camPos.Z + discPos.Z)
                                .Translate(-origx, 0, -origz)
                                .Rotate(discRotRad)
                                .Scale(0.45f, 0.45f, 0.45f)
                                .Translate(origx, origy, origz)
                                .Values
            ;
            rpi.RenderMesh(discMeshRef);

            prog.Stop();
        }
示例#21
0
        internal void UpdateVoxel(IPlayer byPlayer, ItemSlot itemslot, Vec3i voxelPos, BlockFacing facing, bool isBreak)
        {
            int mode = ChiselMode(byPlayer);

            if (mode == 5)
            {
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)api.World;

                string prevName = blockName;
                GuiDialogBlockEntityTextInput dlg = new GuiDialogBlockEntityTextInput(Lang.Get("Block name"), pos, blockName, api as ICoreClientAPI);
                dlg.OnTextChanged = (text) => blockName = text;
                dlg.OnCloseCancel = () => blockName = prevName;
                dlg.TryOpen();
            }

            bool wasChanged = false;

            if (mode == 4)
            {
                RotateModel(byPlayer, isBreak);
                wasChanged = true;
            }
            else
            {
                int   size     = ChiselSize(byPlayer);
                Vec3i addAtPos = voxelPos.Clone().Add(size * facing.Normali.X, size * facing.Normali.Y, size * facing.Normali.Z);

                if (isBreak)
                {
                    wasChanged = SetVoxel(voxelPos, false, byPlayer);
                }
                else
                {
                    if (addAtPos.X >= 0 && addAtPos.X < 16 && addAtPos.Y >= 0 && addAtPos.Y < 16 && addAtPos.Z >= 0 && addAtPos.Z < 16)
                    {
                        wasChanged = SetVoxel(addAtPos, true, byPlayer);
                    }
                }
            }


            if (!wasChanged)
            {
                return;
            }

            if (api.Side == EnumAppSide.Client)
            {
                RegenMesh();
            }

            RegenSelectionBoxes(byPlayer);
            MarkDirty(true);

            // Send a custom network packet for server side, because
            // serverside blockselection index is inaccurate
            if (api.Side == EnumAppSide.Client)
            {
                SendUseOverPacket(byPlayer, voxelPos, facing, isBreak);
            }

            double posx = pos.X + voxelPos.X / 16f;
            double posy = pos.Y + voxelPos.Y / 16f;
            double posz = pos.Z + voxelPos.Z / 16f;

            api.World.PlaySoundAt(new AssetLocation("sounds/player/knap" + (api.World.Rand.Next(2) > 0 ? 1 : 2)), posx, posy, posz, byPlayer, true, 12, 1);

            if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative)
            {
                itemslot.Itemstack?.Collectible.DamageItem(api.World, byPlayer.Entity, itemslot);
            }


            if (VoxelCuboids.Count == 0)
            {
                api.World.BlockAccessor.SetBlock(0, pos);
                return;
            }
        }
示例#22
0
        public int GetBucketHashCode(IClientWorldAccessor world, ItemStack contentStack)
        {
            string s = contentStack.StackSize + "x" + contentStack.Collectible.Code.ToShortString();

            return(s.GetHashCode());
        }
        public override void GameTick(Entity entity, float dt)
        {
            EntityPlayer   entityplayer = entity as EntityPlayer;
            EntityControls controls     = entityplayer.Controls;

            string  playerUID = entity.WatchedAttributes.GetString("playerUID");
            IPlayer player    = entity.World.PlayerByUid(playerUID);

            if (entity.World is IServerWorldAccessor && ((IServerPlayer)player).ConnectionState != EnumClientState.Playing)
            {
                return;
            }

            if (player != null)
            {
                IClientWorldAccessor clientWorld = entity.World as IClientWorldAccessor;

                // Tyron Nov. 10 2020: This line of code was from August 2020 where it fixed jitter of other players related to climbing ladders?
                // Cannot repro. But what I can repro is this line breaks player animations. They are stuck in a permanent land pose, so disabled for now.
                //if (clientWorld != null && clientWorld.Player.ClientId != player.ClientId) return;

                // We pretend the entity is flying to disable gravity so that EntityBehaviorInterpolatePosition system
                // can work better
                controls.IsFlying            = player.WorldData.FreeMove || (clientWorld != null && clientWorld.Player.ClientId != player.ClientId);
                controls.NoClip              = player.WorldData.NoClip;
                controls.MovespeedMultiplier = player.WorldData.MoveSpeedMultiplier;
            }

            EntityPos pos = entity.World is IServerWorldAccessor ? entity.ServerPos : entity.Pos;



            if (controls.TriesToMove && player is IClientPlayer)
            {
                IClientPlayer cplr = player as IClientPlayer;

                float prevYaw = pos.Yaw;

                if (entity.Swimming)
                {
                    float prevPitch = pos.Pitch;
                    pos.Yaw   = cplr.CameraYaw;
                    pos.Pitch = cplr.CameraPitch;
                    controls.CalcMovementVectors(pos, dt);
                    pos.Yaw   = prevYaw;
                    pos.Pitch = prevPitch;
                }
                else
                {
                    pos.Yaw = cplr.CameraYaw;
                    controls.CalcMovementVectors(pos, dt);
                    pos.Yaw = prevYaw;
                }

                float desiredYaw = (float)Math.Atan2(controls.WalkVector.X, controls.WalkVector.Z) - GameMath.PIHALF;

                float yawDist = GameMath.AngleRadDistance(entityplayer.WalkYaw, desiredYaw);
                entityplayer.WalkYaw += GameMath.Clamp(yawDist, -8 * dt * GlobalConstants.OverallSpeedMultiplier, 8 * dt * GlobalConstants.OverallSpeedMultiplier);
                entityplayer.WalkYaw  = GameMath.Mod(entityplayer.WalkYaw, GameMath.TWOPI);

                if (entity.Swimming)
                {
                    float desiredPitch = -(float)Math.Sin(pos.Pitch); // (float)controls.FlyVector.Y * GameMath.PI;
                    float pitchDist    = GameMath.AngleRadDistance(entityplayer.WalkPitch, desiredPitch);
                    entityplayer.WalkPitch += GameMath.Clamp(pitchDist, -2 * dt * GlobalConstants.OverallSpeedMultiplier, 2 * dt * GlobalConstants.OverallSpeedMultiplier);
                    entityplayer.WalkPitch  = GameMath.Mod(entityplayer.WalkPitch, GameMath.TWOPI);
                }
                else
                {
                    entityplayer.WalkPitch = 0;
                }
            }
            else
            {
                controls.CalcMovementVectors(pos, dt);
            }

            TickEntityPhysics(pos, controls, dt);
        }
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (stack == null && fuelLevel == 0)
            {
                return;
            }

            IRenderAPI           rpi         = capi.Render;
            IClientWorldAccessor worldAccess = capi.World;
            EntityPos            plrPos      = worldAccess.Player.Entity.Pos;
            Vec3d camPos = worldAccess.Player.Entity.CameraPos;

            rpi.GlDisableCullFace();
            IStandardShaderProgram prog = rpi.StandardShader;

            prog.Use();
            prog.RgbaAmbientIn = rpi.AmbientColor;
            prog.RgbaFogIn     = rpi.FogColor;
            prog.FogMinIn      = rpi.FogMin;
            prog.FogDensityIn  = rpi.FogDensity;
            prog.RgbaTint      = ColorUtil.WhiteArgbVec;
            prog.WaterWave     = 0;
            //rpi.GlMatrixModeModelView();


            if (stack != null && workItemMeshRef != null)
            {
                int temp = (int)stack.Collectible.GetTemperature(capi.World, stack);

                prog.ExtraGlow = GameMath.Clamp((temp - 700) / 2, 0, 255);

                Vec4f lightrgbs = capi.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);

                float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f(temp);
                lightrgbs[0] += 2 * glowColor[0];
                lightrgbs[1] += 2 * glowColor[1];
                lightrgbs[2] += 2 * glowColor[2];

                prog.RgbaLightIn = lightrgbs;
                prog.RgbaBlockIn = ColorUtil.WhiteArgbVec;

                // The work item
                rpi.BindTexture2d(workItemTexPos.atlasTextureId);

                prog.ModelMatrix      = ModelMat.Identity().Translate(pos.X - camPos.X, pos.Y - camPos.Y + 7 / 16f + fuelLevel * 0.65f, pos.Z - camPos.Z).Values;
                prog.ViewMatrix       = rpi.CameraMatrixOriginf;
                prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;

                rpi.RenderMesh(workItemMeshRef);
            }

            if (fuelLevel > 0)
            {
                Vec4f lightrgbs = capi.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);

                prog.RgbaLightIn = lightrgbs;
                prog.RgbaBlockIn = ColorUtil.WhiteArgbVec;
                prog.ExtraGlow   = 0;

                // The coal or embers
                rpi.BindTexture2d(burning ? embertexpos.atlasTextureId : coaltexpos.atlasTextureId);

                prog.ModelMatrix      = ModelMat.Identity().Translate(pos.X - camPos.X, pos.Y - camPos.Y + 7 / 16f + fuelLevel * 0.65f, pos.Z - camPos.Z).Values;
                prog.ViewMatrix       = rpi.CameraMatrixOriginf;
                prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;

                rpi.RenderMesh(burning ? emberQuadRef : coalQuadRef);
            }


            prog.Stop();
        }
 public static Stack <ClientSystem> GetVanillaSystems(this IClientWorldAccessor world)
 {
     return(new((world as ClientMain).GetField <ClientSystem[]>("clientSystems")));
 }
 public static List <Thread> GetClientThreads(this IClientWorldAccessor world)
 {
     return((world as ClientMain).GetField <List <Thread> >("clientThreads"));
 }
示例#27
0
 /// <summary>
 /// Gets the StackDescription for the item.
 /// </summary>
 /// <param name="world">The world the item resides in.</param>
 /// <param name="extendedDebugInfo">Whether or not we have Extended Debug Info enabled.</param>
 /// <returns></returns>
 public virtual string GetStackDescription(IClientWorldAccessor world, bool extendedDebugInfo)
 {
     return(itemstack?.GetDescription(world, this, extendedDebugInfo));
 }
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            if (LevelLeft <= 0 && LevelRight <= 0)
            {
                return;
            }

            IRenderAPI           rpi         = api.Render;
            IClientWorldAccessor worldAccess = api.World;
            EntityPos            plrPos      = worldAccess.Player.Entity.Pos;
            Vec3d camPos = worldAccess.Player.Entity.CameraPos;

            rpi.GlDisableCullFace();
            IStandardShaderProgram prog = rpi.StandardShader;

            prog.Use();
            prog.RgbaAmbientIn    = rpi.AmbientColor;
            prog.RgbaFogIn        = rpi.FogColor;
            prog.FogMinIn         = rpi.FogMin;
            prog.FogDensityIn     = rpi.FogDensity;
            prog.RgbaTint         = ColorUtil.WhiteArgbVec;
            prog.DontWarpVertices = 0;
            prog.ExtraGodray      = 0;
            prog.AddRenderFlags   = 0;

            if (LevelLeft > 0 && TextureNameLeft != null)
            {
                Vec4f   lightrgbs = api.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);
                float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f((int)TemperatureLeft);
                int     extraGlow = (int)GameMath.Clamp((TemperatureLeft - 550) / 1.5f, 0, 255);

                prog.RgbaLightIn = lightrgbs;
                prog.RgbaGlowIn  = new Vec4f(glowColor[0], glowColor[1], glowColor[2], extraGlow / 255f);

                prog.ExtraGlow    = extraGlow;
                prog.NormalShaded = 0;

                int texid = api.Render.GetOrLoadTexture(TextureNameLeft);
                rpi.BindTexture2d(texid);

                float xzOffset = (QuantityMolds > 1) ? 4.5f : 8.5f;

                prog.ModelMatrix = ModelMat
                                   .Identity()
                                   .Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z)
                                   .Translate(xzOffset / 16f, 1 / 16f + LevelLeft / 850f, 8.5f / 16)
                                   .RotateX(90 * GameMath.DEG2RAD)
                                   .Scale(0.5f * 3 / 16f, 0.5f * 7 / 16f, 0.5f)
                                   .Values
                ;
                prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;
                prog.ViewMatrix       = rpi.CameraMatrixOriginf;

                rpi.RenderMesh(quadModelRef);
            }


            if (LevelRight > 0 && QuantityMolds > 1 && TextureNameRight != null)
            {
                Vec4f   lightrgbs = api.World.BlockAccessor.GetLightRGBs(pos.X, pos.Y, pos.Z);
                float[] glowColor = ColorUtil.GetIncandescenceColorAsColor4f((int)TemperatureRight);
                int     extraGlow = (int)GameMath.Clamp((TemperatureRight - 550) / 1.5f, 0, 255);

                prog.RgbaLightIn = lightrgbs;
                prog.RgbaGlowIn  = new Vec4f(glowColor[0], glowColor[1], glowColor[2], extraGlow / 255f);

                prog.ExtraGlow    = extraGlow;
                prog.NormalShaded = 0;

                int texid = api.Render.GetOrLoadTexture(TextureNameRight);
                rpi.BindTexture2d(texid);

                /*
                 * rpi.GlPushMatrix();
                 * rpi.GlLoadMatrix(api.Render.CameraMatrixOrigin);
                 * rpi.GlTranslate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z);
                 * rpi.GlTranslate(11.5f / 16f, 1 / 16f + LevelRight / 850f, 8.5f / 16);
                 * rpi.GlRotate(90, 1, 0, 0);
                 * rpi.GlScale(0.5f * 3 / 16f, 0.5f * 7 / 16f, 0.5f);
                 * prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;
                 * prog.ModelViewMatrix = rpi.CurrentModelviewMatrix;
                 * rpi.GlPopMatrix();
                 */

                prog.ModelMatrix = ModelMat
                                   .Identity()
                                   .Translate(pos.X - camPos.X, pos.Y - camPos.Y, pos.Z - camPos.Z)
                                   .Translate(11.5f / 16f, 1 / 16f + LevelRight / 850f, 8.5f / 16)
                                   .RotateX(90 * GameMath.DEG2RAD)
                                   .Scale(0.5f * 3 / 16f, 0.5f * 7 / 16f, 0.5f)
                                   .Values
                ;
                prog.ProjectionMatrix = rpi.CurrentProjectionMatrix;
                prog.ViewMatrix       = rpi.CameraMatrixOriginf;


                rpi.RenderMesh(quadModelRef);
            }


            prog.Stop();
            rpi.GlEnableCullFace();
        }
示例#29
0
        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            switch (packetid)
            {
            case (int)Packet.OpenGUI:
                using (MemoryStream ms = new MemoryStream(data))
                {
                    if (invDialog != null)
                    {
                        if (invDialog?.IsOpened() == true)
                        {
                            invDialog.TryClose();
                        }
                        invDialog?.Dispose();
                        invDialog = null;
                        return;
                    }

                    BinaryReader reader = new BinaryReader(ms);

                    string dialogClassName = reader.ReadString();
                    string dialogTitle     = reader.ReadString();

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);

                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();

                    invDialog = new GuiDialogTinkerTable(dialogTitle, Inventory, Pos, Api as ICoreClientAPI);

                    invDialog.TryOpen();
                }
                break;

            case (int)Packet.CloseGUI:
                IClientWorldAccessor clientWorld = (IClientWorldAccessor)Api.World;
                clientWorld.Player.InventoryManager.CloseInventory(Inventory);
                if (invDialog?.IsOpened() == true)
                {
                    invDialog?.TryClose();
                }
                invDialog?.Dispose();
                invDialog = null;
                break;

            case (int)Packet.UpdateInv:
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);

                    TreeAttribute tree = new TreeAttribute();
                    tree.FromBytes(reader);

                    Inventory.FromTreeAttributes(tree);
                    Inventory.ResolveBlocksOrItems();
                    invDialog?.SetupDialog();
                }
                break;
            }
        }
示例#30
0
        public override bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
        {
            float backwards = -Math.Min(0.8f, 3 * secondsPassed);
            float stab      = Math.Min(1.2f, 20 * Math.Max(0, secondsPassed - 0.25f));

            if (byEntity.World.Side == EnumAppSide.Client)
            {
                IClientWorldAccessor world = byEntity.World as IClientWorldAccessor;
                ModelTransform       tf    = new ModelTransform();
                tf.EnsureDefaultValues();


                float sum          = stab + backwards;
                float ztranslation = Math.Min(0.2f, 1.5f * secondsPassed);
                float easeout      = Math.Max(0, 2 * (secondsPassed - 1));

                if (secondsPassed > 0.4f)
                {
                    sum = Math.Max(0, sum - easeout);
                }
                ztranslation = Math.Max(0, ztranslation - easeout);

                tf.Translation.Set(-1f * sum, ztranslation * 0.4f, -sum * 0.8f * 2.6f);
                tf.Rotation.Set(-sum * 9, sum * 30, -sum * 30);

                byEntity.Controls.UsingHeldItemTransformAfter = tf;


                if (stab > 1.15f && byEntity.Attributes.GetInt("didattack") == 0)
                {
                    world.TryAttackEntity(entitySel);
                    byEntity.Attributes.SetInt("didattack", 1);
                    world.AddCameraShake(0.25f);
                }
            }
            else
            {
                if (stab > 1.15f && byEntity.Attributes.GetInt("didattack") == 0 && entitySel != null)
                {
                    byEntity.Attributes.SetInt("didattack", 1);

                    bool canhackEntity =
                        entitySel.Entity.Properties.Attributes?["hackedEntity"].Exists == true &&
                        slot.Itemstack.ItemAttributes.IsTrue("hacking") == true && api.ModLoader.GetModSystem <CharacterSystem>().HasTrait((byEntity as EntityPlayer).Player, "technical")
                    ;
                    ICoreServerAPI sapi = api as ICoreServerAPI;

                    if (canhackEntity)
                    {
                        sapi.World.PlaySoundAt(new AssetLocation("sounds/player/hackingspearhit.ogg"), entitySel.Entity, null);
                    }

                    if (api.World.Rand.NextDouble() < 0.15 && canhackEntity)
                    {
                        SpawnEntityInPlaceOf(entitySel.Entity, entitySel.Entity.Properties.Attributes["hackedEntity"].AsString(), byEntity);
                        sapi.World.DespawnEntity(entitySel.Entity, new EntityDespawnReason()
                        {
                            reason = EnumDespawnReason.Removed
                        });
                    }
                }
            }

            return(secondsPassed < 1.2f);
        }