Skip to content

Commit a5b859c

Browse files
committed
Add Cardboard Box
1 parent a32aad3 commit a5b859c

22 files changed

Lines changed: 448 additions & 128 deletions

changelog-next.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
- Added Copper Campfire and Copper Brazier.
2-
- Copper Lanterns can now be placed on walls.
3-
- Changed hitbox of Long Flower Pot, Basket and Benches to be half block high.
4-
- Fixed Plain Shelf loosing items when placing additional one in block.
1+
- Added Cardboard Box:
2+
- Similar block to existing Basket (Shulker Box like with only 5 slots).
3+
- Crafted with 4 Planks, 4 Papers and 1 Slime Ball.

gradle.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ org.gradle.parallel=true
44

55
# Fabric Properties
66
# check these on https://fabricmc.net/develop
7-
minecraft_version=1.21.11-rc3
8-
yarn_mappings=1.21.11-rc3+build.1
9-
loader_version=0.18.1
7+
minecraft_version=1.21.11
8+
yarn_mappings=1.21.11+build.1
9+
loader_version=0.18.2
1010
loom_version=1.10-SNAPSHOT
1111

1212
# Fabric API
13-
fabric_version=0.139.4+1.21.11
13+
fabric_version=0.139.5+1.21.11
1414

1515
# Mod Properties
16-
mod_version = 0.10.0
16+
mod_version = 0.10.1
1717
maven_group = eu.pb4
1818
archives_base_name = polydecorations
1919

src/main/java/eu/pb4/polydecorations/block/DecorationsBlockEntities.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import net.minecraft.world.level.block.entity.BlockEntityType;
1818
import java.util.ArrayList;
1919

