Skip to content

Commit

Permalink
fix drill and BEDROCKIUM
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Dec 1, 2024
1 parent 8df6179 commit ce3c431
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// 1.21.1 2024-10-15T19:12:00.271604029 Item Models: carbort
// 1.21.1 2024-12-01T11:43:53.841484748 Item Models: carbort
a45ed4013794544639dd8410330e73fcedbf41bb assets/carbort/models/item/bean.json
f66b17585aa3815322f2dcc8278e5203ed0ab18e assets/carbort/models/item/bean_wand.json
044fecf12bb49ab4714fa125b416740776dffd31 assets/carbort/models/item/bedrock_drill.json
0afd690876654ab329015c02e029fd9e764a7d89 assets/carbort/models/item/bedrockium_ingot.json
44943658365709a2625f083514959d2dcb0b08b0 assets/carbort/models/item/chunk_analyzer.json
018d73fc2c24ef0f56835e5d7efc8752a10c9093 assets/carbort/models/item/deepsteal_ingot.json
e61a2481d9a2dc6d89c934921e2aab0cc3b35add assets/carbort/models/item/division_sigil.json
acdf847e559af9dac575d3705359fcae8fbb6525 assets/carbort/models/item/fire_in_a_bottle.json
3a5f2fcb47efbbc91cc4d4f65eb102a734282b73 assets/carbort/models/item/golden_bean.json
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/com/leclowndu93150/carbort/Carbort.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
package com.leclowndu93150.carbort;

import com.leclowndu93150.carbort.api.items.IEnergyItem;
import com.leclowndu93150.carbort.capabilties.ItemStackEnergyStorage;
import com.leclowndu93150.carbort.content.items.UnstableIngotItem;
import com.leclowndu93150.carbort.networking.ChunkAnalyzerDataPayload;
import com.leclowndu93150.carbort.networking.ChunkAnalyzerTogglePayload;
import com.leclowndu93150.carbort.networking.PayloadActions;
import com.leclowndu93150.carbort.registries.*;
import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.ModelEvent;
import net.neoforged.neoforge.event.tick.PlayerTickEvent;
import net.neoforged.neoforge.event.tick.ServerTickEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
import org.slf4j.Logger;

