Skip to content

Commit

Permalink
Progress towards finalizing the joining explosions feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ArkoSammy12 committed Sep 24, 2023
1 parent 5a18d4d commit af09e01
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/java/xd/arkosammy/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.nio.file.Files;
import java.nio.file.Path;

public abstract class Config {
public final class Config {

private Config(){}
private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("creeper-healing.toml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.ArrayList;
import java.util.List;

public abstract class DelaysConfig {
public final class DelaysConfig {

private DelaysConfig(){}
private static final List<ConfigEntry<Double>> delaysEntryList = new ArrayList<>();
Expand Down Expand Up @@ -143,7 +143,7 @@ public static void loadSettingsToMemory(CommentedFileConfig fileConfig){

} else {

CreeperHealing.LOGGER.warn("Invalid value in config file for setting: " + configEntry.getName());
CreeperHealing.LOGGER.error("Invalid value in config file for setting: " + configEntry.getName());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.ArrayList;
import java.util.List;

public abstract class ExplosionSourceConfig {
public final class ExplosionSourceConfig {

private ExplosionSourceConfig(){}
private static final List<ConfigEntry<Boolean>> explosionSourceEntryList = new ArrayList<>();
Expand Down Expand Up @@ -204,7 +204,7 @@ public static void loadSettingsToMemory(CommentedFileConfig fileConfig){

} else {

CreeperHealing.LOGGER.warn("Invalid value in config file for setting: " + configEntry.getName());
CreeperHealing.LOGGER.error("Invalid value in config file for setting: " + configEntry.getName());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.ArrayList;
import java.util.List;

public abstract class ModeConfig {
public final class ModeConfig {

private ModeConfig(){}
private static final List<ConfigEntry<Boolean>> modeEntryList = new ArrayList<>();
Expand Down Expand Up @@ -97,7 +97,7 @@ public static void loadSettingsToMemory(CommentedFileConfig fileConfig){

} else {

CreeperHealing.LOGGER.warn("Invalid value in config file for setting: " + configEntry.getName());
CreeperHealing.LOGGER.error("Invalid value in config file for setting: " + configEntry.getName());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.ArrayList;
import java.util.List;

public abstract class PreferencesConfig {
public final class PreferencesConfig {

private PreferencesConfig(){}
private static final List<ConfigEntry<Boolean>> preferencesEntryList = new ArrayList<>();
Expand Down Expand Up @@ -199,11 +199,10 @@ public static void loadSettingsToMemory(CommentedFileConfig fileConfig){
if(value instanceof Boolean boolValue){

configEntry.setValue(boolValue);
CreeperHealing.LOGGER.info("Loaded entry: " + configEntry.getName() + " with value: " + configEntry.getValue());

} else {

CreeperHealing.LOGGER.warn("Invalid value in config file for setting: " + configEntry.getName());
CreeperHealing.LOGGER.error("Invalid value in config file for setting: " + configEntry.getName());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.HashMap;
import java.util.Map;

public abstract class ReplaceMapConfig {
public final class ReplaceMapConfig {

private ReplaceMapConfig(){}
private static final HashMap<String, String> replaceMap = new HashMap<>();
Expand All @@ -16,13 +16,13 @@ private ReplaceMapConfig(){}
Specify the block's namespace along with the block's name identifier, separated by a colon.
Example entry:
"minecraft:gold_block" = "minecraft:stone"
Warning, do not set a block to be replaced with more than one block! For example, the following will cause an error:
Warning, the same key cannot appear more than once in the replace map! For example, the following will cause an error:
"minecraft:diamond_block" = "minecraft:stone"
"minecraft:diamond_block" = "minecraft:air"\s""";


public static HashMap<String, String> getReplaceMap(){
return replaceMap;
return replaceMap;
}

public static void saveToFileWithDefaultValues(CommentedFileConfig fileConfig){
Expand Down Expand Up @@ -53,11 +53,11 @@ public static void loadReplaceMapToMemory(CommentedFileConfig fileConfig){

} else if (!(entry.getValue() instanceof String)) {

CreeperHealing.LOGGER.warn("Invalid value in replace map for key: " + entry.getKey());
CreeperHealing.LOGGER.error("Invalid value in replace map for key: " + entry.getKey());

} else if (entry.getKey() == null) {

CreeperHealing.LOGGER.warn("Invalid key found in replace map.");
CreeperHealing.LOGGER.error("Invalid key found in replace map.");

}

Expand Down
41 changes: 32 additions & 9 deletions src/main/java/xd/arkosammy/explosions/ExplosionEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static ExplosionEvent newExplosionEvent(List<AffectedBlock> affectedBlock
} else {
ExplosionListHandler.getExplosionEventList().removeIf(collidingExplosions::contains);
collidingExplosions.add(explosionEvent);
return combineCollidingExplosions(collidingExplosions, world.getServer());
return combineCollidingExplosions(collidingExplosions, explosionEvent, world);
}
}

Expand Down Expand Up @@ -169,21 +169,44 @@ private Integer findNextPlaceableBlock(MinecraftServer server){
return null;
}

private static ExplosionEvent combineCollidingExplosions(Set<ExplosionEvent> collidingExplosions, MinecraftServer server){
//TODO: Decide on either of the two implementations below

private static ExplosionEvent combineCollidingExplosions(Set<ExplosionEvent> collidingExplosions, ExplosionEvent newestExplosion, World world){

List<AffectedBlock> combinedAffectedBlockList = collidingExplosions.stream()
.flatMap(explosionEvent -> explosionEvent.getAffectedBlocksList().stream())
.collect(Collectors.toList());
ExplosionEvent explosionEvent = new ExplosionEvent(ExplosionUtils.sortAffectedBlocksList(combinedAffectedBlockList, world.getServer()), newestExplosion.getExplosionTimer(), newestExplosion.getCurrentAffectedBlockCounter(), newestExplosion.isMarkedWithDayTimeHealingMode());
long newestExplosionBlockTimers = newestExplosion.getCurrentAffectedBlock().getAffectedBlockTimer();
explosionEvent.getAffectedBlocksList().forEach(affectedBlock -> affectedBlock.setAffectedBlockTimer(newestExplosionBlockTimers));
if(explosionEvent.isMarkedWithDayTimeHealingMode())
explosionEvent.setupDayTimeHealing(world);
return explosionEvent;
}

private static ExplosionEvent combineCollidingExplosionsAlt(Set<ExplosionEvent> collidingExplosions, World world){

List<AffectedBlock> combinedAffectedBlockList = collidingExplosions.stream()
.flatMap(explosionEvent -> explosionEvent.getAffectedBlocksList().stream())
.collect(Collectors.toList());
List<ExplosionEvent> listToFindOldest = new ArrayList<>(collidingExplosions);
//TODO: Decide on implementation details to decide what explosion to use to inherit properties from
ExplosionEvent oldestExplosion = listToFindOldest.get(0);
for(ExplosionEvent explosionEvent : listToFindOldest){

List<ExplosionEvent> listToFindOldestExplosion = new ArrayList<>(collidingExplosions);
ExplosionEvent oldestExplosion = listToFindOldestExplosion.get(0);
long averageTimers = 0;
for(ExplosionEvent explosionEvent : listToFindOldestExplosion){
if(explosionEvent.getExplosionTimer() < oldestExplosion.getExplosionTimer()){
oldestExplosion = explosionEvent;
}
averageTimers += explosionEvent.getExplosionTimer();
}
return new ExplosionEvent(ExplosionUtils.sortAffectedBlocksList(combinedAffectedBlockList, server), oldestExplosion.getExplosionTimer(), oldestExplosion.getCurrentAffectedBlockCounter(), oldestExplosion.isMarkedWithDayTimeHealingMode());

long newTimer = averageTimers/(listToFindOldestExplosion.isEmpty() ? 1 : listToFindOldestExplosion.size());
ExplosionEvent explosionEvent = new ExplosionEvent(ExplosionUtils.sortAffectedBlocksList(combinedAffectedBlockList, world.getServer()), (oldestExplosion.getExplosionTimer() + newTimer)/2, oldestExplosion.getCurrentAffectedBlockCounter(), oldestExplosion.isMarkedWithDayTimeHealingMode());
for(AffectedBlock affectedBlock : explosionEvent.getAffectedBlocksList()){
affectedBlock.setAffectedBlockTimer(oldestExplosion.getAffectedBlocksList().get(0).getAffectedBlockTimer());
}
if(explosionEvent.isMarkedWithDayTimeHealingMode()) {
explosionEvent.setupDayTimeHealing(world);
}
return explosionEvent;
}

}

0 comments on commit af09e01

Please sign in to comment.