Fix problems with combining spell modifiers
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package electroblob.wizardry.util;
|
package electroblob.wizardry.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import electroblob.wizardry.event.SpellCastEvent;
|
import electroblob.wizardry.event.SpellCastEvent;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
@@ -77,13 +78,11 @@ public final class SpellModifiers {
|
|||||||
* @return The SpellModifiers object, allowing this method to be chained onto the constructor.
|
* @return The SpellModifiers object, allowing this method to be chained onto the constructor.
|
||||||
*/
|
*/
|
||||||
public SpellModifiers combine(SpellModifiers modifiers){
|
public SpellModifiers combine(SpellModifiers modifiers){
|
||||||
for(Entry<String, Float> entry : multiplierMap.entrySet()){
|
for(String key : Sets.union(this.multiplierMap.keySet(), modifiers.multiplierMap.keySet())){
|
||||||
float newValue = entry.getValue() * modifiers.get(entry.getKey());
|
float newValue = this.get(key) * modifiers.get(key);
|
||||||
entry.setValue(newValue);
|
|
||||||
// Also need to update the synced map if the modifier is synced in either object
|
// Also need to update the synced map if the modifier is synced in either object
|
||||||
if(this.syncedMultiplierMap.containsKey(entry.getKey()) || modifiers.syncedMultiplierMap.containsKey(entry.getKey())){
|
boolean sync = this.syncedMultiplierMap.containsKey(key) || modifiers.syncedMultiplierMap.containsKey(key);
|
||||||
this.syncedMultiplierMap.put(entry.getKey(), newValue);
|
this.set(key, newValue, sync);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user