Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Mitigate server-side crash
Browse files Browse the repository at this point in the history
  • Loading branch information
florensie committed Dec 17, 2021
1 parent fb4f3a1 commit d3f5a5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.3] - 2021-12-17
### Fixed
- Mitigate a server-side crash

## [4.0.2] - 2021-10-04
### Fixed
- Rollback bundled version of expandability
Expand Down Expand Up @@ -202,7 +206,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release

[Unreleased]: https://github.com/florensie/artifacts-fabric/compare/v4.0.1...HEAD
[Unreleased]: https://github.com/florensie/artifacts-fabric/compare/v4.0.3...HEAD
[4.0.3]: https://github.com/florensie/artifacts-fabric/compare/v4.0.2...v4.0.3
[4.0.2]: https://github.com/florensie/artifacts-fabric/compare/v4.0.1...v4.0.2
[4.0.1]: https://github.com/florensie/artifacts-fabric/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/florensie/artifacts-fabric/compare/v3.2.1...v4.0.0
[3.2.1]: https://github.com/florensie/artifacts-fabric/compare/v3.2.0...v3.2.1
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loader_version=0.11.7
parchment_version=2021.08.29

# Mod Properties
mod_version=4.0.2+fabric
mod_version=4.0.3+fabric
maven_group=artifacts
archives_base_name=artifacts

Expand Down
29 changes: 7 additions & 22 deletions src/main/java/artifacts/components/EntityKillTrackerComponent.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package artifacts.components;

import artifacts.mixin.extensions.DefaultedRegistryExtensions;
import com.google.common.collect.EvictingQueue;
import dev.onyxstudios.cca.api.v3.component.Component;
import dev.onyxstudios.cca.api.v3.entity.PlayerComponent;
import java.util.Optional;
import java.util.Queue;
import java.util.stream.Collectors;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;

import java.util.Queue;

@SuppressWarnings("UnstableApiUsage")
public class EntityKillTrackerComponent implements PlayerComponent<Component> {

Expand All @@ -33,25 +27,16 @@ public double getKillRatio(EntityType<?> type) {
return this.getlastKilledEntityTypes().stream().filter(type::equals).count() / (double) MAX_SIZE;
}

/*
* Read and write implementation removed because of https://github.com/florensie/artifacts-fabric/issues/50
* Didn't remove entire functionality to make sure we're compatible with clients
*/

@Override
public void readFromNbt(CompoundTag tag) {
if (tag.contains("lastKilledEntities")) {
this.lastKilledEntityTypes = tag.getList("lastKilledEntities", 8).stream()
.map(entityTypeId -> Registry.ENTITY_TYPE.getOptional(new ResourceLocation(entityTypeId.getAsString())))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toCollection(() -> EvictingQueue.create(MAX_SIZE)));
}
}

@Override
public void writeToNbt(CompoundTag tag) {
//noinspection unchecked
tag.put("lastKilledEntities", this.lastKilledEntityTypes.stream()
.map(((DefaultedRegistryExtensions<EntityType<?>>) Registry.ENTITY_TYPE)::artifacts$getIdOrEmpty)
//.flatMap(Optional::stream) TODO: Java 9+
.filter(Optional::isPresent)
.map(identifier -> StringTag.valueOf(identifier.get().toString()))
.collect(Collectors.toCollection(ListTag::new)));
}
}

0 comments on commit d3f5a5d

Please sign in to comment.