Skip to content

Commit f97f45e

Browse files
committed
v. 1.21.7 BlockEntity and Tree work
1 parent 22da4fa commit f97f45e

21 files changed

Lines changed: 756 additions & 78 deletions

src/main/java/com/github/aechtrob/prehistoricnature/PrehistoricNature.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import com.github.aechtrob.prehistoricnature.block.ModBlocks;
44
import com.github.aechtrob.prehistoricnature.creativetabs.ModCreativeTabs;
55
import com.github.aechtrob.prehistoricnature.entity.blockentity.ModBlockEntities;
6+
import com.github.aechtrob.prehistoricnature.entity.blockentity.model.DNARecombinerCentrifugeHatchModel;
7+
import com.github.aechtrob.prehistoricnature.entity.blockentity.model.DNARecombinerCentrifugePhialModel;
8+
import com.github.aechtrob.prehistoricnature.entity.blockentity.model.DNARecombinerCentrifugeSpindleModel;
9+
import com.github.aechtrob.prehistoricnature.entity.blockentity.model.DNARecombinerCentrifugeTopModel;
10+
import com.github.aechtrob.prehistoricnature.entity.blockentity.renderer.BlockEntityDNARecombinerCentrifugeRenderer;
611
import com.github.aechtrob.prehistoricnature.entity.entity.ModEntities;
712
import com.github.aechtrob.prehistoricnature.entity.entity.render.PNBenchEntityRenderer;
813
import com.github.aechtrob.prehistoricnature.entity.entity.render.PNBoatChestRenderer;
@@ -241,6 +246,7 @@ public static void onClientSetup(FMLClientSetupEvent event)
241246
@SubscribeEvent
242247
public static void onClientSetup(EntityRenderersEvent.RegisterRenderers event)
243248
{
249+
event.registerBlockEntityRenderer(ModBlockEntities.CENTRIFUGE.get(), BlockEntityDNARecombinerCentrifugeRenderer::new);
244250
event.registerBlockEntityRenderer(ModBlockEntities.PN_SIGN.get(), SignRenderer::new);
245251
event.registerBlockEntityRenderer(ModBlockEntities.PN_HANGING_SIGN.get(), HangingSignRenderer::new);
246252
event.registerEntityRenderer(ModEntities.BENCH_ENTITY.get(), PNBenchEntityRenderer::new);
@@ -271,7 +277,12 @@ public static void onClientSetup(EntityRenderersEvent.RegisterRenderers event)
271277
@SubscribeEvent
272278
public static void onClientSetup(EntityRenderersEvent.RegisterLayerDefinitions event)
273279
{
274-
//PNEntities.registerEntityLayers(event);
280+
event.registerLayerDefinition(DNARecombinerCentrifugeTopModel.LAYER_LOCATION, DNARecombinerCentrifugeTopModel::createBodyLayer);
281+
event.registerLayerDefinition(DNARecombinerCentrifugeHatchModel.LAYER_LOCATION, DNARecombinerCentrifugeHatchModel::createBodyLayer);
282+
event.registerLayerDefinition(DNARecombinerCentrifugePhialModel.LAYER_LOCATION, DNARecombinerCentrifugePhialModel::createBodyLayer);
283+
event.registerLayerDefinition(DNARecombinerCentrifugeSpindleModel.LAYER_LOCATION, DNARecombinerCentrifugeSpindleModel::createBodyLayer);
284+
285+
275286
}
276287
}
277288
}

src/main/java/com/github/aechtrob/prehistoricnature/block/BlockDNARecombinerCentrifuge.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
package com.github.aechtrob.prehistoricnature.block;
22

3+
import com.github.aechtrob.prehistoricnature.PrehistoricNatureConfig;
34
import com.github.aechtrob.prehistoricnature.entity.blockentity.BlockEntityDNARecombinerCentrifuge;
45
import com.github.aechtrob.prehistoricnature.entity.blockentity.ModBlockEntities;
56
import com.mojang.serialization.MapCodec;
67
import net.minecraft.core.BlockPos;
78
import net.minecraft.core.Direction;
9+
import net.minecraft.util.RandomSource;
10+
import net.minecraft.world.item.context.BlockPlaceContext;
811
import net.minecraft.world.level.BlockGetter;
912
import net.minecraft.world.level.Level;
13+
import net.minecraft.world.level.LevelReader;
14+
import net.minecraft.world.level.ScheduledTickAccess;
1015
import net.minecraft.world.level.block.*;
1116
import net.minecraft.world.level.block.entity.BlockEntity;
1217
import net.minecraft.world.level.block.entity.BlockEntityTicker;
1318
import net.minecraft.world.level.block.entity.BlockEntityType;
1419
import net.minecraft.world.level.block.state.BlockState;
1520
import net.minecraft.world.level.block.state.StateDefinition;
21+
import net.minecraft.world.level.block.state.properties.BooleanProperty;
1622
import net.minecraft.world.level.block.state.properties.EnumProperty;
1723
import net.minecraft.world.level.block.state.properties.Property;
24+
import net.minecraft.world.level.material.FluidState;
1825
import net.minecraft.world.phys.shapes.CollisionContext;
26+
import net.minecraft.world.phys.shapes.Shapes;
1927
import net.minecraft.world.phys.shapes.VoxelShape;
2028
import org.jetbrains.annotations.Nullable;
2129

