From 4b2ca83d2b341bdc967961b447c0898d86e8092c Mon Sep 17 00:00:00 2001 From: DaniTheSkunk <> Date: Mon, 31 Oct 2022 22:37:34 +0000 Subject: [PATCH] started implementing mailbox --- assets/model/mailbox.aseprite | Bin 0 -> 1012 bytes assets/model/mailbox.bbmodel | 1 + assets/model/mailbox.json | 70 ++++++++++++ assets/model/mailbox.png | Bin 0 -> 536 bytes .../skunkstuff/Blocks/BlockEntityMailbox.java | 100 ++++++++++++++++++ .../skunkstuff/Blocks/BlockEntityTypes.java | 30 ++++++ .../skunkstuff/Blocks/BlockMailbox.java | 74 +++++++++++++ .../skunkstuff/Blocks/Blocks.java | 2 +- .../danitheskunk/skunkstuff/SkunkStuff.java | 4 + .../skunkstuff/blockstates/mailbox.json | 19 ++++ .../assets/skunkstuff/lang/en_us.json | 5 +- .../skunkstuff/models/block/mailbox.json | 70 ++++++++++++ .../skunkstuff/models/item/mailbox.json | 3 + .../skunkstuff/textures/block/mailbox.png | Bin 0 -> 536 bytes .../loot_tables/blocks/mailbox.json | 20 ++++ .../data/skunkstuff/recipes/mailbox.json | 16 +++ 16 files changed, 412 insertions(+), 2 deletions(-) create mode 100644 assets/model/mailbox.aseprite create mode 100644 assets/model/mailbox.bbmodel create mode 100644 assets/model/mailbox.json create mode 100644 assets/model/mailbox.png create mode 100644 src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockEntityMailbox.java create mode 100644 src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockEntityTypes.java create mode 100644 src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockMailbox.java create mode 100644 src/main/resources/assets/skunkstuff/blockstates/mailbox.json create mode 100644 src/main/resources/assets/skunkstuff/models/block/mailbox.json create mode 100644 src/main/resources/assets/skunkstuff/models/item/mailbox.json create mode 100644 src/main/resources/assets/skunkstuff/textures/block/mailbox.png create mode 100644 src/main/resources/data/skunkstuff/loot_tables/blocks/mailbox.json create mode 100644 src/main/resources/data/skunkstuff/recipes/mailbox.json diff --git a/assets/model/mailbox.aseprite b/assets/model/mailbox.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..bc1ec9490cb3578d70bf815ba5e64fe7628a05bb GIT binary patch literal 1012 zcmeyu%)szqDIgETB*TSp_r_Xdcioph-YufMx&<0O|fQ6Q~cQ zY55XakOl>yAK(CJ5(6uPPhw?ikvx!zDaj6zR4_!BW?=wX50f_11UiFN0Vo0l|Ct~( z12~>4=DeL@$aTm-q;2nP_kuT1SY?hlzPRVf|6t7nRvBBjaCUQc_jWy@lL8wS`l|ZR zK2jt9CqP5iuA)-E_UO-rT#jj05r6B+HB!r~17b$>mk{p+@S=+;TI|KHg6 z<8i06a@cs{aYn}Wjd7u14{nh9F|0J)gul}F2{C&*pyX}=_ zKaby&-@4dJ&g$`}>*e;J>rU7|`)TpyzPR!4qOaHU*8MW@-1~3o@4%P;MgRTyf9t;J z%J>&Q?Oa~`Lk?$9fE2~8Oq{!T9+1TfO)`jp(qK?z00z|bgPaWp0xW-TH@7bJlJ;c3 zexP<;D@POm`@|!qj%WDJ7$Px$(n&-?RCt{2*uP5xVHgMS@5L(;QArN(%sSd9!@_PUipgREFl=pzu z&o?Z_6Vh#UQ%=C~X&FG-hfwqoK(CysSX*9^YWLiJRT|e1LbZ7>!r{R#RNgsW zluo4DdKLLH82JPk)oRrl^#ixuP0RkrgVxvL#^qdMWCC;tNJK itemStacks; + + public BlockEntityMailbox(BlockPos pos, BlockState state) { + super(BlockEntityTypes.MAILBOX, pos, state); + this.itemStacks = NonNullList.withSize(SLOTS.length, ItemStack.EMPTY); + } + + @Override + protected Component getDefaultName() { + return Component.translatable("block.skunkstuff.mailbox"); + } + + @Override + protected AbstractContainerMenu createMenu(int syncId, + Inventory playerInventory) { + return null; + } + + @Override + public int getContainerSize() { + return SLOTS.length; + } + + @Override + public boolean isEmpty() { + return itemStacks.isEmpty(); + } + + @Override + public ItemStack getItem(int slot) { + return itemStacks.get(slot); + } + + @Override + public ItemStack removeItem(int slot, int amount) { + var itemStack = ContainerHelper.removeItem(itemStacks, slot, amount); + if(!itemStack.isEmpty()) { + this.setChanged(); + } + return itemStack; + } + + @Override + public ItemStack removeItemNoUpdate(int slot) { + return ContainerHelper.takeItem(itemStacks, slot); + } + + @Override + public void setItem(int slot, ItemStack stack) { + itemStacks.set(slot, stack); + if(stack.getCount() > this.getMaxStackSize()) { + stack.setCount(this.getMaxStackSize()); + } + + this.setChanged(); + } + + @Override + public boolean stillValid(Player player) { + if(this.level.getBlockEntity(this.worldPosition) != this) { + return false; + } else { + return !( + player.distanceToSqr( + (double) this.worldPosition.getX() + + 0.5, + (double) this.worldPosition.getY() + 0.5, + (double) this.worldPosition.getZ() + 0.5 + ) > 64.0 + ); + } + } + + @Override + public void clearContent() { + itemStacks.clear(); + } + + +} diff --git a/src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockEntityTypes.java b/src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockEntityTypes.java new file mode 100644 index 0000000..81f79f2 --- /dev/null +++ b/src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockEntityTypes.java @@ -0,0 +1,30 @@ +package com.danitheskunk.skunkstuff.Blocks; + +import com.danitheskunk.skunkstuff.SkunkStuff; +import com.google.common.collect.ImmutableSet; +import com.mojang.datafixers.types.Type; +import net.minecraft.Util; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.datafix.fixes.References; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import org.quiltmc.qsl.block.entity.api.QuiltBlockEntityTypeBuilder; + +import java.util.Set; + +public class BlockEntityTypes { + public static final BlockEntityType MAILBOX = + QuiltBlockEntityTypeBuilder.create(BlockEntityMailbox::new, + SkunkStuff.MAILBOX_BLOCK).build(); + public static void register() { + Registry.register( + Registry.BLOCK_ENTITY_TYPE, + new ResourceLocation(Blocks.namespace, "mailbox"), + MAILBOX + ); + } +} diff --git a/src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockMailbox.java b/src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockMailbox.java new file mode 100644 index 0000000..f5ba48c --- /dev/null +++ b/src/main/java/com/danitheskunk/skunkstuff/Blocks/BlockMailbox.java @@ -0,0 +1,74 @@ +package com.danitheskunk.skunkstuff.Blocks; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; + +public class BlockMailbox extends BaseEntityBlock { + private static final VoxelShape AABB_EASTWEST = Block.box(0.0, + 0.0, + 4.0, + 16.0, + 11.0, + 12.0 + ); + + private static final VoxelShape AABB_NORTHSOUTH = Block.box(4.0, + 0.0, + 0.0, + 12.0, + 11.0, + 16.0 + ); + private static final VoxelShape AABB_NOPE = Block.box(0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ); + + public BlockMailbox(Properties properties) { + super(properties); + } + + @Override + public VoxelShape getShape(BlockState state, BlockGetter world, + BlockPos pos, CollisionContext context) { + return switch(state.getValue(DirectionalBlock.FACING)) { + case NORTH, SOUTH -> AABB_NORTHSOUTH; + case WEST, EAST -> AABB_EASTWEST; + case UP, DOWN -> AABB_NOPE; + }; + } + + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(DirectionalBlock.FACING); + } + + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return (BlockState) this.defaultBlockState().setValue( + DirectionalBlock.FACING, + ctx.getNearestLookingDirection().getOpposite() + ); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new BlockEntityMailbox(pos, state); + } + + @Override + public RenderShape getRenderShape(BlockState state) { + return RenderShape.MODEL; + } +} diff --git a/src/main/java/com/danitheskunk/skunkstuff/Blocks/Blocks.java b/src/main/java/com/danitheskunk/skunkstuff/Blocks/Blocks.java index 9c9e779..f328178 100644 --- a/src/main/java/com/danitheskunk/skunkstuff/Blocks/Blocks.java +++ b/src/main/java/com/danitheskunk/skunkstuff/Blocks/Blocks.java @@ -12,7 +12,7 @@ import java.util.List; public class Blocks { private static final List deferred = new ArrayList<>(); - private static final String namespace = "skunkstuff"; + public static final String namespace = "skunkstuff"; public static BlockBuilder register() { return new BlockBuilder(); diff --git a/src/main/java/com/danitheskunk/skunkstuff/SkunkStuff.java b/src/main/java/com/danitheskunk/skunkstuff/SkunkStuff.java index 5b959e1..e9a33b1 100644 --- a/src/main/java/com/danitheskunk/skunkstuff/SkunkStuff.java +++ b/src/main/java/com/danitheskunk/skunkstuff/SkunkStuff.java @@ -1,8 +1,10 @@ package com.danitheskunk.skunkstuff; import com.danitheskunk.skunkstuff.Blocks.BlockGoban; +import com.danitheskunk.skunkstuff.Blocks.BlockMailbox; import com.danitheskunk.skunkstuff.Blocks.Blocks; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.DispenserBlock; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.slf4j.Logger; @@ -29,6 +31,8 @@ public class SkunkStuff implements ModInitializer { "crimson_goban").type(BlockGoban.class).build(); public static final Block MANGROVE_GOBAN_BLOCK = Blocks.register().name( "mangrove_goban").type(BlockGoban.class).build(); + public static final Block MAILBOX_BLOCK = Blocks.register().name("mailbox").type( + BlockMailbox.class).build(); @Override public void onInitialize(ModContainer mod) { diff --git a/src/main/resources/assets/skunkstuff/blockstates/mailbox.json b/src/main/resources/assets/skunkstuff/blockstates/mailbox.json new file mode 100644 index 0000000..f90e25a --- /dev/null +++ b/src/main/resources/assets/skunkstuff/blockstates/mailbox.json @@ -0,0 +1,19 @@ +{ + "variants": { + "facing=north": { + "model": "skunkstuff:block/mailbox" + }, + "facing=east": { + "model": "skunkstuff:block/mailbox", + "y": 90 + }, + "facing=south": { + "model": "skunkstuff:block/mailbox", + "y": 180 + }, + "facing=west": { + "model": "skunkstuff:block/mailbox", + "y": 270 + } + } +} diff --git a/src/main/resources/assets/skunkstuff/lang/en_us.json b/src/main/resources/assets/skunkstuff/lang/en_us.json index 4842c3d..fefa0bc 100644 --- a/src/main/resources/assets/skunkstuff/lang/en_us.json +++ b/src/main/resources/assets/skunkstuff/lang/en_us.json @@ -16,5 +16,8 @@ "block.skunkstuff.mangrove.goban": "Mangrove Goban", "block.skunkstuff.oak_goban": "Oak Goban", "block.skunkstuff.spruce_goban": "Spruce Goban", - "block.skunkstuff.warped_goban": "Warped Goban" + "block.skunkstuff.warped_goban": "Warped Goban", + + "item.skunkstuff.mailbox": "Mailbox", + "block.skunkstuff.mailbox": "Mailbox" } diff --git a/src/main/resources/assets/skunkstuff/models/block/mailbox.json b/src/main/resources/assets/skunkstuff/models/block/mailbox.json new file mode 100644 index 0000000..330bee3 --- /dev/null +++ b/src/main/resources/assets/skunkstuff/models/block/mailbox.json @@ -0,0 +1,70 @@ +{ + "credit": "Made with Blockbench", + "texture_size": [64, 64], + "textures": { + "0": "skunkstuff:block/mailbox", + "particle": "skunkstuff:block/mailbox" + }, + "elements": [ + { + "from": [4, 0, 0], + "to": [12, 8, 16], + "faces": { + "north": {"uv": [0, 6, 2, 8], "texture": "#0"}, + "east": {"uv": [0, 0, 4, 2], "texture": "#0"}, + "south": {"uv": [4, 5, 6, 7], "texture": "#0"}, + "west": {"uv": [0, 2, 4, 4], "texture": "#0"}, + "up": {"uv": [4, 6, 0, 4], "rotation": 90, "texture": "#0"}, + "down": {"uv": [8, 0, 4, 2], "rotation": 270, "texture": "#0"} + } + }, + { + "from": [5, 8, 0], + "to": [11, 10, 16], + "faces": { + "north": {"uv": [2, 6.5, 3.5, 7], "texture": "#0"}, + "east": {"uv": [2, 7, 6, 7.5], "texture": "#0"}, + "south": {"uv": [2, 6, 3.5, 6.5], "texture": "#0"}, + "west": {"uv": [6, 7, 10, 7.5], "texture": "#0"}, + "up": {"uv": [8, 3.5, 4, 2], "rotation": 90, "texture": "#0"}, + "down": {"uv": [8, 3.5, 4, 5], "rotation": 270, "texture": "#0"} + } + }, + { + "from": [6, 10, 0], + "to": [10, 11, 16], + "faces": { + "north": {"uv": [8, 0.25, 9, 0.5], "texture": "#0"}, + "east": {"uv": [2, 7.5, 6, 7.75], "texture": "#0"}, + "south": {"uv": [8, 0, 9, 0.25], "texture": "#0"}, + "west": {"uv": [6, 7.5, 10, 7.75], "texture": "#0"}, + "up": {"uv": [10, 6, 6, 5], "rotation": 90, "texture": "#0"}, + "down": {"uv": [10, 6, 6, 7], "rotation": 270, "texture": "#0"} + } + }, + { + "from": [3, 5, 1], + "to": [4, 6, 9], + "faces": { + "north": {"uv": [3.75, 6.75, 4, 7], "texture": "#0"}, + "east": {"uv": [2, 7.75, 4, 8], "texture": "#0"}, + "south": {"uv": [3.5, 6.75, 3.75, 7], "texture": "#0"}, + "west": {"uv": [4, 7.75, 6, 8], "texture": "#0"}, + "up": {"uv": [8, 8, 6, 7.75], "rotation": 90, "texture": "#0"}, + "down": {"uv": [2, 8, 0, 8.25], "rotation": 270, "texture": "#0"} + } + }, + { + "from": [3, 4, 8], + "to": [4, 5, 9], + "faces": { + "north": {"uv": [3.75, 6.25, 4, 6.5], "texture": "#0"}, + "east": {"uv": [3.5, 6, 3.75, 6.25], "texture": "#0"}, + "south": {"uv": [3.75, 6, 4, 6.25], "texture": "#0"}, + "west": {"uv": [3.5, 6.25, 3.75, 6.5], "texture": "#0"}, + "up": {"uv": [3.75, 6.75, 3.5, 6.5], "rotation": 90, "texture": "#0"}, + "down": {"uv": [4, 6.5, 3.75, 6.75], "rotation": 270, "texture": "#0"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/skunkstuff/models/item/mailbox.json b/src/main/resources/assets/skunkstuff/models/item/mailbox.json new file mode 100644 index 0000000..3a1e16f --- /dev/null +++ b/src/main/resources/assets/skunkstuff/models/item/mailbox.json @@ -0,0 +1,3 @@ +{ + "parent": "skunkstuff:block/mailbox" +} \ No newline at end of file diff --git a/src/main/resources/assets/skunkstuff/textures/block/mailbox.png b/src/main/resources/assets/skunkstuff/textures/block/mailbox.png new file mode 100644 index 0000000000000000000000000000000000000000..ad0520d104ddb478833226aa33fa8cbeb9224998 GIT binary patch literal 536 zcmV+z0_XjSP)Px$(n&-?RCt{2*uP5xVHgMS@5L(;QArN(%sSd9!@_PUipgREFl=pzu z&o?Z_6Vh#UQ%=C~X&FG-hfwqoK(CysSX*9^YWLiJRT|e1LbZ7>!r{R#RNgsW zluo4DdKLLH82JPk)oRrl^#ixuP0RkrgVxvL#^qdMWCC;tNJK