Skip to content

Commit

Permalink
Fixed bug in evaluation, and potential crash hidden by bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigereye504 committed Sep 27, 2020
1 parent 4e00ccd commit dd990ec
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.9.3+build.207

# Mod Properties
mod_version = 1.2.2
mod_version = 1.2.3
maven_group = net.tigereye.chestcavity
archives_base_name = chestcavity

Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/tigereye/chestcavity/ChestCavity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

public class ChestCavity implements ModInitializer {
public static final String MODID = "chestcavity";
public static final boolean DEBUG_MODE = false;

//public static final ComponentKey<InventoryComponent> INVENTORY_COMPONENT = ComponentRegistry.INSTANCE.registerStatic(new Identifier("chestcavity","inventory_component"), InventoryComponent.class);
public static final ComponentType<InventoryComponent> INVENTORYCOMPONENT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public void setEntity(PlayerEntity player){

public void initCCListener()
{
System.out.println("Initializing Chest Cavity Listener!");
if(CCListener == null)
{
System.out.println("Initializing Chest Cavity Listener!");
CCListener = new ChestCavityListener(owner);
inventory.addListener(CCListener);
CCListener.EvaluateChestCavity(inventory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.tigereye.chestcavity.ChestCavity;
import net.tigereye.chestcavity.items.ChestCavityOrgan;
import net.tigereye.chestcavity.items.CCItems;
import net.tigereye.chestcavity.items.VanillaOrgans;
Expand Down Expand Up @@ -61,13 +62,14 @@ public boolean EvaluateChestCavity(Inventory inv)
}
}
}

organScores.forEach((key,value) ->
System.out.print(key.toString()+": "+value+" "));
System.out.print("\n");

if(oldScores.equals(organScores))
if(!oldScores.equals(organScores))
{
if(ChestCavity.DEBUG_MODE) {
System.out.println("Displaying organ scores:");
organScores.forEach((key, value) ->
System.out.print(key.toString() + ": " + value + " "));
System.out.print("\n");
}
OrganUpdateCallback.EVENT.invoker().onOrganUpdate(player, oldScores, organScores);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public static void TickLiver(PlayerEntity player,ChestCavityListener chestCavity
for(Map.Entry<StatusEffect,StatusEffectInstance> iter : player.getActiveStatusEffects().entrySet()){
if (((CCStatusEffect)iter.getValue().getEffectType()).CC_IsHarmful()) {
newDur = Math.max(0, iter.getValue().getDuration() + Math.round(LIVER_SPEED * (1 - liverScore) / 2));
System.out.println("updating status effect: old duration "+iter.getValue().getDuration()+", new duration "+newDur+".");
((CCStatusEffectInstance) iter.getValue()).CC_setDuration(newDur);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public static void register(){
private static void UpdateHeart(PlayerEntity player, Map<Identifier, Float> oldScores, Map<Identifier, Float> newScores) {
//Update Max Health Modifier
if(oldScores.getOrDefault(CCItems.ORGANS_HEART,0f) != newScores.getOrDefault(CCItems.ORGANS_HEART,0f)){
EntityAttributeInstance att = player.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH);
EntityAttributeInstance att;
try {
att = player.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH);
}
catch(NullPointerException e){
return;
}
EntityAttributeModifier mod = new EntityAttributeModifier(heartID, "ChestCavityHeartMaxHP",
(newScores.getOrDefault(CCItems.ORGANS_HEART,0f)*6)-6, EntityAttributeModifier.Operation.ADDITION);
ReplaceAttributeModifier(att,mod);
Expand All @@ -35,13 +41,19 @@ private static void UpdateHeart(PlayerEntity player, Map<Identifier, Float> oldS

private static void UpdateMuscle(PlayerEntity player, Map<Identifier, Float> oldScores, Map<Identifier, Float> newScores) {
if(oldScores.getOrDefault(CCItems.ORGANS_MUSCLE,0f) != newScores.getOrDefault(CCItems.ORGANS_MUSCLE,0f)) {
//Update Damage Modifier
EntityAttributeInstance att = player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE);
//Update Damage Modifier and Speed Modifier
EntityAttributeInstance att;
EntityAttributeInstance att2;
try {
att = player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE);
att2 = player.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED);
}
catch(NullPointerException e){
return;
}
EntityAttributeModifier mod = new EntityAttributeModifier(muscleID1, "ChestCavityMuscleAttackDamage",
(newScores.getOrDefault(CCItems.ORGANS_MUSCLE, 0f) / (64 * 8)) - 1, EntityAttributeModifier.Operation.MULTIPLY_BASE);
ReplaceAttributeModifier(att, mod);
//Update Move Speeeeed
EntityAttributeInstance att2 = player.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED);
EntityAttributeModifier mod2 = new EntityAttributeModifier(muscleID2, "ChestCavityMuscleMovementSpeed",
(newScores.getOrDefault(CCItems.ORGANS_MUSCLE, 0f) / (64 * 8 * 2)) - .5, EntityAttributeModifier.Operation.MULTIPLY_BASE);
ReplaceAttributeModifier(att2, mod2);
Expand All @@ -51,7 +63,13 @@ private static void UpdateMuscle(PlayerEntity player, Map<Identifier, Float> old
private static void UpdateSpine(PlayerEntity player, Map<Identifier, Float> oldScores, Map<Identifier, Float> newScores) {
if(oldScores.getOrDefault(CCItems.ORGANS_SPINE,0f) != newScores.getOrDefault(CCItems.ORGANS_SPINE,0f)) {
//Update Speed Modifier. No spine? NO MOVING.
EntityAttributeInstance att = player.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED);
EntityAttributeInstance att;
try {
att = player.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED);
}
catch(NullPointerException e){
return;
}
EntityAttributeModifier mod = new EntityAttributeModifier(spineID, "ChestCavitySpineMovement",
Math.min(0, newScores.getOrDefault(CCItems.ORGANS_SPINE, 0f) - 1), EntityAttributeModifier.Operation.MULTIPLY_TOTAL);
ReplaceAttributeModifier(att, mod);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "chestcavity",
"version": "1.2.1",
"version": "1.2.3",

"name": "Chest Cavity",
"description": "Perfectly Safe Extra Storage",
Expand Down

0 comments on commit dd990ec

Please sign in to comment.