Skip to content

Commit

Permalink
Actual update woah crazy
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed May 19, 2024
1 parent 34cd467 commit 7bd37b8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 34 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Changed the color of totem particles depending on the shark type used.
- Added an icelandic translation (Thanks @VipelyRS)
- Updated to 1.20.6.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.15.6
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.15.11

# Mod Properties
mod_version=1.3.0
mod_version=1.3.1
maven_group=dev.enjarai.blahajtotem
archives_base_name=blahaj-totem

# Dependencies
fabric_version=0.89.3+1.20.1
fabric_version=0.98.0+1.20.6
3 changes: 2 additions & 1 deletion src/main/java/dev/enjarai/blahajtotem/BlahajTotem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {

@Nullable
public static BlahajType getShorkType(ItemStack stack) {
if (stack.isOf(Items.TOTEM_OF_UNDYING) && stack.hasCustomName()) {
if (stack.isOf(Items.TOTEM_OF_UNDYING) && stack.contains(DataComponentTypes.CUSTOM_NAME)) {
var name = Arrays.asList(stack.getName().getString().toLowerCase(Locale.ROOT).split("[ \\-_]"));
var variant = VARIANTS.stream().filter(v -> name.contains(v.name())).reduce((v1, v2) -> v2.name().length() > v1.name().length() ? v2 : v1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
package dev.enjarai.blahajtotem.particle;

import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import dev.enjarai.blahajtotem.BlahajTotem;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType;
import net.minecraft.registry.Registries;

public record BlahajParticleEffect(ParticleType<BlahajParticleEffect> type, int[] colors) implements ParticleEffect {
@SuppressWarnings("deprecation")
public static final ParticleEffect.Factory<BlahajParticleEffect> PARAMETERS_FACTORY = new ParticleEffect.Factory<>() {
@Override
public BlahajParticleEffect read(ParticleType<BlahajParticleEffect> type, StringReader reader) throws CommandSyntaxException {
return new BlahajParticleEffect(type, new int[0]); // This doesn't actually need to work with commands, so dummy impl it is
}

@Override
public BlahajParticleEffect read(ParticleType<BlahajParticleEffect> type, PacketByteBuf buf) {
return new BlahajParticleEffect(type, buf.readIntArray());
}
};
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.IntStream;

@Override
public ParticleType<?> getType() {
return type;
public record BlahajParticleEffect(ParticleType<BlahajParticleEffect> type, int[] colors) implements ParticleEffect {
public static MapCodec<BlahajParticleEffect> createCodec(ParticleType<BlahajParticleEffect> type) {
return Codec.INT_STREAM.xmap(
intStream -> new BlahajParticleEffect(type, intStream.toArray()),
effect -> IntStream.of(effect.colors)
).fieldOf("colors");
}

@Override
public void write(PacketByteBuf buf) {
buf.writeIntArray(colors);
public static PacketCodec<RegistryByteBuf, BlahajParticleEffect> createPacketCodec(ParticleType<BlahajParticleEffect> type) {
return PacketCodec.tuple(
PacketCodecs.collection(ArrayList::new, PacketCodecs.INTEGER, 32), effect -> Arrays.stream(effect.colors).boxed().toList(),
list -> new BlahajParticleEffect(type, list.stream().mapToInt(i -> i).toArray())
);
}

@Override
public String asString() {
return Registries.PARTICLE_TYPE.getId(getType()) + "";
public ParticleType<?> getType() {
return type;
}

public static int[] getColorsForShork(ItemStack shorkStack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import net.minecraft.registry.Registry;

public class ModParticles {
public static final ParticleType<BlahajParticleEffect> BLAHAJ_OF_UNDYING = FabricParticleTypes.complex(BlahajParticleEffect.PARAMETERS_FACTORY);
public static final ParticleType<BlahajParticleEffect> BLAHAJ_OF_UNDYING =
FabricParticleTypes.complex(BlahajParticleEffect::createCodec, BlahajParticleEffect::createPacketCodec);

public static void register() {
Registry.register(Registries.PARTICLE_TYPE, BlahajTotem.id("blahaj_of_undying"), BLAHAJ_OF_UNDYING);
Expand Down

0 comments on commit 7bd37b8

Please sign in to comment.