More porting

This commit is contained in:
Mrbysco 2024-07-24 21:16:44 +02:00
parent 0f9d017634
commit 856e07a521
5 changed files with 33 additions and 44 deletions

View file

@ -10,16 +10,13 @@ import net.minecraft.network.codec.StreamCodec;
import javax.annotation.Nonnull;
public record BeamParticleData(double endX, double endY, double endZ, float red, float green, float blue, float alpha,
int maxAge, double rotationTime, float size) implements ParticleOptions {
public record BeamParticleData(double endX, double endY, double endZ, int color, int maxAge, double rotationTime,
float size) implements ParticleOptions {
public static final MapCodec<BeamParticleData> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
Codec.DOUBLE.fieldOf("endX").forGetter(d -> d.endX),
Codec.DOUBLE.fieldOf("endY").forGetter(d -> d.endY),
Codec.DOUBLE.fieldOf("endZ").forGetter(d -> d.endZ),
Codec.FLOAT.fieldOf("r").forGetter(d -> d.red),
Codec.FLOAT.fieldOf("g").forGetter(d -> d.green),
Codec.FLOAT.fieldOf("b").forGetter(d -> d.blue),
Codec.FLOAT.fieldOf("alpha").forGetter(d -> d.alpha),
Codec.INT.fieldOf("color").forGetter(d -> d.color),
Codec.INT.fieldOf("maxAge").forGetter(d -> d.maxAge),
Codec.DOUBLE.fieldOf("rotationTime").forGetter(d -> d.rotationTime),
Codec.FLOAT.fieldOf("size").forGetter(d -> d.size)
@ -30,17 +27,15 @@ public record BeamParticleData(double endX, double endY, double endZ, float red,
);
public static BeamParticleData fromNetwork(@Nonnull RegistryFriendlyByteBuf pBuffer) {
return new BeamParticleData(pBuffer.readDouble(), pBuffer.readDouble(), pBuffer.readDouble(), pBuffer.readFloat(), pBuffer.readFloat(), pBuffer.readFloat(), pBuffer.readFloat(), pBuffer.readInt(), pBuffer.readDouble(), pBuffer.readFloat());
return new BeamParticleData(pBuffer.readDouble(), pBuffer.readDouble(), pBuffer.readDouble(), pBuffer.readInt(),
pBuffer.readInt(), pBuffer.readDouble(), pBuffer.readFloat());
}
public static void toNetwork(@Nonnull RegistryFriendlyByteBuf pBuffer, BeamParticleData pRecipe) {
pBuffer.writeDouble(pRecipe.endX());
pBuffer.writeDouble(pRecipe.endY());
pBuffer.writeDouble(pRecipe.endZ());
pBuffer.writeFloat(pRecipe.red());
pBuffer.writeFloat(pRecipe.green());
pBuffer.writeFloat(pRecipe.blue());
pBuffer.writeFloat(pRecipe.alpha());
pBuffer.writeInt(pRecipe.color());
pBuffer.writeInt(pRecipe.maxAge());
pBuffer.writeDouble(pRecipe.rotationTime());
pBuffer.writeFloat(pRecipe.size());

View file

@ -13,8 +13,10 @@ package de.ellpeck.actuallyadditions.mod.particle;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
@ -25,22 +27,18 @@ import net.minecraft.client.particle.SpriteSet;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.util.FastColor;
import org.jetbrains.annotations.Nullable;
public class ParticleBeam extends Particle {
public static final ParticleRenderType LASER_RENDER = new ParticleRenderType() {
@Nullable
@Override
public void begin(BufferBuilder buffer, TextureManager textureManager) {
public BufferBuilder begin(Tesselator tesselator, TextureManager textureManager) {
RenderSystem.disableCull();
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
}
@Override
public void end(Tesselator tesselator) {
RenderSystem.enableCull();
RenderSystem.disableBlend();
RenderSystem.defaultBlendFunc();
return tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
}
@Override
@ -52,13 +50,13 @@ public class ParticleBeam extends Particle {
private final double endX;
private final double endY;
private final double endZ;
private final float[] color;
private final int color;
private final double rotationTime;
private final float size;
private final float alpha;
public ParticleBeam(ClientLevel world, double startX, double startY, double startZ, double endX, double endY, double endZ,
float[] color, float alpha, int maxAge, double rotationTime, float size) {
int color, int maxAge, double rotationTime, float size) {
super(world, startX, startY, startZ);
this.endX = endX;
this.endY = endY;
@ -67,7 +65,7 @@ public class ParticleBeam extends Particle {
this.rotationTime = rotationTime;
this.size = size;
this.lifetime = maxAge;
this.alpha = alpha;
this.alpha = FastColor.ARGB32.alpha(color) / 255.0F;
}
@Override
@ -89,26 +87,20 @@ public class ParticleBeam extends Particle {
}
@Override
public Particle createParticle(BeamParticleData data, ClientLevel worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
return new ParticleBeam(worldIn, x, y, z, data.endX, data.endY, data.endZ, data.color, data.alpha, data.maxAge,
data.rotationTime, data.size);
public Particle createParticle(BeamParticleData data, ClientLevel worldIn, double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed) {
return new ParticleBeam(worldIn, x, y, z, data.endX(), data.endY(), data.endZ(), data.color(), data.maxAge(),
data.rotationTime(), data.size());
}
public static ParticleOptions createData(double endX, double endY, double endZ, float[] color, float alpha,
public static ParticleOptions createData(double endX, double endY, double endZ, int color,
int maxAge, double rotationTime, float size) {
return new BeamParticleData(endX, endY, endZ, color, alpha, maxAge, rotationTime, size);
return new BeamParticleData(endX, endY, endZ, color, maxAge, rotationTime, size);
}
public static ParticleOptions createData(double endX, double endY, double endZ, int color, float alpha,
int maxAge, double rotationTime, float size) {
return new BeamParticleData(endX, endY, endZ, colorFromInt(color), alpha, maxAge, rotationTime, size);
}
private static float[] colorFromInt(int color) {
float red = (float)(FastColor.ARGB32.red(color) / 255.0);
float green = (float)(FastColor.ARGB32.green(color) / 255.0);
float blue = (float)(FastColor.ARGB32.blue(color) / 255.0);
return new float[] {red, green, blue};
return new BeamParticleData(endX, endY, endZ, color, maxAge, rotationTime, size);
}
}
}

View file

@ -118,7 +118,7 @@ public class ParticleLaserItem extends Particle {
@Override
public Particle createParticle(LaserItemParticleData data, ClientLevel worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
return new ParticleLaserItem(worldIn, x, y, z, data.stack, ySpeed, data.outputX, data.outputY, data.outputZ);
return new ParticleLaserItem(worldIn, x, y, z, data.stack(), ySpeed, data.outputX(), data.outputY(), data.outputZ());
}
public static ParticleOptions createData(ItemStack stack, double outputX, double outputY, double outputZ) {

View file

@ -37,6 +37,7 @@ import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.FastColor;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemDisplayContext;
@ -327,13 +328,14 @@ public final class AssetUtil {
//Thanks to feldim2425 for this.
//I can't do rendering code. Ever.
public static void renderLaserParticle(VertexConsumer builder, Camera camera, double firstX, double firstY, double firstZ, double secondX, double secondY, double secondZ, float rotationTime, float a, float beamWidth, float[] color) {
public static void renderLaserParticle(VertexConsumer builder, Camera camera, double firstX, double firstY, double firstZ,
double secondX, double secondY, double secondZ, float rotationTime, float a, float beamWidth, int color) {
Level world = Minecraft.getInstance().level;
Vec3 cam = camera.getPosition();
float r = color[0];
float g = color[1];
float b = color[2];
float r = FastColor.ARGB32.red(color) / 255.0F;
float g = FastColor.ARGB32.green(color) / 255.0F;
float b = FastColor.ARGB32.blue(color) / 255.0F;
Vec3 vec1 = new Vec3(firstX, firstY, firstZ);
Vec3 vec2 = new Vec3(secondX, secondY, secondZ);

View file

@ -264,7 +264,7 @@ public final class WorldUtil {
BreakEvent event = new BreakEvent(level, pos, state, fake);
NeoForge.EVENT_BUS.post(event);
if (!event.isCanceled()) {
return EventHooks.doPlayerHarvestCheck(fake, state, true) ? 1F : 0F;
return EventHooks.doPlayerHarvestCheck(fake, state, level, pos) ? 1F : 0F;
//return ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1, false, fake); //TODO what?!
}
}
@ -302,8 +302,8 @@ public final class WorldUtil {
// server sided handling
if (!level.isClientSide) {
// send the blockbreak event
int xp = CommonHooks.onBlockBreakEvent(level, ((ServerPlayer) player).gameMode.getGameModeForPlayer(), (ServerPlayer) player, pos);
if (xp == -1) {
var event = CommonHooks.fireBlockBreak(level, ((ServerPlayer) player).gameMode.getGameModeForPlayer(), (ServerPlayer) player, pos, state);
if (event.isCanceled()) {
return false;
}
@ -311,7 +311,7 @@ public final class WorldUtil {
if (block.onDestroyedByPlayer(state, level, pos, player, true, state.getFluidState())) { // boolean is if block can be harvested, checked above
block.destroy(level, pos, state);
block.playerDestroy(level, player, pos, state, blockEntity, stack);
block.popExperience(((ServerLevel) level), pos, xp);
// block.popExperience(((ServerLevel) level), pos, xp);
}
// always send block update to client