Skip to content

Commit

Permalink
change converted texture overlay storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Sep 19, 2023
1 parent fc06ab5 commit 051cae4
Show file tree
Hide file tree
Showing 32 changed files with 276 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.PathfinderMob;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
Expand Down Expand Up @@ -69,8 +70,16 @@ public interface IVampirismEntityRegistry {
/**
* @return A map mapping the overlay resource location string to e convertible entity's class
*/
@NotNull
Map<EntityType<? extends PathfinderMob>, ResourceLocation> getConvertibleOverlay();

/**
* directly return the overlay texture for the given entity
* @param sourceEntity the string values of the source entity's registry name
*/
@Nullable
ResourceLocation getConvertibleOverlay(String sourceEntity);

/**
* @return The custom constructor registered for the given entity's class. Can be null if none is registered
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.teamlapen.vampirism.api.entity.convertible;

import de.teamlapen.vampirism.api.entity.vampire.IVampireMob;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.PathfinderMob;
import org.jetbrains.annotations.Nullable;

Expand All @@ -14,9 +13,15 @@ public interface IConvertedCreature<T extends PathfinderMob> extends IVampireMob

class Data<T> {

@Nullable
public ResourceLocation texture;
}

Data<T> data();
default Data<T> data() {
return new Data<>();
}


@Nullable
default String getSourceEntityId() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface IConvertingHandler<T extends PathfinderMob> {
@Nullable
IConvertedCreature<T> createFrom(T entity);

void updateEntityAttributes(PathfinderMob creature);

/**
* If Vampirism's default converted creature is used, this can be used to specify some properties of the converted creature
*/
Expand All @@ -29,31 +31,31 @@ interface IDefaultHelper {
/**
* use {@link #getAttributeModifier()} instead
*/
@Deprecated
@Deprecated(forRemoval = true)
default double getConvertedDMG(EntityType<? extends PathfinderMob> entity) {
return 0;
}

/**
* use {@link #getAttributeModifier()} instead
*/
@Deprecated
@Deprecated(forRemoval = true)
default double getConvertedKnockbackResistance(EntityType<? extends PathfinderMob> entity) {
return 0;
}

/**
* use {@link #getAttributeModifier()} instead
*/
@Deprecated
@Deprecated(forRemoval = true)
default double getConvertedMaxHealth(EntityType<? extends PathfinderMob> entity) {
return 0;
}

/**
* use {@link #getAttributeModifier()} instead
*/
@Deprecated
@Deprecated(forRemoval = true)
default double getConvertedSpeed(EntityType<? extends PathfinderMob> entity) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,21 @@ default T cureEntity(@NotNull ServerLevel world, @NotNull PathfinderMob entity,
return newEntity;
}

@NotNull
EntityDataAccessor<Boolean> getConvertingDataParam();

@NotNull
EntityDataAccessor<String> getSourceEntityDataParam();

@Override
default @Nullable String getSourceEntityId() {
String overlay = this.getRepresentingEntity().getEntityData().get(getSourceEntityDataParam());
if (overlay.isEmpty()) {
return null;
}
return overlay;
}

/**
* call in {@link Entity#handleEntityEvent(byte)}
*
Expand Down Expand Up @@ -132,6 +145,7 @@ default boolean isConverting(@NotNull PathfinderMob entity) {
*/
default void registerConvertingData(@NotNull PathfinderMob entity) {
entity.getEntityData().define(this.getConvertingDataParam(), false);
entity.getEntityData().define(this.getSourceEntityDataParam(), "");
}

/**
Expand All @@ -146,4 +160,6 @@ default void startConverting(@Nullable UUID conversionStarterIn, int conversionT
entity.removeEffect(MobEffects.WEAKNESS);
entity.level().broadcastEntityEvent(entity, (CURE_EVENT_ID));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"type": "vampirism:special",
"converted_type": "vampirism:converted_donkey"
},
"overlay": "vampirism:textures/entity/vanilla/donkey_overlay.png"
"overlay": "vampirism:textures/entity/vanilla/horse_overlay.png"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"type": "vampirism:special",
"converted_type": "vampirism:converted_mule"
},
"overlay": "vampirism:textures/entity/vanilla/mule_overlay.png"
"overlay": "vampirism:textures/entity/vanilla/horse_overlay.png"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"overlay": "vampirism:textures/entity/vanilla/ocelot_overlay.png"
"overlay": "vampirism:textures/entity/vanilla/cat_overlay.png"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"overlay": "vampirism:textures/entity/vanilla/polar_bear_overlay.png"
"overlay": "vampirism:textures/entity/vanilla/polarbear_overlay.png"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"type": "vampirism:special",
"converted_type": "vampirism:villager_converted"
},
"overlay": "vampirism:textures/entity/vanilla/villager_overlay_overlay.png"
"overlay": "vampirism:textures/entity/vanilla/villager_overlay.png"
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ public ResourceLocation getTextureLocation(@NotNull ConvertedCreatureEntity enti
public void render(@NotNull ConvertedCreatureEntity entity, float entityYaw, float partialTicks, @NotNull PoseStack matrixStack, @NotNull MultiBufferSource renderTypeBuffer, int packedLightIn) {
PathfinderMob creature = entity.getOldCreature();
if (creature != null) {
// creature.removed = false;
renderOverlay = true;
this.entityRenderDispatcher.render(creature, 0, 0, 0, 0, 0, matrixStack, renderTypeBuffer, packedLightIn);
renderOverlay = false;
// creature.removed = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package de.teamlapen.vampirism.client.renderer.entity.layers;

import com.mojang.blaze3d.vertex.PoseStack;
import de.teamlapen.vampirism.api.VampirismAPI;
import de.teamlapen.vampirism.api.entity.convertible.IConvertedCreature;
import de.teamlapen.vampirism.client.renderer.entity.ConvertedCreatureRenderer;
import de.teamlapen.vampirism.entity.ConvertedCreature;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.RenderLayerParent;
Expand All @@ -12,6 +12,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -32,12 +33,18 @@ public ConvertedVampireEntityLayer(@NotNull RenderLayerParent<T, U> entityRender

@Override
public void render(@NotNull PoseStack matrixStack, @NotNull MultiBufferSource iRenderTypeBuffer, int i, @NotNull T entity, float v, float v1, float v2, float v3, float v4, float v5) {
if (entity instanceof ConvertedCreature<?> converted && !entity.isInvisible() && (!checkIfRender || ConvertedCreatureRenderer.renderOverlay)) {
ResourceLocation texture = converted.data().texture;
//noinspection ConstantValue,DataFlowIssue
if (texture != null && Minecraft.getInstance().textureManager.getTexture(texture, null) != null) {
if(!entity.isInvisible()) {
String sourceId = null;
if (ConvertedCreatureRenderer.renderOverlay) {
sourceId = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()).toString();
} else if(!checkIfRender && entity instanceof IConvertedCreature<?> converted) {
sourceId = converted.getSourceEntityId();
}
ResourceLocation texture = VampirismAPI.entityRegistry().getConvertibleOverlay(sourceId);
if (texture != null) {
renderColoredCutoutModel(this.getParentModel(), texture, matrixStack, iRenderTypeBuffer, i, entity, 1, 1, 1);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.core.ModEntities;
import de.teamlapen.vampirism.data.reloadlistener.ConvertiblesReloadListener;
import de.teamlapen.vampirism.entity.converted.ConvertedCowEntity;
import de.teamlapen.vampirism.entity.converted.ConvertedSheepEntity;
import de.teamlapen.vampirism.entity.converted.ConvertedVillagerEntity;
import de.teamlapen.vampirism.entity.converted.converter.SpecialConverter;
import de.teamlapen.vampirism.util.RegUtil;
import net.minecraft.data.CachedOutput;
Expand Down Expand Up @@ -56,16 +53,16 @@ private void registerConvertibles(BiConsumer<EntityType<? extends PathfinderMob>

consumer.accept(EntityType.COW, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_COW), overlay.apply("cow")));
consumer.accept(EntityType.LLAMA, new ConvertiblesReloadListener.EntityEntry(overlay.apply("llama")));
consumer.accept(EntityType.OCELOT, new ConvertiblesReloadListener.EntityEntry(overlay.apply("ocelot")));
consumer.accept(EntityType.OCELOT, new ConvertiblesReloadListener.EntityEntry(overlay.apply("cat")));
consumer.accept(EntityType.PANDA, new ConvertiblesReloadListener.EntityEntry(overlay.apply("panda")));
consumer.accept(EntityType.PIG, new ConvertiblesReloadListener.EntityEntry(overlay.apply("pig")));
consumer.accept(EntityType.POLAR_BEAR, new ConvertiblesReloadListener.EntityEntry(overlay.apply("polar_bear")));
consumer.accept(EntityType.POLAR_BEAR, new ConvertiblesReloadListener.EntityEntry(overlay.apply("polarbear")));
consumer.accept(EntityType.RABBIT, new ConvertiblesReloadListener.EntityEntry(overlay.apply("rabbit")));
consumer.accept(EntityType.SHEEP, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_SHEEP), overlay.apply("sheep")));
consumer.accept(EntityType.VILLAGER, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.VILLAGER_CONVERTED), overlay.apply("villager_overlay")));
consumer.accept(EntityType.VILLAGER, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.VILLAGER_CONVERTED), overlay.apply("villager")));
consumer.accept(EntityType.HORSE, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_HORSE), overlay.apply("horse")));
consumer.accept(EntityType.DONKEY, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_DONKEY), overlay.apply("donkey")));
consumer.accept(EntityType.MULE, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_MULE), overlay.apply("mule")));
consumer.accept(EntityType.DONKEY, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_DONKEY), overlay.apply("horse")));
consumer.accept(EntityType.MULE, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_MULE), overlay.apply("horse")));
consumer.accept(EntityType.FOX, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_FOX), overlay.apply("fox")));
consumer.accept(EntityType.GOAT, new ConvertiblesReloadListener.EntityEntry(new SpecialConverter<>(ModEntities.CONVERTED_GOAT), overlay.apply("goat")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,17 @@ public ConvertingAttributeModifier(List<com.mojang.datafixers.util.Pair<Attribut
this(values.stream().collect(Collectors.toMap(com.mojang.datafixers.util.Pair::getFirst, com.mojang.datafixers.util.Pair::getSecond, (a, b) -> b)));
}

private static final Codec<com.mojang.datafixers.util.Pair<FloatProvider, Double>> CODEC_PAIR = RecordCodecBuilder.create(inst -> {
private static final Codec<com.mojang.datafixers.util.Pair<Attribute, com.mojang.datafixers.util.Pair<FloatProvider, Double>>> CODEC_PAIR = RecordCodecBuilder.create(inst -> {
return inst.group(
FloatProvider.CODEC.fieldOf("modifier").forGetter(com.mojang.datafixers.util.Pair::getFirst),
Codec.DOUBLE.fieldOf("fallback_base").forGetter(com.mojang.datafixers.util.Pair::getSecond)
).apply(inst, com.mojang.datafixers.util.Pair::new);
});
public static final Codec<ConvertingAttributeModifier> CODEC = RecordCodecBuilder.create(inst -> {
return inst.group(
Codec.pair(ForgeRegistries.ATTRIBUTES.getCodec(), CODEC_PAIR).listOf().fieldOf("attribute_modifier").forGetter(m -> {
return m.attributeModifier.entrySet().stream().map(s -> com.mojang.datafixers.util.Pair.of(s.getKey(), s.getValue())).toList();
})
).apply(inst, ConvertingAttributeModifier::new);
ForgeRegistries.ATTRIBUTES.getCodec().fieldOf("attribute").forGetter(com.mojang.datafixers.util.Pair::getFirst),
FloatProvider.CODEC.fieldOf("modifier").forGetter(s -> s.getSecond().getFirst()),
Codec.DOUBLE.optionalFieldOf("fallback_base", 1d).forGetter(s -> s.getSecond().getSecond())
).apply(inst, ((attribute, floatProvider, aDouble) -> com.mojang.datafixers.util.Pair.of(attribute, com.mojang.datafixers.util.Pair.of(floatProvider, aDouble))));
});
public static final Codec<ConvertingAttributeModifier> CODEC = CODEC_PAIR.listOf().xmap(
ConvertingAttributeModifier::new,
x -> x.attributeModifier.entrySet().stream().map(s -> com.mojang.datafixers.util.Pair.of(s.getKey(), com.mojang.datafixers.util.Pair.of(s.getValue().getFirst(), s.getValue().getSecond()))).collect(Collectors.toList())
);

public com.mojang.datafixers.util.Pair<FloatProvider, Double> modifier(Attribute attribute) {
return attributeModifier.get(attribute);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package de.teamlapen.vampirism.entity;

import de.teamlapen.vampirism.api.entity.convertible.IConvertedCreature;
import de.teamlapen.vampirism.entity.converted.CurableConvertedCreature;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Difficulty;
import net.minecraft.world.entity.PathfinderMob;
import org.jetbrains.annotations.NotNull;
Expand All @@ -18,14 +16,8 @@ default void tickC() {
}

default void readAdditionalSaveDataC(@NotNull CompoundTag compound) {
if (compound.contains("convertedOverlay")) {
this.data().texture = new ResourceLocation(compound.getString("convertedOverlay"));
} else {
this.data().texture = null;
}
}

default void addAdditionalSaveDataC(@NotNull CompoundTag compound) {
compound.putString("convertedOverlay", this.data().texture.toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package de.teamlapen.vampirism.entity.converted;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.teamlapen.vampirism.api.VReference;
import de.teamlapen.vampirism.api.entity.convertible.Converter;
import de.teamlapen.vampirism.api.entity.convertible.IConvertingHandler;
import de.teamlapen.vampirism.config.BalanceMobProps;
import de.teamlapen.vampirism.core.ModAttributes;
import de.teamlapen.vampirism.core.ModEntities;
import de.teamlapen.vampirism.data.reloadlistener.ConvertiblesReloadListener;
import de.teamlapen.vampirism.entity.converted.converter.DefaultConverter;
import de.teamlapen.vampirism.util.Helper;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Difficulty;
import net.minecraft.world.InteractionHand;
Expand All @@ -30,20 +21,15 @@
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.Cow;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ItemUtils;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public class ConvertedCowEntity extends Cow implements CurableConvertedCreature<Cow, ConvertedCowEntity> {

private static final EntityDataAccessor<Boolean> CONVERTING = SynchedEntityData.defineId(ConvertedCowEntity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<String> OVERLAY_TEXTURE = SynchedEntityData.defineId(ConvertedCowEntity.class, EntityDataSerializers.STRING);

private final Data<Cow> data = new Data<>();

Expand All @@ -60,10 +46,15 @@ public static boolean checkConvertedCowSpawnRules(EntityType<? extends Animal> p
}

@Override
public EntityDataAccessor<Boolean> getConvertingDataParam() {
public @NotNull EntityDataAccessor<Boolean> getConvertingDataParam() {
return CONVERTING;
}

@Override
public @NotNull EntityDataAccessor<String> getSourceEntityDataParam() {
return OVERLAY_TEXTURE;
}

@Override
public Data<Cow> data() {
return this.data;
Expand Down
Loading

0 comments on commit 051cae4

Please sign in to comment.