Skip to content

Instantly share code, notes, and snippets.

@Cyken-Zeraux
Created December 15, 2016 15:58
Show Gist options
  • Save Cyken-Zeraux/0c8c8ffeebf5da5bc432f830d4c2128a to your computer and use it in GitHub Desktop.
Save Cyken-Zeraux/0c8c8ffeebf5da5bc432f830d4c2128a to your computer and use it in GitHub Desktop.
using Sandbox.ModAPI;
using VRage.ModAPI;
using VRage.Game.Components;
using VRage.Game;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Definitions;
using Sandbox.Game.Entities;
using Sandbox.ModAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VRage;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRageMath;
using VRage.Voxels;
using System.Collections.Generic;
using VRage.Game.Components;
using Sandbox.Definitions;
using VRage.ObjectBuilders;
using VRage;
using VRage.Game.Entity;
using Sandbox.Common.ObjectBuilders;
using Sandbox.ModAPI;
using Sandbox.Game.Entities;
using VRage.Game.ModAPI;
using VRage.Game;
using Sandbox.ModAPI.Interfaces;
using VRage.Game.ModAPI.Interfaces;
using Sandbox.Game.Components;
using Sandbox.Game.Gui;
using Sandbox.Game.Entities.Character;
using Sandbox.Game.Entities.Cube;
using Sandbox.ModAPI.Interfaces.Terminal;
using Sandbox.Game.Localization;
using Sandbox.Game.Multiplayer;
using SpaceEngineers.Game.ModAPI;
using Sandbox.Game.World;
using Sandbox.Graphics.GUI;
using System;
using System.Diagnostics;
using System.Text;
using Sandbox.Game.EntityComponents;
using VRageMath;
using VRage.Utils;
using VRage.Game.Entity.UseObject;
using VRage.ModAPI;
using VRage.Library.Utils;
using VRage.Game.GUI.TextPanel;
using VRage.Network;
using Sandbox.Engine.Multiplayer;
using VRage.Sync;
namespace czaux.noshrapnel100
{
[MySessionComponentDescriptor(MyUpdateOrder.BeforeSimulation)]
public class NoShrapnel : MySessionComponentBase
{
public static bool m_init { get; private set; }
//Our hash for the "Scrap" subtype
public static MyStringHash m_scraphash = MyStringHash.GetOrCompute("Scrap");
public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
{
}
public void init()
{
m_init = true;
//Only on the server
//if(MyAPIGateway.Multiplayer.IsServer)
//{
//Bind function to the 'OnEntityAdd' session event.
MyAPIGateway.Entities.OnEntityAdd += Entities_OnEntityAdd;
//}
}
//Do our actual removal.
void Entities_OnEntityAdd(IMyEntity entity)
{
IMyFloatingObject floaty = entity as IMyFloatingObject;
if(floaty != null)
{
var objectbuild = floaty.GetObjectBuilder();
if(objectbuild != null)
{
var subtype = objectbuild.SubtypeId;
if(subtype != null)
{
if(subtype.Equals(m_scraphash))
{
MyLog.Default.WriteLine("Deleted shrapnel");
if (MyAPIGateway.Multiplayer.IsServer)
{
entity.Close();
}
}
}
}
}
//Won't actually get this. Dunno why.
//MyPhysicalItemDefinition PhysicalItem = entity as MyPhysicalItemDefinition;
/*
if (PhysicalItem != null)
{
MyLog.Default.WriteLine("GotPhysical");
MyStringHash? subtype = PhysicalItem.Id.SubtypeId;
if(subtype != null)
{
if (m_scraphash.Equals(PhysicalItem?.Id.SubtypeId))
{
MyAPIGateway.Utilities.SendMessage("Deleted shrapnel");
if (MyAPIGateway.Multiplayer.IsServer)
{
entity.Close();
}
}
}
}
*/
}
public override void UpdateBeforeSimulation()
{
//We execute this as a 'one-shot', because the topmost
//Init doesn't have the information for MyAPIGateway
if (!m_init)
{
init();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment