add black hole tnt (missing textures)

This commit is contained in:
Jenny 2025-01-22 23:28:01 +01:00
parent b6f950b788
commit 8b6f06101a
Signed by: Jenny
GPG Key ID: 4A98012FB1C39311
7 changed files with 188 additions and 0 deletions

View File

@ -0,0 +1,59 @@
package com.jenny.compressedtnt.blocks;
import com.jenny.compressedtnt.entities.blackHolePrimedTNT;
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 blackHoleTNTBlock extends TntBlock {
public final float pRadius, speed;
public final int fuseTime;
public blackHoleTNTBlock(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) {
blackHolePrimedTNT primedtnt = new blackHolePrimedTNT(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, BlockPos blockPos, Explosion pExplosion) {
if (!level.isClientSide) {
blackHolePrimedTNT primedtnt = new blackHolePrimedTNT(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

@ -43,6 +43,10 @@ public class blocks {
public static final RegistryObject<Block> TNT_HOMING= BLOCKS.register("tnt_homing", () -> new homingTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80, 1));
public static final RegistryObject<Item> TNT_HOMING_ITEM = ITEMS.register("tnt_homing", () -> new BlockItem(TNT_HOMING.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_BLACK_HOLE= BLOCKS.register("tnt_black_hole", () -> new blackHoleTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80, 1));
public static final RegistryObject<Item> TNT_BLACK_HOLE_ITEM = ITEMS.register("tnt_black_hole", () -> new BlockItem(TNT_BLACK_HOLE.get(), new Item.Properties()));
public static void register(IEventBus bus) {
BLOCKS.register(bus);
ITEMS.register(bus);

View File

@ -24,6 +24,7 @@ public class creativeTab {
output.accept(blocks.TNT_CLUSTER_4.get());
output.accept(blocks.TNT_CLUSTER_8.get());
output.accept(blocks.TNT_HOMING.get());
output.accept(blocks.TNT_BLACK_HOLE.get());
}).title(Component.literal("Compressed TNT")).build());
public static void register(IEventBus bus) {

View File

@ -0,0 +1,97 @@
package com.jenny.compressedtnt.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.*;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.List;
public class blackHolePrimedTNT extends basePrimedTNT {
private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(blackHolePrimedTNT.class, EntityDataSerializers.FLOAT);
public blackHolePrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, float speed) {
super(entities.TNT_BLACK_HOLE.get(), pLevel, pOwner);
this.setRenderID("black_hole");
this.setPos(pX, pY, pZ);
this.setOwner(pOwner);
this.setSpeed(speed);
this.setPower(power);
this.setFuse(fuse);
}
public blackHolePrimedTNT(EntityType<blackHolePrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("black_hole");
}
private Vec3 targetVector(Entity target) {
double dist = getTargetDist(target);
float speed = getSpeed();
Vec3 mult = new Vec3(speed / dist, speed / dist, speed / dist);
Vec3 ret = this.position().subtract(target.position()).normalize().multiply(mult);
if (dist < this.position().subtract(target.position().add(ret)).length()) {
// reduce overshoot
return Vec3.ZERO;
}
else {
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
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();
}
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
return 0.15F;
}
}

View File

@ -28,6 +28,10 @@ public class entities {
ENTITY_TYPES.register("tnt_cluster", () -> EntityType.Builder.<ClusterPrimedTNT>of(ClusterPrimedTNT::new, MobCategory.MISC)
.sized(0.48F, 0.48F).fireImmune().clientTrackingRange(8).build("tnt_cluster"));
public static final RegistryObject<EntityType<blackHolePrimedTNT>> TNT_BLACK_HOLE =
ENTITY_TYPES.register("tnt_chunk", () -> EntityType.Builder.<blackHolePrimedTNT>of(blackHolePrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_chunk"));
public static void register(IEventBus eventBus) {
ENTITY_TYPES.register(eventBus);
}
@ -35,6 +39,7 @@ public class entities {
public static void registerRenderers () {
EntityRenderers.register(TNT_STRONGER.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_HOMING.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_BLACK_HOLE.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_CLUSTER.get(), clusterTNTRenderer::new);

View File

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "compressedtnt:block/ttn_black_hole"
}
}
}

View File

@ -0,0 +1,15 @@
{
"type": "minecraft:crafting_shapeless",
"category": "redstone",
"ingredients":[
{
"item": "minecraft:tnt"
},
{
"item": "minecraft:end_crystal"
}
],
"result": {
"item": "compressedtnt:tnt_black_hole"
}
}