Nuke fixes and improvements

This commit is contained in:
modmuss50 2023-05-16 11:03:35 +01:00 committed by modmuss
parent 898476ffb6
commit 8f8de066f6
4 changed files with 72 additions and 23 deletions

View file

@ -27,11 +27,12 @@ package techreborn;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.minecraft.client.item.ClampedModelPredicateProvider;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.Baker;
import net.minecraft.client.render.model.ModelBakeSettings;
@ -63,6 +64,7 @@ import techreborn.client.render.BaseDynamicFluidBakedModel;
import techreborn.client.render.DynamicBucketBakedModel;
import techreborn.client.render.DynamicCellBakedModel;
import techreborn.client.render.entitys.CableCoverRenderer;
import techreborn.client.render.entitys.NukeRenderer;
import techreborn.client.render.entitys.StorageUnitRenderer;
import techreborn.client.render.entitys.TurbineRenderer;
import techreborn.init.ModFluids;
@ -141,18 +143,20 @@ public class TechRebornClient implements ClientModInitializer {
BlockRenderLayerMap.INSTANCE.putFluid(fluid.getFlowingFluid(), RenderLayer.getTranslucent());
}
BlockEntityRendererRegistry.register(TRBlockEntities.INDUSTRIAL_GRINDER, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.FUSION_CONTROL_COMPUTER, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.INDUSTRIAL_BLAST_FURNACE, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.VACUUM_FREEZER, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.FLUID_REPLICATOR, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.INDUSTRIAL_SAWMILL, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.DISTILLATION_TOWER, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.IMPLOSION_COMPRESSOR, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.GREENHOUSE_CONTROLLER, MultiblockRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.STORAGE_UNIT, StorageUnitRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.CABLE, CableCoverRenderer::new);
BlockEntityRendererRegistry.register(TRBlockEntities.WIND_MILL, TurbineRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.INDUSTRIAL_GRINDER, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.FUSION_CONTROL_COMPUTER, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.INDUSTRIAL_BLAST_FURNACE, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.VACUUM_FREEZER, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.FLUID_REPLICATOR, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.INDUSTRIAL_SAWMILL, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.DISTILLATION_TOWER, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.IMPLOSION_COMPRESSOR, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.GREENHOUSE_CONTROLLER, MultiblockRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.STORAGE_UNIT, StorageUnitRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.CABLE, CableCoverRenderer::new);
BlockEntityRendererFactories.register(TRBlockEntities.WIND_MILL, TurbineRenderer::new);
EntityRendererRegistry.register(TRContent.ENTITY_NUKE, NukeRenderer::new);
registerPredicateProvider(
BatpackItem.class,

View file

@ -59,7 +59,7 @@ public class NukeRenderer extends EntityRenderer<EntityNukePrimed> {
@Override
public void render(EntityNukePrimed entity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
matrixStack.push();
matrixStack.translate(0.0D, 0.5D, 0.0D);
matrixStack.translate(1D, 0.5D, 0);
if ((float) entity.getFuse() - g + 1.0F < 10.0F) {
float h = 1.0F - ((float) entity.getFuse() - g + 1.0F) / 10.0F;
h = MathHelper.clamp(h, 0.0F, 1.0F);

View file

@ -28,26 +28,50 @@ import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.TntEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.entity.boss.BossBar;
import net.minecraft.entity.boss.ServerBossBar;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.explosion.RebornExplosion;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
/**
* Created by Mark on 13/03/2016.
*/
public class EntityNukePrimed extends TntEntity {
@Nullable LivingEntity owner;
public EntityNukePrimed(EntityType<EntityNukePrimed> entityType, World world) {
super(entityType, world);
private final ServerBossBar bossBar = new ServerBossBar(Text.translatable("block.techreborn.nuke"), BossBar.Color.RED, BossBar.Style.PROGRESS);
public EntityNukePrimed(EntityType<? extends EntityNukePrimed> type, World world) {
super(type, world);
setFuse(TechRebornConfig.nukeFuseTime);
}
public EntityNukePrimed(World world, double x, double y, double z, LivingEntity tntPlacedBy) {
super(world, x, y, z, tntPlacedBy);
public EntityNukePrimed(World world, double x, double y, double z, LivingEntity owner) {
this(TRContent.ENTITY_NUKE, world);
this.setPosition(x, y, z);
double d = world.random.nextDouble() * 6.2831854820251465;
this.setVelocity(-Math.sin(d) * 0.02, 0.2f, -Math.cos(d) * 0.02);
this.setFuse(80);
this.prevX = x;
this.prevY = y;
this.prevZ = z;
this.owner = owner;
setFuse(TechRebornConfig.nukeFuseTime);
}
@Nullable
@Override
public LivingEntity getOwner() {
return owner;
}
@Override
public void tick() {
if (!this.hasNoGravity()) {
@ -61,6 +85,8 @@ public class EntityNukePrimed extends TntEntity {
}
setFuse(getFuse() - 1);
bossBar.setPercent((float) getFuse() / TechRebornConfig.nukeFuseTime);
if (this.getFuse() <= 0) {
this.remove(RemovalReason.KILLED);
if (!this.getWorld().isClient) {
@ -68,9 +94,6 @@ public class EntityNukePrimed extends TntEntity {
}
} else {
this.updateWaterState();
if (this.getWorld().isClient) {
this.getWorld().addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D);
}
}
}
@ -82,4 +105,16 @@ public class EntityNukePrimed extends TntEntity {
nukeExplosion.setLivingBase(getOwner());
nukeExplosion.applyExplosion();
}
@Override
public void onStartedTrackingBy(ServerPlayerEntity player) {
super.onStartedTrackingBy(player);
this.bossBar.addPlayer(player);
}
@Override
public void onStoppedTrackingBy(ServerPlayerEntity player) {
super.onStoppedTrackingBy(player);
this.bossBar.removePlayer(player);
}
}

View file

@ -28,12 +28,16 @@ import com.google.common.base.Preconditions;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.type.BlockSetTypeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.block.type.WoodTypeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.block.*;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
@ -1587,10 +1591,16 @@ public class TRContent {
}
}
public static EntityType<EntityNukePrimed> ENTITY_NUKE;
public static EntityType<EntityNukePrimed> ENTITY_NUKE = FabricEntityTypeBuilder.create()
.entityFactory((EntityType.EntityFactory<EntityNukePrimed>) EntityNukePrimed::new)
.dimensions(EntityDimensions.fixed(1f, 1f))
.trackRangeChunks(10)
.build();
static {
ModRegistry.register();
TRItemGroup.register();
Registry.register(Registries.ENTITY_TYPE, new Identifier(TechReborn.MOD_ID, "nuke"), ENTITY_NUKE);
}
}