Skip to content

Commit

Permalink
improve mod decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Jul 12, 2024
1 parent 322c7f8 commit 901de89
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public DecorationFeatureRenderer(RenderLayerParent<T, M> context) {
public void render(PoseStack matrices, MultiBufferSource vertexConsumers, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
if(entity instanceof DecoratedMob decorated) {
if(decorated.winterly$isDecorated()) {
MobDecorationRenderer renderer = MobDecorationRenderers.getRenderer(decorated.winterly$getIndex());
MobDecorationRenderer renderer = MobDecorations.getRenderer(decorated.winterly$getIndex());
renderer.render(this.getParentModel(), matrices, vertexConsumers, light, entity, limbAngle, limbDistance, tickDelta, animationProgress, headYaw, headPitch);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ru.pinkgoosik.winterly.client.render;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.world.entity.LivingEntity;
import ru.pinkgoosik.winterly.Winterly;
import ru.pinkgoosik.winterly.client.model.WinterlyModels;

public class HatAndScarfRenderer extends MobDecorationRenderer {
public final String scarf;
public final String hat;

public HatAndScarfRenderer(String scarf, String hat) {
this.scarf = scarf;
this.hat = hat;
}

@Override
public void render(HumanoidModel<?> contextModel, PoseStack matrices, MultiBufferSource vertexConsumers, int light, LivingEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
WinterlyModels.SCARF_MODEL.scarf.copyFrom(contextModel.body);
VertexConsumer vertexConsumerScarf = vertexConsumers.getBuffer(RenderType.entityCutout(Winterly.id("textures/entity/" + scarf + ".png")));
WinterlyModels.SCARF_MODEL.renderToBuffer(matrices, vertexConsumerScarf, light, OverlayTexture.NO_OVERLAY);

WinterlyModels.SANTA_HAT_MODEL.hat.copyFrom(contextModel.head);
VertexConsumer vertexConsumerHat = vertexConsumers.getBuffer(RenderType.entityCutout(Winterly.id("textures/entity/" + hat + ".png")));
WinterlyModels.SANTA_HAT_MODEL.renderToBuffer(matrices, vertexConsumerHat, light, OverlayTexture.NO_OVERLAY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import net.minecraft.world.entity.LivingEntity;

public abstract class MobDecorationRenderer {
public final String texture;

public MobDecorationRenderer(String texture) {
this.texture = texture;
}

abstract public void render(HumanoidModel<?> contextModel, PoseStack matrices, MultiBufferSource vertexConsumers, int light, LivingEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;

@Environment(EnvType.CLIENT)
public class MobDecorationRenderers {
public class MobDecorations {
public static final List<MobDecorationRenderer> LIST = new ArrayList<>();

public static void init() {
Expand All @@ -17,6 +17,14 @@ public static void init() {

santaHat("red_santa_hat");
santaHat("blue_santa_hat");

scarfAndHat("red_scarf", "red_santa_hat");
scarfAndHat("green_scarf", "red_santa_hat");
scarfAndHat("blue_scarf", "red_santa_hat");

scarfAndHat("red_scarf", "blue_santa_hat");
scarfAndHat("green_scarf", "blue_santa_hat");
scarfAndHat("blue_scarf", "blue_santa_hat");
}

private static void scarf(String texture) {
Expand All @@ -27,11 +35,16 @@ private static void santaHat(String texture) {
LIST.add(new SantaHatRenderer(texture));
}

public static MobDecorationRenderer getRenderer(int index){
private static void scarfAndHat(String scarf, String hat) {
LIST.add(new HatAndScarfRenderer(scarf, hat));
}

public static MobDecorationRenderer getRenderer(int index) {
try {
return MobDecorationRenderers.LIST.get(index);
}catch (IndexOutOfBoundsException e) {
return MobDecorationRenderers.LIST.get(MobDecorationRenderers.LIST.size() - 1);
return MobDecorations.LIST.get(index);
}
catch (IndexOutOfBoundsException e) {
return MobDecorations.LIST.getLast();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import ru.pinkgoosik.winterly.client.model.WinterlyModels;

public class SantaHatRenderer extends MobDecorationRenderer {
public final String texture;

public SantaHatRenderer(String texture) {
super(texture);
}
public SantaHatRenderer(String texture) {
this.texture = texture;
}

@Override
public void render(HumanoidModel<?> contextModel, PoseStack matrices, MultiBufferSource vertexConsumers, int light, LivingEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import ru.pinkgoosik.winterly.client.model.WinterlyModels;

public class ScarfRenderer extends MobDecorationRenderer {
public final String texture;

public ScarfRenderer(String texture) {
super(texture);
this.texture = texture;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.pinkgoosik.winterly.Winterly;
import ru.pinkgoosik.winterly.client.render.MobDecorations;
import ru.pinkgoosik.winterly.extension.DecoratedMob;
import ru.pinkgoosik.winterly.util.HolidayUtils;

Expand All @@ -33,7 +34,7 @@ void finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, Mob
if(!this.level().dimension().equals(Level.NETHER)) {
int chance = Winterly.config.mobDecorations.chance;
if(chance > 0 && Math.random() < (double)chance / 100) {
decorated.winterly$setDecoration(level.getRandom().nextInt(5));
decorated.winterly$setDecoration(level.getRandom().nextInt(MobDecorations.LIST.size()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.pinkgoosik.winterly.Winterly;
import ru.pinkgoosik.winterly.client.render.MobDecorations;
import ru.pinkgoosik.winterly.extension.DecoratedMob;
import ru.pinkgoosik.winterly.util.HolidayUtils;

Expand Down Expand Up @@ -71,7 +72,7 @@ void finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, Mob
if(!this.level().dimension().equals(Level.NETHER)) {
int chance = Winterly.config.mobDecorations.chance;
if(chance > 0 && Math.random() < (double)chance / 100) {
this.winterly$setDecoration(level.getRandom().nextInt(5));
this.winterly$setDecoration(level.getRandom().nextInt(MobDecorations.LIST.size()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import ru.pinkgoosik.winterly.client.model.SantaHatModel;
import ru.pinkgoosik.winterly.client.model.ScarfModel;
import ru.pinkgoosik.winterly.client.render.DecorationFeatureRenderer;
import ru.pinkgoosik.winterly.client.render.MobDecorationRenderers;
import ru.pinkgoosik.winterly.client.render.MobDecorations;
import ru.pinkgoosik.winterly.item.CommonSantaHatItem;
import ru.pinkgoosik.winterly.item.CommonScarfItem;
import ru.pinkgoosik.winterly.registry.CommonWinterlyBlocks;
Expand All @@ -31,7 +31,7 @@ public void onInitializeClient() {
registerModelLayer(WinterlyModelLayers.SANTA_HAT_LAYER, SantaHatModel::getTexturedModelData);
registerModelLayer(WinterlyModelLayers.SCARF_LAYER, ScarfModel::getTexturedModelData);

MobDecorationRenderers.init();
MobDecorations.init();

BlockRenderLayerMap map = BlockRenderLayerMap.INSTANCE;
CommonWinterlyBlocks.BLOCKS.forEach((id, sup) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import ru.pinkgoosik.winterly.client.model.SantaHatModel;
import ru.pinkgoosik.winterly.client.model.ScarfModel;
import ru.pinkgoosik.winterly.client.render.DecorationFeatureRenderer;
import ru.pinkgoosik.winterly.client.render.MobDecorationRenderers;
import ru.pinkgoosik.winterly.client.render.MobDecorations;
import ru.pinkgoosik.winterly.config.WinterlyClientConfig;
import ru.pinkgoosik.winterly.item.CommonSantaHatItem;
import ru.pinkgoosik.winterly.item.CommonScarfItem;
Expand Down Expand Up @@ -58,7 +58,7 @@ private static void clientSetup(FMLClientSetupEvent event) {
});
}

MobDecorationRenderers.init();
MobDecorations.init();
ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> (client, screen) -> WinterlyClientConfig.buildScreen(screen));
}
}

0 comments on commit 901de89

Please sign in to comment.