public static void Postfix(ChiselBlockModelCache __instance, ItemStack forStack, ref ICoreClientAPI ___capi, ref MeshRef __result) { int?setMesh = forStack.Attributes.TryGetInt("chiselplusmesh"); if (setMesh != null && setMesh != (int)EnumChiselPlusMesh.none) { Vec3f rot = new Vec3f() { X = forStack.Attributes.TryGetFloat("chiselplusRotX") ?? 0.0f, Y = forStack.Attributes.TryGetFloat("chiselplusRotY") ?? 0.0f, Z = forStack.Attributes.TryGetFloat("chiselplusRotZ") ?? 0.0f }; string name = Enum.GetName(typeof(EnumChiselPlusMesh), setMesh); IntArrayAttribute materials = forStack.Attributes["materials"] as IntArrayAttribute; if (name == null || materials == null) { return; } string code = string.Format("chiselplus:genericblocks-{0}", name); ___capi.Tesselator.TesselateBlock(___capi.World.BlockAccessor.GetBlock(new AssetLocation(code)), out MeshData mesh); TextureSource texSource = new TextureSource(___capi.World as ClientMain, ___capi.BlockTextureAtlas.Size, ___capi.World.BlockAccessor.GetBlock(materials.value.FirstOrDefault())); Dictionary <string, int> textureCodeToIdMapping = texSource.GetField <Dictionary <string, int> >("textureCodeToIdMapping"); mesh.SetTexPos(texSource[textureCodeToIdMapping.FirstOrDefault().Key]); mesh.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), GameMath.DEG2RAD * rot.X, GameMath.DEG2RAD * rot.Y, GameMath.DEG2RAD * rot.Z); __result = ___capi.Render.UploadMesh(mesh); } }
public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling) { if (blockSel?.BlockEntity(api) is BlockEntityChisel) { handling = EnumHandHandling.PreventDefault; BlockEntityChisel entityChisel = ((BlockEntityChisel)blockSel.BlockEntity(api)); ITreeAttribute blueprintTree = slot?.Itemstack?.Attributes; ITreeAttribute dummy = blueprintTree.Clone(); entityChisel.ToTreeAttributes(dummy); blueprintTree["materials"] = dummy["materials"]; if (byEntity.Controls.Sneak) { blueprintTree["cuboids"] = new IntArrayAttribute(); entityChisel.ToTreeAttributes(blueprintTree); slot.MarkDirty(); } else if (blueprintTree["cuboids"] != null) { entityChisel.FromTreeAtributes(blueprintTree, api.World); } if (api.Side.IsClient()) { entityChisel.RegenMesh(); } } base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); tree["materials"] = new IntArrayAttribute(Materials); tree["cuboids"] = new IntArrayAttribute(VoxelCuboids.ToArray()); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); ITreeAttribute invtree = new TreeAttribute(); Inventory.ToTreeAttributes(invtree); tree["inventory"] = invtree; tree.SetFloat("inputGrindTime", inputGrindTime); tree.SetInt("nowOutputFace", nowOutputFace); List <int> vals = new List <int>(); foreach (var val in playersGrinding) { IPlayer plr = Api.World.PlayerByUid(val.Key); if (plr == null) { continue; } vals.Add(plr.ClientId); } tree["clientIdsGrinding"] = new IntArrayAttribute(vals.ToArray()); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); IntArrayAttribute attr = new IntArrayAttribute(); attr.value = MaterialIds; if (attr.value != null) { tree["materials"] = attr; } tree["cuboids"] = new IntArrayAttribute(VoxelCuboids.ToArray()); if (SnowCuboids.Count > 0) { tree["snowcuboids"] = new IntArrayAttribute(SnowCuboids.ToArray()); } if (GroundSnowCuboids.Count > 0) { tree["groundSnowCuboids"] = new IntArrayAttribute(GroundSnowCuboids.ToArray()); } tree.SetBytes("emitSideAo", new byte[] { (byte)((emitSideAo[0] ? 1 : 0) | (emitSideAo[1] ? 2 : 0) | (emitSideAo[2] ? 4 : 0) | (emitSideAo[3] ? 8 : 0) | (emitSideAo[4] ? 16 : 0) | (emitSideAo[5] ? 32 : 0)) }); tree.SetBytes("sideSolid", new byte[] { (byte)((sideSolid[0] ? 1 : 0) | (sideSolid[1] ? 2 : 0) | (sideSolid[2] ? 4 : 0) | (sideSolid[3] ? 8 : 0) | (sideSolid[4] ? 16 : 0) | (sideSolid[5] ? 32 : 0)) }); tree.SetString("blockName", BlockName); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); ITreeAttribute invtree = new TreeAttribute(); Inventory.ToTreeAttributes(invtree); tree["inventory"] = invtree; tree.SetFloat("inputGrindTime", inputGrindTime); tree["clientIdsGrinding"] = new IntArrayAttribute(playersGrinding.Select(p => p.ClientId).ToArray()); }
public override void ToTreeAttributes(ITreeAttribute tree) { base.ToTreeAttributes(tree); StringArrayAttribute attr = new StringArrayAttribute(); string[] materialCodes = new string[MaterialIds.Length]; for (int i = 0; i < MaterialIds.Length; i++) { materialCodes[i] = api.World.Blocks[MaterialIds[i]].Code.ToString(); } attr.value = materialCodes; tree["materials"] = attr; tree["cuboids"] = new IntArrayAttribute(VoxelCuboids.ToArray()); tree.SetString("blockName", blockName); }
public override void OnCreatedByCrafting(ItemSlot[] allInputslots, ItemSlot outputSlot, GridRecipe byRecipe) { List <int> matids = new List <int>(); bool first = false; foreach (var val in allInputslots) { if (val.Empty) { continue; } if (!first) { first = true; outputSlot.Itemstack.Attributes = val.Itemstack.Attributes.Clone(); } int[] mats = (val.Itemstack.Attributes?["materials"] as IntArrayAttribute)?.value; if (mats != null) { matids.AddRange(mats); } string[] smats = (val.Itemstack.Attributes?["materials"] as StringArrayAttribute)?.value; if (smats != null) { foreach (var code in smats) { Block block = api.World.GetBlock(new AssetLocation(code)); if (block != null) { matids.Add(block.Id); } } } } IntArrayAttribute attr = new IntArrayAttribute(matids.ToArray()); outputSlot.Itemstack.Attributes["materials"] = attr; base.OnCreatedByCrafting(allInputslots, outputSlot, byRecipe); }
public void OnTransformed(ITreeAttribute tree, int byDegrees, EnumAxis?aroundAxis) { List <uint> rotatedCuboids = new List <uint>(); VoxelCuboids = new List <uint>((tree["cuboids"] as IntArrayAttribute).AsUint); CuboidWithMaterial cwm = tmpCuboid; foreach (var val in VoxelCuboids) { FromUint(val, cwm); Cuboidi rotated = cwm.Clone(); if (aroundAxis == EnumAxis.X) { rotated.X1 = 16 - rotated.X1; rotated.X2 = 16 - rotated.X2; } if (aroundAxis == EnumAxis.Y) { rotated.Y1 = 16 - rotated.Y1; rotated.Y2 = 16 - rotated.Y2; } if (aroundAxis == EnumAxis.Z) { rotated.Z1 = 16 - rotated.Z1; rotated.Z2 = 16 - rotated.Z2; } rotated = rotated.RotatedCopy(0, byDegrees, 0, new Vec3d(8, 8, 8)); cwm.Set(rotated.X1, rotated.Y1, rotated.Z1, rotated.X2, rotated.Y2, rotated.Z2); rotatedCuboids.Add(ToCuboid(cwm)); } tree["cuboids"] = new IntArrayAttribute(rotatedCuboids.ToArray()); }
protected virtual void ProbeBlockDensityMode(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, BlockSelection blockSel) { IPlayer byPlayer = null; if (byEntity is EntityPlayer) { byPlayer = world.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); } Block block = world.BlockAccessor.GetBlock(blockSel.Position); float dropMul = 1f; if (block.BlockMaterial == EnumBlockMaterial.Ore || block.BlockMaterial == EnumBlockMaterial.Stone) { dropMul = 0; } block.OnBlockBroken(world, blockSel.Position, byPlayer, dropMul); if (!block.Code.Path.StartsWith("rock") && !block.Code.Path.StartsWith("ore")) { return; } IServerPlayer splr = byPlayer as IServerPlayer; if (splr == null) { return; } if (splr.WorldData.CurrentGameMode == EnumGameMode.Creative) { PrintProbeResults(world, splr, itemslot, blockSel.Position); return; } IntArrayAttribute attr = itemslot.Itemstack.Attributes["probePositions"] as IntArrayAttribute; if ((attr == null || attr.value == null || attr.value.Length == 0)) { itemslot.Itemstack.Attributes["probePositions"] = attr = new IntArrayAttribute(); attr.AddInt(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z); splr.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("Ok, need 2 more samples"), EnumChatType.Notification); } else { float requiredSamples = 2; attr.AddInt(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z); int[] vals = attr.value; for (int i = 0; i < vals.Length; i += 3) { int x = vals[i]; int y = vals[i + 1]; int z = vals[i + 2]; float mindist = 99; for (int j = i + 3; j < vals.Length; j += 3) { int dx = x - vals[j]; int dy = y - vals[j + 1]; int dz = z - vals[j + 2]; mindist = Math.Min(mindist, GameMath.Sqrt(dx * dx + dy * dy + dz * dz)); } if (i + 3 < vals.Length) { requiredSamples -= GameMath.Clamp(mindist * mindist, 3, 16) / 16; if (mindist > 20) { splr.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("Sample too far away from initial reading. Sampling around this point now, need 2 more samples."), EnumChatType.Notification); attr.value = new int[] { blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z }; return; } } } if (requiredSamples > 0) { int q = (int)Math.Ceiling(requiredSamples); splr.SendMessage(GlobalConstants.InfoLogChatGroup, q > 1 ? Lang.Get("propick-xsamples", q) : Lang.Get("propick-1sample"), EnumChatType.Notification); } else { int startX = vals[0]; int startY = vals[1]; int startZ = vals[2]; PrintProbeResults(world, splr, itemslot, new BlockPos(startX, startY, startZ)); attr.value = new int[0]; } } }
void ProbeGround(IWorldAccessor world, IEntity byEntity, IItemSlot itemslot, BlockSelection blockSel) { IPlayer byPlayer = null; if (byEntity is IEntityPlayer) { byPlayer = world.PlayerByUid(((IEntityPlayer)byEntity).PlayerUID); } Block block = world.BlockAccessor.GetBlock(blockSel.Position); block.OnBlockBroken(world, blockSel.Position, byPlayer, 0); if (!block.Code.Path.StartsWith("rock") && !block.Code.Path.StartsWith("ore")) { return; } IServerPlayer splr = byPlayer as IServerPlayer; if (splr != null) { IntArrayAttribute attr = itemslot.Itemstack.Attributes["probePositions"] as IntArrayAttribute; if (attr == null || attr.value == null || attr.value.Length == 0) { itemslot.Itemstack.Attributes["probePositions"] = attr = new IntArrayAttribute(); attr.AddInt(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z); splr.SendMessage(GlobalConstants.CurrentChatGroup, "Ok, need 2 more samples", EnumChatType.Notification); } else { float requiredSamples = 2; attr.AddInt(blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z); int[] vals = attr.value; for (int i = 0; i < vals.Length; i += 3) { int x = vals[i]; int z = vals[i + 2]; float mindist = 99; for (int j = i + 3; j < vals.Length; j += 3) { int dx = x - vals[j]; int dz = z - vals[j + 2]; mindist = Math.Min(mindist, GameMath.Sqrt(dx * dx + dz * dz)); } if (i + 3 < vals.Length) { requiredSamples -= GameMath.Clamp(mindist * mindist, 0, 16) / 16; if (mindist > 16) { splr.SendMessage(GlobalConstants.CurrentChatGroup, "Sample too far away from initial reading. Sampling around this point now, need 2 more samples.", EnumChatType.Notification); attr.value = new int[] { blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z }; return; } } } if (requiredSamples > 0) { int q = (int)Math.Ceiling(requiredSamples); splr.SendMessage(GlobalConstants.CurrentChatGroup, "Ok, need " + q + " more " + (q == 1 ? "sample" : "samples"), EnumChatType.Notification); } else { int startX = vals[0]; int startY = vals[1]; int startZ = vals[2]; PrintProbeResults(world, splr, itemslot, new BlockPos(startX, startY, startZ)); attr.value = new int[0]; } } } }