Start making a particle
This commit is contained in:
parent
835530ce13
commit
c20960c005
9 changed files with 136 additions and 21 deletions
|
@ -6,11 +6,18 @@ import org.dimdev.dimdoors.client.ModSkyRendering;
|
|||
import org.dimdev.dimdoors.entity.ModEntityTypes;
|
||||
import org.dimdev.dimdoors.entity.MonolithEntity;
|
||||
import org.dimdev.dimdoors.fluid.ModFluids;
|
||||
import org.dimdev.dimdoors.particle.ModParticleTypes;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class DimensionalDoorsClientInitializer implements ClientModInitializer {
|
||||
|
@ -21,7 +28,8 @@ public class DimensionalDoorsClientInitializer implements ClientModInitializer {
|
|||
ModFluids.initClient();
|
||||
ModBlockEntityTypes.initClient();
|
||||
ModBlocks.initClient();
|
||||
ModParticleTypes.initClient();
|
||||
|
||||
ClientSidePacketRegistry.INSTANCE.register(DimensionalDoorsInitializer.MONOLITH_PARTICLE_PACKET, MonolithEntity::spawnParticles);
|
||||
ClientPlayNetworking.registerReceiver(DimensionalDoorsInitializer.MONOLITH_PARTICLE_PACKET, (client, networkHandler, buf, sender) -> MonolithEntity.spawnParticles(buf, client));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.dimdev.dimdoors.entity.ModEntityTypes;
|
|||
import org.dimdev.dimdoors.entity.stat.ModStats;
|
||||
import org.dimdev.dimdoors.fluid.ModFluids;
|
||||
import org.dimdev.dimdoors.item.ModItems;
|
||||
import org.dimdev.dimdoors.particle.ModParticleTypes;
|
||||
import org.dimdev.dimdoors.pockets.SchematicHandler;
|
||||
import org.dimdev.dimdoors.pockets.SchematicV2Handler;
|
||||
import org.dimdev.dimdoors.rift.targets.Targets;
|
||||
|
@ -71,6 +72,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
|
|||
ModCommands.init();
|
||||
ModFluids.init();
|
||||
ModSoundEvents.init();
|
||||
ModParticleTypes.init();
|
||||
|
||||
ModConfig.deserialize();
|
||||
|
||||
|
|
|
@ -33,4 +33,4 @@ public class MonolithModel extends EntityModel<MonolithEntity> {
|
|||
this.body.yaw = netHeadYaw * 0.017453292F;
|
||||
this.body.pitch = headPitch * 0.017453292F;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.dimdev.dimdoors.client;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.dimdev.dimdoors.entity.MonolithEntity;
|
||||
|
||||
|
@ -12,7 +13,7 @@ import net.minecraft.util.Identifier;
|
|||
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
|
||||
|
||||
public class MonolithRenderer extends LivingEntityRenderer<MonolithEntity, MonolithModel> {
|
||||
private static final List<Identifier> MONOLITH_TEXTURES = Lists.newArrayList(
|
||||
public static final List<Identifier> MONOLITH_TEXTURES = ImmutableList.of(
|
||||
new Identifier("dimdoors:textures/mob/monolith/monolith0.png"),
|
||||
new Identifier("dimdoors:textures/mob/monolith/monolith1.png"),
|
||||
new Identifier("dimdoors:textures/mob/monolith/monolith2.png"),
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.dimdev.dimdoors.item.ModItems;
|
|||
import org.dimdev.dimdoors.sound.ModSoundEvents;
|
||||
import org.dimdev.dimdoors.world.ModDimensions;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.EntityDimensions;
|
||||
import net.minecraft.entity.EntityPose;
|
||||
import net.minecraft.entity.EntityType;
|
||||
|
@ -33,6 +34,7 @@ import net.minecraft.world.WorldAccess;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.network.PacketContext;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketSender;
|
||||
|
||||
public class MonolithEntity extends MobEntity {
|
||||
public final EntityDimensions DIMENSIONS = EntityDimensions.fixed(3f, 6f);
|
||||
|
@ -231,25 +233,25 @@ public class MonolithEntity extends MobEntity {
|
|||
return EYE_HEIGHT;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static void spawnParticles(PacketContext context, PacketByteBuf data) {
|
||||
PlayerEntity player = context.getPlayer();
|
||||
int aggro = data.readInt();
|
||||
public static void spawnParticles(PacketByteBuf data, MinecraftClient client) {
|
||||
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||
int aggro = data.readInt();
|
||||
|
||||
context.getTaskQueue().execute(() -> {
|
||||
if (aggro < 120) {
|
||||
return;
|
||||
}
|
||||
int count = 10 * aggro / MAX_AGGRO;
|
||||
for (int i = 1; i < count; ++i) {
|
||||
player.world.addParticle(ParticleTypes.PORTAL, player.getX() + (random.nextDouble() - 0.5D) * 3.0,
|
||||
player.getY() + random.nextDouble() * player.getHeight() - 0.75D,
|
||||
player.getZ() + (random.nextDouble() - 0.5D) * player.getWidth(),
|
||||
(random.nextDouble() - 0.5D) * 2.0D, -random.nextDouble(),
|
||||
(random.nextDouble() - 0.5D) * 2.0D);
|
||||
}
|
||||
});
|
||||
}
|
||||
client.execute(() -> {
|
||||
if (aggro < 120) {
|
||||
return;
|
||||
}
|
||||
int count = 10 * aggro / MAX_AGGRO;
|
||||
for (int i = 1; i < count; ++i) {
|
||||
//noinspection ConstantConditions
|
||||
player.world.addParticle(ParticleTypes.PORTAL, player.getX() + (random.nextDouble() - 0.5D) * 3.0,
|
||||
player.getY() + random.nextDouble() * player.getHeight() - 0.75D,
|
||||
player.getZ() + (random.nextDouble() - 0.5D) * player.getWidth(),
|
||||
(random.nextDouble() - 0.5D) * 2.0D, -random.nextDouble(),
|
||||
(random.nextDouble() - 0.5D) * 2.0D);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public float getAggroProgress() {
|
||||
return (float) this.aggro / MAX_AGGRO;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package org.dimdev.dimdoors.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
|
||||
@Mixin(DefaultParticleType.class)
|
||||
public interface DefaultParticleTypeAccessor {
|
||||
@Invoker("<init>")
|
||||
static DefaultParticleType createDefaultParticleType(boolean alwaysShow) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package org.dimdev.dimdoors.particle;
|
||||
|
||||
import org.dimdev.dimdoors.mixin.DefaultParticleTypeAccessor;
|
||||
import org.dimdev.dimdoors.particle.client.MonolithParticle;
|
||||
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
|
||||
|
||||
public class ModParticleTypes {
|
||||
public static final DefaultParticleType MONOLITH = DefaultParticleTypeAccessor.createDefaultParticleType(false);
|
||||
|
||||
public static void init() {
|
||||
Registry.register(Registry.PARTICLE_TYPE, new Identifier("dimdoors", "monolith"), MONOLITH);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public static void initClient() {
|
||||
ParticleFactoryRegistry.getInstance().register(MONOLITH, new MonolithParticle.Factory());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package org.dimdev.dimdoors.particle.client;
|
||||
|
||||
import org.dimdev.dimdoors.client.MonolithModel;
|
||||
import org.dimdev.dimdoors.client.MonolithRenderer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.particle.ParticleFactory;
|
||||
import net.minecraft.client.particle.ParticleTextureSheet;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.particle.DefaultParticleType;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class MonolithParticle extends Particle {
|
||||
private final MonolithModel model;
|
||||
private final RenderLayer layer;
|
||||
|
||||
private MonolithParticle(ClientWorld world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
this.maxAge = 30;
|
||||
this.model = new MonolithModel();
|
||||
this.layer = RenderLayer.getEntitySolid(MonolithRenderer.MONOLITH_TEXTURES.get(14));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildGeometry(VertexConsumer vertexConsumer, Camera camera, float tickDelta) {
|
||||
float delta = ((float)this.age + tickDelta) / (float)this.maxAge;
|
||||
MatrixStack matrices = new MatrixStack();
|
||||
matrices.multiply(camera.getRotation());
|
||||
matrices.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(150.0F * delta - 60.0F));
|
||||
matrices.scale(-1.0F, -1.0F, 1.0F);
|
||||
matrices.translate(0.0D, -1.1009999513626099D, 1.5D);
|
||||
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
|
||||
VertexConsumer vertexConsumer2 = immediate.getBuffer(this.layer);
|
||||
this.model.render(matrices, vertexConsumer2, 0xf000f0, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
|
||||
immediate.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleTextureSheet getType() {
|
||||
return ParticleTextureSheet.CUSTOM;
|
||||
}
|
||||
|
||||
public static class Factory implements ParticleFactory<DefaultParticleType> {
|
||||
@Nullable
|
||||
@Override
|
||||
public Particle createParticle(DefaultParticleType parameters, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
|
||||
return new MonolithParticle(world, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
"ChunkGeneratorAccessor",
|
||||
"ChunkGeneratorSettingsAccessor",
|
||||
"DefaultBiomeFeaturesMixin",
|
||||
"DefaultParticleTypeAccessor",
|
||||
"DimensionTypeAccessor",
|
||||
"DirectionAccessor",
|
||||
"GenerationSettingsAccessor",
|
||||
|
|
Loading…
Reference in a new issue