20+
import static eu.pb4.polydecorations.ModInit.id;
21+
2022
public class DecorationsBlockEntities {
2123
public static final BlockEntityType<?> SHELF = register("shelf", ShelfBlockEntity::new, DecorationsBlocks.SHELF.values().toArray(new PlainShelfBlock[0]));
2224
public static final BlockEntityType<?> SIGN_POST = register("sign_post", SignPostBlockEntity::new,
@@ -31,7 +33,8 @@ public class DecorationsBlockEntities {
3133
DecorationsBlocks.WOODEN_MAILBOX.values().toArray(new Block[0]));
3234
public static final BlockEntityType<?> GLOBE = register("globe", GenericSingleItemBlockEntity::globe, DecorationsBlocks.GLOBE);
3335
public static final BlockEntityType<?> TRASHCAN = register("trashcan", TrashCanBlockEntity::new, DecorationsBlocks.TRASHCAN);
34-
public static final BlockEntityType<?> BASKET = register("basket", BasketBlockEntity::new, DecorationsBlocks.BASKET);
36+
public static final BlockEntityType<?> GENERIC_PICKABLE_STORAGE = register("generic_pickable_storage", PickableItemContainerBlockEntity::new,
37+
DecorationsBlocks.BASKET, DecorationsBlocks.CARDBOARD_BOX);
3538
public static final BlockEntityType<?> WIND_CHIME = register("wind_chime", WindChimeBlockEntity::new, DecorationsBlocks.WIND_CHIME);
3639

3740
public static final BlockEntityType<?> DISPLAY_CASE = register("display_case",
@@ -62,5 +65,6 @@ public static <T extends BlockEntity> BlockEntityType<T> register(String path, F
6265
}
6366

6467
public static void register() {
68+
BuiltInRegistries.BLOCK_ENTITY_TYPE.addAlias(id("basket"), id("generic_pickable_storage"));
6569
}
6670
}

src/main/java/eu/pb4/polydecorations/block/DecorationsBlocks.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import eu.pb4.polydecorations.block.item.*;
99
import eu.pb4.polydecorations.block.other.GhostLightBlock;
1010
import eu.pb4.polydecorations.block.other.RopeBlock;
11+
import eu.pb4.polydecorations.util.DecorationSoundEvents;
1112
import eu.pb4.polydecorations.util.WoodUtil;
1213
import eu.pb4.polymer.core.api.block.PolymerBlock;
1314
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
@@ -87,11 +88,16 @@ public class DecorationsBlocks {
8788
public static final TrashCanBlock TRASHCAN = register("trashcan", settings -> new TrashCanBlock(settings
8889
.mapColor(MapColor.METAL).strength(3.5F).sound(SoundType.LANTERN).noOcclusion()));
8990

90-
public static final BasketBlock BASKET = register("basket", settings -> new BasketBlock(settings
91+
public static final PickableItemContainerBlock BASKET = register("basket", settings -> new BasketBlock(settings
9192
.mapColor(MapColor.WOOD).strength(0.5F)
9293
.ignitedByLava()
9394
.sound(SoundType.SCAFFOLDING).noOcclusion()));
9495

96+
public static final PickableItemContainerBlock CARDBOARD_BOX = register("cardboard_box", settings -> new PickableItemContainerBlock(settings
97+
.mapColor(MapColor.WOOD).strength(0.4F)
98+
.ignitedByLava()
99+
.sound(SoundType.SCAFFOLDING).noOcclusion(), DecorationSoundEvents.BASKET_OPEN, DecorationSoundEvents.BASKET_CLOSE));
100+
95101
public static final LargeFlowerPotBlock LARGE_FLOWER_POT = register("large_flower_pot", settings -> new LargeFlowerPotBlock(settings
96102
.mapColor(MapColor.COLOR_ORANGE).instrument(NoteBlockInstrument.BASEDRUM).strength(1.25F).noOcclusion()));
97103

src/main/java/eu/pb4/polydecorations/block/item/BasketBlock.java

Lines changed: 12 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package eu.pb4.polydecorations.block.item;
22

33
import com.mojang.serialization.MapCodec;
4-
import eu.pb4.factorytools.api.block.BarrierBasedWaterloggable;
54
import eu.pb4.factorytools.api.block.FactoryBlock;
65
import eu.pb4.factorytools.api.block.QuickWaterloggable;
76
import eu.pb4.factorytools.api.virtualentity.BlockModel;
87
import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil;
98
import eu.pb4.polydecorations.block.DecorationsBlocks;
9+
import eu.pb4.polydecorations.util.DecorationSoundEvents;
1010
import eu.pb4.polydecorations.util.DecorationsUtil;
1111
import eu.pb4.polymer.blocks.api.PolymerTexturedBlock;
1212
import eu.pb4.polymer.virtualentity.api.ElementHolder;
@@ -18,6 +18,7 @@
1818
import net.minecraft.resources.Identifier;
1919
import net.minecraft.server.level.ServerLevel;
2020
import net.minecraft.server.level.ServerPlayer;
21+
import net.minecraft.sounds.SoundEvent;
2122
import net.minecraft.util.RandomSource;
2223
import net.minecraft.world.Containers;
2324
import net.minecraft.world.InteractionResult;
@@ -28,11 +29,7 @@
2829
import net.minecraft.world.level.Level;
2930
import net.minecraft.world.level.LevelReader;
3031
import net.minecraft.world.level.ScheduledTickAccess;
31-
import net.minecraft.world.level.block.BaseEntityBlock;
32-
import net.minecraft.world.level.block.Block;
33-
import net.minecraft.world.level.block.Blocks;
34-
import net.minecraft.world.level.block.ChainBlock;
35-
import net.minecraft.world.level.block.ShulkerBoxBlock;
32+
import net.minecraft.world.level.block.*;
3633
import net.minecraft.world.level.block.entity.BlockEntity;
3734
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
3835
import net.minecraft.world.level.block.state.BlockState;
@@ -53,21 +50,19 @@
5350

5451
import static eu.pb4.polydecorations.util.DecorationsUtil.id;
5552

56-
public class BasketBlock extends BaseEntityBlock implements FactoryBlock, QuickWaterloggable, PolymerTexturedBlock {
57-
public static final Identifier CONTENTS_DYNAMIC_DROP_ID = ShulkerBoxBlock.CONTENTS;
58-
59-
public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
60-
public static final BooleanProperty OPEN = BlockStateProperties.OPEN;
53+
public class BasketBlock extends PickableItemContainerBlock {
6154
public static final BooleanProperty HANGING = BlockStateProperties.HANGING;
6255

56+
6357
public BasketBlock(Properties settings) {
64-
super(settings);
65-
this.registerDefaultState(this.defaultBlockState().setValue(WATERLOGGED, false).setValue(OPEN, false).setValue(HANGING, false));
58+
super(settings, DecorationSoundEvents.BASKET_OPEN, DecorationSoundEvents.BASKET_CLOSE);
59+
this.registerDefaultState(this.defaultBlockState().setValue(HANGING, false));
6660
}
6761

6862
@Override
6963
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
70-
builder.add(WATERLOGGED, FACING, OPEN, HANGING);
64+
super.createBlockStateDefinition(builder);
65+
builder.add(HANGING);
7166
}
7267

7368
@Nullable
@@ -76,56 +71,6 @@ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
7671
return waterLog(ctx, this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getOpposite()).setValue(HANGING, canHangingOn(ctx.getLevel(), ctx.getClickedPos().above())));
7772
}
7873

79-
@Override
80-
public InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
81-
if (!player.isShiftKeyDown() && world.getBlockEntity(pos) instanceof BasketBlockEntity be) {
82-
be.openGui((ServerPlayer) player);
83-
return InteractionResult.SUCCESS_SERVER;
84-
}
85-
86-
return InteractionResult.PASS;
87-
}
88-
89-
@Override
90-
protected void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
91-
if (world.getBlockEntity(pos) instanceof BasketBlockEntity be) {
92-
be.tick();
93-
}
94-
}
95-
96-
97-
@Override
98-
public BlockState playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) {
99-
if (world.getBlockEntity(pos) instanceof BasketBlockEntity be) {
100-
if (!world.isClientSide() && player.preventsBlockDrops() && !be.isEmpty()) {
101-
var itemStack = this.asItem().getDefaultInstance();
102-
itemStack.applyComponents(be.collectComponents());
103-
ItemEntity itemEntity = new ItemEntity(world, (double) pos.getX() + 0.5, (double) pos.getY() + 0.5, (double) pos.getZ() + 0.5, itemStack);
104-
itemEntity.setDefaultPickUpDelay();
105-
world.addFreshEntity(itemEntity);
106-
} else {
107-
//be.generateLoot(player);
108-
}
109-
}
110-
111-
return super.playerWillDestroy(world, pos, state, player);
112-
}
113-
114-
@Override
115-
protected List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
116-
BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
117-
if (blockEntity instanceof ShulkerBoxBlockEntity be) {
118-
builder = builder.withDynamicDrop(CONTENTS_DYNAMIC_DROP_ID, (lootConsumer) -> {
119-
for (int i = 0; i < be.getContainerSize(); ++i) {
120-
lootConsumer.accept(be.getItem(i));
121-
}
122-
123-
});
124-
}
125-
126-
return super.getDrops(state, builder);
127-
}
128-
12974
@Override
13075
public BlockState getPolymerBlockState(BlockState blockState, PacketContext packetContext) {
13176
return blockState.getValue(WATERLOGGED) ? DecorationsUtil.CAMPFIRE_WATERLOGGED_STATE : DecorationsUtil.CAMPFIRE_STATE;
@@ -148,45 +93,21 @@ protected BlockState updateShape(BlockState state, LevelReader world, ScheduledT
14893

14994
private boolean canHangingOn(LevelReader world, BlockPos up) {
15095
var state = world.getBlockState(up);
151-
15296
return state.is(DecorationsBlocks.ROPE) || state.getBlock() instanceof ChainBlock && state.getValue(ChainBlock.AXIS) == Direction.Axis.Y;
15397
}
15498

155-
public FluidState getFluidState(BlockState state) {
156-
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
157-
}
158-
159-
@Override
160-
protected void affectNeighborsAfterRemoval(BlockState state, ServerLevel world, BlockPos pos, boolean moved) {
161-
Containers.updateNeighboursAfterDestroy(state, world, pos);
162-
super.affectNeighborsAfterRemoval(state, world, pos, moved);
163-
}
164-
165-
@Override
166-
protected MapCodec<? extends BaseEntityBlock> codec() {
167-
return null;
168-
}
169-
17099
@Override
171100
public @Nullable ElementHolder createElementHolder(ServerLevel world, BlockPos pos, BlockState initialBlockState) {
172101
return new Model(world, initialBlockState);
173102
}
174103

175-
@Nullable
176-
@Override
177-
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
178-
return new BasketBlockEntity(pos, state);
179-
}
180-
181-
public static final class Model extends BlockModel {
182-
public static final ItemStack BASKET_OPEN = ItemDisplayElementUtil.getModel(id("block/basket_open"));
183-
public static final ItemStack BASKET_CLOSE = ItemDisplayElementUtil.getModel(id("block/basket_closed"));
104+
public final class Model extends BlockModel {
184105
private final ItemDisplayElement main;
185106

186107
public Model(ServerLevel world, BlockState state) {
187108
var direction = state.getValue(FACING).toYRot();
188109

189-
this.main = ItemDisplayElementUtil.createSimple(state.getValue(OPEN) ? BASKET_OPEN : BASKET_CLOSE);
110+
this.main = ItemDisplayElementUtil.createSimple(state.getValue(OPEN) ? modelOpen : modelClosed);
190111
this.main.setScale(new Vector3f(2));
191112
this.main.setTranslation(new Vector3f(0, state.getValue(HANGING) ? 3 / 16f - 0.005f : 0.005f, 0));
192113
this.main.setYaw(direction);
@@ -200,7 +121,7 @@ public void notifyUpdate(HolderAttachment.UpdateType updateType) {
200121
var direction = state.getValue(FACING).toYRot();
201122
this.main.setYaw(direction);
202123
this.main.setTranslation(new Vector3f(0, state.getValue(HANGING) ? 3 / 16f - 0.005f : 0.005f, 0));
203-
this.main.setItem(state.getValue(OPEN) ? BASKET_OPEN : BASKET_CLOSE);
124+
this.main.setItem(state.getValue(OPEN) ? modelOpen : modelClosed);
204125
this.tick();
205126
}
206127
}

0 commit comments

Comments
 (0)