Jump to content

Can't use pigment on right block (labeled trunk)


Frepo

Recommended Posts

 

So I've made a labeled trunk. Everything works fine, except for using pigment (say charcoal) on the right part/block of the trunk. Instead of opening the write-text-gui, it piles the charcoal on the ground in front of the chest. My entity (BlockEntityFTTrunkLabeled) is derived from the BlockEntityLabeledChest, so it shouldn't do that, at least not in ItemPileable...

image.png.5c3ac1a4593639d7e1e693cb6e953289.png

It so strange since I can open the trunk on both the left and the right block, that interaction works fine. But I can only trigger the write-text-interaction on the left. I've checked and compared the code a hundred times over, but I just can't find the error. It must be something either in the OnPlayerRightClick method:

Spoiler
        public override bool OnPlayerRightClick(IPlayer byPlayer, BlockSelection blockSel)
        {
            if (byPlayer != null)
            {
                EntityPlayer entity = byPlayer.Entity;
                bool? flag;
                if (entity == null)
                {
                    flag = null;
                }
                else
                {
                    EntityControls controls = entity.Controls;
                    flag = ((controls != null) ? new bool?(controls.ShiftKey) : null);
                }
                bool? flag2 = flag;
                bool flag3 = true;
                if (flag2.GetValueOrDefault() == flag3 & flag2 != null)
                {
                    ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot;
                    if (hotbarSlot != null)
                    {
                        ItemStack itemstack = hotbarSlot.Itemstack;
                        bool? flag4;
                        if (itemstack == null)
                        {
                            flag4 = null;
                        }
                        else
                        {
                            JsonObject itemAttributes = itemstack.ItemAttributes;
                            if (itemAttributes == null)
                            {
                                flag4 = null;
                            }
                            else
                            {
                                JsonObject jsonObject = itemAttributes["pigment"];
                                flag4 = ((jsonObject != null) ? new bool?(jsonObject["color"].Exists) : null);
                            }
                        }
                        flag2 = flag4;
                        flag3 = true;
                        if (flag2.GetValueOrDefault() == flag3 & flag2 != null)
                        {
                            JsonObject jsonObject2 = hotbarSlot.Itemstack.ItemAttributes["pigment"]["color"];
                            int r = jsonObject2["red"].AsInt(0);
                            int g = jsonObject2["green"].AsInt(0);
                            int b = jsonObject2["blue"].AsInt(0);
                            this.tempColor = ColorUtil.ToRgba(255, r, g, b);
                            this.tempStack = hotbarSlot.TakeOut(1);
                            hotbarSlot.MarkDirty();
                            if (this.Api.World is IServerWorldAccessor)
                            {
                                byte[] data;
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    BinaryWriter binaryWriter = new BinaryWriter(ms);
                                    binaryWriter.Write("BlockEntityTextInput");
                                    binaryWriter.Write(Lang.Get("Edit chest label text", Array.Empty<object>()));
                                    binaryWriter.Write(this.text);
                                    data = ms.ToArray();
                                }
                                ((ICoreServerAPI)this.Api).Network.SendBlockEntityPacket((IServerPlayer)byPlayer, this.Pos.X, this.Pos.Y, this.Pos.Z, 1001, data);
                            }
                            return true;
                        }
                    }
                }
            }
            return base.OnPlayerRightClick(byPlayer, blockSel);
        }

 

