Skip to content

Commit

Permalink
Merge pull request #1469 from YocyCraft/dev/sunflower
Browse files Browse the repository at this point in the history
Implementation of heliostats sunflower model 实装定日镜的向日葵模型
  • Loading branch information
Gu-ZT authored Jan 9, 2025
2 parents 2b12b6a + 3b03951 commit 3f1bef0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/generated/resources/assets/anvilcraft/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@
"text.autoconfig.anvilcraft.option.giantAnvilMaxShockRadius.@Tooltip": "ɹoıʌɐɥǝq ʞɔoɥs s,ןıʌuɐ ʇuɐıb ɟo snıpɐɹ ɯnɯıxɐW",
"text.autoconfig.anvilcraft.option.heliostatsDetectionInterval": "ןɐʌɹǝʇuı uoıʇɔǝʇǝp sʇɐʇsoıןǝH",
"text.autoconfig.anvilcraft.option.heliostatsDetectionInterval.@Tooltip": "suoıʇɔǝʇǝp ʇɐʇsoıןǝɥ uǝǝʍʇǝq sʞɔıʇ ɟo ɹǝqɯnu ǝɥ⟘",
"text.autoconfig.anvilcraft.option.heliostatsSunflowerModel": "ןǝpoW ɹǝʍoןɟunS sʇɐʇsoıןǝH",
"text.autoconfig.anvilcraft.option.heliostatsSunflowerModel.@Tooltip": "ǝɯoıq suıɐןԀ ɹǝʍoןɟunS uı ןǝpoɯ pɐǝɥ ɹǝʍoןɟuns ɹǝpuǝɹ sʇɐʇsoıןǝH",
"text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "uʍopןooƆ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI",
"text.autoconfig.anvilcraft.option.inductionLightBlockRipeningRange": "ǝbuɐᴚ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI",
"text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "buıʞɔǝɥƆ ʇɔɐdɯI oᗡ ɹǝsɐꞀ sI",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/anvilcraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@
"text.autoconfig.anvilcraft.option.giantAnvilMaxShockRadius.@Tooltip": "Maximum radius of giant anvil's shock behavior",
"text.autoconfig.anvilcraft.option.heliostatsDetectionInterval": "Heliostats detection interval",
"text.autoconfig.anvilcraft.option.heliostatsDetectionInterval.@Tooltip": "The number of ticks between heliostat detections",
"text.autoconfig.anvilcraft.option.heliostatsSunflowerModel": "Heliostats Sunflower Model",
"text.autoconfig.anvilcraft.option.heliostatsSunflowerModel.@Tooltip": "Heliostats render sunflower head model in Sunflower Plains biome",
"text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "Induction Light Block Ripening Cooldown",
"text.autoconfig.anvilcraft.option.inductionLightBlockRipeningRange": "Induction Light Block Ripening Range",
"text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "Is Laser Do Impact Checking",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Objects;

