Compare commits

...

5 Commits

27 changed files with 776 additions and 93 deletions

View File

@ -26,7 +26,7 @@ loader_version_range=[47,)
#
# Parchment is an unofficial project maintained by ParchmentMC, separate from Minecraft Forge.
# Additional setup is needed to use their mappings, see https://parchmentmc.org/docs/getting-started
mapping_channel=official
mapping_channel=parchment
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=1.20.1
@ -38,7 +38,7 @@ mod_name=Compressed TNT
# 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.0.1
mod_version=0.2.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

@ -1,32 +1,17 @@
package com.jenny.compressedtnt;
import com.jenny.compressedtnt.blocks.*;
import com.jenny.compressedtnt.blocks.blocks;
import com.jenny.compressedtnt.entities.entities;
import com.mojang.logging.LogUtils;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.slf4j.Logger;
// The value here should match an entry in the META-INF/mods.toml file
@ -38,63 +23,23 @@ public class Compressedtnt {
// Directly reference a slf4j logger
private static final Logger LOGGER = LogUtils.getLogger();
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
public static final RegistryObject<strongerTNTBlock> TNT_8 = BLOCKS.register("tnt_8", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE), 8.0f, 80));
public static final RegistryObject<Item> TNT_8_ITEM = ITEMS.register("tnt_8", () -> new BlockItem(TNT_8.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_16 = BLOCKS.register("tnt_16", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE), 16.0f, 80));
public static final RegistryObject<Item> TNT_16_ITEM = ITEMS.register("tnt_16", () -> new BlockItem(TNT_16.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_32 = BLOCKS.register("tnt_32", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE), 32.0f, 80));
public static final RegistryObject<Item> TNT_32_ITEM = ITEMS.register("tnt_32", () -> new BlockItem(TNT_32.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_64 = BLOCKS.register("tnt_64", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE), 64.0f, 80));
public static final RegistryObject<Item> TNT_64_ITEM = ITEMS.register("tnt_64", () -> new BlockItem(TNT_64.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_128 = BLOCKS.register("tnt_128", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE), 128.0f, 80));
public static final RegistryObject<Item> TNT_128_ITEM = ITEMS.register("tnt_128", () -> new BlockItem(TNT_128.get(), new Item.Properties()));
public static final RegistryObject<CreativeModeTab> CREATIVE_TAB = CREATIVE_MODE_TABS.register("compressedtnt", () -> CreativeModeTab.builder().withTabsBefore(CreativeModeTabs.COMBAT).icon(() -> TNT_8_ITEM.get().getDefaultInstance()).displayItems((parameters, output) -> {
output.accept(TNT_8.get());
output.accept(TNT_16.get());
output.accept(TNT_32.get());
output.accept(TNT_64.get());
output.accept(TNT_128.get());
}).title(Component.literal("Compressed TNT")).build());
public Compressedtnt() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(this::commonSetup);
// Register the Deferred Register to the mod event bus so blocks get registered
BLOCKS.register(modEventBus);
// Register the Deferred Register to the mod event bus so items get registered
ITEMS.register(modEventBus);
// Register the Deferred Register to the mod event bus so tabs get registered
CREATIVE_MODE_TABS.register(modEventBus);
blocks.register(modEventBus);
creativeTab.register(modEventBus);
entities.register(modEventBus);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
// Register the item to a creative tab
modEventBus.addListener(this::addCreative);
}
private void commonSetup(final FMLCommonSetupEvent event) {
}
// Add the example block item to the building blocks tab
private void addCreative(BuildCreativeModeTabContentsEvent event) {
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event) {
@ -107,7 +52,7 @@ public class Compressedtnt {
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event) {
entities.registerRenderers();
}
}
}

View File