@@ -30,25 +38,53 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
3038
public static final MapCodec<BlockDNARecombinerCentrifuge> CODEC = simpleCodec(BlockDNARecombinerCentrifuge::new);
3139
public static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 16, 16);
3240
public static EnumProperty<Direction> FACING;
41+
public static BooleanProperty RF;
3342

3443
public BlockDNARecombinerCentrifuge(Properties properties) {
3544
super(properties);
36-
this.registerDefaultState(((BlockState)this.stateDefinition.any()).setValue(FACING, Direction.NORTH));
45+
this.registerDefaultState(((BlockState)((BlockState)this.stateDefinition.any()).setValue(FACING, Direction.NORTH)).setValue(RF, PrehistoricNatureConfig.machinesRF));
3746
}
3847

3948
@Override
4049
protected MapCodec<? extends Block> codec() {
4150
return CODEC;
4251
}
4352

53+
@Override
54+
public boolean hidesNeighborFace(BlockGetter level, BlockPos pos, BlockState state, BlockState neighborState, Direction dir) {
55+
if (dir != Direction.DOWN) {
56+
return false;
57+
}
58+
return super.hidesNeighborFace(level, pos, state, neighborState, dir);
59+
}
60+
61+
@Override
62+
protected VoxelShape getOcclusionShape(BlockState state) {
63+
return Shapes.empty();
64+
}
65+
66+
@Override
67+
protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess p_374352_, BlockPos pos, Direction direction, BlockPos p_56930_, BlockState p_56927_, RandomSource p_374581_) {
68+
return state.setValue(RF, PrehistoricNatureConfig.machinesRF);
69+
}
70+
71+
@Override
72+
public BlockState getStateForPlacement(BlockPlaceContext context) {
73+
Direction direction = context.getClickedFace();
74+
BlockPos blockpos = context.getClickedPos();
75+
FluidState fluidstate = context.getLevel().getFluidState(blockpos);
76+
BlockState blockstate = (BlockState)this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(RF, PrehistoricNatureConfig.machinesRF);
77+
return (BlockState)blockstate;
78+
}
79+
4480
@Override
4581
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
4682
return SHAPE;
4783
}
4884

4985
@Override
5086
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
51-
builder.add(new Property[]{FACING});
87+
builder.add(new Property[]{FACING, RF});
5288
}
5389

5490
@Override
@@ -76,7 +112,7 @@ public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
76112

77113
static {
78114
FACING = HorizontalDirectionalBlock.FACING;
115+
RF = BooleanProperty.create("rf");
79116
}
80117

81-
82118
}

src/main/java/com/github/aechtrob/prehistoricnature/entity/blockentity/BlockEntityDNARecombinerCentrifuge.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public int getContainerSize() {
6464
return 4;
6565
}
6666

