Skip to content

Commit

Permalink
✨ Sleeping bag can be used without the backpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiviacz1337 committed Nov 3, 2023
1 parent ce6e35b commit b1848e0
Show file tree
Hide file tree
Showing 19 changed files with 499 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ public boolean deploySleepingBag(World world, BlockPos pos)
if(!world.isClient)
{
BlockState sleepingBagState = getProperSleepingBag(getSleepingBagColor());
world.setBlockState(sleepingBagPos1, sleepingBagState.with(SleepingBagBlock.FACING, direction).with(SleepingBagBlock.PART, BedPart.FOOT), 3);
world.setBlockState(sleepingBagPos2, sleepingBagState.with(SleepingBagBlock.FACING, direction).with(SleepingBagBlock.PART, BedPart.HEAD), 3);
world.setBlockState(sleepingBagPos1, sleepingBagState.with(SleepingBagBlock.FACING, direction).with(SleepingBagBlock.PART, BedPart.FOOT).with(SleepingBagBlock.CAN_DROP, false), 3);
world.setBlockState(sleepingBagPos2, sleepingBagState.with(SleepingBagBlock.FACING, direction).with(SleepingBagBlock.PART, BedPart.HEAD).with(SleepingBagBlock.CAN_DROP, false), 3);

world.updateNeighborsAlways(pos, sleepingBagState.getBlock());
world.updateNeighborsAlways(sleepingBagPos2, sleepingBagState.getBlock());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.stat.Stats;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class SleepingBagBlock extends BedBlock
{
public static final EnumProperty<BedPart> PART;
public static final BooleanProperty OCCUPIED;
public static final BooleanProperty CAN_DROP;

private static final VoxelShape SLEEPING_BAG_SHAPE;
private static final VoxelShape SLEEPING_BAG_SHAPE_NORTH;
Expand All @@ -56,7 +58,7 @@ public class SleepingBagBlock extends BedBlock
public SleepingBagBlock(DyeColor color, Settings settings)
{
super(color, settings);
this.setDefaultState(this.stateManager.getDefaultState().with(PART, BedPart.FOOT).with(OCCUPIED, false));
this.setDefaultState(this.stateManager.getDefaultState().with(PART, BedPart.FOOT).with(OCCUPIED, false).with(CAN_DROP, true));
}

@Override
Expand Down Expand Up @@ -310,7 +312,7 @@ public PistonBehavior getPistonBehavior(BlockState state) {

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING, PART, OCCUPIED);
builder.add(FACING, PART, OCCUPIED, CAN_DROP);
}

@Override
Expand All @@ -335,6 +337,16 @@ public long getRenderingSeed(BlockState state, BlockPos pos)
return MathHelper.hashCode(blockPos.getX(), pos.getY(), blockPos.getZ());
}

@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder)
{
if(!state.get(CAN_DROP))
{
return List.of();
}
return super.getDroppedStacks(state, builder);
}

@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state)
{
Expand All @@ -344,6 +356,7 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state)
static {
PART = Properties.BED_PART;
OCCUPIED = Properties.OCCUPIED;
CAN_DROP = Properties.CONDITIONAL;
SLEEPING_BAG_SHAPE = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D);
SLEEPING_BAG_SHAPE_NORTH = Stream.of(
Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package com.tiviacz.travelersbackpack.items;

import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.ActionResult;
import net.minecraft.item.BedItem;

public class SleepingBagItem extends BlockItem
public class SleepingBagItem extends BedItem
{
public SleepingBagItem(Block block, Settings settings)
{
super(block, settings);
}

public ActionResult useOnBlock(ItemUsageContext context)
{
return ActionResult.FAIL;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:black_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:black_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/black_sleeping_bag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:blue_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:blue_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/blue_sleeping_bag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:brown_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:brown_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/brown_sleeping_bag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:cyan_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:cyan_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/cyan_sleeping_bag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:gray_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:gray_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/gray_sleeping_bag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:green_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:green_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/green_sleeping_bag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:light_blue_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:light_blue_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/light_blue_sleeping_bag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:light_gray_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:light_gray_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/light_gray_sleeping_bag"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"conditions": [
{
"block": "travelersbackpack:lime_sleeping_bag",
"condition": "minecraft:block_state_property",
"properties": {
"part": "head"
}
}
],
"name": "travelersbackpack:lime_sleeping_bag"
}
],
"rolls": 1.0
}
],
"random_sequence": "travelersbackpack:blocks/lime_sleeping_bag"
}
Loading

0 comments on commit b1848e0

Please sign in to comment.