@ -0,0 +1,75 @@
package com.jenny.compressedtnt.blocks;
import com.jenny.compressedtnt.entities.ClusterPrimedTNT;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
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.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
public class ClusterTNTBlock extends TntBlock {
public final float pRadius;
public final int fuseTime;
public final int childCount;
public final int childRange;
public ClusterTNTBlock(BlockBehaviour.Properties p_57422_, float pRadius, int fuseTime, int childCount, int childRange) {
super(p_57422_);
this.pRadius = pRadius;
this.fuseTime = fuseTime;
this.childCount = childCount;
this.childRange = childRange;
}
@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.childCount, this.childRange);
}
@Deprecated
public static void explode(Level p_57434_, BlockPos p_57435_, float pRadius, int fuseTime, int childCount, int childRange) {
explode(p_57434_, p_57435_, (LivingEntity)null, pRadius, fuseTime, childCount, childRange);
}
public static Vec3 getMove(Level level, int childRange) {
RandomSource rng = level.getRandom();
float offsetX = (float) rng.nextInt(- childRange, childRange + 1) / 15;
float offsetZ = (float) rng.nextInt(- childRange, childRange + 1) / 15;
return new Vec3(offsetX, 0, offsetZ);
}
@Deprecated
private static void explode(Level level, BlockPos blockPos, @Nullable LivingEntity entity, float pRadius, int fuseTime, int childCount, int childRange) {
if (!level.isClientSide) {
for (int i = 0; i < childCount; i++) {
ClusterPrimedTNT primedtnt = new ClusterPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, entity, pRadius, fuseTime, getMove(level, childRange));
level.addFreshEntity(primedtnt);
level.gameEvent(entity, GameEvent.PRIME_FUSE, blockPos);
}
level.playSound((Player) null, blockPos.getX(), blockPos.getY(), blockPos.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
}
}
@Override
public void wasExploded(Level level, BlockPos blockPos, Explosion pExplosion) {
if (!level.isClientSide) {
for (int i = 0; i < childCount; i++) {
int ft = (short) (level.random.nextInt(fuseTime / 4) + fuseTime / 8);
ClusterPrimedTNT primedtnt = new ClusterPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, pExplosion.getIndirectSourceEntity(), pRadius, ft, getMove(level, childRange));
level.addFreshEntity(primedtnt);
}
}
}
}

View File

@ -1,23 +0,0 @@
package com.jenny.compressedtnt.blocks;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.level.Level;
import javax.annotation.Nullable;
public class StrongerPrimedTNT extends PrimedTnt {
final float pRadius;
public StrongerPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float pRadius, int fuseTime) {
super(pLevel, pX, pY, pZ, pOwner);
this.pRadius = pRadius;
this.setFuse(fuseTime);
}
@Override
protected void explode() {
float $$0 = pRadius;
this.level().explode(this, this.getX(), this.getY((double)0.0625F), this.getZ(), pRadius, Level.ExplosionInteraction.TNT);
}
}

View File

