public override void Click(Entity entity, ItemStack item) { // TODO: Should non-players be allowed here? if (!(entity is PlayerEntity)) { return; } PlayerEntity player = (PlayerEntity)entity; // TODO: Generic 'player.gettargetblock'? Location eye = player.GetEyePosition(); Location forw = player.ForwardVector(); RayCastResult rcr; bool h = player.TheRegion.SpecialCaseRayTrace(eye, forw, 5, MaterialSolidity.ANY, player.IgnoreThis, out rcr); if (h) { if (rcr.HitObject != null && rcr.HitObject is EntityCollidable && ((EntityCollidable)rcr.HitObject).Entity != null) { // TODO: ??? } else if (player.TheRegion.GlobalTickTime - player.LastBlockBreak >= 0.2) { Location block = new Location(rcr.HitData.Location) - new Location(rcr.HitData.Normal).Normalize() * 0.01; Material mat = player.TheRegion.GetBlockMaterial(block); if (mat != Material.AIR) { try { Structure structure = new Structure(player.TheRegion, block, 20); // TODO: 20 -> Item Attribute? int c = 0; while (entity.TheServer.Files.Exists("structures/" + item.SecondaryName + c + ".str")) { c++; } entity.TheServer.Files.WriteBytes("structures/" + item.SecondaryName + c + ".str", structure.ToBytes()); player.SendMessage(TextChannel.COMMAND_RESPONSE, "^2Saved structure as " + item.SecondaryName + c); // TODO: Click sound! player.LastBlockBreak = player.TheRegion.GlobalTickTime; } catch (Exception ex) { Utilities.CheckException(ex); player.SendMessage(TextChannel.COMMAND_RESPONSE, "^1Failed to create structure: " + ex.Message); } } } } }
public override void Click(Entity entity, ItemStack item) { // TODO: Should non-players be allowed here? if (!(entity is PlayerEntity)) { return; } PlayerEntity player = (PlayerEntity)entity; if (player.TheRegion.GlobalTickTime - player.LastBlockBreak < 0.2) { return; } // TODO: Generic 'player.gettargetblock'? Location eye = player.GetEyePosition(); Location forw = player.ForwardVector(); RayCastResult rcr; bool h = player.TheRegion.SpecialCaseRayTrace(eye, forw, player.PastingDist, MaterialSolidity.ANY, player.IgnoreThis, out rcr); Location pasteloc = (eye + forw * player.PastingDist + player.Pasting.rotOffs).GetBlockLocation(); if (h) { if (rcr.HitObject != null && rcr.HitObject is EntityCollidable && ((EntityCollidable)rcr.HitObject).Entity != null) { // TODO: ??? } else { Location block = (new Location(rcr.HitData.Location) - new Location(rcr.HitData.Normal).Normalize() * 0.01).GetBlockLocation(); Material mat = player.TheRegion.GetBlockMaterial(block); if (mat != Material.AIR) { pasteloc = block + (player.Pasting != null ? player.Pasting.rotOffs : Location.Zero); } } } try { if (!entity.TheServer.Files.Exists("structures/" + item.SecondaryName + ".str")) // TODO: structure helper engine { throw new Exception("File does not exist!"); // TODO: Handle better. } Structure structure = new Structure(entity.TheServer.Files.ReadBytes("structures/" + item.SecondaryName + ".str")); int ang = (player.Pasting != null ? player.Pasting.Angle : 0); structure.Paste(player.TheRegion, pasteloc, ang); player.SendMessage(TextChannel.COMMAND_RESPONSE, "^2Pasted structure at " + pasteloc + ", with offset of " + structure.Origin.X + "," + structure.Origin.Y + "," + structure.Origin.Z + " at angle " + ang); // TODO: Pasting sound of some form! And particles! player.LastBlockBreak = player.TheRegion.GlobalTickTime; } catch (Exception ex) { Utilities.CheckException(ex); player.SendMessage(TextChannel.COMMAND_RESPONSE, "^1Failed to paste structure: " + ex.Message); } }
// TODO: Should non-players be allowed here? public void Copy(PlayerEntity player, ItemStack item) { try { Structure structure = new Structure(player.TheRegion, player.Selection.Min, player.Selection.Max, player.GetPosition().GetBlockLocation()); int c = 0; while (player.TheServer.Files.Exists("structures/" + item.SecondaryName + c + ".str")) { c++; } player.TheServer.Files.WriteBytes("structures/" + item.SecondaryName + c + ".str", structure.ToBytes()); player.SendMessage(TextChannel.DEBUG_INFO, "^2Saved structure as " + item.SecondaryName + c); // TODO: Click sound! player.LastBlockBreak = player.TheRegion.GlobalTickTime; } catch (Exception ex) { Utilities.CheckException(ex); player.SendMessage(TextChannel.DEBUG_INFO, "^1Failed to create structure: " + ex.Message); } }
public override void SwitchTo(Entity entity, ItemStack item) { // TODO: Should non-players be allowed here? if (!(entity is PlayerEntity)) { return; } PlayerEntity player = (PlayerEntity)entity; if (player.Pasting != null) { player.Pasting.RemoveMe(); player.Pasting = null; } player.PastingDist = 5; if (!entity.TheServer.Files.Exists("structures/" + item.SecondaryName + ".str")) // TODO: structure helper engine { throw new Exception("File does not exist!"); // TODO: Handle better. } Structure structure = new Structure(entity.TheServer.Files.ReadBytes("structures/" + item.SecondaryName + ".str")); player.Pasting = structure.ToBGE(player.TheRegion, player.GetPosition()); player.TheRegion.SpawnEntity(player.Pasting); }