Skip to content

Commit

Permalink
More chameleon work
Browse files Browse the repository at this point in the history
  • Loading branch information
ManaStar committed Feb 17, 2024
1 parent 2431e7d commit 3225dd3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/generated/resources/assets/sullysmod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"item.minecraft.splash_potion.effect.unluck": "Splash Potion of Bad Luck",
"item.minecraft.tipped_arrow.effect.unluck": "Arrow of Bad Luck",
"item.sullysmod.bouldering_zombie_spawn_egg": "Bouldering Zombie Spawn Egg",
"item.sullysmod.chameleon_spawn_egg": "Chameleon Spawn Egg",
"item.sullysmod.cooked_lanternfish": "Cooked Lanternfish",
"item.sullysmod.cooked_piranha": "Cooked Piranha",
"item.sullysmod.glass_vial": "Glass Vial",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "minecraft:item/template_spawn_egg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import com.uraneptus.sullysmod.common.entities.Chameleon;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.model.GeoModel;
import software.bernie.geckolib.core.object.Color;
import software.bernie.geckolib.renderer.GeoRenderer;
import software.bernie.geckolib.renderer.layer.GeoRenderLayer;

Expand All @@ -21,9 +23,15 @@ public ChameleonColorLayer(GeoRenderer<Chameleon> entityRendererIn) {

@Override
public void render(PoseStack poseStack, Chameleon animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
RenderType tintRenderType = RenderType.entityCutout(TEXTURE);
RenderType tintRenderType = RenderType.entityTranslucent(TEXTURE);
Color current = Color.ofOpaque(animatable.getCurrentColor());
Color target = Color.ofOpaque(animatable.getTargetColor());

getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, tintRenderType, bufferSource.getBuffer(tintRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);

if (!current.equals(target)) {
current = Color.ofRGB(Mth.lerp(partialTick / 30F, current.getRedFloat(), target.getRedFloat()), Mth.lerp(partialTick / 30F, current.getGreenFloat(), target.getGreenFloat()), Mth.lerp(partialTick / 30F, current.getBlueFloat(), target.getBlueFloat()));
animatable.setCurrentColor(current.hashCode());
}

getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, tintRenderType, bufferSource.getBuffer(tintRenderType), partialTick, packedLight, LivingEntityRenderer.getOverlayCoords(animatable, 0.0F), current.brighter(1.2F).getRedFloat(), current.brighter(1.2F).getGreenFloat(), current.brighter(1.2F).getBlueFloat(), 1F);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.uraneptus.sullysmod.SullysMod;
import com.uraneptus.sullysmod.core.other.tags.SMItemTags;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
Expand All @@ -11,10 +12,13 @@
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.*;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import software.bernie.geckolib.animatable.GeoEntity;
Expand All @@ -29,6 +33,8 @@

public class Chameleon extends Animal implements GeoEntity {
private static final EntityDataAccessor<Integer> TARGET_COLOR = SynchedEntityData.defineId(Chameleon.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Integer> CURRENT_COLOR = SynchedEntityData.defineId(Chameleon.class, EntityDataSerializers.INT);

private final AnimatableInstanceCache instanceCache = GeckoLibUtil.createInstanceCache(this);
protected static final RawAnimation WALKING = RawAnimation.begin().thenLoop("animation.chameleon.walking");
public static final Ingredient FOOD_ITEMS = Ingredient.of(SMItemTags.CHAMELEON_FOOD);
Expand All @@ -39,8 +45,12 @@ public Chameleon(EntityType<? extends Animal> entityType, Level level) {

@Override
protected void registerGoals() {
super.registerGoals();
}
goalSelector.addGoal(0, new FloatGoal(this));
goalSelector.addGoal(1, new BreedGoal(this, 0.6D));
goalSelector.addGoal(2, new TemptGoal(this, 0.6D, FOOD_ITEMS, false));
goalSelector.addGoal(3, new WaterAvoidingRandomStrollGoal(this, 0.5D));
goalSelector.addGoal(4, new LookAtPlayerGoal(this, Player.class, 6.0F));
goalSelector.addGoal(5, new RandomLookAroundGoal(this)); }

@Override
protected float getStandingEyeHeight(Pose pPose, EntityDimensions pDimensions) {
Expand Down Expand Up @@ -93,30 +103,53 @@ public void setTargetColor(int targetColor) {
this.entityData.set(TARGET_COLOR, targetColor);
}

public int getCurrentColor() {
return this.entityData.get(CURRENT_COLOR);
}

public void setCurrentColor(int currentColor) {
this.entityData.set(CURRENT_COLOR, currentColor);
}

private void determineTargetColor() {
int color = this.level().getBlockState(this.getOnPos()).getMapColor(this.level(), this.getOnPos()).col;
if (color != this.getTargetColor()) {
SullysMod.LOGGER.info("SERVER: " + color);
this.setTargetColor(color);
BlockPos currentPos = this.blockPosition();
BlockPos floorPos = this.getOnPos();
BlockState sharedBlock = this.level().getBlockState(currentPos);
BlockState floor = this.level().getBlockState(floorPos);

if (!sharedBlock.isAir()) {
int sharedColor = sharedBlock.getMapColor(this.level(), currentPos).col;
if (this.getTargetColor() != sharedColor && sharedColor != 0) {
this.setTargetColor(sharedColor);
}
}
else {
int floorColor = floor.getMapColor(this.level(), floorPos).col;
if (this.getTargetColor() != floorColor && floorColor != 0) {
this.setTargetColor(floorColor);
}
}
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(TARGET_COLOR, 0);
this.entityData.define(TARGET_COLOR, 6645808);
this.entityData.define(CURRENT_COLOR, 6645808);
}

@Override
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
nbt.putInt("targetColor", getTargetColor());
nbt.putInt("currentColor", getCurrentColor());
}

@Override
public void readAdditionalSaveData(CompoundTag nbt) {
super.readAdditionalSaveData(nbt);
this.setTargetColor(nbt.getInt("targetColor"));
this.setCurrentColor(nbt.getInt("currentColor"));
}

public static AttributeSupplier.Builder createAttributes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected void registerModels() {
basicSpawnEggItem(SMItems.LANTERNFISH_SPAWN_EGG);
basicSpawnEggItem(SMItems.PIRANHA_SPAWN_EGG);
basicSpawnEggItem(SMItems.TORTOISE_SPAWN_EGG);
basicSpawnEggItem(SMItems.CHAMELEON_SPAWN_EGG);
basicSpawnEggItem(SMItems.BOULDERING_ZOMBIE_SPAWN_EGG);
basicSpawnEggItem(SMItems.JUNGLE_SPIDER_SPAWN_EGG);
basicItem(SMItems.LANTERNFISH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected void addTranslations() {
forItem(SMItems.JADE_SHIELD);
forItem(SMItems.TORTOISE_SCUTE);
forItem(SMItems.TORTOISE_SHELL);
forItem(SMItems.CHAMELEON_SPAWN_EGG);
forItem(SMItems.BOULDERING_ZOMBIE_SPAWN_EGG);
forItem(SMItems.JUNGLE_SPIDER_SPAWN_EGG);
forItem(SMItems.GLASS_VIAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class SMItems {
public static final RegistryObject<ForgeSpawnEggItem> JUNGLE_SPIDER_SPAWN_EGG = HELPER.createSpawnEggItem("jungle_spider", SMEntityTypes.JUNGLE_SPIDER::get, 5597514, 11013646);
public static final RegistryObject<Item> PIRANHA_BUCKET = HELPER.createItem("piranha_bucket", () -> SMItems.createMobBucketItem(SMEntityTypes.PIRANHA::get));
public static final RegistryObject<ForgeSpawnEggItem> PIRANHA_SPAWN_EGG = HELPER.createSpawnEggItem("piranha", SMEntityTypes.PIRANHA::get, 15561472, 4240022);
public static final RegistryObject<ForgeSpawnEggItem> CHAMELEON_SPAWN_EGG = HELPER.createSpawnEggItem("chameleon", SMEntityTypes.CHAMELEON::get, 9804590, 6645808);

public static Item createMobBucketItem(Supplier<EntityType<? extends WaterAnimal>> entityType) {
return new MobBucketItem(entityType, () -> Fluids.WATER, () -> SoundEvents.BUCKET_EMPTY_FISH, PropertyUtil.stacksOnce());
Expand Down

0 comments on commit 3225dd3

Please sign in to comment.