Skip to content

Commit

Permalink
Initial work on villagers
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Mar 4, 2021
1 parent 8992f6f commit faf6ecc
Show file tree
Hide file tree
Showing 22 changed files with 261 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
import net.minecraft.client.renderer.entity.ArrowRenderer;
import net.minecraft.client.renderer.entity.LlamaSpitRenderer;
import net.minecraft.client.renderer.entity.SpriteRenderer;
import net.minecraft.client.renderer.entity.VillagerRenderer;
import net.minecraft.client.renderer.tileentity.SignTileEntityRenderer;
import net.minecraft.entity.EntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemModelsProperties;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.FoliageColors;
import net.minecraft.world.biome.BiomeColors;
Expand Down Expand Up @@ -268,7 +270,7 @@ public static void registerModels(ModelRegistryEvent event) {
RenderingRegistry.registerEntityRenderingHandler(AtumEntities.MUMMY, manager -> new AtumBipedRender<>(manager, new MonsterModel<>(0.0F, false), new MonsterModel<>(0.5F, false), new MonsterModel<>(1.0F, false)));
RenderingRegistry.registerEntityRenderingHandler(AtumEntities.FORSAKEN, manager -> new AtumBipedRender<>(manager, new ForsakenModel(), new ForsakenModel(0.5F), new ForsakenModel(1.0F)));
RenderingRegistry.registerEntityRenderingHandler(AtumEntities.WRAITH, manager -> new AtumBipedRender<>(manager, new MonsterModel<>(0.0F, false), new MonsterModel<>(0.5F, false), new MonsterModel<>(1.0F, false)));
RenderingRegistry.registerEntityRenderingHandler(AtumEntities.SUNSPEAKER, AtumBipedRender::new);
RenderingRegistry.registerEntityRenderingHandler(AtumEntities.VILLAGER, manager -> new AtumVillagerRenderer(manager, (IReloadableResourceManager) Minecraft.getInstance().getResourceManager()));
RenderingRegistry.registerEntityRenderingHandler(AtumEntities.BONESTORM, manager -> new AtumMobRender<>(manager, new BonestormModel<>()));
RenderingRegistry.registerEntityRenderingHandler(AtumEntities.STONEGUARD, AtumBipedRender::new);
RenderingRegistry.registerEntityRenderingHandler(AtumEntities.STONEWARDEN, StonewardenRender::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.teammetallurgy.atum.client.render.entity.mobs;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.teammetallurgy.atum.entity.villager.AtumVillagerEntity;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.layers.VillagerLevelPendantLayer;
import net.minecraft.client.renderer.entity.model.PlayerModel;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.util.ResourceLocation;

import javax.annotation.Nonnull;

public class AtumVillagerRenderer extends MobRenderer<AtumVillagerEntity, PlayerModel<AtumVillagerEntity>> {
private static final ResourceLocation VILLAGER_TEXTURES = new ResourceLocation("textures/entity/villager/villager.png");

public AtumVillagerRenderer(EntityRendererManager renderManager, IReloadableResourceManager resourceManager) {
super(renderManager, new PlayerModel<>(0.0F, false), 0.5F);
//this.addLayer(new VillagerLevelPendantLayer(this, resourceManager, "villager")); //TODO Add custom ones
}

@Override
@Nonnull
public ResourceLocation getEntityTexture(@Nonnull AtumVillagerEntity entity) {
return VILLAGER_TEXTURES;
}

@Override
protected void preRenderCallback(AtumVillagerEntity atumVillagerEntity, @Nonnull MatrixStack matrixStack, float partialTickTime) {
float f = 0.9375F;
if (atumVillagerEntity.isChild()) {
f = (float) ((double) f * 0.5D);
this.shadowSize = 0.25F;
} else {
this.shadowSize = 0.5F;
}
matrixStack.scale(f, f, f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import java.util.function.BiPredicate;

public class SunspeakerEntity extends EfreetBaseEntity implements IReputationTracking, IMerchant { //consider changing Relics trading/buying to same system as Piglins
private static final DataParameter<SunspeakerData> SUNSPEAKER_DATA = EntityDataManager.createKey(SunspeakerEntity.class, AtumDataSerializer.SUNSPEAKER_DATA);
//private static final DataParameter<SunspeakerData> SUNSPEAKER_DATA = EntityDataManager.createKey(SunspeakerEntity.class, AtumDataSerializer.SUNSPEAKER_DATA);
@Nullable
private PlayerEntity customer;
@Nullable
Expand Down Expand Up @@ -96,7 +96,7 @@ public SunspeakerEntity(EntityType<? extends SunspeakerEntity> entityType, World
((GroundPathNavigator) this.getNavigator()).setBreakDoors(true);
this.getNavigator().setCanSwim(true);
this.setItemStackToSlot(EquipmentSlotType.MAINHAND, new ItemStack(ScepterItem.getScepter(God.RA)));
this.setSunspeakerData(this.getSunspeakerData().withLevel(0));
//this.setSunspeakerData(this.getSunspeakerData().withLevel(0));
}

@Override
Expand Down Expand Up @@ -134,10 +134,10 @@ public void resetBrain(ServerWorld serverWorld) {
private void initBrain(Brain<SunspeakerEntity> brain) {
float speed = (float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) + 0.75F; //Add additional speed, due to weird issue

brain.registerActivity(Activity.CORE, SunspeakerTasks.core(speed));
/*brain.registerActivity(Activity.CORE, SunspeakerTasks.core(speed));
brain.registerActivity(Activity.MEET, SunspeakerTasks.meet(speed), ImmutableSet.of(Pair.of(MemoryModuleType.MEETING_POINT, MemoryModuleStatus.VALUE_PRESENT)));
brain.registerActivity(Activity.REST, SunspeakerTasks.rest(speed));
brain.registerActivity(Activity.IDLE, SunspeakerTasks.idle(speed));
brain.registerActivity(Activity.IDLE, SunspeakerTasks.idle(speed));*/
brain.setDefaultActivities(ImmutableSet.of(Activity.CORE));
brain.setFallbackActivity(Activity.IDLE);
brain.switchTo(Activity.IDLE);
Expand Down Expand Up @@ -203,9 +203,11 @@ public Entity changeDimension(@Nonnull ServerWorld world, @Nonnull ITeleporter t
@Override
@Nullable
public AgeableEntity func_241840_a(@Nonnull ServerWorld world, @Nonnull AgeableEntity ageable) {
SunspeakerEntity sunspeaker = new SunspeakerEntity(AtumEntities.SUNSPEAKER, world);
/*SunspeakerEntity sunspeaker = new SunspeakerEntity(AtumEntities.SUNSPEAKER, world);
sunspeaker.onInitialSpawn(world, this.world.getDifficultyForLocation(sunspeaker.getPosition()), SpawnReason.BREEDING, null, null);
return sunspeaker;
*/
return null;
}

@Override
Expand Down Expand Up @@ -261,22 +263,22 @@ public void onTrade(@Nonnull MerchantOffer offer) {
}

public void setSunspeakerData(SunspeakerData sunspeakerData) {
this.dataManager.set(SUNSPEAKER_DATA, sunspeakerData);
//this.dataManager.set(SUNSPEAKER_DATA, sunspeakerData);
}

public SunspeakerData getSunspeakerData() {
/*public SunspeakerData getSunspeakerData() {
return this.dataManager.get(SUNSPEAKER_DATA);
}
}*/

protected void onSunSpeakerTrade(MerchantOffer offer) {
int xpAmount = 3 + this.rand.nextInt(4);
this.xp += offer.getGivenExp();
this.previousCustomer = this.getCustomer();
if (this.canLevelUp()) {
/*if (this.canLevelUp()) {
this.timeUntilReset = 40;
this.leveledUp = true;
xpAmount += 5;
}
}*/

if (offer.getDoesRewardExp()) {
this.world.addEntity(new ExperienceOrbEntity(this.world, this.getPosX(), this.getPosY() + 0.5D, this.getPosZ(), xpAmount));
Expand Down Expand Up @@ -348,13 +350,13 @@ public int getPlayerReputation(PlayerEntity player) {
return this.gossip.getReputation(player.getUniqueID(), (gossipType) -> true);
}

private boolean canLevelUp() {
/*private boolean canLevelUp() {
int level = this.getSunspeakerData().getLevel();
return level < 4 && VillagerData.canLevelUp(level) && this.xp >= VillagerData.getExperienceNext(level);
}
}*/

private void levelUp() {
this.setSunspeakerData(this.getSunspeakerData().withLevel(this.getSunspeakerData().getLevel() + 1));
//this.setSunspeakerData(this.getSunspeakerData().withLevel(this.getSunspeakerData().getLevel() + 1));
this.populateTradeData();
}

Expand Down Expand Up @@ -403,15 +405,15 @@ public int getMaxSpawnedInChunk() {
}

protected void populateTradeData() {
SunspeakerData sunspeakerData = this.getSunspeakerData();
/*SunspeakerData sunspeakerData = this.getSunspeakerData();
List<VillagerTrades.ITrade[]> trades = TRADES;
if (trades != null && !trades.isEmpty()) {
VillagerTrades.ITrade[] trade = trades.get(sunspeakerData.getLevel() - 1);
if (trade != null) {
MerchantOffers merchantoffers = this.getOffers();
this.addTrades(merchantoffers, trade, 2);
}
}
}*/
}

private void tickGossip() {
Expand Down Expand Up @@ -567,7 +569,7 @@ private void shakeHead() {
private void displayMerchantGui(PlayerEntity player) {
this.recalculateSpecialPricesFor(player);
this.setCustomer(player);
this.openMerchantContainer(player, this.getDisplayName(), this.getSunspeakerData().getLevel());
//this.openMerchantContainer(player, this.getDisplayName(), this.getSunspeakerData().getLevel());
}

private void resetAllSpecialPrices() {
Expand Down Expand Up @@ -696,7 +698,7 @@ public void wakeUp() {
@Override
protected void registerData() {
super.registerData();
this.dataManager.register(SUNSPEAKER_DATA, new SunspeakerData(1));
//this.dataManager.register(SUNSPEAKER_DATA, new SunspeakerData(1));
}

@Override
Expand All @@ -706,9 +708,9 @@ public void writeAdditional(@Nonnull CompoundNBT compound) {
if (!merchantOffers.isEmpty()) {
compound.put("Offers", merchantOffers.write());
}
SunspeakerData.CODEC.encodeStart(NBTDynamicOps.INSTANCE, this.getSunspeakerData()).resultOrPartial(LOGGER::error).ifPresent((data) -> {
/*SunspeakerData.CODEC.encodeStart(NBTDynamicOps.INSTANCE, this.getSunspeakerData()).resultOrPartial(LOGGER::error).ifPresent((data) -> {
compound.put("SunspeakerData", data);
});
});*/
compound.put("Gossips", this.gossip.write(NBTDynamicOps.INSTANCE).getValue());
compound.putInt("Xp", this.xp);
compound.putLong("LastRestock", this.lastRestock);
Expand Down Expand Up @@ -741,7 +743,7 @@ public void readAdditional(@Nonnull CompoundNBT compound) {
this.restocksToday = compound.getInt("RestocksToday");
}

public static class SunspeakerTasks {
/*public static class SunspeakerTasks {
public static ImmutableList<Pair<Integer, ? extends Task<? super SunspeakerEntity>>> core(float speed) {
return ImmutableList.of(Pair.of(0, new SwimTask(0.8F)), Pair.of(0, new InteractWithDoorTask()), Pair.of(0, new LookTask(45, 90)), Pair.of(0, new WakeUpTask()), Pair.of(1, new WalkToTargetTask()), Pair.of(3, new SunspeakerTradeTask(speed)), Pair.of(5, new PickupWantedItemTask<>(speed, false, 4)), Pair.of(10, new GatherPOITask(PointOfInterestType.HOME, MemoryModuleType.HOME, false, Optional.of((byte)14))));
}
Expand All @@ -751,7 +753,7 @@ public static class SunspeakerTasks {
}
public static ImmutableList<Pair<Integer, ? extends Task<? super SunspeakerEntity>>> rest(float speed) {
return ImmutableList.of(/*Pair.of(2, new StayNearPointTask(MemoryModuleType.HOME, speed, 1, 150, 1200)),*/ Pair.of(3, new ExpirePOITask(PointOfInterestType.HOME, MemoryModuleType.HOME)), Pair.of(3, new SleepAtHomeTask()), Pair.of(5, new FirstShuffledTask<>(ImmutableMap.of(MemoryModuleType.HOME, MemoryModuleStatus.VALUE_ABSENT), ImmutableList.of(Pair.of(new WalkToHouseTask(speed), 1), Pair.of(new WalkRandomlyTask(speed), 4), Pair.of(new DummyTask(20, 40), 2)))), lookAtPlayerOrSunspeaker(), Pair.of(99, new UpdateActivityTask()));
return ImmutableList.of(Pair.of(3, new ExpirePOITask(PointOfInterestType.HOME, MemoryModuleType.HOME)), Pair.of(3, new SleepAtHomeTask()), Pair.of(5, new FirstShuffledTask<>(ImmutableMap.of(MemoryModuleType.HOME, MemoryModuleStatus.VALUE_ABSENT), ImmutableList.of(Pair.of(new WalkToHouseTask(speed), 1), Pair.of(new WalkRandomlyTask(speed), 4), Pair.of(new DummyTask(20, 40), 2)))), lookAtPlayerOrSunspeaker(), Pair.of(99, new UpdateActivityTask()));
}
public static ImmutableList<Pair<Integer, ? extends Task<? super SunspeakerEntity>>> idle(float p_220641_1_) {
Expand All @@ -765,7 +767,7 @@ private static Pair<Integer, Task<LivingEntity>> lookAtMany() {
private static Pair<Integer, Task<LivingEntity>> lookAtPlayerOrSunspeaker() {
return Pair.of(5, new FirstShuffledTask<>(ImmutableList.of(Pair.of(new LookAtEntityTask(AtumEntities.SUNSPEAKER, 8.0F), 2), Pair.of(new LookAtEntityTask(EntityType.PLAYER, 8.0F), 2), Pair.of(new DummyTask(30, 60), 8))));
}
}
}*/

static class ItemsForCoins implements VillagerTrades.ITrade {
private final int price;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,76 @@
package com.teammetallurgy.atum.entity.villager;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.entity.merchant.villager.VillagerData;
import net.minecraft.entity.merchant.villager.VillagerProfession;
import net.minecraft.entity.villager.VillagerType;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.registry.Registry;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class AtumVillagerData extends VillagerData { //Same as vanilla VillagerData, but makes sure VillagerType is not used
public static final Codec<AtumVillagerData> CODEC = RecordCodecBuilder.create((dataInstance) -> {
return dataInstance.group(Registry.VILLAGER_PROFESSION.fieldOf("profession").orElseGet(() -> {
return VillagerProfession.NONE;
}).forGetter((data) -> {
return data.profession;
}), Codec.INT.fieldOf("level").orElse(1).forGetter((data) -> {
return data.level;
}), IStringSerializable.createEnumCodec(Race::values, Race::getTypeFromName).fieldOf("race").orElse(Race.HUMAN).forGetter((data) -> {
return data.race;
}), Codec.BOOL.fieldOf("is_female").orElse(false).forGetter((data) -> {
return data.isFemale;
})).apply(dataInstance, AtumVillagerData::new);
});
private final VillagerProfession profession;
private final int level;
private final Race race;
private final boolean isFemale;

public AtumVillagerData(VillagerProfession profession, int level) {
public AtumVillagerData(VillagerProfession profession, int level, Race race, boolean isFemale) {
super(null, profession, level);
this.profession = profession;
this.level = level;
this.race = race;
this.isFemale = isFemale;
}

public Race getRace() {
return this.race;
}

public boolean isFemale() {
return this.isFemale;
}

@Override
@Nonnull
public VillagerData withProfession(@Nonnull VillagerProfession profession) {
return new AtumVillagerData(profession, this.getLevel());
return new AtumVillagerData(profession, this.getLevel(), this.getRace(), this.isFemale());
}

@Override
@Nonnull
public VillagerData withType(@Nullable VillagerType type) {
return new AtumVillagerData(this.getProfession(), this.getLevel());
return new AtumVillagerData(this.getProfession(), this.getLevel(), this.getRace(), this.isFemale());
}

@Override
@Nonnull
public VillagerData withLevel(int level) {
return new AtumVillagerData(this.getProfession(), level);
return new AtumVillagerData(this.getProfession(), level, this.getRace(), this.isFemale());
}

@Nonnull
public VillagerData withRace(Race race) {
return new AtumVillagerData(this.getProfession(), this.getLevel(), race, this.isFemale());
}

@Nonnull
public VillagerData withGender(boolean isFemale) {
return new AtumVillagerData(this.getProfession(), this.getLevel(), this.getRace(), isFemale);
}
}

0 comments on commit faf6ecc

Please sign in to comment.