Skip to content

Commit e44760f

Browse files
committed
implement the loaded property
1 parent 5ea452e commit e44760f

File tree

7 files changed

+199
-171
lines changed

7 files changed

+199
-171
lines changed

src/client/java/fn10/musicexpansion/providers/MusicExpandedModelProvider.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,24 @@ public MusicExpandedModelProvider(FabricDataOutput output) {
2424
@Override
2525
public void generateBlockStateModels(BlockModelGenerators blockStateModelGenerator) {
2626
// Disc Burner
27-
MultiVariant basic = BlockModelGenerators
27+
MultiVariant nodisc = BlockModelGenerators
2828
.plainVariant(Identifier.fromNamespaceAndPath(MusicExpanded.MOD_ID, "block/disc_burner"));
29+
MultiVariant hasdisc = BlockModelGenerators
30+
.plainVariant(Identifier.fromNamespaceAndPath(MusicExpanded.MOD_ID, "block/disc_burner_loaded"));
2931
blockStateModelGenerator.blockStateOutput
3032
.accept(MultiVariantGenerator.dispatch(MusicExpandedBlocks.DISC_BURNER_BLOCK)
31-
.with(PropertyDispatch.initial(DiscBurnerBlock.FACING)
32-
.select(Direction.NORTH, basic)
33-
.select(Direction.EAST, basic.with(BlockModelGenerators.Y_ROT_90))
34-
.select(Direction.SOUTH, basic.with(BlockModelGenerators.Y_ROT_180))
35-
.select(Direction.WEST, basic.with(BlockModelGenerators.Y_ROT_270))));
33+
.with(PropertyDispatch.initial(DiscBurnerBlock.FACING, DiscBurnerBlock.LOADED)
34+
.select(Direction.NORTH, false, nodisc)
35+
.select(Direction.EAST, false, nodisc.with(BlockModelGenerators.Y_ROT_90))
36+
.select(Direction.SOUTH, false, nodisc.with(BlockModelGenerators.Y_ROT_180))
37+
.select(Direction.WEST, false, nodisc.with(BlockModelGenerators.Y_ROT_270))
38+
.select(Direction.NORTH, true, hasdisc)
39+
.select(Direction.EAST, true, hasdisc.with(BlockModelGenerators.Y_ROT_90))
40+
.select(Direction.SOUTH, true, hasdisc.with(BlockModelGenerators.Y_ROT_180))
41+
.select(Direction.WEST, true, hasdisc.with(BlockModelGenerators.Y_ROT_270))));
3642
blockStateModelGenerator.registerSimpleItemModel(MusicExpandedBlocks.DISC_BURNER_BLOCK,
3743
Identifier.fromNamespaceAndPath(MusicExpanded.MOD_ID, "block/disc_burner"));
38-
44+
3945
}
4046

4147
@Override

src/main/generated/.cache/2fbf86ff4149eee6b9e08a0f457798e7a5fdf460

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// 1.21.11 -999999999-01-01T00:00:00 Compact Discs/Model Definitions
2-
3641b499761bd54e1de7df9244201ef9f224b5de assets/compactdiscs/blockstates/disc_burner.json
2+
ad0431593969498adf5853a2f86435123cd48221 assets/compactdiscs/blockstates/disc_burner.json
33
8992f88c013726b4bf1b9ff417bf12e3b61cd436 assets/compactdiscs/items/compact_disc.json
44
d576ad8cd6569e6aac06a71159d22196e667d55f assets/compactdiscs/items/disc_burner.json
55
23ab07262c413c1fa3d89e78ba9cd3fd4125b9cd assets/compactdiscs/items/glass_dust.json

src/main/java/fn10/musicexpansion/blocks/DiscBurnerBlock.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import com.mojang.serialization.MapCodec;
88

9-
import fn10.musicexpansion.MusicExpanded;
109
import fn10.musicexpansion.blocks.entity.DiscBurnerBlockEntity;
1110
import fn10.musicexpansion.reg.MusicExpandedBlockEntitys;
1211
import fn10.musicexpansion.reg.MusicExpandedItems;
@@ -25,9 +24,12 @@
2524
import net.minecraft.world.level.block.Mirror;
2625
import net.minecraft.world.level.block.Rotation;
2726
import net.minecraft.world.level.block.entity.BlockEntity;
27+
import net.minecraft.world.level.block.entity.BlockEntityTicker;
28+
import net.minecraft.world.level.block.entity.BlockEntityType;
2829
import net.minecraft.world.level.block.state.BlockState;
2930
import net.minecraft.world.level.block.state.StateDefinition;
3031
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
32+
import net.minecraft.world.level.block.state.properties.BooleanProperty;
3133
import net.minecraft.world.level.block.state.properties.EnumProperty;
3234
import net.minecraft.world.phys.BlockHitResult;
3335
import net.minecraft.world.phys.shapes.CollisionContext;
@@ -36,10 +38,11 @@
3638
public class DiscBurnerBlock extends BaseEntityBlock {
3739

3840
public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
41+
public static final BooleanProperty LOADED = BooleanProperty.create("loaded");
3942

4043
public DiscBurnerBlock(Properties properties) {
4144
super(properties.noOcclusion());
42-
registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH));
45+
registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH).setValue(LOADED, false));
4346
}
4447