@ParametersAreNonnullByDefault
public class HeliostatsBlockEntity extends BlockEntity {
@Getter
private BlockPos irritatePos;
Expand Down Expand Up @@ -86,7 +89,7 @@ public boolean setIrritatePos(BlockPos pos) {
return validatePos(pos).isWorking();
}

private WorkResult validatePos(BlockPos irritatePos) {
private WorkResult validatePos(@Nullable BlockPos irritatePos) {
normalVector3f = new Vector3f();
if (level == null) return WorkResult.UNKNOWN;
if (level.isClientSide && Minecraft.getInstance().player == null) return WorkResult.UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void registerModels(ModelEvent.RegisterAdditional event) {
event.register(ModelResourceLocation.standalone(AnvilCraft.of("item/crab_claw_holding_block")));
event.register(ModelResourceLocation.standalone(AnvilCraft.of("item/crab_claw_holding_item")));
event.register(ModelResourceLocation.standalone(AnvilCraft.of("block/heliostats_head")));
event.register(ModelResourceLocation.standalone(AnvilCraft.of("block/heliostats_head_sunflower")));
event.register(ModelResourceLocation.standalone(AnvilCraft.of("block/creative_generator_cube")));
event.register(ModelResourceLocation.standalone(AnvilCraft.of("block/charge_collector_cube")));
event.register(ModelResourceLocation.standalone(AnvilCraft.of("block/laser")));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package dev.dubhe.anvilcraft.client.renderer.blockentity;

import com.mojang.blaze3d.vertex.PoseStack;
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.block.entity.HeliostatsBlockEntity;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.resources.model.ModelResourceLocation;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.NotNull;
import org.joml.Quaternionf;
import org.joml.Vector3f;

import java.util.Optional;

@MethodsReturnNonnullByDefault
public class HeliostatsRenderer implements BlockEntityRenderer<HeliostatsBlockEntity> {
private static final ModelResourceLocation HELIOSTATS_HEAD =
ModelResourceLocation.standalone(AnvilCraft.of("block/heliostats_head"));
private static final ModelResourceLocation HELIOSTATS_HEAD_SUNFLOWER =
ModelResourceLocation.standalone(AnvilCraft.of("block/heliostats_head_sunflower"));

@SuppressWarnings("unused")
public HeliostatsRenderer(BlockEntityRendererProvider.Context context) {
Expand All @@ -29,6 +34,15 @@ private float getHorizontalAngle(float x, float z) {
return z < 0 ? (float) (angle + Math.PI) : angle;
}

private ModelResourceLocation getHeadModel(HeliostatsBlockEntity blockEntity) {
return Optional.of(blockEntity)
.filter($ -> AnvilCraft.config.heliostatsSunflowerModel)
.filter(be -> be.getLevel() != null)
.map(be -> be.getLevel().getBiome(be.getBlockPos()))
.map(biome -> biome.is(Biomes.SUNFLOWER_PLAINS))
.orElse(false) ? HELIOSTATS_HEAD_SUNFLOWER : HELIOSTATS_HEAD;
}

@Override
public void render(
@NotNull HeliostatsBlockEntity blockEntity,
Expand All @@ -44,18 +58,17 @@ public void render(
poseStack.mulPose(new Quaternionf()
.rotateY(getHorizontalAngle(blockEntity.getNormalVector3f().x, blockEntity.getNormalVector3f().z)));
poseStack.mulPose(new Quaternionf().rotateX((float)
(Math.atan(Math.sqrt((blockEntity.getNormalVector3f().z * blockEntity.getNormalVector3f().z)
+ (blockEntity.getNormalVector3f().x * blockEntity.getNormalVector3f().x))
(Math.atan(Math.hypot(blockEntity.getNormalVector3f().z, blockEntity.getNormalVector3f().x)
/ blockEntity.getNormalVector3f().y))));
}
Minecraft.getInstance()
.getBlockRenderer()
Minecraft minecraft = Minecraft.getInstance();
minecraft.getBlockRenderer()
.getModelRenderer()
.renderModel(
poseStack.last(),
buffer.getBuffer(RenderType.cutout()),
null,
Minecraft.getInstance().getModelManager().getModel(HELIOSTATS_HEAD),
minecraft.getModelManager().getModel(this.getHeadModel(blockEntity)),
0,
0,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public class AnvilCraftConfig implements ConfigData {
@SerializedName("Heliostats detection interval")
public int heliostatsDetectionInterval = 4;

@ConfigEntry.Gui.Tooltip
@Comment("Heliostats render sunflower head model in Sunflower Plains biome")
public boolean heliostatsSunflowerModel = true;

@ConfigEntry.Gui.Tooltip
@Comment("Do not render power component tooltip when jade present")
public boolean doNotShowTooltipWhenJadePresent = true;
Expand Down

0 comments on commit 3f1bef0

Please sign in to comment.