Skip to content

Commit

Permalink
fix server crash
Browse files Browse the repository at this point in the history
  • Loading branch information
IAFEnvoy committed Nov 22, 2024
1 parent 70bda05 commit 05db3b8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.16.9
# Mod Properties
mod_version=1.1
mod_version=1.1.1
maven_group=com.iafenvoy.banner
archives_base_name=MobsBanner
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.iafenvoy.mobsbanner.component.BannerBlockComponent;
import com.iafenvoy.mobsbanner.component.CcaComponentHelper;
import com.iafenvoy.mobsbanner.cursed.DummyClientPlayerEntity;
import com.iafenvoy.mobsbanner.data.DefaultMobBannerData;
import com.iafenvoy.mobsbanner.util.DyeColorUtil;
import com.mojang.datafixers.util.Pair;
Expand Down Expand Up @@ -113,9 +112,7 @@ public static ItemStack create(Identifier id, Item baseItem, EntityType<?> type,
@Nullable
public static LivingEntity createEntity(EntityType<?> type, NbtCompound nbt, World world) {
if (type == null) return null;
if (type == EntityType.PLAYER)
return DummyClientPlayerEntity.get(nbt.containsUuid("player_uuid") ? nbt.getUuid("player_uuid") : null, nbt.getString("player_name"));
else if (type.create(world) instanceof LivingEntity livingEntity) {
if (type.create(world) instanceof LivingEntity livingEntity) {
try {
livingEntity.readCustomDataFromNbt(nbt);
livingEntity.tick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.iafenvoy.mobsbanner.banner.MobBannerHelper;
import com.iafenvoy.mobsbanner.component.BannerBlockComponent;
import com.iafenvoy.mobsbanner.cursed.DummyClientPlayerEntity;
import com.iafenvoy.mobsbanner.data.DefaultMobBannerData;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -10,6 +11,7 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.LinkedList;
Expand All @@ -28,13 +30,20 @@ public static LivingEntity get(BannerBlockComponent component, BlockPos pos) {
Optional<Cache> cache = CACHE.stream().filter(x -> x.match(component)).findFirst();
if (cache.isPresent()) return cache.get().living;
}
LivingEntity living = MobBannerHelper.createEntity(component.getType(), component.getEntityData(), MinecraftClient.getInstance().world);
LivingEntity living = createEntity(component.getType(), component.getEntityData(), MinecraftClient.getInstance().world);
if (living == null) return null;
if (fulfilled)
CACHE.add(new Cache(component.getType(), component.getEntityData(), component.getTransform(), pos, living));
return living;
}

@Nullable
public static LivingEntity createEntity(EntityType<?> type, NbtCompound nbt, World world) {
if (type == EntityType.PLAYER)
return DummyClientPlayerEntity.get(nbt.containsUuid("player_uuid") ? nbt.getUuid("player_uuid") : null, nbt.getString("player_name"));
return MobBannerHelper.createEntity(type, nbt, world);
}

private record Cache(EntityType<?> type, NbtCompound nbt, DefaultMobBannerData.TransformData transform,
BlockPos pos, LivingEntity living) {
public boolean match(BannerBlockComponent component) {
Expand Down

0 comments on commit 05db3b8

Please sign in to comment.