67+
public double getHatchVal() {
68+
return this.hatchVal;
69+
}
70+
71+
public void setHatchVal(double val) {
72+
this.hatchVal = val;
73+
}
74+
6775
@Override
6876
public boolean isEmpty() {
6977
Iterator var1 = this.centrifugeContents.iterator();
@@ -181,6 +189,9 @@ protected void saveAdditional(ValueOutput output) {
181189

182190
public static <T extends BlockEntity> void tick(Level level, BlockPos blockPos, BlockState state, T t) {
183191
if (PrehistoricNatureConfig.machinesRF) {
192+
if (!state.getValue(BlockDNARecombinerCentrifuge.RF)) {
193+
level.setBlock(blockPos, state.setValue(BlockDNARecombinerCentrifuge.RF, true), 3);
194+
}
184195
BlockEntity blockEntity = level.getBlockEntity(blockPos);
185196
if (blockEntity instanceof BlockEntityDNARecombinerCentrifuge) {
186197
BlockEntityDNARecombinerCentrifuge entity = (BlockEntityDNARecombinerCentrifuge) blockEntity;
@@ -213,6 +224,11 @@ public static <T extends BlockEntity> void tick(Level level, BlockPos blockPos,
213224
}
214225
}
215226
}
227+
else {
228+
if (state.getValue(BlockDNARecombinerCentrifuge.RF)) {
229+
level.setBlock(blockPos, state.setValue(BlockDNARecombinerCentrifuge.RF, false), 3);
230+
}
231+
}
216232

217233
boolean updated = false;
218234
BlockEntity blockEntity = level.getBlockEntity(blockPos);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.github.aechtrob.prehistoricnature.entity.blockentity.model;// Made with Blockbench 4.12.5
2+
// Exported for Minecraft version 1.17 or later with Mojang mappings
3+
// Paste this class into your mod and generate all required imports
4+
5+
6+
import com.github.aechtrob.prehistoricnature.PrehistoricNature;
7+
import com.github.aechtrob.prehistoricnature.entity.blockentity.renderer.renderstate.BlockEntityDNARecombinerCentrifugeRenderState;
8+
import net.minecraft.client.model.EntityModel;
9+
import net.minecraft.client.model.geom.ModelLayerLocation;
10+
import net.minecraft.client.model.geom.ModelPart;
11+
import net.minecraft.client.model.geom.PartPose;
12+
import net.minecraft.client.model.geom.builders.*;
13+
import net.minecraft.resources.ResourceLocation;
14+
15+
public class DNARecombinerCentrifugeHatchModel<T extends BlockEntityDNARecombinerCentrifugeRenderState> extends EntityModel<T> {
16+
17+
public static final ModelLayerLocation LAYER_LOCATION =
18+
new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(PrehistoricNature.MODID, "dna_recombiner_centrifuge_hatch"), "main");
19+
20+
public final ModelPart lid;
21+
public final ModelPart right;
22+
public final ModelPart left;
23+
24+
public DNARecombinerCentrifugeHatchModel(ModelPart root) {
25+
super(root);
26+
this.lid = root.getChild("lid");
27+
this.right = this.lid.getChild("right");
28+
this.left = this.lid.getChild("left");
29+
}
30+
31+
public static LayerDefinition createBodyLayer() {
32+
MeshDefinition meshdefinition = new MeshDefinition();
33+
PartDefinition partdefinition = meshdefinition.getRoot();
34+
35+
PartDefinition lid = partdefinition.addOrReplaceChild("lid", CubeListBuilder.create(), PartPose.offset(7.0F, 15.0F, 0.0F));
36+
37+
PartDefinition right = lid.addOrReplaceChild("right", CubeListBuilder.create().texOffs(0, 0).addBox(-9.0F, -7.0F, -1.5F, 4.0F, 1.0F, 2.0F, new CubeDeformation(-0.5F)),
38+
PartPose.offset(0.0F, 0.0F, 0.0F));
39+
40+
PartDefinition left = lid.addOrReplaceChild("left", CubeListBuilder.create().texOffs(0, 0).addBox(-9.0F, -7.0F, -0.5F, 4.0F, 1.0F, 2.0F, new CubeDeformation(-0.5F)),
41+
PartPose.offset(0.0F, 0.0F, 0.0F));
42+
43+
return LayerDefinition.create(meshdefinition, 48, 32);
44+
}
45+
46+
@Override
47+
public void setupAnim(T renderState) {
48+
super.setupAnim(renderState);
49+
//this.root().getAllParts().forEach(ModelPart::resetPose);
50+
}
51+
52+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.github.aechtrob.prehistoricnature.entity.blockentity.model;// Made with Blockbench 4.12.5
2+
// Exported for Minecraft version 1.17 or later with Mojang mappings
3+
// Paste this class into your mod and generate all required imports
4+
5+
6+
import com.github.aechtrob.prehistoricnature.PrehistoricNature;
7+
import com.github.aechtrob.prehistoricnature.entity.blockentity.renderer.renderstate.BlockEntityDNARecombinerCentrifugeRenderState;
8+
import net.minecraft.client.model.EntityModel;
9+
import net.minecraft.client.model.geom.ModelLayerLocation;
10+
import net.minecraft.client.model.geom.ModelPart;
11+
import net.minecraft.client.model.geom.PartPose;
12+
import net.minecraft.client.model.geom.builders.*;
13+
import net.minecraft.resources.ResourceLocation;
14+
15+
public class DNARecombinerCentrifugePhialModel<T extends BlockEntityDNARecombinerCentrifugeRenderState> extends EntityModel<T> {
16+
17+
public static final ModelLayerLocation LAYER_LOCATION =
18+
new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(PrehistoricNature.MODID, "dna_recombiner_centrifuge_phial"), "main");
19+
20+
private final ModelPart phial1centre;
21+
private final ModelPart phial1pivot;
22+
23+
public DNARecombinerCentrifugePhialModel(ModelPart root) {
24+
super(root);
25+
this.phial1centre = root.getChild("phial1centre");
26+
this.phial1pivot = this.phial1centre.getChild("phial1pivot");
27+
}
28+
29+
public static LayerDefinition createBodyLayer() {
30+
MeshDefinition meshdefinition = new MeshDefinition();
31+
PartDefinition partdefinition = meshdefinition.getRoot();
32+
33+
PartDefinition phial1centre = partdefinition.addOrReplaceChild("phial1centre", CubeListBuilder.create(), PartPose.offset(0.0F, 14.5F, 0.0F));
34+
35+
PartDefinition phial1pivot = phial1centre.addOrReplaceChild("phial1pivot", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, -2.0F));
36+
37+
PartDefinition phial1b_r1 = phial1pivot.addOrReplaceChild("phial1b_r1", CubeListBuilder.create().texOffs(0, -4).addBox(0.0F, -4.0F, -2.0F, 0.0F, 8.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 3.0F, 0.0F, 0.0F, 0.7854F, 0.0F));
38+
39+
PartDefinition phial1a_r1 = phial1pivot.addOrReplaceChild("phial1a_r1", CubeListBuilder.create().texOffs(0, -4).addBox(0.0F, -4.0F, -2.0F, 0.0F, 8.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 3.0F, 0.0F, 0.0F, -0.7854F, 0.0F));
40+
41+
return LayerDefinition.create(meshdefinition, 8, 8);
42+
}
43+
44+
@Override
45+
public void setupAnim(T renderState) {
46+
super.setupAnim(renderState);
47+
//this.root().getAllParts().forEach(ModelPart::resetPose);
48+
}
49+
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.github.aechtrob.prehistoricnature.entity.blockentity.model;// Made with Blockbench 4.12.5
2+
// Exported for Minecraft version 1.17 or later with Mojang mappings
3+
// Paste this class into your mod and generate all required imports
4+
5+
6+
import com.github.aechtrob.prehistoricnature.PrehistoricNature;
7+
import com.github.aechtrob.prehistoricnature.entity.blockentity.renderer.renderstate.BlockEntityDNARecombinerCentrifugeRenderState;
8+
import net.minecraft.client.model.EntityModel;
9+
import net.minecraft.client.model.geom.ModelLayerLocation;
10+
import net.minecraft.client.model.geom.ModelPart;
11+
import net.minecraft.client.model.geom.PartPose;
12+
import net.minecraft.client.model.geom.builders.*;
13+
import net.minecraft.resources.ResourceLocation;
14+
15+
public class DNARecombinerCentrifugeSpindleModel<T extends BlockEntityDNARecombinerCentrifugeRenderState> extends EntityModel<T> {
16+
17+
public static final ModelLayerLocation LAYER_LOCATION =
18+
new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(PrehistoricNature.MODID, "dna_recombiner_centrifuge_spindle"), "main");
19+
20+
private final ModelPart spindle;
21+
22+
public DNARecombinerCentrifugeSpindleModel(ModelPart root) {
23+
super(root);
24+
this.spindle = root.getChild("spindle");
25+
}
26+
27+
public static LayerDefinition createBodyLayer() {
28+
MeshDefinition meshdefinition = new MeshDefinition();
29+
PartDefinition partdefinition = meshdefinition.getRoot();
30+
31+
PartDefinition spindle = partdefinition.addOrReplaceChild("spindle", CubeListBuilder.create().texOffs(5, 6).addBox(-2.0F, -2.0F, -1.0F, 4.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
32+
.texOffs(7, 0).addBox(-1.0F, -1.0F, -1.0F, 2.0F, 3.0F, 2.0F, new CubeDeformation(0.0F))
33+
.texOffs(5, 5).addBox(-1.0F, -3.0F, -1.0F, 2.0F, 1.0F, 2.0F, new CubeDeformation(0.0F))
34+
.texOffs(5, 5).addBox(-1.0F, -2.0F, 1.0F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
35+
.texOffs(5, 5).addBox(-1.0F, -2.0F, -2.0F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F))
36+
.texOffs(0, 1).addBox(-0.5F, -2.0F, -3.0F, 1.0F, 0.0F, 1.0F, new CubeDeformation(0.0F))
37+
.texOffs(0, 1).addBox(-0.5F, -2.0F, 2.0F, 1.0F, 0.0F, 1.0F, new CubeDeformation(0.0F))
38+
.texOffs(0, 1).addBox(-3.0F, -2.0F, -0.5F, 1.0F, 0.0F, 1.0F, new CubeDeformation(0.0F))
39+
.texOffs(0, 1).addBox(2.0F, -2.0F, -0.5F, 1.0F, 0.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 16.0F, 0.0F));
40+
41+
return LayerDefinition.create(meshdefinition, 16, 16);
42+
}
43+
44+
@Override
45+
public void setupAnim(T renderState) {
46+
super.setupAnim(renderState);
47+
//this.root().getAllParts().forEach(ModelPart::resetPose);
48+
}
49+
50+
}

0 commit comments

Comments
 (0)