@Mod(Carbort.MODID)
public class Carbort {
public final class Carbort {
public static final String MODID = "carbort";

public static final Logger LOGGER = LogUtils.getLogger();
Expand All @@ -36,12 +48,24 @@ public Carbort(IEventBus modEventBus, ModContainer modContainer) {
CBDataComponents.DATA_COMPONENTS.register(modEventBus);
CBMenus.MENUS.register(modEventBus);

modEventBus.addListener(this::registerBakedModels);
modEventBus.addListener(this::registerCapabilities);
modEventBus.addListener(this::registerPayloads);

modContainer.registerConfig(ModConfig.Type.COMMON, CarbortConfig.SPEC);
}

private void registerBakedModels(ModelEvent.RegisterAdditional event) {
event.register(ModelResourceLocation.standalone(ResourceLocation.fromNamespaceAndPath(MODID, "block/bedrock_drill_head")));
private void registerCapabilities(RegisterCapabilitiesEvent event) {
for (Item item : BuiltInRegistries.ITEM) {
if (item instanceof IEnergyItem energyItem) {
event.registerItem(Capabilities.EnergyStorage.ITEM,
(itemStack, ctx) -> new ItemStackEnergyStorage(energyItem.getCapacity(), itemStack), item);
}
}
}

private void registerPayloads(RegisterPayloadHandlersEvent event) {
PayloadRegistrar registrar = event.registrar(Carbort.MODID);
registrar.playBidirectional(ChunkAnalyzerTogglePayload.TYPE, ChunkAnalyzerTogglePayload.STREAM_CODEC, PayloadActions::chunkAnalyzerAction);
registrar.playToClient(ChunkAnalyzerDataPayload.TYPE, ChunkAnalyzerDataPayload.STREAM_CODEC, PayloadActions::chunkAnalyzerData);
}
}
64 changes: 63 additions & 1 deletion src/main/java/com/leclowndu93150/carbort/CarbortClient.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,83 @@
package com.leclowndu93150.carbort;

import com.leclowndu93150.carbort.client.models.BedrockDrillHeadModel;
import com.leclowndu93150.carbort.client.renderer.blockentities.BedrockDrillBER;
import com.leclowndu93150.carbort.content.screen.ChunkAnalyzerScreen;
import com.leclowndu93150.carbort.registries.CBBlockEntities;
import com.leclowndu93150.carbort.registries.CBDataComponents;
import com.leclowndu93150.carbort.registries.CBItems;
import com.leclowndu93150.carbort.registries.CBMenus;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.ModelEvent;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
import org.jetbrains.annotations.NotNull;

@Mod(value = CarbortClient.MODID, dist = Dist.CLIENT)
public class CarbortClient {
public final class CarbortClient {
public static final String MODID = "carbort";

public CarbortClient(IEventBus modEventBus) {
modEventBus.addListener(this::registerBakedModels);
modEventBus.addListener(this::registerBERs);
modEventBus.addListener(this::registerMenuScreens);
modEventBus.addListener(this::registerColorHandlers);
modEventBus.addListener(this::registerClientExtensions);
modEventBus.addListener(this::registerModels);
}

private void registerBERs(EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(CBBlockEntities.BEDROCK_DRILL.get(), BedrockDrillBER::new);
}

private void registerMenuScreens(RegisterMenuScreensEvent event) {
event.register(CBMenus.CHUNK_ANALYZER_MENU.get(), ChunkAnalyzerScreen::new);
}

private void registerColorHandlers(RegisterColorHandlersEvent.Item event) {
event.register((stack, tintIndex) -> {
if (stack.has(CBDataComponents.TIMER)) {
int remainingTime = stack.getOrDefault(CBDataComponents.TIMER, 0);
int maxTime = 100;

float progress = Math.max(0, Math.min(1, (float) remainingTime / maxTime));

int red = 255;
int green = (int) (255 * progress);
int blue = (int) (255 * progress);

return FastColor.ARGB32.opaque((red << 16) | (green << 8) | blue);
}
return FastColor.ARGB32.opaque(0xFFFFFF);
}, CBItems.UNSTABLE_INGOT);
}

private void registerClientExtensions(RegisterClientExtensionsEvent event) {
event.registerItem(new IClientItemExtensions() {
@Override
public HumanoidModel.@NotNull ArmPose getArmPose(LivingEntity entityLiving, InteractionHand hand, ItemStack itemStack) {
return HumanoidModel.ArmPose.CROSSBOW_CHARGE;
}
}, CBItems.IRON_GREAT_SWORD);
}

private void registerBakedModels(ModelEvent.RegisterAdditional event) {
event.register(ModelResourceLocation.standalone(ResourceLocation.fromNamespaceAndPath(MODID, "block/bedrock_drill_head")));
}

private void registerModels(EntityRenderersEvent.RegisterLayerDefinitions event) {
event.registerLayerDefinition(BedrockDrillHeadModel.LAYER_LOCATION, BedrockDrillHeadModel::createBodyLayer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.neoforged.neoforge.common.ModConfigSpec;

@EventBusSubscriber(modid = Carbort.MODID, bus = EventBusSubscriber.Bus.MOD)
public class CarbortConfig {
public final class CarbortConfig {
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();

private static final ModConfigSpec.IntValue CHUNK_ANALYZER_ENERGY_USAGE = BUILDER
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
package com.leclowndu93150.carbort.client.models;

import com.leclowndu93150.carbort.Carbort;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.Material;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.InventoryMenu;

public class BedrockDrillHeadModel {}// extends Model {
// public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation("modid", "custommodel"), "main");
// private final ModelPart drill_head;
//
// public BedrockDrillHeadModel(ModelPart root) {
// this.drill_head = root.getChild("drill_head");
// }
//
// public static LayerDefinition createBodyLayer() {
// MeshDefinition meshdefinition = new MeshDefinition();
// PartDefinition partdefinition = meshdefinition.getRoot();
//
// PartDefinition drill_head = partdefinition.addOrReplaceChild("drill_head", CubeListBuilder.create().texOffs(0, 0).addBox(-2.0F, -14.0F, -2.0F, 4.0F, 20.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 16.0F, 0.0F));
//
// PartDefinition cube_r1 = drill_head.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(16, 14).addBox(-2.0F, 2.0F, -1.0F, 4.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 1.0503F, 5.5355F, -0.7854F, 0.0F, 0.0F));
//
// PartDefinition cube_r2 = drill_head.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(16, 6).addBox(-1.0F, 2.0F, -2.0F, 2.0F, 4.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(-5.5355F, 1.0503F, 0.0F, 0.0F, 0.0F, -0.7854F));
//
// PartDefinition cube_r3 = drill_head.addOrReplaceChild("cube_r3", CubeListBuilder.create().texOffs(0, 24).addBox(-1.0F, 2.0F, -2.0F, 2.0F, 4.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(5.5355F, 1.0503F, 0.0F, 0.0F, 0.0F, 0.7854F));
//
// PartDefinition cube_r4 = drill_head.addOrReplaceChild("cube_r4", CubeListBuilder.create().texOffs(16, 0).addBox(-2.0F, -1.0F, 2.0F, 4.0F, 2.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 1.0503F, -5.5355F, -0.7854F, 0.0F, 0.0F));
//
// return LayerDefinition.create(meshdefinition, 32, 32);
// }
//}
public class BedrockDrillHeadModel extends Model {
public static final Material CRUCIBLE_LOCATION = new Material(
InventoryMenu.BLOCK_ATLAS, ResourceLocation.fromNamespaceAndPath(Carbort.MODID, "entity/bedrock_drill_head")
);
public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(Carbort.MODID, "bedrock_drill_head"), "main");
private final ModelPart drill_head;

public BedrockDrillHeadModel(ModelPart root) {
super(RenderType::entitySolid);
this.drill_head = root.getChild("drill_head");
}

public static LayerDefinition createBodyLayer() {
MeshDefinition meshdefinition = new MeshDefinition();
PartDefinition partdefinition = meshdefinition.getRoot();

PartDefinition drill_head = partdefinition.addOrReplaceChild("drill_head", CubeListBuilder.create().texOffs(0, 0).addBox(-2.0F, -14.0F, -2.0F, 4.0F, 20.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 16.0F, 0.0F));

PartDefinition cube_r1 = drill_head.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(16, 14).addBox(-2.0F, 2.0F, -1.0F, 4.0F, 4.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 1.0503F, 5.5355F, -0.7854F, 0.0F, 0.0F));

PartDefinition cube_r2 = drill_head.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(16, 6).addBox(-1.0F, 2.0F, -2.0F, 2.0F, 4.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(-5.5355F, 1.0503F, 0.0F, 0.0F, 0.0F, -0.7854F));

PartDefinition cube_r3 = drill_head.addOrReplaceChild("cube_r3", CubeListBuilder.create().texOffs(0, 24).addBox(-1.0F, 2.0F, -2.0F, 2.0F, 4.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(5.5355F, 1.0503F, 0.0F, 0.0F, 0.0F, 0.7854F));

PartDefinition cube_r4 = drill_head.addOrReplaceChild("cube_r4", CubeListBuilder.create().texOffs(16, 0).addBox(-2.0F, -1.0F, 2.0F, 4.0F, 2.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 1.0503F, -5.5355F, -0.7854F, 0.0F, 0.0F));

return LayerDefinition.create(meshdefinition, 32, 32);
}

@Override
public void renderToBuffer(PoseStack poseStack, VertexConsumer buffer, int packedLight, int packedOverlay, int color) {
drill_head.y = 0;
drill_head.render(poseStack, buffer, packedLight, packedOverlay);
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
package com.leclowndu93150.carbort.client.renderer.blockentities;

import com.leclowndu93150.carbort.Carbort;
import com.leclowndu93150.carbort.client.models.BedrockDrillHeadModel;
import com.leclowndu93150.carbort.content.blockentities.BedrockDrillBE;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
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.BakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.client.model.data.ModelData;

public class BedrockDrillBER implements BlockEntityRenderer<BedrockDrillBE> {
private int rotation = 0;
private final BedrockDrillHeadModel model;

public BedrockDrillBER(BlockEntityRendererProvider.Context context) {
this.model = new BedrockDrillHeadModel(context.bakeLayer(BedrockDrillHeadModel.LAYER_LOCATION));
}

@Override
public void render(BedrockDrillBE blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay) {
if (rotation < 359) {
rotation++;
} else {
rotation = 0;
}

Minecraft mc = Minecraft.getInstance();
BakedModel model = mc.getModelManager().getModel(ModelResourceLocation.standalone(ResourceLocation.fromNamespaceAndPath(Carbort.MODID, "block/bedrock_drill_head")));
float angle = blockEntity.getIndependentAngle(partialTick);
poseStack.pushPose();
{
poseStack.translate(0.5, 0, 0.5);
poseStack.mulPose(Axis.YP.rotationDegrees(rotation));
poseStack.mulPose(Axis.YP.rotationDegrees(angle));
poseStack.mulPose(Axis.XP.rotationDegrees(180));
poseStack.translate(-0.5, 0, -0.5);
mc.getBlockRenderer().getModelRenderer().renderModel(poseStack.last(), bufferSource.getBuffer(RenderType.SOLID), blockEntity.getBlockState(), model, 255, 255, 255, packedLight, packedOverlay, ModelData.EMPTY, RenderType.SOLID);
poseStack.translate(0.5, -0.375, 0.5);
this.model.renderToBuffer(poseStack, BedrockDrillHeadModel.CRUCIBLE_LOCATION.buffer(bufferSource, RenderType::entitySolid), packedLight, packedOverlay);
}
poseStack.popPose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
package com.leclowndu93150.carbort.content.blockentities;

import com.leclowndu93150.carbort.Carbort;
import com.leclowndu93150.carbort.api.blockentities.ContainerBlockEntity;
import com.leclowndu93150.carbort.api.capabilities.IOActions;
import com.leclowndu93150.carbort.registries.CBBlockEntities;
import it.unimi.dsi.fastutil.Pair;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.capabilities.BlockCapability;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class BedrockDrillBE extends ContainerBlockEntity {
public float independentAngle;
public float chasingVelocity;
public int speed;

public BedrockDrillBE(BlockPos pos, BlockState blockState) {
super(CBBlockEntities.BEDROCK_DRILL.get(), pos, blockState);
this.speed = 1000;
}

@Override
public void commonTick() {
float actualSpeed = getSpeed();
chasingVelocity += ((actualSpeed * 10 / 3f) - chasingVelocity) * .25f;
independentAngle += chasingVelocity;
}

private float getSpeed() {
return speed;
}

public float getIndependentAngle(float partialTicks) {
return (independentAngle + partialTicks * chasingVelocity) / 360;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public BedrockDrillBlock(Properties properties) {

@Override
public boolean tickingEnabled() {
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ protected void registerModels() {
basicItem(CBItems.GOLDEN_BEAN);
basicItem(CBItems.FIRE_IN_A_BOTTLE);
basicItem(CBItems.DIVISION_SIGIL);
basicItem(CBItems.BEDROCKIUM_INGOT);
basicItem(CBItems.DEEPSTEAL_INGOT);

handHeldItem(CBItems.BEAN_WAND);
handHeldItem(CBItems.PARTY_PICKAXE);
Expand Down

This file was deleted.

Loading

0 comments on commit ce3c431

Please sign in to comment.