more config options + fix prev. commit breaking arrows

This commit is contained in:
Jenny 2025-02-11 17:45:58 +01:00
parent 57eb7e5442
commit 5c5ab8c3dc
Signed by: Jenny
GPG Key ID: 2072A14E40940632
9 changed files with 72 additions and 42 deletions

View File

@ -38,7 +38,7 @@ mod_name=Enhanced Explosives
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=0.12.1
mod_version=0.13.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@ -2,7 +2,7 @@ package com.jenny.enhancedexplosives;
import com.jenny.enhancedexplosives.blocks.blocks;
import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.config.ConfigCommon;
import com.jenny.enhancedexplosives.config.ConfigServer;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items;
import com.jenny.enhancedexplosives.particles.particles;
@ -41,8 +41,8 @@ public class EnhancedExplosives {
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigClient.SPEC, "EnhancedExplosives-client.toml");
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigCommon.SPEC, "EnhancedExplosives-common.toml");
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigClient.SPEC, "enhancedexplosives-client.toml");
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigServer.SPEC, "enhancedexplosives-server.toml");
}
private void commonSetup(final FMLCommonSetupEvent event) {
@ -59,10 +59,8 @@ public class EnhancedExplosives {
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientModEvents {
@SuppressWarnings("removal")
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event) {
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigClient.SPEC);
entities.registerRenderers();
}
}

View File

@ -1,21 +0,0 @@
package com.jenny.enhancedexplosives.config;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ConfigCommon {
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC = BUILDER.build();
@SubscribeEvent
static void onLoad(final ModConfigEvent event)
{
}
}

View File

@ -0,0 +1,28 @@
package com.jenny.enhancedexplosives.config;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.common.Mod;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ConfigServer {
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;
public static final ForgeConfigSpec.ConfigValue<Boolean> claymoreInstantDespawn;
public static final ForgeConfigSpec.ConfigValue<Boolean> homingAtPlayers;
public static final ForgeConfigSpec.ConfigValue<Boolean> carpetCompactDetonation;
static {
claymoreInstantDespawn = BUILDER.comment("Claymore arrows despawn instantly upon hitting a surface")
.define("claymore_instant_arrow_despawn", false);
homingAtPlayers = BUILDER.comment("Homing TNTs are allowed to follow players")
.define("homing_tnt_target_players", true);
carpetCompactDetonation = BUILDER.comment("Carpet Arrow TNTs explode upon explosion damage; This reduces spread")
.define("carpet_arrow_compact_detonation", true);
SPEC = BUILDER.build();
}
}

View File

@ -15,11 +15,11 @@ public class baseArrow extends AbstractArrow {
super(pEntityType, pLevel);
}
public baseArrow(Level pLevel, double pX, double pY, double pZ, EntityType<? extends baseArrow> pEntityType) {
super(pEntityType, pX, pY, pZ, pLevel);
public baseArrow(Level pLevel, LivingEntity pShooter, EntityType<? extends baseArrow> pEntityType) {
super(pEntityType, pShooter, pLevel);
}
public baseArrow(Level pLevel, LivingEntity pShooter, EntityType<? extends baseArrow> pEntityType) {
public baseArrow(Level pLevel, EntityType<? extends baseArrow> pEntityType) {
super(pEntityType, pLevel);
}

View File

@ -1,11 +1,11 @@
package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.config.ConfigClient;
import com.jenny.enhancedexplosives.config.ConfigServer;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items;
import com.jenny.enhancedexplosives.particles.particles;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
@ -20,13 +20,13 @@ public class carpetArrowPart extends baseArrow {
}
public carpetArrowPart(Level pLevel, LivingEntity pShooter) {
super(pLevel, pShooter, entities.ARROW_CARPET_PART.get());
super(pLevel, entities.ARROW_CARPET_PART.get());
}
@Override
public void tick() {
super.tick();
if (this.inGround || this.hurtMarked) {
if (this.inGround || (this.hurtMarked && !this.level().isClientSide && ConfigServer.carpetCompactDetonation.get())) {
explode();
}
}

View File

@ -1,5 +1,6 @@
package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.config.ConfigServer;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items;
import net.minecraft.world.entity.EntityType;
@ -9,7 +10,7 @@ import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
public class claymoreArrow extends baseArrow{
private final int r = level().isClientSide ? 0 : level().getRandom().nextInt(0, 20);
private final int r = level().isClientSide ? 0 : (ConfigServer.claymoreInstantDespawn.get() ? -20 : level().getRandom().nextInt(0, 20));
public claymoreArrow(EntityType<claymoreArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel);

View File

@ -43,11 +43,9 @@ public class tunnelArrow extends baseArrow{
}
protected void explode() {
// sync();
Vec3 rot = getTargetVec( - getXRot(), - getYRot(), 0);
for (int i = 0; i < explosionCount; i++) {
Vec3 pos = position().add(rot.multiply(i * spacing, i * spacing, i * spacing));
System.out.println(level().isClientSide + "|" + i + "|" + pos + "|" + getXRot() + "|" + getYRot());
level().explode(this, pos.x, pos.y, pos.z,
power, Level.ExplosionInteraction.TNT);
}

View File

@ -1,23 +1,25 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.blocks.blocks;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.config.ConfigClient;
import net.minecraft.core.BlockPos;
import com.jenny.enhancedexplosives.config.ConfigServer;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class homingPrimedTNT extends basePrimedTNT {
private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(homingPrimedTNT.class, EntityDataSerializers.FLOAT);
@ -51,10 +53,34 @@ public class homingPrimedTNT extends basePrimedTNT {
}
public void findTarget() {
target = closestEntity(getEntities());
}
private LivingEntity closestEntity(List<LivingEntity> entities) {
double dist = Double.MAX_VALUE;
LivingEntity target = null;
for (LivingEntity e : entities) {
double newDist = e.position().distanceTo(position());
if (newDist < dist) {
target = e;
dist = newDist;
}
}
return target;
}
protected List<LivingEntity> getEntities() {
List<LivingEntity> ret_list = new ArrayList<>();
Vec3 corner1 = this.position().subtract(15, 15, 15);
Vec3 corner2 = this.position().add(15, 15, 15);
AABB boundingBox = new AABB(corner1, corner2);
target = this.level().getNearestEntity(LivingEntity.class, TargetingConditions.forNonCombat(), null, this.getX(), this.getY(), this.getZ(), boundingBox);
for (LivingEntity entity : level().getEntitiesOfClass(LivingEntity.class, boundingBox)) {
if (level().getPlayerByUUID(entity.getUUID()) == null || ConfigServer.homingAtPlayers.get()) { // prevent aiming at player if config says so
ret_list.add(entity);
}
}
return ret_list;
}
@Override