Skip to content

Commit

Permalink
Update fabric.mod.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ArkoSammy12 committed Sep 17, 2024
1 parent 83b0df5 commit da7cf06
Show file tree
Hide file tree
Showing 23 changed files with 439 additions and 133 deletions.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ repositories {
url "https://maven.enjarai.dev/releases"
}

maven {
name "enjaraiMavenMirrors"
url "https://maven.enjarai.dev/mirrors"
}


maven {
// Patbox's SGui
name "nucleoid"
Expand All @@ -40,7 +46,7 @@ loom {
splitEnvironmentSourceSets()

mods {
"creeper-healing" {
"creeperhealing" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
Expand Down Expand Up @@ -86,6 +92,13 @@ dependencies {
// Monkey config
modImplementation("xd.arkosammy:monkeyconfig:${project.monkey_config_version}")

// Trickster
modImplementation("dev.enjarai:trickster:${project.trickster_version}")

// Mythic Metals
modImplementation("maven.modrinth:bAWzYNRd:${project.mythic_metals_version}")


// Creeper Overhaul
//modImplementation("maven.modrinth:MI1LWe93:${project.creeper_overhaul_version}")

Expand Down
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ monkey_config_version=0.1.2+1.21
# Creeper Overhaul
creeper_overhaul_version=pv1EuPwm

# Trickster
trickster_version=2.0.0-alpha.25b

# Mythic Metals
mythic_metals_version=VDByzfQk

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package xd.arkosammy.creeperhealing;

import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class CreeperHealingMixinConfigPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
}

@Override
public String getRefMapperConfig() {
return "";
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
String[] packageTree = mixinClassName.split("\\.");
if (Arrays.asList(packageTree).contains("compat")) {
String modId = packageTree[packageTree.length - 2];
return FabricLoader.getInstance().isModLoaded(modId);
}
return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> getMixins() {
return List.of();
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import xd.arkosammy.creeperhealing.explosions.factories.ExplosionEventFactory;
import xd.arkosammy.creeperhealing.managers.ExplosionManager;
import xd.arkosammy.creeperhealing.util.ExplosionContext;
Expand Down Expand Up @@ -42,15 +43,21 @@ public void registerExplosionManager(ExplosionManager explosionManager) {

public void emitExplosionContext(Identifier explosionManagerId, ExplosionContext explosionContext) {
synchronized (this.explosionManagers) {
boolean foundManager = false;
for (ExplosionManager explosionManager : this.explosionManagers) {
if (!explosionManager.getId().equals(explosionManagerId)) {
continue;
}
ExplosionEventFactory<?> explosionEventFactory = explosionManager.getExplosionContextToEventFactoryFunction().apply(explosionContext);
explosionManager.addExplosionEvent(explosionEventFactory);
return;
explosionManager.onExplosionContext(explosionContext);
foundManager = true;
break;
}
if (!foundManager) {
CreeperHealing.LOGGER.warn("Found no ExplosionManager with ID {}. An explosion will not be healed", explosionManagerId);
}
if (foundManager) {
Collections.rotate(this.explosionManagers, 1);
}
CreeperHealing.LOGGER.warn("Found no ExplosionManager with ID {}. An explosion will not be healed", explosionManagerId);
}
}

Expand All @@ -68,6 +75,7 @@ void invokeOnServerStopping(MinecraftServer server) {
explosionManager.onServerStopping(server);
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ private void handleChestBlockIfNeeded(ExplosionEvent explosionEvent, BlockState
if (!affectedState.isOf(Blocks.CHEST) || !affectedPosition.equals(otherHalfPos)) {
continue;
}
singleAffectedBlock.tryHealing(server, explosionEvent);
if (!singleAffectedBlock.isPlaced()) {
singleAffectedBlock.tryHealing(server, explosionEvent);
}
singleAffectedBlock.setPlaced();
}

Expand All @@ -209,12 +211,12 @@ public SerializedAffectedBlock asSerialized() {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SingleAffectedBlock that)) return false;
return Objects.equals(getBlockPos(), that.getBlockPos()) && Objects.equals(getBlockState(), that.getBlockState()) && Objects.equals(getWorldRegistryKey(), that.getWorldRegistryKey());
return Objects.equals(blockPos, that.blockPos) && Objects.equals(blockState, that.blockState) && Objects.equals(worldRegistryKey, that.worldRegistryKey) && Objects.equals(nbt, that.nbt);
}

@Override
public int hashCode() {
return Objects.hash(getBlockPos(), getBlockState(), getWorldRegistryKey());
return Objects.hash(blockPos, blockState, worldRegistryKey, nbt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum ConfigSettings {
MAKE_FALLING_BLOCKS_FALL(new BooleanSetting.Builder(new SettingLocation(SettingGroups.PREFERENCES.getName(), "make_falling_blocks_fall"), "(Default = true) Allows for a falling block, like sand or gravel, to fall when healed. Disabling this option makes the falling block have to receive a neighbor update before falling.", true)),
BLOCK_PLACEMENT_SOUND_EFFECT(new BooleanSetting.Builder(new SettingLocation(SettingGroups.PREFERENCES.getName(), "block_placement_sound_effect"), "(Default = true) Whether a block placement sound effect should be played when a block is healed.", true)),
BLOCK_PLACEMENT_PARTICLES(new BooleanSetting.Builder(new SettingLocation(SettingGroups.PREFERENCES.getName(), "block_placement_particles"), "(Default = true) Whether a block placement sound effect should produce some cloud particles.", true)),
HEALING_PARTICLE_TYPE(new StringSetting.Builder(new SettingLocation(SettingGroups.PREFERENCES.getName(), "healing_particle_type"), "(Default = minecraft:cloud) The type of the particle to use when healing blocks.", "minecraft:cloud")),
HEAL_ON_HEALING_POTION_SPLASH(new BooleanSetting.Builder(new SettingLocation(SettingGroups.PREFERENCES.getName(), "heal_on_healing_potion_splash"), "(Default = true) Makes explosion heal immediately when a potion of Healing is thrown on them.", true)),
HEAL_ON_REGENERATION_POTION_SPLASH(new BooleanSetting.Builder(new SettingLocation(SettingGroups.PREFERENCES.getName(), "heal_on_regeneration_potion_splash"), "(Default = true) Makes explosions begin their healing process when a potion of Regeneration is thrown on them.", true)),
ENABLE_WHITELIST(new BooleanSetting.Builder(new SettingLocation(SettingGroups.PREFERENCES.getName(), "enable_whitelist"), "(Default = false) Toggle the usage of the whitelist.", false)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;

Expand Down Expand Up @@ -156,4 +157,15 @@ public final void findAndMarkPlaced(BlockPos blockPos, BlockState blockState, Wo
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AbstractExplosionEvent that)) return false;
return Objects.equals(affectedBlocks, that.affectedBlocks);
}

@Override
public int hashCode() {
return Objects.hashCode(affectedBlocks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@
public class DefaultExplosionManager implements ExplosionManager {

public static final Identifier ID = Identifier.of(CreeperHealing.MOD_ID, "default_explosion_manager");
private static final Function<ExplosionContext, ExplosionEventFactory<?>> explosionContextToFactoryFunction = explosionContext -> {
List<BlockPos> indirectlyExplodedPositions = explosionContext.indirectlyAffectedPositions();
Map<BlockPos, Pair<BlockState, BlockEntity>> affectedStatesAndBlockEntities = explosionContext.affectedStatesAndBlockEntities();
DefaultExplosionFactory explosionFactory = new DefaultExplosionFactory(
affectedStatesAndBlockEntities,
explosionContext.vanillaAffectedPositions(),
indirectlyExplodedPositions,
explosionContext.world()
);
return explosionFactory;
};
private static final String SCHEDULED_EXPLOSIONS_FILE = "scheduled-explosions.json";

private final Codec<DefaultExplosionManager> codec;
Expand Down Expand Up @@ -89,11 +78,6 @@ public void onServerStopping(MinecraftServer server) {
this.explosionEvents.clear();
}

@Override
public Function<ExplosionContext, ExplosionEventFactory<?>> getExplosionContextToEventFactoryFunction() {
return explosionContextToFactoryFunction;
}

@Override
public void tick(MinecraftServer server) {
if (this.explosionEvents.isEmpty() || !server.getTickManager().shouldTick()) {
Expand All @@ -106,20 +90,27 @@ public void tick(MinecraftServer server) {
}

@Override
public <T extends ExplosionEvent> void addExplosionEvent(ExplosionEventFactory<T> explosionEventFactory) {
ExplosionEvent explosionEvent = explosionEventFactory.createExplosionEvent();
public void onExplosionContext(ExplosionContext explosionContext) {
List<BlockPos> indirectlyExplodedPositions = explosionContext.indirectlyAffectedPositions();
Map<BlockPos, Pair<BlockState, BlockEntity>> affectedStatesAndBlockEntities = explosionContext.affectedStatesAndBlockEntities();
DefaultExplosionFactory explosionFactory = new DefaultExplosionFactory(
affectedStatesAndBlockEntities,
explosionContext.vanillaAffectedPositions(),
indirectlyExplodedPositions,
explosionContext.world()
);
ExplosionEvent explosionEvent = explosionFactory.createExplosionEvent();
if (explosionEvent == null) {
return;
}
Set<ExplosionEvent> collidingExplosions = this.getCollidingExplosions(explosionEvent, explosionEventFactory.getAffectedPositions());
Set<ExplosionEvent> collidingExplosions = this.getCollidingExplosions(explosionEvent, explosionFactory.getAffectedPositions());
if (collidingExplosions.isEmpty()) {
this.explosionEvents.add(explosionEvent);
} else {
this.explosionEvents.removeIf(collidingExplosions::contains);
collidingExplosions.add(explosionEvent);
this.explosionEvents.add(combineCollidingExplosions(explosionEvent, collidingExplosions, explosionEventFactory));
this.explosionEvents.add(combineCollidingExplosions(explosionEvent, collidingExplosions, explosionFactory));
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ public interface ExplosionManager {

Identifier getId();

Function<ExplosionContext, ExplosionEventFactory<?>> getExplosionContextToEventFactoryFunction();

void tick(MinecraftServer server);

Stream<ExplosionEvent> getExplosionEvents();

<T extends ExplosionEvent> void addExplosionEvent(ExplosionEventFactory<T> explosionEventFactory);
void onExplosionContext(ExplosionContext explosionContext);

default void onServerStarting(MinecraftServer server) {
this.readExplosionEvents(server);
Expand Down
Loading

0 comments on commit da7cf06

Please sign in to comment.