Skip to content

Commit

Permalink
fix(shaft): fixed wrong block item for transmission shaft
Browse files Browse the repository at this point in the history
  • Loading branch information
D4RKAR117 committed Jun 24, 2024
1 parent 0d3cee9 commit cdc35fc
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 84 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod_name=Cog Works Engineering
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=PolyFormPerimeter-1.0
# The mod version. See https://semver.org/
mod_version=0.8.1
mod_version=0.8.2
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
// 1.21 2024-06-23T16:53:27.3530409 Block States: cog_works
166ddf49766b244c9f0800b336c33207b43ac59d assets/cog_works/blockstates/transmission_shaft.json
c7635b13750120d159bbca9312cb7decc8fdd531 assets/cog_works/models/block/iron_transmission_shaft.json
737664283c3a8aa4143cafe3a7bb356f9444609c assets/cog_works/models/block/stone_transmission_shaft.json
bdc61a1eb5805eaa8a85f82b07712d2d551f5382 assets/cog_works/models/block/wood_transmission_shaft.json
// 1.21 2024-06-23T19:30:04.8733538 Block States: cog_works
9b8930b24122053f57f866fa2f5862634eb44da7 assets/cog_works/blockstates/transmission_shaft.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
{
"variants": {
"build_material=iron,facing=down": {
"model": "cog_works:block/iron_transmission_shaft"
"facing=down,shaft_material=iron": {
"model": "minecraft:block/cube"
},
"build_material=iron,facing=east": {
"model": "cog_works:block/iron_transmission_shaft"
"facing=down,shaft_material=stone": {
"model": "minecraft:block/cube"
},
"build_material=iron,facing=north": {
"model": "cog_works:block/iron_transmission_shaft"
"facing=down,shaft_material=wood": {
"model": "minecraft:block/cube"
},
"build_material=iron,facing=south": {
"model": "cog_works:block/iron_transmission_shaft"
"facing=east,shaft_material=iron": {
"model": "minecraft:block/cube"
},
"build_material=iron,facing=up": {
"model": "cog_works:block/iron_transmission_shaft"
"facing=east,shaft_material=stone": {
"model": "minecraft:block/cube"
},
"build_material=iron,facing=west": {
"model": "cog_works:block/iron_transmission_shaft"
"facing=east,shaft_material=wood": {
"model": "minecraft:block/cube"
},
"build_material=stone,facing=down": {
"model": "cog_works:block/stone_transmission_shaft"
"facing=north,shaft_material=iron": {
"model": "minecraft:block/cube"
},
"build_material=stone,facing=east": {
"model": "cog_works:block/stone_transmission_shaft"
"facing=north,shaft_material=stone": {
"model": "minecraft:block/cube"
},
"build_material=stone,facing=north": {
"model": "cog_works:block/stone_transmission_shaft"
"facing=north,shaft_material=wood": {
"model": "minecraft:block/cube"
},
"build_material=stone,facing=south": {
"model": "cog_works:block/stone_transmission_shaft"
"facing=south,shaft_material=iron": {
"model": "minecraft:block/cube"
},
"build_material=stone,facing=up": {
"model": "cog_works:block/stone_transmission_shaft"
"facing=south,shaft_material=stone": {
"model": "minecraft:block/cube"
},
"build_material=stone,facing=west": {
"model": "cog_works:block/stone_transmission_shaft"
"facing=south,shaft_material=wood": {
"model": "minecraft:block/cube"
},
"build_material=wood,facing=down": {
"model": "cog_works:block/wood_transmission_shaft"
"facing=up,shaft_material=iron": {
"model": "minecraft:block/cube"
},
"build_material=wood,facing=east": {
"model": "cog_works:block/wood_transmission_shaft"
"facing=up,shaft_material=stone": {
"model": "minecraft:block/cube"
},
"build_material=wood,facing=north": {
"model": "cog_works:block/wood_transmission_shaft"
"facing=up,shaft_material=wood": {
"model": "minecraft:block/cube"
},
"build_material=wood,facing=south": {
"model": "cog_works:block/wood_transmission_shaft"
"facing=west,shaft_material=iron": {
"model": "minecraft:block/cube"
},
"build_material=wood,facing=up": {
"model": "cog_works:block/wood_transmission_shaft"
"facing=west,shaft_material=stone": {
"model": "minecraft:block/cube"
},
"build_material=wood,facing=west": {
"model": "cog_works:block/wood_transmission_shaft"
"facing=west,shaft_material=wood": {
"model": "minecraft:block/cube"
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/java/dev/darkar/cog_works/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.darkar.cog_works.block.TransmissionShaftBlock;
import dev.darkar.cog_works.block.entity.TransmissionShaftBlockEntity;
import dev.darkar.cog_works.block.item.TransmissionShaftBlockItem;
import dev.darkar.cog_works.item.EmptySampleTubeItem;
import dev.darkar.cog_works.item.FilledSampleTubeItem;
import dev.darkar.cog_works.item.ProspectingPickItem;
Expand Down Expand Up @@ -91,7 +92,8 @@ public static class Items {
//region BlockItems

//region Machines
public static final DeferredItem<BlockItem> TRANSMISSION_SHAFT = registerBlockItem(Blocks.TRANSMISSION_SHAFT);
public static final DeferredItem<BlockItem> TRANSMISSION_SHAFT = DEFERRED_REGISTRY.register(
"transmission_shaft", TransmissionShaftBlockItem::new);
//endregion

//endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
Expand All @@ -19,20 +20,21 @@
public class TransmissionShaftBlock extends Block implements EntityBlock {

public static final DirectionProperty FACING = BlockStateProperties.FACING;
public static final BuildMaterialProperty MATERIAL = BuildMaterialProperty.create("build_material");
public static final BuildMaterialProperty SHAFT_MATERIAL = BuildMaterialProperty.create("shaft_material");

private static final Properties blockProperties = Properties.of()
.strength(2.0F)
.requiresCorrectToolForDrops()
.lightLevel(state -> 7)
.sound(SoundType.METAL)
.noOcclusion();

public TransmissionShaftBlock() {
super(blockProperties);

registerDefaultState(stateDefinition.any()
.setValue(FACING, Direction.NORTH)
.setValue(MATERIAL, BuildMaterial.STONE)
.setValue(SHAFT_MATERIAL, BuildMaterial.STONE)
);
}

Expand All @@ -49,7 +51,7 @@ public RenderShape getRenderShape(BlockState state) {
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING);
builder.add(MATERIAL);
builder.add(SHAFT_MATERIAL);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package dev.darkar.cog_works.block.entity.model;

import dev.darkar.cog_works.block.TransmissionShaftBlock;
import dev.darkar.cog_works.block.entity.TransmissionShaftBlockEntity;
import dev.darkar.cog_works.utils.enums.BuildMaterial;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import software.bernie.geckolib.model.GeoModel;

import static dev.darkar.cog_works.CogWorks.MOD_ID;
Expand All @@ -19,16 +16,7 @@ public ResourceLocation getModelResource(TransmissionShaftBlockEntity animatable

@Override
public ResourceLocation getTextureResource(TransmissionShaftBlockEntity animatable) {
BlockState state = animatable.getBlockState();

BuildMaterial material = state.getValue(TransmissionShaftBlock.MATERIAL);

String materialPrefix = material
.getSerializedName()
.toLowerCase();

return ResourceLocation.fromNamespaceAndPath(MOD_ID, String.format("textures/block/%s_transmission_shaft.png",
materialPrefix));
return ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/block/transmission_shaft.png");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.darkar.cog_works.block.entity.renderer;

import com.mojang.blaze3d.vertex.PoseStack;
import dev.darkar.cog_works.block.entity.TransmissionShaftBlockEntity;
import dev.darkar.cog_works.block.entity.model.TransmissionShaftBlockEntityModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import software.bernie.geckolib.renderer.GeoBlockRenderer;
Expand All @@ -21,4 +23,9 @@ public TransmissionShaftBlockEntityRenderer()
{
return RenderType.entityTranslucent(texture);
}

@Override
protected void rotateBlock(Direction facing, PoseStack poseStack) {
super.rotateBlock(facing, poseStack);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.darkar.cog_works.block.item;

import dev.darkar.cog_works.Registry;
import dev.darkar.cog_works.block.item.renderer.TransmissionShaftBlockItemRenderer;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.world.item.BlockItem;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.SingletonGeoAnimatable;
import software.bernie.geckolib.animatable.client.GeoRenderProvider;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;

import java.util.function.Consumer;

public class TransmissionShaftBlockItem extends BlockItem implements GeoItem {

private static final Properties itemProperties = new Properties()
.stacksTo(64);

private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);

public TransmissionShaftBlockItem() {
super(Registry.Blocks.TRANSMISSION_SHAFT.get(), itemProperties);
SingletonGeoAnimatable.registerSyncedAnimatable(this);
}


@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {

}

@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return cache;
}

@Override
public void createGeoRenderer(Consumer<GeoRenderProvider> consumer) {
consumer.accept(new GeoRenderProvider() {
private TransmissionShaftBlockItemRenderer renderer;

@Override
public BlockEntityWithoutLevelRenderer getGeoItemRenderer() {
if (renderer == null) {
renderer = new TransmissionShaftBlockItemRenderer();
}

return this.renderer;
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.darkar.cog_works.block.item.model;

import dev.darkar.cog_works.block.item.TransmissionShaftBlockItem;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.model.GeoModel;

import static dev.darkar.cog_works.CogWorks.MOD_ID;

public class TransmissionShaftBlockItemModel extends GeoModel<TransmissionShaftBlockItem> {

@Override
public ResourceLocation getModelResource(TransmissionShaftBlockItem animatable) {
return ResourceLocation.fromNamespaceAndPath(MOD_ID, "geo/block/transmission_shaft.geo.json");
}

@Override
public ResourceLocation getTextureResource(TransmissionShaftBlockItem animatable) {
return ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/block/transmission_shaft.png");
}


@Override
public ResourceLocation getAnimationResource(TransmissionShaftBlockItem animatable) {
return ResourceLocation.fromNamespaceAndPath(MOD_ID, "animations/block/transmission_shaft.animation.json");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.darkar.cog_works.block.item.renderer;

import dev.darkar.cog_works.block.item.TransmissionShaftBlockItem;
import dev.darkar.cog_works.block.item.model.TransmissionShaftBlockItemModel;
import software.bernie.geckolib.renderer.GeoItemRenderer;

public class TransmissionShaftBlockItemRenderer extends GeoItemRenderer<TransmissionShaftBlockItem> {

public TransmissionShaftBlockItemRenderer() {
super(new TransmissionShaftBlockItemModel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ public BlockStateGenerator(PackOutput output, ExistingFileHelper existingFileHel
protected void registerStatesAndModels() {

getVariantBuilder(Registry.Blocks.TRANSMISSION_SHAFT.get()).forAllStates(state -> {
BuildMaterial mat = state.getValue(TransmissionShaftBlock.MATERIAL);
BuildMaterial shaftMat = state.getValue(TransmissionShaftBlock.SHAFT_MATERIAL);

String variantName = String.format("%s_transmission_shaft", mat.getSerializedName());
String variantName = String.format("%s_transmission_shaft", shaftMat.getSerializedName());

ResourceLocation matTexture = ResourceLocation.fromNamespaceAndPath(MOD_ID, String.format(
"block/%s", variantName));
ResourceLocation matTexture = ResourceLocation.fromNamespaceAndPath(MOD_ID, "block/transmission_shaft");


ModelFile standardBlock = models().withExistingParent(variantName, "block/cube_all")
.texture("all", matTexture);
ModelFile standardBlock = models().getExistingFile(mcLoc("block/cube"));


return ConfiguredModel.builder().modelFile(standardBlock).build();
return ConfiguredModel
.builder().modelFile(standardBlock).build();
});
}

Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit cdc35fc

Please sign in to comment.