-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from CleverNucleus/1.19.2/dev
1.19.2/dev
- Loading branch information
Showing
24 changed files
with
258 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,19 +54,17 @@ jobs: | |
if: github.ref == 'refs/heads/${{ env.BRANCH_PREFIX }}/main' | ||
uses: Kir-Antipov/[email protected] | ||
with: | ||
#curseforge-id: 514734 | ||
#curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} | ||
#curseforge-dependencies: | | ||
# fabric-api | depends | * | ||
#curseforge-files-secondary: build/libs/*-@(sources\|javadoc).jar | ||
curseforge-id: 514734 | ||
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} | ||
curseforge-dependencies: | | ||
fabric-api | depends | * | ||
curseforge-files-secondary: build/libs/*-@(sources\|javadoc).jar | ||
|
||
modrinth-id: wFyCClLQ | ||
modrinth-token: "${{ secrets.MODRINTH_TOKEN }}" | ||
modrinth-dependencies: | | ||
fabric-api | depends | * | ||
# Modrinth has issues accepting javadocs right now | ||
modrinth-files-primary: build/libs/!(*-@(sources)).jar | ||
modrinth-files-secondary: build/libs/*-sources.jar | ||
|
||
github-tag: "${{ steps.mod_version.outputs.mod_version }}" | ||
github-token: ${{ secrets.REPOSITORY_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
### Changelog | ||
|
||
+Added hierarchy entity types that can be used to apply attributes to all entities that are an instance of an entity class. Currently supported types are as follows: | ||
This is primarily a bug-fixing and optimisation update. | ||
|
||
| **Identifier** | **Class Type** | | ||
| -------------- | -------------- | | ||
| `dataattributes:living_entity` | `LivingEntity` | | ||
| `dataattributes:mob_entity` | `MobEntity` | | ||
| `dataattributes:path_aware_entity` | `PathAwareEntity` | | ||
| `dataattributes:hostile_entity` | `HostileEntity` | | ||
| `dataattributes:passive_entity` | `PassiveEntity` | | ||
| `dataattributes:animal_entity` | `AnimalEntity` | | ||
*Changed the way `/reload` works to refresh attributes: | ||
|
||
These have a hierarchy of: | ||
- No longer saves the `updateFlag` to the level's nbt data. | ||
- No longer injects the `updateFlag` into vanilla packets. | ||
- Instead, we only use the `updateFlag` in runtime - not saving it at all, anywhere. | ||
|
||
``` | ||
LivingEntity | ||
┗ MobEntity | ||
┗ PathAwareEntity | ||
┣ HostileEntity | ||
┗ PassiveEntity | ||
┗ AnimalEntity | ||
``` | ||
*Fixed [#80](https://github.com/CleverNucleus/data-attributes/issues/80): attribute tracking is handled differently now. | ||
|
||
This feature is useful for when you want to modify the attributes of many different mobs, but do not know every mob's `EntityType` identifier. | ||
*Likely fixed an incompatibility between Data Attributes and ReplayMod: we no longer mess around with world properties at all. | ||
|
||
**May* have fixed long-standing issues [24](https://github.com/CleverNucleus/data-attributes/issues/24) and [10](https://github.com/CleverNucleus/data-attributes/issues/10): almost all networking has been removed - now we only send/receive two custom packets in the whole mod: on game join and when `/reload` is executed. | ||
|
||
*Various performance improvements. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/com/github/clevernucleus/dataattributes/impl/AttributeContainerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.github.clevernucleus.dataattributes.impl; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import com.github.clevernucleus.dataattributes.impl.AttributeManager.Tuple; | ||
import com.github.clevernucleus.dataattributes.mutable.MutableAttributeContainer; | ||
import com.github.clevernucleus.dataattributes.mutable.MutableDefaultAttributeContainer; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.attribute.AttributeContainer; | ||
import net.minecraft.entity.attribute.DefaultAttributeContainer; | ||
import net.minecraft.entity.attribute.DefaultAttributeRegistry; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public final class AttributeContainerHandler { | ||
private Map<Integer, Tuple<DefaultAttributeContainer>> implicitContainers; | ||
private Map<EntityType<? extends LivingEntity>, DefaultAttributeContainer> explicitContainers; | ||
|
||
protected AttributeContainerHandler() { | ||
this.implicitContainers = ImmutableMap.of(); | ||
this.explicitContainers = ImmutableMap.of(); | ||
} | ||
|
||
protected AttributeContainer getContainer(final EntityType<? extends LivingEntity> entityType, final LivingEntity livingEntity) { | ||
DefaultAttributeContainer.Builder builder = DefaultAttributeContainer.builder(); | ||
((MutableDefaultAttributeContainer)DefaultAttributeRegistry.get(entityType)).copy(builder); | ||
|
||
for(int i = 0; i < this.implicitContainers.size(); i++) { | ||
Tuple<DefaultAttributeContainer> tuple = this.implicitContainers.get(i); | ||
Class<? extends LivingEntity> type = tuple.livingEntity(); | ||
|
||
if(type.isInstance(livingEntity)) { | ||
((MutableDefaultAttributeContainer)tuple.value()).copy(builder); | ||
} | ||
} | ||
|
||
if(this.explicitContainers.containsKey(entityType)) { | ||
((MutableDefaultAttributeContainer)this.explicitContainers.get(entityType)).copy(builder); | ||
} | ||
|
||
AttributeContainer container = new AttributeContainer(builder.build()); | ||
((MutableAttributeContainer)container).setLivingEntity(livingEntity); | ||
|
||
return container; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
protected void buildContainers(final Map<Identifier, EntityTypeData> entityTypeDataIn, Map<Identifier, Tuple<Integer>> entityTypeInstances) { | ||
Collection<Identifier> entityTypes = Registry.ENTITY_TYPE.getIds().stream().filter(id -> DefaultAttributeRegistry.hasDefinitionFor(Registry.ENTITY_TYPE.get(id))).collect(Collectors.toSet()); | ||
ImmutableMap.Builder<Integer, Tuple<DefaultAttributeContainer>> implicitContainers = ImmutableMap.builder(); | ||
ImmutableMap.Builder<EntityType<? extends LivingEntity>, DefaultAttributeContainer> explicitContainers = ImmutableMap.builder(); | ||
Map<Integer, Tuple<Identifier>> orderedEntityTypes = new HashMap<>(); | ||
|
||
for(Identifier identifier : entityTypeDataIn.keySet()) { | ||
if(entityTypeInstances.containsKey(identifier)) { | ||
Tuple<Integer> tuple = entityTypeInstances.get(identifier); | ||
orderedEntityTypes.put(tuple.value(), new Tuple<Identifier>(tuple.livingEntity(), identifier)); | ||
} | ||
if(!entityTypes.contains(identifier)) continue; | ||
EntityType<? extends LivingEntity> entityType = (EntityType<? extends LivingEntity>)Registry.ENTITY_TYPE.get(identifier); | ||
DefaultAttributeContainer.Builder builder = DefaultAttributeContainer.builder(); | ||
EntityTypeData entityTypeData = entityTypeDataIn.get(identifier); | ||
entityTypeData.build(builder, DefaultAttributeRegistry.get(entityType)); | ||
explicitContainers.put(entityType, builder.build()); | ||
} | ||
|
||
final int size = orderedEntityTypes.size(); | ||
final int max = orderedEntityTypes.keySet().stream().mapToInt(Integer::intValue).max().orElse(0); | ||
|
||
for(Map.Entry<Integer, Tuple<Identifier>> entry : orderedEntityTypes.entrySet()) { | ||
Tuple<Identifier> tuple = entry.getValue(); | ||
Identifier identifier = tuple.value(); | ||
final int hierarchy = entry.getKey(); | ||
final int index = Math.round((float)size * (float)hierarchy / (float)max) - 1; | ||
DefaultAttributeContainer.Builder builder = DefaultAttributeContainer.builder(); | ||
EntityTypeData entityTypeData = entityTypeDataIn.get(identifier); | ||
entityTypeData.build(builder, null); | ||
implicitContainers.put(index, new Tuple<DefaultAttributeContainer>(tuple.livingEntity(), builder.build())); | ||
} | ||
|
||
this.implicitContainers = implicitContainers.build(); | ||
this.explicitContainers = explicitContainers.build(); | ||
} | ||
} |
Oops, something went wrong.