Charging Station fixes, dust, and 2 patreon names
This commit is contained in:
5 files changed
+68
-42
No files matched your search
@@ -147,6 +147,9 @@ namespace CalamityMod
|
||||
if (Main.netMode != NetmodeID.MultiplayerClient)
|
||||
NPC.NewNPC(x, y, ModContent.NPCType<SuperDummyNPC>());
|
||||
break;
|
||||
|
||||
|
||||
// Ozzatron's packets
|
||||
case CalamityModMessageType.PowerCellFactory:
|
||||
TEPowerCellFactory.ReadSyncPacket(reader);
|
||||
break;
|
||||
@@ -156,6 +159,8 @@ namespace CalamityMod
|
||||
case CalamityModMessageType.ChargingStationItemChange:
|
||||
TEChargingStation.ReadItemSyncPacket(reader);
|
||||
break;
|
||||
|
||||
|
||||
case CalamityModMessageType.DraedonFieldGeneratorSync:
|
||||
int entityID2 = reader.ReadInt32();
|
||||
(TileEntity.ByID[entityID2] as TEDraedonFieldGenerator).Time = reader.ReadInt32();
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace CalamityMod.NPCs
|
||||
{
|
||||
"Rythmi",
|
||||
"Izuna",
|
||||
"Jasmine", // <@!430532867479699456> (phantasmagoria#6777)
|
||||
};
|
||||
private const int DyeTraderVanillaNames = 16;
|
||||
private static readonly string[] DyeTraderNames = null;
|
||||
@@ -73,6 +74,7 @@ namespace CalamityMod.NPCs
|
||||
{
|
||||
"Lilly",
|
||||
"Daawn", // <@!206162323541458944> (Daawnily#3859)
|
||||
"Robin", // <@!654737510030639112> (Altzeus#8687)
|
||||
};
|
||||
private const int MerchantVanillaNames = 23;
|
||||
private static readonly string[] MerchantNames = null;
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace CalamityMod.TileEntities
|
||||
}
|
||||
public Item PluggedItem = new Item();
|
||||
private bool syncItemCharge = false;
|
||||
public bool ClientChargingDust = false;
|
||||
|
||||
// This returns whether the charging station's inserted ("plugged") item can actually be charged.
|
||||
private bool PluggedItemCanCharge
|
||||
@@ -40,7 +41,7 @@ namespace CalamityMod.TileEntities
|
||||
return modItem.UsesCharge && modItem.Charge < modItem.MaxCharge;
|
||||
}
|
||||
}
|
||||
private bool CanDoWork => _stack > 0 && PluggedItemCanCharge;
|
||||
public bool CanDoWork => _stack > 0 && PluggedItemCanCharge;
|
||||
|
||||
// Red when not actively charging an item, green when charging
|
||||
public Color LightColor => CanDoWork ? Color.MediumSpringGreen : Color.Red;
|
||||
@@ -69,12 +70,9 @@ namespace CalamityMod.TileEntities
|
||||
CalamityGlobalItem modItem = PluggedItem.Calamity();
|
||||
modItem.Charge += PowerCell.ChargeValue;
|
||||
if (modItem.Charge >= modItem.MaxCharge)
|
||||
{
|
||||
modItem.Charge = modItem.MaxCharge;
|
||||
SpawnChargingDust(true);
|
||||
}
|
||||
else
|
||||
SpawnChargingDust(false);
|
||||
|
||||
SpawnChargingDust();
|
||||
|
||||
// Set the flag for syncing the plugged item's charge as well.
|
||||
syncItemCharge = true;
|
||||
@@ -85,9 +83,16 @@ namespace CalamityMod.TileEntities
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnChargingDust(bool chargeComplete)
|
||||
public void SpawnChargingDust()
|
||||
{
|
||||
int dustID = 182; // 60
|
||||
bool chargeComplete = false;
|
||||
if (!PluggedItem.IsAir)
|
||||
{
|
||||
CalamityGlobalItem modItem = PluggedItem.Calamity();
|
||||
chargeComplete = modItem.Charge == modItem.MaxCharge;
|
||||
}
|
||||
|
||||
int dustID = 182; // Mechanical Cart laser dust. Looks epic.
|
||||
int numDust = 18;
|
||||
if (chargeComplete)
|
||||
numDust *= 3;
|
||||
@@ -189,14 +194,14 @@ namespace CalamityMod.TileEntities
|
||||
{
|
||||
writer.Write(ChargingTimer);
|
||||
writer.Write(_stack);
|
||||
writer.WriteItem(PluggedItem, true, false);
|
||||
writer.WriteItem(PluggedItem, true);
|
||||
}
|
||||
|
||||
public override void NetReceive(BinaryReader reader, bool lightReceive)
|
||||
{
|
||||
ChargingTimer = reader.ReadInt16();
|
||||
_stack = reader.ReadInt16();
|
||||
PluggedItem = reader.ReadItem();
|
||||
PluggedItem = reader.ReadItem(true);
|
||||
}
|
||||
|
||||
// This packet may or may not contain the plugged item's charge value. If it doesn't, it contains a dummy value (NaN) instead.
|
||||
@@ -242,7 +247,11 @@ namespace CalamityMod.TileEntities
|
||||
{
|
||||
CalamityGlobalItem modItem = charger.PluggedItem?.Calamity() ?? null;
|
||||
if (modItem != null && modItem.UsesCharge)
|
||||
{
|
||||
if (modItem.Charge != chargeOrNaN && Main.netMode == NetmodeID.MultiplayerClient)
|
||||
charger.ClientChargingDust = true;
|
||||
modItem.Charge = chargeOrNaN;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,27 +5,45 @@ using Terraria.ModLoader;
|
||||
|
||||
namespace CalamityMod.TileEntities
|
||||
{
|
||||
public static class TileEntityTimeHandler
|
||||
{
|
||||
public static void Update()
|
||||
{
|
||||
// Specifically on multiplayer clients, manually update the time variables of Power Cell Factories every frame.
|
||||
// This makes sure they animate. It will NOT produce cells; that code can only run server side.
|
||||
// Time is manually synced from the server every time a cell is created, so even under heavy lag they cannot stay desynced indefinitely.
|
||||
if (Main.netMode == NetmodeID.MultiplayerClient)
|
||||
{
|
||||
byte factoryType = ModContent.GetInstance<TEPowerCellFactory>().type;
|
||||
var enumerator = TileEntity.ByID.Values.GetEnumerator();
|
||||
do
|
||||
{
|
||||
TileEntity te = enumerator.Current;
|
||||
if (te != null && te.type == factoryType)
|
||||
{
|
||||
TEPowerCellFactory factory = (TEPowerCellFactory)te;
|
||||
++factory.Time;
|
||||
}
|
||||
} while (enumerator.MoveNext());
|
||||
}
|
||||
}
|
||||
}
|
||||
public static class TileEntityTimeHandler
|
||||
{
|
||||
public static void Update()
|
||||
{
|
||||
MultiplayerClientUpdateVisuals();
|
||||
}
|
||||
private static void MultiplayerClientUpdateVisuals()
|
||||
{
|
||||
if (Main.netMode != NetmodeID.MultiplayerClient)
|
||||
return;
|
||||
|
||||
byte factoryType = ModContent.GetInstance<TEPowerCellFactory>().type;
|
||||
byte chargerType = ModContent.GetInstance<TEChargingStation>().type;
|
||||
|
||||
var enumerator = TileEntity.ByID.Values.GetEnumerator();
|
||||
do
|
||||
{
|
||||
TileEntity te = enumerator.Current;
|
||||
if (te != null && te.type == factoryType)
|
||||
{
|
||||
// Specifically on multiplayer clients, manually update the time variables of Power Cell Factories every frame.
|
||||
// This makes sure they animate. It will NOT produce cells; that code can only run server side.
|
||||
// Time is manually synced from the server every time a cell is created, so even under heavy lag they cannot stay desynced indefinitely.
|
||||
TEPowerCellFactory factory = (TEPowerCellFactory)te;
|
||||
++factory.Time;
|
||||
}
|
||||
if (te != null && te.type == chargerType)
|
||||
{
|
||||
// Specifically on multiplayer clients, produce charging dust when the "should dust" flag is set by the most recent sync packet.
|
||||
// This makes sure they produce charging dust for all clients. It will NOT actually charge items; that code can only run server side.
|
||||
TEChargingStation charger = (TEChargingStation)te;
|
||||
|
||||
if (charger.ClientChargingDust && charger.CanDoWork)
|
||||
{
|
||||
charger.ClientChargingDust = false;
|
||||
charger.SpawnChargingDust();
|
||||
}
|
||||
}
|
||||
} while (enumerator.MoveNext());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,15 +82,7 @@ namespace CalamityMod.UI
|
||||
if (mouseRect.Intersects(pluggedSlotRect))
|
||||
{
|
||||
if (!pluggedItem.IsAir)
|
||||
{
|
||||
// The charge variables are contained in CalamityGlobalItem so they must be set manually. SetDefaults won't cover it.
|
||||
// Not sure if this line is necessary.
|
||||
// Main.HoverItem = new Item();
|
||||
Main.HoverItem.SetDefaults(pluggedItem.type);
|
||||
CalamityGlobalItem calHoverItem = Main.HoverItem.Calamity(), calPlugged = pluggedItem.Calamity();
|
||||
calHoverItem.Charge = calPlugged.Charge;
|
||||
calHoverItem.MaxCharge = calPlugged.MaxCharge;
|
||||
}
|
||||
Main.HoverItem = pluggedItem;
|
||||
|
||||
if (Main.mouseLeft && Main.mouseLeftRelease)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user