or in my json-file (which is basically a mash of the vanilla chest-trunk and chest-labeled😞

Spoiler
{
	code: "ftlabeledtrunk",
	class: "BlockGenericTypedContainerTrunk",
	entityclass: "BlockEntityFTTrunkLabeled",
	attributes: {
		partialAttachable: true,
		inventoryClassName: "chest",
		defaultType: "acacia",
		types: ["oak", "acacia", "baldcypress", "birch", "ebony", "kapok", "larch", "maple", "pine", "purpleheart", "redwood", "walnut"],
		rotatatableInterval: {
			"acacia": "22.5degnot45deg",
			"baldcypress": "22.5degnot45deg",
			"birch": "22.5degnot45deg",
			"ebony": "22.5degnot45deg",
			"kapok": "22.5degnot45deg",
			"larch": "22.5degnot45deg",
			"maple": "22.5degnot45deg",
			"pine": "22.5degnot45deg",
			"purpleheart": "22.5degnot45deg",
			"redwood": "22.5degnot45deg",
			"walnut": "22.5degnot45deg",
			"oak": "22.5degnot45deg"
		},
		drop: {
			"acacia": true,
			"baldcypress": true,
			"birch": true,
			"ebony": true,
			"kapok": true,
			"larch": true,
			"maple": true,
			"pine": true,
			"purpleheart": true,
			"redwood": true,
			"walnut": true,
			"oak": true
		},
		quantitySlots: {
			"acacia": 36,
			"baldcypress": 36,
			"birch": 36,
			"ebony": 36,
			"kapok": 36,
			"larch": 36,
			"maple": 36,
			"pine": 36,
			"purpleheart": 36,
			"redwood": 36,
			"walnut": 36,
			"oak": 36
		},
		quantityColumns: {
			"acacia": 9,
			"baldcypress": 9,
			"birch": 9,
			"ebony": 9,
			"kapok": 9,
			"larch": 9,
			"maple": 9,
			"pine": 9,
			"purpleheart": 9,
			"redwood": 9,
			"walnut": 9,
			"oak": 9
		},
		dialogTitleLangCode: {
			"acacia": "trunkcontents",
			"baldcypress": "trunkcontents",
			"birch": "trunkcontents",
			"ebony": "trunkcontents",
			"kapok": "trunkcontents",
			"larch": "trunkcontents",
			"maple": "trunkcontents",
			"pine": "trunkcontents",
			"purpleheart": "trunkcontents",
			"redwood": "trunkcontents",
			"walnut": "trunkcontents",
			"oak": "trunkcontents"
		},
		storageType: {
			"acacia": 189,
			"baldcypress": 189,
			"birch": 189,
			"ebony": 189,
			"kapok": 189,
			"larch": 189,
			"maple": 189,
			"pine": 189,
			"purpleheart": 189,
			"redwood": 189,
			"walnut": 189,
			"oak": 189
		},
		retrieveOnly: {
			"acacia": false,
			"baldcypress": false,
			"birch": false,
			"ebony": false,
			"kapok": false,
			"larch": false,
			"maple": false,
			"pine": false,
			"purpleheart": false,
			"redwood": false,
			"walnut": false,
			"oak": false
		},
		shape: {
			"acacia": "fregtech:block/chest/trunk-labeled-0",
			"baldcypress": "fregtech:block/chest/trunk-labeled-1",
			"birch": "fregtech:block/chest/trunk-labeled-2",
			"ebony": "fregtech:block/chest/trunk-labeled-3",
			"kapok": "fregtech:block/chest/trunk-labeled-4",
			"larch": "fregtech:block/chest/trunk-labeled-5",
			"maple": "fregtech:block/chest/trunk-labeled-6",
			"pine": "fregtech:block/chest/trunk-labeled-7",
			"purpleheart": "fregtech:block/chest/trunk-labeled-8",
			"redwood": "fregtech:block/chest/trunk-labeled-9",
			"walnut": "fregtech:block/chest/trunk-labeled-10",
			"oak": "fregtech:block/chest/trunk-labeled-11"
		},
		typedOpenSound: {
			"acacia": "game:sounds/block/largechestopen",
			"baldcypress": "game:sounds/block/largechestopen",
			"birch": "game:sounds/block/largechestopen",
			"ebony": "game:sounds/block/largechestopen",
			"kapok": "game:sounds/block/largechestopen",
			"larch": "game:sounds/block/largechestopen",
			"maple": "game:sounds/block/largechestopen",
			"pine": "game:sounds/block/largechestopen",
			"purpleheart": "game:sounds/block/largechestopen",
			"redwood": "game:sounds/block/largechestopen",
			"walnut": "game:sounds/block/largechestopen",
			"oak": "game:sounds/block/largechestopen"
		},
		typedCloseSound: {
			"acacia": "game:sounds/block/largechestclose",
			"baldcypress": "game:sounds/block/largechestclose",
			"birch": "game:sounds/block/largechestclose",
			"ebony": "game:sounds/block/largechestclose",
			"kapok": "game:sounds/block/largechestclose",
			"larch": "game:sounds/block/largechestclose",
			"maple": "game:sounds/block/largechestclose",
			"pine": "game:sounds/block/largechestclose",
			"purpleheart": "game:sounds/block/largechestclose",
			"redwood": "game:sounds/block/largechestclose",
			"walnut": "game:sounds/block/largechestclose",
			"oak": "game:sounds/block/largechestclose"
		},
		variantByGroup: "side",
		variantByGroupInventory: null
	},
	behaviors: [
		{ name: "HorizontalOrientable"},
		{ name: "Multiblock", propertiesByType: {
				"*-north": { sizex: 2, sizey: 1, sizez: 1, cposition: { x: 0, y: 0, z: 0 } },
				"*-east": { sizex: 1, sizey: 1, sizez: 2, cposition: { x: 0, y: 0, z: 0 } },
				"*-south": { sizex: 2, sizey: 1, sizez: 1, cposition: { x: 1, y: 0, z: 0 } },
				"*-west": { sizex: 1, sizey: 1, sizez: 2, cposition: { x: 0, y: 0, z: 1 } } 
			}
		},
		{ name: "Lockable" },
		{ name: "Container"}
	],
	entityBehaviors: [{ name: "Animatable" }],
	variantgroups: [
		{ code:"side", loadFromProperties: "game:abstract/horizontalorientation" }
	],
	creativeinventory: {  },
	creativeinventoryStacksByType: {
		"*-east": [
			{
				tabs: [ "general", "decorative" ],
				stacks: [
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "acacia" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "baldcypress" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "birch" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "ebony" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "kapok" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "larch" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "maple" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "pine" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "purpleheart" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "redwood" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "walnut" } },
					{ type: "block", code: "ftlabeledtrunk-east", attributes: { type: "oak" } },
				]
			}
		]
	},
	heldTpIdleAnimation: "holdunderarm",
	shapeInventory: { base: "game:block/wood/trunk/normal-sign", rotateY: 270 },
	shapeByType: {
		"*-north": { base: "game:block/wood/trunk/normal-sign", rotateY: 0 },
		"*-east": { base: "game:block/wood/trunk/normal-sign", rotateY: 270 },
		"*-west": { base: "game:block/wood/trunk/normal-sign", rotateY: 90 },
		"*-south": { base: "game:block/wood/trunk/normal-sign", rotateY: 180 },
	},
	"_comment": "Must declare textures so they get added to the block texture atlas",
	textures: {
		"acacia-right-side": { base: "fregtech:chest/right-side-acacia" },
		"acacia-sides2": { base: "fregtech:chest/sides-acacia" },
		"acacia-lid": { base: "game:block/wood/debarked/acacia" },
		"acacia-accessories": { base: "fregtech:chest/accessories-acacia" },
		"acacia-left-side": { base: "fregtech:chest/left-side-acacia" },
		
		"baldcypress-right-side": { base: "fregtech:chest/right-side-baldcypress" },
		"baldcypress-sides2": { base: "fregtech:chest/sides-baldcypress" },
		"baldcypress-lid": { base: "game:block/wood/debarked/baldcypress" },
		"baldcypress-accessories": { base: "fregtech:chest/accessories-baldcypress" },
		"baldcypress-left-side": { base: "fregtech:chest/left-side-baldcypress" },
		
		"birch-right-side": { base: "fregtech:chest/right-side-birch" },
		"birch-sides2": { base: "fregtech:chest/sides-birch" },
		"birch-lid": { base: "game:block/wood/debarked/birch" },
		"birch-accessories": { base: "fregtech:chest/accessories-birch" },
		"birch-left-side": { base: "fregtech:chest/left-side-birch" },
		
		"ebony-right-side": { base: "fregtech:chest/right-side-ebony" },
		"ebony-sides2": { base: "fregtech:chest/sides-ebony" },
		"ebony-lid": { base: "game:block/wood/debarked/ebony" },
		"ebony-accessories": { base: "fregtech:chest/accessories-ebony" },
		"ebony-left-side": { base: "fregtech:chest/left-side-ebony" },
		
		"kapok-right-side": { base: "fregtech:chest/right-side-kapok" },
		"kapok-sides2": { base: "fregtech:chest/sides-kapok" },
		"kapok-lid": { base: "game:block/wood/debarked/kapok" },
		"kapok-accessories": { base: "fregtech:chest/accessories-kapok" },
		"kapok-left-side": { base: "fregtech:chest/left-side-kapok" },
		
		"larch-right-side": { base: "fregtech:chest/right-side-larch" },
		"larch-sides2": { base: "fregtech:chest/sides-larch" },
		"larch-lid": { base: "game:block/wood/debarked/larch" },
		"larch-accessories": { base: "fregtech:chest/accessories-larch" },
		"larch-left-side": { base: "fregtech:chest/left-side-larch" },
		
		"maple-right-side": { base: "fregtech:chest/right-side-maple" },
		"maple-sides2": { base: "fregtech:chest/sides-maple" },
		"maple-lid": { base: "game:block/wood/debarked/maple" },
		"maple-accessories": { base: "fregtech:chest/accessories-maple" },
		"maple-left-side": { base: "fregtech:chest/left-side-maple" },
		
		"pine-right-side": { base: "fregtech:chest/right-side-pine" },
		"pine-sides2": { base: "fregtech:chest/sides-pine" },
		"pine-lid": { base: "game:block/wood/debarked/pine" },
		"pine-accessories": { base: "fregtech:chest/accessories-pine" },
		"pine-left-side": { base: "fregtech:chest/left-side-pine" },
		
		"purpleheart-right-side": { base: "fregtech:chest/right-side-purpleheart" },
		"purpleheart-sides2": { base: "fregtech:chest/sides-purpleheart" },
		"purpleheart-lid": { base: "game:block/wood/debarked/purpleheart" },
		"purpleheart-accessories": { base: "fregtech:chest/accessories-purpleheart" },
		"purpleheart-left-side": { base: "fregtech:chest/left-side-purpleheart" },
		
		"redwood-right-side": { base: "fregtech:chest/right-side-redwood" },
		"redwood-sides2": { base: "fregtech:chest/sides-redwood" },
		"redwood-lid": { base: "game:block/wood/debarked/redwood" },
		"redwood-accessories": { base: "fregtech:chest/accessories-redwood" },
		"redwood-left-side": { base: "fregtech:chest/left-side-redwood" },
		
		"walnut-right-side": { base: "fregtech:chest/right-side-walnut" },
		"walnut-sides2": { base: "fregtech:chest/sides-walnut" },
		"walnut-lid": { base: "game:block/wood/debarked/walnut" },
		"walnut-accessories": { base: "fregtech:chest/accessories-walnut" },
		"walnut-left-side": { base: "fregtech:chest/left-side-walnut" },
		
		"oak-right-side": { base: "game:block/wood/trunk/right-side" },
		"oak-sides2": { base: "game:block/wood/trunk/sides" },
		"oak-lid": { base: "game:block/wood/trunk/lid" },
		"oak-accessories": { base: "game:block/wood/trunk/accessories" },
		"oak-left-side": { base: "game:block/wood/trunk/left-side" },
		
	},
	blockmaterial: "Wood",
	replaceable: 900,
	resistance: 3,
	lightAbsorption: 0,
	sideAo: { all: false },
	sidesolid: {
		all: false
	},
	sideopaque: {
		all: false
	},
	collisionSelectionBox: {
		x1: 0.0625, y1: 0, z1: 0.0625, x2: 1, y2: 0.8125, z2: 0.9375,
		rotateYByType: {
			"*-east": 270,
			"*-west": 90,
			"*-south": 180
		}
	},
	combustibleProps: {
		burnTemperature: 600,
		burnDuration: 35,
	},
	sounds: {
		"place": "game:block/planks",
		"hit": "game:block/planks",
		"break": "game:block/planks",
		"walk": "game:walk/wood"
	},
	materialDensity: 600,
	tpHandTransform: {
		translation: { x: -0.3, y: -0.5, z: -0.3 },
		rotation: { x: 0, y: 90, z: -102 },
		scale: 0.56
	},
	guiTransform: {
		origin: { x: 0.5, y: 0.5, z: 0.97 },
		scale: 0.95
	}
}

 

I've paid extra attention to the multiblock behavior and collisionSelectionBox, but I guess it's not that since interaction (opening the trunk) works as expected.

full BlockEntityFTTrunkLabeled class (if it helps)

Spoiler
namespace fregtech
{
    internal class BlockEntityFTTrunkLabeled : BlockEntityLabeledChest
    {
        public BlockEntityFTTrunkLabeled()
        {
        }

        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);
            this.LateInitInventory();
            this.OnTick(1f);

            if (api is ICoreClientAPI)
            {
                this.trunklabelrenderer = new FTTrunkLabelRenderer(this.Pos, api as ICoreClientAPI);
                this.trunklabelrenderer.SetRotation(this.MeshAngle);
                this.trunklabelrenderer.SetNewText(this.text, this.color);
            }
        }

        public override float GetPerishRate()
        {
            return base.GetPerishRate() * 1.35f;
        }

        public override float MeshAngle
        {
            get
            {
                return base.MeshAngle;
            }
            set
            {
                FTTrunkLabelRenderer chestLabelRenderer = this.trunklabelrenderer;
                if (chestLabelRenderer != null)
                {
                    chestLabelRenderer.SetRotation(value);
                }
                base.MeshAngle = value;
            }
        }

        public override string DialogTitle
        {
            get
            {
                if (this.text == null || this.text.Length == 0)
                {
                    return Lang.Get("Chest Contents", Array.Empty<object>());
                }
                return this.text.Replace("\r", "").Replace("\n", " ").Substring(0, Math.Min(this.text.Length, 15));
            }
        }

        public override bool OnPlayerRightClick(IPlayer byPlayer, BlockSelection blockSel)
        {
            if (byPlayer != null)
            {
                EntityPlayer entity = byPlayer.Entity;
                bool? flag;
                if (entity == null)
                {
                    flag = null;
                }
                else
                {
                    EntityControls controls = entity.Controls;
                    flag = ((controls != null) ? new bool?(controls.ShiftKey) : null);
                }
                bool? flag2 = flag;
                bool flag3 = true;
                if (flag2.GetValueOrDefault() == flag3 & flag2 != null)
                {
                    ItemSlot hotbarSlot = byPlayer.InventoryManager.ActiveHotbarSlot;
                    if (hotbarSlot != null)
                    {
                        ItemStack itemstack = hotbarSlot.Itemstack;
                        bool? flag4;
                        if (itemstack == null)
                        {
                            flag4 = null;
                        }
                        else
                        {
                            JsonObject itemAttributes = itemstack.ItemAttributes;
                            if (itemAttributes == null)
                            {
                                flag4 = null;
                            }
                            else
                            {
                                JsonObject jsonObject = itemAttributes["pigment"];
                                flag4 = ((jsonObject != null) ? new bool?(jsonObject["color"].Exists) : null);
                            }
                        }
                        flag2 = flag4;
                        flag3 = true;
                        if (flag2.GetValueOrDefault() == flag3 & flag2 != null)
                        {
                            JsonObject jsonObject2 = hotbarSlot.Itemstack.ItemAttributes["pigment"]["color"];
                            int r = jsonObject2["red"].AsInt(0);
                            int g = jsonObject2["green"].AsInt(0);
                            int b = jsonObject2["blue"].AsInt(0);
                            this.tempColor = ColorUtil.ToRgba(255, r, g, b);
                            this.tempStack = hotbarSlot.TakeOut(1);
                            hotbarSlot.MarkDirty();
                            if (this.Api.World is IServerWorldAccessor)
                            {
                                byte[] data;
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    BinaryWriter binaryWriter = new BinaryWriter(ms);
                                    binaryWriter.Write("BlockEntityTextInput");
                                    binaryWriter.Write(Lang.Get("Edit chest label text", Array.Empty<object>()));
                                    binaryWriter.Write(this.text);
                                    data = ms.ToArray();
                                }
                                ((ICoreServerAPI)this.Api).Network.SendBlockEntityPacket((IServerPlayer)byPlayer, this.Pos.X, this.Pos.Y, this.Pos.Z, 1001, data);
                            }
                            return true;
                        }
                    }
                }
            }
            return base.OnPlayerRightClick(byPlayer, blockSel);
        }

        public override void OnReceivedClientPacket(IPlayer player, int packetid, byte[] data)
        {
            if (packetid == 1002)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);
                    this.text = reader.ReadString();
                    if (this.text == null)
                    {
                        this.text = "";
                    }
                }
                this.color = this.tempColor;
                base.MarkDirty(true, null);
                this.Api.World.BlockAccessor.GetChunkAtBlockPos(this.Pos.X, this.Pos.Y, this.Pos.Z).MarkModified();
                if (this.Api.World.Rand.NextDouble() < 0.85)
                {
                    player.InventoryManager.TryGiveItemstack(this.tempStack, false);
                }
            }
            if (packetid == 1003 && this.tempStack != null)
            {
                player.InventoryManager.TryGiveItemstack(this.tempStack, false);
                this.tempStack = null;
            }
            base.OnReceivedClientPacket(player, packetid, data);

        }

        public override void OnReceivedServerPacket(int packetid, byte[] data)
        {
            IClientWorldAccessor clientWorldAccessor = (IClientWorldAccessor)this.Api.World;

            if (packetid == 1001)
            {
                using (MemoryStream ms = new MemoryStream(data))
                {
                    BinaryReader reader = new BinaryReader(ms);
                    reader.ReadString();
                    string dialogTitle = reader.ReadString();
                    this.text = reader.ReadString();
                    if (this.text == null)
                    {
                        this.text = "";
                    }
                    
                    this.textdialog = new GuiDialogBlockEntityTextInput(dialogTitle, this.Pos, this.text, this.Api as ICoreClientAPI, 115, 4);
                    this.textdialog.OnTextChanged = new Action<string>(this.DidChangeTextClientSide);
                    this.textdialog.OnCloseCancel = delegate ()
                    {
                        FTTrunkLabelRenderer chestLabelRenderer = this.trunklabelrenderer;
                        if (chestLabelRenderer != null)
                        {
                            chestLabelRenderer.SetNewText(this.text, this.color);
                        }
                        (this.Api as ICoreClientAPI).Network.SendBlockEntityPacket(this.Pos.X, this.Pos.Y, this.Pos.Z, 1003, null);
                    };
                    this.textdialog.TryOpen();
                }
            }
            if (packetid == 1000)
            {
                using (MemoryStream ms2 = new MemoryStream(data))
                {
                    BinaryReader reader2 = new BinaryReader(ms2);
                    this.text = reader2.ReadString();
                    if (this.text == null)
                    {
                        this.text = "";
                    }
                    if (this.trunklabelrenderer != null)
                    {
                        this.trunklabelrenderer.SetNewText(this.text, this.color);
                    }
                }
            }
            
            //base.OnReceivedServerPacket(packetid, data);

            //IClientWorldAccessor clientWorldAccessor = (IClientWorldAccessor)Api.World;
            if (packetid == 5000)
            {
                if (invDialog != null)
                {
                    if (invDialog?.IsOpened() ?? false)
                    {
                        invDialog.TryClose();
                    }

                    invDialog?.Dispose();
                    invDialog = null;
                    return;
                }

                TreeAttribute treeAttribute = new TreeAttribute();
                string dialogTitle;
                int cols;
                using (MemoryStream input = new MemoryStream(data))
                {
                    BinaryReader binaryReader = new BinaryReader(input);
                    binaryReader.ReadString();
                    dialogTitle = binaryReader.ReadString();
                    cols = binaryReader.ReadByte();
                    treeAttribute.FromBytes(binaryReader);
                }

                Inventory.FromTreeAttributes(treeAttribute);
                Inventory.ResolveBlocksOrItems();
                invDialog = new GuiDialogBlockEntityInventory(dialogTitle, Inventory, Pos, cols, Api as ICoreClientAPI);
                Block block = Api.World.BlockAccessor.GetBlock(Pos);
                string text = block.Attributes?["openSound"]?.AsString();
                string text2 = block.Attributes?["closeSound"]?.AsString();
                AssetLocation assetLocation = ((text == null) ? null : AssetLocation.Create(text, block.Code.Domain));
                AssetLocation assetLocation2 = ((text2 == null) ? null : AssetLocation.Create(text2, block.Code.Domain));
                invDialog.OpenSound = assetLocation ?? OpenSound;
                invDialog.CloseSound = assetLocation2 ?? CloseSound;
                invDialog.TryOpen();
            }

            if (packetid == 1001)
            {
                clientWorldAccessor.Player.InventoryManager.CloseInventory(Inventory);
                if (invDialog?.IsOpened() ?? false)
                {
                    invDialog?.TryClose();
                }

                invDialog?.Dispose();
                invDialog = null;
            }
        }

        private void DidChangeTextClientSide(string text)
        {
            FTTrunkLabelRenderer chestLabelRenderer = this.trunklabelrenderer;
            if (chestLabelRenderer == null)
            {
                return;
            }
            chestLabelRenderer.SetNewText(text, this.tempColor);
        }

        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            //base.FromTreeAttributes(tree, worldForResolving);

            // from BlockEntityGenericTypedContainer
            string text = type;
            type = tree.GetString("type", defaultType);
            MeshAngle = tree.GetFloat("meshAngle", MeshAngle);
            if (Inventory == null)
            {
                if (tree.HasAttribute("forBlockId"))
                {
                    InitInventory(worldForResolving.GetBlock((ushort)tree.GetInt("forBlockId")));
                }
                else if (tree.HasAttribute("forBlockCode"))
                {
                    InitInventory(worldForResolving.GetBlock(new AssetLocation(tree.GetString("forBlockCode"))));
                }
                else
                {
                    if (tree.GetTreeAttribute("inventory").GetInt("qslots") == 8)
                    {
                        quantitySlots = 8;
                        inventoryClassName = "basket";
                        dialogTitleLangCode = "basketcontents";
                        if (type == null)
                        {
                            type = "reed";
                        }
                    }

                    InitInventory(null);
                }
            }
            else if (type != text)
            {
                InitInventory(base.Block);
                if (Api == null)
                {
                    Api = worldForResolving.Api;
                }

                LateInitInventory();
            }

            if (Api != null && Api.Side == EnumAppSide.Client)
            {
                ownMesh = null;
                MarkDirty(redrawOnClient: true);
            }

            // from BlockEntity
            Pos = new BlockPos(tree.GetInt("posx"), tree.GetInt("posy"), tree.GetInt("posz"));
            foreach (BlockEntityBehavior behavior in Behaviors)
            {
                behavior.FromTreeAttributes(tree, worldForResolving);
            }

            // from BlockEntityContainer
            Inventory.FromTreeAttributes(tree.GetTreeAttribute("inventory"));

            this.color = tree.GetInt("color", 0);
            this.text = tree.GetString("text", null);
            FTTrunkLabelRenderer chestLabelRenderer = this.trunklabelrenderer;
            if (chestLabelRenderer == null)
            {
                return;
            }
            chestLabelRenderer.SetNewText(this.text, this.color);


        }

        public override void ToTreeAttributes(ITreeAttribute tree)
        {
            //base.ToTreeAttributes(tree);

            // from BlockEntity
            tree.SetInt("posx", Pos.X);
            tree.SetInt("posy", Pos.Y);
            tree.SetInt("posz", Pos.Z);
            if (Block != null)
            {
                tree.SetString("blockCode", Block.Code.ToShortString());
            }

            foreach (BlockEntityBehavior behavior in Behaviors)
            {
                behavior.ToTreeAttributes(tree);
            }

            // from BlockEntityContainer
            if (Inventory != null)
            {
                ITreeAttribute treeAttribute = new TreeAttribute();
                Inventory.ToTreeAttributes(treeAttribute);
                tree["inventory"] = treeAttribute;
            }

            // from GenericTypeEntityContainer
            if (base.Block != null)
            {
                tree.SetString("forBlockCode", base.Block.Code.ToShortString());
            }

            if (type == null)
            {
                type = defaultType;
            }
            tree.SetString("type", type);
            tree.SetFloat("meshAngle", MeshAngle);

            // this class' code
            tree.SetInt("color", this.color);
            tree.SetString("text", this.text);
        }

        public override void OnBlockRemoved()
        {
            base.OnBlockRemoved();
            if (this.trunklabelrenderer != null)
            {
                this.trunklabelrenderer.Dispose();
                this.trunklabelrenderer = null;
            }
            GuiDialogBlockEntityTextInput guiDialogBlockEntityTextInput = this.textdialog;
            if (guiDialogBlockEntityTextInput != null)
            {
                guiDialogBlockEntityTextInput.TryClose();
            }
            GuiDialogBlockEntityTextInput guiDialogBlockEntityTextInput2 = this.textdialog;
            if (guiDialogBlockEntityTextInput2 == null)
            {
                return;
            }
            guiDialogBlockEntityTextInput2.Dispose();
        }

        public override void OnBlockBroken(IPlayer byPlayer = null)
        {
            base.OnBlockBroken(byPlayer);
            FTTrunkLabelRenderer chestLabelRenderer = this.trunklabelrenderer;
            if (chestLabelRenderer == null)
            {
                return;
            }
            chestLabelRenderer.Dispose();
        }

        public override void OnBlockUnloaded()
        {
            base.OnBlockUnloaded();
            FTTrunkLabelRenderer chestLabelRenderer = this.trunklabelrenderer;
            if (chestLabelRenderer != null)
            {
                chestLabelRenderer.Dispose();
            }
            GuiDialogBlockEntityTextInput guiDialogBlockEntityTextInput = this.textdialog;
            if (guiDialogBlockEntityTextInput != null)
            {
                guiDialogBlockEntityTextInput.TryClose();
            }
            GuiDialogBlockEntityTextInput guiDialogBlockEntityTextInput2 = this.textdialog;
            if (guiDialogBlockEntityTextInput2 == null)
            {
                return;
            }
            guiDialogBlockEntityTextInput2.Dispose();
        }

        private string text = "";

        private FTTrunkLabelRenderer trunklabelrenderer;

        private int color;

        private int tempColor;

        private ItemStack tempStack;

        private GuiDialogBlockEntityTextInput textdialog;

        private MeshData ownMesh;
    }
}

 

 

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.