diff --git a/src/main/java/net/doppelr/lemonmates/AllCreativeModeTabs.java b/src/main/java/net/doppelr/lemonmates/AllCreativeModeTabs.java index 6b24e92..fea77ea 100644 --- a/src/main/java/net/doppelr/lemonmates/AllCreativeModeTabs.java +++ b/src/main/java/net/doppelr/lemonmates/AllCreativeModeTabs.java @@ -7,6 +7,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.CreativeModeTabs; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.registries.DeferredRegister; @@ -16,6 +17,11 @@ public class AllCreativeModeTabs { public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, LemonMates.MOD_ID); + private static ItemStack lemonadeJugStack(ItemStack stack) { + stack.set(AllDataComponents.CAN_POUR, false); + return stack; + } + public static final DeferredHolder BASE_CREATIVE_TAB = CREATIVE_MODE_TABS.register("base", () -> CreativeModeTab.builder() .title(Component.translatable("itemGroup." + LemonMates.MOD_ID + ".base")) @@ -36,6 +42,7 @@ public class AllCreativeModeTabs { // Misc output.accept(ModBlocks.LEMONADE_GLASS); + output.accept(lemonadeJugStack(ModBlocks.TERRACOTTA_LEMONADE_JUG.toStack())); // Finished Lemonades output.accept(ModItems.CITRON_LEMONADE_BOTTLE); diff --git a/src/main/java/net/doppelr/lemonmates/block/ModBlocks.java b/src/main/java/net/doppelr/lemonmates/block/ModBlocks.java index b44a981..d156259 100644 --- a/src/main/java/net/doppelr/lemonmates/block/ModBlocks.java +++ b/src/main/java/net/doppelr/lemonmates/block/ModBlocks.java @@ -10,6 +10,7 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.properties.BlockSetType; import net.minecraft.world.level.block.state.properties.WoodType; +import net.minecraft.world.level.material.PushReaction; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.registries.DeferredBlock; import net.neoforged.neoforge.registries.DeferredRegister; @@ -111,7 +112,7 @@ public class ModBlocks { public static final DeferredBlock LEMONADE_GLASS = registerBlock("lemonade_glass", () -> new ModDrinkingGlassBlock(BlockBehaviour.Properties.of() - .sound(SoundType.GLASS) + .sound(SoundType.GLASS).pushReaction(PushReaction.DESTROY) )); public static final DeferredBlock LEMONADE_GLASS_DECORATED = registerBlock("lemonade_glass_decorated", () -> new ModDrinkingGlassBlock(BlockBehaviour.Properties.of() diff --git a/src/main/java/net/doppelr/lemonmates/block/ModDrinkingGlassBlock.java b/src/main/java/net/doppelr/lemonmates/block/ModDrinkingGlassBlock.java index 4c55ce1..eb4c499 100644 --- a/src/main/java/net/doppelr/lemonmates/block/ModDrinkingGlassBlock.java +++ b/src/main/java/net/doppelr/lemonmates/block/ModDrinkingGlassBlock.java @@ -28,13 +28,19 @@ import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; @@ -42,7 +48,7 @@ import java.util.List; -public class ModDrinkingGlassBlock extends HorizontalDirectionalBlock { +public class ModDrinkingGlassBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock { public static final MapCodec CODEC = simpleCodec(ModDrinkingGlassBlock::new); private static final VoxelShape SHAPE = Block.box(5.0, 0, 5, 11, 7, 11); @@ -52,6 +58,7 @@ public class ModDrinkingGlassBlock extends HorizontalDirectionalBlock { public static final EnumProperty FRUIT_SLICE = AllBlockStateProperties.FRUIT_SLICES; public static final EnumProperty UMBRELLA = AllBlockStateProperties.UMBRELLAS; public static final BooleanProperty ICE_CUBES = AllBlockStateProperties.ICE_CUBES; + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; protected ModDrinkingGlassBlock(Properties properties) { super(properties); @@ -62,7 +69,22 @@ protected ModDrinkingGlassBlock(Properties properties) { .setValue(STRAW, StrawsVariants.NONE) .setValue(FRUIT_SLICE, FruitSlices.NONE) .setValue(UMBRELLA, UmbrellaVariants.NONE) - .setValue(ICE_CUBES, false)); + .setValue(ICE_CUBES, false) + .setValue(WATERLOGGED, false)); + } + + @Override + protected BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) { + if (state.getValue(WATERLOGGED)) { + level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); + } + + return super.updateShape(state, facing, facingState, level, currentPos, facingPos); + } + + @Override + protected FluidState getFluidState(BlockState state) { + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } public void customConsumptionBehaviours(BlockState state, Player player) {} @@ -248,8 +270,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev return super.useItemOn(stack, state, level, pos, player, hand, hitResult); } - @Override - public BlockState playerWillDestroy(Level level, BlockPos pos, BlockState state, Player player) { + public void destroyReaction(Level level, BlockPos pos, BlockState state) { if (!level.isClientSide) { ItemStack itemStack = new ItemStack(this); int drinkLevel = state.getValue(DRINK_LEVEL); @@ -273,6 +294,11 @@ public BlockState playerWillDestroy(Level level, BlockPos pos, BlockState state, itemEntity.setDefaultPickUpDelay(); level.addFreshEntity(itemEntity); } + } + + @Override + public BlockState playerWillDestroy(Level level, BlockPos pos, BlockState state, Player player) { + this.destroyReaction(level, pos, state); return super.playerWillDestroy(level, pos, state, player); } @@ -280,8 +306,12 @@ public BlockState playerWillDestroy(Level level, BlockPos pos, BlockState state, public void appendHoverText(ItemStack stack, Item.TooltipContext context, List tooltipComponents, TooltipFlag tooltipFlag) { super.appendHoverText(stack, context, tooltipComponents, tooltipFlag); - if (stack.has(DataComponents.BLOCK_STATE)) - tooltipComponents.add(Component.literal("Has Decorations Applied").withStyle(ChatFormatting.ITALIC, ChatFormatting.GRAY)); + BlockItemStateProperties dataComponentType = stack.get(DataComponents.BLOCK_STATE); + if (dataComponentType != null) + if ((dataComponentType.get(AllBlockStateProperties.STRAWS) != null && dataComponentType.get(AllBlockStateProperties.STRAWS) != StrawsVariants.NONE) + || (dataComponentType.get(AllBlockStateProperties.FRUIT_SLICES) != null && dataComponentType.get(AllBlockStateProperties.FRUIT_SLICES) != FruitSlices.NONE) + || (dataComponentType.get(AllBlockStateProperties.UMBRELLAS) != null && dataComponentType.get(AllBlockStateProperties.UMBRELLAS) != UmbrellaVariants.NONE)) + tooltipComponents.add(Component.literal("Has Decorations Applied").withStyle(ChatFormatting.ITALIC, ChatFormatting.GRAY)); } @Override @@ -302,6 +332,6 @@ public BlockState getStateForPlacement(BlockPlaceContext context) { @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(FACING, STRAW, FRUIT_SLICE, UMBRELLA, DRINK_LEVEL, ICE_CUBES, FLUID); + builder.add(FACING, STRAW, FRUIT_SLICE, UMBRELLA, DRINK_LEVEL, ICE_CUBES, FLUID, WATERLOGGED); } } diff --git a/src/main/java/net/doppelr/lemonmates/block/ModJugBlock.java b/src/main/java/net/doppelr/lemonmates/block/ModJugBlock.java index 913d468..d87c368 100644 --- a/src/main/java/net/doppelr/lemonmates/block/ModJugBlock.java +++ b/src/main/java/net/doppelr/lemonmates/block/ModJugBlock.java @@ -4,6 +4,7 @@ import net.doppelr.lemonmates.AllDataComponents; import net.doppelr.lemonmates.block.properties.ApplicableFluidsToFluidContainer; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.DataComponents; import net.minecraft.world.entity.item.ItemEntity; @@ -12,24 +13,44 @@ import net.minecraft.world.item.component.BlockItemStateProperties; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -public class ModJugBlock extends Block { +public class ModJugBlock extends Block implements SimpleWaterloggedBlock { private static final VoxelShape SHAPE = Block.box(5, 0, 5, 11, 10, 11); public static final IntegerProperty JUG_LEVEL = AllBlockStateProperties.JUG_LEVEL; public static final EnumProperty FLUID = AllBlockStateProperties.APPLICABLE_FLUID_TO_CONTAINER; public static final BooleanProperty CAN_POUR = AllBlockStateProperties.CAN_POUR; + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public ModJugBlock(Properties properties) { super(properties); - this.registerDefaultState(this.defaultBlockState().setValue(JUG_LEVEL, 0).setValue(FLUID, ApplicableFluidsToFluidContainer.NONE).setValue(CAN_POUR, false)); + this.registerDefaultState(this.defaultBlockState().setValue(JUG_LEVEL, 0).setValue(FLUID, ApplicableFluidsToFluidContainer.NONE).setValue(CAN_POUR, false).setValue(WATERLOGGED, false)); + } + + @Override + protected BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) { + if (state.getValue(WATERLOGGED)) { + level.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); + } + + return super.updateShape(state, facing, facingState, level, currentPos, facingPos); + } + + @Override + protected FluidState getFluidState(BlockState state) { + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @Override @@ -67,6 +88,6 @@ protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(JUG_LEVEL, FLUID, CAN_POUR); + builder.add(JUG_LEVEL, FLUID, CAN_POUR, WATERLOGGED); } } diff --git a/src/main/java/net/doppelr/lemonmates/block/entity/ModBlockEntities.java b/src/main/java/net/doppelr/lemonmates/block/entity/ModBlockEntities.java index f6ade35..71507d3 100644 --- a/src/main/java/net/doppelr/lemonmates/block/entity/ModBlockEntities.java +++ b/src/main/java/net/doppelr/lemonmates/block/entity/ModBlockEntities.java @@ -2,15 +2,12 @@ import net.doppelr.lemonmates.LemonMates; import net.doppelr.lemonmates.block.ModBlocks; -import net.doppelr.lemonmates.entity.LemonadeglassEntity; import net.minecraft.core.registries.Registries; import net.minecraft.world.level.block.entity.BlockEntityType; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; -import java.util.function.Supplier; - public class ModBlockEntities { public static DeferredRegister> BLOCK_ENTITIES = DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, LemonMates.MOD_ID); @@ -27,12 +24,6 @@ public class ModBlockEntities { ModBlocks.ORANGE_HANGING_SIGN.get(), ModBlocks.ORANGE_WALL_HANGING_SIGN.get(), ModBlocks.CITRON_HANGING_SIGN.get(), ModBlocks.CITRON_WALL_HANGING_SIGN.get()).build(null)); - public static final Supplier> LEMONADE_GLASS_ENTITY = - BLOCK_ENTITIES.register("lemonade_glass_entity", () -> - BlockEntityType.Builder.of(LemonadeglassEntity::new, - ModBlocks.LEMONADE_GLASS.get()).build(null) - ); - public static void register(IEventBus eventBus) { BLOCK_ENTITIES.register(eventBus); } diff --git a/src/main/java/net/doppelr/lemonmates/entity/LemonadeglassEntity.java b/src/main/java/net/doppelr/lemonmates/entity/LemonadeglassEntity.java deleted file mode 100644 index ac3324d..0000000 --- a/src/main/java/net/doppelr/lemonmates/entity/LemonadeglassEntity.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.doppelr.lemonmates.entity; - -import net.doppelr.lemonmates.block.entity.ModBlockEntities; -import net.minecraft.core.BlockPos; -import net.minecraft.core.HolderLookup; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; - -public class LemonadeglassEntity extends BlockEntity { - private int hasSlice; // 0 = none, 1 = orange, 2 = lemon - private String lemonade; // none, citronFull, citronHalf, orangeFull, orangeHalf, raspberryFull, raspberryHalf, summerFull, summerHalf, watermelonFull, watermelonHalf - private int umbrellaMain; // 0 = white, 1 = light gray, 2 = gray, 3 = black, 4 = brown, 5 = red, 6 = orange, 7 = yellow, 8 = lime, 9 = green, 10 = cyan, 11 = light blue, 12 = blue, 13 = purple, 14 = magenta, 15 = pink - private int umbrellaSecondary; // 0 = white, 1 = light gray, 2 = gray, 3 = black, 4 = brown, 5 = red, 6 = orange, 7 = yellow, 8 = lime, 9 = green, 10 = cyan, 11 = light blue, 12 = blue, 13 = purple, 14 = magenta, 15 = pink - private int straw; // 0 = none, 1 = red/white, 2 = rainbow, 3 = trans, 4 = nonbinary, 5 = lesbian, 6 = gay, 7 = genderfluid, 8 = ace, 9 = aro, 10 = agender, 11 = aroace, 12 = bisexual, 13 = pansexual - - public LemonadeglassEntity(BlockPos pos, BlockState state) { - super(ModBlockEntities.LEMONADE_GLASS_ENTITY.get(), pos, state); - } - - @Override - public void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) { - super.loadAdditional(tag, registries); - this.hasSlice = tag.getInt("hasSlice"); - this.lemonade = tag.getString("lemonade"); - this.umbrellaMain = tag.getInt("umbrellaMain"); - this.umbrellaSecondary = tag.getInt("umbrellaSecondary"); - this.straw = tag.getInt("straw"); - } - - @Override - public void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { - super.saveAdditional(tag, registries); - tag.putInt("hasSlice", this.hasSlice); - tag.putString("lemonade", this.lemonade); - tag.putInt("umbrellaMain", this.umbrellaMain); - tag.putInt("umbrellaSecondary", this.umbrellaSecondary); - tag.putInt("straw", this.straw); - } -}