Plato Platypus Posted October 16, 2023 Report Posted October 16, 2023 (edited) Does anyone know where i can find the files or config that deal with the lantern color selection? for example you add blue glass to a lantern and then the lantern emits a blue color? i would like to add this to a mod ive been working on but cannot figure out hwo this is accomplished. thanks for your assistance:D Edited October 16, 2023 by Plato Platypus
Frepo Posted October 16, 2023 Report Posted October 16, 2023 (edited) If you take a look in the BlockLantern class, you'll find the method GetLightHsv, which retrieves the light from the lantern. Spoiler public override byte[] GetLightHsv(IBlockAccessor blockAccessor, BlockPos pos, ItemStack stack = null) { if (pos != null) { BELantern be = blockAccessor.GetBlockEntity(pos) as BELantern; if (be != null) { return be.GetLightHsv(); } } if (stack != null) { string lining = stack.Attributes.GetString("lining", null); stack.Attributes.GetString("material", null); int v = (int)(this.LightHsv[2] + ((lining != "plain") ? 2 : 0)); byte[] lightHsv = new byte[] { this.LightHsv[0], this.LightHsv[1], (byte)v }; BELantern.setLightColor(this.LightHsv, lightHsv, stack.Attributes.GetString("glass", null)); return lightHsv; } return base.GetLightHsv(blockAccessor, pos, stack); } And in this method is a call to it's entity class, BELantern: BELantern.setLightColor(this.LightHsv, lightHsv, stack.Attributes.GetString("glass", null)); Where the glass attribute is passed in. And as the name implies, this is where the light is set depending on the glass. Spoiler public static void setLightColor(byte[] origLightHsv, byte[] lightHsv, string color) { if (color != null) { switch (color.Length) { case 3: if (color == "red") { lightHsv[0] = 0; lightHsv[1] = 4; return; } break; case 4: { char c = color[0]; if (c != 'b') { if (c == 'p') { if (color == "pink") { lightHsv[0] = 54; lightHsv[1] = 4; return; } } } else if (color == "blue") { lightHsv[0] = 42; lightHsv[1] = 4; return; } break; } case 5: { char c = color[0]; if (c != 'b') { if (c == 'g') { if (color == "green") { lightHsv[0] = 20; lightHsv[1] = 4; return; } } } else if (color == "brown") { lightHsv[0] = 5; lightHsv[1] = 4; return; } break; } case 6: { char c = color[0]; if (c != 'v') { if (c == 'y') { if (color == "yellow") { lightHsv[0] = 11; lightHsv[1] = 4; return; } } } else if (color == "violet") { lightHsv[0] = 48; lightHsv[1] = 4; return; } break; } } } lightHsv[1] = origLightHsv[1]; lightHsv[0] = origLightHsv[0]; } Also in BELantern is where the player sets the color by interaction. Spoiler internal bool Interact(IPlayer byPlayer) { ItemSlot slot = byPlayer.InventoryManager.ActiveHotbarSlot; if (slot.Empty) { return false; } CollectibleObject obj = slot.Itemstack.Collectible; if (obj.FirstCodePart(0) == "glass" && obj.Variant.ContainsKey("color")) { if (this.glass != "quartz" && byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative) { ItemStack stack = new ItemStack(this.Api.World.GetBlock(new AssetLocation("glass-" + this.glass)), 1); if (!byPlayer.InventoryManager.TryGiveItemstack(stack, true)) { this.Api.World.SpawnItemEntity(stack, this.Pos.ToVec3d().Add(0.5, 0.0, 0.5), null); } } this.glass = obj.Variant["color"]; if (byPlayer.WorldData.CurrentGameMode != EnumGameMode.Creative && this.glass != "quartz") { slot.TakeOut(1); } if (this.Api.Side == EnumAppSide.Client) { (byPlayer as IClientPlayer).TriggerFpAnimation(EnumHandInteract.HeldItemInteract); } Vec3d soundpos = this.Pos.ToVec3d().Add(0.5, 0.0, 0.5); this.Api.World.PlaySoundAt(this.Api.World.GetBlock(new AssetLocation("glass-" + this.glass)).Sounds.Place, soundpos.X, soundpos.Y, soundpos.Z, byPlayer, true, 32f, 1f); BELantern.setLightColor(this.origlightHsv, this.lightHsv, this.glass); this.Api.World.BlockAccessor.ExchangeBlock(base.Block.Id, this.Pos); this.MarkDirty(true, null); return true; } if (this.lining == null || (this.lining == "plain" && obj is ItemMetalPlate && (obj.Variant["metal"] == "gold" || obj.Variant["metal"] == "silver"))) { this.lining = obj.Variant["metal"]; if (this.Api.Side == EnumAppSide.Client) { (byPlayer as IClientPlayer).TriggerFpAnimation(EnumHandInteract.HeldItemInteract); } Vec3d soundpos2 = this.Pos.ToVec3d().Add(0.5, 0.0, 0.5); this.Api.World.PlaySoundAt(new AssetLocation("sounds/block/plate"), soundpos2.X, soundpos2.Y, soundpos2.Z, byPlayer, true, 32f, 1f); slot.TakeOut(1); this.MarkDirty(true, null); return true; } return false; } Edited October 16, 2023 by Frepo 1 1
Recommended Posts