4548
@Override
@@ -75,18 +78,20 @@ protected BlockState mirror(BlockState blockState, Mirror mirror) {
7578
@Override
7679
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
7780
builder.add(FACING);
81+
builder.add(LOADED);
7882
}
7983

8084
public @Nullable BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
81-
return this.defaultBlockState().setValue(FACING, blockPlaceContext.getHorizontalDirection().getOpposite());
85+
return this.defaultBlockState().setValue(LOADED, false).setValue(FACING,
86+
blockPlaceContext.getHorizontalDirection().getOpposite());
8287
}
8388

8489
@Override
8590
public InteractionResult useWithoutItem(BlockState blockState, Level level, BlockPos blockPos, Player player,
8691
BlockHitResult blockHitResult) {
8792
MenuProvider menuProvider = getMenuProvider(blockState, level, blockPos);
88-
player.openMenu(menuProvider);
89-
return InteractionResult.SUCCESS;
93+
player.openMenu(menuProvider);
94+
return InteractionResult.SUCCESS;
9095
}
9196

9297
@Override
@@ -104,4 +109,11 @@ public InteractionResult useItemOn(ItemStack itemStack, BlockState blockState, L
104109
return useWithoutItem(blockState, level, blockPos, player, blockHitResult);
105110
}
106111
}
112+
113+
@Nullable
114+
@Override
115+
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level world, BlockState state,
116+
BlockEntityType<T> type) {
117+
return createTickerHelper(type, MusicExpandedBlockEntitys.DISC_BURNER_BENTITY, DiscBurnerBlockEntity::tick);
118+
}
107119
}

src/main/java/fn10/musicexpansion/blocks/entity/DiscBurnerBlockEntity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fn10.musicexpansion.blocks.entity;
22

3+
import fn10.musicexpansion.MusicExpanded;
4+
import fn10.musicexpansion.blocks.DiscBurnerBlock;
35
import fn10.musicexpansion.menu.DiscBurnerMenu;
46
import fn10.musicexpansion.reg.MusicExpandedBlockEntitys;
57
import net.minecraft.core.BlockPos;
@@ -8,6 +10,7 @@
810
import net.minecraft.world.entity.player.Inventory;
911
import net.minecraft.world.inventory.AbstractContainerMenu;
1012
import net.minecraft.world.item.ItemStack;
13+
import net.minecraft.world.level.Level;
1114
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
1215
import net.minecraft.world.level.block.state.BlockState;
1316

@@ -50,4 +53,9 @@ protected NonNullList<ItemStack> getItems() {
5053
protected void setItems(NonNullList<ItemStack> nonNullList) {
5154
inventory = nonNullList;
5255
}
56+
57+
public static void tick(Level world, BlockPos blockPos, BlockState blockState, DiscBurnerBlockEntity entity) {
58+
MusicExpanded.LOGGER.info("tick " + !entity.inventory.get(0).isEmpty());
59+
world.setBlockAndUpdate(blockPos, blockState.setValue(DiscBurnerBlock.LOADED, !entity.inventory.get(0).isEmpty()));
60+
}
5361
}

src/main/java/fn10/musicexpansion/menu/DiscBurnerMenu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public DiscBurnerMenu(Inventory plrInventory, Container discBurner, int i) {
2222
checkContainerSize(discBurner, 3);
2323

2424
addStandardInventorySlots(plrInventory, 8, 81);
25-
INSERTED_DISC_SLOT = new Slot(discBurner, 0, 80, 13);
25+
INSERTED_DISC_SLOT = new Slot(discBurner, 0, 80, 15);
2626

2727
addSlot(INSERTED_DISC_SLOT);
2828
}

src/main/resources/assets/compactdiscs/models/block/disc_burner.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"credit": "Made with Blockbench; Made by xFN10x",
44
"texture_size": [64, 64],
55
"textures": {
6+
"particle": "minecraft:block/smooth_stone",
67
"main": "compactdiscs:block/disc_burner"
78
},
89
"elements": [

0 commit comments

Comments
 (0)