@ -0,0 +1,50 @@
package com.jenny.compressedtnt.blocks;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import static com.jenny.compressedtnt.Compressedtnt.MODID;
public class blocks {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final RegistryObject<strongerTNTBlock> TNT_8 = BLOCKS.register("tnt_8", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.STONE), 8.0f, 80));
public static final RegistryObject<Item> TNT_8_ITEM = ITEMS.register("tnt_8", () -> new BlockItem(TNT_8.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_16 = BLOCKS.register("tnt_16", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 16.0f, 80));
public static final RegistryObject<Item> TNT_16_ITEM = ITEMS.register("tnt_16", () -> new BlockItem(TNT_16.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_32 = BLOCKS.register("tnt_32", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 32.0f, 80));
public static final RegistryObject<Item> TNT_32_ITEM = ITEMS.register("tnt_32", () -> new BlockItem(TNT_32.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_64 = BLOCKS.register("tnt_64", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 64.0f, 80));
public static final RegistryObject<Item> TNT_64_ITEM = ITEMS.register("tnt_64", () -> new BlockItem(TNT_64.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_128 = BLOCKS.register("tnt_128", () -> new strongerTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 128.0f, 80));
public static final RegistryObject<Item> TNT_128_ITEM = ITEMS.register("tnt_128", () -> new BlockItem(TNT_128.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_CLUSTER_2 = BLOCKS.register("tnt_cluster_2", () -> new ClusterTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80, 2, 10));
public static final RegistryObject<Item> TNT_CLUSTER__2ITEM = ITEMS.register("tnt_cluster_2", () -> new BlockItem(TNT_CLUSTER_2.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_CLUSTER_4 = BLOCKS.register("tnt_cluster_4", () -> new ClusterTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80, 4, 10));
public static final RegistryObject<Item> TNT_CLUSTER_4_ITEM = ITEMS.register("tnt_cluster_4", () -> new BlockItem(TNT_CLUSTER_4.get(), new Item.Properties()));
public static final RegistryObject<Block> TNT_CLUSTER_8 = BLOCKS.register("tnt_cluster_8", () -> new ClusterTNTBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_RED), 4.0f, 80, 8, 10));
public static final RegistryObject<Item> TNT_CLUSTER_8_ITEM = ITEMS.register("tnt_cluster_8", () -> new BlockItem(TNT_CLUSTER_8.get(), new Item.Properties()));
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 void register(IEventBus bus) {
BLOCKS.register(bus);
ITEMS.register(bus);
}
}

View File

@ -0,0 +1,60 @@
package com.jenny.compressedtnt.blocks;
import com.jenny.compressedtnt.entities.homingPrimedTNT;
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.BlockBehaviour;
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 homingTNTBlock extends TntBlock {
public final float pRadius, speed;
public final int fuseTime;
public homingTNTBlock(BlockBehaviour.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) {
homingPrimedTNT primedtnt = new homingPrimedTNT(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) {
homingPrimedTNT primedtnt = new homingPrimedTNT(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

@ -1,11 +1,13 @@
package com.jenny.compressedtnt.blocks;
import com.jenny.compressedtnt.entities.StrongerPrimedTNT;
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.BlockBehaviour;
@ -24,7 +26,7 @@ public class strongerTNTBlock extends TntBlock {
this.fuseTime = fuseTime;
}
@Override
public void onCaughtFire(BlockState state, Level world, BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
explode(world, pos, igniter, this.pRadius, this.fuseTime);
}
@ -34,7 +36,6 @@ public class strongerTNTBlock extends TntBlock {
explode(p_57434_, p_57435_, (LivingEntity)null, pRadius, fuseTime);
}
/** @deprecated */
@Deprecated
private static void explode(Level p_57437_, BlockPos p_57438_, @Nullable LivingEntity p_57439_, float pRadius, int fuseTime) {
if (!p_57437_.isClientSide) {
@ -45,4 +46,13 @@ public class strongerTNTBlock extends TntBlock {
}
}
@Override
public void wasExploded(Level level, BlockPos blockPos, Explosion pExplosion) {
if (!level.isClientSide) {
int ft = (short) (level.random.nextInt(fuseTime / 4) + fuseTime / 8);
StrongerPrimedTNT primedtnt = new StrongerPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, pExplosion.getIndirectSourceEntity(), pRadius, ft);
level.addFreshEntity(primedtnt);
}
}
}

View File

@ -0,0 +1,32 @@
package com.jenny.compressedtnt;
import com.jenny.compressedtnt.blocks.blocks;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;
import static com.jenny.compressedtnt.Compressedtnt.MODID;
public class creativeTab {
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
public static final RegistryObject<CreativeModeTab> CREATIVE_TAB = CREATIVE_MODE_TABS.register("compressedtnt", () -> CreativeModeTab.builder().withTabsBefore(CreativeModeTabs.COMBAT).icon(() -> blocks.TNT_8_ITEM.get().getDefaultInstance()).displayItems((parameters, output) -> {
output.accept(blocks.TNT_8.get());
output.accept(blocks.TNT_16.get());
output.accept(blocks.TNT_32.get());
output.accept(blocks.TNT_64.get());
output.accept(blocks.TNT_128.get());
output.accept(blocks.TNT_CLUSTER_2.get());
output.accept(blocks.TNT_CLUSTER_4.get());
output.accept(blocks.TNT_CLUSTER_8.get());
output.accept(blocks.TNT_HOMING.get());
}).title(Component.literal("Compressed TNT")).build());
public static void register(IEventBus bus) {
CREATIVE_MODE_TABS.register(bus);
}
}

View File

@ -1,6 +1,7 @@
package com.jenny.compressedtnt.datagen;
import com.jenny.compressedtnt.Compressedtnt;
import com.jenny.compressedtnt.blocks.blocks;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
@ -20,11 +21,14 @@ public class ModBlockStateProvider extends BlockStateProvider {
@Override
protected void registerStatesAndModels() {
sideTopBottom(Compressedtnt.TNT_8.get());
sideTopBottom(Compressedtnt.TNT_16.get());
sideTopBottom(Compressedtnt.TNT_32.get());
sideTopBottom(Compressedtnt.TNT_64.get());
sideTopBottom(Compressedtnt.TNT_128.get());
sideTopBottom(blocks.TNT_8.get());
sideTopBottom(blocks.TNT_16.get());
sideTopBottom(blocks.TNT_32.get());
sideTopBottom(blocks.TNT_64.get());
sideTopBottom(blocks.TNT_128.get());
sideTopBottom(blocks.TNT_CLUSTER_2.get());
sideTopBottom(blocks.TNT_CLUSTER_4.get());
sideTopBottom(blocks.TNT_CLUSTER_8.get());
}
private void blockWithItem(RegistryObject<Block> blockRegistryObject) {

View File

@ -0,0 +1,25 @@
package com.jenny.compressedtnt.entities;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
public class ClusterPrimedTNT extends basePrimedTNT {
public ClusterPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, Vec3 move) {
super(entities.TNT_CLUSTER.get(), pLevel, pOwner);
this.setPos(pX, pY, pZ);
this.setFuse(fuse);
this.setPower(power);
this.addDeltaMovement(move);
this.setRenderID("cluster");
}
public ClusterPrimedTNT(EntityType<ClusterPrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("cluster");
}
}

View File

@ -0,0 +1,34 @@
package com.jenny.compressedtnt.entities;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import javax.annotation.Nullable;
public class StrongerPrimedTNT extends basePrimedTNT {
public StrongerPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
super(entities.TNT_STRONGER.get(), pLevel, pOwner);
this.setPos(pX, pY, pZ);
this.setFuse(fuse);
this.setPower(power);
this.setRenderID(evalRenderID());
}
public StrongerPrimedTNT(EntityType<StrongerPrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID(evalRenderID());
}
public String evalRenderID() {
int a = (int) this.getPower();
return switch ((int) this.getPower()) {
case 8 -> "stronger_8";
case 16 -> "stronger_16";
case 32 -> "stronger_32";
case 64 -> "stronger_64";
case 128 -> "stronger_128";
default -> "default";
};
}
}

View File

@ -0,0 +1,119 @@
package com.jenny.compressedtnt.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.level.Level;
import javax.annotation.Nullable;
public abstract class basePrimedTNT extends Entity implements TraceableEntity {
private static final EntityDataAccessor<Integer> DATA_FUSE_ID = SynchedEntityData.defineId(basePrimedTNT.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Float> DATA_POWER_ID = SynchedEntityData.defineId(basePrimedTNT.class, EntityDataSerializers.FLOAT);
private static final EntityDataAccessor<String> DATA_RENDER_ID = SynchedEntityData.defineId(basePrimedTNT.class, EntityDataSerializers.STRING);
@Nullable
private LivingEntity owner;
private String renderID = "default";
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner) {
super(pEntityType, pLevel);
double d0 = pLevel.random.nextDouble() * (double)((float)Math.PI * 2F);
this.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D);
this.blocksBuilding = true;
this.owner = owner;
}
protected void explode() {
this.level().explode(this, this.getX(), this.getY(0.0625D), this.getZ(), this.getPower(), Level.ExplosionInteraction.TNT);
}
public int getFuse() {
return this.entityData.get(DATA_FUSE_ID);
}
public void setFuse(int fuse) {
this.entityData.set(DATA_FUSE_ID, fuse);
}
public float getPower() {
return this.entityData.get(DATA_POWER_ID);
}
public void setPower(float power) {
this.entityData.set(DATA_POWER_ID, power);
}
public void tick() {
if (!this.isNoGravity()) {
this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D));
}
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.98D));
if (this.onGround()) {
this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, -0.5D, 0.7D));
}
int i = this.getFuse() - 1;
this.setFuse(i);
if (i <= 0) {
this.discard();
if (!this.level().isClientSide) {
this.explode();
}
} else {
this.updateInWaterStateAndDoFluidPushing();
if (this.level().isClientSide) {
this.level().addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D);
}
}
}
public boolean isPickable() {
return !this.isRemoved();
}
protected Entity.MovementEmission getMovementEmission() {
return Entity.MovementEmission.NONE;
}
protected void defineSynchedData() {
this.entityData.define(DATA_FUSE_ID, 80);
this.entityData.define(DATA_POWER_ID, 4.0f);
this.entityData.define(DATA_RENDER_ID, "default");
}
protected void addAdditionalSaveData(CompoundTag pCompound) {
pCompound.putShort("Fuse", (short)this.getFuse());
pCompound.putFloat("Power", (short)this.getPower());
pCompound.putString("RenderID", getRenderID());
}
protected void readAdditionalSaveData(CompoundTag pCompound) {
this.setFuse(pCompound.getShort("Fuse"));
this.setPower(pCompound.getFloat("Power"));
this.setRenderID(pCompound.getString("RenderID"));
}
@Nullable
public LivingEntity getOwner() {
return this.owner;
}
public void setOwner(LivingEntity owner) {
this.owner = owner;
}
public void setRenderID(String renderID) {
this.entityData.set(DATA_RENDER_ID, renderID);
}
public String getRenderID() {
return this.entityData.get(DATA_RENDER_ID);
}
}

