First Machine Age's Mods (Combined repo.)
Revision | 66937a22478d726533179f3517396a0d9893098d (tree) |
---|---|
Zeit | 2022-02-05 09:28:43 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
Mostly functional brazier
Should also decay (untested)
@@ -16,17 +16,24 @@ namespace FirstMachineAge | ||
16 | 16 | { |
17 | 17 | private const string stateKey = @"state"; |
18 | 18 | private const string fuledValue = @"fueled"; |
19 | + private const string extinguishedValue = @"extinguished"; | |
19 | 20 | private const string litValue = @"lit"; |
20 | 21 | private const float ignitionTime = 2f; |
21 | 22 | private const int fuelReqt = 5; |
22 | 23 | private const float fireDmg = 0.5f; |
23 | - private WorldInteraction[ ] interactMustFuel, interactMustIgnight; | |
24 | + private const int fuel_Temp = 999; | |
25 | + private const int fuel_Duration = 30; | |
24 | 26 | |
27 | + private WorldInteraction[ ] interactMustFuel, interactMustIgnight; | |
28 | + private string flameoutPercentKey = @"flameoutPercent"; | |
29 | + private WeatherSystemBase weatherSys; | |
25 | 30 | |
26 | 31 | public override void OnLoaded(ICoreAPI api) |
27 | 32 | { |
28 | 33 | base.OnLoaded(api); |
29 | 34 | |
35 | + weatherSys = api.ModLoader.GetModSystem<WeatherSystemBase>( ); | |
36 | + | |
30 | 37 | if (api.Side.IsClient( )) |
31 | 38 | { |
32 | 39 | var clientAPI = api as ICoreClientAPI; |
@@ -35,7 +42,7 @@ namespace FirstMachineAge | ||
35 | 42 | List<ItemStack> ignitionSources = new List<ItemStack>(); |
36 | 43 | |
37 | 44 | foreach (CollectibleObject obj in api.World.Collectibles) { |
38 | - if (obj.CombustibleProps?.BurnTemperature >= 999 && obj.CombustibleProps?.BurnDuration >= 30) | |
45 | + if (obj.CombustibleProps?.BurnTemperature >= fuel_Temp && obj.CombustibleProps?.BurnDuration >= fuel_Duration) | |
39 | 46 | { |
40 | 47 | List<ItemStack> stacks = obj.GetHandBookStacks(clientAPI); |
41 | 48 | if (stacks != null) solidFuels.AddRange(stacks); |
@@ -81,6 +88,13 @@ namespace FirstMachineAge | ||
81 | 88 | } |
82 | 89 | } |
83 | 90 | |
91 | + public float FlameoutPercent { | |
92 | + get | |
93 | + { | |
94 | + return this.Attributes[flameoutPercentKey].AsFloat(0.01f); | |
95 | + } | |
96 | + } | |
97 | + | |
84 | 98 | public override EnumIgniteState OnTryIgniteBlock(EntityAgent byEntity, BlockPos pos, float secondsIgniting) |
85 | 99 | { |
86 | 100 | if (Fueled) |
@@ -113,7 +127,7 @@ namespace FirstMachineAge | ||
113 | 127 | if ((!Fueled && !Lit) |
114 | 128 | && hbItemStack != null |
115 | 129 | && hbItemStack.Class == EnumItemClass.Item |
116 | - && hbItemStack.Item?.CombustibleProps.BurnTemperature >= 999 && hbItemStack.Item?.CombustibleProps.BurnDuration >= 30) | |
130 | + && hbItemStack.Item?.CombustibleProps.BurnTemperature >= fuel_Temp && hbItemStack.Item?.CombustibleProps.BurnDuration >= fuel_Duration) | |
117 | 131 | { |
118 | 132 | if (byPlayer != null && byPlayer.WorldData.CurrentGameMode == EnumGameMode.Survival) { |
119 | 133 | if (byPlayer.InventoryManager.ActiveHotbarSlot.StackSize >= fuelReqt) { |
@@ -151,8 +165,8 @@ namespace FirstMachineAge | ||
151 | 165 | { |
152 | 166 | if (entity is EntityAgent && entity.Alive) |
153 | 167 | { |
154 | - entity.ReceiveDamage(new DamageSource( ) { Source = EnumDamageSource.Block, SourceBlock = this, Type = EnumDamageType.Fire, SourcePos = pos.ToVec3d( ) }, fireDmg); | |
155 | - | |
168 | + entity.ReceiveDamage(new DamageSource( ) { Source = EnumDamageSource.Block, SourceBlock = this, Type = EnumDamageType.Fire, SourcePos = pos.ToVec3d( ), DamageTier = 5, KnockbackStrength = 0.25f }, fireDmg); | |
169 | + if (Sounds?.Inside != null) world.PlaySoundAt(Sounds.Inside, entity.Pos.X, entity.Pos.Y, entity.Pos.Z); | |
156 | 170 | } |
157 | 171 | } |
158 | 172 | } |
@@ -171,6 +185,38 @@ namespace FirstMachineAge | ||
171 | 185 | return null;//Must be burning |
172 | 186 | } |
173 | 187 | |
188 | + | |
189 | + public override bool ShouldReceiveServerGameTicks(IWorldAccessor world, BlockPos pos, Random offThreadRandom, out object extra) | |
190 | + { | |
191 | + extra = null; | |
192 | + | |
193 | + if (Lit) { | |
194 | + var rainLevel = world.BlockAccessor.GetRainMapHeightAt(pos); | |
195 | + if (pos.Y >= rainLevel) { //Brr, its Wet out here! | |
196 | + var rainPos = new BlockPos(pos.X, rainLevel, pos.Z); | |
197 | + var precip = weatherSys.GetPrecipitation(pos.ToVec3d()); | |
198 | + | |
199 | + if (precip >= 0.4) { return true; } | |
200 | + if (offThreadRandom.NextDouble( ) <= (FlameoutPercent * 10) ) { return true; } | |
201 | + } | |
202 | + else if (offThreadRandom.NextDouble( ) <= FlameoutPercent){ return true; } | |
203 | + } | |
204 | + | |
205 | + return false; | |
206 | + } | |
207 | + | |
208 | + public override void OnServerGameTick(IWorldAccessor world, BlockPos pos, object extra = null) | |
209 | + { | |
210 | + if (Lit) { | |
211 | + #if DEBUG | |
212 | + api.Logger.VerboseDebug("Got server-game tick for flameout! @ {0}", pos); | |
213 | + #endif | |
214 | + | |
215 | + Block extinctBlock = world.GetBlock(CodeWithVariant(stateKey, extinguishedValue)); | |
216 | + world.BlockAccessor.ExchangeBlock(extinctBlock.BlockId, pos); | |
217 | + world.BlockAccessor.MarkBlockDirty(pos); | |
218 | + } | |
219 | + } | |
174 | 220 | } |
175 | 221 | } |
176 | 222 |
@@ -3,7 +3,7 @@ | ||
3 | 3 | class: "RectangularBrazier", |
4 | 4 | maxstacksize: 1, |
5 | 5 | variantgroups: [ |
6 | - { code: "state", states: ["empty","fueled","lit","extinct"] } | |
6 | + { code: "state", states: ["empty","fueled","lit","extinguished"] } | |
7 | 7 | ], |
8 | 8 | behaviorsByType: { |
9 | 9 | "*-lit": [{ name: "HeatSource", properties: { heatStrength: 8 } }], |
@@ -24,7 +24,7 @@ | ||
24 | 24 | base: "block/metal/brazier2", SelectiveElements:["Base/Leg*","Base/Grille1","Base/Embers"], |
25 | 25 | |
26 | 26 | }, |
27 | - "*-extinct": { | |
27 | + "*-extinguished": { | |
28 | 28 | base: "block/metal/brazier2", SelectiveElements:["Base/Leg*","Base/Grille1","Base/Ash/Lump*"], |
29 | 29 | |
30 | 30 | }, |
@@ -36,12 +36,8 @@ | ||
36 | 36 | "coal": { base: "game:block/coal/charcoal"}, |
37 | 37 | "rusty-iron": { base: "game:block/currency/rusty-iron"}, |
38 | 38 | }, |
39 | - attributes: { | |
40 | - transientProps: { | |
41 | - convertFrom: "brazier-lit", | |
42 | - convertTo: "brazier-extinct", | |
43 | - inGameHours: "100", | |
44 | - } | |
39 | + attributes: { | |
40 | + flameoutPercent: 0.001, | |
45 | 41 | }, |
46 | 42 | creativeinventory: { "decorative": ["brazier-empty"] , "defensive": ["brazier-empty"] }, |
47 | 43 | blockmaterial: "Metal", |
@@ -56,8 +52,8 @@ | ||
56 | 52 | particlePropertiesByType: { |
57 | 53 | "*-lit": [ |
58 | 54 | { |
59 | - hsvaColor: [{ avg: 50, var: 10 }, { avg: 255, var: 0 }, { avg: 200, var: 10 }, { avg: 250, var: 0 }], | |
60 | - posOffset: [{ avg: 0.55, var: 0.06 },{ avg: 0.65, var: -0.9 },{ avg: 0.0, var: -0.35 }], | |
55 | + hsvaColor: [{ avg: 34, var: 10 }, { avg: 255, var: 0 }, { avg: 240, var: 10 }, { avg: 200, var: 50 }], | |
56 | + posOffset: [{ avg: 0.1, var: 0.5 },{ avg: -0.2, var: 0.0 },{ avg: 0.1, var: 0.25 }], | |
61 | 57 | velocity: [{ avg: 0.1, var: 0.5 },{ avg: 0.1, var: -0.1 },{ avg: -0.2, var: -0.1 }], |
62 | 58 | opacityEvolve: { transform: "linear", factor: -90 }, |
63 | 59 | gravityEffect: { avg: -0.02, var: 0.0 }, |
@@ -76,7 +72,8 @@ | ||
76 | 72 | "place": "game:block/anvil", |
77 | 73 | "break": "game:block/anvil", |
78 | 74 | "hit": "game:block/anvil", |
79 | - ambientByType: { "*-lit": "game:effect/embers" } | |
75 | + ambientByType: { "*-lit": "game:effect/embers" }, | |
76 | + insideByType: { "*-lit": "game:effect/extinguish1" }, | |
80 | 77 | }, |
81 | 78 | drops: [ |
82 | 79 | { type: "block", code: "brazier-empty", quantity: { avg: 1 } } |
@@ -26,7 +26,7 @@ | ||
26 | 26 | "defensive:blockdesc-log_barricade-*":"A rough barrier fit for the Frontier.", |
27 | 27 | "defensive:blockdesc-crusie_lamp-*":"Burn that midnight fuel faster.", |
28 | 28 | "defensive:blockdesc-brazier-empty":"Needs fuel...", |
29 | - "defensive:blockdesc-brazier-extinct":"Needs fuel again...", | |
29 | + "defensive:blockdesc-brazier-extinguished":"Needs fuel again...", | |
30 | 30 | "defensive:blockdesc-brazier-lit":"What a lovely warm glow.", |
31 | 31 | |
32 | 32 | "game:tabname-defensive":"Defensive Stuff", |