added repulsive tnt

This commit is contained in:
Jenny 2025-01-31 00:57:43 +01:00
parent b8240c61c2
commit 871c1f9888
Signed by: Jenny
GPG Key ID: 2072A14E40940632
12 changed files with 188 additions and 1 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.9.9
mod_version=0.10.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

@ -56,6 +56,9 @@ public class blocks {
public static final RegistryObject<Block> TNT_ENDER = BLOCKS.register("tnt_ender", () -> new enderTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80));
public static final RegistryObject<Item> TNT_ENDER_ITEM = ITEMS.register("tnt_ender", () -> new BlockItemTooltip(TNT_ENDER.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_REPULSIVE = BLOCKS.register("tnt_repulsive", () -> new repulsiveTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80, 1));
public static final RegistryObject<Item> TNT_REPULSIVE_ITEM = ITEMS.register("tnt_repulsive", () -> new BlockItemTooltip(TNT_REPULSIVE.get(), new Item.Properties()));
public static void register(IEventBus bus) {
BLOCKS.register(bus);

View File

@ -0,0 +1,60 @@
package com.jenny.enhancedexplosives.blocks;
import com.jenny.enhancedexplosives.entities.tnt.blackHolePrimedTNT;
import com.jenny.enhancedexplosives.entities.tnt.repulsivePrimedTNT;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.TntBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
public class repulsiveTNTBlock extends TntBlock {
public final float pRadius, speed;
public final int fuseTime;
public repulsiveTNTBlock(Properties p_57422_, float pRadius, int fuseTime, float speed) {
super(p_57422_);
this.pRadius = pRadius;
this.fuseTime = fuseTime;
this.speed = speed;
}
@Override
public void onCaughtFire(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
explode(world, pos, igniter, this.pRadius, this.fuseTime, this.speed);
}
@Deprecated
public static void explode(Level p_57434_, BlockPos p_57435_, float pRadius, int fuseTime, float speed) {
explode(p_57434_, p_57435_, (LivingEntity)null, pRadius, fuseTime, speed);
}
@Deprecated
private static void explode(Level level, BlockPos blockPos, @Nullable LivingEntity entity, float pRadius, int fuseTime, float speed) {
if (!level.isClientSide) {
repulsivePrimedTNT primedtnt = new repulsivePrimedTNT(level, (double)blockPos.getX() + (double)0.5F, (double)blockPos.getY(), (double)blockPos.getZ() + (double)0.5F, entity, pRadius, fuseTime, speed);
level.addFreshEntity(primedtnt);
level.playSound((Player)null, primedtnt.getX(), primedtnt.getY(), primedtnt.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
level.gameEvent(entity, GameEvent.PRIME_FUSE, blockPos);
}
}
@Override
public void wasExploded(Level level, @NotNull BlockPos blockPos, @NotNull Explosion pExplosion) {
if (!level.isClientSide) {
repulsivePrimedTNT primedtnt = new repulsivePrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, pExplosion.getIndirectSourceEntity(), pRadius, fuseTime, speed);
int i = primedtnt.getFuse();
primedtnt.setFuse((short) (level.random.nextInt(i / 4) + i / 8));
level.addFreshEntity(primedtnt);
}
}
}

View File

@ -26,6 +26,7 @@ public class creativeTab {
output.accept(blocks.TNT_CLUSTER_8.get());
output.accept(blocks.TNT_HOMING.get());
output.accept(blocks.TNT_BLACK_HOLE.get());
output.accept(blocks.TNT_REPULSIVE.get());
output.accept(blocks.TNT_CLAYMORE.get());
output.accept(blocks.TNT_SELECTIVE.get());
output.accept(blocks.TNT_ENDER.get());

View File

@ -29,6 +29,7 @@ public class ModBlockStateProvider extends BlockStateProvider {
sideTopBottom(blocks.TNT_ENDER);
sideTopBottom(blocks.TNT_CLAYMORE);
SideTop(blocks.TNT_BLACK_HOLE);
SideTop(blocks.TNT_REPULSIVE);
SideOnlyTNT(blocks.TNT_CLUSTER_2);
SideOnlyTNT(blocks.TNT_CLUSTER_4);
SideOnlyTNT(blocks.TNT_CLUSTER_8);

View File

@ -47,6 +47,10 @@ public class entities {
ENTITY_TYPES.register("tnt_ender", () -> EntityType.Builder.<enderPrimedTNT>of(enderPrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_ender"));
public static final RegistryObject<EntityType<repulsivePrimedTNT>> TNT_REPULSIVE =
ENTITY_TYPES.register("tnt_repulsive", () -> EntityType.Builder.<repulsivePrimedTNT>of(repulsivePrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_repulsive"));
public static final RegistryObject<EntityType<tntArrow>> ARROW_TNT =
ENTITY_TYPES.register("arrow_tnt", () -> EntityType.Builder.<tntArrow>of(tntArrow::new, MobCategory.MISC)
.sized(0.48F, 0.48F).clientTrackingRange(64).build("arrow_tnt"));
@ -85,6 +89,8 @@ public class entities {
EntityRenderers.register(TNT_BLACK_HOLE.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_CLAYMORE.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_ENDER.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_REPULSIVE.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_SELECTIVE.get(), SelectiveTNTRenderer::new);
EntityRenderers.register(TNT_CLUSTER.get(), clusterTNTRenderer::new);
@ -95,6 +101,7 @@ public class entities {
EntityRenderers.register(ARROW_CARPET.get(), TNTArrowRenderer::new);
EntityRenderers.register(ARROW_CARPT_PART.get(), TNTArrowRenderer::new);
EntityRenderers.register(ARROW_TUNNEL.get(), TNTArrowRenderer::new);
EntityRenderers.register(ARROW_CLAYMORE.get(), baseArrowRenderer::new);
}
}

View File

@ -0,0 +1,99 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.blocks.blocks;
import com.jenny.enhancedexplosives.entities.entities;
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.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.List;
public class repulsivePrimedTNT extends basePrimedTNT {
private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(repulsivePrimedTNT.class, EntityDataSerializers.FLOAT);
public repulsivePrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, float speed) {
super(entities.TNT_REPULSIVE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
this.setSpeed(speed);
}
public repulsivePrimedTNT(EntityType<repulsivePrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setSpeed(this.getSpeed());
}
private Vec3 targetVector(Entity target) {
double dist = getTargetDist(target);
float speed = getSpeed();
Vec3 mult = new Vec3(speed / dist, speed / dist, speed / dist);
Vec3 ret = target.position().subtract(this.position()).normalize().multiply(mult);
return ret;
}
public double getTargetDist(Entity target) {
return target.position().subtract(this.position()).length();
}
public List<Entity> findTargets() {
Vec3 corner1 = this.position().subtract(15, 15, 15);
Vec3 corner2 = this.position().add(15, 15, 15);
AABB boundingBox = new AABB(corner1, corner2);
return this.level().getEntities(this, boundingBox);
}
@Override
public void tick() {
for (Entity e : findTargets()) {
e.addDeltaMovement(targetVector(e));
}
super.tick();
}
@Override
public void explode() {
for (Entity e : findTargets()) {
e.addDeltaMovement(targetVector(e).scale(3));
}
super.explode();
}
@Override
protected void addAdditionalSaveData(CompoundTag pCompound) {
pCompound.putFloat("Speed", this.getSpeed());
super.addAdditionalSaveData(pCompound);
}
@Override
protected void readAdditionalSaveData(CompoundTag pCompound) {
this.setSpeed(pCompound.getFloat("Speed"));
super.readAdditionalSaveData(pCompound);
}
public void setSpeed(float speed) {
this.entityData.set(DATA_SPEED_ID, speed);
}
public float getSpeed() {
return this.entityData.get(DATA_SPEED_ID);
}
@Override
protected void defineSynchedData() {
this.entityData.define(DATA_SPEED_ID, 4.0f);
super.defineSynchedData();
}
@Override
public Block renderBlock() {
return blocks.TNT_REPULSIVE.get();
}
}

View File

@ -12,6 +12,7 @@
"block.enhancedexplosives.tnt_claymore": "Claymore TNT",
"block.enhancedexplosives.tnt_selective": "Selective TNT",
"block.enhancedexplosives.tnt_ender": "Ender TNT",
"block.enhancedexplosives.tnt_repulsive": "Repulsive TNT",
"tooltip.enhancedexplosives.tnt_cluster_2": "splits into 2 small TNTs",
"tooltip.enhancedexplosives.tnt_cluster_4": "splits into 4 small TNTs",
@ -21,6 +22,7 @@
"tooltip.enhancedexplosives.tnt_claymore": "throws arrows into all direcctions upon explosion",
"tooltip.enhancedexplosives.tnt_selective": "only destroys the type of block it explodes on",
"tooltip.enhancedexplosives.tnt_ender": "teleports in a 16 block radius upon priming",
"tooltip.enhancedexplosives.tnt_repulsive": "repels all close entities",
"item.enhancedexplosives.arrow_tnt": "TNT Arrow",
"item.enhancedexplosives.arrow_concussive": "Concussive Arrow",

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -0,0 +1,7 @@
{
"animation": {
"frametime": 1,
"interpolate": true,
"frames": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -0,0 +1,7 @@
{
"animation": {
"frametime": 1,
"interpolate": true,
"frames": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]
}
}