View File

@ -0,0 +1,66 @@
package com.jenny.compressedtnt.entities.client;
import com.jenny.compressedtnt.blocks.blocks;
import com.jenny.compressedtnt.entities.basePrimedTNT;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.TntMinecartRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;
public class BaseTNTRenderer extends EntityRenderer<basePrimedTNT> {
private final BlockRenderDispatcher blockRenderer;
public BaseTNTRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.shadowRadius = 0.5F;
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(basePrimedTNT pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight) {
pPoseStack.pushPose();
pPoseStack.translate(0.0F, 0.5F, 0.0F);
int i = pEntity.getFuse();
if ((float)i - pPartialTicks + 1.0F < 10.0F) {
float f = 1.0F - ((float)i - pPartialTicks + 1.0F) / 10.0F;
f = Mth.clamp(f, 0.0F, 1.0F);
f *= f;
f *= f;
float f1 = 1.0F + f * 0.3F;
pPoseStack.scale(f1, f1, f1);
}
String renderID = pEntity.getRenderID();
if (renderID == null) {
renderID = "";
}
Block block = switch (renderID) {
case "stronger_8" -> blocks.TNT_8.get();
case "stronger_16" -> blocks.TNT_16.get();
case "stronger_32" -> blocks.TNT_32.get();
case "stronger_64" -> blocks.TNT_64.get();
case "stronger_128" -> blocks.TNT_128.get();
case "homing" -> blocks.TNT_HOMING.get();
default -> Blocks.NETHER_PORTAL; // placeholder for debugging
};
pPoseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
pPoseStack.translate(-0.5F, -0.5F, 0.5F);
pPoseStack.mulPose(Axis.YP.rotationDegrees(90.0F));
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, block.defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
@NotNull
public ResourceLocation getTextureLocation(@NotNull basePrimedTNT pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}

View File

@ -0,0 +1,53 @@
package com.jenny.compressedtnt.entities.client;
import com.jenny.compressedtnt.entities.ClusterPrimedTNT;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.TntMinecartRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;
public class clusterTNTRenderer extends EntityRenderer<ClusterPrimedTNT> {
private final BlockRenderDispatcher blockRenderer;
public clusterTNTRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.shadowRadius = 0.5F;
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(ClusterPrimedTNT pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight) {
pPoseStack.pushPose();
pPoseStack.translate(0.0F, 0.5F, 0.0F);
int i = pEntity.getFuse();
if ((float)i - pPartialTicks + 1.0F < 10.0F) {
float f = 1.0F - ((float)i - pPartialTicks + 1.0F) / 10.0F;
f = Mth.clamp(f, 0.0F, 1.0F);
f *= f;
f *= f;
float f1 = 0.5f + f * 0.3F;
pPoseStack.scale(f1, f1, f1);
}
else {
pPoseStack.scale(0.5f, 0.5f, 0.5f);
}
pPoseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
pPoseStack.translate(-0.5F, -0.5F, 0.5F);
pPoseStack.mulPose(Axis.YP.rotationDegrees(90.0F));
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, Blocks.TNT.defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
public @NotNull ResourceLocation getTextureLocation(@NotNull ClusterPrimedTNT pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}

View File

@ -0,0 +1,42 @@
package com.jenny.compressedtnt.entities;
import com.jenny.compressedtnt.entities.client.BaseTNTRenderer;
import com.jenny.compressedtnt.entities.client.clusterTNTRenderer;
import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import static com.jenny.compressedtnt.Compressedtnt.MODID;
public class entities {
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES =
DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID);
public static final RegistryObject<EntityType<homingPrimedTNT>> TNT_HOMING =
ENTITY_TYPES.register("tnt_homing", () -> EntityType.Builder.<homingPrimedTNT>of(homingPrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_homing"));
public static final RegistryObject<EntityType<StrongerPrimedTNT>> TNT_STRONGER =
ENTITY_TYPES.register("tnt_stronger", () -> EntityType.Builder.<StrongerPrimedTNT>of(StrongerPrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_stronger"));
public static final RegistryObject<EntityType<ClusterPrimedTNT>> TNT_CLUSTER =
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 void register(IEventBus eventBus) {
ENTITY_TYPES.register(eventBus);
}
public static void registerRenderers () {
EntityRenderers.register(TNT_STRONGER.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_HOMING.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_CLUSTER.get(), clusterTNTRenderer::new);
}
}

View File

@ -0,0 +1,70 @@
package com.jenny.compressedtnt.entities;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
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;
public class homingPrimedTNT extends basePrimedTNT {
float speed = 0;
Entity target;
public homingPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, float speed) {
super(entities.TNT_HOMING.get(), pLevel, pOwner);
this.setPos(pX, pY, pZ);
this.setOwner(pOwner);
this.speed = speed;
this.target = null;
this.setPower(power);
this.setFuse(fuse);
this.setRenderID("homing");
}
public homingPrimedTNT(EntityType<homingPrimedTNT> entityType, Level level) {
super(entityType, level, null);
}
private Vec3 targetVector() {
double targetDist = getTargetDist();
Vec3 targetVec = new Vec3(0, 0, 0);
if (targetDist > 3) {
targetVec = new Vec3(target.getX() - this.getX(), target.getY() - this.getY(), target.getZ() - this.getZ()).normalize().multiply(speed, speed, speed);
if (targetDist < 10) {
targetVec.multiply(targetDist / 10, targetDist / 10, targetDist / 10);
}
}
return targetVec;
}
public double getTargetDist() {
return new Vec3(target.getX(), target.getY(), target.getZ()).subtract(this.getX(), this.getY(), this.getZ()).length();
}
public void findTarget() {
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);
}
@Override
public void tick() {
if (target == null) {
findTarget();
}
else {
if (getTargetDist() > 15) {target = null;} else {addDeltaMovement(targetVector());}
}
super.tick();
}
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
return 0.15F;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,13 @@
{
"type": "minecraft:crafting_shapeless",
"category": "redstone",
"ingredients":[
{
"item": "minecraft:tnt",
"count": 2
}
],
"result": {
"item": "compressedtnt:tnt_cluster_2"
}
}

View File

@ -0,0 +1,13 @@
{
"type": "minecraft:crafting_shapeless",
"category": "redstone",
"ingredients":[
{
"item": "minecraft:tnt",
"count": 4
}
],
"result": {
"item": "compressedtnt:tnt_cluster_4"
}
}

View File

@ -0,0 +1,13 @@
{
"type": "minecraft:crafting_shapeless",
"category": "redstone",
"ingredients":[
{
"item": "compressedtnt:tnt_cluster_2",
"count": 2
}
],
"result": {
"item": "compressedtnt:tnt_cluster_4"
}
}

View File

@ -0,0 +1,13 @@
{
"type": "minecraft:crafting_shapeless",
"category": "redstone",
"ingredients":[
{
"item": "minecraft:tnt",
"count": 8
}
],
"result": {
"item": "compressedtnt:tnt_cluster_8"
}
}

View File

@ -0,0 +1,13 @@
{
"type": "minecraft:crafting_shapeless",
"category": "redstone",
"ingredients":[
{
"item": "compressedtnt:tnt_cluster_2",
"count": 4
}
],
"result": {
"item": "compressedtnt:tnt_cluster_8"
}
}

View File

@ -0,0 +1,13 @@
{
"type": "minecraft:crafting_shapeless",
"category": "redstone",
"ingredients":[
{
"item": "compressedtnt:tnt_cluster_4",
"count": 2
}
],
"result": {
"item": "compressedtnt:tnt_cluster_8"
}
}

View File

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