Skip to content

Commit

Permalink
feat: new foliot models - thanks @FeellianSinger
Browse files Browse the repository at this point in the history
  • Loading branch information
klikli-dev committed Jan 21, 2024
1 parent 4fe0696 commit df6d466
Show file tree
Hide file tree
Showing 18 changed files with 1,661 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ public abstract class StorageControllerGuiBase<T extends StorageControllerContai
protected int rows;
protected int columns;

protected int previousPage;
protected int currentPage;
protected int totalPages;

protected boolean forceFocus;
protected long lastClick;

private int lastCachedStacksToDisplayCount;

private List<ItemStack> cachedStacksToDisplay;
private String cachedSearchString;

Expand Down Expand Up @@ -536,9 +539,19 @@ public void initButtons() {

protected void drawItems(GuiGraphics guiGraphics, float partialTicks, int mouseX, int mouseY) {
List<ItemStack> stacksToDisplay = this.applySearchToItems();
this.sortItemStacks(stacksToDisplay);
this.buildPage(stacksToDisplay);
this.buildItemSlots(stacksToDisplay);

var changedPage = this.previousPage != this.currentPage;
this.previousPage = this.currentPage;

var changedStacksToDisplay = this.lastCachedStacksToDisplayCount != this.cachedStacksToDisplay.size();
this.lastCachedStacksToDisplayCount = this.cachedStacksToDisplay.size();

if(changedPage || changedStacksToDisplay){
this.sortItemStacks(stacksToDisplay);
this.buildPage(stacksToDisplay);
this.buildItemSlots(stacksToDisplay);
}

this.drawItemSlots(guiGraphics, mouseX, mouseY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,80 +22,79 @@

package com.klikli_dev.occultism.client.model.entity;

import com.klikli_dev.occultism.Occultism;
import com.klikli_dev.occultism.common.entity.spirit.FoliotEntity;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import com.klikli_dev.occultism.registry.OccultismSpiritJobs;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;

import java.util.Objects;

public class FoliotModel extends HumanoidModel<FoliotEntity> {

private final ModelPart leftHorn;
private final ModelPart rightHorn;
public class FoliotModel extends DefaultedEntityGeoModel<FoliotEntity> {

public FoliotModel(ModelPart part) {
super(part);
this.leftHorn = this.head.getChild("left_horn");
this.rightHorn = this.head.getChild("right_horn");
public final static String ASSET_SUBPATH = "foliot";

public final ModelData crusher;
public final ModelData transporter;
public final ModelData janitor;
public final ModelData lumberjack;

public FoliotModel() {
super(new ResourceLocation(Occultism.MODID, ASSET_SUBPATH), false);

this.crusher = this.buildModelData("crusher");
this.transporter = this.buildModelData("transporter");
this.janitor = this.buildModelData("janitor");
this.lumberjack = this.buildModelData("lumberjack");
}

public ModelData getModelData(FoliotEntity animatable) {
var job = animatable.getJobID();

if (Objects.equals(job, OccultismSpiritJobs.TRANSPORT_ITEMS.getId().toString())) {
return this.transporter;
}

if (Objects.equals(job, OccultismSpiritJobs.CLEANER.getId().toString())) {
return this.janitor;
}

if (Objects.equals(job, OccultismSpiritJobs.LUMBERJACK.getId().toString())) {
return this.lumberjack;
}

return this.crusher;
}

public static LayerDefinition createBodyLayer() {
MeshDefinition mesh = new MeshDefinition();
PartDefinition parts = mesh.getRoot();
PartDefinition head = parts.addOrReplaceChild("head", CubeListBuilder.create()
.addBox("", -4.0F, -8.0F, -4.0F, 8, 8, 8, CubeDeformation.NONE, 0, 0),
PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0, 0, 0));

PartDefinition hat = parts.addOrReplaceChild("hat", CubeListBuilder.create()
.addBox("", -5.0F, -10.0F, -5.0F, 10, 10, 10, CubeDeformation.NONE, 24, 44),
PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0, 0, 0));

PartDefinition body = parts.addOrReplaceChild("body", CubeListBuilder.create()
.addBox("", -4.0F, 0.0F, -3.0F, 8, 12, 6, CubeDeformation.NONE, 0, 16),
PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 0, 0, 0));

PartDefinition rightArm = parts.addOrReplaceChild("right_arm", CubeListBuilder.create()
.addBox("", -1.0F, -1.6816F, -1.2683F, 3, 11, 3, CubeDeformation.NONE, 12, 34),
PartPose.offsetAndRotation(5.0F, 3.0F, -1.0F, -0.75F, 0.0F, 0.0F));
PartDefinition leftArm = parts.addOrReplaceChild("left_arm", CubeListBuilder.create().
addBox("", -2.0F, -2.0F, -2.0F, 3, 11, 3, CubeDeformation.NONE, 0, 34),
PartPose.offsetAndRotation(-5.0F, 3.0F, -1.0F, -0.75F, 0.0F, 0.0F));
PartDefinition rightLeg = parts.addOrReplaceChild("right_leg", CubeListBuilder.create()
.addBox("", -2.0F, 0.0F, -2.0F, 4, 12, 4, CubeDeformation.NONE, 28, 28),
PartPose.offsetAndRotation(2.0F, 12.0F, 0.0F, 0, 0, 0));
PartDefinition leftLeg = parts.addOrReplaceChild("left_leg", CubeListBuilder.create().
addBox("", -2.0F, 0.0F, -2.0F, 4, 12, 4, CubeDeformation.NONE, 28, 12),
PartPose.offsetAndRotation(-2.0F, 12.0F, 0.0F, 0, 0, 0));

PartDefinition leftHorn = head.addOrReplaceChild("left_horn", CubeListBuilder.create()
.addBox("", 0.5F, -0.5F, -2.5F, 1, 1, 6, CubeDeformation.NONE, 24, 0)
.addBox("", 0.5F, 4.5F, -1.5F, 1, 1, 5, CubeDeformation.NONE, 32, 0)
.addBox("", 0.5F, 5.5F, -0.5F, 1, 1, 3, CubeDeformation.NONE, 0, 0)
.addBox("", 0.5F, 0.5F, 1.5F, 1, 1, 3, CubeDeformation.NONE, 39, 0)
.addBox("", 0.5F, 1.5F, 2.5F, 1, 1, 3, CubeDeformation.NONE, 37, 6)
.addBox("", 0.5F, 2.5F, 2.5F, 1, 1, 3, CubeDeformation.NONE, 32, 7)
.addBox("", 0.5F, 3.5F, 1.5F, 1, 1, 3, CubeDeformation.NONE, 0, 4)
.addBox("", 0.5F, 0.5F, -2.5F, 1, 1, 2, CubeDeformation.NONE, 0, 16)
.addBox("", 0.5F, 3.5F, -1.5F, 1, 1, 1, CubeDeformation.NONE, 22, 20)
.addBox("", 0.5F, 1.5F, -2.5F, 1, 1, 1, CubeDeformation.NONE, 0, 19),
PartPose.offsetAndRotation(3.5F, -8.5F, -1.5F, 0, 0, 0));

PartDefinition rightHorn = head.addOrReplaceChild("right_horn", CubeListBuilder.create()
.addBox("", 0.5F, -0.5F, -2.5F, 1, 1, 6, CubeDeformation.NONE, 24, 0)
.addBox("", 0.5F, 4.5F, -1.5F, 1, 1, 5, CubeDeformation.NONE, 32, 0)
.addBox("", 0.5F, 5.5F, -0.5F, 1, 1, 3, CubeDeformation.NONE, 0, 0)
.addBox("", 0.5F, 0.5F, 1.5F, 1, 1, 3, CubeDeformation.NONE, 39, 0)
.addBox("", 0.5F, 1.5F, 2.5F, 1, 1, 3, CubeDeformation.NONE, 37, 6)
.addBox("", 0.5F, 2.5F, 2.5F, 1, 1, 3, CubeDeformation.NONE, 32, 7)
.addBox("", 0.5F, 3.5F, 1.5F, 1, 1, 3, CubeDeformation.NONE, 0, 4)
.addBox("", 0.5F, 0.5F, -2.5F, 1, 1, 2, CubeDeformation.NONE, 0, 16)
.addBox("", 0.5F, 3.5F, -1.5F, 1, 1, 1, CubeDeformation.NONE, 22, 20)
.addBox("", 0.5F, 1.5F, -2.5F, 1, 1, 1, CubeDeformation.NONE, 0, 19),
PartPose.offsetAndRotation(-5.5F, -8.5F, -1.5F, 0, 0, 0));


return LayerDefinition.create(mesh, 64, 64);
@Override
public ResourceLocation getModelResource(FoliotEntity animatable) {
return this.getModelData(animatable).model();
}

@Override
public ResourceLocation getTextureResource(FoliotEntity animatable) {
return this.getModelData(animatable).texture();
}

@Override
public ResourceLocation getAnimationResource(FoliotEntity animatable) {
return this.getModelData(animatable).animation();
}

public ModelData buildModelData(String job) {
return this.buildModelData(job, "_");
}

public ModelData buildModelData(String job, String separator) {
return new ModelData(
this.buildFormattedModelPath(new ResourceLocation(Occultism.MODID, ASSET_SUBPATH + separator + job)),
this.buildFormattedTexturePath(new ResourceLocation(Occultism.MODID, ASSET_SUBPATH + separator + job)),
this.buildFormattedAnimationPath(new ResourceLocation(Occultism.MODID, ASSET_SUBPATH + separator + job))
);
}

public record ModelData(ResourceLocation model, ResourceLocation texture, ResourceLocation animation) {
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,12 @@
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.renderer.GeoEntityRenderer;

public class FoliotRenderer extends BipedSpiritRenderer<FoliotEntity, FoliotModel> {

private static final ResourceLocation[] TEXTURES = {new ResourceLocation(Occultism.MODID,
"textures/entity/foliot.png")};
public class FoliotRenderer extends GeoEntityRenderer<FoliotEntity> {

public FoliotRenderer(EntityRendererProvider.Context context) {
super(context, new FoliotModel(context.bakeLayer(OccultismModelLayers.FOLIOT)), 0.25f);
}

@Override
public ResourceLocation getTextureLocation(FoliotEntity entity) {
return TEXTURES[entity.getEntityData().get(entity.getDataParameterSkin())];
}

@Override
protected void scale(FoliotEntity entity, PoseStack matrixStackIn, float partialTickTime) {
super.scale(entity, matrixStackIn, partialTickTime);
matrixStackIn.scale(0.6f, 0.6f, 0.6f);
super(context, new FoliotModel());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void tick(E entity) {
if (NearestTreeSensor.isLog(entity.level(), treePos)) {
BrainUtils.setMemory(entity, MemoryModuleType.LOOK_TARGET, new BlockPosTracker(treePos));
this.breakingTime++;
entity.swing(InteractionHand.MAIN_HAND);
entity.swing(InteractionHand.MAIN_HAND, true);
int i = (int) ((float) this.breakingTime / 160.0F * 10.0F);
if (this.breakingTime % 10 == 0) {
entity.playSound(SoundEvents.WOOD_HIT, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.level.Level;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.GeoAnimatable;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.core.animation.AnimationController;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.core.animation.RawAnimation;
import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;

public class FoliotEntity extends SpiritEntity {
public class FoliotEntity extends SpiritEntity implements GeoEntity {

AnimatableInstanceCache animatableInstanceCache = GeckoLibUtil.createInstanceCache(this);

public FoliotEntity(EntityType<? extends SpiritEntity> type, Level level) {
super(type, level);
}

//region Static Methods
public static AttributeSupplier.Builder createAttributes() {
return SpiritEntity.createAttributes()
.add(Attributes.ATTACK_DAMAGE, 1.0)
Expand All @@ -43,5 +53,30 @@ public static AttributeSupplier.Builder createAttributes() {
.add(Attributes.ARMOR_TOUGHNESS, 1.0)
.add(Attributes.FOLLOW_RANGE, 50.0);
}
//endregion Static Methods

@Override
public int getCurrentSwingDuration() {
return 11; //to match our attack animation speed + 1 tick
}

@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
var mainController = new AnimationController<>(this, "mainController", 0, this::animPredicate);
controllers.add(mainController);
}

private <T extends GeoAnimatable> PlayState animPredicate(AnimationState<T> tAnimationState) {

if (this.swinging) {
return tAnimationState.setAndContinue(RawAnimation.begin().thenLoop("attack"));
}

return tAnimationState.setAndContinue(tAnimationState.isMoving() ? RawAnimation.begin().thenPlay("walk") : RawAnimation.begin().thenPlay("idle"));
}


@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.animatableInstanceCache;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public static void onRegisterEntityRendererLayerDefinitions(EntityRenderersEvent
event.registerLayerDefinition(OccultismModelLayers.FAMILIAR_MUMMY, MummyFamiliarModel::createBodyLayer);
event.registerLayerDefinition(OccultismModelLayers.FAMILIAR_BEAVER, BeaverFamiliarModel::createBodyLayer);
event.registerLayerDefinition(OccultismModelLayers.DJINNI, DjinniModel::createBodyLayer);
event.registerLayerDefinition(OccultismModelLayers.FOLIOT, FoliotModel::createBodyLayer);
event.registerLayerDefinition(OccultismModelLayers.MARID, MaridModel::createBodyLayer);
event.registerLayerDefinition(OccultismModelLayers.KAPOW, MummyFamiliarRenderer.KapowModel::createBodyLayer);
}
Expand Down
Loading

0 comments on commit df6d466

Please sign in to comment.