Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiPredicate;
import java.util.function.Function;
Expand All @@ -61,7 +63,9 @@ public ResourceLocation getFormId() {
return ChangedRegistry.TRANSFUR_VARIANT.get().getKey(this);
}

public TransfurMode transfurMode() { return transfurMode; }
public TransfurMode transfurMode() {
return transfurMode;
}

public boolean isGendered() {
return ChangedTransfurVariants.Gendered.hasOpposite(this);
Expand Down Expand Up @@ -148,12 +152,22 @@ public String toString() {
public final TransfurMode transfurMode;
public final float cameraZOffset;
public final ResourceLocation sound;
@Deprecated
public final List<Supplier<? extends AbstractAbility<?>>> defaultAbilities;

public TransfurVariant(Supplier<EntityType<T>> ctor,
BreatheMode breatheMode,
VisionType visionType, UseItemMode itemUseMode, @Nullable BiPredicate<T, PathfinderMob> scares, TransfurMode transfurMode,
float cameraZOffset, ResourceLocation sound) {
this(ctor, List.of(), breatheMode, visionType, itemUseMode, scares, transfurMode, cameraZOffset, sound);
}

public TransfurVariant(Supplier<EntityType<T>> ctor, List<Supplier<? extends AbstractAbility<?>>> defaultAbilities,
BreatheMode breatheMode,
VisionType visionType, UseItemMode itemUseMode, @Nullable BiPredicate<T, PathfinderMob> scares, TransfurMode transfurMode,
float cameraZOffset, ResourceLocation sound) {
this.ctor = ctor;
this.defaultAbilities = defaultAbilities;
this.breatheMode = breatheMode;
this.visionType = visionType;
this.itemUseMode = itemUseMode;
Expand All @@ -163,6 +177,11 @@ public TransfurVariant(Supplier<EntityType<T>> ctor,
this.sound = sound;
}

@Deprecated
public List<Supplier<? extends AbstractAbility<?>>> getDefaultAbilities() {
return defaultAbilities;
}

@Deprecated
public LatexTypeOld getLatexType() {
return LatexTypeOld.NEUTRAL;
Expand Down Expand Up @@ -228,9 +247,7 @@ protected static boolean canEntityWearItem(ChangedEntity entity, ItemStack itemS
if (itemStack.getItem() instanceof ExtendedItemProperties wearableItem) {
if (!wearableItem.allowedInSlot(itemStack, entity, slot))
return false;
}

else { // Default expected entity shapes
} else { // Default expected entity shapes
boolean shapeFits = switch (slot) {
case HEAD -> entity.getEntityShape().getHeadShape() == ClothingShape.Head.ANTHRO;
case CHEST -> entity.getEntityShape().getTorsoShape() == ClothingShape.Torso.ANTHRO;
Expand Down Expand Up @@ -269,7 +286,7 @@ public static void takeOldEntityItems(@NotNull IAbstractChangedEntity mapTo, @No
// Let items not taken to drop normally
}
} else if (mapFrom instanceof MobDataExtension mob) { // Inherit equipment and drop chance
boolean hurtByPlayerAtAll = ((LivingEntityDataExtension)mapFrom).changed$getLastHurtByPlayerTime() > 0;
boolean hurtByPlayerAtAll = ((LivingEntityDataExtension) mapFrom).changed$getLastHurtByPlayerTime() > 0;
boolean recipientIsPlayer = mapTo.isPlayer();
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack itemstack = mapFrom.getItemBySlot(slot);
Expand All @@ -278,7 +295,7 @@ public static void takeOldEntityItems(@NotNull IAbstractChangedEntity mapTo, @No
if (slot.isArmor() && newEntity.getItemBySlot(slot).isEmpty() && canEntityWearItem(mapTo.getChangedEntity(), itemstack, slot)) { // Take armor
if (recipientIsPlayer) { // Simulate drop chance when player is getting items
boolean guaranteedDrop = f > 1.0F;
if (!itemstack.isEmpty() && !EnchantmentHelper.hasVanishingCurse(itemstack) && Math.max(mapFrom.getRandom().nextFloat() - (float)0 * 0.01F, 0.0F) < f) {
if (!itemstack.isEmpty() && !EnchantmentHelper.hasVanishingCurse(itemstack) && Math.max(mapFrom.getRandom().nextFloat() - (float) 0 * 0.01F, 0.0F) < f) {
if (!guaranteedDrop && itemstack.isDamageableItem()) {
itemstack.setDamageValue(itemstack.getMaxDamage() - mapFrom.getRandom().nextInt(1 + mapFrom.getRandom().nextInt(Math.max(itemstack.getMaxDamage() - 3, 1))));
}
Expand All @@ -295,7 +312,7 @@ public static void takeOldEntityItems(@NotNull IAbstractChangedEntity mapTo, @No
mapFrom.setItemSlot(slot, ItemStack.EMPTY);
} else { // Drop items based on drop chance
boolean guaranteedDrop = f > 1.0F;
if (!itemstack.isEmpty() && !EnchantmentHelper.hasVanishingCurse(itemstack) && (hurtByPlayerAtAll || guaranteedDrop) && Math.max(mapFrom.getRandom().nextFloat() - (float)0 * 0.01F, 0.0F) < f) {
if (!itemstack.isEmpty() && !EnchantmentHelper.hasVanishingCurse(itemstack) && (hurtByPlayerAtAll || guaranteedDrop) && Math.max(mapFrom.getRandom().nextFloat() - (float) 0 * 0.01F, 0.0F) < f) {
if (!guaranteedDrop && itemstack.isDamageableItem()) {
itemstack.setDamageValue(itemstack.getMaxDamage() - mapFrom.getRandom().nextInt(1 + mapFrom.getRandom().nextInt(Math.max(itemstack.getMaxDamage() - 3, 1))));
}
Expand Down Expand Up @@ -339,7 +356,7 @@ private static int durabilityToXp(int durability) {
}

public static void takeOldEntityExperience(@NotNull IAbstractChangedEntity mapTo, @NotNull LivingEntity mapFrom) {
var ext = (LivingEntityDataExtension)mapFrom;
var ext = (LivingEntityDataExtension) mapFrom;

if (mapFrom.level() instanceof ServerLevel && !mapFrom.wasExperienceConsumed() && (ext.changed$isAlwaysExperienceDropper() || ext.changed$getLastHurtByPlayerTime() > 0 && mapFrom.shouldDropExperience() && mapFrom.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) {
int preReward = mapFrom.getExperienceReward();
Expand Down Expand Up @@ -385,7 +402,7 @@ public IAbstractChangedEntity replaceEntity(@NotNull LivingEntity entity, @Nulla

IAbstractChangedEntity abstraction = IAbstractChangedEntity.forEntity(newEntity);
if (entity instanceof Player player) {
newEntity.getBasicPlayerInfo().copyFrom(((PlayerDataExtension)player).getBasicPlayerInfo());
newEntity.getBasicPlayerInfo().copyFrom(((PlayerDataExtension) player).getBasicPlayerInfo());
if (ProcessTransfur.isPlayerTransfurred(player))
newEntity.copyTraitsFrom(IAbstractChangedEntity.forPlayer(player));

Expand Down Expand Up @@ -464,9 +481,10 @@ public static class Builder<T extends ChangedEntity> {
boolean reducedFall = false;
VisionType visionType = VisionType.NORMAL;
UseItemMode itemUseMode = UseItemMode.NORMAL;
@Nullable BiPredicate<T, PathfinderMob> scares = null;
@Nullable
BiPredicate<T, PathfinderMob> scares = null;
TransfurMode transfurMode = TransfurMode.REPLICATION;
List<Function<EntityType<?>, ? extends AbstractAbility<?>>> abilities = new ArrayList<>();
List<Supplier<? extends AbstractAbility<?>>> abilities = new ArrayList<>();
float cameraZOffset = 0.0F;
ResourceLocation sound = ChangedSounds.TRANSFUR_BY_LATEX.getId();

Expand All @@ -475,7 +493,8 @@ public Builder(Supplier<EntityType<T>> entityType) {
this.scares(AbstractVillager.class, TransfurVariant::shouldScareVillager);
}

public void ignored() {}
public void ignored() {
}

public static <T extends ChangedEntity> Builder<T> of(Supplier<EntityType<T>> entityType) {
return new Builder<T>(entityType);
Expand All @@ -488,23 +507,28 @@ public Builder<T> gills() {

@Deprecated(forRemoval = true)
public Builder<T> gills(boolean suffocate_on_land) {
this.breatheMode = suffocate_on_land ? BreatheMode.WATER : BreatheMode.ANY; return this;
this.breatheMode = suffocate_on_land ? BreatheMode.WATER : BreatheMode.ANY;
return this;
}

public Builder<T> breatheMode(BreatheMode mode) {
this.breatheMode = mode; return this;
this.breatheMode = mode;
return this;
}

public Builder<T> noVision() {
this.visionType = VisionType.BLIND; return this;
this.visionType = VisionType.BLIND;
return this;
}

public Builder<T> noVision(boolean v) {
this.visionType = v ? VisionType.BLIND : visionType; return this;
this.visionType = v ? VisionType.BLIND : visionType;
return this;
}

public Builder<T> reducedFall(boolean v) {
this.reducedFall = v; return this;
this.reducedFall = v;
return this;
}

@Deprecated(forRemoval = true)
Expand All @@ -527,7 +551,7 @@ public <E extends PathfinderMob> Builder<T> scares(Class<E> type) {

public <E extends PathfinderMob> Builder<T> scares(Class<E> type, BiPredicate<T, E> predicate) {
final BiPredicate<T, PathfinderMob> wrappingPredicate = (aggressor, target) -> {
return type.isInstance(target) && predicate.test(aggressor, (E)target);
return type.isInstance(target) && predicate.test(aggressor, (E) target);
};
scares = scares == null ? wrappingPredicate : scares.or(wrappingPredicate);
return this;
Expand Down Expand Up @@ -567,20 +591,21 @@ public Builder<T> extraJumps(int count) {
@Deprecated(forRemoval = true)
public Builder<T> addAbility(Function<EntityType<?>, ? extends AbstractAbility<?>> ability) {
if (ability != null)
this.abilities.add(ability);
this.abilities.add(() -> ability.apply(this.entityType.get()));
return this;
}

@Deprecated(forRemoval = true)
@Deprecated()
public Builder<T> addAbility(Supplier<? extends AbstractAbility<?>> ability) {
if (ability != null)
this.abilities.add(type -> ability.get());
this.abilities.add(ability);
return this;
}

@Deprecated(forRemoval = true)
public Builder<T> abilities(List<Function<EntityType<?>, ? extends AbstractAbility<?>>> abilities) {
this.abilities = new ArrayList<>(abilities); return this;
@Deprecated()
public Builder<T> abilities(List<Supplier<? extends AbstractAbility<?>>> abilities) {
this.abilities = new ArrayList<>(abilities);
return this;
}

@Deprecated(forRemoval = true)
Expand All @@ -604,15 +629,18 @@ public Builder<T> replicating() {
}

public Builder<T> nightVision() {
this.visionType = VisionType.NIGHT_VISION; return this;
this.visionType = VisionType.NIGHT_VISION;
return this;
}

public Builder<T> nightVision(boolean v) {
this.visionType = v ? VisionType.NIGHT_VISION : visionType; return this;
this.visionType = v ? VisionType.NIGHT_VISION : visionType;
return this;
}

public Builder<T> visionType(VisionType type) {
this.visionType = type; return this;
this.visionType = type;
return this;
}

@Deprecated(forRemoval = true)
Expand All @@ -631,7 +659,8 @@ public Builder<T> miningStrength(MiningStrength strength) {
}

public Builder<T> transfurMode(TransfurMode mode) {
this.transfurMode = mode; return this;
this.transfurMode = mode;
return this;
}

@Deprecated(forRemoval = true)
Expand Down Expand Up @@ -673,7 +702,7 @@ public Builder<T> sound(ResourceLocation event) {
}

public TransfurVariant<T> build() {
return new TransfurVariant<>(entityType, breatheMode,
return new TransfurVariant<>(entityType, abilities, breatheMode,
visionType, itemUseMode, scares, transfurMode, cameraZOffset, sound);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ public TransfurVariantInstance(TransfurVariant<T> parent, Player host) {
this.breatheMode = parent.breatheMode;
this.visionType = parent.visionType;
this.itemUseMode = parent.itemUseMode;

// Support for the old Default Abilities, is Recommended to make a "default abilities" tree instead of rely on this feature.
// It will not be removed but at same time it will not get any updates or something similar.
List<Supplier<? extends AbstractAbility<?>>> defaultAbilities = this.parent.getDefaultAbilities();
if (!defaultAbilities.isEmpty()) {
defaultAbilities.forEach(abilitySupplier -> {
AbstractAbility<?> ability = abilitySupplier.get();
this.abilityInstances.put(ability, ability.makeInstance(IAbstractChangedEntity.forPlayer(host)));
});
}
}

@Nullable
Expand Down Expand Up @@ -1002,6 +1012,17 @@ protected void tickBreathing(LivingBreatheEvent event) {

protected void updateAbilitiesMap() {
Map<AbstractAbility<?>, Integer> abilitiesToAdd = new Object2IntArrayMap<>();

List<Supplier<? extends AbstractAbility<?>>> defaultAbilities = this.parent.getDefaultAbilities();
if (!defaultAbilities.isEmpty()) {
defaultAbilities.forEach(abilitySupplier -> {
AbstractAbility<?> ability = abilitySupplier.get();
int defaultAbilityLevel = 0; // Addon will love me because of this variable.

abilitiesToAdd.putIfAbsent(ability, defaultAbilityLevel); // Default abilities have 1 as value
});
}

visitActiveNodeEffects(ChangedAbilityTreeCodecs.UNLOCK_ACTIVE_ABILITY_EFFECT.get(), activeAbilityNode -> {
abilitiesToAdd.compute(activeAbilityNode.ability, (ability, amplifier) -> {
if (amplifier == null)
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public net.minecraft.world.entity.Entity f_19819_ # portalEntrancePos
public net.minecraft.world.entity.Entity f_19815_ # dimensions
public net.minecraft.world.entity.Entity f_19816_ # eyeHeight

public net.minecraft.world.entity.Entity forgeFluidTypeOnEyes # forgeFluidTypeOnEyes

public net.minecraft.world.entity.LivingEntity f_20899_ # jumping
public net.minecraft.world.entity.LivingEntity f_20931_ # swimAmount
Expand All @@ -17,6 +16,8 @@ public net.minecraft.world.entity.WalkAnimationState f_267406_ # speedOld
public net.minecraft.world.entity.WalkAnimationState f_267371_ # speed
public net.minecraft.world.entity.WalkAnimationState f_267358_ # position

public net.minecraft.world.entity.Entity forgeFluidTypeOnEyes # forgeFluidTypeOnEyes

protected net.minecraft.world.entity.Mob f_21359_ # leashInfoTag

protected net.minecraft.world.entity.ai.goal.MeleeAttackGoal f_25543_ # path
Expand Down